polystore 0.8.0 → 0.9.0
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/autocomplete.png +0 -0
- package/assets/autocomplete.webp +0 -0
- package/assets/favicon.png +0 -0
- package/assets/home.html +379 -0
- package/assets/splash.png +0 -0
- package/documentation.page.json +12 -0
- package/package.json +8 -3
- package/readme.md +291 -82
- package/src/clients/cloudflare.js +49 -0
- package/src/clients/cookie.js +55 -0
- package/src/clients/etcd.js +39 -0
- package/src/clients/file.js +75 -0
- package/src/clients/forage.js +42 -0
- package/src/clients/index.js +21 -0
- package/src/clients/level.js +45 -0
- package/src/clients/memory.js +38 -0
- package/src/clients/redis.js +56 -0
- package/src/clients/storage.js +43 -0
- package/src/index.js +269 -391
- package/src/index.test.js +273 -37
- package/src/index.types.ts +1 -0
- package/src/{index.d.ts → indexa.d.ts} +5 -3
- package/src/test/customFull.js +38 -0
- package/src/test/customSimple.js +23 -0
- package/src/test/setup.js +12 -0
- package/src/utils.js +44 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/assets/home.html
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
<br />
|
|
2
|
+
|
|
3
|
+
<section class="hero flex center nowrap">
|
|
4
|
+
<div>
|
|
5
|
+
<h1>Polystore</h1>
|
|
6
|
+
<p style="max-width: 620px">
|
|
7
|
+
A universal library for standardizing KV-stores. Great when you don't want
|
|
8
|
+
to depend on a specific implementation, or for library builders that want
|
|
9
|
+
to accept any KV store available.
|
|
10
|
+
</p>
|
|
11
|
+
<pre class="small">npm install polystore</pre>
|
|
12
|
+
<div class="buttons">
|
|
13
|
+
<a class="button" href="/documentation">Documentation</a>
|
|
14
|
+
<a
|
|
15
|
+
class="pseudo button"
|
|
16
|
+
href="https://www.paypal.me/franciscopresencia/19"
|
|
17
|
+
>Donate</a
|
|
18
|
+
>
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
<div style="width: 550px; max-width: 100%">
|
|
22
|
+
<pre><code class="language-js">import kv from "polystore";
|
|
23
|
+
|
|
24
|
+
const store = kv(new Map());
|
|
25
|
+
|
|
26
|
+
await store.set("key1", { hello: "world" });
|
|
27
|
+
const value = await store.get("key1");
|
|
28
|
+
// { hello: "world" }</code></pre>
|
|
29
|
+
</div>
|
|
30
|
+
</section>
|
|
31
|
+
|
|
32
|
+
<div class="separator">
|
|
33
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 20">
|
|
34
|
+
<circle cx="10" cy="10" r="3" />
|
|
35
|
+
<line x1="20" y1="10" x2="260" y2="10" />
|
|
36
|
+
<circle cx="270" cy="10" r="3" />
|
|
37
|
+
<circle class="empty" cx="283" cy="10" r="3" />
|
|
38
|
+
<circle class="empty" cx="300" cy="10" r="5" />
|
|
39
|
+
<circle class="empty" cx="317" cy="10" r="3" />
|
|
40
|
+
<circle cx="330" cy="10" r="3" />
|
|
41
|
+
<line x1="340" y1="10" x2="580" y2="10" />
|
|
42
|
+
<circle cx="590" cy="10" r="3" />
|
|
43
|
+
</svg>
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
<section class="features flex one two-500 three-900">
|
|
47
|
+
<div>
|
|
48
|
+
<div class="feature">
|
|
49
|
+
<header>
|
|
50
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
|
51
|
+
<path
|
|
52
|
+
d="M18 8h1a4 4 0 010 8h-1M2 8h16v9a4 4 0 01-4 4H6a4 4 0 01-4-4V8zM6 1v3M10 1v3M14 1v3"
|
|
53
|
+
/>
|
|
54
|
+
</svg>
|
|
55
|
+
<h3>Easy peasy</h3>
|
|
56
|
+
</header>
|
|
57
|
+
<p>
|
|
58
|
+
It's a KV store. It has <code>add()</code>, <code>set()</code>,
|
|
59
|
+
<code>get()</code>, <code>has()</code>, <code>del()</code>
|
|
60
|
+
<a href="/documentation#api" target="_blank">and more</a>.
|
|
61
|
+
</p>
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
<div>
|
|
66
|
+
<div class="feature">
|
|
67
|
+
<header>
|
|
68
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
|
69
|
+
<path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z" />
|
|
70
|
+
<path d="M14 2v6h6M16 13H8M16 17H8M10 9H8" />
|
|
71
|
+
</svg>
|
|
72
|
+
<h3>Documented</h3>
|
|
73
|
+
</header>
|
|
74
|
+
<p>
|
|
75
|
+
<a href="/documentation#getting-started">Getting started</a>,
|
|
76
|
+
<a href="/documentation#api">API</a>,
|
|
77
|
+
<a href="/documentation#clients">Clients</a> and
|
|
78
|
+
<a href="/documentation#examples">examples</a> for your convenience.
|
|
79
|
+
</p>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
<div>
|
|
83
|
+
<div class="feature">
|
|
84
|
+
<header>
|
|
85
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
|
86
|
+
<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path>
|
|
87
|
+
<polyline points="22 4 12 14.01 9 11.01"></polyline>
|
|
88
|
+
</svg>
|
|
89
|
+
<h3>Tested and Typed</h3>
|
|
90
|
+
</header>
|
|
91
|
+
<p>
|
|
92
|
+
<a
|
|
93
|
+
href="https://github.com/franciscop/polystore/actions"
|
|
94
|
+
target="_blank"
|
|
95
|
+
>600+ tests</a
|
|
96
|
+
>, TS definitions and JSDocs for the best experience using the library.
|
|
97
|
+
</p>
|
|
98
|
+
</div>
|
|
99
|
+
</div>
|
|
100
|
+
<div>
|
|
101
|
+
<div class="feature">
|
|
102
|
+
<header>
|
|
103
|
+
<svg
|
|
104
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
105
|
+
width="24"
|
|
106
|
+
height="24"
|
|
107
|
+
viewBox="0 0 24 24"
|
|
108
|
+
fill="none"
|
|
109
|
+
stroke="currentColor"
|
|
110
|
+
stroke-width="2"
|
|
111
|
+
stroke-linecap="round"
|
|
112
|
+
stroke-linejoin="round"
|
|
113
|
+
class="feather feather-globe"
|
|
114
|
+
>
|
|
115
|
+
<circle cx="12" cy="12" r="10"></circle>
|
|
116
|
+
<line x1="2" y1="12" x2="22" y2="12"></line>
|
|
117
|
+
<path
|
|
118
|
+
d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"
|
|
119
|
+
></path>
|
|
120
|
+
</svg>
|
|
121
|
+
<h3>Universal Javascript</h3>
|
|
122
|
+
</header>
|
|
123
|
+
<p>
|
|
124
|
+
Use it with React, Angular, Plain JS, Node.js, Bun, Tauri, Electron,
|
|
125
|
+
etc.
|
|
126
|
+
</p>
|
|
127
|
+
</div>
|
|
128
|
+
</div>
|
|
129
|
+
|
|
130
|
+
<div>
|
|
131
|
+
<div class="feature">
|
|
132
|
+
<header>
|
|
133
|
+
<svg
|
|
134
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
135
|
+
width="24"
|
|
136
|
+
height="24"
|
|
137
|
+
viewBox="0 0 24 24"
|
|
138
|
+
fill="none"
|
|
139
|
+
stroke="currentColor"
|
|
140
|
+
stroke-width="2"
|
|
141
|
+
stroke-linecap="round"
|
|
142
|
+
stroke-linejoin="round"
|
|
143
|
+
>
|
|
144
|
+
<path
|
|
145
|
+
d="M20.24 12.24a6 6 0 00-8.49-8.49L5 10.5V19h8.5zM16 8L2 22M17.5 15H9"
|
|
146
|
+
/>
|
|
147
|
+
</svg>
|
|
148
|
+
<h3>Tiny Footprint</h3>
|
|
149
|
+
</header>
|
|
150
|
+
<p>
|
|
151
|
+
At
|
|
152
|
+
<a href="https://bundlephobia.com/package/polystore" target="_blank"
|
|
153
|
+
>just <strong>2.4b</strong></a
|
|
154
|
+
>
|
|
155
|
+
(min+gzip), the impact on your app loading time is minimal.
|
|
156
|
+
</p>
|
|
157
|
+
</div>
|
|
158
|
+
</div>
|
|
159
|
+
|
|
160
|
+
<div>
|
|
161
|
+
<div class="feature">
|
|
162
|
+
<header>
|
|
163
|
+
<svg
|
|
164
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
165
|
+
width="24"
|
|
166
|
+
height="24"
|
|
167
|
+
viewBox="0 0 24 24"
|
|
168
|
+
fill="none"
|
|
169
|
+
stroke="currentColor"
|
|
170
|
+
stroke-width="2"
|
|
171
|
+
stroke-linecap="round"
|
|
172
|
+
stroke-linejoin="round"
|
|
173
|
+
class="feather feather-clock"
|
|
174
|
+
>
|
|
175
|
+
<circle cx="12" cy="12" r="10"></circle>
|
|
176
|
+
<polyline points="12 6 12 12 16 14"></polyline>
|
|
177
|
+
</svg>
|
|
178
|
+
<h3>Intuitive expirations</h3>
|
|
179
|
+
</header>
|
|
180
|
+
<p>Write the expiration as <code>100s</code>, <code>1week</code>, etc.</p>
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
</section>
|
|
184
|
+
|
|
185
|
+
<div class="separator">
|
|
186
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 20">
|
|
187
|
+
<circle cx="10" cy="10" r="3" />
|
|
188
|
+
<line x1="20" y1="10" x2="260" y2="10" />
|
|
189
|
+
<circle cx="270" cy="10" r="3" />
|
|
190
|
+
<circle class="empty" cx="283" cy="10" r="3" />
|
|
191
|
+
<circle class="empty" cx="300" cy="10" r="5" />
|
|
192
|
+
<circle class="empty" cx="317" cy="10" r="3" />
|
|
193
|
+
<circle cx="330" cy="10" r="3" />
|
|
194
|
+
<line x1="340" y1="10" x2="580" y2="10" />
|
|
195
|
+
<circle cx="590" cy="10" r="3" />
|
|
196
|
+
</svg>
|
|
197
|
+
</div>
|
|
198
|
+
|
|
199
|
+
<section class="hero flex one two-900 center">
|
|
200
|
+
<div>
|
|
201
|
+
<div class="content">
|
|
202
|
+
<h2>🧩 Support for many clients</h2>
|
|
203
|
+
<p>
|
|
204
|
+
We support 10+ clients with documentation for each of them. Adding your
|
|
205
|
+
own client is also easy, you only need to define 3 methods:
|
|
206
|
+
<code>.get()</code>, <code>.set()</code> and <code>.entries()</code>.
|
|
207
|
+
</p>
|
|
208
|
+
<p>
|
|
209
|
+
<a class="pseudo button" href="/documentation#clients">
|
|
210
|
+
Documentation
|
|
211
|
+
</a>
|
|
212
|
+
</p>
|
|
213
|
+
</div>
|
|
214
|
+
</div>
|
|
215
|
+
<div>
|
|
216
|
+
<pre><code class="language-js">import kv from "polystore";
|
|
217
|
+
|
|
218
|
+
const store1 = kv(new Map());
|
|
219
|
+
const store2 = kv(localStorage);
|
|
220
|
+
const store3 = kv(redisClient);
|
|
221
|
+
const store4 = kv("cookie");
|
|
222
|
+
const store5 = kv("file:///users/me/kv.json");
|
|
223
|
+
const store6 = kv(yourOwnStore);</code></pre>
|
|
224
|
+
</div>
|
|
225
|
+
</section>
|
|
226
|
+
|
|
227
|
+
<br />
|
|
228
|
+
|
|
229
|
+
<section class="hero flex one two-900 center">
|
|
230
|
+
<div>
|
|
231
|
+
<div class="content">
|
|
232
|
+
<h2>🏖️ Clean and intuitive API</h2>
|
|
233
|
+
<p>
|
|
234
|
+
A set of high-performance atomic operations with <code>.add()</code>,
|
|
235
|
+
<code>.set()</code>, <code>.get()</code>, <code>.has()</code> or
|
|
236
|
+
<code>.del()</code>
|
|
237
|
+
</p>
|
|
238
|
+
<p>
|
|
239
|
+
You can also work with all of entries with <code>.keys()</code>,
|
|
240
|
+
<code>.values()</code>, <code>.entries()</code>, <code>.all()</code> and
|
|
241
|
+
<code>.clear()</code>.
|
|
242
|
+
</p>
|
|
243
|
+
</div>
|
|
244
|
+
</div>
|
|
245
|
+
<div>
|
|
246
|
+
<pre><code class="language-js">const key1 = await store.add("value2");
|
|
247
|
+
const key2 = await store.set("key1", "value1");
|
|
248
|
+
const isthere = await store.has("key1");
|
|
249
|
+
|
|
250
|
+
const allKeys = await store.keys();
|
|
251
|
+
const allValues = await store.values();
|
|
252
|
+
const obj = await store.all();
|
|
253
|
+
// etc</code></pre>
|
|
254
|
+
</div>
|
|
255
|
+
</section>
|
|
256
|
+
|
|
257
|
+
<section class="hero flex one two-900 center">
|
|
258
|
+
<div>
|
|
259
|
+
<div class="content">
|
|
260
|
+
<h2>🛗 Create substores</h2>
|
|
261
|
+
<p>
|
|
262
|
+
We include the `.prefix()` method to allow you to work with a subset of
|
|
263
|
+
items easily.
|
|
264
|
+
</p>
|
|
265
|
+
<p>
|
|
266
|
+
e.g. if you have a session store and want to create a subset of sessions
|
|
267
|
+
only for auth, you would do
|
|
268
|
+
<code>const auth = session.prefix('auth:');</code> and then use
|
|
269
|
+
<code>auth</code> like if it was an independent, KV store.
|
|
270
|
+
</p>
|
|
271
|
+
</div>
|
|
272
|
+
</div>
|
|
273
|
+
<div>
|
|
274
|
+
<pre><code class="language-js">import kv from "polystore";
|
|
275
|
+
const store = kv(new Map());
|
|
276
|
+
|
|
277
|
+
const auth = store.prefix("auth:");
|
|
278
|
+
auth.set("key1", "value1");
|
|
279
|
+
console.log(await auth.entries());
|
|
280
|
+
// [["key1", "value1"]]
|
|
281
|
+
|
|
282
|
+
console.log(await store.entries());
|
|
283
|
+
// [["auth:key1", "value1"]]</code></pre>
|
|
284
|
+
</div>
|
|
285
|
+
</section>
|
|
286
|
+
|
|
287
|
+
<br />
|
|
288
|
+
|
|
289
|
+
<section class="hero flex one two-900 center">
|
|
290
|
+
<div>
|
|
291
|
+
<div class="content">
|
|
292
|
+
<h2>⏰ Easy expiration time</h2>
|
|
293
|
+
<p>
|
|
294
|
+
Unified expiration time so you can do
|
|
295
|
+
<code>{ expires: "1day" }</code> across ANY client. With polystore just
|
|
296
|
+
write in English and forget about calculating TTL, Unix time, seconds vs
|
|
297
|
+
milliseconds bugs, etc.
|
|
298
|
+
</p>
|
|
299
|
+
<p>
|
|
300
|
+
<a class="pseudo button" href="/documentation#expiration-explained">
|
|
301
|
+
Documentation
|
|
302
|
+
</a>
|
|
303
|
+
</p>
|
|
304
|
+
</div>
|
|
305
|
+
</div>
|
|
306
|
+
<div>
|
|
307
|
+
<pre><code class="language-js">import kv from "polystore";
|
|
308
|
+
const store = kv(new Map());
|
|
309
|
+
|
|
310
|
+
const auth = store.prefix("auth:");
|
|
311
|
+
auth.set("key1", "value1");
|
|
312
|
+
console.log(await auth.entries());
|
|
313
|
+
// [["key1", "value1"]]
|
|
314
|
+
|
|
315
|
+
console.log(await store.entries());
|
|
316
|
+
// [["auth:key1", "value1"]]</code></pre>
|
|
317
|
+
</div>
|
|
318
|
+
</section>
|
|
319
|
+
|
|
320
|
+
<br />
|
|
321
|
+
|
|
322
|
+
<section class="hero flex one two-900 center">
|
|
323
|
+
<div>
|
|
324
|
+
<div class="content">
|
|
325
|
+
<h2>✨ Magic Autocomplete</h2>
|
|
326
|
+
<p>
|
|
327
|
+
Added jsdocs so the expected parameters and return value will be clearly
|
|
328
|
+
defined in your IDE/Code Editor.
|
|
329
|
+
</p>
|
|
330
|
+
<p>
|
|
331
|
+
We added the <em>description</em>, a representative <em>example</em> and
|
|
332
|
+
even a <em>link</em> for more information for
|
|
333
|
+
<strong>every one</strong> of the methods available! We want you to have
|
|
334
|
+
the best development experience possible with Polystore!
|
|
335
|
+
</p>
|
|
336
|
+
</div>
|
|
337
|
+
</div>
|
|
338
|
+
<div>
|
|
339
|
+
<div class="splash">
|
|
340
|
+
<img
|
|
341
|
+
width="535"
|
|
342
|
+
src="https://raw.githubusercontent.com/franciscop/polystore/master/assets/autocomplete.webp"
|
|
343
|
+
/>
|
|
344
|
+
</div>
|
|
345
|
+
</div>
|
|
346
|
+
</section>
|
|
347
|
+
|
|
348
|
+
<div class="separator">
|
|
349
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 20">
|
|
350
|
+
<circle cx="10" cy="10" r="3" />
|
|
351
|
+
<line x1="20" y1="10" x2="260" y2="10" />
|
|
352
|
+
<circle cx="270" cy="10" r="3" />
|
|
353
|
+
<circle class="empty" cx="283" cy="10" r="3" />
|
|
354
|
+
<circle class="empty" cx="300" cy="10" r="5" />
|
|
355
|
+
<circle class="empty" cx="317" cy="10" r="3" />
|
|
356
|
+
<circle cx="330" cy="10" r="3" />
|
|
357
|
+
<line x1="340" y1="10" x2="580" y2="10" />
|
|
358
|
+
<circle cx="590" cy="10" r="3" />
|
|
359
|
+
</svg>
|
|
360
|
+
</div>
|
|
361
|
+
|
|
362
|
+
<div style="text-align: center">
|
|
363
|
+
<p>
|
|
364
|
+
Created by <a href="https://francisco.io/" target="_blank">Francisco</a> and
|
|
365
|
+
<a
|
|
366
|
+
href="https://github.com/franciscop/polystore/graphs/contributors"
|
|
367
|
+
target="_blank"
|
|
368
|
+
>other contributors</a
|
|
369
|
+
>.
|
|
370
|
+
</p>
|
|
371
|
+
<p>
|
|
372
|
+
Need help?
|
|
373
|
+
<a
|
|
374
|
+
href="https://superpeer.com/francisco/-/javascript-and-react-help"
|
|
375
|
+
target="_blank"
|
|
376
|
+
>Book a call</a
|
|
377
|
+
>.
|
|
378
|
+
</p>
|
|
379
|
+
</div>
|
|
Binary file
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title": "🏬 Polystore - A universal library for standardizing any KV-store",
|
|
3
|
+
"home": "assets/home.html",
|
|
4
|
+
"homepage": "https://polystore.dev/",
|
|
5
|
+
"menu": {
|
|
6
|
+
"Documentation": "/documentation",
|
|
7
|
+
"Issues": "https://github.com/franciscop/polystore/issues",
|
|
8
|
+
"Contribute": "https://github.com/franciscop/polystore/blob/master/Contributing.md",
|
|
9
|
+
"Get help": "https://superpeer.com/francisco/-/javascript-and-react-help",
|
|
10
|
+
"Github": "https://github.com/franciscop/polystore"
|
|
11
|
+
}
|
|
12
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polystore",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
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",
|
|
@@ -8,12 +8,11 @@
|
|
|
8
8
|
"funding": "https://www.paypal.me/franciscopresencia/19",
|
|
9
9
|
"author": "Francisco Presencia <public@francisco.io> (https://francisco.io/)",
|
|
10
10
|
"main": "src/index.js",
|
|
11
|
-
"types": "src/index.d.ts",
|
|
12
11
|
"type": "module",
|
|
13
12
|
"scripts": {
|
|
14
13
|
"size": "echo $(gzip -c src/index.js | wc -c) bytes",
|
|
15
14
|
"start": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch --coverage --detectOpenHandles",
|
|
16
|
-
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --detectOpenHandles && check-dts src/index.types.ts"
|
|
15
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --ci --watchAll=false --detectOpenHandles && check-dts src/index.types.ts"
|
|
17
16
|
},
|
|
18
17
|
"keywords": [
|
|
19
18
|
"kv",
|
|
@@ -27,14 +26,20 @@
|
|
|
27
26
|
"devDependencies": {
|
|
28
27
|
"check-dts": "^0.7.2",
|
|
29
28
|
"dotenv": "^16.3.1",
|
|
29
|
+
"edge-mock": "^0.0.15",
|
|
30
30
|
"esbuild": "^0.19.4",
|
|
31
|
+
"etcd3": "^1.1.2",
|
|
31
32
|
"jest": "^29.7.0",
|
|
32
33
|
"jest-environment-jsdom": "^29.7.0",
|
|
34
|
+
"level": "^8.0.1",
|
|
33
35
|
"localforage": "^1.10.0",
|
|
34
36
|
"redis": "^4.6.10"
|
|
35
37
|
},
|
|
36
38
|
"jest": {
|
|
37
39
|
"testEnvironment": "jsdom",
|
|
40
|
+
"setupFiles": [
|
|
41
|
+
"./src/test/setup.js"
|
|
42
|
+
],
|
|
38
43
|
"transform": {},
|
|
39
44
|
"modulePathIgnorePatterns": [
|
|
40
45
|
"src/test/"
|