@keyv/mongo 1.2.3 → 2.1.5
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/README.md +1 -1
- package/package.json +67 -58
- package/src/index.d.ts +37 -0
- package/src/index.js +316 -29
- package/.nyc_output/75d5eb8a-e710-4b9c-b31b-a01057405bbb.json +0 -1
- package/.nyc_output/9d2bad29-9c8d-4010-8038-b67b4271b6a5.json +0 -1
- package/.nyc_output/processinfo/75d5eb8a-e710-4b9c-b31b-a01057405bbb.json +0 -1
- package/.nyc_output/processinfo/9d2bad29-9c8d-4010-8038-b67b4271b6a5.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/test/test.js +0 -44
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> MongoDB storage adapter for Keyv
|
|
4
4
|
|
|
5
|
-
[](https://github.com/jaredwray/keyv/actions/workflows/tests.yaml)
|
|
6
6
|
[](https://codecov.io/gh/jaredwray/keyv)
|
|
7
7
|
[](https://www.npmjs.com/package/@keyv/mongo)
|
|
8
8
|
|
package/package.json
CHANGED
|
@@ -1,60 +1,69 @@
|
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
2
|
+
"name": "@keyv/mongo",
|
|
3
|
+
"version": "2.1.5",
|
|
4
|
+
"description": "MongoDB storage adapter for Keyv",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "xo && nyc ava",
|
|
8
|
+
"coverage": "nyc report --reporter=text-lcov > coverage.lcov",
|
|
9
|
+
"clean": "rm -rf node_modules && rm -rf .nyc_output && rm -rf coverage.lcov"
|
|
10
|
+
},
|
|
11
|
+
"xo": {
|
|
12
|
+
"extends": "xo-lukechilds",
|
|
13
|
+
"rules": {
|
|
14
|
+
"unicorn/prefer-module": 0,
|
|
15
|
+
"unicorn/no-array-reduce": 0,
|
|
16
|
+
"unicorn/prefer-object-from-entries": 0
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"ava": {
|
|
20
|
+
"require": [
|
|
21
|
+
"requirable"
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/jaredwray/keyv.git"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"mongo",
|
|
30
|
+
"mongodb",
|
|
31
|
+
"keyv",
|
|
32
|
+
"storage",
|
|
33
|
+
"adapter",
|
|
34
|
+
"key",
|
|
35
|
+
"value",
|
|
36
|
+
"store",
|
|
37
|
+
"cache",
|
|
38
|
+
"ttl"
|
|
39
|
+
],
|
|
40
|
+
"author": "Jared Wray <me@jaredwray.com> (https://jaredwray.com)",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/jaredwray/keyv/issues"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/jaredwray/keyv",
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"mongodb": "^4.4.1",
|
|
48
|
+
"pify": "^5.0.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@keyv/test-suite": "*",
|
|
52
|
+
"ava": "^4.1.0",
|
|
53
|
+
"eslint-config-xo-lukechilds": "^1.0.1",
|
|
54
|
+
"keyv": "*",
|
|
55
|
+
"nyc": "^15.1.0",
|
|
56
|
+
"requirable": "^1.0.5",
|
|
57
|
+
"this": "^1.1.0",
|
|
58
|
+
"tsd": "^0.20.0",
|
|
59
|
+
"typescript": "^4.6.3",
|
|
60
|
+
"xo": "^0.48.0"
|
|
61
|
+
},
|
|
62
|
+
"tsd" : {
|
|
63
|
+
"directory" : "test"
|
|
64
|
+
},
|
|
65
|
+
"types": "./src/index.d.ts",
|
|
66
|
+
"files": [
|
|
67
|
+
"src"
|
|
68
|
+
]
|
|
60
69
|
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import EventEmitter from 'node:events';
|
|
2
|
+
import GridFSBucket from 'mongodb';
|
|
3
|
+
|
|
4
|
+
declare class KeyvMongo extends EventEmitter {
|
|
5
|
+
readonly ttlSupport: false;
|
|
6
|
+
opts: Record<string, any>;
|
|
7
|
+
connect: Promise<any>;
|
|
8
|
+
db: import('mongodb').Db;
|
|
9
|
+
bucket: GridFSBucket;
|
|
10
|
+
store: import('mongodb').Collection<import('bson').Document>;
|
|
11
|
+
constructor(options?: string | KeyvMongo.Options);
|
|
12
|
+
get(key: string): Promise<string | undefined>;
|
|
13
|
+
getMany(keys: string[]): Promise<string[] | undefined>;
|
|
14
|
+
set(key: string, value: string | undefined): Promise<any>;
|
|
15
|
+
delete(key: string): boolean;
|
|
16
|
+
deleteMany(keys: string[]): boolean;
|
|
17
|
+
clearExpired(): false | Promise<boolean>;
|
|
18
|
+
clearUnusedFor(seconds: any): false | Promise<boolean>;
|
|
19
|
+
clear(): Promise<void>;
|
|
20
|
+
iterator(namespace: string | undefined): AsyncGenerator<any, void, any>;
|
|
21
|
+
has(key: string): boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export = KeyvMongo;
|
|
25
|
+
|
|
26
|
+
declare namespace KeyvMongo {
|
|
27
|
+
interface Options {
|
|
28
|
+
url?: string | undefined;
|
|
29
|
+
collection?: string | undefined;
|
|
30
|
+
namespace?: string | undefined;
|
|
31
|
+
serialize?: any;
|
|
32
|
+
deserialize?: any;
|
|
33
|
+
useGridFS?: boolean | undefined;
|
|
34
|
+
uri?: string | undefined;
|
|
35
|
+
dialect?: string | undefined;
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
// @ts-ignore
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
const EventEmitter = require('events');
|
|
4
|
-
const
|
|
5
|
+
const { Buffer } = require('buffer');
|
|
6
|
+
const mongoClient = require('mongodb').MongoClient;
|
|
7
|
+
const { GridFSBucket } = require('mongodb');
|
|
5
8
|
const pify = require('pify');
|
|
6
9
|
|
|
10
|
+
const keyvMongoKeys = new Set(['url', 'collection', 'namespace', 'serialize', 'deserialize', 'uri', 'useGridFS', 'dialect']);
|
|
7
11
|
class KeyvMongo extends EventEmitter {
|
|
8
12
|
constructor(url, options) {
|
|
9
13
|
super();
|
|
@@ -14,46 +18,213 @@ class KeyvMongo extends EventEmitter {
|
|
|
14
18
|
}
|
|
15
19
|
|
|
16
20
|
if (url.uri) {
|
|
17
|
-
url =
|
|
21
|
+
url = { url: url.uri, ...url };
|
|
18
22
|
}
|
|
19
23
|
|
|
20
|
-
this.opts =
|
|
24
|
+
this.opts = {
|
|
21
25
|
url: 'mongodb://127.0.0.1:27017',
|
|
22
26
|
collection: 'keyv',
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
...url,
|
|
28
|
+
...options,
|
|
29
|
+
};
|
|
25
30
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
const mongoOptions = Object.fromEntries(
|
|
32
|
+
Object.entries(this.opts).filter(
|
|
33
|
+
([k]) => !keyvMongoKeys.has(k),
|
|
34
|
+
),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
this.opts = Object.fromEntries(
|
|
38
|
+
Object.entries(this.opts).filter(
|
|
39
|
+
([k]) => keyvMongoKeys.has(k),
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
// Implementation from sql by lukechilds,
|
|
44
|
+
this.connect = new Promise(resolve => {
|
|
45
|
+
mongoClient.connect(this.opts.url, mongoOptions
|
|
46
|
+
, (error, client) => {
|
|
47
|
+
if (error) {
|
|
48
|
+
return this.emit('error', error);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
this.db = client.db(this.opts.db);
|
|
52
|
+
if (this.opts.useGridFS) {
|
|
53
|
+
this.bucket = new GridFSBucket(this.db, {
|
|
54
|
+
readPreference: this.opts.readPreference || 'primary',
|
|
55
|
+
bucketName: this.opts.collection,
|
|
56
|
+
});
|
|
57
|
+
this.store = this.db.collection(this.opts.collection + '.files');
|
|
58
|
+
this.store.createIndex({
|
|
59
|
+
filename: 'hashed',
|
|
60
|
+
});
|
|
61
|
+
this.store.createIndex({
|
|
62
|
+
uploadDate: -1,
|
|
63
|
+
});
|
|
64
|
+
this.store.createIndex({
|
|
65
|
+
'metadata.expiresAt': 1,
|
|
66
|
+
});
|
|
67
|
+
this.store.createIndex({
|
|
68
|
+
'metadata.lastAccessed': 1,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
for (const method of [
|
|
72
|
+
'updateOne',
|
|
73
|
+
'count',
|
|
74
|
+
]) {
|
|
75
|
+
this.store[method] = pify(this.store[method].bind(this.store));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
for (const method of [
|
|
79
|
+
'find',
|
|
80
|
+
'drop',
|
|
81
|
+
]) {
|
|
82
|
+
this.bucket[method] = pify(this.bucket[method].bind(this.bucket));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
resolve({ bucket: this.bucket, store: this.store, db: this.db });
|
|
86
|
+
} else {
|
|
87
|
+
this.store = this.db.collection(this.opts.collection);
|
|
88
|
+
this.store.createIndex(
|
|
89
|
+
{ key: 1 },
|
|
90
|
+
{
|
|
91
|
+
unique: true,
|
|
92
|
+
background: true,
|
|
93
|
+
},
|
|
94
|
+
);
|
|
95
|
+
this.store.createIndex(
|
|
96
|
+
{ expiresAt: 1 },
|
|
97
|
+
{
|
|
98
|
+
expireAfterSeconds: 0,
|
|
99
|
+
background: true,
|
|
100
|
+
},
|
|
101
|
+
);
|
|
39
102
|
|
|
40
|
-
|
|
103
|
+
for (const method of [
|
|
104
|
+
'updateOne',
|
|
105
|
+
'findOne',
|
|
106
|
+
'deleteOne',
|
|
107
|
+
'deleteMany',
|
|
108
|
+
'count',
|
|
109
|
+
]) {
|
|
110
|
+
this.store[method] = pify(this.store[method].bind(this.store));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
resolve(this.store);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
41
117
|
}
|
|
42
118
|
|
|
43
119
|
get(key) {
|
|
44
|
-
|
|
45
|
-
.then(
|
|
46
|
-
|
|
120
|
+
if (this.opts.useGridFS) {
|
|
121
|
+
return this.connect.then(client => {
|
|
122
|
+
client.store.updateOne({
|
|
123
|
+
filename: key,
|
|
124
|
+
}, {
|
|
125
|
+
$set: {
|
|
126
|
+
'metadata.lastAccessed': new Date(),
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const stream = client.bucket.openDownloadStreamByName(key);
|
|
131
|
+
return new Promise(resolve => {
|
|
132
|
+
let resp = [];
|
|
133
|
+
stream.on('error', () => resolve());
|
|
134
|
+
|
|
135
|
+
stream.on('end', () => {
|
|
136
|
+
resp = Buffer.concat(resp).toString('utf-8');
|
|
137
|
+
resolve(resp);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
stream.on('data', chunk => {
|
|
141
|
+
resp.push(chunk);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return this.connect.then(store =>
|
|
148
|
+
store.findOne({ key: { $eq: key } }).then(doc => {
|
|
149
|
+
if (!doc) {
|
|
47
150
|
return undefined;
|
|
48
151
|
}
|
|
49
152
|
|
|
50
153
|
return doc.value;
|
|
51
|
-
})
|
|
154
|
+
}),
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
getMany(keys) {
|
|
159
|
+
if (this.opts.useGridFS) {
|
|
160
|
+
const promises = [];
|
|
161
|
+
for (const key of keys) {
|
|
162
|
+
promises.push(this.get(key));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return Promise.allSettled(promises)
|
|
166
|
+
.then(values => {
|
|
167
|
+
const data = [];
|
|
168
|
+
for (const value of values) {
|
|
169
|
+
data.push(value.value);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return data.every(x => x === undefined) ? [] : data;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const results = [...keys];
|
|
177
|
+
return this.connect.then(store =>
|
|
178
|
+
store.s.db.collection(this.opts.collection)
|
|
179
|
+
.find({ key: { $in: keys } })
|
|
180
|
+
.project({ _id: 0, value: 1, key: 1 })
|
|
181
|
+
.toArray().then(values => {
|
|
182
|
+
let i = 0;
|
|
183
|
+
for (const key of keys) {
|
|
184
|
+
const rowIndex = values.findIndex(row => row.key === key);
|
|
185
|
+
|
|
186
|
+
if (rowIndex > -1) {
|
|
187
|
+
results[i] = values[rowIndex].value;
|
|
188
|
+
} else {
|
|
189
|
+
results[i] = undefined;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
i++;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return results.every(x => x === undefined) ? [] : results;
|
|
196
|
+
}),
|
|
197
|
+
);
|
|
52
198
|
}
|
|
53
199
|
|
|
54
200
|
set(key, value, ttl) {
|
|
55
|
-
const expiresAt =
|
|
56
|
-
|
|
201
|
+
const expiresAt = typeof ttl === 'number' ? new Date(Date.now() + ttl) : null;
|
|
202
|
+
|
|
203
|
+
if (this.opts.useGridFS) {
|
|
204
|
+
return this.connect.then(client => {
|
|
205
|
+
const stream = client.bucket.openUploadStream(key, {
|
|
206
|
+
metadata: {
|
|
207
|
+
expiresAt,
|
|
208
|
+
lastAccessed: new Date(),
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
return new Promise(resolve => {
|
|
213
|
+
stream.on('finish', () => {
|
|
214
|
+
resolve(stream);
|
|
215
|
+
});
|
|
216
|
+
stream.end(value);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return this.connect.then(store =>
|
|
222
|
+
store.updateOne(
|
|
223
|
+
{ key: { $eq: key } },
|
|
224
|
+
{ $set: { key, value, expiresAt } },
|
|
225
|
+
{ upsert: true },
|
|
226
|
+
),
|
|
227
|
+
);
|
|
57
228
|
}
|
|
58
229
|
|
|
59
230
|
delete(key) {
|
|
@@ -61,13 +232,129 @@ class KeyvMongo extends EventEmitter {
|
|
|
61
232
|
return Promise.resolve(false);
|
|
62
233
|
}
|
|
63
234
|
|
|
64
|
-
|
|
65
|
-
.then(
|
|
235
|
+
if (this.opts.useGridFS) {
|
|
236
|
+
return this.connect.then(client => {
|
|
237
|
+
const connection = client.db;
|
|
238
|
+
const bucket = new GridFSBucket(connection, {
|
|
239
|
+
bucketName: this.opts.collection,
|
|
240
|
+
});
|
|
241
|
+
return bucket.find({ filename: key }).toArray()
|
|
242
|
+
.then(files => client.bucket.delete(files[0]._id).then(() => true))
|
|
243
|
+
.catch(() => false);
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return this.connect.then(store =>
|
|
248
|
+
store
|
|
249
|
+
.deleteOne({ key: { $eq: key } })
|
|
250
|
+
.then(object => object.deletedCount > 0),
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
deleteMany(keys) {
|
|
255
|
+
if (this.opts.useGridFS) {
|
|
256
|
+
return this.connect.then(client => {
|
|
257
|
+
const connection = client.db;
|
|
258
|
+
const bucket = new GridFSBucket(connection, {
|
|
259
|
+
bucketName: this.opts.collection,
|
|
260
|
+
});
|
|
261
|
+
return bucket.find({ filename: { $in: keys } }).toArray()
|
|
262
|
+
.then(
|
|
263
|
+
files => {
|
|
264
|
+
if (files.length === 0) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
files.map(file => client.bucket.delete(file._id));
|
|
269
|
+
return true;
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return this.connect.then(store =>
|
|
275
|
+
store
|
|
276
|
+
.deleteMany({ key: { $in: keys } })
|
|
277
|
+
.then(object => object.deletedCount > 0),
|
|
278
|
+
);
|
|
66
279
|
}
|
|
67
280
|
|
|
68
281
|
clear() {
|
|
69
|
-
|
|
70
|
-
.then(() => undefined);
|
|
282
|
+
if (this.opts.useGridFS) {
|
|
283
|
+
return this.connect.then(client => client.bucket.drop().then(() => undefined));
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return this.connect.then(store =>
|
|
287
|
+
store
|
|
288
|
+
.deleteMany({
|
|
289
|
+
key: { $regex: this.namespace ? `^${this.namespace}:*` : '' },
|
|
290
|
+
})
|
|
291
|
+
.then(() => undefined),
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
clearExpired() {
|
|
296
|
+
if (!this.opts.useGridFS) {
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return this.connect.then(client => {
|
|
301
|
+
const connection = client.db;
|
|
302
|
+
const bucket = new GridFSBucket(connection, {
|
|
303
|
+
bucketName: this.opts.collection,
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
return bucket.find({
|
|
307
|
+
'metadata.expiresAt': {
|
|
308
|
+
$lte: new Date(Date.now()),
|
|
309
|
+
},
|
|
310
|
+
}).toArray()
|
|
311
|
+
.then(expiredFiles => Promise.all(expiredFiles.map(file => client.bucket.delete(file._id))).then(() => true));
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
clearUnusedFor(seconds) {
|
|
316
|
+
if (!this.opts.useGridFS) {
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return this.connect.then(client => {
|
|
321
|
+
const connection = client.db;
|
|
322
|
+
const bucket = new GridFSBucket(connection, {
|
|
323
|
+
bucketName: this.opts.collection,
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
return bucket.find({
|
|
327
|
+
'metadata.lastAccessed': {
|
|
328
|
+
$lte: new Date(Date.now() - (seconds * 1000)),
|
|
329
|
+
},
|
|
330
|
+
}).toArray()
|
|
331
|
+
.then(lastAccessedFiles => Promise.all(lastAccessedFiles.map(file => client.bucket.delete(file._id))).then(() => true));
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
async * iterator(namespace) {
|
|
336
|
+
const iterator = await this.connect.then(store =>
|
|
337
|
+
store
|
|
338
|
+
.find({
|
|
339
|
+
key: new RegExp(`^${namespace ? namespace + ':' : '.*'}`),
|
|
340
|
+
})
|
|
341
|
+
.map(x => [x.key, x.value]),
|
|
342
|
+
);
|
|
343
|
+
yield * iterator;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
has(key) {
|
|
347
|
+
if (this.opts.useGridFS) {
|
|
348
|
+
return this.connect.then(client => client.store.count(
|
|
349
|
+
{ filename: { $eq: key } },
|
|
350
|
+
).then(doc => doc !== 0));
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
return this.connect.then(store =>
|
|
354
|
+
store.count(
|
|
355
|
+
{ key: { $eq: key } },
|
|
356
|
+
),
|
|
357
|
+
).then(doc => doc !== 0);
|
|
71
358
|
}
|
|
72
359
|
}
|
|
73
360
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/src/index.js":{"path":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/src/index.js","statementMap":{"0":{"start":{"line":3,"column":21},"end":{"line":3,"column":38}},"1":{"start":{"line":4,"column":16},"end":{"line":4,"column":34}},"2":{"start":{"line":5,"column":13},"end":{"line":5,"column":28}},"3":{"start":{"line":9,"column":2},"end":{"line":9,"column":10}},"4":{"start":{"line":10,"column":2},"end":{"line":10,"column":26}},"5":{"start":{"line":11,"column":2},"end":{"line":11,"column":18}},"6":{"start":{"line":12,"column":2},"end":{"line":14,"column":3}},"7":{"start":{"line":13,"column":3},"end":{"line":13,"column":17}},"8":{"start":{"line":16,"column":2},"end":{"line":18,"column":3}},"9":{"start":{"line":17,"column":3},"end":{"line":17,"column":46}},"10":{"start":{"line":20,"column":2},"end":{"line":23,"column":19}},"11":{"start":{"line":24,"column":2},"end":{"line":24,"column":35}},"12":{"start":{"line":26,"column":21},"end":{"line":26,"column":61}},"13":{"start":{"line":27,"column":2},"end":{"line":30,"column":5}},"14":{"start":{"line":31,"column":2},"end":{"line":34,"column":5}},"15":{"start":{"line":35,"column":2},"end":{"line":38,"column":9}},"16":{"start":{"line":36,"column":3},"end":{"line":36,"column":62}},"17":{"start":{"line":37,"column":3},"end":{"line":37,"column":17}},"18":{"start":{"line":40,"column":2},"end":{"line":40,"column":58}},"19":{"start":{"line":40,"column":31},"end":{"line":40,"column":56}},"20":{"start":{"line":44,"column":2},"end":{"line":51,"column":6}},"21":{"start":{"line":46,"column":4},"end":{"line":48,"column":5}},"22":{"start":{"line":47,"column":5},"end":{"line":47,"column":22}},"23":{"start":{"line":50,"column":4},"end":{"line":50,"column":21}},"24":{"start":{"line":55,"column":20},"end":{"line":55,"column":81}},"25":{"start":{"line":56,"column":2},"end":{"line":56,"column":91}},"26":{"start":{"line":60,"column":2},"end":{"line":62,"column":3}},"27":{"start":{"line":61,"column":3},"end":{"line":61,"column":33}},"28":{"start":{"line":64,"column":2},"end":{"line":65,"column":33}},"29":{"start":{"line":65,"column":19},"end":{"line":65,"column":31}},"30":{"start":{"line":69,"column":2},"end":{"line":70,"column":26}},"31":{"start":{"line":70,"column":15},"end":{"line":70,"column":24}},"32":{"start":{"line":74,"column":0},"end":{"line":74,"column":27}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":8,"column":1},"end":{"line":8,"column":2}},"loc":{"start":{"line":8,"column":27},"end":{"line":41,"column":2}},"line":8},"1":{"name":"(anonymous_1)","decl":{"start":{"line":35,"column":54},"end":{"line":35,"column":55}},"loc":{"start":{"line":35,"column":74},"end":{"line":38,"column":3}},"line":35},"2":{"name":"(anonymous_2)","decl":{"start":{"line":40,"column":22},"end":{"line":40,"column":23}},"loc":{"start":{"line":40,"column":31},"end":{"line":40,"column":56}},"line":40},"3":{"name":"(anonymous_3)","decl":{"start":{"line":43,"column":1},"end":{"line":43,"column":2}},"loc":{"start":{"line":43,"column":10},"end":{"line":52,"column":2}},"line":43},"4":{"name":"(anonymous_4)","decl":{"start":{"line":45,"column":9},"end":{"line":45,"column":10}},"loc":{"start":{"line":45,"column":16},"end":{"line":51,"column":4}},"line":45},"5":{"name":"(anonymous_5)","decl":{"start":{"line":54,"column":1},"end":{"line":54,"column":2}},"loc":{"start":{"line":54,"column":22},"end":{"line":57,"column":2}},"line":54},"6":{"name":"(anonymous_6)","decl":{"start":{"line":59,"column":1},"end":{"line":59,"column":2}},"loc":{"start":{"line":59,"column":13},"end":{"line":66,"column":2}},"line":59},"7":{"name":"(anonymous_7)","decl":{"start":{"line":65,"column":9},"end":{"line":65,"column":10}},"loc":{"start":{"line":65,"column":19},"end":{"line":65,"column":31}},"line":65},"8":{"name":"(anonymous_8)","decl":{"start":{"line":68,"column":1},"end":{"line":68,"column":2}},"loc":{"start":{"line":68,"column":9},"end":{"line":71,"column":2}},"line":68},"9":{"name":"(anonymous_9)","decl":{"start":{"line":70,"column":9},"end":{"line":70,"column":10}},"loc":{"start":{"line":70,"column":15},"end":{"line":70,"column":24}},"line":70}},"branchMap":{"0":{"loc":{"start":{"line":11,"column":8},"end":{"line":11,"column":17}},"type":"binary-expr","locations":[{"start":{"line":11,"column":8},"end":{"line":11,"column":11}},{"start":{"line":11,"column":15},"end":{"line":11,"column":17}}],"line":11},"1":{"loc":{"start":{"line":12,"column":2},"end":{"line":14,"column":3}},"type":"if","locations":[{"start":{"line":12,"column":2},"end":{"line":14,"column":3}},{"start":{"line":12,"column":2},"end":{"line":14,"column":3}}],"line":12},"2":{"loc":{"start":{"line":16,"column":2},"end":{"line":18,"column":3}},"type":"if","locations":[{"start":{"line":16,"column":2},"end":{"line":18,"column":3}},{"start":{"line":16,"column":2},"end":{"line":18,"column":3}}],"line":16},"3":{"loc":{"start":{"line":46,"column":4},"end":{"line":48,"column":5}},"type":"if","locations":[{"start":{"line":46,"column":4},"end":{"line":48,"column":5}},{"start":{"line":46,"column":4},"end":{"line":48,"column":5}}],"line":46},"4":{"loc":{"start":{"line":55,"column":20},"end":{"line":55,"column":81}},"type":"cond-expr","locations":[{"start":{"line":55,"column":48},"end":{"line":55,"column":74}},{"start":{"line":55,"column":77},"end":{"line":55,"column":81}}],"line":55},"5":{"loc":{"start":{"line":60,"column":2},"end":{"line":62,"column":3}},"type":"if","locations":[{"start":{"line":60,"column":2},"end":{"line":62,"column":3}},{"start":{"line":60,"column":2},"end":{"line":62,"column":3}}],"line":60}},"s":{"0":1,"1":1,"2":1,"3":157,"4":157,"5":157,"6":157,"7":154,"8":157,"9":1,"10":157,"11":157,"12":157,"13":157,"14":157,"15":157,"16":471,"17":471,"18":157,"19":0,"20":25,"21":25,"22":8,"23":17,"24":26,"25":26,"26":7,"27":1,"28":6,"29":6,"30":129,"31":129,"32":1},"f":{"0":157,"1":471,"2":0,"3":25,"4":25,"5":26,"6":7,"7":6,"8":129,"9":129},"b":{"0":[157,1],"1":[154,3],"2":[1,156],"3":[8,17],"4":[1,25],"5":[1,6]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"476cb42cd1352543dc6c059664b734698fa13176","contentHash":"de28073ec4cda2eeada2d5d2a61686fd7ca7e66537795de14b90ad61d1cd6a55"}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":"9d2bad29-9c8d-4010-8038-b67b4271b6a5","pid":73263,"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/mongo","time":1641658792943,"ppid":73262,"coverageFilename":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/.nyc_output/75d5eb8a-e710-4b9c-b31b-a01057405bbb.json","externalId":"","uuid":"75d5eb8a-e710-4b9c-b31b-a01057405bbb","files":["/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/src/index.js"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":null,"pid":73262,"argv":["/Users/jaredwray/.nvm/versions/node/v16.13.1/bin/node","/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/node_modules/.bin/ava"],"execArgv":[],"cwd":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo","time":1641658792716,"ppid":73261,"coverageFilename":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/.nyc_output/9d2bad29-9c8d-4010-8038-b67b4271b6a5.json","externalId":"","uuid":"9d2bad29-9c8d-4010-8038-b67b4271b6a5","files":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"processes":{"75d5eb8a-e710-4b9c-b31b-a01057405bbb":{"parent":"9d2bad29-9c8d-4010-8038-b67b4271b6a5","children":[]},"9d2bad29-9c8d-4010-8038-b67b4271b6a5":{"parent":null,"children":["75d5eb8a-e710-4b9c-b31b-a01057405bbb"]}},"files":{"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/src/index.js":["75d5eb8a-e710-4b9c-b31b-a01057405bbb"]},"externalIds":{}}
|
package/test/test.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
const test = require('ava');
|
|
2
|
-
const keyvTestSuite = require('@keyv/test-suite').default;
|
|
3
|
-
const Keyv = require('keyv');
|
|
4
|
-
const KeyvMongo = require('this');
|
|
5
|
-
|
|
6
|
-
const mongoURL = 'mongodb://127.0.0.1:27017';
|
|
7
|
-
|
|
8
|
-
const store = () => new KeyvMongo(mongoURL);
|
|
9
|
-
keyvTestSuite(test, Keyv, store);
|
|
10
|
-
|
|
11
|
-
test('default options', t => {
|
|
12
|
-
const store = new KeyvMongo();
|
|
13
|
-
t.deepEqual(store.opts, {
|
|
14
|
-
url: mongoURL,
|
|
15
|
-
collection: 'keyv',
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('default options with url.uri', t => {
|
|
20
|
-
const store = new KeyvMongo({ uri: mongoURL });
|
|
21
|
-
t.is(store.opts.uri, mongoURL);
|
|
22
|
-
t.is(store.opts.url, mongoURL);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('Collection option merges into default options', t => {
|
|
26
|
-
const store = new KeyvMongo({ collection: 'foo' });
|
|
27
|
-
t.deepEqual(store.opts, {
|
|
28
|
-
url: mongoURL,
|
|
29
|
-
collection: 'foo',
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('Collection option merges into default options if URL is passed', t => {
|
|
34
|
-
const store = new KeyvMongo(mongoURL, { collection: 'foo' });
|
|
35
|
-
t.deepEqual(store.opts, {
|
|
36
|
-
url: mongoURL,
|
|
37
|
-
collection: 'foo',
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('.delete() with no args doesn\'t empty the collection', async t => {
|
|
42
|
-
const store = new KeyvMongo('foo'); // Make sure we don't actually connect
|
|
43
|
-
t.false(await store.delete());
|
|
44
|
-
});
|