@awsless/dynamodb-server 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +30 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -598,6 +598,25 @@ function evaluateCondition(expression, item, context) {
|
|
|
598
598
|
}
|
|
599
599
|
throw new ValidationException(`Unexpected token: ${token.type}`);
|
|
600
600
|
}
|
|
601
|
+
function parseSizeValue() {
|
|
602
|
+
consume("FUNCTION");
|
|
603
|
+
consume("LPAREN");
|
|
604
|
+
const pathToken = consume("PATH");
|
|
605
|
+
consume("RPAREN");
|
|
606
|
+
const segments = parsePath(pathToken.value, context.expressionAttributeNames);
|
|
607
|
+
const value = getValueAtPath(item, segments);
|
|
608
|
+
let size = 0;
|
|
609
|
+
if (value) {
|
|
610
|
+
if ("S" in value) size = value.S.length;
|
|
611
|
+
else if ("B" in value) size = value.B.length;
|
|
612
|
+
else if ("SS" in value) size = value.SS.length;
|
|
613
|
+
else if ("NS" in value) size = value.NS.length;
|
|
614
|
+
else if ("BS" in value) size = value.BS.length;
|
|
615
|
+
else if ("L" in value) size = value.L.length;
|
|
616
|
+
else if ("M" in value) size = Object.keys(value.M).length;
|
|
617
|
+
}
|
|
618
|
+
return size;
|
|
619
|
+
}
|
|
601
620
|
function parseFunction() {
|
|
602
621
|
const funcToken = consume("FUNCTION");
|
|
603
622
|
consume("LPAREN");
|
|
@@ -707,12 +726,18 @@ function evaluateCondition(expression, item, context) {
|
|
|
707
726
|
const nextToken = current();
|
|
708
727
|
if (nextToken?.type === "COMPARATOR") {
|
|
709
728
|
consume("COMPARATOR");
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
729
|
+
let rightNum;
|
|
730
|
+
if (current()?.type === "FUNCTION" && current()?.value === "size") {
|
|
731
|
+
rightNum = parseSizeValue();
|
|
732
|
+
} else {
|
|
733
|
+
const rightToken = consume();
|
|
734
|
+
const rightValue = resolveOperand2(rightToken);
|
|
735
|
+
if (!rightValue || !("N" in rightValue)) {
|
|
736
|
+
throw new ValidationException("Size comparison requires numeric operand");
|
|
737
|
+
}
|
|
738
|
+
rightNum = Number(rightValue.N);
|
|
714
739
|
}
|
|
715
|
-
return compareNumbers(size,
|
|
740
|
+
return compareNumbers(size, rightNum, nextToken.value);
|
|
716
741
|
}
|
|
717
742
|
return size > 0;
|
|
718
743
|
}
|