SudoSOS Back-end API / internal/sync-service / SyncService
Abstract Class: SyncService<T> ​
SyncService interface.
SyncService is the abstract class which is used to sync entity data. This can be used to integrate external data sources into the SudoSOS back-end.
Extends ​
Extended by ​
Type Parameters ​
| Type Parameter |
|---|
T |
Constructors ​
Constructor ​
new SyncService<T>(manager?): SyncService<T>;Parameters ​
| Parameter | Type |
|---|---|
manager? | EntityManager |
Returns ​
SyncService<T>
Inherited from ​
Properties ​
| Property | Modifier | Type | Inherited from |
|---|---|---|---|
manager | protected | EntityManager | WithManager.manager |
Methods ​
down() ​
abstract down(entity, isDryRun?): Promise<void>;Down is called when the SyncService decides that the entity is no longer connected to this sync service be removed. This can be used to remove the entity from the database or clean up entities.
This should be revertible and idempotent!
Parameters ​
| Parameter | Type | Description |
|---|---|---|
entity | T | - |
isDryRun? | boolean | Whether this is a dry run (no actual changes) |
Returns ​
Promise<void>
fetch() ​
abstract fetch(): Promise<void>;Fetches the user data from the external data source. sync can be seen as a push and fetch as a pull.
Returns ​
Promise<void>
guard() ​
abstract guard(entity): Promise<boolean>;Guard determines whether the entity should be synced using this sync service.
Not passing the guard will result in the user being skipped. A skipped sync does not count as a failure.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
entity | T | The entity to check. |
Returns ​
Promise<boolean>
True if the entity should be synced, false otherwise.
post() ​
post(): Promise<void>;Called after a sync batch is finished.
Returns ​
Promise<void>
pre() ​
pre(): Promise<void>;Called before a sync batch is started.
Returns ​
Promise<void>
sync() ​
abstract protected sync(entity, isDryRun?): Promise<boolean>;Synchronizes the user data with the external data source.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
entity | T | The user to synchronize. |
isDryRun? | boolean | Whether this is a dry run (no actual changes) |
Returns ​
Promise<boolean>
True if the user was synchronized, false otherwise.
up() ​
up(entity, isDryRun?): Promise<SyncResult>;Up is a wrapper around sync that handles the guard.
Parameters ​
| Parameter | Type | Default value | Description |
|---|---|---|---|
entity | T | undefined | - |
isDryRun | boolean | false | Whether this is a dry run (no actual changes) |
Returns ​
Promise<SyncResult>
The result of the sync.