Skip to content

Commit 169942f

Browse files
Merge remote-tracking branch 'origin/main' into watches
2 parents 7193b12 + 97da283 commit 169942f

32 files changed

+190
-121
lines changed

.changeset/bright-snakes-clean.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

.changeset/cuddly-dingos-check.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

.changeset/mighty-doors-judge.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

.changeset/orange-baboons-work.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

.changeset/short-countries-swim.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/attachments/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"test": "pnpm build && vitest"
3030
},
3131
"peerDependencies": {
32-
"@powersync/common": "workspace:^1.33.2"
32+
"@powersync/common": "workspace:^1.34.0"
3333
},
3434
"devDependencies": {
3535
"@powersync/common": "workspace:*",

packages/common/CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# @powersync/common
22

3+
## 1.34.0
4+
5+
### Minor Changes
6+
7+
- ab33799: Add experimental support for raw tables, giving you full control over the table structure to sync into.
8+
While PowerSync manages tables as JSON views by default, raw tables have to be created by the application
9+
developer.
10+
11+
For more information about raw tables, see [the documentation](https://docs.powersync.com/usage/use-case-examples/raw-tables).
12+
13+
- 810c6ad: Propagate logger from PowerSyncDatabase to streaming sync and remote implementations, and tweak some log messages.
14+
15+
### Patch Changes
16+
17+
- a1aa18c: Fix sync stream delays during CRUD upload.
18+
- 9fb898d: [Internal] Removed shared mutex implementation of `readLock` and `writeLock`.
19+
320
## 1.33.2
421

522
### Patch Changes

packages/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@powersync/common",
3-
"version": "1.33.2",
3+
"version": "1.34.0",
44
"publishConfig": {
55
"registry": "https://registry.npmjs.org/",
66
"access": "public"

packages/common/src/client/AbstractPowerSyncDatabase.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ export const DEFAULT_POWERSYNC_CLOSE_OPTIONS: PowerSyncCloseOptions = {
143143

144144
export const DEFAULT_POWERSYNC_DB_OPTIONS = {
145145
retryDelayMs: 5000,
146-
logger: Logger.get('PowerSyncDatabase'),
147146
crudUploadThrottleMs: DEFAULT_CRUD_UPLOAD_THROTTLE_MS
148147
};
149148

@@ -192,6 +191,8 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
192191

193192
protected runExclusiveMutex: Mutex;
194193

194+
logger: ILogger;
195+
195196
constructor(options: PowerSyncDatabaseOptionsWithDBAdapter);
196197
constructor(options: PowerSyncDatabaseOptionsWithOpenFactory);
197198
constructor(options: PowerSyncDatabaseOptionsWithSettings);
@@ -215,6 +216,8 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
215216
throw new Error('The provided `database` option is invalid.');
216217
}
217218

219+
this.logger = options.logger ?? Logger.get(`PowerSyncDatabase[${this._database.name}]`);
220+
218221
this.bucketStorageAdapter = this.generateBucketStorageAdapter();
219222
this.closed = false;
220223
this.currentStatus = new SyncStatus({});
@@ -435,7 +438,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
435438
try {
436439
schema.validate();
437440
} catch (ex) {
438-
this.options.logger?.warn('Schema validation failed. Unexpected behaviour could occur', ex);
441+
this.logger.warn('Schema validation failed. Unexpected behaviour could occur', ex);
439442
}
440443
this._schema = schema;
441444

@@ -444,10 +447,6 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
444447
this.iterateListeners(async (cb) => cb.schemaChanged?.(schema));
445448
}
446449

447-
get logger() {
448-
return this.options.logger!;
449-
}
450-
451450
/**
452451
* Wait for initialization to complete.
453452
* While initializing is automatic, this helps to catch and report initialization errors.
@@ -951,7 +950,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
951950
* @param options Options for configuring watch behavior
952951
*/
953952
watchWithCallback(sql: string, parameters?: any[], handler?: WatchHandler, options?: SQLWatchOptions): void {
954-
const { onResult, onError = (e: Error) => this.options.logger?.error(e) } = handler ?? {};
953+
const { onResult, onError = (e: Error) => this.logger.error(e) } = handler ?? {};
955954
if (!onResult) {
956955
throw new Error('onResult is required');
957956
}
@@ -1111,7 +1110,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
11111110
* @returns A dispose function to stop watching for changes
11121111
*/
11131112
onChangeWithCallback(handler?: WatchOnChangeHandler, options?: SQLOnChangeOptions): () => void {
1114-
const { onChange, onError = (e: Error) => this.options.logger?.error(e) } = handler ?? {};
1113+
const { onChange, onError = (e: Error) => this.logger.error(e) } = handler ?? {};
11151114
if (!onChange) {
11161115
throw new Error('onChange is required');
11171116
}

packages/common/src/client/sync/bucket/SqliteBucketStorage.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
9292
async saveSyncData(batch: SyncDataBatch, fixedKeyFormat: boolean = false) {
9393
await this.writeTransaction(async (tx) => {
9494
for (const b of batch.buckets) {
95-
const result = await tx.execute('INSERT INTO powersync_operations(op, data) VALUES(?, ?)', [
95+
await tx.execute('INSERT INTO powersync_operations(op, data) VALUES(?, ?)', [
9696
'save',
9797
JSON.stringify({ buckets: [b.toJSON(fixedKeyFormat)] })
9898
]);
99-
this.logger.debug('saveSyncData', JSON.stringify(result));
99+
this.logger.debug(`Saved batch of data for bucket: ${b.bucket}, operations: ${b.data.length}`);
100100
}
101101
});
102102
}
@@ -115,7 +115,7 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
115115
await tx.execute('INSERT INTO powersync_operations(op, data) VALUES(?, ?)', ['delete_bucket', bucket]);
116116
});
117117

118-
this.logger.debug('done deleting bucket');
118+
this.logger.debug(`Done deleting bucket ${bucket}`);
119119
}
120120

121121
async hasCompletedSync() {
@@ -139,6 +139,11 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
139139
}
140140
return { ready: false, checkpointValid: false, checkpointFailures: r.checkpointFailures };
141141
}
142+
if (priority == null) {
143+
this.logger.debug(`Validated checksums checkpoint ${checkpoint.last_op_id}`);
144+
} else {
145+
this.logger.debug(`Validated checksums for partial checkpoint ${checkpoint.last_op_id}, priority ${priority}`);
146+
}
142147

143148
let buckets = checkpoint.buckets;
144149
if (priority !== undefined) {
@@ -158,7 +163,6 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
158163

159164
const valid = await this.updateObjectsFromBuckets(checkpoint, priority);
160165
if (!valid) {
161-
this.logger.debug('Not at a consistent checkpoint - cannot update local db');
162166
return { ready: false, checkpointValid: true };
163167
}
164168

@@ -221,7 +225,6 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
221225
]);
222226

223227
const resultItem = rs.rows?.item(0);
224-
this.logger.debug('validateChecksums priority, checkpoint, result item', priority, checkpoint, resultItem);
225228
if (!resultItem) {
226229
return {
227230
checkpointValid: false,
@@ -262,34 +265,32 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
262265

263266
const opId = await cb();
264267

265-
this.logger.debug(`[updateLocalTarget] Updating target to checkpoint ${opId}`);
266-
267268
return this.writeTransaction(async (tx) => {
268269
const anyData = await tx.execute('SELECT 1 FROM ps_crud LIMIT 1');
269270
if (anyData.rows?.length) {
270271
// if isNotEmpty
271-
this.logger.debug('updateLocalTarget', 'ps crud is not empty');
272+
this.logger.debug(`New data uploaded since write checkpoint ${opId} - need new write checkpoint`);
272273
return false;
273274
}
274275

275276
const rs = await tx.execute("SELECT seq FROM sqlite_sequence WHERE name = 'ps_crud'");
276277
if (!rs.rows?.length) {
277278
// assert isNotEmpty
278-
throw new Error('SQlite Sequence should not be empty');
279+
throw new Error('SQLite Sequence should not be empty');
279280
}
280281

281282
const seqAfter: number = rs.rows?.item(0)['seq'];
282-
this.logger.debug('seqAfter', JSON.stringify(rs.rows?.item(0)));
283283
if (seqAfter != seqBefore) {
284-
this.logger.debug('seqAfter != seqBefore', seqAfter, seqBefore);
284+
this.logger.debug(
285+
`New data uploaded since write checpoint ${opId} - need new write checkpoint (sequence updated)`
286+
);
287+
285288
// New crud data may have been uploaded since we got the checkpoint. Abort.
286289
return false;
287290
}
288291

289-
const response = await tx.execute("UPDATE ps_buckets SET target_op = CAST(? as INTEGER) WHERE name='$local'", [
290-
opId
291-
]);
292-
this.logger.debug(['[updateLocalTarget] Response from updating target_op ', JSON.stringify(response)]);
292+
this.logger.debug(`Updating target write checkpoint to ${opId}`);
293+
await tx.execute("UPDATE ps_buckets SET target_op = CAST(? as INTEGER) WHERE name='$local'", [opId]);
293294
return true;
294295
});
295296
}

0 commit comments

Comments
 (0)