Skip to content

Commit a0e739e

Browse files
[Fix] Missing transactionId value + Reconnect Issue (#59)
1 parent ac800cc commit a0e739e

File tree

5 files changed

+58
-12
lines changed

5 files changed

+58
-12
lines changed

.changeset/little-bikes-sort.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@journeyapps/powersync-sdk-common': patch
3+
---
4+
5+
Fixed missing `transactionId` value in crud transaction response.

.changeset/sharp-lamps-perform.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@journeyapps/powersync-sdk-react-native': patch
3+
---
4+
5+
Fixed issue where SDK would fail to reconnect after disconnecting.

demos/react-native-supabase-todolist/ios/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ SPEC CHECKSUMS:
13531353
ExpoSecureStore: c84ae37d1c36f38524d289c67c3a2e3fc56f1108
13541354
EXSplashScreen: 39244885abfb1b12765aae89edb90f8c88db6bbd
13551355
FBLazyVector: fbc4957d9aa695250b55d879c1d86f79d7e69ab4
1356-
FBReactNativeSpec: 330cf4c6cf09f4085799e5e5fa0e1adc22972cf2
1356+
FBReactNativeSpec: 1b6e109181e519dc05c5f0a0546cb8c60cd9a4bb
13571357
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
13581358
glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2
13591359
hermes-engine: b361c9ef5ef3cda53f66e195599b47e1f84ffa35
@@ -1399,7 +1399,7 @@ SPEC CHECKSUMS:
13991399
React-RCTText: 73006e95ca359595c2510c1c0114027c85a6ddd3
14001400
React-RCTVibration: 599f427f9cbdd9c4bf38959ca020e8fef0717211
14011401
React-rendererdebug: f2946e0a1c3b906e71555a7c4a39aa6a6c0e639b
1402-
React-rncore: cf40dd2b824f5443532aa504dfb812319da9ff0a
1402+
React-rncore: c165a5d77c7785ae19fa5599fea04cc71a9c9ea4
14031403
React-runtimeexecutor: 2d1f64f58193f00a3ad71d3f89c2bfbfe11cf5a5
14041404
React-runtimescheduler: df8945a656356ff10f58f65a70820478bfcf33ad
14051405
React-utils: f5bc61e7ea3325c0732ae2d755f4441940163b85
@@ -1410,9 +1410,9 @@ SPEC CHECKSUMS:
14101410
RNScreens: b582cb834dc4133307562e930e8fa914b8c04ef2
14111411
RNVectorIcons: 210f910e834e3485af40693ad4615c1ec22fc02b
14121412
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
1413-
Yoga: 13c8ef87792450193e117976337b8527b49e8c03
1413+
Yoga: e64aa65de36c0832d04e8c7bd614396c77a80047
14141414
ZXingObjC: 8898711ab495761b2dbbdec76d90164a6d7e14c5
14151415

14161416
PODFILE CHECKSUM: 91f1b09fe73837e9fdaecdd06e4916926352d556
14171417

1418-
COCOAPODS: 1.14.3
1418+
COCOAPODS: 1.13.0

packages/powersync-sdk-common/src/client/AbstractPowerSyncDatabase.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import { CrudBatch } from './sync/bucket/CrudBatch';
1515
import { CrudTransaction } from './sync/bucket/CrudTransaction';
1616
import { BucketStorageAdapter, PSInternalTable } from './sync/bucket/BucketStorageAdapter';
17-
import { CrudEntry } from './sync/bucket/CrudEntry';
17+
import { CrudEntry, CrudEntryJSON } from './sync/bucket/CrudEntry';
1818
import { mutexRunExclusive } from '../utils/mutex';
1919
import { BaseObserver } from '../utils/BaseObserver';
2020
import { EventIterator } from 'event-iterator';
@@ -394,22 +394,24 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
394394
*/
395395
async getNextCrudTransaction(): Promise<CrudTransaction> {
396396
return await this.readTransaction(async (tx) => {
397-
const first = await tx.execute(`SELECT id, tx_id, data FROM ${PSInternalTable.CRUD} ORDER BY id ASC LIMIT 1`);
397+
const first = await tx.getOptional<CrudEntryJSON>(
398+
`SELECT id, tx_id, data FROM ${PSInternalTable.CRUD} ORDER BY id ASC LIMIT 1`
399+
);
398400

399-
if (!first.rows.length) {
401+
if (!first) {
400402
return null;
401403
}
402-
const txId: number | undefined = first['tx_id'];
404+
const txId = first.tx_id;
403405

404406
let all: CrudEntry[] = [];
405407
if (!txId) {
406-
all = [CrudEntry.fromRow(first.rows.item(0))];
408+
all = [CrudEntry.fromRow(first)];
407409
} else {
408-
const result = await tx.execute(
410+
const result = await tx.getAll<CrudEntryJSON>(
409411
`SELECT id, tx_id, data FROM ${PSInternalTable.CRUD} WHERE tx_id = ? ORDER BY id ASC`,
410412
[txId]
411413
);
412-
all = result.rows._array.map((row) => CrudEntry.fromRow(row));
414+
all = result.map((row) => CrudEntry.fromRow(row));
413415
}
414416

415417
const last = all[all.length - 1];

packages/powersync-sdk-react-native/src/sync/stream/ReactNativeRemote.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,40 @@ export class ReactNativeRemote extends AbstractRemote {
100100
throw error;
101101
}
102102

103-
return res.body;
103+
/**
104+
* The can-ndjson-stream does not handle aborted streams well on web.
105+
* This will intercept the readable stream and close the stream if
106+
* aborted.
107+
* TODO this function is duplicated in the Web SDK.
108+
* The common SDK is a bit oblivious to `ReadableStream` classes.
109+
* This should be improved when moving to Websockets
110+
*/
111+
const reader = res.body.getReader();
112+
const outputStream = new ReadableStream({
113+
start(controller) {
114+
return processStream();
115+
116+
async function processStream(): Promise<void> {
117+
if (signal?.aborted) {
118+
controller.close();
119+
}
120+
try {
121+
const { done, value } = await reader.read();
122+
// When no more data needs to be consumed, close the stream
123+
if (done) {
124+
controller.close();
125+
return;
126+
}
127+
// Enqueue the next data chunk into our target stream
128+
controller.enqueue(value);
129+
return processStream();
130+
} catch (ex) {
131+
controller.close();
132+
}
133+
}
134+
}
135+
});
136+
137+
return new Response(outputStream).body;
104138
}
105139
}

0 commit comments

Comments
 (0)