diff --git a/packages/powersync-sdk-common/src/client/AbstractPowerSyncDatabase.ts b/packages/powersync-sdk-common/src/client/AbstractPowerSyncDatabase.ts index bad6431b..958cbce6 100644 --- a/packages/powersync-sdk-common/src/client/AbstractPowerSyncDatabase.ts +++ b/packages/powersync-sdk-common/src/client/AbstractPowerSyncDatabase.ts @@ -114,14 +114,25 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver cb.initialized?.()); } + /** + * Replace the schema with a new version. This is for advanced use cases - typically the schema should just be specified once in the constructor. + * + * Cannot be used while connected - this should only be called before [AbstractPowerSyncDatabase.connect]. + */ async updateSchema(schema: Schema) { if (this.abortController) { throw new Error('Cannot update schema while connected'); @@ -226,6 +242,11 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver(callback: (db: DBAdapter) => Promise) { @@ -466,6 +488,12 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver( callback: (tx: Transaction) => Promise, lockTimeout: number = DEFAULT_LOCK_TIMEOUT_MS @@ -481,6 +509,11 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver( callback: (tx: Transaction) => Promise, lockTimeout: number = DEFAULT_LOCK_TIMEOUT_MS @@ -496,6 +529,11 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver { //Fetch initial data yield await this.executeReadOnly(sql, parameters); @@ -582,6 +620,9 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver tx.execute(sql, params)); diff --git a/packages/powersync-sdk-common/src/client/AbstractPowerSyncOpenFactory.ts b/packages/powersync-sdk-common/src/client/AbstractPowerSyncOpenFactory.ts index 7d7e8ab0..dfaa1e9d 100644 --- a/packages/powersync-sdk-common/src/client/AbstractPowerSyncOpenFactory.ts +++ b/packages/powersync-sdk-common/src/client/AbstractPowerSyncOpenFactory.ts @@ -20,6 +20,9 @@ export abstract class AbstractPowerSyncDatabaseOpenFactory { options.logger = options.logger ?? Logger.get(`PowerSync ${this.options.dbFilename}`); } + /** + * Schema used for the local database. + */ get schema() { return this.options.schema; } diff --git a/packages/powersync-sdk-common/src/client/sync/bucket/CrudBatch.ts b/packages/powersync-sdk-common/src/client/sync/bucket/CrudBatch.ts index 51ac45fc..683f56fb 100644 --- a/packages/powersync-sdk-common/src/client/sync/bucket/CrudBatch.ts +++ b/packages/powersync-sdk-common/src/client/sync/bucket/CrudBatch.ts @@ -1,9 +1,21 @@ import { CrudEntry } from './CrudEntry'; +/** + * TODO + */ export class CrudBatch { constructor( + /** + * List of client-side changes. + */ public crud: CrudEntry[], + /** + * true if there are more changes in the local queue. + */ public haveMore: boolean, + /** + * Call to remove the changes from the local queue, once successfully uploaded. + */ public complete: (writeCheckpoint?: string) => Promise ) {} } diff --git a/packages/powersync-sdk-common/src/client/sync/bucket/CrudEntry.ts b/packages/powersync-sdk-common/src/client/sync/bucket/CrudEntry.ts index 25732ae7..a12fe3d0 100644 --- a/packages/powersync-sdk-common/src/client/sync/bucket/CrudEntry.ts +++ b/packages/powersync-sdk-common/src/client/sync/bucket/CrudEntry.ts @@ -38,12 +38,33 @@ export type CrudEntryOutputJSON = { data: Record; }; +/** + * A single client-side change. + */ export class CrudEntry { + /** + * Auto-incrementing client-side id. + */ clientId: number; + /** + * ID of the changed row. + */ id: string; + /** + * Type of change. + */ op: UpdateType; + /** + * Data associated with the change. + */ opData?: Record; + /** + * Table that contained the change. + */ table: string; + /** + * Auto-incrementing transaction id. This is the same for all operations within the same transaction. + */ transactionId?: number; static fromRow(dbRow: CrudEntryJSON) { @@ -67,6 +88,9 @@ export class CrudEntry { this.transactionId = transactionId; } + /** + * TODO: Converts the change to JSON format, as required by the dev crud API. + */ toJSON(): CrudEntryOutputJSON { return { op_id: this.clientId, @@ -78,6 +102,9 @@ export class CrudEntry { }; } + /** + * The hash code for this object. + */ hashCode() { return hash([this.transactionId, this.clientId, this.op, this.table, this.id, this.opData]); } diff --git a/packages/powersync-sdk-common/src/client/sync/bucket/CrudTransaction.ts b/packages/powersync-sdk-common/src/client/sync/bucket/CrudTransaction.ts index 1a726b23..ad5f6ee9 100644 --- a/packages/powersync-sdk-common/src/client/sync/bucket/CrudTransaction.ts +++ b/packages/powersync-sdk-common/src/client/sync/bucket/CrudTransaction.ts @@ -1,10 +1,22 @@ import { CrudBatch } from './CrudBatch'; import { CrudEntry } from './CrudEntry'; +/** + * TODO + */ export class CrudTransaction extends CrudBatch { constructor( + /** + * List of client-side changes. + */ public crud: CrudEntry[], + /** + * Call to remove the changes from the local queue, once successfully uploaded. + */ public complete: (checkpoint?: string) => Promise, + /** + * Unique transaction id. + */ public transactionId?: number ) { super(crud, false, complete); diff --git a/packages/powersync-sdk-common/src/client/sync/bucket/SqliteBucketStorage.ts b/packages/powersync-sdk-common/src/client/sync/bucket/SqliteBucketStorage.ts index 6a0310d2..0c727ee9 100644 --- a/packages/powersync-sdk-common/src/client/sync/bucket/SqliteBucketStorage.ts +++ b/packages/powersync-sdk-common/src/client/sync/bucket/SqliteBucketStorage.ts @@ -80,8 +80,6 @@ export class SqliteBucketStorage implements BucketStorageAdapter { /** * Mark a bucket for deletion. - * - * @param bucket */ private async deleteBucket(bucket: string) { // Delete a bucket, but allow it to be re-created. diff --git a/packages/powersync-sdk-common/src/db/crud/SyncStatus.ts b/packages/powersync-sdk-common/src/db/crud/SyncStatus.ts index e4d5e14f..a5f30bf1 100644 --- a/packages/powersync-sdk-common/src/db/crud/SyncStatus.ts +++ b/packages/powersync-sdk-common/src/db/crud/SyncStatus.ts @@ -14,14 +14,23 @@ export type SyncStatusOptions = { export class SyncStatus { constructor(protected options: SyncStatusOptions) {} + /** + * true if currently connected. + */ get connected() { return this.options.connected ?? false; } + /** + * TODO + */ get lastSyncedAt() { return this.options.lastSyncedAt; } + /** + * TODO + */ get dataFlowStatus() { return ( this.options.dataFlow ?? { diff --git a/packages/powersync-sdk-common/src/db/crud/UploadQueueStatus.ts b/packages/powersync-sdk-common/src/db/crud/UploadQueueStatus.ts index 8ad7e5d2..53fcde73 100644 --- a/packages/powersync-sdk-common/src/db/crud/UploadQueueStatus.ts +++ b/packages/powersync-sdk-common/src/db/crud/UploadQueueStatus.ts @@ -1,6 +1,12 @@ export class UploadQueueStats { constructor( + /** + * Number of records in the upload queue. + */ public count: number, + /** + * Size of the upload queue in bytes. + */ public size: number = null ) {}