Repository navigation
fix(driver): broadcast query events in capacitor and nativescript drivers - #12724
kyungseopk1m wants to merge 3 commits into
Conversation
commit: |
Code Review by Qodo
1.
|
|
This repository was recently restructured into a pnpm workspace, and the If your branch has diverged enough that a full rebase isn't worth it, Sorry for the disruption, and thanks for your patience. |
…vers The Capacitor and NativeScript query runners never emitted the `beforeQuery`/`afterQuery` subscriber events, so subscribers registered through those two drivers were never invoked, unlike every other SQLite family driver (better-sqlite3, cordova, expo, sqljs, react-native). Add the broadcasts to each driver's `query()` mirroring the existing sibling drivers. In NativeScript the native call is callback based, so `broadcasterResult.wait()` is awaited inside the callback right before resolving or rejecting, ensuring async subscribers settle before the query promise does, on both the success and failure paths. The failure branch also gains a missing `return` so a failed query no longer falls through and emits a spurious success event.
Both runners await the afterQuery broadcaster result from inside a callback (NativeScript) or after the awaited native call (Capacitor). A rejecting subscriber previously left the NativeScript query promise pending forever, and on Capacitor a subscriber rejection on the error path superseded the original query error via the trailing finally. Await the broadcaster result explicitly on each path: on the error path the subscriber rejection is swallowed so the original QueryFailedError is preserved, and on the success path it propagates as the query's own rejection. Both drivers now behave consistently. Also drop the any casts and the eslint-disable from the new test.
536ea9b to
f5c451a
Compare
Description
The Capacitor and NativeScript query runners never emit the
beforeQuery/afterQuerysubscriber events. Subscribers registered through these two drivers are therefore never invoked, unlike every other SQLite-family driver (better-sqlite3, cordova, expo, sqljs, react-native), all of which broadcast these events from theirquery()method.This has been the case since both drivers were added; they never contained the broadcast calls.
Fix
Add the
beforeQuery/afterQuerybroadcasts to each driver'squery(), mirroring the existing sibling drivers.afterQuerybroadcast andawait broadcasterResult.wait()are therefore placed inside the callback, right before resolving or rejecting, so that async subscribers settle before the query promise does. This is done on both the success and failure paths. The failure branch also gains areturnthat was missing: without it the handler fell through afterfail()and produced a second, spurious success result (previously harmless only because resolving an already-rejected promise is a no-op, but it would now emit an incorrect success event).Tests
Added
test/unit/driver/query-broadcast-events.test.tscovering Capacitor and NativeScript, success and failure, each asserting that an asyncafterQuerysubscriber has fully settled beforequery()resolves/rejects. With the previous (broken) NativeScript ordering the success/failure cases resolve before the subscriber settles; with the fix all four pass. The rest of the unit suite passes unchanged.These two drivers target mobile runtimes that are not exercised in CI, so verification is at the unit level against the broadcaster contract.