@keyv/mongo 1.0.4 → 1.2.2

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":null,"pid":22835,"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":1641079896700,"ppid":22834,"coverageFilename":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/.nyc_output/5820d74a-2c5d-4545-b2e1-19b4fc0d16f0.json","externalId":"","uuid":"5820d74a-2c5d-4545-b2e1-19b4fc0d16f0","files":[]}
@@ -0,0 +1 @@
1
+ {"parent":"5820d74a-2c5d-4545-b2e1-19b4fc0d16f0","pid":22836,"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":1641079896918,"ppid":22835,"coverageFilename":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/.nyc_output/e600d32e-2bd2-4fcc-ba04-b79d5cfa2d6b.json","externalId":"","uuid":"e600d32e-2bd2-4fcc-ba04-b79d5cfa2d6b","files":["/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/src/index.js"]}
@@ -0,0 +1 @@
1
+ {"processes":{"5820d74a-2c5d-4545-b2e1-19b4fc0d16f0":{"parent":null,"children":["e600d32e-2bd2-4fcc-ba04-b79d5cfa2d6b"]},"e600d32e-2bd2-4fcc-ba04-b79d5cfa2d6b":{"parent":"5820d74a-2c5d-4545-b2e1-19b4fc0d16f0","children":[]}},"files":{"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/src/index.js":["e600d32e-2bd2-4fcc-ba04-b79d5cfa2d6b"]},"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)
5
+ [![build](https://github.com/lukechilds/keyv-mongo/actions/workflows/build.yaml/badge.svg)](https://github.com/lukechilds/keyv-mongo/actions/workflows/build.yaml)
6
6
  [![Coverage Status](https://coveralls.io/repos/github/lukechilds/keyv-mongo/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/keyv-mongo?branch=master)
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.0.4",
3
+ "version": "1.2.2",
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,25 +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.4.1",
42
- "pify": "3.0.0"
47
+ "mongojs": "^3",
48
+ "pify": "^5.0.0"
43
49
  },
44
50
  "devDependencies": {
45
- "ava": "^0.22.0",
46
- "coveralls": "^2.13.1",
47
- "eslint-config-xo-lukechilds": "^1.0.0",
48
- "keyv": "*",
49
51
  "@keyv/test-suite": "*",
50
- "nyc": "^11.0.3",
51
- "requirable": "^1.0.1",
52
- "this": "^1.0.2",
53
- "xo": "^0.19.0"
52
+ "ava": "^3.15.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
+ "xo": "^0.47.0"
54
59
  }
55
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(opts) {
8
+ constructor(url, options) {
9
9
  super();
10
10
  this.ttlSupport = false;
11
- opts = opts || {};
12
- if (typeof opts === 'string') {
13
- opts = { url: opts };
11
+ url = url || {};
12
+ if (typeof url === 'string') {
13
+ url = { url };
14
14
  }
15
- if (opts.uri) {
16
- opts = Object.assign({ url: opts.uri }, opts);
15
+
16
+ if (url.uri) {
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
- }, 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,18 +1,40 @@
1
- import test from 'ava';
2
- import keyvTestSuite, { keyvOfficialTests } from '@keyv/test-suite';
3
- import Keyv from 'keyv';
4
- 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');
5
5
 
6
- keyvOfficialTests(test, Keyv, 'mongodb://127.0.0.1:27017', 'mongodb://127.0.0.1:1234');
6
+ const mongoURL = 'mongodb://127.0.0.1:27017';
7
7
 
8
- const store = () => new KeyvMongo();
8
+ const store = () => new KeyvMongo(mongoURL);
9
9
  keyvTestSuite(test, Keyv, store);
10
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
+
11
25
  test('Collection option merges into default options', t => {
12
26
  const store = new KeyvMongo({ collection: 'foo' });
13
27
  t.deepEqual(store.opts, {
14
- url: 'mongodb://127.0.0.1:27017',
15
- collection: 'foo'
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',
16
38
  });
17
39
  });
18
40
 
package/.npmignore DELETED
@@ -1,75 +0,0 @@
1
- ## Node
2
-
3
- #npm5
4
- package-lock.json
5
-
6
- # Logs
7
- logs
8
- *.log
9
- npm-debug.log*
10
-
11
- # Runtime data
12
- pids
13
- *.pid
14
- *.seed
15
- *.pid.lock
16
-
17
- # Directory for instrumented libs generated by jscoverage/JSCover
18
- lib-cov
19
-
20
- # Coverage directory used by tools like istanbul
21
- coverage
22
-
23
- # nyc test coverage
24
- .nyc_output
25
-
26
- # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
27
- .grunt
28
-
29
- # node-waf configuration
30
- .lock-wscript
31
-
32
- # Compiled binary addons (http://nodejs.org/api/addons.html)
33
- build/Release
34
-
35
- # Dependency directories
36
- node_modules
37
- jspm_packages
38
-
39
- # Optional npm cache directory
40
- .npm
41
-
42
- # Optional eslint cache
43
- .eslintcache
44
-
45
- # Optional REPL history
46
- .node_repl_history
47
-
48
- ## OS X
49
-
50
- *.DS_Store
51
- .AppleDouble
52
- .LSOverride
53
-
54
- # Icon must end with two \r
55
- Icon
56
-
57
-
58
- # Thumbnails
59
- ._*
60
-
61
- # Files that might appear in the root of a volume
62
- .DocumentRevisions-V100
63
- .fseventsd
64
- .Spotlight-V100
65
- .TemporaryItems
66
- .Trashes
67
- .VolumeIcon.icns
68
- .com.apple.timemachine.donotpresent
69
-
70
- # Directories potentially created on remote AFP share
71
- .AppleDB
72
- .AppleDesktop
73
- Network Trash Folder
74
- Temporary Items
75
- .apdisk
package/.travis.yml DELETED
@@ -1,12 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - '8'
4
- - '6'
5
- - '4'
6
- services:
7
- - mongodb
8
- script: npm test
9
- after_success: npm run coverage
10
- notifications:
11
- email:
12
- 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.