polystore 0.15.11 → 0.15.12
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 +3 -3
- package/src/server.js +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polystore",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.12",
|
|
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
|
@@ -36,8 +36,8 @@ Available clients for the KV store:
|
|
|
36
36
|
- [**Cookies** `"cookie"`](#cookies) (fe): persist the data using cookies
|
|
37
37
|
- [**LocalForage** `localForage`](#local-forage) (fe): persist the data on IndexedDB
|
|
38
38
|
- [**Fetch API** `"https://..."`](#fetch-api) (fe+be): call an API to save/retrieve the data
|
|
39
|
-
- [**File** `
|
|
40
|
-
- [**Folder** `
|
|
39
|
+
- [**File** `"file:///[...].json"`](#file) (be): store the data in a single JSON file in your FS
|
|
40
|
+
- [**Folder** `"file:///[...]/"`](#folder) (be): store each key in a folder as json files
|
|
41
41
|
- [**Redis Client** `redisClient`](#redis-client) (be): use the Redis instance that you connect to
|
|
42
42
|
- [**Cloudflare KV** `env.KV_NAMESPACE`](#cloudflare-kv) (be): use Cloudflare's KV store
|
|
43
43
|
- [**Level** `new Level('example', { valueEncoding: 'json' })`](#level) (fe+be): support the whole Level ecosystem
|
|
@@ -646,7 +646,7 @@ console.log(await store.get("key1"));
|
|
|
646
646
|
|
|
647
647
|
> Note: the API client expire resolution is in the seconds, so times shorter than 1 second like `expires: 0.02` (20 ms) don't make sense for this storage method and won't properly save them.
|
|
648
648
|
|
|
649
|
-
> Note: see the reference implementation in src/server.js
|
|
649
|
+
> Note: see the [reference implementation in src/server.js](https://github.com/franciscop/polystore/blob/master/src/server.js)
|
|
650
650
|
|
|
651
651
|
|
|
652
652
|
### File
|
package/src/server.js
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
import http from "node:http";
|
|
3
3
|
import kv from "./index.js";
|
|
4
4
|
|
|
5
|
+
// Add/remove the key whether you want the API to be behind a key
|
|
6
|
+
const key = null;
|
|
7
|
+
// const key = 'MY-SECRET-KEY';
|
|
8
|
+
|
|
5
9
|
// Modify this to use any sub-store as desired. It's nice
|
|
6
10
|
// to use polystore itself for the polystore server library!'
|
|
7
11
|
const store = kv(new Map());
|
|
@@ -51,6 +55,9 @@ async function fetch({ method, url, body }) {
|
|
|
51
55
|
|
|
52
56
|
// http or express server-like handler:
|
|
53
57
|
async function server(req, res) {
|
|
58
|
+
// Secure it behind a key (optional)
|
|
59
|
+
if (key && req.headers.get("x-api-key") !== key) return res.send(401);
|
|
60
|
+
|
|
54
61
|
const url = new URL(req.url, "http://localhost:3000/").href;
|
|
55
62
|
const reply = await fetch({ ...req, url });
|
|
56
63
|
res.writeHead(reply.status, null, reply.headers || {});
|