-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f202944
commit 64c1840
Showing
5 changed files
with
73 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 57 additions & 4 deletions
61
packages/web/src/db/sync/SSRWebStreamingSyncImplementation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,76 @@ | ||
import { | ||
AbstractStreamingSyncImplementation, | ||
AbstractStreamingSyncImplementationOptions, | ||
BaseObserver, | ||
LockOptions, | ||
LockType | ||
LockType, | ||
PowerSyncConnectionOptions, | ||
StreamingSyncImplementation, | ||
SyncStatus, | ||
SyncStatusOptions | ||
} from '@powersync/common'; | ||
import { Mutex } from 'async-mutex'; | ||
|
||
export class SSRStreamingSyncImplementation extends AbstractStreamingSyncImplementation { | ||
export class SSRStreamingSyncImplementation extends BaseObserver implements StreamingSyncImplementation { | ||
syncMutex: Mutex; | ||
crudMutex: Mutex; | ||
|
||
isConnected: boolean; | ||
lastSyncedAt?: Date | undefined; | ||
syncStatus: SyncStatus; | ||
|
||
constructor(options: AbstractStreamingSyncImplementationOptions) { | ||
super(options); | ||
super(); | ||
this.syncMutex = new Mutex(); | ||
this.crudMutex = new Mutex(); | ||
this.syncStatus = new SyncStatus({}); | ||
this.isConnected = false; | ||
} | ||
|
||
obtainLock<T>(lockOptions: LockOptions<T>): Promise<T> { | ||
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<void> {} | ||
|
||
async dispose() {} | ||
|
||
/** | ||
* This is a no-op in SSR mode | ||
*/ | ||
async disconnect(): Promise<void> {} | ||
|
||
/** | ||
* This SSR Mode implementation is immediately ready. | ||
*/ | ||
async waitForReady() {} | ||
|
||
/** | ||
* This will never resolve in SSR Mode. | ||
*/ | ||
async waitForStatus(status: SyncStatusOptions) { | ||
return new Promise<void>((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() {} | ||
} |