feat: add services package
This commit is contained in:
14
packages/services/src/Domain/Sync/SyncMode.ts
Normal file
14
packages/services/src/Domain/Sync/SyncMode.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
/* istanbul ignore file */
|
||||
|
||||
export enum SyncMode {
|
||||
/**
|
||||
* Performs a standard sync, uploading any dirty items and retrieving items.
|
||||
*/
|
||||
Default = 1,
|
||||
/**
|
||||
* The first sync for an account, where we first want to download all remote items first
|
||||
* before uploading any dirty items. This allows a consumer, for example, to download
|
||||
* all data to see if user has an items key, and if not, only then create a new one.
|
||||
*/
|
||||
DownloadFirst = 2,
|
||||
}
|
||||
21
packages/services/src/Domain/Sync/SyncOptions.ts
Normal file
21
packages/services/src/Domain/Sync/SyncOptions.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/* istanbul ignore file */
|
||||
|
||||
import { SyncMode } from './SyncMode'
|
||||
import { SyncQueueStrategy } from './SyncQueueStrategy'
|
||||
import { SyncSource } from './SyncSource'
|
||||
|
||||
export type SyncOptions = {
|
||||
queueStrategy?: SyncQueueStrategy
|
||||
mode?: SyncMode
|
||||
/** Whether the server should compute and return an integrity hash. */
|
||||
checkIntegrity?: boolean
|
||||
/** Internally used to keep track of how sync requests were spawned. */
|
||||
source: SyncSource
|
||||
/** Whether to await any sync requests that may be queued from this call. */
|
||||
awaitAll?: boolean
|
||||
/**
|
||||
* A callback that is triggered after pre-sync save completes,
|
||||
* and before the sync request is network dispatched
|
||||
*/
|
||||
onPresyncSave?: () => void
|
||||
}
|
||||
14
packages/services/src/Domain/Sync/SyncQueueStrategy.ts
Normal file
14
packages/services/src/Domain/Sync/SyncQueueStrategy.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
/* istanbul ignore file */
|
||||
|
||||
export enum SyncQueueStrategy {
|
||||
/**
|
||||
* Promise will be resolved on the next sync request after the current one completes.
|
||||
* If there is no scheduled sync request, one will be scheduled.
|
||||
*/
|
||||
ResolveOnNext = 1,
|
||||
/**
|
||||
* A new sync request is guarenteed to be generated for your request, no matter how long it takes.
|
||||
* Promise will be resolved whenever this sync request is processed in the serial queue.
|
||||
*/
|
||||
ForceSpawnNew = 2,
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
/* istanbul ignore file */
|
||||
|
||||
import { SyncOptions } from './SyncOptions'
|
||||
|
||||
export interface SyncServiceInterface {
|
||||
sync(options?: Partial<SyncOptions>): Promise<unknown>
|
||||
}
|
||||
11
packages/services/src/Domain/Sync/SyncSource.ts
Normal file
11
packages/services/src/Domain/Sync/SyncSource.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
/* istanbul ignore file */
|
||||
|
||||
export enum SyncSource {
|
||||
External = 1,
|
||||
SpawnQueue = 2,
|
||||
ResolveQueue = 3,
|
||||
MoreDirtyItems = 4,
|
||||
AfterDownloadFirst = 5,
|
||||
IntegrityCheck = 6,
|
||||
ResolveOutOfSync = 7,
|
||||
}
|
||||
Reference in New Issue
Block a user