generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SyncEngineLevel respects most recent startSync interval. (#887)
This PR slightly modifies the way sync works. - startSync now does a sync operation immediately as well as setting an interval, this way you don't have to wait the entire interval. - calling subsequent startSync will: - replace the interval - if there is a sync already running it will not perform a sync immediately, if no sync is running it will also perform an immediate sync. - calling a sync performs a one-shot sync. - calling a sync while a sync is already in progress will throw.
- Loading branch information
1 parent
4527444
commit da3630a
Showing
5 changed files
with
208 additions
and
37 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
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,13 +1,43 @@ | ||
import type { Web5PlatformAgent } from './agent.js'; | ||
|
||
/** | ||
* The SyncEngine is responsible for syncing messages between the agent and the platform. | ||
*/ | ||
export type SyncIdentityOptions = { | ||
/** | ||
* The delegate DID that should be used to sign the sync messages. | ||
*/ | ||
delegateDid?: string; | ||
/** | ||
* The protocols that should be synced for this identity, if an empty array is provided, all messages for all protocols will be synced. | ||
*/ | ||
protocols: string[] | ||
} | ||
export interface SyncEngine { | ||
/** | ||
* The agent that the SyncEngine is attached to. | ||
*/ | ||
agent: Web5PlatformAgent; | ||
/** | ||
* Register an identity to be managed by the SyncEngine for syncing. | ||
* The options can define specific protocols that should only be synced, or a delegate DID that should be used to sign the sync messages. | ||
*/ | ||
registerIdentity(params: { did: string, options?: SyncIdentityOptions }): Promise<void>; | ||
/** | ||
* Preforms a one-shot sync operation. If no direction is provided, it will perform both push and pull. | ||
* @param direction which direction you'd like to perform the sync operation. | ||
* | ||
* @throws {Error} if a sync is already in progress or the sync operation fails. | ||
*/ | ||
sync(direction?: 'push' | 'pull'): Promise<void>; | ||
/** | ||
* Starts a periodic sync that runs at an interval. Subsequent calls to startSync will update the interval. | ||
* | ||
* @param params { interval: string } the interval at which the sync operation should be performed. ex: '30s', '1m', '10m' | ||
*/ | ||
startSync(params: { interval: string }): Promise<void>; | ||
/** | ||
* Stops the periodic sync operation, will complete the current sync operation if one is already in progress. | ||
*/ | ||
stopSync(): void; | ||
} |
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