Skip to content

Commit

Permalink
fix: handle falsy value expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
luismeyer committed Feb 2, 2024
1 parent 47a3167 commit 58d0ca4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
6 changes: 2 additions & 4 deletions scripts/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ const ping = async () => {
};

try {
const res = await DDBClient.instance.send(new ListTablesCommand({}));

console.log({ res });
await DDBClient.instance.send(new ListTablesCommand({}));
} catch (error) {
console.log({ error });
console.error({ error });

return false;
}
Expand Down
8 changes: 0 additions & 8 deletions src/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ export const expressionAttributeValues = <
for (const key of keys) {
const value = options[key];

if (value === undefined) {
continue;
}

if (!isDuenamoExpression(value)) {
result[expressionAttributeValueKey(key)] = value;

Expand Down Expand Up @@ -116,10 +112,6 @@ export const conditionExpression = <
for (const key of keys) {
const value = options[key];

if (!value) {
continue;
}

const nameKey = expressionAttributeNameKey(key);
const valueKey = expressionAttributeValueKey(key);

Expand Down
19 changes: 19 additions & 0 deletions test/expression.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,22 @@ test('Condition-Expression handles duenamo expression IN', t => {

t.is(exp, '#foo IN (:foo_0, :foo_1, :foo_2, :foo_3)');
});

test('Condition-Expression handles equal expression and duenamo expression', t => {
const exp = conditionExpression({
id: NOT('1'),
name: 'username',
foo: IN('bar', 'baz'),
});

t.is(exp, '#id <> :id and #name = :name and #foo IN (:foo_0, :foo_1)');
});

test('Condition-Expression handles booleans', t => {
const exp = conditionExpression({
disabled: false,
name: 'username',
});

t.is(exp, '#disabled = :disabled and #name = :name');
});

0 comments on commit 58d0ca4

Please sign in to comment.