From 64c184020702885711248c69b5ce0c0614870610 Mon Sep 17 00:00:00 2001 From: Steven Ontong Date: Mon, 9 Sep 2024 10:22:26 +0200 Subject: [PATCH] ssr mode fixes --- .changeset/four-birds-raise.md | 6 ++ .../src/client/AbstractPowerSyncDatabase.ts | 3 +- packages/web/src/db/PowerSyncDatabase.ts | 8 +-- .../db/adapters/AbstractWebSQLOpenFactory.ts | 10 +-- .../sync/SSRWebStreamingSyncImplementation.ts | 61 +++++++++++++++++-- 5 files changed, 73 insertions(+), 15 deletions(-) create mode 100644 .changeset/four-birds-raise.md diff --git a/.changeset/four-birds-raise.md b/.changeset/four-birds-raise.md new file mode 100644 index 00000000..9bb3a6cb --- /dev/null +++ b/.changeset/four-birds-raise.md @@ -0,0 +1,6 @@ +--- +'@powersync/common': minor +'@powersync/web': minor +--- + +Fixed SSR Mode detection for DB adapters. Removed the potential for SSR Web Streamining implementations from to perform syncing operations. diff --git a/packages/common/src/client/AbstractPowerSyncDatabase.ts b/packages/common/src/client/AbstractPowerSyncDatabase.ts index d97d9642..9cbf37f2 100644 --- a/packages/common/src/client/AbstractPowerSyncDatabase.ts +++ b/packages/common/src/client/AbstractPowerSyncDatabase.ts @@ -23,7 +23,6 @@ import { CrudBatch } from './sync/bucket/CrudBatch'; import { CrudEntry, CrudEntryJSON } from './sync/bucket/CrudEntry'; import { CrudTransaction } from './sync/bucket/CrudTransaction'; import { - AbstractStreamingSyncImplementation, DEFAULT_CRUD_UPLOAD_THROTTLE_MS, PowerSyncConnectionOptions, StreamingSyncImplementation, @@ -239,7 +238,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver(lockOptions: LockOptions): Promise { const mutex = lockOptions.type == LockType.CRUD ? this.crudMutex : this.syncMutex; return mutex.runExclusive(lockOptions.callback); } + + /** + * This is a no-op in SSR mode + */ + async connect(options?: PowerSyncConnectionOptions): Promise {} + + async dispose() {} + + /** + * This is a no-op in SSR mode + */ + async disconnect(): Promise {} + + /** + * This SSR Mode implementation is immediately ready. + */ + async waitForReady() {} + + /** + * This will never resolve in SSR Mode. + */ + async waitForStatus(status: SyncStatusOptions) { + return new Promise((r) => {}); + } + + /** + * Returns a placeholder checkpoint. This should not be used. + */ + async getWriteCheckpoint() { + return '1'; + } + + /** + * The SSR mode adapter will never complete syncing. + */ + async hasCompletedSync() { + return false; + } + + /** + * This is a no-op in SSR mode. + */ + triggerCrudUpload() {} }