keyv 4.2.1 → 4.2.2
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/package.json +1 -1
- package/src/index.d.ts +68 -9
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -1,23 +1,82 @@
|
|
|
1
1
|
import {EventEmitter} from 'events';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
type WithRequiredProperties<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
4
|
+
|
|
5
|
+
declare class Keyv<Value = any, Options extends Record<string, any> = Record<string, unknown>> extends EventEmitter {
|
|
6
|
+
/**
|
|
7
|
+
* `this.opts` is an object containing at least the properties listed
|
|
8
|
+
* below. However, `Keyv.Options` allows arbitrary properties as well.
|
|
9
|
+
* These properties can be specified as the second type parameter to `Keyv`.
|
|
10
|
+
*/
|
|
11
|
+
opts: WithRequiredProperties<
|
|
12
|
+
Keyv.Options<Value>,
|
|
13
|
+
'deserialize' | 'namespace' | 'serialize' | 'store' | 'uri'
|
|
14
|
+
> &
|
|
15
|
+
Options;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param opts The options object is also passed through to the storage adapter. Check your storage adapter docs for any extra options.
|
|
19
|
+
*/
|
|
20
|
+
constructor(options?: Keyv.Options<Value> & Options);
|
|
21
|
+
/**
|
|
22
|
+
* @param uri The connection string URI.
|
|
23
|
+
*
|
|
24
|
+
* Merged into the options object as options.uri.
|
|
25
|
+
* @param opts The options object is also passed through to the storage adapter. Check your storage adapter docs for any extra options.
|
|
26
|
+
*/
|
|
27
|
+
constructor(uri?: string, options?: Keyv.Options<Value> & Options);
|
|
28
|
+
|
|
29
|
+
/** Returns the value. */
|
|
30
|
+
get<Raw extends boolean = false>(key: string, options?: {raw?: Raw}):
|
|
31
|
+
Promise<(Raw extends false
|
|
32
|
+
? Value
|
|
33
|
+
: Keyv.DeserializedData<Value>) | undefined>;
|
|
34
|
+
/**
|
|
35
|
+
* Set a value.
|
|
36
|
+
*
|
|
37
|
+
* By default keys are persistent. You can set an expiry TTL in milliseconds.
|
|
38
|
+
*/
|
|
39
|
+
set(key: string, value: Value, ttl?: number): Promise<true>;
|
|
40
|
+
/**
|
|
41
|
+
* Deletes an entry.
|
|
42
|
+
*
|
|
43
|
+
* Returns `true` if the key existed, `false` if not.
|
|
44
|
+
*/
|
|
7
45
|
delete(key: string): Promise<boolean>;
|
|
46
|
+
/** Delete all entries in the current namespace. */
|
|
8
47
|
clear(): Promise<void>;
|
|
9
|
-
has(key: string): Promise<boolean>;
|
|
10
48
|
}
|
|
11
49
|
|
|
12
50
|
declare namespace Keyv {
|
|
13
|
-
interface Options {
|
|
51
|
+
interface Options<Value> {
|
|
52
|
+
[key: string]: any;
|
|
53
|
+
|
|
54
|
+
/** Namespace for the current instance. */
|
|
14
55
|
namespace?: string | undefined;
|
|
15
|
-
|
|
16
|
-
|
|
56
|
+
/** A custom serialization function. */
|
|
57
|
+
serialize?: ((data: DeserializedData<Value>) => string) | undefined;
|
|
58
|
+
/** A custom deserialization function. */
|
|
59
|
+
deserialize?: ((data: string) => DeserializedData<Value> | undefined) | undefined;
|
|
60
|
+
/** The connection string URI. */
|
|
61
|
+
uri?: string | undefined;
|
|
62
|
+
/** The storage adapter instance to be used by Keyv. */
|
|
63
|
+
store?: Store<Value> | undefined;
|
|
64
|
+
/** Default TTL. Can be overridden by specififying a TTL on `.set()`. */
|
|
17
65
|
ttl?: number | undefined;
|
|
66
|
+
/** Specify an adapter to use. e.g `'redis'` or `'mongodb'`. */
|
|
67
|
+
adapter?: 'redis' | 'mongodb' | 'mongo' | 'sqlite' | 'postgresql' | 'postgres' | 'mysql' | undefined;
|
|
18
68
|
}
|
|
19
69
|
|
|
20
|
-
|
|
70
|
+
interface DeserializedData<Value> {
|
|
71
|
+
value: Value; expires: number | undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface Store<Value> {
|
|
75
|
+
get(key: string): Value | Promise<Value | undefined> | undefined;
|
|
76
|
+
set(key: string, value: Value, ttl?: number): any;
|
|
77
|
+
delete(key: string): boolean | Promise<boolean>;
|
|
78
|
+
clear(): void | Promise<void>;
|
|
79
|
+
}
|
|
21
80
|
}
|
|
22
81
|
|
|
23
82
|
export = Keyv;
|