polystore 0.18.0 → 0.20.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.
- package/index.d.ts +60 -27
- package/index.js +216 -78
- package/package.json +14 -2
- package/readme.md +229 -172
- package/src/express.js +47 -0
package/index.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
type Prefix = string;
|
|
1
2
|
type Expires = number | null | string;
|
|
3
|
+
type Options = {
|
|
4
|
+
prefix?: Prefix;
|
|
5
|
+
expires?: Expires;
|
|
6
|
+
};
|
|
2
7
|
type StoreData<T extends Serializable = Serializable> = {
|
|
3
8
|
value: T;
|
|
4
9
|
expires: number | null;
|
|
@@ -8,7 +13,7 @@ type Serializable = string | number | boolean | null | (Serializable | null)[] |
|
|
|
8
13
|
};
|
|
9
14
|
interface ClientExpires {
|
|
10
15
|
TYPE: string;
|
|
11
|
-
|
|
16
|
+
HAS_EXPIRATION: true;
|
|
12
17
|
promise?: Promise<any>;
|
|
13
18
|
test?: (client: any) => boolean;
|
|
14
19
|
get<T extends Serializable>(key: string): Promise<T | null> | T | null;
|
|
@@ -27,7 +32,7 @@ interface ClientExpires {
|
|
|
27
32
|
}
|
|
28
33
|
interface ClientNonExpires {
|
|
29
34
|
TYPE: string;
|
|
30
|
-
|
|
35
|
+
HAS_EXPIRATION: false;
|
|
31
36
|
promise?: Promise<any>;
|
|
32
37
|
test?: (client: any) => boolean;
|
|
33
38
|
get<T extends Serializable>(key: string): Promise<StoreData<T> | null> | StoreData<T> | null;
|
|
@@ -40,19 +45,21 @@ interface ClientNonExpires {
|
|
|
40
45
|
values?<T extends Serializable>(prefix: string): Promise<StoreData<T>[]> | StoreData<T>[];
|
|
41
46
|
entries?<T extends Serializable>(prefix: string): Promise<[string, StoreData<T>][]> | [string, StoreData<T>][];
|
|
42
47
|
all?<T extends Serializable>(prefix: string): Promise<Record<string, StoreData<T>>> | Record<string, StoreData<T>>;
|
|
48
|
+
prune?(): Promise<any> | any;
|
|
43
49
|
clear?(prefix: string): Promise<any> | any;
|
|
44
50
|
clearAll?(): Promise<any> | any;
|
|
45
51
|
close?(): Promise<any> | any;
|
|
46
52
|
}
|
|
47
53
|
type Client = ClientExpires | ClientNonExpires;
|
|
48
54
|
|
|
49
|
-
declare class Store<
|
|
55
|
+
declare class Store<TD extends Serializable = Serializable> {
|
|
50
56
|
#private;
|
|
51
|
-
PREFIX:
|
|
57
|
+
PREFIX: Prefix;
|
|
58
|
+
EXPIRES: Expires;
|
|
52
59
|
promise: Promise<Client> | null;
|
|
53
60
|
client: Client;
|
|
54
61
|
type: string;
|
|
55
|
-
constructor(clientPromise?: any);
|
|
62
|
+
constructor(clientPromise?: any, options?: Options);
|
|
56
63
|
/**
|
|
57
64
|
* Save the data on an autogenerated key, can add expiration as well:
|
|
58
65
|
*
|
|
@@ -64,8 +71,8 @@ declare class Store<TDefault extends Serializable = Serializable> {
|
|
|
64
71
|
*
|
|
65
72
|
* **[→ Full .add() Docs](https://polystore.dev/documentation#add)**
|
|
66
73
|
*/
|
|
67
|
-
add(value:
|
|
68
|
-
add<T extends
|
|
74
|
+
add(value: TD, options?: Options): Promise<string>;
|
|
75
|
+
add<T extends TD>(value: T, options?: Options): Promise<string>;
|
|
69
76
|
/**
|
|
70
77
|
* Save the data on the given key, can add expiration as well:
|
|
71
78
|
*
|
|
@@ -77,8 +84,8 @@ declare class Store<TDefault extends Serializable = Serializable> {
|
|
|
77
84
|
*
|
|
78
85
|
* **[→ Full .set() Docs](https://polystore.dev/documentation#set)**
|
|
79
86
|
*/
|
|
80
|
-
set(key: string, value:
|
|
81
|
-
set<T extends
|
|
87
|
+
set(key: string, value: TD, options?: Options): Promise<string>;
|
|
88
|
+
set<T extends TD>(key: string, value: T, options?: Options): Promise<string>;
|
|
82
89
|
/**
|
|
83
90
|
* Read a single value from the KV store:
|
|
84
91
|
*
|
|
@@ -93,8 +100,8 @@ declare class Store<TDefault extends Serializable = Serializable> {
|
|
|
93
100
|
*
|
|
94
101
|
* **[→ Full .get() Docs](https://polystore.dev/documentation#get)**
|
|
95
102
|
*/
|
|
96
|
-
get(key: string): Promise<
|
|
97
|
-
get<T extends
|
|
103
|
+
get(key: string): Promise<TD | null>;
|
|
104
|
+
get<T extends TD>(key: string): Promise<T | null>;
|
|
98
105
|
/**
|
|
99
106
|
* Check whether a key exists or not:
|
|
100
107
|
*
|
|
@@ -144,8 +151,8 @@ declare class Store<TDefault extends Serializable = Serializable> {
|
|
|
144
151
|
*
|
|
145
152
|
* **[→ Full Iterator Docs](https://polystore.dev/documentation#iterator)**
|
|
146
153
|
*/
|
|
147
|
-
[Symbol.asyncIterator](): AsyncGenerator<[string,
|
|
148
|
-
[Symbol.asyncIterator]<T extends
|
|
154
|
+
[Symbol.asyncIterator](): AsyncGenerator<[string, TD], void, unknown>;
|
|
155
|
+
[Symbol.asyncIterator]<T extends TD>(): AsyncGenerator<[
|
|
149
156
|
string,
|
|
150
157
|
T
|
|
151
158
|
], void, unknown>;
|
|
@@ -162,8 +169,8 @@ declare class Store<TDefault extends Serializable = Serializable> {
|
|
|
162
169
|
*
|
|
163
170
|
* **[→ Full .entries() Docs](https://polystore.dev/documentation#entries)**
|
|
164
171
|
*/
|
|
165
|
-
entries(): Promise<[string,
|
|
166
|
-
entries<T extends
|
|
172
|
+
entries(): Promise<[string, TD][]>;
|
|
173
|
+
entries<T extends TD>(): Promise<[string, T][]>;
|
|
167
174
|
/**
|
|
168
175
|
* Return an array of the keys in the store:
|
|
169
176
|
*
|
|
@@ -191,8 +198,8 @@ declare class Store<TDefault extends Serializable = Serializable> {
|
|
|
191
198
|
*
|
|
192
199
|
* **[→ Full .values() Docs](https://polystore.dev/documentation#values)**
|
|
193
200
|
*/
|
|
194
|
-
values(): Promise<
|
|
195
|
-
values<T extends
|
|
201
|
+
values(): Promise<TD[]>;
|
|
202
|
+
values<T extends TD>(): Promise<T[]>;
|
|
196
203
|
/**
|
|
197
204
|
* Return an object with the keys:values in the store:
|
|
198
205
|
*
|
|
@@ -206,20 +213,24 @@ declare class Store<TDefault extends Serializable = Serializable> {
|
|
|
206
213
|
*
|
|
207
214
|
* **[→ Full .all() Docs](https://polystore.dev/documentation#all)**
|
|
208
215
|
*/
|
|
209
|
-
all(): Promise<Record<string,
|
|
210
|
-
all<T extends
|
|
216
|
+
all(): Promise<Record<string, TD>>;
|
|
217
|
+
all<T extends TD>(): Promise<Record<string, T>>;
|
|
211
218
|
/**
|
|
212
|
-
*
|
|
219
|
+
* Create a substore where all the keys are stored with
|
|
220
|
+
* the given prefix:
|
|
213
221
|
*
|
|
214
222
|
* ```js
|
|
215
|
-
*
|
|
223
|
+
* const session = store.prefix("session:");
|
|
224
|
+
* await session.set("key1", "value1");
|
|
225
|
+
* console.log(await session.entries()); // session.
|
|
226
|
+
* // [["key1", "value1"]]
|
|
227
|
+
* console.log(await store.entries()); // store.
|
|
228
|
+
* // [["session:key1", "value1"]]
|
|
216
229
|
* ```
|
|
217
230
|
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
* **[→ Full .clear() Docs](https://polystore.dev/documentation#clear)**
|
|
231
|
+
* **[→ Full .prefix() Docs](https://polystore.dev/documentation#prefix)**
|
|
221
232
|
*/
|
|
222
|
-
|
|
233
|
+
prefix(prefix?: Prefix): Store<TD>;
|
|
223
234
|
/**
|
|
224
235
|
* Create a substore where all the keys are stored with
|
|
225
236
|
* the given prefix:
|
|
@@ -235,7 +246,29 @@ declare class Store<TDefault extends Serializable = Serializable> {
|
|
|
235
246
|
*
|
|
236
247
|
* **[→ Full .prefix() Docs](https://polystore.dev/documentation#prefix)**
|
|
237
248
|
*/
|
|
238
|
-
|
|
249
|
+
expires(expires?: Expires): Store<TD>;
|
|
250
|
+
/**
|
|
251
|
+
* Delete all of the records of the store:
|
|
252
|
+
*
|
|
253
|
+
* ```js
|
|
254
|
+
* await store.clear();
|
|
255
|
+
* ```
|
|
256
|
+
*
|
|
257
|
+
* It's useful for cache invalidation, clearing the data, and testing.
|
|
258
|
+
*
|
|
259
|
+
* **[→ Full .clear() Docs](https://polystore.dev/documentation#clear)**
|
|
260
|
+
*/
|
|
261
|
+
clear(): Promise<void>;
|
|
262
|
+
/**
|
|
263
|
+
* Remove all expired records from the store.
|
|
264
|
+
*
|
|
265
|
+
* ```js
|
|
266
|
+
* await store.prune();
|
|
267
|
+
* ```
|
|
268
|
+
*
|
|
269
|
+
* Only affects stores where expiration is managed by this wrapper.
|
|
270
|
+
*/
|
|
271
|
+
prune(): Promise<void>;
|
|
239
272
|
/**
|
|
240
273
|
* Stop the connection to the store, if any:
|
|
241
274
|
*
|
|
@@ -250,6 +283,6 @@ declare class Store<TDefault extends Serializable = Serializable> {
|
|
|
250
283
|
close(): Promise<void>;
|
|
251
284
|
}
|
|
252
285
|
declare function createStore(): Store<Serializable>;
|
|
253
|
-
declare function createStore<T extends Serializable = Serializable>(client?: any): Store<T>;
|
|
286
|
+
declare function createStore<T extends Serializable = Serializable>(client?: any, options?: Options): Store<T>;
|
|
254
287
|
|
|
255
288
|
export { type Client, type Serializable, Store, createStore as default };
|