Skip to content

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 ​

ts
new SyncService<T>(manager?): SyncService<T>;

Parameters ​

ParameterType
manager?EntityManager

Returns ​

SyncService<T>

Inherited from ​

WithManager.constructor

Properties ​

PropertyModifierTypeInherited from
managerprotectedEntityManagerWithManager.manager

Methods ​

down() ​

ts
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 ​

ParameterTypeDescription
entityT-
isDryRun?booleanWhether this is a dry run (no actual changes)

Returns ​

Promise<void>


fetch() ​

ts
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() ​

ts
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 ​

ParameterTypeDescription
entityTThe entity to check.

Returns ​

Promise<boolean>

True if the entity should be synced, false otherwise.


post() ​

ts
post(): Promise<void>;

Called after a sync batch is finished.

Returns ​

Promise<void>


pre() ​

ts
pre(): Promise<void>;

Called before a sync batch is started.

Returns ​

Promise<void>


sync() ​

ts
abstract protected sync(entity, isDryRun?): Promise<boolean>;

Synchronizes the user data with the external data source.

Parameters ​

ParameterTypeDescription
entityTThe user to synchronize.
isDryRun?booleanWhether this is a dry run (no actual changes)

Returns ​

Promise<boolean>

True if the user was synchronized, false otherwise.


up() ​

ts
up(entity, isDryRun?): Promise<SyncResult>;

Up is a wrapper around sync that handles the guard.

Parameters ​

ParameterTypeDefault valueDescription
entityTundefined-
isDryRunbooleanfalseWhether this is a dry run (no actual changes)

Returns ​

Promise<SyncResult>

The result of the sync.