-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
74 lines (65 loc) · 2.24 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
declare module 'native-keyshare' {
interface SetOptions {
immutable?: boolean;
minBufferSize?: number;
ttl?: number | undefined;
skipLock?: boolean;
}
// Shared key-value store interface
interface ISharedKVStore {
/**
* Sets a key-value pair in the store.
* @param key - The key to set.
* @param value - The value to associate with the key.
* @param options - Optional SetOptions.
* @returns `true` if the operation is successful, otherwise `false`.
*/
set(key: string, value: any, options: SetOptions = {}): boolean;
/**
* Gets the value associated with a key.
* @param key - The key to retrieve.
* @param skipLock - Optional boolean if skip the lock.
* @returns The associated value, or `undefined` if the key does not exist.
*/
get<T = any>(key: string, skipLock = false): T | undefined;
/**
* Deletes a key-value pair from the store.
* @param key - The key to delete.
* @returns `true` if the key was deleted, otherwise `false`.
*/
delete(key: string): boolean;
/**
* List all keys in store.
* @param pattern - Optional pattern.
* @returns array of keys.
*/
listKeys(pattern?: string): string[];
/**
* Lock a key in store.
* @param key - The key to lock.
* @param timeout - Optional timeout (in ms. defualt 1000).
* @returns true if locked.
*/
lock(key: string, timeout: number = 1000): boolean;
/**
* Release locked key in store.
* @param key - Release a lock.
* @returns true if released.
*/
release(key: string): boolean;
/**
* Clear the store.
*/
clear(): void;
/**
* Close the store. cleanup local maps and buffer references.
*/
close(): void;
}
/**
* Creates a new shared key-value store.
* @param parentPort - The parent port for the worker thread.
* @returns An instance of `ISharedKVStore`.
*/
export function createStore(parentPort?: MessagePort | null): ISharedKVStore;
}