keyv 1.0.5 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -38,11 +38,11 @@ npm install --save keyv
38
38
  By default everything is stored in memory, you can optionally also install a storage adapter.
39
39
 
40
40
  ```
41
- npm install --save keyv-redis
42
- npm install --save keyv-mongo
43
- npm install --save keyv-sqlite
44
- npm install --save keyv-postgres
45
- npm install --save keyv-mysql
41
+ npm install --save @keyv/redis
42
+ npm install --save @keyv/mongo
43
+ npm install --save @keyv/sqlite
44
+ npm install --save @keyv/postgres
45
+ npm install --save @keyv/mysql
46
46
  ```
47
47
 
48
48
  Create a new Keyv instance, passing your connection string if applicable. Keyv will automatically load the correct storage adapter.
@@ -91,11 +91,11 @@ The official storage adapters are covered by [over 150 integration tests](https:
91
91
 
92
92
  Database | Adapter | Native TTL | Status
93
93
  ---|---|---|---
94
- Redis | [keyv-redis](https://github.com/lukechilds/keyv-redis) | Yes | [![Build Status](https://travis-ci.org/lukechilds/keyv-redis.svg?branch=master)](https://travis-ci.org/lukechilds/keyv-redis) [![Coverage Status](https://coveralls.io/repos/github/lukechilds/keyv-redis/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/keyv-redis?branch=master)
95
- MongoDB | [keyv-mongo](https://github.com/lukechilds/keyv-mongo) | Yes | [![Build Status](https://travis-ci.org/lukechilds/keyv-mongo.svg?branch=master)](https://travis-ci.org/lukechilds/keyv-mongo) [![Coverage Status](https://coveralls.io/repos/github/lukechilds/keyv-mongo/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/keyv-mongo?branch=master)
96
- SQLite | [keyv-sqlite](https://github.com/lukechilds/keyv-sqlite) | No | [![Build Status](https://travis-ci.org/lukechilds/keyv-sqlite.svg?branch=master)](https://travis-ci.org/lukechilds/keyv-sqlite) [![Coverage Status](https://coveralls.io/repos/github/lukechilds/keyv-sqlite/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/keyv-sqlite?branch=master)
97
- PostgreSQL | [keyv-postgres](https://github.com/lukechilds/keyv-postgres) | No | [![Build Status](https://travis-ci.org/lukechilds/keyv-postgres.svg?branch=master)](https://travis-ci.org/lukechildskeyv-postgreskeyv) [![Coverage Status](https://coveralls.io/repos/github/lukechilds/keyv-postgres/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/keyv-postgres?branch=master)
98
- MySQL | [keyv-mysql](https://github.com/lukechilds/keyv-mysql) | No | [![Build Status](https://travis-ci.org/lukechilds/keyv-mysql.svg?branch=master)](https://travis-ci.org/lukechilds/keyv-mysql) [![Coverage Status](https://coveralls.io/repos/github/lukechilds/keyv-mysql/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/keyv-mysql?branch=master)
94
+ Redis | [@keyv/redis](https://github.com/lukechilds/keyv-redis) | Yes | [![Build Status](https://travis-ci.org/lukechilds/keyv-redis.svg?branch=master)](https://travis-ci.org/lukechilds/keyv-redis) [![Coverage Status](https://coveralls.io/repos/github/lukechilds/keyv-redis/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/keyv-redis?branch=master)
95
+ MongoDB | [@keyv/mongo](https://github.com/lukechilds/keyv-mongo) | Yes | [![Build Status](https://travis-ci.org/lukechilds/keyv-mongo.svg?branch=master)](https://travis-ci.org/lukechilds/keyv-mongo) [![Coverage Status](https://coveralls.io/repos/github/lukechilds/keyv-mongo/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/keyv-mongo?branch=master)
96
+ SQLite | [@keyv/sqlite](https://github.com/lukechilds/keyv-sqlite) | No | [![Build Status](https://travis-ci.org/lukechilds/keyv-sqlite.svg?branch=master)](https://travis-ci.org/lukechilds/keyv-sqlite) [![Coverage Status](https://coveralls.io/repos/github/lukechilds/keyv-sqlite/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/keyv-sqlite?branch=master)
97
+ PostgreSQL | [@keyv/postgres](https://github.com/lukechilds/keyv-postgres) | No | [![Build Status](https://travis-ci.org/lukechilds/keyv-postgres.svg?branch=master)](https://travis-ci.org/lukechildskeyv-postgreskeyv) [![Coverage Status](https://coveralls.io/repos/github/lukechilds/keyv-postgres/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/keyv-postgres?branch=master)
98
+ MySQL | [@keyv/mysql](https://github.com/lukechilds/keyv-mysql) | No | [![Build Status](https://travis-ci.org/lukechilds/keyv-mysql.svg?branch=master)](https://travis-ci.org/lukechilds/keyv-mysql) [![Coverage Status](https://coveralls.io/repos/github/lukechilds/keyv-mysql/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/keyv-mysql?branch=master)
99
99
 
100
100
  ## Third-party Storage Adapters
101
101
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keyv",
3
- "version": "1.0.5",
3
+ "version": "3.0.0",
4
4
  "description": "Simple key-value storage with support for multiple backends",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -32,18 +32,18 @@
32
32
  "json-buffer": "3.0.0"
33
33
  },
34
34
  "devDependencies": {
35
- "ava": "^0.20.0",
36
- "coveralls": "^2.13.1",
35
+ "ava": "^0.22.0",
36
+ "coveralls": "^3.0.0",
37
37
  "eslint-config-xo-lukechilds": "^1.0.0",
38
- "keyv-mongo": "*",
39
- "keyv-mysql": "*",
40
- "keyv-postgres": "*",
41
- "keyv-redis": "*",
42
- "keyv-sqlite": "*",
43
- "keyv-test-suite": "*",
38
+ "@keyv/mongo": "*",
39
+ "@keyv/mysql": "*",
40
+ "@keyv/postgres": "*",
41
+ "@keyv/redis": "*",
42
+ "@keyv/sqlite": "*",
43
+ "@keyv/test-suite": "*",
44
44
  "nyc": "^11.0.3",
45
45
  "this": "^1.0.2",
46
- "timekeeper": "^1.0.0",
46
+ "timekeeper": "^2.0.0",
47
47
  "xo": "^0.19.0"
48
48
  }
49
49
  }
package/src/index.js CHANGED
@@ -5,13 +5,13 @@ const JSONB = require('json-buffer');
5
5
 
6
6
  const loadStore = opts => {
7
7
  const adapters = {
8
- redis: 'keyv-redis',
9
- mongodb: 'keyv-mongo',
10
- mongo: 'keyv-mongo',
11
- sqlite: 'keyv-sqlite',
12
- postgresql: 'keyv-postgres',
13
- postgres: 'keyv-postgres',
14
- mysql: 'keyv-mysql'
8
+ redis: '@keyv/redis',
9
+ mongodb: '@keyv/mongo',
10
+ mongo: '@keyv/mongo',
11
+ sqlite: '@keyv/sqlite',
12
+ postgresql: '@keyv/postgres',
13
+ postgres: '@keyv/postgres',
14
+ mysql: '@keyv/mysql'
15
15
  };
16
16
  if (opts.adapter || opts.uri) {
17
17
  const adapter = opts.adapter || /^[^:]*/.exec(opts.uri)[0];
@@ -48,17 +48,19 @@ class Keyv extends EventEmitter {
48
48
  get(key) {
49
49
  key = this._getKeyPrefix(key);
50
50
  const store = this.opts.store;
51
- return Promise.resolve(store.get(key)).then(data => {
52
- data = (typeof data === 'string') ? JSONB.parse(data) : data;
53
- if (data === undefined) {
54
- return undefined;
55
- }
56
- if (!store.ttlSupport && typeof data.expires === 'number' && Date.now() > data.expires) {
57
- this.delete(key);
58
- return undefined;
59
- }
60
- return store.ttlSupport ? data : data.value;
61
- });
51
+ return Promise.resolve()
52
+ .then(() => store.get(key))
53
+ .then(data => {
54
+ data = (typeof data === 'string') ? JSONB.parse(data) : data;
55
+ if (data === undefined) {
56
+ return undefined;
57
+ }
58
+ if (typeof data.expires === 'number' && Date.now() > data.expires) {
59
+ this.delete(key);
60
+ return undefined;
61
+ }
62
+ return data.value;
63
+ });
62
64
  }
63
65
 
64
66
  set(key, value, ttl) {
@@ -73,10 +75,8 @@ class Keyv extends EventEmitter {
73
75
 
74
76
  return Promise.resolve()
75
77
  .then(() => {
76
- if (!store.ttlSupport) {
77
- const expires = (typeof ttl === 'number') ? (Date.now() + ttl) : null;
78
- value = { value, expires };
79
- }
78
+ const expires = (typeof ttl === 'number') ? (Date.now() + ttl) : null;
79
+ value = { value, expires };
80
80
  return store.set(key, JSONB.stringify(value), ttl);
81
81
  })
82
82
  .then(() => true);
@@ -85,12 +85,14 @@ class Keyv extends EventEmitter {
85
85
  delete(key) {
86
86
  key = this._getKeyPrefix(key);
87
87
  const store = this.opts.store;
88
- return Promise.resolve(store.delete(key));
88
+ return Promise.resolve()
89
+ .then(() => store.delete(key));
89
90
  }
90
91
 
91
92
  clear() {
92
93
  const store = this.opts.store;
93
- return Promise.resolve(store.clear());
94
+ return Promise.resolve()
95
+ .then(() => store.clear());
94
96
  }
95
97
  }
96
98
 
package/.npmignore DELETED
@@ -1,77 +0,0 @@
1
- test/testdb.sqlite
2
-
3
- ## Node
4
-
5
- #npm5
6
- package-lock.json
7
-
8
- # Logs
9
- logs
10
- *.log
11
- npm-debug.log*
12
-
13
- # Runtime data
14
- pids
15
- *.pid
16
- *.seed
17
- *.pid.lock
18
-
19
- # Directory for instrumented libs generated by jscoverage/JSCover
20
- lib-cov
21
-
22
- # Coverage directory used by tools like istanbul
23
- coverage
24
-
25
- # nyc test coverage
26
- .nyc_output
27
-
28
- # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
29
- .grunt
30
-
31
- # node-waf configuration
32
- .lock-wscript
33
-
34
- # Compiled binary addons (http://nodejs.org/api/addons.html)
35
- build/Release
36
-
37
- # Dependency directories
38
- node_modules
39
- jspm_packages
40
-
41
- # Optional npm cache directory
42
- .npm
43
-
44
- # Optional eslint cache
45
- .eslintcache
46
-
47
- # Optional REPL history
48
- .node_repl_history
49
-
50
- ## OS X
51
-
52
- *.DS_Store
53
- .AppleDouble
54
- .LSOverride
55
-
56
- # Icon must end with two \r
57
- Icon
58
-
59
-
60
- # Thumbnails
61
- ._*
62
-
63
- # Files that might appear in the root of a volume
64
- .DocumentRevisions-V100
65
- .fseventsd
66
- .Spotlight-V100
67
- .TemporaryItems
68
- .Trashes
69
- .VolumeIcon.icns
70
- .com.apple.timemachine.donotpresent
71
-
72
- # Directories potentially created on remote AFP share
73
- .AppleDB
74
- .AppleDesktop
75
- Network Trash Folder
76
- Temporary Items
77
- .apdisk
package/.travis.yml DELETED
@@ -1,21 +0,0 @@
1
- dist: trusty
2
- language: node_js
3
- node_js:
4
- - '8'
5
- - '6'
6
- - '4'
7
- services:
8
- - redis-server
9
- - mongodb
10
- - mysql
11
- addons:
12
- postgresql: '9.5'
13
- before_script:
14
- - psql -c 'create database keyv_test;' -U postgres
15
- - mysql -u root -e 'CREATE DATABASE keyv_test;'
16
- - mysql -u root -e 'GRANT ALL PRIVILEGES ON keyv_test.* TO 'mysql'@'localhost';'
17
- script: npm run test:full
18
- after_success: npm run coverage
19
- notifications:
20
- email:
21
- on_success: never
package/media/logo.svg DELETED
@@ -1,10 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
- <svg width="512" height="512" viewBox="0 0 512 512" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
- <defs>
4
- <linearGradient x1="30%" y1="20%" x2="65%" y2="50%" id="gradient">
5
- <stop stop-color="#24C6DC" offset="0%"></stop>
6
- <stop stop-color="#C86DD7" offset="100%"></stop>
7
- </linearGradient>
8
- </defs>
9
- <path fill="url(#gradient)" fill-rule="nonzero" d="M189 196v-17.4c13.7 10.2 40.2 15 66.5 15 26.3 0 52.8-4.8 66.5-15V196c0 12-30 21.8-66.5 21.8-36.6 0-66.5-9.8-66.5-21.8zm133 16.6v19.8c-3.7 11-32.3 19.4-66.5 19.4s-62.8-8.5-66.5-19.4v-20c13.7 10.4 40.2 15 66.5 15 26.3 0 52.8-4.6 66.5-14.8zM189 162v-17.4c13.7 10.2 40.2 15 66.5 15 26.3 0 52.8-4.8 66.5-15V162c0 12-30 22-66.5 22-36.6 0-66.5-10-66.5-22zm66.5-12c-36.7 0-66.5-10-66.5-22s29.8-21.8 66.5-21.8S322 116 322 128s-29.8 22-66.5 22zm.5 362C114.6 512 0 397.4 0 256S114.6 0 256 0s256 114.6 256 256-114.6 256-256 256zm0-3c139.7 0 253-113.3 253-253S395.6 3 256 3 3 116.4 3 256s113.3 253 253 253zM122 351.2l56-51h5l-56.5 51 59.3 60h-5l-58.7-59.7v59.8h-3.5v-111h3.4v51zm77 23.3c0 4.4.7 8.7 2 13 1.3 4.3 3.3 8 6 11.5 2.6 3.5 6 6.3 10 8.4 4 2 9 3 14.5 3 5.7 0 10.7-1 15-3.3 4.5-2 8.3-5.4 11.5-9.7l2.5 2.2c-3.5 4.6-7.7 8-12.4 10.5-4.7 2.4-10.2 3.6-16.5 3.6-5.3 0-10.2-1-14.6-3-4.5-1.8-8.3-4.5-11.5-8-3.2-3.4-5.6-7.5-7.4-12.3-1.6-5-2.5-10-2.5-15.7 0-5.5 1-10.5 2.7-15 1.8-4.7 4.2-8.7 7.3-12 3-3.4 6.7-6 11-7.8 4-2 8.6-2.8 13.4-2.8 5.6 0 10.5 1 14.7 3 4.2 2 7.7 4.6 10.4 8 3 3 5 6.8 6.3 11 1.4 4 2 8.3 2 12.6v3H199zm61-3c0-4.7-.8-9-2.4-13-1.5-3.8-3.5-7-6.2-10-2.6-2.6-5.7-4.8-9.4-6.3-3.6-1.5-7.7-2.3-12.2-2.3-5.5 0-10 1-14 3.4-4 2.2-7 5-9.5 8.3-2.5 3.3-4.3 6.8-5.4 10.4-1.3 3.7-1.8 7-1.8 9.6h61zm40.7 63.7c-1.6 4.5-4 8-6.6 10.5-2.7 2.4-6.3 3.6-10.7 3.6-1 0-2 0-3.3-.3-1.2 0-2.3-.3-3-.7l.8-3c.6.3 1.5.5 2.6.7 1 .2 2.2.3 3.2.3 2.2 0 4-.4 5.8-1.3 1.6-.8 3-2 4-3.2 1.3-1.3 2.2-2.8 3-4.4.8-1.7 1.5-3.4 2-5l7-19-28.5-74.2h3.6l26.6 70.4 25.6-70.4h3.7l-35.8 96zm76.3-24h-4.5l-28.4-72h3.8l27 68.7h.2l26-68.8h3.7L377 411.4z"></path>
10
- </svg>
package/test/keyv.js DELETED
@@ -1,84 +0,0 @@
1
- import test from 'ava';
2
- import tk from 'timekeeper';
3
- import keyvTestSuite from 'keyv-test-suite';
4
- import Keyv from 'this';
5
-
6
- test.serial('Keyv is a class', t => {
7
- t.is(typeof Keyv, 'function');
8
- t.throws(() => Keyv()); // eslint-disable-line new-cap
9
- t.notThrows(() => new Keyv());
10
- });
11
-
12
- test.serial('Keyv accepts storage adapters', async t => {
13
- const store = new Map();
14
- const keyv = new Keyv({ store });
15
- t.is(store.size, 0);
16
- await keyv.set('foo', 'bar');
17
- t.is(await keyv.get('foo'), 'bar');
18
- t.is(store.size, 1);
19
- });
20
-
21
- test.serial('Keyv hands tll functionality over to ttl supporting stores', async t => {
22
- t.plan(3);
23
- const store = new Map();
24
- store.ttlSupport = true;
25
- const storeSet = store.set;
26
- store.set = (key, val, ttl) => {
27
- t.is(ttl, 100);
28
- storeSet.call(store, key, val, ttl);
29
- };
30
- const keyv = new Keyv({ store });
31
- await keyv.set('foo', 'bar', 100);
32
- t.is(await keyv.get('foo'), 'bar');
33
- tk.freeze(Date.now() + 150);
34
- t.is(await keyv.get('foo'), 'bar');
35
- tk.reset();
36
- });
37
-
38
- test.serial('Keyv respects default tll option', async t => {
39
- const store = new Map();
40
- const keyv = new Keyv({ store, ttl: 100 });
41
- await keyv.set('foo', 'bar');
42
- t.is(await keyv.get('foo'), 'bar');
43
- tk.freeze(Date.now() + 150);
44
- t.is(await keyv.get('foo'), undefined);
45
- tk.reset();
46
- });
47
-
48
- test.serial('.set(key, val, ttl) overwrites default tll option', async t => {
49
- const startTime = Date.now();
50
- tk.freeze(startTime);
51
- const store = new Map();
52
- const keyv = new Keyv({ store, ttl: 200 });
53
- await keyv.set('foo', 'bar');
54
- await keyv.set('fizz', 'buzz', 100);
55
- await keyv.set('ping', 'pong', 300);
56
- t.is(await keyv.get('foo'), 'bar');
57
- t.is(await keyv.get('fizz'), 'buzz');
58
- t.is(await keyv.get('ping'), 'pong');
59
- tk.freeze(startTime + 150);
60
- t.is(await keyv.get('foo'), 'bar');
61
- t.is(await keyv.get('fizz'), undefined);
62
- t.is(await keyv.get('ping'), 'pong');
63
- tk.freeze(startTime + 250);
64
- t.is(await keyv.get('foo'), undefined);
65
- t.is(await keyv.get('ping'), 'pong');
66
- tk.freeze(startTime + 350);
67
- t.is(await keyv.get('ping'), undefined);
68
- tk.reset();
69
- });
70
-
71
- test.serial('.set(key, val, ttl) where ttl is "0" overwrites default tll option and sets key to never expire', async t => {
72
- const startTime = Date.now();
73
- tk.freeze(startTime);
74
- const store = new Map();
75
- const keyv = new Keyv({ store, ttl: 200 });
76
- await keyv.set('foo', 'bar', 0);
77
- t.is(await keyv.get('foo'), 'bar');
78
- tk.freeze(startTime + 250);
79
- t.is(await keyv.get('foo'), 'bar');
80
- tk.reset();
81
- });
82
-
83
- const store = () => new Map();
84
- keyvTestSuite(test, Keyv, store);
@@ -1,9 +0,0 @@
1
- import test from 'ava';
2
- import keyvTestSuite, { keyvOfficialTests } from 'keyv-test-suite';
3
- import Keyv from 'this';
4
- import KeyvMongo from 'keyv-mongo';
5
-
6
- keyvOfficialTests(test, Keyv, 'mongodb://127.0.0.1:27017', 'mongodb://127.0.0.1:1234');
7
-
8
- const store = () => new KeyvMongo('mongodb://127.0.0.1:27017');
9
- keyvTestSuite(test, Keyv, store);
@@ -1,9 +0,0 @@
1
- import test from 'ava';
2
- import keyvTestSuite, { keyvOfficialTests } from 'keyv-test-suite';
3
- import Keyv from 'this';
4
- import KeyvMysql from 'keyv-mysql';
5
-
6
- keyvOfficialTests(test, Keyv, 'mysql://mysql@localhost/keyv_test', 'mysql://foo');
7
-
8
- const store = () => new KeyvMysql('mysql://mysql@localhost/keyv_test');
9
- keyvTestSuite(test, Keyv, store);
@@ -1,9 +0,0 @@
1
- import test from 'ava';
2
- import keyvTestSuite, { keyvOfficialTests } from 'keyv-test-suite';
3
- import Keyv from 'this';
4
- import KeyvPostgres from 'keyv-postgres';
5
-
6
- keyvOfficialTests(test, Keyv, 'postgresql://postgres@localhost:5432/keyv_test', 'postgresql://foo');
7
-
8
- const store = () => new KeyvPostgres('postgresql://postgres@localhost:5432/keyv_test');
9
- keyvTestSuite(test, Keyv, store);
@@ -1,9 +0,0 @@
1
- import test from 'ava';
2
- import keyvTestSuite, { keyvOfficialTests } from 'keyv-test-suite';
3
- import Keyv from 'this';
4
- import KeyvRedis from 'keyv-redis';
5
-
6
- keyvOfficialTests(test, Keyv, 'redis://localhost', 'redis://foo');
7
-
8
- const store = () => new KeyvRedis('redis://localhost');
9
- keyvTestSuite(test, Keyv, store);
@@ -1,9 +0,0 @@
1
- import test from 'ava';
2
- import keyvTestSuite, { keyvOfficialTests } from 'keyv-test-suite';
3
- import Keyv from 'this';
4
- import KeyvSqlite from 'keyv-sqlite';
5
-
6
- keyvOfficialTests(test, Keyv, 'sqlite://test/testdb.sqlite', 'sqlite://non/existent/database.sqlite');
7
-
8
- const store = () => new KeyvSqlite('sqlite://test/testdb.sqlite');
9
- keyvTestSuite(test, Keyv, store);