Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-sync-streams-iif-arity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/service-sync-rules': patch
---

Validate `iif()` calls with the same three-argument arity used by the sync stream evaluator.
2 changes: 1 addition & 1 deletion packages/sync-rules/src/sync_plan/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const supportedFunctions: Record<string, ArgumentCount> = {
hex: 1,
ifnull: { min: 2 },
//if: { min: 2 },
iif: { min: 2 },
iif: 3,
instr: 2,
length: 1,
// TODO: Establish defaults for case sensitivity, changing escape characters, ICU support.
Expand Down
16 changes: 16 additions & 0 deletions packages/sync-rules/test/src/compiler/sqlite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ describe('sqlite conversion', () => {
]);
});

test('iif requires exactly three args', () => {
expect(translate('iif(1, 2)')[1]).toStrictEqual([
{
message: 'Expected at least 3 arguments',
source: 'iif(1, 2)'
}
]);

expect(translate('iif(1, 2, 3, 4)')[1]).toStrictEqual([
{
message: 'Expected at most 3 arguments',
source: 'iif(1, 2, 3, 4)'
}
]);
});

test.skip('must be even', () => {
expect(translate("json_object('foo')")[1]).toStrictEqual([
{
Expand Down