Merge pull request #2654 from strongloop/feature/kvao-iterate-keys-2x

KeyValueModel: add API for listing keys
This commit is contained in:
Miroslav Bajtoš 2016-08-18 14:21:45 +02:00 committed by GitHub
commit 0627f62e45
2 changed files with 33 additions and 0 deletions

View File

@ -16,6 +16,16 @@ module.exports = function(KeyValueModel) {
throwNotAttached(this.modelName, 'expire'); throwNotAttached(this.modelName, 'expire');
}; };
// TODO add api docs
KeyValueModel.keys = function(filter, options, callback) {
throwNotAttached(this.modelName, 'keys');
};
// TODO add api docs
KeyValueModel.iterateKeys = function(filter, options) {
throwNotAttached(this.modelName, 'iterateKeys');
};
KeyValueModel.setup = function() { KeyValueModel.setup = function() {
KeyValueModel.base.setup.apply(this, arguments); KeyValueModel.base.setup.apply(this, arguments);
@ -51,6 +61,15 @@ module.exports = function(KeyValueModel) {
], ],
http: { path: '/:key/expire', verb: 'put' }, http: { path: '/:key/expire', verb: 'put' },
}); });
this.remoteMethod('keys', {
accepts: {
arg: 'filter', type: 'object', required: false,
http: { source: 'query' },
},
returns: { arg: 'keys', type: ['string'], root: true },
http: { path: '/keys', verb: 'get' },
});
}; };
}; };

View File

@ -80,6 +80,20 @@ describe('KeyValueModel', function() {
.send({ ttl: 10 }) .send({ ttl: 10 })
.expect(404, done); .expect(404, done);
}); });
it('provides "keys(filter)" at "GET /keys"', function(done) {
CacheItem.set('list-key', AN_OBJECT_VALUE, function(err) {
if (err) return done(err);
request.get('/CacheItems/keys')
.send(AN_OBJECT_VALUE)
.end(function(err, res) {
if (err) return done(err);
if (res.body.error) return done(res.body.error);
expect(res.body).to.eql(['list-key']);
done();
});
});
});
}); });
function setupAppAndCacheItem() { function setupAppAndCacheItem() {