polystore 0.6.0 → 0.7.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/package.json +1 -1
- package/readme.md +1 -1
- package/src/index.js +5 -1
- package/src/index.test.js +33 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polystore",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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",
|
package/readme.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Polystore [](https://www.npmjs.com/package/polystore) [](https://github.com/franciscop/polystore/blob/master/.github/workflows/tests.yml) [](https://www.npmjs.com/package/polystore) [](https://github.com/franciscop/polystore/blob/master/.github/workflows/tests.yml) [](https://github.com/franciscop/polystore/blob/master/src/index.js)
|
|
2
2
|
|
|
3
3
|
A small compatibility layer for many KV stores like localStorage, Redis, FileSystem, etc:
|
|
4
4
|
|
package/src/index.js
CHANGED
|
@@ -49,6 +49,10 @@ layers.extra = (store) => {
|
|
|
49
49
|
const add = async (value, options) => store.set(generateId(), value, options);
|
|
50
50
|
const has = async (key) => (await store.get(key)) !== null;
|
|
51
51
|
const del = async (key) => store.set(key, null);
|
|
52
|
+
const all = async (prefix = "") => {
|
|
53
|
+
const entries = await store.entries(prefix);
|
|
54
|
+
return Object.fromEntries(entries);
|
|
55
|
+
};
|
|
52
56
|
const keys = async (prefix = "") => {
|
|
53
57
|
const all = await store.entries(prefix);
|
|
54
58
|
return all.map((p) => p[0]);
|
|
@@ -57,7 +61,7 @@ layers.extra = (store) => {
|
|
|
57
61
|
const all = await store.entries(prefix);
|
|
58
62
|
return all.map((p) => p[1]);
|
|
59
63
|
};
|
|
60
|
-
return { add, has, del, keys, values, ...store };
|
|
64
|
+
return { add, has, del, keys, values, all, ...store };
|
|
61
65
|
};
|
|
62
66
|
|
|
63
67
|
// Adds an expiration layer to those stores that don't have it;
|
package/src/index.test.js
CHANGED
|
@@ -104,6 +104,15 @@ for (let [name, store] of stores) {
|
|
|
104
104
|
]);
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
+
it("can get the all object", async () => {
|
|
108
|
+
await store.set("a", "b");
|
|
109
|
+
await store.set("c", "d");
|
|
110
|
+
expect(await store.all()).toEqual({
|
|
111
|
+
a: "b",
|
|
112
|
+
c: "d",
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
107
116
|
it("can get the keys with a colon prefix", async () => {
|
|
108
117
|
await store.set("a:0", "a0");
|
|
109
118
|
await store.set("a:1", "a1");
|
|
@@ -132,6 +141,18 @@ for (let [name, store] of stores) {
|
|
|
132
141
|
]);
|
|
133
142
|
});
|
|
134
143
|
|
|
144
|
+
it("can get the all object with a colon prefix", async () => {
|
|
145
|
+
await store.set("a:0", "a0");
|
|
146
|
+
await store.set("a:1", "a1");
|
|
147
|
+
await store.set("b:0", "b0");
|
|
148
|
+
await store.set("a:2", "a2");
|
|
149
|
+
expect(await store.all("a:")).toEqual({
|
|
150
|
+
"a:0": "a0",
|
|
151
|
+
"a:1": "a1",
|
|
152
|
+
"a:2": "a2",
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
135
156
|
it("can get the keys with a dash prefix", async () => {
|
|
136
157
|
await store.set("a-0", "a0");
|
|
137
158
|
await store.set("a-1", "a1");
|
|
@@ -160,6 +181,18 @@ for (let [name, store] of stores) {
|
|
|
160
181
|
]);
|
|
161
182
|
});
|
|
162
183
|
|
|
184
|
+
it("can get the all object with a dash prefix", async () => {
|
|
185
|
+
await store.set("a-0", "a0");
|
|
186
|
+
await store.set("a-1", "a1");
|
|
187
|
+
await store.set("b-0", "b0");
|
|
188
|
+
await store.set("a-2", "a2");
|
|
189
|
+
expect(await store.all("a-")).toEqual({
|
|
190
|
+
"a-0": "a0",
|
|
191
|
+
"a-1": "a1",
|
|
192
|
+
"a-2": "a2",
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
163
196
|
it("can delete the data", async () => {
|
|
164
197
|
await store.set("a", "b");
|
|
165
198
|
expect(await store.get("a")).toBe("b");
|