polystore 0.9.1 → 0.9.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/assets/home.html +5 -3
- package/package.json +1 -1
- package/readme.md +12 -0
- package/src/index.js +7 -8
- package/src/index.test.js +1 -1
package/assets/home.html
CHANGED
|
@@ -18,13 +18,15 @@
|
|
|
18
18
|
>
|
|
19
19
|
</div>
|
|
20
20
|
</div>
|
|
21
|
-
<div style="width:
|
|
21
|
+
<div style="width: 570px; max-width: 100%">
|
|
22
22
|
<pre><code class="language-js">import kv from "polystore";
|
|
23
|
+
import { createClient } from "redis";
|
|
23
24
|
|
|
24
|
-
const
|
|
25
|
+
const REDIS = process.env.REDIS_URL;
|
|
26
|
+
const store = kv(createClient(REDIS));
|
|
25
27
|
|
|
26
28
|
await store.set("key1", { hello: "world" });
|
|
27
|
-
|
|
29
|
+
console.log(await store.get("key1"));
|
|
28
30
|
// { hello: "world" }</code></pre>
|
|
29
31
|
</div>
|
|
30
32
|
</section>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polystore",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "A small compatibility layer for many popular KV stores like localStorage, Redis, FileSystem, etc.",
|
|
5
5
|
"homepage": "https://github.com/franciscop/polystore",
|
|
6
6
|
"repository": "https://github.com/franciscop/polystore.git",
|
package/readme.md
CHANGED
|
@@ -67,6 +67,18 @@ const store = kv(MyClientOrStoreInstance);
|
|
|
67
67
|
// use the store
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
+
If the instance you pass contains a `connect()` or `open()` method, polystore **will** call that without any argument:
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
// Simpler
|
|
74
|
+
const store = kv(createClient());
|
|
75
|
+
|
|
76
|
+
// NO NEED
|
|
77
|
+
const client = createClient();
|
|
78
|
+
client.connect();
|
|
79
|
+
const store = kv(client);
|
|
80
|
+
```
|
|
81
|
+
|
|
70
82
|
While you can keep a reference to the store and access it directly, we strongly recommend if you are going to use a store, to only access it through `polystore`, since we do add custom serialization and extra properties for e.g. expiration time:
|
|
71
83
|
|
|
72
84
|
```js
|
package/src/index.js
CHANGED
|
@@ -32,14 +32,11 @@ class Store {
|
|
|
32
32
|
|
|
33
33
|
constructor(clientPromise = new Map()) {
|
|
34
34
|
this.promise = Promise.resolve(clientPromise).then(async (client) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (this.client.connect) {
|
|
41
|
-
await this.client.connect();
|
|
42
|
-
}
|
|
35
|
+
if (client?.open) await client.open();
|
|
36
|
+
if (client?.connect) await client.connect();
|
|
37
|
+
client = getClient(client);
|
|
38
|
+
this.#validate(client);
|
|
39
|
+
this.client = client;
|
|
43
40
|
this.promise = null;
|
|
44
41
|
return client;
|
|
45
42
|
});
|
|
@@ -309,6 +306,8 @@ class Store {
|
|
|
309
306
|
}
|
|
310
307
|
|
|
311
308
|
async close() {
|
|
309
|
+
await this.promise;
|
|
310
|
+
|
|
312
311
|
if (this.client.close) {
|
|
313
312
|
return this.client.close();
|
|
314
313
|
}
|
package/src/index.test.js
CHANGED
|
@@ -27,7 +27,7 @@ stores.push([`kv("cookie")`, kv("cookie")]);
|
|
|
27
27
|
stores.push(["kv(new KVNamespace())", kv(new KVNamespace())]);
|
|
28
28
|
stores.push([`kv(new Level("data"))`, kv(new Level("data"))]);
|
|
29
29
|
if (process.env.REDIS) {
|
|
30
|
-
stores.push(["kv(redis)", kv(createClient()
|
|
30
|
+
stores.push(["kv(redis)", kv(createClient())]);
|
|
31
31
|
}
|
|
32
32
|
if (process.env.ETCD) {
|
|
33
33
|
stores.push(["kv(new Etcd3())", kv(new Etcd3())]);
|