Skip to content

Fix Sync Streams json_each object and scalar evaluation#647

Open
sravan27 wants to merge 1 commit into
powersync-ja:mainfrom
sravan27:sravan27/fix-sync-streams-json-each-shapes
Open

Fix Sync Streams json_each object and scalar evaluation#647
sravan27 wants to merge 1 commit into
powersync-ja:mainfrom
sravan27:sravan27/fix-sync-streams-json-each-shapes

Conversation

@sravan27
Copy link
Copy Markdown

This fixes a Sync Streams JavaScript evaluator divergence from SQLite around json_each().

SQLite's json_each() emits rows for JSON arrays, JSON objects, and scalar JSON values:

SELECT key, value FROM json_each('{"a":1,"b":true}');
SELECT key, value FROM json_each('42');

The current JavaScript table-valued-function evaluator only accepts arrays, throws for objects, and cannot expose the key column. That means valid Sync Streams rules using object-shaped request/JWT/connection JSON can fail or diverge when evaluated by the JavaScript engine.

This PR:

  • Keeps existing array behavior.
  • Adds SQLite-compatible rows for JSON objects using object keys.
  • Adds SQLite-compatible scalar handling with key = null.
  • Exposes both key and value columns from the JavaScript evaluator.
  • Adds focused engine coverage for object and scalar json_each() evaluation.
  • Adds a patch changeset for @powersync/service-sync-rules.

Verification:

corepack pnpm --filter @powersync/service-sync-rules exec vitest --run test/src/sync_plan/engine/engine.test.ts -t "javascript.*json_each"
corepack pnpm --filter @powersync/service-sync-rules run build:tsc
git diff --check

Note: the local node:sqlite side of this engine test still hits the same local Node binding issue seen on earlier Sync Streams PR verification (column index out of range while binding table-valued JSON inputs), so I scoped the runnable local test command to the JavaScript evaluator path this patch changes.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 21, 2026

🦋 Changeset detected

Latest commit: 7a6bae6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
@powersync/service-sync-rules Patch
@powersync/service-core Patch
@powersync/lib-services-framework Patch
@powersync/service-module-mongodb-storage Patch
@powersync/service-module-mongodb Patch
@powersync/service-module-mssql Patch
@powersync/service-module-mysql Patch
@powersync/service-module-postgres-storage Patch
@powersync/service-module-postgres Patch
@powersync/service-module-core Patch
@powersync/service-image Patch
test-client Patch
@powersync/service-rsocket-router Patch
@powersync/lib-service-mongodb Patch
@powersync/lib-service-postgres Patch
@powersync/service-schema Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant