@keyv/mongo 1.1.0 → 1.2.3

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.
@@ -0,0 +1 @@
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"}}
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1 @@
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":[]}
@@ -0,0 +1 @@
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/README.md CHANGED
@@ -1,12 +1,12 @@
1
- # @keyv/mongo [<img width="100" align="right" src="https://rawgit.com/lukechilds/keyv/master/media/logo.svg" alt="keyv">](https://github.com/lukechilds/keyv)
1
+ # @keyv/mongo [<img width="100" align="right" src="https://jaredwray.com/images/keyv.svg" alt="keyv">](https://github.com/jaredwra/keyv)
2
2
 
3
3
  > MongoDB storage adapter for Keyv
4
4
 
5
- [![Build Status](https://travis-ci.org/lukechilds/keyv-mongo.svg?branch=master)](https://travis-ci.org/lukechilds/keyv-mongo)
6
- [![Coverage Status](https://coveralls.io/repos/github/lukechilds/keyv-mongo/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/keyv-mongo?branch=master)
5
+ [![build](https://github.com/jaredwray/keyv/actions/workflows/build.yaml/badge.svg)](https://github.com/jaredwray/keyv/actions/workflows/build.yaml)
6
+ [![codecov](https://codecov.io/gh/jaredwray/keyv/branch/master/graph/badge.svg?token=bRzR3RyOXZ)](https://codecov.io/gh/jaredwray/keyv)
7
7
  [![npm](https://img.shields.io/npm/v/@keyv/mongo.svg)](https://www.npmjs.com/package/@keyv/mongo)
8
8
 
9
- MongoDB storage adapter for [Keyv](https://github.com/lukechilds/keyv).
9
+ MongoDB storage adapter for [Keyv](https://github.com/jaredwray/keyv).
10
10
 
11
11
  Uses TTL indexes to automatically remove expired documents. However [MongoDB doesn't guarantee data will be deleted immediately upon expiration](https://docs.mongodb.com/manual/core/index-ttl/#timing-of-the-delete-operation), so expiry dates are revalidated in Keyv.
12
12
 
@@ -35,4 +35,4 @@ const keyv = new Keyv('mongodb://user:pass@localhost:27017/dbname', { collection
35
35
 
36
36
  ## License
37
37
 
38
- MIT © Luke Childs
38
+ MIT © Jared Wray & Luke Childs
package/package.json CHANGED
@@ -1,14 +1,20 @@
1
1
  {
2
2
  "name": "@keyv/mongo",
3
- "version": "1.1.0",
3
+ "version": "1.2.3",
4
4
  "description": "MongoDB storage adapter for Keyv",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
7
7
  "test": "xo && nyc ava",
8
- "coverage": "nyc report --reporter=text-lcov | coveralls"
8
+ "coverage": "nyc report --reporter=text-lcov > coverage.lcov",
9
+ "clean": "rm -rf node_modules && rm -rf .nyc_output && rm -rf coverage.lcov"
9
10
  },
10
11
  "xo": {
11
- "extends": "xo-lukechilds"
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
+ }
12
18
  },
13
19
  "ava": {
14
20
  "require": [
@@ -17,7 +23,7 @@
17
23
  },
18
24
  "repository": {
19
25
  "type": "git",
20
- "url": "git+https://github.com/lukechilds/keyv-mongo.git"
26
+ "url": "git+https://github.com/jaredwray/keyv.git"
21
27
  },
22
28
  "keywords": [
23
29
  "mongo",
@@ -31,26 +37,24 @@
31
37
  "cache",
32
38
  "ttl"
33
39
  ],
34
- "author": "Luke Childs <lukechilds123@gmail.com> (http://lukechilds.co.uk)",
40
+ "author": "Jared Wray <me@jaredwray.com> (https://jaredwray.com)",
35
41
  "license": "MIT",
36
42
  "bugs": {
37
- "url": "https://github.com/lukechilds/keyv-mongo/issues"
43
+ "url": "https://github.com/jaredwray/keyv/issues"
38
44
  },
39
- "homepage": "https://github.com/lukechilds/keyv-mongo",
45
+ "homepage": "https://github.com/jaredwray/keyv",
40
46
  "dependencies": {
41
- "mongojs": "2.5.0",
42
- "pify": "3.0.0"
47
+ "mongojs": "^3",
48
+ "pify": "^5.0.0"
43
49
  },
44
50
  "devDependencies": {
45
51
  "@keyv/test-suite": "*",
46
- "ava": "^0.25.0",
47
- "coveralls": "^3.0.0",
48
- "dotenv": "^6.2.0",
49
- "eslint-config-xo-lukechilds": "^1.0.0",
52
+ "ava": "^3.15.0",
53
+ "eslint-config-xo-lukechilds": "^1.0.1",
50
54
  "keyv": "*",
51
- "nyc": "^11.0.3",
52
- "requirable": "^1.0.1",
53
- "this": "^1.0.2",
54
- "xo": "^0.20.1"
55
+ "nyc": "^15.1.0",
56
+ "requirable": "^1.0.5",
57
+ "this": "^1.1.0",
58
+ "xo": "^0.47.0"
55
59
  }
56
60
  }
package/src/index.js CHANGED
@@ -5,37 +5,39 @@ const mongojs = require('mongojs');
5
5
  const pify = require('pify');
6
6
 
7
7
  class KeyvMongo extends EventEmitter {
8
- constructor(url, opts) {
8
+ constructor(url, options) {
9
9
  super();
10
10
  this.ttlSupport = false;
11
11
  url = url || {};
12
12
  if (typeof url === 'string') {
13
13
  url = { url };
14
14
  }
15
+
15
16
  if (url.uri) {
16
17
  url = Object.assign({ url: url.uri }, url);
17
18
  }
19
+
18
20
  this.opts = Object.assign({
19
21
  url: 'mongodb://127.0.0.1:27017',
20
- collection: 'keyv'
21
- }, url, opts);
22
+ collection: 'keyv',
23
+ }, url, options);
22
24
  this.db = mongojs(this.opts.url);
23
25
 
24
26
  const collection = this.db.collection(this.opts.collection);
25
27
  collection.createIndex({ key: 1 }, {
26
28
  unique: true,
27
- background: true
29
+ background: true,
28
30
  });
29
31
  collection.createIndex({ expiresAt: 1 }, {
30
32
  expireAfterSeconds: 0,
31
- background: true
33
+ background: true,
32
34
  });
33
- this.mongo = ['update', 'findOne', 'remove'].reduce((obj, method) => {
34
- obj[method] = pify(collection[method].bind(collection));
35
- return obj;
35
+ this.mongo = ['update', 'findOne', 'remove'].reduce((object, method) => {
36
+ object[method] = pify(collection[method].bind(collection));
37
+ return object;
36
38
  }, {});
37
39
 
38
- this.db.on('error', err => this.emit('error', err));
40
+ this.db.on('error', error => this.emit('error', error));
39
41
  }
40
42
 
41
43
  get(key) {
@@ -44,21 +46,23 @@ class KeyvMongo extends EventEmitter {
44
46
  if (doc === null) {
45
47
  return undefined;
46
48
  }
49
+
47
50
  return doc.value;
48
51
  });
49
52
  }
50
53
 
51
54
  set(key, value, ttl) {
52
55
  const expiresAt = (typeof ttl === 'number') ? new Date(Date.now() + ttl) : null;
53
- return this.mongo.update({ key }, { key, value, expiresAt }, { upsert: true });
56
+ return this.mongo.update({ key }, { $set: { key, value, expiresAt } }, { upsert: true });
54
57
  }
55
58
 
56
59
  delete(key) {
57
60
  if (typeof key !== 'string') {
58
61
  return Promise.resolve(false);
59
62
  }
63
+
60
64
  return this.mongo.remove({ key })
61
- .then(obj => obj.n > 0);
65
+ .then(object => object.n > 0);
62
66
  }
63
67
 
64
68
  clear() {
package/test/test.js CHANGED
@@ -1,21 +1,32 @@
1
- import 'dotenv/config'; // eslint-disable-line import/no-unassigned-import
2
- import test from 'ava';
3
- import keyvTestSuite, { keyvOfficialTests } from '@keyv/test-suite';
4
- import Keyv from 'keyv';
5
- import KeyvMongo from 'this';
1
+ const test = require('ava');
2
+ const keyvTestSuite = require('@keyv/test-suite').default;
3
+ const Keyv = require('keyv');
4
+ const KeyvMongo = require('this');
6
5
 
7
- const mongoURL = process.env.MONGO_URL || 'mongodb://127.0.0.1:27017';
8
-
9
- keyvOfficialTests(test, Keyv, mongoURL, 'mongodb://127.0.0.1:1234');
6
+ const mongoURL = 'mongodb://127.0.0.1:27017';
10
7
 
11
8
  const store = () => new KeyvMongo(mongoURL);
12
9
  keyvTestSuite(test, Keyv, store);
13
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
+
14
25
  test('Collection option merges into default options', t => {
15
26
  const store = new KeyvMongo({ collection: 'foo' });
16
27
  t.deepEqual(store.opts, {
17
- url: 'mongodb://127.0.0.1:27017',
18
- collection: 'foo'
28
+ url: mongoURL,
29
+ collection: 'foo',
19
30
  });
20
31
  });
21
32
 
@@ -23,7 +34,7 @@ test('Collection option merges into default options if URL is passed', t => {
23
34
  const store = new KeyvMongo(mongoURL, { collection: 'foo' });
24
35
  t.deepEqual(store.opts, {
25
36
  url: mongoURL,
26
- collection: 'foo'
37
+ collection: 'foo',
27
38
  });
28
39
  });
29
40
 
package/.travis.yml DELETED
@@ -1,13 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - 'node'
4
- - '10'
5
- - '8'
6
- - '6'
7
- services:
8
- - mongodb
9
- script: npm test
10
- after_success: npm run coverage
11
- notifications:
12
- email:
13
- on_success: never
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2017 Luke Childs
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.