diff --git a/package.json b/package.json index 954483ac7..efafd5d40 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kuzzle-sdk", - "version": "5.0.1", + "version": "5.0.2", "description": "Official Javascript SDK for Kuzzle", "author": "The Kuzzle Team ", "repository": { diff --git a/src/MemoryStorage.js b/src/MemoryStorage.js index 2a67b8195..22abce605 100644 --- a/src/MemoryStorage.js +++ b/src/MemoryStorage.js @@ -4,7 +4,12 @@ var getIdField = {getter: true, required: ['_id', 'field']}, getKeys = {getter: true, required: ['keys']}, getMember = {getter: true, required: ['_id', 'member']}, - getxScan = {getter: true, required: ['_id', 'cursor'], opts: ['match', 'count']}, + getxScan = { + getter: true, + required: ['_id', 'cursor'], + opts: ['match', 'count'], + mapResults: mapScanResults + }, getZrange = { getter: true, required: ['_id', 'start', 'stop'], @@ -112,7 +117,7 @@ var rpush: {required: ['_id', 'values']}, rpushx: setIdValue, sadd: {required: ['_id', 'members']}, - scan: {getter: true, required: ['cursor'], opts: ['match', 'count']}, + scan: {getter: true, required: ['cursor'], opts: ['match', 'count'], mapResults: mapScanResults}, scard: getId, sdiff: {getter: true, required: ['_id', 'keys']}, sdiffstore: {required: ['_id', 'keys', 'destination']}, @@ -490,4 +495,35 @@ function mapZrangeResults(results) { return mapped; } +/** + * Map *scan calls results, from: + * [ + * "", + * [ + * "value1", + * "value2", + * "..." + * ] + * ] + * + * To: + * { + * cursor: , + * values: [ + * "value1", + * "value2", + * "..." + * ] + * } + * + * @param {array.} results + * @return {object} + */ +function mapScanResults(results) { + return { + cursor: results[0], + values: results[1] + }; +} + module.exports = MemoryStorage; diff --git a/test/MemoryStorage/methods.test.js b/test/MemoryStorage/methods.test.js index 25fca4dbf..19239df13 100644 --- a/test/MemoryStorage/methods.test.js +++ b/test/MemoryStorage/methods.test.js @@ -492,7 +492,7 @@ describe('MemoryStorage methods', function () { {_id: 'key', cursor: 0}, {count: 42, match: 'foo*'}, [42, ['bar', 'baz', 'qux']], - [42, ['bar', 'baz', 'qux']] + {cursor: 42, values: ['bar', 'baz', 'qux']} ); }); @@ -966,7 +966,7 @@ describe('MemoryStorage methods', function () { {cursor: 0}, {count: 42, match: 'foo*'}, [42, ['bar', 'baz', 'qux']], - [42, ['bar', 'baz', 'qux']] + {cursor: 42, values: ['bar', 'baz', 'qux']} ); }); @@ -1158,7 +1158,7 @@ describe('MemoryStorage methods', function () { {_id: 'key', cursor: 0}, {count: 42, match: 'foo*'}, [42, ['bar', 'baz', 'qux']], - [42, ['bar', 'baz', 'qux']] + {cursor: 42, values: ['bar', 'baz', 'qux']} ); }); @@ -1472,7 +1472,7 @@ describe('MemoryStorage methods', function () { {_id: 'key', cursor: 0}, {count: 42, match: 'foo*'}, [42, ['bar', 'baz', 'qux']], - [42, ['bar', 'baz', 'qux']] + {cursor: 42, values: ['bar', 'baz', 'qux']} ); });