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 CHANGED
@@ -18,13 +18,15 @@
18
18
  >
19
19
  </div>
20
20
  </div>
21
- <div style="width: 550px; max-width: 100%">
21
+ <div style="width: 570px; max-width: 100%">
22
22
  <pre><code class="language-js">import kv from &quot;polystore&quot;;
23
+ import { createClient } from "redis";
23
24
 
24
- const store = kv(new Map());
25
+ const REDIS = process.env.REDIS_URL;
26
+ const store = kv(createClient(REDIS));
25
27
 
26
28
  await store.set(&quot;key1&quot;, { hello: &quot;world&quot; });
27
- const value = await store.get(&quot;key1&quot;);
29
+ console.log(await store.get(&quot;key1&quot;));
28
30
  // { hello: &quot;world&quot; }</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.1",
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
- this.client = getClient(client);
36
- this.#validate(this.client);
37
- if (this.client.open) {
38
- await this.client.open();
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().connect())]);
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())]);