collection-sync / Exports / SynchronizableCollection
- cleanUp
- commitSync
- countAll
- findByIds
- initialize
- itemsNewerThan
- itemsToFetch
- itemsToPost
- itemsToSync
- latestUpdatedItem
- needsSync
- preCommitSync
- preExecuteSync
- rollbackSync
- sync
- syncAux
- syncBatch
• new SynchronizableCollection(syncMetadata
)
Name | Type |
---|---|
syncMetadata |
CollectionSyncMetadata |
SynchronizableCollection.ts:24
• Private
Optional
_parent: Collection
SynchronizableCollection.ts:20
• Private
Readonly
defaultSyncOptions: SyncOptions
SynchronizableCollection.ts:13
• syncMetadata: CollectionSyncMetadata
SynchronizableCollection.ts:22
• Private
synchronizers: Synchronizer
[] = []
Store history of sync operations.
SynchronizableCollection.ts:18
• get
lastSynchronizer(): undefined
| Synchronizer
undefined
| Synchronizer
SynchronizableCollection.ts:77
• get
parent(): undefined
| Collection
undefined
| Collection
SynchronizableCollection.ts:73
• set
parent(p
): void
Name | Type |
---|---|
p |
undefined | Collection |
void
SynchronizableCollection.ts:69
▸ cleanUp(_synchronizer
): Promise
<void
>
Executed at the end of each sync operation (whether it succeeded or not). It's recommended to implement cleaning logic if necessary.
Name | Type |
---|---|
_synchronizer |
Synchronizer |
Promise
<void
>
SynchronizableCollection.ts:63
▸ commitSync(_itemsToSync
, _ignoredItems
, _conflictItems
): Promise
<boolean
>
Commits the sync operation. Database engines that don't support
this should implement a method that returns true
(because the
data was already added without the need for a commit statement).
Make sure to commit the data from one specific sync process in order to avoid committing data
pushed by multiple users synchronizing at the same time.
Name | Type |
---|---|
_itemsToSync |
SyncItem [] |
_ignoredItems |
SyncItem [] |
_conflictItems |
SyncItem [] |
Promise
<boolean
>
SynchronizableCollection.ts:52
▸ Abstract
countAll(): number
| Promise
<number
>
Gets the number of items in the collection.
number
| Promise
<number
>
SynchronizableCollection.ts:28
▸ Abstract
findByIds(ids
): SyncItem
[] | Promise
<SyncItem
[]>
Returns a list of records using an ID list as search query.
Name | Type |
---|---|
ids |
DocId [] |
SyncItem
[] | Promise
<SyncItem
[]>
SynchronizableCollection.ts:29
▸ Abstract
initialize(): Promise
<void
>
Executes async logic to initialize collection or datastore (open file, create database connection, etc).
Promise
<void
>
SynchronizableCollection.ts:33
▸ Abstract
itemsNewerThan(date
, limit
): SyncItem
[] | Promise
<SyncItem
[]>
Returns a list of items that have updatedAt
greater than argument provided.
The list MUST be ordered by updatedAt ASC
, otherwise an exception will be thrown (no syncing
will be executed).
Name | Type |
---|---|
date |
undefined | Date |
limit |
number |
SyncItem
[] | Promise
<SyncItem
[]>
SynchronizableCollection.ts:31
▸ Private
itemsToFetch(lastSyncAt
, limit
): Promise
<SyncItem
[]>
Name | Type |
---|---|
lastSyncAt |
undefined | Date |
limit |
number |
Promise
<SyncItem
[]>
SynchronizableCollection.ts:115
▸ Private
itemsToPost(lastSyncAt
, limit
): Promise
<SyncItem
[]>
Name | Type |
---|---|
lastSyncAt |
undefined | Date |
limit |
number |
Promise
<SyncItem
[]>
SynchronizableCollection.ts:119
▸ itemsToSync(syncOperation
, limit
): Promise
<SyncItem
[]>
Gets list of items that can be synced (to either fetch or post).
Name | Type |
---|---|
syncOperation |
SyncOperation |
limit |
number |
Promise
<SyncItem
[]>
SynchronizableCollection.ts:124
▸ Abstract
latestUpdatedItem(): undefined
| SyncItem
| Promise
<undefined
| SyncItem
>
Gets the highest updateAt
date in the collection.
undefined
| SyncItem
| Promise
<undefined
| SyncItem
>
SynchronizableCollection.ts:32
▸ needsSync(syncOperation
): Promise
<boolean
>
Determines if synchronization is needed. This only performs a simple date check
to see if the source collection has at least one item that's newer than the last
sync date. This doesn't determine if items are actually different from those in the
destination collection. This means that even if this method returns true
, there may
be occasions where no item is actually synced because they were identical. Checking which
items have actually changed is more expensive, and usually it's recommended to be done
while executing the actual sync, and in small batches (the last sync date is updated after
every batch, meaning that after enough sync operations, this method will begin to return false
).
One example of this can be seen when the local collection posts an item to the parent collection,
updating the last post date, but not the fetch date. Then, when checking if fetch is necessary,
it will return true
because it just posted a new object and only based on dates, it will determine
that the item has not been fetched yet. However when executing the fetch operation, all items
will be ignored because that new item from the server collection is the same as the one in the
local collection (since it was the local collection which posted it in the first place). This happens
because last fetch and post dates are updated individually.
Name | Type |
---|---|
syncOperation |
SyncOperation |
Promise
<boolean
>
SynchronizableCollection.ts:100
▸ preCommitSync(_synchronizer
): Promise
<boolean
>
Executes before committing the data. If this method returns false
, then committing will
be aborted. It will only commit the data if the return value is true
.
Name | Type |
---|---|
_synchronizer |
Synchronizer |
Promise
<boolean
>
SynchronizableCollection.ts:48
▸ preExecuteSync(_synchronizer
): Promise
<boolean
>
Executes before starting to send the data to the destination collection.
If this method returns false
, syncing will be aborted, and will continue only if
the return value is true
.
Name | Type |
---|---|
_synchronizer |
Synchronizer |
Promise
<boolean
>
SynchronizableCollection.ts:40
▸ rollbackSync(_itemsToSync
, _ignoredItems
, _conflictItems
): Promise
<void
>
Rollbacks the current data that's being synchronized. Make sure to rollback the data from one specific sync process in order to avoid discarding data pushed by multiple users synchronizing at the same time.
Name | Type |
---|---|
_itemsToSync |
SyncItem [] |
_ignoredItems |
SyncItem [] |
_conflictItems |
SyncItem [] |
Promise
<void
>
SynchronizableCollection.ts:56
▸ sync(syncOperation
, limit
, options?
, date?
): Promise
<Synchronizer
>
Wraps sync operation so that cleanUp
and rollback
are conveniently placed at the end
and always executed.
Name | Type |
---|---|
syncOperation |
SyncOperation |
limit |
number |
options |
SyncOptions |
date? |
Date |
Promise
<Synchronizer
>
SynchronizableCollection.ts:147
▸ Private
syncAux(synchronizer
, syncOperation
): Promise
<void
>
Name | Type |
---|---|
synchronizer |
Synchronizer |
syncOperation |
SyncOperation |
Promise
<void
>
SynchronizableCollection.ts:173
▸ Abstract
syncBatch(items
): SyncItem
[] | Promise
<SyncItem
[]>
Syncs (upsert/delete) a batch (list) of items into this collection. Order of document processing doesn't need to be in any particular order.
Name | Type |
---|---|
items |
SyncItem [] |