keyv 4.1.0 → 4.2.1
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 +55 -46
- package/src/index.d.ts +23 -0
- package/src/index.js +169 -24
- package/.nyc_output/17c338d1-cd21-4d2f-9d97-398f18a945cf.json +0 -1
- package/.nyc_output/67b1f344-0eec-41a3-a665-c824c346e898.json +0 -1
- package/.nyc_output/adb04494-7d0a-443f-9130-94b19c3fa19c.json +0 -1
- package/.nyc_output/processinfo/17c338d1-cd21-4d2f-9d97-398f18a945cf.json +0 -1
- package/.nyc_output/processinfo/67b1f344-0eec-41a3-a665-c824c346e898.json +0 -1
- package/.nyc_output/processinfo/adb04494-7d0a-443f-9130-94b19c3fa19c.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/test/test.js +0 -130
- package/test/testdb.sqlite +0 -0
package/package.json
CHANGED
|
@@ -1,48 +1,57 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
2
|
+
"name": "keyv",
|
|
3
|
+
"version": "4.2.1",
|
|
4
|
+
"description": "Simple key-value storage with support for multiple backends",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "xo && nyc ava --serial",
|
|
8
|
+
"coverage": "nyc report --reporter=text-lcov > coverage.lcov",
|
|
9
|
+
"clean": "rm -rf node_modules && rm -rf .nyc_output && rm -rf coverage.lcov && rm -rf ./test/testdb.sqlite"
|
|
10
|
+
},
|
|
11
|
+
"xo": {
|
|
12
|
+
"rules": {
|
|
13
|
+
"unicorn/prefer-module": 0,
|
|
14
|
+
"unicorn/prefer-node-protocol": 0
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/jaredwray/keyv.git"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"key",
|
|
23
|
+
"value",
|
|
24
|
+
"store",
|
|
25
|
+
"cache",
|
|
26
|
+
"ttl"
|
|
27
|
+
],
|
|
28
|
+
"author": "Jared Wray <me@jaredwray.com> (http://jaredwray.com)",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/jaredwray/keyv/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/jaredwray/keyv",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"compress-brotli": "^1.3.6",
|
|
36
|
+
"json-buffer": "3.0.1"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@keyv/test-suite": "*",
|
|
40
|
+
"ava": "^4.1.0",
|
|
41
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
42
|
+
"nyc": "^15.1.0",
|
|
43
|
+
"pify": "5.0.0",
|
|
44
|
+
"this": "^1.1.0",
|
|
45
|
+
"timekeeper": "^2.2.0",
|
|
46
|
+
"tsd": "^0.20.0",
|
|
47
|
+
"typescript": "^4.6.3",
|
|
48
|
+
"xo": "^0.48.0"
|
|
49
|
+
},
|
|
50
|
+
"tsd" : {
|
|
51
|
+
"directory" : "test"
|
|
52
|
+
},
|
|
53
|
+
"types": "./src/index.d.ts",
|
|
54
|
+
"files": [
|
|
55
|
+
"src"
|
|
56
|
+
]
|
|
48
57
|
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {EventEmitter} from 'events';
|
|
2
|
+
|
|
3
|
+
declare class Keyv<T = any> extends EventEmitter {
|
|
4
|
+
constructor(uri: string, options: Keyv.Options);
|
|
5
|
+
get(key: string, options?: any): Promise<T>;
|
|
6
|
+
set(key: string, value: T, ttl?: number): Promise<boolean>;
|
|
7
|
+
delete(key: string): Promise<boolean>;
|
|
8
|
+
clear(): Promise<void>;
|
|
9
|
+
has(key: string): Promise<boolean>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare namespace Keyv {
|
|
13
|
+
interface Options {
|
|
14
|
+
namespace?: string | undefined;
|
|
15
|
+
serialize?: ((data: any) => string) | undefined;
|
|
16
|
+
deserialize?: ((data: string) => any | undefined) | undefined;
|
|
17
|
+
ttl?: number | undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type Store<T> = Keyv<T>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export = Keyv;
|
package/src/index.js
CHANGED
|
@@ -2,11 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const EventEmitter = require('events');
|
|
4
4
|
const JSONB = require('json-buffer');
|
|
5
|
-
|
|
6
|
-
// eslint-disable-next-line no-extend-native
|
|
7
|
-
BigInt.prototype.toJSON = function () {
|
|
8
|
-
return this.toString();
|
|
9
|
-
};
|
|
5
|
+
const compressBrotli = require('compress-brotli');
|
|
10
6
|
|
|
11
7
|
const loadStore = options => {
|
|
12
8
|
const adapters = {
|
|
@@ -27,49 +23,168 @@ const loadStore = options => {
|
|
|
27
23
|
return new Map();
|
|
28
24
|
};
|
|
29
25
|
|
|
26
|
+
const iterableAdapters = [
|
|
27
|
+
'sqlite',
|
|
28
|
+
'postgres',
|
|
29
|
+
'mysql',
|
|
30
|
+
'mongo',
|
|
31
|
+
'redis',
|
|
32
|
+
];
|
|
33
|
+
|
|
30
34
|
class Keyv extends EventEmitter {
|
|
31
35
|
constructor(uri, options) {
|
|
32
36
|
super();
|
|
33
|
-
this.opts =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
options,
|
|
41
|
-
);
|
|
37
|
+
this.opts = {
|
|
38
|
+
namespace: 'keyv',
|
|
39
|
+
serialize: JSONB.stringify,
|
|
40
|
+
deserialize: JSONB.parse,
|
|
41
|
+
...((typeof uri === 'string') ? {uri} : uri),
|
|
42
|
+
...options,
|
|
43
|
+
};
|
|
42
44
|
|
|
43
45
|
if (!this.opts.store) {
|
|
44
|
-
const adapterOptions =
|
|
46
|
+
const adapterOptions = {...this.opts};
|
|
45
47
|
this.opts.store = loadStore(adapterOptions);
|
|
46
48
|
}
|
|
47
49
|
|
|
50
|
+
if (this.opts.compress) {
|
|
51
|
+
const brotli = compressBrotli(this.opts.compress.opts);
|
|
52
|
+
this.opts.serialize = async ({value, expires}) => brotli.serialize({value: await brotli.compress(value), expires});
|
|
53
|
+
this.opts.deserialize = async data => {
|
|
54
|
+
const {value, expires} = brotli.deserialize(data);
|
|
55
|
+
return {value: await brotli.decompress(value), expires};
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
48
59
|
if (typeof this.opts.store.on === 'function') {
|
|
49
60
|
this.opts.store.on('error', error => this.emit('error', error));
|
|
50
61
|
}
|
|
51
62
|
|
|
52
63
|
this.opts.store.namespace = this.opts.namespace;
|
|
64
|
+
|
|
65
|
+
const generateIterator = iterator =>
|
|
66
|
+
async function * () {
|
|
67
|
+
for await (const [key, raw] of typeof iterator === 'function'
|
|
68
|
+
? iterator(this.opts.store.namespace)
|
|
69
|
+
: iterator) {
|
|
70
|
+
const data = typeof raw === 'string' ? this.opts.deserialize(raw) : raw;
|
|
71
|
+
if (this.opts.store.namespace && !key.includes(this.opts.store.namespace)) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (typeof data.expires === 'number' && Date.now() > data.expires) {
|
|
76
|
+
this.delete(key);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
yield [this._getKeyUnprefix(key), data.value];
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// Attach iterators
|
|
85
|
+
if (typeof this.opts.store[Symbol.iterator] === 'function' && this.opts.store instanceof Map) {
|
|
86
|
+
this.iterator = generateIterator(this.opts.store);
|
|
87
|
+
} else if (typeof this.opts.store.iterator === 'function' && this.opts.store.opts
|
|
88
|
+
&& this._checkIterableAdaptar()) {
|
|
89
|
+
this.iterator = generateIterator(this.opts.store.iterator.bind(this.opts.store));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
_checkIterableAdaptar() {
|
|
94
|
+
return iterableAdapters.includes(this.opts.store.opts.dialect)
|
|
95
|
+
|| iterableAdapters.findIndex(element => this.opts.store.opts.url.includes(element)) >= 0;
|
|
53
96
|
}
|
|
54
97
|
|
|
55
98
|
_getKeyPrefix(key) {
|
|
56
99
|
return `${this.opts.namespace}:${key}`;
|
|
57
100
|
}
|
|
58
101
|
|
|
102
|
+
_getKeyPrefixArray(keys) {
|
|
103
|
+
return keys.map(key => `${this.opts.namespace}:${key}`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
_getKeyUnprefix(key) {
|
|
107
|
+
return this.opts.store.namespace
|
|
108
|
+
? key
|
|
109
|
+
.split(':')
|
|
110
|
+
.splice(1)
|
|
111
|
+
.join(':')
|
|
112
|
+
: key;
|
|
113
|
+
}
|
|
114
|
+
|
|
59
115
|
get(key, options) {
|
|
60
|
-
const
|
|
61
|
-
const
|
|
116
|
+
const {store} = this.opts;
|
|
117
|
+
const isArray = Array.isArray(key);
|
|
118
|
+
const keyPrefixed = isArray ? this._getKeyPrefixArray(key) : this._getKeyPrefix(key);
|
|
119
|
+
if (isArray && store.getMany === undefined) {
|
|
120
|
+
const promises = [];
|
|
121
|
+
for (const key of keyPrefixed) {
|
|
122
|
+
promises.push(Promise.resolve()
|
|
123
|
+
.then(() => store.get(key))
|
|
124
|
+
.then(data => (typeof data === 'string') ? this.opts.deserialize(data) : data)
|
|
125
|
+
.then(data => {
|
|
126
|
+
if (data === undefined || data === null) {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (typeof data.expires === 'number' && Date.now() > data.expires) {
|
|
131
|
+
return this.delete(key).then(() => undefined);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return (options && options.raw) ? data : data.value;
|
|
135
|
+
}),
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return Promise.allSettled(promises)
|
|
140
|
+
.then(values => {
|
|
141
|
+
const data = [];
|
|
142
|
+
for (const value of values) {
|
|
143
|
+
data.push(value.value);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return data.every(x => x === undefined) ? [] : data;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
62
150
|
return Promise.resolve()
|
|
63
|
-
.then(() => store.get(keyPrefixed))
|
|
151
|
+
.then(() => isArray ? store.getMany(keyPrefixed) : store.get(keyPrefixed))
|
|
64
152
|
.then(data => (typeof data === 'string') ? this.opts.deserialize(data) : data)
|
|
65
153
|
.then(data => {
|
|
154
|
+
// Console.log('get', data);
|
|
66
155
|
if (data === undefined || data === null) {
|
|
67
156
|
return undefined;
|
|
68
157
|
}
|
|
69
158
|
|
|
159
|
+
if (isArray) {
|
|
160
|
+
const result = [];
|
|
161
|
+
if (data.length === 0) {
|
|
162
|
+
return [];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
for (let row of data) {
|
|
166
|
+
if ((typeof row === 'string')) {
|
|
167
|
+
row = this.opts.deserialize(row);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (row === undefined || row === null) {
|
|
171
|
+
result.push(undefined);
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (typeof row.expires === 'number' && Date.now() > row.expires) {
|
|
176
|
+
this.delete(key).then(() => undefined);
|
|
177
|
+
result.push(undefined);
|
|
178
|
+
} else {
|
|
179
|
+
result.push((options && options.raw) ? row : row.value);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return result.every(x => x === undefined) ? [] : result;
|
|
184
|
+
}
|
|
185
|
+
|
|
70
186
|
if (typeof data.expires === 'number' && Date.now() > data.expires) {
|
|
71
|
-
this.delete(key);
|
|
72
|
-
return undefined;
|
|
187
|
+
return this.delete(key).then(() => undefined);
|
|
73
188
|
}
|
|
74
189
|
|
|
75
190
|
return (options && options.raw) ? data : data.value;
|
|
@@ -86,7 +201,7 @@ class Keyv extends EventEmitter {
|
|
|
86
201
|
ttl = undefined;
|
|
87
202
|
}
|
|
88
203
|
|
|
89
|
-
const {
|
|
204
|
+
const {store} = this.opts;
|
|
90
205
|
|
|
91
206
|
return Promise.resolve()
|
|
92
207
|
.then(() => {
|
|
@@ -95,7 +210,7 @@ class Keyv extends EventEmitter {
|
|
|
95
210
|
this.emit('error', 'symbol cannot be serialized');
|
|
96
211
|
}
|
|
97
212
|
|
|
98
|
-
value = {
|
|
213
|
+
value = {value, expires};
|
|
99
214
|
return this.opts.serialize(value);
|
|
100
215
|
})
|
|
101
216
|
.then(value => store.set(keyPrefixed, value, ttl))
|
|
@@ -103,17 +218,47 @@ class Keyv extends EventEmitter {
|
|
|
103
218
|
}
|
|
104
219
|
|
|
105
220
|
delete(key) {
|
|
221
|
+
const {store} = this.opts;
|
|
222
|
+
if (Array.isArray(key)) {
|
|
223
|
+
const keyPrefixed = this._getKeyPrefixArray(key);
|
|
224
|
+
if (store.deleteMany === undefined) {
|
|
225
|
+
const promises = [];
|
|
226
|
+
for (const key of keyPrefixed) {
|
|
227
|
+
promises.push(store.delete(key));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return Promise.allSettled(promises)
|
|
231
|
+
.then(values => values.every(x => x.value === true));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return Promise.resolve()
|
|
235
|
+
.then(() => store.deleteMany(keyPrefixed));
|
|
236
|
+
}
|
|
237
|
+
|
|
106
238
|
const keyPrefixed = this._getKeyPrefix(key);
|
|
107
|
-
const { store } = this.opts;
|
|
108
239
|
return Promise.resolve()
|
|
109
240
|
.then(() => store.delete(keyPrefixed));
|
|
110
241
|
}
|
|
111
242
|
|
|
112
243
|
clear() {
|
|
113
|
-
const {
|
|
244
|
+
const {store} = this.opts;
|
|
114
245
|
return Promise.resolve()
|
|
115
246
|
.then(() => store.clear());
|
|
116
247
|
}
|
|
248
|
+
|
|
249
|
+
has(key) {
|
|
250
|
+
const keyPrefixed = this._getKeyPrefix(key);
|
|
251
|
+
const {store} = this.opts;
|
|
252
|
+
return Promise.resolve()
|
|
253
|
+
.then(async () => {
|
|
254
|
+
if (typeof store.has === 'function') {
|
|
255
|
+
return store.has(keyPrefixed);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const value = await store.get(keyPrefixed);
|
|
259
|
+
return value !== undefined;
|
|
260
|
+
});
|
|
261
|
+
}
|
|
117
262
|
}
|
|
118
263
|
|
|
119
264
|
module.exports = Keyv;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/keyv/src/index.js":{"path":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/keyv/src/index.js","statementMap":{"0":{"start":{"line":3,"column":21},"end":{"line":3,"column":38}},"1":{"start":{"line":4,"column":14},"end":{"line":4,"column":36}},"2":{"start":{"line":7,"column":0},"end":{"line":9,"column":2}},"3":{"start":{"line":8,"column":1},"end":{"line":8,"column":24}},"4":{"start":{"line":11,"column":18},"end":{"line":28,"column":1}},"5":{"start":{"line":12,"column":18},"end":{"line":21,"column":2}},"6":{"start":{"line":22,"column":1},"end":{"line":25,"column":2}},"7":{"start":{"line":23,"column":18},"end":{"line":23,"column":66}},"8":{"start":{"line":24,"column":2},"end":{"line":24,"column":51}},"9":{"start":{"line":27,"column":1},"end":{"line":27,"column":18}},"10":{"start":{"line":32,"column":2},"end":{"line":32,"column":10}},"11":{"start":{"line":33,"column":2},"end":{"line":41,"column":4}},"12":{"start":{"line":43,"column":2},"end":{"line":46,"column":3}},"13":{"start":{"line":44,"column":26},"end":{"line":44,"column":54}},"14":{"start":{"line":45,"column":3},"end":{"line":45,"column":47}},"15":{"start":{"line":48,"column":2},"end":{"line":50,"column":3}},"16":{"start":{"line":49,"column":3},"end":{"line":49,"column":67}},"17":{"start":{"line":49,"column":40},"end":{"line":49,"column":65}},"18":{"start":{"line":52,"column":2},"end":{"line":52,"column":50}},"19":{"start":{"line":56,"column":2},"end":{"line":56,"column":41}},"20":{"start":{"line":60,"column":22},"end":{"line":60,"column":45}},"21":{"start":{"line":61,"column":20},"end":{"line":61,"column":29}},"22":{"start":{"line":62,"column":2},"end":{"line":76,"column":6}},"23":{"start":{"line":63,"column":15},"end":{"line":63,"column":37}},"24":{"start":{"line":64,"column":17},"end":{"line":64,"column":80}},"25":{"start":{"line":66,"column":4},"end":{"line":68,"column":5}},"26":{"start":{"line":67,"column":5},"end":{"line":67,"column":22}},"27":{"start":{"line":70,"column":4},"end":{"line":73,"column":5}},"28":{"start":{"line":71,"column":5},"end":{"line":71,"column":22}},"29":{"start":{"line":72,"column":5},"end":{"line":72,"column":22}},"30":{"start":{"line":75,"column":4},"end":{"line":75,"column":56}},"31":{"start":{"line":80,"column":22},"end":{"line":80,"column":45}},"32":{"start":{"line":81,"column":2},"end":{"line":83,"column":3}},"33":{"start":{"line":82,"column":3},"end":{"line":82,"column":23}},"34":{"start":{"line":85,"column":2},"end":{"line":87,"column":3}},"35":{"start":{"line":86,"column":3},"end":{"line":86,"column":19}},"36":{"start":{"line":89,"column":20},"end":{"line":89,"column":29}},"37":{"start":{"line":91,"column":2},"end":{"line":102,"column":21}},"38":{"start":{"line":93,"column":20},"end":{"line":93,"column":73}},"39":{"start":{"line":94,"column":4},"end":{"line":96,"column":5}},"40":{"start":{"line":95,"column":5},"end":{"line":95,"column":55}},"41":{"start":{"line":98,"column":4},"end":{"line":98,"column":31}},"42":{"start":{"line":99,"column":4},"end":{"line":99,"column":38}},"43":{"start":{"line":101,"column":18},"end":{"line":101,"column":52}},"44":{"start":{"line":102,"column":15},"end":{"line":102,"column":19}},"45":{"start":{"line":106,"column":22},"end":{"line":106,"column":45}},"46":{"start":{"line":107,"column":20},"end":{"line":107,"column":29}},"47":{"start":{"line":108,"column":2},"end":{"line":109,"column":42}},"48":{"start":{"line":109,"column":15},"end":{"line":109,"column":40}},"49":{"start":{"line":113,"column":20},"end":{"line":113,"column":29}},"50":{"start":{"line":114,"column":2},"end":{"line":115,"column":30}},"51":{"start":{"line":115,"column":15},"end":{"line":115,"column":28}},"52":{"start":{"line":119,"column":0},"end":{"line":119,"column":22}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":7,"column":26},"end":{"line":7,"column":27}},"loc":{"start":{"line":7,"column":38},"end":{"line":9,"column":1}},"line":7},"1":{"name":"(anonymous_1)","decl":{"start":{"line":11,"column":18},"end":{"line":11,"column":19}},"loc":{"start":{"line":11,"column":29},"end":{"line":28,"column":1}},"line":11},"2":{"name":"(anonymous_2)","decl":{"start":{"line":31,"column":1},"end":{"line":31,"column":2}},"loc":{"start":{"line":31,"column":27},"end":{"line":53,"column":2}},"line":31},"3":{"name":"(anonymous_3)","decl":{"start":{"line":49,"column":31},"end":{"line":49,"column":32}},"loc":{"start":{"line":49,"column":40},"end":{"line":49,"column":65}},"line":49},"4":{"name":"(anonymous_4)","decl":{"start":{"line":55,"column":1},"end":{"line":55,"column":2}},"loc":{"start":{"line":55,"column":20},"end":{"line":57,"column":2}},"line":55},"5":{"name":"(anonymous_5)","decl":{"start":{"line":59,"column":1},"end":{"line":59,"column":2}},"loc":{"start":{"line":59,"column":19},"end":{"line":77,"column":2}},"line":59},"6":{"name":"(anonymous_6)","decl":{"start":{"line":63,"column":9},"end":{"line":63,"column":10}},"loc":{"start":{"line":63,"column":15},"end":{"line":63,"column":37}},"line":63},"7":{"name":"(anonymous_7)","decl":{"start":{"line":64,"column":9},"end":{"line":64,"column":10}},"loc":{"start":{"line":64,"column":17},"end":{"line":64,"column":80}},"line":64},"8":{"name":"(anonymous_8)","decl":{"start":{"line":65,"column":9},"end":{"line":65,"column":10}},"loc":{"start":{"line":65,"column":17},"end":{"line":76,"column":4}},"line":65},"9":{"name":"(anonymous_9)","decl":{"start":{"line":79,"column":1},"end":{"line":79,"column":2}},"loc":{"start":{"line":79,"column":22},"end":{"line":103,"column":2}},"line":79},"10":{"name":"(anonymous_10)","decl":{"start":{"line":92,"column":9},"end":{"line":92,"column":10}},"loc":{"start":{"line":92,"column":15},"end":{"line":100,"column":4}},"line":92},"11":{"name":"(anonymous_11)","decl":{"start":{"line":101,"column":9},"end":{"line":101,"column":10}},"loc":{"start":{"line":101,"column":18},"end":{"line":101,"column":52}},"line":101},"12":{"name":"(anonymous_12)","decl":{"start":{"line":102,"column":9},"end":{"line":102,"column":10}},"loc":{"start":{"line":102,"column":15},"end":{"line":102,"column":19}},"line":102},"13":{"name":"(anonymous_13)","decl":{"start":{"line":105,"column":1},"end":{"line":105,"column":2}},"loc":{"start":{"line":105,"column":13},"end":{"line":110,"column":2}},"line":105},"14":{"name":"(anonymous_14)","decl":{"start":{"line":109,"column":9},"end":{"line":109,"column":10}},"loc":{"start":{"line":109,"column":15},"end":{"line":109,"column":40}},"line":109},"15":{"name":"(anonymous_15)","decl":{"start":{"line":112,"column":1},"end":{"line":112,"column":2}},"loc":{"start":{"line":112,"column":9},"end":{"line":116,"column":2}},"line":112},"16":{"name":"(anonymous_16)","decl":{"start":{"line":115,"column":9},"end":{"line":115,"column":10}},"loc":{"start":{"line":115,"column":15},"end":{"line":115,"column":28}},"line":115}},"branchMap":{"0":{"loc":{"start":{"line":22,"column":1},"end":{"line":25,"column":2}},"type":"if","locations":[{"start":{"line":22,"column":1},"end":{"line":25,"column":2}},{"start":{"line":22,"column":1},"end":{"line":25,"column":2}}],"line":22},"1":{"loc":{"start":{"line":22,"column":5},"end":{"line":22,"column":35}},"type":"binary-expr","locations":[{"start":{"line":22,"column":5},"end":{"line":22,"column":20}},{"start":{"line":22,"column":24},"end":{"line":22,"column":35}}],"line":22},"2":{"loc":{"start":{"line":23,"column":18},"end":{"line":23,"column":66}},"type":"binary-expr","locations":[{"start":{"line":23,"column":18},"end":{"line":23,"column":33}},{"start":{"line":23,"column":37},"end":{"line":23,"column":66}}],"line":23},"3":{"loc":{"start":{"line":39,"column":3},"end":{"line":39,"column":44}},"type":"cond-expr","locations":[{"start":{"line":39,"column":31},"end":{"line":39,"column":38}},{"start":{"line":39,"column":41},"end":{"line":39,"column":44}}],"line":39},"4":{"loc":{"start":{"line":43,"column":2},"end":{"line":46,"column":3}},"type":"if","locations":[{"start":{"line":43,"column":2},"end":{"line":46,"column":3}},{"start":{"line":43,"column":2},"end":{"line":46,"column":3}}],"line":43},"5":{"loc":{"start":{"line":48,"column":2},"end":{"line":50,"column":3}},"type":"if","locations":[{"start":{"line":48,"column":2},"end":{"line":50,"column":3}},{"start":{"line":48,"column":2},"end":{"line":50,"column":3}}],"line":48},"6":{"loc":{"start":{"line":64,"column":17},"end":{"line":64,"column":80}},"type":"cond-expr","locations":[{"start":{"line":64,"column":46},"end":{"line":64,"column":73}},{"start":{"line":64,"column":76},"end":{"line":64,"column":80}}],"line":64},"7":{"loc":{"start":{"line":66,"column":4},"end":{"line":68,"column":5}},"type":"if","locations":[{"start":{"line":66,"column":4},"end":{"line":68,"column":5}},{"start":{"line":66,"column":4},"end":{"line":68,"column":5}}],"line":66},"8":{"loc":{"start":{"line":66,"column":8},"end":{"line":66,"column":43}},"type":"binary-expr","locations":[{"start":{"line":66,"column":8},"end":{"line":66,"column":26}},{"start":{"line":66,"column":30},"end":{"line":66,"column":43}}],"line":66},"9":{"loc":{"start":{"line":70,"column":4},"end":{"line":73,"column":5}},"type":"if","locations":[{"start":{"line":70,"column":4},"end":{"line":73,"column":5}},{"start":{"line":70,"column":4},"end":{"line":73,"column":5}}],"line":70},"10":{"loc":{"start":{"line":70,"column":8},"end":{"line":70,"column":69}},"type":"binary-expr","locations":[{"start":{"line":70,"column":8},"end":{"line":70,"column":40}},{"start":{"line":70,"column":44},"end":{"line":70,"column":69}}],"line":70},"11":{"loc":{"start":{"line":75,"column":11},"end":{"line":75,"column":55}},"type":"cond-expr","locations":[{"start":{"line":75,"column":38},"end":{"line":75,"column":42}},{"start":{"line":75,"column":45},"end":{"line":75,"column":55}}],"line":75},"12":{"loc":{"start":{"line":75,"column":12},"end":{"line":75,"column":34}},"type":"binary-expr","locations":[{"start":{"line":75,"column":12},"end":{"line":75,"column":19}},{"start":{"line":75,"column":23},"end":{"line":75,"column":34}}],"line":75},"13":{"loc":{"start":{"line":81,"column":2},"end":{"line":83,"column":3}},"type":"if","locations":[{"start":{"line":81,"column":2},"end":{"line":83,"column":3}},{"start":{"line":81,"column":2},"end":{"line":83,"column":3}}],"line":81},"14":{"loc":{"start":{"line":85,"column":2},"end":{"line":87,"column":3}},"type":"if","locations":[{"start":{"line":85,"column":2},"end":{"line":87,"column":3}},{"start":{"line":85,"column":2},"end":{"line":87,"column":3}}],"line":85},"15":{"loc":{"start":{"line":93,"column":20},"end":{"line":93,"column":73}},"type":"cond-expr","locations":[{"start":{"line":93,"column":49},"end":{"line":93,"column":65}},{"start":{"line":93,"column":69},"end":{"line":93,"column":73}}],"line":93},"16":{"loc":{"start":{"line":94,"column":4},"end":{"line":96,"column":5}},"type":"if","locations":[{"start":{"line":94,"column":4},"end":{"line":96,"column":5}},{"start":{"line":94,"column":4},"end":{"line":96,"column":5}}],"line":94}},"s":{"0":1,"1":1,"2":1,"3":0,"4":1,"5":3,"6":3,"7":2,"8":2,"9":1,"10":197,"11":197,"12":197,"13":3,"14":3,"15":197,"16":188,"17":1,"18":197,"19":95,"20":46,"21":46,"22":46,"23":46,"24":46,"25":46,"26":9,"27":37,"28":5,"29":5,"30":32,"31":39,"32":39,"33":34,"34":39,"35":1,"36":39,"37":39,"38":39,"39":39,"40":1,"41":38,"42":38,"43":38,"44":38,"45":10,"46":10,"47":10,"48":10,"49":163,"50":163,"51":163,"52":1},"f":{"0":0,"1":3,"2":197,"3":1,"4":95,"5":46,"6":46,"7":46,"8":46,"9":39,"10":39,"11":38,"12":38,"13":10,"14":10,"15":163,"16":163},"b":{"0":[2,1],"1":[3,3],"2":[2,2],"3":[2,195],"4":[3,194],"5":[188,9],"6":[37,9],"7":[9,37],"8":[46,37],"9":[5,32],"10":[37,13],"11":[1,31],"12":[32,1],"13":[34,5],"14":[1,38],"15":[6,33],"16":[1,38]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"a1f9f50840413fbf8dec11cc75e741387da8a6d0","contentHash":"0ecb4ae8fe157ca1a77008538c0b536709aa7c13d364d4266adea5319bee04f1"}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":"67b1f344-0eec-41a3-a665-c824c346e898","pid":4476,"argv":["/Users/jaredwray/.nvm/versions/node/v16.13.1/bin/node","/Users/jaredwray/src/github.com/jaredwray/keyv/node_modules/update-notifier/check.js","{\"pkg\":{\"name\":\"ava\",\"version\":\"3.15.0\"},\"distTag\":\"latest\"}"],"execArgv":[],"cwd":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/keyv","time":1643754172416,"ppid":4475,"coverageFilename":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/keyv/.nyc_output/17c338d1-cd21-4d2f-9d97-398f18a945cf.json","externalId":"","uuid":"17c338d1-cd21-4d2f-9d97-398f18a945cf","files":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":null,"pid":4475,"argv":["/Users/jaredwray/.nvm/versions/node/v16.13.1/bin/node","/Users/jaredwray/src/github.com/jaredwray/keyv/packages/keyv/node_modules/.bin/ava","--serial"],"execArgv":[],"cwd":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/keyv","time":1643754172273,"ppid":4474,"coverageFilename":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/keyv/.nyc_output/67b1f344-0eec-41a3-a665-c824c346e898.json","externalId":"","uuid":"67b1f344-0eec-41a3-a665-c824c346e898","files":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":"67b1f344-0eec-41a3-a665-c824c346e898","pid":4477,"argv":["/Users/jaredwray/.nvm/versions/node/v16.13.1/bin/node","/Users/jaredwray/src/github.com/jaredwray/keyv/node_modules/ava/lib/worker/subprocess.js"],"execArgv":[],"cwd":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/keyv","time":1643754172556,"ppid":4475,"coverageFilename":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/keyv/.nyc_output/adb04494-7d0a-443f-9130-94b19c3fa19c.json","externalId":"","uuid":"adb04494-7d0a-443f-9130-94b19c3fa19c","files":["/Users/jaredwray/src/github.com/jaredwray/keyv/packages/keyv/src/index.js"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"processes":{"17c338d1-cd21-4d2f-9d97-398f18a945cf":{"parent":"67b1f344-0eec-41a3-a665-c824c346e898","children":[]},"67b1f344-0eec-41a3-a665-c824c346e898":{"parent":null,"children":["17c338d1-cd21-4d2f-9d97-398f18a945cf","adb04494-7d0a-443f-9130-94b19c3fa19c"]},"adb04494-7d0a-443f-9130-94b19c3fa19c":{"parent":"67b1f344-0eec-41a3-a665-c824c346e898","children":[]}},"files":{"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/keyv/src/index.js":["adb04494-7d0a-443f-9130-94b19c3fa19c"]},"externalIds":{}}
|
package/test/test.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
const test = require('ava');
|
|
2
|
-
const { default: keyvTestSuite, keyvOfficialTests } = require('@keyv/test-suite');
|
|
3
|
-
const Keyv = require('this');
|
|
4
|
-
const tk = require('timekeeper');
|
|
5
|
-
const KeyvSqlite = require('@keyv/sqlite');
|
|
6
|
-
|
|
7
|
-
keyvOfficialTests(test, Keyv, 'sqlite://test/testdb.sqlite', 'sqlite://non/existent/database.sqlite');
|
|
8
|
-
const store = () => new KeyvSqlite({ uri: 'sqlite://test/testdb.sqlite', busyTimeout: 3000 });
|
|
9
|
-
keyvTestSuite(test, Keyv, store);
|
|
10
|
-
|
|
11
|
-
test.serial('Keyv is a class', t => {
|
|
12
|
-
t.is(typeof Keyv, 'function');
|
|
13
|
-
t.throws(() => Keyv()); // eslint-disable-line new-cap
|
|
14
|
-
t.notThrows(() => new Keyv());
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test.serial('Keyv accepts storage adapters', async t => {
|
|
18
|
-
const store = new Map();
|
|
19
|
-
const keyv = new Keyv({ store });
|
|
20
|
-
t.is(store.size, 0);
|
|
21
|
-
await keyv.set('foo', 'bar');
|
|
22
|
-
t.is(await keyv.get('foo'), 'bar');
|
|
23
|
-
t.is(store.size, 1);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test.serial('Keyv passes tll info to stores', async t => {
|
|
27
|
-
t.plan(1);
|
|
28
|
-
const store = new Map();
|
|
29
|
-
const storeSet = store.set;
|
|
30
|
-
store.set = (key, value, ttl) => {
|
|
31
|
-
t.is(ttl, 100);
|
|
32
|
-
storeSet.call(store, key, value, ttl);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const keyv = new Keyv({ store });
|
|
36
|
-
await keyv.set('foo', 'bar', 100);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test.serial('Keyv respects default tll option', async t => {
|
|
40
|
-
const store = new Map();
|
|
41
|
-
const keyv = new Keyv({ store, ttl: 100 });
|
|
42
|
-
await keyv.set('foo', 'bar');
|
|
43
|
-
t.is(await keyv.get('foo'), 'bar');
|
|
44
|
-
tk.freeze(Date.now() + 150);
|
|
45
|
-
t.is(await keyv.get('foo'), undefined);
|
|
46
|
-
t.is(store.size, 0);
|
|
47
|
-
tk.reset();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test.serial('.set(key, val, ttl) overwrites default tll option', async t => {
|
|
51
|
-
const startTime = Date.now();
|
|
52
|
-
tk.freeze(startTime);
|
|
53
|
-
const store = new Map();
|
|
54
|
-
const keyv = new Keyv({ store, ttl: 200 });
|
|
55
|
-
await keyv.set('foo', 'bar');
|
|
56
|
-
await keyv.set('fizz', 'buzz', 100);
|
|
57
|
-
await keyv.set('ping', 'pong', 300);
|
|
58
|
-
t.is(await keyv.get('foo'), 'bar');
|
|
59
|
-
t.is(await keyv.get('fizz'), 'buzz');
|
|
60
|
-
t.is(await keyv.get('ping'), 'pong');
|
|
61
|
-
tk.freeze(startTime + 150);
|
|
62
|
-
t.is(await keyv.get('foo'), 'bar');
|
|
63
|
-
t.is(await keyv.get('fizz'), undefined);
|
|
64
|
-
t.is(await keyv.get('ping'), 'pong');
|
|
65
|
-
tk.freeze(startTime + 250);
|
|
66
|
-
t.is(await keyv.get('foo'), undefined);
|
|
67
|
-
t.is(await keyv.get('ping'), 'pong');
|
|
68
|
-
tk.freeze(startTime + 350);
|
|
69
|
-
t.is(await keyv.get('ping'), undefined);
|
|
70
|
-
tk.reset();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test.serial('.set(key, val, ttl) where ttl is "0" overwrites default tll option and sets key to never expire', async t => {
|
|
74
|
-
const startTime = Date.now();
|
|
75
|
-
tk.freeze(startTime);
|
|
76
|
-
const store = new Map();
|
|
77
|
-
const keyv = new Keyv({ store, ttl: 200 });
|
|
78
|
-
await keyv.set('foo', 'bar', 0);
|
|
79
|
-
t.is(await keyv.get('foo'), 'bar');
|
|
80
|
-
tk.freeze(startTime + 250);
|
|
81
|
-
t.is(await keyv.get('foo'), 'bar');
|
|
82
|
-
tk.reset();
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test.serial('.get(key, {raw: true}) returns the raw object instead of the value', async t => {
|
|
86
|
-
const store = new Map();
|
|
87
|
-
const keyv = new Keyv({ store });
|
|
88
|
-
await keyv.set('foo', 'bar');
|
|
89
|
-
const value = await keyv.get('foo');
|
|
90
|
-
const rawObject = await keyv.get('foo', { raw: true });
|
|
91
|
-
t.is(value, 'bar');
|
|
92
|
-
t.is(rawObject.value, 'bar');
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test.serial('Keyv uses custom serializer when provided instead of json-buffer', async t => {
|
|
96
|
-
t.plan(3);
|
|
97
|
-
const store = new Map();
|
|
98
|
-
const serialize = data => {
|
|
99
|
-
t.pass();
|
|
100
|
-
return JSON.stringify(data);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const deserialize = data => {
|
|
104
|
-
t.pass();
|
|
105
|
-
return JSON.parse(data);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const keyv = new Keyv({ store, serialize, deserialize });
|
|
109
|
-
await keyv.set('foo', 'bar');
|
|
110
|
-
t.is(await keyv.get('foo'), 'bar');
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test.serial('Keyv supports async serializer/deserializer', async t => {
|
|
114
|
-
t.plan(3);
|
|
115
|
-
const store = new Map();
|
|
116
|
-
|
|
117
|
-
const serialize = async data => {
|
|
118
|
-
t.pass();
|
|
119
|
-
return JSON.stringify(data);
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const deserialize = async data => {
|
|
123
|
-
t.pass();
|
|
124
|
-
return JSON.parse(data);
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
const keyv = new Keyv({ store, serialize, deserialize });
|
|
128
|
-
await keyv.set('foo', 'bar');
|
|
129
|
-
t.is(await keyv.get('foo'), 'bar');
|
|
130
|
-
});
|
package/test/testdb.sqlite
DELETED
|
Binary file
|