polystore 0.9.0 → 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>
@@ -150,7 +152,7 @@ const value = await store.get(&quot;key1&quot;);
150
152
  <p>
151
153
  At
152
154
  <a href="https://bundlephobia.com/package/polystore" target="_blank"
153
- >just <strong>2.4b</strong></a
155
+ >just <strong>2.4kb</strong></a
154
156
  >
155
157
  (min+gzip), the impact on your app loading time is minimal.
156
158
  </p>
@@ -304,16 +306,14 @@ console.log(await store.entries());
304
306
  </div>
305
307
  </div>
306
308
  <div>
307
- <pre><code class="language-js">import kv from "polystore";
308
- const store = kv(new Map());
309
+ <pre><code class="language-js">await store.get("key"); // null
309
310
 
310
- const auth = store.prefix(&quot;auth:&quot;);
311
- auth.set(&quot;key1&quot;, &quot;value1&quot;);
312
- console.log(await auth.entries());
313
- // [[&quot;key1&quot;, &quot;value1&quot;]]
311
+ await store.set("key", "value", { expires: "1s" });
312
+ await store.get("key"); // "value"
314
313
 
315
- console.log(await store.entries());
316
- // [[&quot;auth:key1&quot;, &quot;value1&quot;]]</code></pre>
314
+ await sleep(2000);
315
+
316
+ await store.get("key"); // null</code></pre>
317
317
  </div>
318
318
  </section>
319
319
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polystore",
3
- "version": "0.9.0",
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,10 +306,12 @@ 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
  }
315
314
  }
316
315
  }
317
316
 
318
- export default kv = (client) => new Store(client);
317
+ export default (client) => new Store(client);
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())]);