Skip to content

Commit

Permalink
Merge pull request #632 from aerospike/exp-map-fix
Browse files Browse the repository at this point in the history
Smalls fixes around getListType and getMapType
  • Loading branch information
DomPeliniAerospike authored Sep 3, 2024
2 parents bcc1273 + 29a98b2 commit a99b18f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/exp_lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const _rtype = _valueExp(exp.ops.VAL_RTYPE, 'intVal')
*********************************************************************************/

function getListType (type, returnType, isMulti) {
if (!Object.values(exp.type).includes(type)) {
throw new TypeError('invalid value for valueType parameter')
}

let expected = type

switch (returnType & ~lists.returnType.INVERTED) {
Expand All @@ -43,9 +47,12 @@ function getListType (type, returnType, isMulti) {
expected = exp.type.LIST
}
break
case lists.returnType.EXISTS:
expected = exp.type.BOOL
break
case lists.returnType.NONE:
default:
throw new TypeError('either set the value type as auto or match with return object data type')
throw new TypeError('either set the return type as auto or match with return object data type')
}

if (type === exp.type.AUTO || type === expected) {
Expand Down
11 changes: 10 additions & 1 deletion lib/exp_maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const _rtype = _valueExp(exp.ops.VAL_RTYPE, 'intVal')
*********************************************************************************/

function getMapType (type, returnType, isMulti) {
if (!Object.values(exp.type).includes(type)) {
throw new TypeError('invalid value for valueType parameter')
}

let expected = type

switch (returnType & ~maps.returnType.INVERTED) {
Expand All @@ -29,12 +33,17 @@ function getMapType (type, returnType, isMulti) {
expected = exp.type.LIST
}
break
case maps.returnType.EXISTS:
expected = exp.type.BOOL
break
case maps.returnType.KEY_VALUE:
case maps.returnType.ORDERED_MAP:
case maps.returnType.UNORDERED_MAP:
expected = exp.type.MAP
break
case maps.returnType.NONE:
default:
throw new TypeError('either set the value type as auto or match with return object data type')
throw new TypeError('either set the return type as auto or match with return object data type')
}

if (type === exp.type.AUTO || type === expected) {
Expand Down

0 comments on commit a99b18f

Please sign in to comment.