polystore 0.11.4 → 0.11.5
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/readme.md +14 -3
- package/src/index.d.ts +25 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polystore",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.5",
|
|
4
4
|
"description": "A small compatibility layer for many popular KV stores like localStorage, Redis, FileSystem, etc.",
|
|
5
5
|
"homepage": "https://polystore.dev/",
|
|
6
6
|
"repository": "https://github.com/franciscop/polystore.git",
|
package/readme.md
CHANGED
|
@@ -249,18 +249,29 @@ You can iterate over the whole store with an async iterator:
|
|
|
249
249
|
|
|
250
250
|
```js
|
|
251
251
|
for await (const [key, value] of store) {
|
|
252
|
-
|
|
252
|
+
console.log(key, value);
|
|
253
253
|
}
|
|
254
254
|
```
|
|
255
255
|
|
|
256
|
-
This is very useful for performance resons.
|
|
256
|
+
This is very useful for performance resons since it will retrieve the data sequentially, avoiding blocking the client while retrieving it all at once. The main disadvantage is if you keep writing data while the async iterator is running.
|
|
257
|
+
|
|
258
|
+
You can also iterate on a subset of the entries with `.prefix()` (the prefix is stripped from the key here, see [.`prefix()`](#prefix)):
|
|
257
259
|
|
|
258
260
|
```js
|
|
261
|
+
const session = store.prefix("session:");
|
|
262
|
+
for await (const [key, value] of session) {
|
|
263
|
+
console.log(key, value);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Same as this (both have the prefix stripped):
|
|
267
|
+
|
|
259
268
|
for await (const [key, value] of store.prefix("session:")) {
|
|
260
|
-
|
|
269
|
+
console.log(key, value);
|
|
261
270
|
}
|
|
262
271
|
```
|
|
263
272
|
|
|
273
|
+
There are also methods to retrieve all of the keys, values, or entries at once below, but those [have worse performance](#performance).
|
|
274
|
+
|
|
264
275
|
### .keys()
|
|
265
276
|
|
|
266
277
|
Get all of the keys in the store, optionally filtered by a prefix:
|
package/src/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
type Options = { expires?: number | string | null };
|
|
2
|
-
type Value =
|
|
1
|
+
export type Options = { expires?: number | string | null };
|
|
2
|
+
export type Value = string | { [key: string]: Value } | Value[];
|
|
3
3
|
|
|
4
|
-
interface Store {
|
|
4
|
+
export interface Store {
|
|
5
5
|
/**
|
|
6
6
|
* Save the data on an autogenerated key, can add expiration as well:
|
|
7
7
|
*
|
|
@@ -13,7 +13,7 @@ interface Store {
|
|
|
13
13
|
*
|
|
14
14
|
* **[→ Full .add() Docs](https://polystore.dev/documentation#add)**
|
|
15
15
|
*/
|
|
16
|
-
add: (value:
|
|
16
|
+
add: <T = Value>(value: T, options?: Options) => Promise<string>;
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Save the data on the given key, can add expiration as well:
|
|
@@ -26,7 +26,7 @@ interface Store {
|
|
|
26
26
|
*
|
|
27
27
|
* **[→ Full .set() Docs](https://polystore.dev/documentation#set)**
|
|
28
28
|
*/
|
|
29
|
-
set: (key: string, value:
|
|
29
|
+
set: <T = Value>(key: string, value: T, options?: Options) => Promise<string>;
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* Read a single value from the KV store:
|
|
@@ -42,7 +42,7 @@ interface Store {
|
|
|
42
42
|
*
|
|
43
43
|
* **[→ Full .get() Docs](https://polystore.dev/documentation#get)**
|
|
44
44
|
*/
|
|
45
|
-
get: (key: string) => Promise<
|
|
45
|
+
get: <T = Value>(key: string) => Promise<T | null>;
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* Check whether a key exists or not:
|
|
@@ -72,7 +72,7 @@ interface Store {
|
|
|
72
72
|
*
|
|
73
73
|
* **[→ Full .del() Docs](https://polystore.dev/documentation#del)**
|
|
74
74
|
*/
|
|
75
|
-
del: (key: string) => Promise<
|
|
75
|
+
del: (key: string) => Promise<string>;
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
78
|
* Return an array of the entries, in the [key, value] format:
|
|
@@ -87,7 +87,7 @@ interface Store {
|
|
|
87
87
|
*
|
|
88
88
|
* **[→ Full .entries() Docs](https://polystore.dev/documentation#entries)**
|
|
89
89
|
*/
|
|
90
|
-
entries: () => Promise<[key: string, value:
|
|
90
|
+
entries: <T = Value>() => Promise<[key: string, value: T][]>;
|
|
91
91
|
|
|
92
92
|
/**
|
|
93
93
|
* Return an array of the keys in the store:
|
|
@@ -117,7 +117,7 @@ interface Store {
|
|
|
117
117
|
*
|
|
118
118
|
* **[→ Full .values() Docs](https://polystore.dev/documentation#values)**
|
|
119
119
|
*/
|
|
120
|
-
values: () => Promise<
|
|
120
|
+
values: <T = Value>() => Promise<T[]>;
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
123
|
* Return an object with the keys:values in the store:
|
|
@@ -132,7 +132,7 @@ interface Store {
|
|
|
132
132
|
*
|
|
133
133
|
* **[→ Full .all() Docs](https://polystore.dev/documentation#all)**
|
|
134
134
|
*/
|
|
135
|
-
all: () => Promise<{ [key: string]:
|
|
135
|
+
all: <T = Value>() => Promise<{ [key: string]: T }>;
|
|
136
136
|
|
|
137
137
|
/**
|
|
138
138
|
* Delete all of the records of the store:
|
|
@@ -176,6 +176,21 @@ interface Store {
|
|
|
176
176
|
* **[→ Full .close() Docs](https://polystore.dev/documentation#close)**
|
|
177
177
|
*/
|
|
178
178
|
close?: () => Promise<null>;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* An iterator that goes through all of the key:value pairs in the client
|
|
182
|
+
*
|
|
183
|
+
* ```js
|
|
184
|
+
* for await (const [key, value] of store) {
|
|
185
|
+
* console.log(key, value);
|
|
186
|
+
* }
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* **[→ Full Iterator Docs](https://polystore.dev/documentation#iterator)**
|
|
190
|
+
*/
|
|
191
|
+
[Symbol.asyncIterator]: () => {
|
|
192
|
+
next: () => Promise<{ value: [string, Value] }>;
|
|
193
|
+
};
|
|
179
194
|
}
|
|
180
195
|
|
|
181
196
|
export default function (store?: any): Store;
|