slatedb-node 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/lib/index.d.ts +360 -0
  2. package/lib/index.js +458 -0
  3. package/package.json +11 -9
package/lib/index.d.ts ADDED
@@ -0,0 +1,360 @@
1
+ type Binary = Buffer | Uint8Array | string;
2
+ interface NativeReadOptions {
3
+ durabilityFilter?: "memory" | "remote";
4
+ dirty?: boolean;
5
+ cacheBlocks?: boolean;
6
+ }
7
+ interface NativeScanOptions extends NativeReadOptions {
8
+ readAheadBytes?: number;
9
+ maxFetchTasks?: number;
10
+ }
11
+ interface NativeWriteOptions {
12
+ awaitDurable?: boolean;
13
+ }
14
+ interface NativePutOptions {
15
+ ttlMs?: number;
16
+ noExpiry?: boolean;
17
+ }
18
+ interface NativeMergeOptions {
19
+ ttlMs?: number;
20
+ noExpiry?: boolean;
21
+ }
22
+ interface NativeCheckpointOptions {
23
+ lifetimeMs?: number;
24
+ source?: string;
25
+ name?: string;
26
+ }
27
+ interface NativeGcDirectoryOptions {
28
+ intervalMs?: number;
29
+ minAgeMs?: number;
30
+ }
31
+ interface NativeGcOptions {
32
+ manifest?: NativeGcDirectoryOptions;
33
+ wal?: NativeGcDirectoryOptions;
34
+ compacted?: NativeGcDirectoryOptions;
35
+ compactions?: NativeGcDirectoryOptions;
36
+ }
37
+ interface NativeCompactionSource {
38
+ sortedRun?: number;
39
+ sst?: string;
40
+ }
41
+ interface NativeCompactionSpec {
42
+ sources: NativeCompactionSource[];
43
+ destination: number;
44
+ }
45
+ interface NativeKeyValue {
46
+ key: Buffer;
47
+ value: Buffer;
48
+ }
49
+ interface NativeWriteHandle {
50
+ seq: number;
51
+ createTs: number;
52
+ }
53
+ interface NativeCheckpointCreateResult {
54
+ id: string;
55
+ manifestId: number;
56
+ }
57
+ interface NativeCheckpoint {
58
+ id: string;
59
+ manifestId: number;
60
+ expireTimeMs: number | null;
61
+ createTimeMs: number;
62
+ name?: string;
63
+ }
64
+ interface NativeSlateDBIterator {
65
+ next(): Promise<NativeKeyValue | null>;
66
+ seek(key: Buffer): Promise<void>;
67
+ close(): Promise<void>;
68
+ }
69
+ interface NativeWriteBatch {
70
+ put(key: Buffer, value: Buffer): void;
71
+ putWithOptions(key: Buffer, value: Buffer, options?: NativePutOptions): void;
72
+ delete(key: Buffer): void;
73
+ merge(key: Buffer, value: Buffer): void;
74
+ mergeWithOptions(key: Buffer, value: Buffer, options?: NativeMergeOptions): void;
75
+ }
76
+ interface NativeSlateDBSnapshot {
77
+ get(key: Buffer): Promise<Buffer | null>;
78
+ getWithOptions(key: Buffer, options?: NativeReadOptions): Promise<Buffer | null>;
79
+ scan(start: Buffer, end?: Buffer): Promise<NativeSlateDBIterator>;
80
+ scanWithOptions(start: Buffer, end?: Buffer, options?: NativeScanOptions): Promise<NativeSlateDBIterator>;
81
+ scanPrefix(prefix: Buffer): Promise<NativeSlateDBIterator>;
82
+ scanPrefixWithOptions(prefix: Buffer, options?: NativeScanOptions): Promise<NativeSlateDBIterator>;
83
+ close(): Promise<void>;
84
+ }
85
+ interface NativeSlateDBTransaction {
86
+ get(key: Buffer): Promise<Buffer | null>;
87
+ getWithOptions(key: Buffer, options?: NativeReadOptions): Promise<Buffer | null>;
88
+ scan(start: Buffer, end?: Buffer): Promise<NativeSlateDBIterator>;
89
+ scanWithOptions(start: Buffer, end?: Buffer, options?: NativeScanOptions): Promise<NativeSlateDBIterator>;
90
+ scanPrefix(prefix: Buffer): Promise<NativeSlateDBIterator>;
91
+ scanPrefixWithOptions(prefix: Buffer, options?: NativeScanOptions): Promise<NativeSlateDBIterator>;
92
+ put(key: Buffer, value: Buffer): Promise<void>;
93
+ putWithOptions(key: Buffer, value: Buffer, options?: NativePutOptions): Promise<void>;
94
+ delete(key: Buffer): Promise<void>;
95
+ merge(key: Buffer, value: Buffer): Promise<void>;
96
+ mergeWithOptions(key: Buffer, value: Buffer, options?: NativeMergeOptions): Promise<void>;
97
+ markRead(keys: Buffer[]): Promise<void>;
98
+ unmarkWrite(keys: Buffer[]): Promise<void>;
99
+ commit(writeOptions?: NativeWriteOptions): Promise<NativeWriteHandle | null>;
100
+ rollback(): Promise<void>;
101
+ close(): Promise<void>;
102
+ }
103
+ interface NativeSlateDBReader {
104
+ get(key: Buffer): Promise<Buffer | null>;
105
+ getWithOptions(key: Buffer, options?: NativeReadOptions): Promise<Buffer | null>;
106
+ scan(start: Buffer, end?: Buffer): Promise<NativeSlateDBIterator>;
107
+ scanWithOptions(start: Buffer, end?: Buffer, options?: NativeScanOptions): Promise<NativeSlateDBIterator>;
108
+ scanPrefix(prefix: Buffer): Promise<NativeSlateDBIterator>;
109
+ scanPrefixWithOptions(prefix: Buffer, options?: NativeScanOptions): Promise<NativeSlateDBIterator>;
110
+ close(): Promise<void>;
111
+ }
112
+ interface NativeSlateDBAdmin {
113
+ readManifest(id?: number): Promise<string | null>;
114
+ listManifests(start?: number, end?: number): Promise<string>;
115
+ readCompactions(id?: number): Promise<string | null>;
116
+ listCompactions(start?: number, end?: number): Promise<string>;
117
+ readCompaction(id: string, compactionsId?: number): Promise<string | null>;
118
+ submitCompaction(spec: NativeCompactionSpec): Promise<string>;
119
+ createCheckpoint(options?: NativeCheckpointOptions): Promise<NativeCheckpointCreateResult>;
120
+ listCheckpoints(name?: string): Promise<NativeCheckpoint[]>;
121
+ refreshCheckpoint(id: string, lifetimeMs?: number): Promise<void>;
122
+ deleteCheckpoint(id: string): Promise<void>;
123
+ getTimestampForSequence(seq: number, roundUp?: boolean): Promise<number | null>;
124
+ getSequenceForTimestamp(timestampMs: number, roundUp?: boolean): Promise<number | null>;
125
+ createClone(parentPath: string, parentCheckpoint?: string): Promise<void>;
126
+ runGcOnce(options?: NativeGcOptions): Promise<void>;
127
+ runGc(options?: NativeGcOptions): Promise<void>;
128
+ }
129
+ interface NativeSlateDB {
130
+ get(key: Buffer): Promise<Buffer | null>;
131
+ getWithOptions(key: Buffer, options?: NativeReadOptions): Promise<Buffer | null>;
132
+ put(key: Buffer, value: Buffer): Promise<NativeWriteHandle>;
133
+ putWithOptions(key: Buffer, value: Buffer, putOptions?: NativePutOptions, writeOptions?: NativeWriteOptions): Promise<NativeWriteHandle>;
134
+ delete(key: Buffer): Promise<NativeWriteHandle>;
135
+ deleteWithOptions(key: Buffer, writeOptions?: NativeWriteOptions): Promise<NativeWriteHandle>;
136
+ merge(key: Buffer, value: Buffer): Promise<NativeWriteHandle>;
137
+ mergeWithOptions(key: Buffer, value: Buffer, mergeOptions?: NativeMergeOptions, writeOptions?: NativeWriteOptions): Promise<NativeWriteHandle>;
138
+ write(batch: NativeWriteBatch): Promise<NativeWriteHandle>;
139
+ writeWithOptions(batch: NativeWriteBatch, writeOptions?: NativeWriteOptions): Promise<NativeWriteHandle>;
140
+ scan(start: Buffer, end?: Buffer): Promise<NativeSlateDBIterator>;
141
+ scanWithOptions(start: Buffer, end?: Buffer, options?: NativeScanOptions): Promise<NativeSlateDBIterator>;
142
+ scanPrefix(prefix: Buffer): Promise<NativeSlateDBIterator>;
143
+ scanPrefixWithOptions(prefix: Buffer, options?: NativeScanOptions): Promise<NativeSlateDBIterator>;
144
+ snapshot(): Promise<NativeSlateDBSnapshot>;
145
+ begin(isolation?: string): Promise<NativeSlateDBTransaction>;
146
+ flush(): Promise<void>;
147
+ flushWithOptions(flushType?: "wal" | "memtable"): Promise<void>;
148
+ metrics(): Promise<Record<string, number>>;
149
+ createCheckpoint(scope?: "all" | "durable", options?: NativeCheckpointOptions): Promise<NativeCheckpointCreateResult>;
150
+ status(): Promise<void>;
151
+ close(): Promise<void>;
152
+ }
153
+ export declare class SlateDBError extends Error {
154
+ cause?: unknown;
155
+ constructor(message: string, cause?: unknown);
156
+ }
157
+ export declare class TransactionError extends SlateDBError {
158
+ }
159
+ export declare class ClosedError extends SlateDBError {
160
+ }
161
+ export declare class UnavailableError extends SlateDBError {
162
+ }
163
+ export declare class InvalidError extends SlateDBError {
164
+ }
165
+ export declare class DataError extends SlateDBError {
166
+ }
167
+ export declare class InternalError extends SlateDBError {
168
+ }
169
+ export interface ReadOptions {
170
+ durabilityFilter?: "memory" | "remote";
171
+ dirty?: boolean;
172
+ cacheBlocks?: boolean;
173
+ }
174
+ export interface ScanOptions extends ReadOptions {
175
+ readAheadBytes?: number;
176
+ maxFetchTasks?: number;
177
+ }
178
+ export interface WriteOptions {
179
+ awaitDurable?: boolean;
180
+ }
181
+ export interface PutOptions {
182
+ ttlMs?: number;
183
+ noExpiry?: boolean;
184
+ }
185
+ export interface MergeOptions {
186
+ ttlMs?: number;
187
+ noExpiry?: boolean;
188
+ }
189
+ export interface CheckpointOptions {
190
+ lifetimeMs?: number;
191
+ source?: string;
192
+ name?: string;
193
+ }
194
+ export interface GcDirectoryOptions {
195
+ intervalMs?: number;
196
+ minAgeMs?: number;
197
+ }
198
+ export interface GcOptions {
199
+ manifest?: GcDirectoryOptions;
200
+ wal?: GcDirectoryOptions;
201
+ compacted?: GcDirectoryOptions;
202
+ compactions?: GcDirectoryOptions;
203
+ }
204
+ export interface CompactionSource {
205
+ sortedRun?: number;
206
+ sst?: string;
207
+ }
208
+ export interface CompactionSpec {
209
+ sources: CompactionSource[];
210
+ destination: number;
211
+ }
212
+ export interface WriteHandle {
213
+ seq: number;
214
+ createTs: number;
215
+ }
216
+ export interface CheckpointCreateResult {
217
+ id: string;
218
+ manifestId: number;
219
+ }
220
+ export interface Checkpoint {
221
+ id: string;
222
+ manifestId: number;
223
+ expireTimeMs: number | null;
224
+ createTimeMs: number;
225
+ name?: string;
226
+ }
227
+ export interface SlateDBOpenOptions {
228
+ path: string;
229
+ url?: string;
230
+ envFile?: string;
231
+ settingsPath?: string;
232
+ settings?: Record<string, unknown>;
233
+ }
234
+ export interface SlateDBReaderOpenOptions {
235
+ path: string;
236
+ url?: string;
237
+ envFile?: string;
238
+ checkpointId?: string;
239
+ manifestPollIntervalMs?: number;
240
+ checkpointLifetimeMs?: number;
241
+ maxMemtableBytes?: number;
242
+ skipWalReplay?: boolean;
243
+ options?: Record<string, unknown>;
244
+ }
245
+ export interface SlateDBAdminOpenOptions {
246
+ path: string;
247
+ url?: string;
248
+ envFile?: string;
249
+ walUrl?: string;
250
+ }
251
+ export declare class SlateDBIterator implements AsyncIterable<[Buffer, Buffer]> {
252
+ private readonly native;
253
+ constructor(nativeIterator: NativeSlateDBIterator);
254
+ next(): Promise<[Buffer, Buffer] | null>;
255
+ seek(key: Binary): Promise<void>;
256
+ close(): Promise<void>;
257
+ [Symbol.asyncIterator](): AsyncIterator<[Buffer, Buffer]>;
258
+ }
259
+ export declare class WriteBatch {
260
+ private readonly native;
261
+ constructor();
262
+ put(key: Binary, value: Binary): void;
263
+ putWithOptions(key: Binary, value: Binary, options?: PutOptions): void;
264
+ delete(key: Binary): void;
265
+ merge(key: Binary, value: Binary): void;
266
+ mergeWithOptions(key: Binary, value: Binary, options?: MergeOptions): void;
267
+ getNative(): NativeWriteBatch;
268
+ }
269
+ export declare class SlateDBSnapshot {
270
+ private readonly native;
271
+ constructor(nativeSnapshot: NativeSlateDBSnapshot);
272
+ get(key: Binary): Promise<Buffer | null>;
273
+ getWithOptions(key: Binary, options?: ReadOptions): Promise<Buffer | null>;
274
+ scan(start: Binary, end?: Binary): Promise<SlateDBIterator>;
275
+ scanWithOptions(start: Binary, end?: Binary, options?: ScanOptions): Promise<SlateDBIterator>;
276
+ scanPrefix(prefix: Binary): Promise<SlateDBIterator>;
277
+ scanPrefixWithOptions(prefix: Binary, options?: ScanOptions): Promise<SlateDBIterator>;
278
+ close(): Promise<void>;
279
+ }
280
+ export declare class SlateDBTransaction {
281
+ private readonly native;
282
+ constructor(nativeTransaction: NativeSlateDBTransaction);
283
+ get(key: Binary): Promise<Buffer | null>;
284
+ getWithOptions(key: Binary, options?: ReadOptions): Promise<Buffer | null>;
285
+ scan(start: Binary, end?: Binary): Promise<SlateDBIterator>;
286
+ scanWithOptions(start: Binary, end?: Binary, options?: ScanOptions): Promise<SlateDBIterator>;
287
+ scanPrefix(prefix: Binary): Promise<SlateDBIterator>;
288
+ scanPrefixWithOptions(prefix: Binary, options?: ScanOptions): Promise<SlateDBIterator>;
289
+ put(key: Binary, value: Binary): Promise<void>;
290
+ putWithOptions(key: Binary, value: Binary, options?: PutOptions): Promise<void>;
291
+ delete(key: Binary): Promise<void>;
292
+ merge(key: Binary, value: Binary): Promise<void>;
293
+ mergeWithOptions(key: Binary, value: Binary, options?: MergeOptions): Promise<void>;
294
+ markRead(keys: Binary[]): Promise<void>;
295
+ unmarkWrite(keys: Binary[]): Promise<void>;
296
+ commit(writeOptions?: WriteOptions): Promise<WriteHandle | null>;
297
+ rollback(): Promise<void>;
298
+ close(): Promise<void>;
299
+ }
300
+ export declare class SlateDBReader {
301
+ private readonly native;
302
+ constructor(nativeReader: NativeSlateDBReader);
303
+ get(key: Binary): Promise<Buffer | null>;
304
+ getWithOptions(key: Binary, options?: ReadOptions): Promise<Buffer | null>;
305
+ scan(start: Binary, end?: Binary): Promise<SlateDBIterator>;
306
+ scanWithOptions(start: Binary, end?: Binary, options?: ScanOptions): Promise<SlateDBIterator>;
307
+ scanPrefix(prefix: Binary): Promise<SlateDBIterator>;
308
+ scanPrefixWithOptions(prefix: Binary, options?: ScanOptions): Promise<SlateDBIterator>;
309
+ close(): Promise<void>;
310
+ }
311
+ export declare class SlateDBAdmin {
312
+ private readonly native;
313
+ constructor(nativeAdmin: NativeSlateDBAdmin);
314
+ readManifest(id?: number): Promise<string | null>;
315
+ listManifests(start?: number, end?: number): Promise<string>;
316
+ readCompactions(id?: number): Promise<string | null>;
317
+ listCompactions(start?: number, end?: number): Promise<string>;
318
+ readCompaction(id: string, compactionsId?: number): Promise<string | null>;
319
+ submitCompaction(spec: CompactionSpec): Promise<string>;
320
+ createCheckpoint(options?: CheckpointOptions): Promise<CheckpointCreateResult>;
321
+ listCheckpoints(name?: string): Promise<Checkpoint[]>;
322
+ refreshCheckpoint(id: string, lifetimeMs?: number): Promise<void>;
323
+ deleteCheckpoint(id: string): Promise<void>;
324
+ getTimestampForSequence(seq: number, roundUp?: boolean): Promise<number | null>;
325
+ getSequenceForTimestamp(timestampMs: number, roundUp?: boolean): Promise<number | null>;
326
+ createClone(parentPath: string, parentCheckpoint?: string): Promise<void>;
327
+ runGcOnce(options?: GcOptions): Promise<void>;
328
+ runGc(options?: GcOptions): Promise<void>;
329
+ }
330
+ export declare class SlateDB {
331
+ private readonly native;
332
+ constructor(nativeDb: NativeSlateDB);
333
+ static open(options: SlateDBOpenOptions): Promise<SlateDB>;
334
+ get(key: Binary): Promise<Buffer | null>;
335
+ getWithOptions(key: Binary, options?: ReadOptions): Promise<Buffer | null>;
336
+ put(key: Binary, value: Binary): Promise<WriteHandle>;
337
+ putWithOptions(key: Binary, value: Binary, putOptions?: PutOptions, writeOptions?: WriteOptions): Promise<WriteHandle>;
338
+ delete(key: Binary): Promise<WriteHandle>;
339
+ deleteWithOptions(key: Binary, writeOptions?: WriteOptions): Promise<WriteHandle>;
340
+ merge(key: Binary, value: Binary): Promise<WriteHandle>;
341
+ mergeWithOptions(key: Binary, value: Binary, mergeOptions?: MergeOptions, writeOptions?: WriteOptions): Promise<WriteHandle>;
342
+ write(batch: WriteBatch): Promise<WriteHandle>;
343
+ writeWithOptions(batch: WriteBatch, writeOptions?: WriteOptions): Promise<WriteHandle>;
344
+ scan(start: Binary, end?: Binary): Promise<SlateDBIterator>;
345
+ scanWithOptions(start: Binary, end?: Binary, options?: ScanOptions): Promise<SlateDBIterator>;
346
+ scanPrefix(prefix: Binary): Promise<SlateDBIterator>;
347
+ scanPrefixWithOptions(prefix: Binary, options?: ScanOptions): Promise<SlateDBIterator>;
348
+ snapshot(): Promise<SlateDBSnapshot>;
349
+ begin(isolation?: "si" | "snapshot" | "ssi" | "serializable" | "serializable_snapshot"): Promise<SlateDBTransaction>;
350
+ flush(): Promise<void>;
351
+ flushWithOptions(flushType?: "wal" | "memtable"): Promise<void>;
352
+ metrics(): Promise<Record<string, number>>;
353
+ createCheckpoint(scope?: "all" | "durable", options?: CheckpointOptions): Promise<CheckpointCreateResult>;
354
+ status(): Promise<void>;
355
+ close(): Promise<void>;
356
+ }
357
+ export declare function open(options: SlateDBOpenOptions): Promise<SlateDB>;
358
+ export declare function openReader(options: SlateDBReaderOpenOptions): Promise<SlateDBReader>;
359
+ export declare function openAdmin(options: SlateDBAdminOpenOptions): Promise<SlateDBAdmin>;
360
+ export {};
package/lib/index.js ADDED
@@ -0,0 +1,458 @@
1
+ /* eslint-disable func-style, @typescript-eslint/consistent-type-definitions */
2
+ import { createRequire } from "node:module";
3
+ const require = createRequire(import.meta.url);
4
+ const native = require("../native.cjs");
5
+ function toBuffer(value) {
6
+ if (Buffer.isBuffer(value)) {
7
+ return value;
8
+ }
9
+ if (typeof value === "string") {
10
+ return Buffer.from(value);
11
+ }
12
+ return Buffer.from(value);
13
+ }
14
+ function mapError(error) {
15
+ const message = error instanceof Error ? error.message : String(error);
16
+ for (const [prefix, ErrorClass] of errorClassMap) {
17
+ if (message.startsWith(prefix)) {
18
+ return new ErrorClass(message.slice(prefix.length).trim(), error);
19
+ }
20
+ }
21
+ if (error instanceof Error) {
22
+ return error;
23
+ }
24
+ return new SlateDBError(message, error);
25
+ }
26
+ async function call(fn) {
27
+ try {
28
+ return await fn();
29
+ }
30
+ catch (error) {
31
+ throw mapError(error);
32
+ }
33
+ }
34
+ function mapWriteHandle(handle) {
35
+ return {
36
+ seq: handle.seq,
37
+ createTs: handle.createTs,
38
+ };
39
+ }
40
+ function mapCheckpointResult(result) {
41
+ return {
42
+ id: result.id,
43
+ manifestId: result.manifestId,
44
+ };
45
+ }
46
+ function mapCheckpoint(checkpoint) {
47
+ return {
48
+ id: checkpoint.id,
49
+ manifestId: checkpoint.manifestId,
50
+ expireTimeMs: checkpoint.expireTimeMs,
51
+ createTimeMs: checkpoint.createTimeMs,
52
+ name: checkpoint.name,
53
+ };
54
+ }
55
+ export class SlateDBError extends Error {
56
+ constructor(message, cause) {
57
+ super(message);
58
+ Object.defineProperty(this, "cause", {
59
+ enumerable: true,
60
+ configurable: true,
61
+ writable: true,
62
+ value: void 0
63
+ });
64
+ this.name = new.target.name;
65
+ this.cause = cause;
66
+ }
67
+ }
68
+ export class TransactionError extends SlateDBError {
69
+ }
70
+ export class ClosedError extends SlateDBError {
71
+ }
72
+ export class UnavailableError extends SlateDBError {
73
+ }
74
+ export class InvalidError extends SlateDBError {
75
+ }
76
+ export class DataError extends SlateDBError {
77
+ }
78
+ export class InternalError extends SlateDBError {
79
+ }
80
+ const errorClassMap = [
81
+ ["TransactionError:", TransactionError],
82
+ ["ClosedError:", ClosedError],
83
+ ["UnavailableError:", UnavailableError],
84
+ ["InvalidError:", InvalidError],
85
+ ["DataError:", DataError],
86
+ ["InternalError:", InternalError],
87
+ ];
88
+ export class SlateDBIterator {
89
+ constructor(nativeIterator) {
90
+ Object.defineProperty(this, "native", {
91
+ enumerable: true,
92
+ configurable: true,
93
+ writable: true,
94
+ value: void 0
95
+ });
96
+ this.native = nativeIterator;
97
+ }
98
+ async next() {
99
+ const kv = await call(() => this.native.next());
100
+ if (kv == null) {
101
+ return null;
102
+ }
103
+ return [kv.key, kv.value];
104
+ }
105
+ async seek(key) {
106
+ await call(() => this.native.seek(toBuffer(key)));
107
+ }
108
+ async close() {
109
+ await call(() => this.native.close());
110
+ }
111
+ [Symbol.asyncIterator]() {
112
+ return {
113
+ next: async () => {
114
+ const value = await this.next();
115
+ if (value == null) {
116
+ return {
117
+ done: true,
118
+ value: undefined,
119
+ };
120
+ }
121
+ return {
122
+ done: false,
123
+ value,
124
+ };
125
+ },
126
+ };
127
+ }
128
+ }
129
+ export class WriteBatch {
130
+ constructor() {
131
+ Object.defineProperty(this, "native", {
132
+ enumerable: true,
133
+ configurable: true,
134
+ writable: true,
135
+ value: void 0
136
+ });
137
+ this.native = new native.NativeWriteBatch();
138
+ }
139
+ put(key, value) {
140
+ this.native.put(toBuffer(key), toBuffer(value));
141
+ }
142
+ putWithOptions(key, value, options) {
143
+ this.native.putWithOptions(toBuffer(key), toBuffer(value), options);
144
+ }
145
+ delete(key) {
146
+ this.native.delete(toBuffer(key));
147
+ }
148
+ merge(key, value) {
149
+ this.native.merge(toBuffer(key), toBuffer(value));
150
+ }
151
+ mergeWithOptions(key, value, options) {
152
+ this.native.mergeWithOptions(toBuffer(key), toBuffer(value), options);
153
+ }
154
+ getNative() {
155
+ return this.native;
156
+ }
157
+ }
158
+ export class SlateDBSnapshot {
159
+ constructor(nativeSnapshot) {
160
+ Object.defineProperty(this, "native", {
161
+ enumerable: true,
162
+ configurable: true,
163
+ writable: true,
164
+ value: void 0
165
+ });
166
+ this.native = nativeSnapshot;
167
+ }
168
+ async get(key) {
169
+ return call(() => this.native.get(toBuffer(key)));
170
+ }
171
+ async getWithOptions(key, options) {
172
+ return call(() => this.native.getWithOptions(toBuffer(key), options));
173
+ }
174
+ async scan(start, end) {
175
+ const iterator = await call(() => this.native.scan(toBuffer(start), end == null ? undefined : toBuffer(end)));
176
+ return new SlateDBIterator(iterator);
177
+ }
178
+ async scanWithOptions(start, end, options) {
179
+ const iterator = await call(() => this.native.scanWithOptions(toBuffer(start), end == null ? undefined : toBuffer(end), options));
180
+ return new SlateDBIterator(iterator);
181
+ }
182
+ async scanPrefix(prefix) {
183
+ const iterator = await call(() => this.native.scanPrefix(toBuffer(prefix)));
184
+ return new SlateDBIterator(iterator);
185
+ }
186
+ async scanPrefixWithOptions(prefix, options) {
187
+ const iterator = await call(() => this.native.scanPrefixWithOptions(toBuffer(prefix), options));
188
+ return new SlateDBIterator(iterator);
189
+ }
190
+ async close() {
191
+ await call(() => this.native.close());
192
+ }
193
+ }
194
+ export class SlateDBTransaction {
195
+ constructor(nativeTransaction) {
196
+ Object.defineProperty(this, "native", {
197
+ enumerable: true,
198
+ configurable: true,
199
+ writable: true,
200
+ value: void 0
201
+ });
202
+ this.native = nativeTransaction;
203
+ }
204
+ async get(key) {
205
+ return call(() => this.native.get(toBuffer(key)));
206
+ }
207
+ async getWithOptions(key, options) {
208
+ return call(() => this.native.getWithOptions(toBuffer(key), options));
209
+ }
210
+ async scan(start, end) {
211
+ const iterator = await call(() => this.native.scan(toBuffer(start), end == null ? undefined : toBuffer(end)));
212
+ return new SlateDBIterator(iterator);
213
+ }
214
+ async scanWithOptions(start, end, options) {
215
+ const iterator = await call(() => this.native.scanWithOptions(toBuffer(start), end == null ? undefined : toBuffer(end), options));
216
+ return new SlateDBIterator(iterator);
217
+ }
218
+ async scanPrefix(prefix) {
219
+ const iterator = await call(() => this.native.scanPrefix(toBuffer(prefix)));
220
+ return new SlateDBIterator(iterator);
221
+ }
222
+ async scanPrefixWithOptions(prefix, options) {
223
+ const iterator = await call(() => this.native.scanPrefixWithOptions(toBuffer(prefix), options));
224
+ return new SlateDBIterator(iterator);
225
+ }
226
+ async put(key, value) {
227
+ await call(() => this.native.put(toBuffer(key), toBuffer(value)));
228
+ }
229
+ async putWithOptions(key, value, options) {
230
+ await call(() => this.native.putWithOptions(toBuffer(key), toBuffer(value), options));
231
+ }
232
+ async delete(key) {
233
+ await call(() => this.native.delete(toBuffer(key)));
234
+ }
235
+ async merge(key, value) {
236
+ await call(() => this.native.merge(toBuffer(key), toBuffer(value)));
237
+ }
238
+ async mergeWithOptions(key, value, options) {
239
+ await call(() => this.native.mergeWithOptions(toBuffer(key), toBuffer(value), options));
240
+ }
241
+ async markRead(keys) {
242
+ await call(() => this.native.markRead(keys.map(toBuffer)));
243
+ }
244
+ async unmarkWrite(keys) {
245
+ await call(() => this.native.unmarkWrite(keys.map(toBuffer)));
246
+ }
247
+ async commit(writeOptions) {
248
+ const handle = await call(() => this.native.commit(writeOptions));
249
+ return handle == null ? null : mapWriteHandle(handle);
250
+ }
251
+ async rollback() {
252
+ await call(() => this.native.rollback());
253
+ }
254
+ async close() {
255
+ await call(() => this.native.close());
256
+ }
257
+ }
258
+ export class SlateDBReader {
259
+ constructor(nativeReader) {
260
+ Object.defineProperty(this, "native", {
261
+ enumerable: true,
262
+ configurable: true,
263
+ writable: true,
264
+ value: void 0
265
+ });
266
+ this.native = nativeReader;
267
+ }
268
+ async get(key) {
269
+ return call(() => this.native.get(toBuffer(key)));
270
+ }
271
+ async getWithOptions(key, options) {
272
+ return call(() => this.native.getWithOptions(toBuffer(key), options));
273
+ }
274
+ async scan(start, end) {
275
+ const iterator = await call(() => this.native.scan(toBuffer(start), end == null ? undefined : toBuffer(end)));
276
+ return new SlateDBIterator(iterator);
277
+ }
278
+ async scanWithOptions(start, end, options) {
279
+ const iterator = await call(() => this.native.scanWithOptions(toBuffer(start), end == null ? undefined : toBuffer(end), options));
280
+ return new SlateDBIterator(iterator);
281
+ }
282
+ async scanPrefix(prefix) {
283
+ const iterator = await call(() => this.native.scanPrefix(toBuffer(prefix)));
284
+ return new SlateDBIterator(iterator);
285
+ }
286
+ async scanPrefixWithOptions(prefix, options) {
287
+ const iterator = await call(() => this.native.scanPrefixWithOptions(toBuffer(prefix), options));
288
+ return new SlateDBIterator(iterator);
289
+ }
290
+ async close() {
291
+ await call(() => this.native.close());
292
+ }
293
+ }
294
+ export class SlateDBAdmin {
295
+ constructor(nativeAdmin) {
296
+ Object.defineProperty(this, "native", {
297
+ enumerable: true,
298
+ configurable: true,
299
+ writable: true,
300
+ value: void 0
301
+ });
302
+ this.native = nativeAdmin;
303
+ }
304
+ async readManifest(id) {
305
+ return call(() => this.native.readManifest(id));
306
+ }
307
+ async listManifests(start, end) {
308
+ return call(() => this.native.listManifests(start, end));
309
+ }
310
+ async readCompactions(id) {
311
+ return call(() => this.native.readCompactions(id));
312
+ }
313
+ async listCompactions(start, end) {
314
+ return call(() => this.native.listCompactions(start, end));
315
+ }
316
+ async readCompaction(id, compactionsId) {
317
+ return call(() => this.native.readCompaction(id, compactionsId));
318
+ }
319
+ async submitCompaction(spec) {
320
+ return call(() => this.native.submitCompaction(spec));
321
+ }
322
+ async createCheckpoint(options) {
323
+ const result = await call(() => this.native.createCheckpoint(options));
324
+ return mapCheckpointResult(result);
325
+ }
326
+ async listCheckpoints(name) {
327
+ const checkpoints = await call(() => this.native.listCheckpoints(name));
328
+ return checkpoints.map(mapCheckpoint);
329
+ }
330
+ async refreshCheckpoint(id, lifetimeMs) {
331
+ await call(() => this.native.refreshCheckpoint(id, lifetimeMs));
332
+ }
333
+ async deleteCheckpoint(id) {
334
+ await call(() => this.native.deleteCheckpoint(id));
335
+ }
336
+ async getTimestampForSequence(seq, roundUp) {
337
+ return call(() => this.native.getTimestampForSequence(seq, roundUp));
338
+ }
339
+ async getSequenceForTimestamp(timestampMs, roundUp) {
340
+ return call(() => this.native.getSequenceForTimestamp(timestampMs, roundUp));
341
+ }
342
+ async createClone(parentPath, parentCheckpoint) {
343
+ await call(() => this.native.createClone(parentPath, parentCheckpoint));
344
+ }
345
+ async runGcOnce(options) {
346
+ await call(() => this.native.runGcOnce(options));
347
+ }
348
+ async runGc(options) {
349
+ await call(() => this.native.runGc(options));
350
+ }
351
+ }
352
+ export class SlateDB {
353
+ constructor(nativeDb) {
354
+ Object.defineProperty(this, "native", {
355
+ enumerable: true,
356
+ configurable: true,
357
+ writable: true,
358
+ value: void 0
359
+ });
360
+ this.native = nativeDb;
361
+ }
362
+ static async open(options) {
363
+ return open(options);
364
+ }
365
+ async get(key) {
366
+ return call(() => this.native.get(toBuffer(key)));
367
+ }
368
+ async getWithOptions(key, options) {
369
+ return call(() => this.native.getWithOptions(toBuffer(key), options));
370
+ }
371
+ async put(key, value) {
372
+ const handle = await call(() => this.native.put(toBuffer(key), toBuffer(value)));
373
+ return mapWriteHandle(handle);
374
+ }
375
+ async putWithOptions(key, value, putOptions, writeOptions) {
376
+ const handle = await call(() => this.native.putWithOptions(toBuffer(key), toBuffer(value), putOptions, writeOptions));
377
+ return mapWriteHandle(handle);
378
+ }
379
+ async delete(key) {
380
+ const handle = await call(() => this.native.delete(toBuffer(key)));
381
+ return mapWriteHandle(handle);
382
+ }
383
+ async deleteWithOptions(key, writeOptions) {
384
+ const handle = await call(() => this.native.deleteWithOptions(toBuffer(key), writeOptions));
385
+ return mapWriteHandle(handle);
386
+ }
387
+ async merge(key, value) {
388
+ const handle = await call(() => this.native.merge(toBuffer(key), toBuffer(value)));
389
+ return mapWriteHandle(handle);
390
+ }
391
+ async mergeWithOptions(key, value, mergeOptions, writeOptions) {
392
+ const handle = await call(() => this.native.mergeWithOptions(toBuffer(key), toBuffer(value), mergeOptions, writeOptions));
393
+ return mapWriteHandle(handle);
394
+ }
395
+ async write(batch) {
396
+ const handle = await call(() => this.native.write(batch.getNative()));
397
+ return mapWriteHandle(handle);
398
+ }
399
+ async writeWithOptions(batch, writeOptions) {
400
+ const handle = await call(() => this.native.writeWithOptions(batch.getNative(), writeOptions));
401
+ return mapWriteHandle(handle);
402
+ }
403
+ async scan(start, end) {
404
+ const iterator = await call(() => this.native.scan(toBuffer(start), end == null ? undefined : toBuffer(end)));
405
+ return new SlateDBIterator(iterator);
406
+ }
407
+ async scanWithOptions(start, end, options) {
408
+ const iterator = await call(() => this.native.scanWithOptions(toBuffer(start), end == null ? undefined : toBuffer(end), options));
409
+ return new SlateDBIterator(iterator);
410
+ }
411
+ async scanPrefix(prefix) {
412
+ const iterator = await call(() => this.native.scanPrefix(toBuffer(prefix)));
413
+ return new SlateDBIterator(iterator);
414
+ }
415
+ async scanPrefixWithOptions(prefix, options) {
416
+ const iterator = await call(() => this.native.scanPrefixWithOptions(toBuffer(prefix), options));
417
+ return new SlateDBIterator(iterator);
418
+ }
419
+ async snapshot() {
420
+ const snapshot = await call(() => this.native.snapshot());
421
+ return new SlateDBSnapshot(snapshot);
422
+ }
423
+ async begin(isolation) {
424
+ const txn = await call(() => this.native.begin(isolation));
425
+ return new SlateDBTransaction(txn);
426
+ }
427
+ async flush() {
428
+ await call(() => this.native.flush());
429
+ }
430
+ async flushWithOptions(flushType) {
431
+ await call(() => this.native.flushWithOptions(flushType));
432
+ }
433
+ async metrics() {
434
+ return call(() => this.native.metrics());
435
+ }
436
+ async createCheckpoint(scope, options) {
437
+ const result = await call(() => this.native.createCheckpoint(scope, options));
438
+ return mapCheckpointResult(result);
439
+ }
440
+ async status() {
441
+ await call(() => this.native.status());
442
+ }
443
+ async close() {
444
+ await call(() => this.native.close());
445
+ }
446
+ }
447
+ export async function open(options) {
448
+ const db = await call(() => native.openNative(options));
449
+ return new SlateDB(db);
450
+ }
451
+ export async function openReader(options) {
452
+ const reader = await call(() => native.openReaderNative(options));
453
+ return new SlateDBReader(reader);
454
+ }
455
+ export async function openAdmin(options) {
456
+ const admin = await call(() => native.openAdminNative(options));
457
+ return new SlateDBAdmin(admin);
458
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slatedb-node",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Node.js bindings for SlateDB via napi-rs",
5
5
  "homepage": "https://github.com/gadget-inc/slatedb-node",
6
6
  "bugs": {
@@ -50,9 +50,11 @@
50
50
  "test": "pnpm run build:debug && pnpm run build:ts && vitest run"
51
51
  },
52
52
  "devDependencies": {
53
+ "@arethetypeswrong/cli": "^0.18.2",
53
54
  "@napi-rs/cli": "^3.2.0",
54
55
  "@types/node": "^24.5.2",
55
56
  "cspell": "^9.6.4",
57
+ "execa": "^5.1.1",
56
58
  "oxfmt": "^0.32.0",
57
59
  "oxlint": "^1.49.0",
58
60
  "oxlint-tsgolint": "^0.14.1",
@@ -85,13 +87,13 @@
85
87
  }
86
88
  },
87
89
  "optionalDependencies": {
88
- "slatedb-node-darwin-x64": "0.1.0",
89
- "slatedb-node-darwin-arm64": "0.1.0",
90
- "slatedb-node-win32-x64-msvc": "0.1.0",
91
- "slatedb-node-win32-arm64-msvc": "0.1.0",
92
- "slatedb-node-linux-x64-gnu": "0.1.0",
93
- "slatedb-node-linux-x64-musl": "0.1.0",
94
- "slatedb-node-linux-arm64-gnu": "0.1.0",
95
- "slatedb-node-linux-arm64-musl": "0.1.0"
90
+ "slatedb-node-darwin-x64": "0.1.1",
91
+ "slatedb-node-darwin-arm64": "0.1.1",
92
+ "slatedb-node-win32-x64-msvc": "0.1.1",
93
+ "slatedb-node-win32-arm64-msvc": "0.1.1",
94
+ "slatedb-node-linux-x64-gnu": "0.1.1",
95
+ "slatedb-node-linux-x64-musl": "0.1.1",
96
+ "slatedb-node-linux-arm64-gnu": "0.1.1",
97
+ "slatedb-node-linux-arm64-musl": "0.1.1"
96
98
  }
97
99
  }