redis-dataloader
Advanced tools
Comparing version 0.5.0 to 1.0.2
12
index.js
const _ = require('lodash'); | ||
const Promise = require('bluebird'); | ||
const DataLoader = require('dataloader'); | ||
const stringify = require('json-stable-stringify'); | ||
const IORedis = require('ioredis'); | ||
const mapPromise = (promise, fn) => Promise.all(promise.map(fn)); | ||
module.exports = fig => { | ||
const redis = fig.redis; | ||
const isIORedis = redis instanceof IORedis; | ||
const isIORedis = redis.constructor.name !== 'RedisClient'; | ||
@@ -39,3 +39,3 @@ const parse = (resp, opt) => | ||
const makeKey = (keySpace, key, cacheKeyFn) => | ||
`${keySpace}:${cacheKeyFn(key)}`; | ||
`${keySpace ? keySpace + ':' : ''}${cacheKeyFn(key)}`; | ||
@@ -78,3 +78,3 @@ const rSetAndGet = (keySpace, key, rawVal, opt) => | ||
? reject(err) | ||
: Promise.map(results, r => parse(r, opt)).then(resolve); | ||
: mapPromise(results, r => parse(r, opt)).then(resolve); | ||
} | ||
@@ -107,3 +107,3 @@ ) | ||
rMGet(this.keySpace, keys, this.opt).then(results => | ||
Promise.map(results, (v, i) => { | ||
mapPromise(results, (v, i) => { | ||
if (v === '') { | ||
@@ -110,0 +110,0 @@ return Promise.resolve(null); |
{ | ||
"name": "redis-dataloader", | ||
"version": "0.5.0", | ||
"version": "1.0.2", | ||
"description": "DataLoader Using Redis as a Cache", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "gulp test" | ||
"test": "mocha test/**/*.unit.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://git@github.com/DubFriend/redis-dataloader.git" | ||
"url": "git+ssh://git@github.com/PatrickJS/redis-dataloader.git" | ||
}, | ||
"keywords": [ | ||
"GraphQL", | ||
"DataLoader", | ||
@@ -20,12 +21,13 @@ "Cache", | ||
], | ||
"author": "Brian Detering", | ||
"contributors": [ | ||
"Brian Detering <BDeterin@gmail.com>", | ||
"PatrickJS <github@patrickjs.com>" | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/DubFriend/redis-dataloader/issues" | ||
"url": "https://github.com/PatrickJS/redis-dataloader/issues" | ||
}, | ||
"homepage": "https://github.com/DubFriend/redis-dataloader#readme", | ||
"homepage": "https://github.com/PatrickJS/redis-dataloader#readme", | ||
"dependencies": { | ||
"bluebird": "^3.5.0", | ||
"dataloader": "^1.2.0", | ||
"ioredis": "^3.1.2", | ||
"json-stable-stringify": "^1.0.1", | ||
@@ -37,8 +39,7 @@ "lodash": "^4.17.2" | ||
"chai-as-promised": "^7.1.1", | ||
"gulp": "^3.9.1", | ||
"gulp-mocha": "^3.0.1", | ||
"ioredis": "^3.1.2", | ||
"mocha": "^8.1.1", | ||
"redis": "^2.6.3", | ||
"redis-mock": "^0.51.0", | ||
"sinon": "^1.17.6" | ||
} | ||
} |
require('./test')({ | ||
name: 'with driver "redis"', | ||
redis: require('redis').createClient(), | ||
redis: require('redis-mock').createClient(), | ||
}); |
const _ = require('lodash'); | ||
const Promise = require('bluebird'); | ||
const chai = require('chai'); | ||
@@ -10,2 +9,4 @@ chai.use(require('chai-as-promised')); | ||
const mapPromise = (promise, fn) => Promise.all(promise.map(fn)); | ||
module.exports = ({ name, redis }) => { | ||
@@ -28,3 +29,3 @@ const RedisDataLoader = createRedisDataLoader({ redis }); | ||
new Promise((resolve, reject) => { | ||
redis.get(k, (err, resp) => (err ? rejecte(err) : resolve(resp))); | ||
redis.get(k, (err, resp) => (err ? reject(err) : resolve(resp))); | ||
}); | ||
@@ -55,7 +56,7 @@ | ||
this.userLoader = () => | ||
new DataLoader(keys => Promise.map(keys, this.loadFn), { | ||
new DataLoader(keys => mapPromise(keys, this.loadFn), { | ||
cache: false, | ||
}); | ||
return Promise.map( | ||
return mapPromise( | ||
_.keys(this.data).concat(['{"a":1,"b":2}', '[1,2]']), | ||
@@ -194,8 +195,6 @@ k => rDel(`${this.keySpace}:${k}`) | ||
done(); | ||
}) | ||
.done(); | ||
}); | ||
}, 1100); | ||
}) | ||
.catch(done) | ||
.done(); | ||
.catch(done); | ||
}); | ||
@@ -214,2 +213,18 @@ | ||
}); | ||
it('should handle optional keySpace', () => { | ||
this.stubs.redisMGet = sinon.stub(redis, 'mget', (keys, cb) => { | ||
cb(null, [JSON.stringify(this.data.json)]); | ||
}); | ||
const loader = new RedisDataLoader(null, this.userLoader()); | ||
return loader | ||
.load('foo') | ||
.then(_ => { | ||
expect(this.stubs.redisMGet.args[0][0]).to.deep.equal([ | ||
'foo', | ||
]); | ||
}); | ||
}); | ||
}); | ||
@@ -216,0 +231,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
26762
3
6
0
9
483
1
- Removedbluebird@^3.5.0
- Removedioredis@^3.1.2
- Removedbluebird@3.7.2(transitive)
- Removedcluster-key-slot@1.1.2(transitive)
- Removeddebug@2.6.9(transitive)
- Removeddenque@1.5.1(transitive)
- Removedflexbuffer@0.0.6(transitive)
- Removedioredis@3.2.2(transitive)
- Removedlodash.assign@4.2.0(transitive)
- Removedlodash.bind@4.2.1(transitive)
- Removedlodash.clone@4.5.0(transitive)
- Removedlodash.clonedeep@4.5.0(transitive)
- Removedlodash.defaults@4.2.0(transitive)
- Removedlodash.difference@4.5.0(transitive)
- Removedlodash.flatten@4.4.0(transitive)
- Removedlodash.foreach@4.5.0(transitive)
- Removedlodash.isempty@4.4.0(transitive)
- Removedlodash.keys@4.2.0(transitive)
- Removedlodash.noop@3.0.1(transitive)
- Removedlodash.partial@4.2.1(transitive)
- Removedlodash.pick@4.4.0(transitive)
- Removedlodash.sample@4.2.1(transitive)
- Removedlodash.shuffle@4.2.0(transitive)
- Removedlodash.values@4.3.0(transitive)
- Removedms@2.0.0(transitive)
- Removedredis-commands@1.7.0(transitive)
- Removedredis-parser@2.6.0(transitive)