feat: add services package

This commit is contained in:
Karol Sójko
2022-07-05 20:51:42 +02:00
parent b614c71e79
commit fbfed0a05c
85 changed files with 2418 additions and 28 deletions

View 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,
}

View 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
}

View 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,
}

View File

@@ -0,0 +1,7 @@
/* istanbul ignore file */
import { SyncOptions } from './SyncOptions'
export interface SyncServiceInterface {
sync(options?: Partial<SyncOptions>): Promise<unknown>
}

View 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,
}