Skip to content

Commit 0a1cc6f

Browse files
Merge pull request #227 from kuzzleio/update-ms-scan-methods
Update MemoryStorage.*scan return value format
2 parents 89503a6 + 0c406b1 commit 0a1cc6f

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kuzzle-sdk",
3-
"version": "5.0.1",
3+
"version": "5.0.2",
44
"description": "Official Javascript SDK for Kuzzle",
55
"author": "The Kuzzle Team <support@kuzzle.io>",
66
"repository": {

src/MemoryStorage.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ var
44
getIdField = {getter: true, required: ['_id', 'field']},
55
getKeys = {getter: true, required: ['keys']},
66
getMember = {getter: true, required: ['_id', 'member']},
7-
getxScan = {getter: true, required: ['_id', 'cursor'], opts: ['match', 'count']},
7+
getxScan = {
8+
getter: true,
9+
required: ['_id', 'cursor'],
10+
opts: ['match', 'count'],
11+
mapResults: mapScanResults
12+
},
813
getZrange = {
914
getter: true,
1015
required: ['_id', 'start', 'stop'],
@@ -112,7 +117,7 @@ var
112117
rpush: {required: ['_id', 'values']},
113118
rpushx: setIdValue,
114119
sadd: {required: ['_id', 'members']},
115-
scan: {getter: true, required: ['cursor'], opts: ['match', 'count']},
120+
scan: {getter: true, required: ['cursor'], opts: ['match', 'count'], mapResults: mapScanResults},
116121
scard: getId,
117122
sdiff: {getter: true, required: ['_id', 'keys']},
118123
sdiffstore: {required: ['_id', 'keys', 'destination']},
@@ -490,4 +495,35 @@ function mapZrangeResults(results) {
490495
return mapped;
491496
}
492497

498+
/**
499+
* Map *scan calls results, from:
500+
* [
501+
* "<cursor>",
502+
* [
503+
* "value1",
504+
* "value2",
505+
* "..."
506+
* ]
507+
* ]
508+
*
509+
* To:
510+
* {
511+
* cursor: <cursor>,
512+
* values: [
513+
* "value1",
514+
* "value2",
515+
* "..."
516+
* ]
517+
* }
518+
*
519+
* @param {array.<string|array>} results
520+
* @return {object}
521+
*/
522+
function mapScanResults(results) {
523+
return {
524+
cursor: results[0],
525+
values: results[1]
526+
};
527+
}
528+
493529
module.exports = MemoryStorage;

test/MemoryStorage/methods.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ describe('MemoryStorage methods', function () {
492492
{_id: 'key', cursor: 0},
493493
{count: 42, match: 'foo*'},
494494
[42, ['bar', 'baz', 'qux']],
495-
[42, ['bar', 'baz', 'qux']]
495+
{cursor: 42, values: ['bar', 'baz', 'qux']}
496496
);
497497
});
498498

@@ -966,7 +966,7 @@ describe('MemoryStorage methods', function () {
966966
{cursor: 0},
967967
{count: 42, match: 'foo*'},
968968
[42, ['bar', 'baz', 'qux']],
969-
[42, ['bar', 'baz', 'qux']]
969+
{cursor: 42, values: ['bar', 'baz', 'qux']}
970970
);
971971
});
972972

@@ -1158,7 +1158,7 @@ describe('MemoryStorage methods', function () {
11581158
{_id: 'key', cursor: 0},
11591159
{count: 42, match: 'foo*'},
11601160
[42, ['bar', 'baz', 'qux']],
1161-
[42, ['bar', 'baz', 'qux']]
1161+
{cursor: 42, values: ['bar', 'baz', 'qux']}
11621162
);
11631163
});
11641164

@@ -1472,7 +1472,7 @@ describe('MemoryStorage methods', function () {
14721472
{_id: 'key', cursor: 0},
14731473
{count: 42, match: 'foo*'},
14741474
[42, ['bar', 'baz', 'qux']],
1475-
[42, ['bar', 'baz', 'qux']]
1475+
{cursor: 42, values: ['bar', 'baz', 'qux']}
14761476
);
14771477
});
14781478

0 commit comments

Comments
 (0)