synckit 0.4.0
synckit: ^0.4.0 copied to clipboard
A Package to Sync data b/w Network and Local Storage.
0.4.0 #
New Features #
"Deleted Docs" Tracking & Sync
Added a system to track document deletions and synchronize them across network and local storage, ensuring that deletes on one client are propagated to others.
-
[Utils]: Added
DeleteDocDatatype alias (Map<String, int>) for representing deleted document metadata (ID → deletion timestamp). -
[NetworkStorage]: Added
getDeletedDocsPath(bool collectionBased, String path)static method to compute the Firestore path for storing deleted docs metadata. -
[NetworkStorage]: Added
streamDeletedDocsData([String? docPath])to stream deleted docs data in real-time. -
[NetworkStorage]: Added
getDeletedDocsData([String? docPath])to fetch deleted docs data. -
[NetworkStorage]: Added
transactionDeleteDoc(Transaction, Dataset<T>, [String? docPath])to write deleted doc metadata within a Firestore transaction. -
[NetworkStorage]:
delete,transactionDelete, andwriteBatchDeletenow also record deletion metadata to a separate deleted-docs document, enabling cross-client deletion sync. -
[LocalStorage]: Added
deleteFromIds(Iterable<String> ids)method to delete entries by IDs directly, without requiring a fullDataset. -
[SyncManager]: Added
syncDeletedDocsparameter (default:false) to opt-in to fetching and syncing deleted docs data from the network. -
[SyncManager]: Added
dispose()method to cancel all active stream subscriptions and prevent memory leaks. Subscription management has been moved here fromSyncedState. -
[SyncManager]:
fetchAndSyncFromNetworknow also fetches deleted docs data and removes those entries from local storage. -
[SyncManager]:
listenQueryFromNetworknow accepts anonDeletedDatacallback; whensyncDeletedDocsis enabled, it also listens to the deleted docs stream. -
[SyncManager]:
getQueryFromNetworknow accepts anonDeletedDatacallback; whensyncDeletedDocsis enabled, it also fetches deleted docs data. -
[SyncedState]:
keepQueryInSyncnow handles deleted docs by removing their IDs from state. -
[SyncedState]:
getQueryFromNetworknow handles deleted docs by removing their IDs from state. -
[SyncedState]:
dispose()now delegates toSyncManager.dispose(), centralizing subscription management.
0.3.19 #
- [SyncedState]: Added a new optional parameter on
refresh, i.ethrowError, allowing users to catch errors, in-case any part of the refresh fails.
0.3.18 #
Improvements #
- [SyncBatch]: Replaced
Completer<void>with callback-based approach. AddedasyncCallbacksandsyncCallbackslists withaddAsyncCallback()andaddSyncCallback()methods for more flexible post-commit operations. - [SyncManager]:
batchUpdate,batchRemove, andbatchClearnow execute local storage operations as async callbacks within the batch commit process. When youawaitthe batch commit, it will only complete successfully after all local storage operations have finished; if any of these operations fail, the commit will fail as well. - [SyncedState]:
batchRemoveAll,batchUpdate, andbatchClearnow schedule state updates via sync callbacks, so that batch commit only returns after successful completion of state update operations as well.
0.3.17 #
- [SyncedState] Removed
_assertIdsExistscheck on all types ofremovemethods.
0.3.16 #
Improvements #
-
[SyncManager]: Modified
fetchAndSyncFromNetworkto skipstorage.clear()whencollectionBasedis enabled. -
[SyncedState]: Updated
refreshandkeepAllInSyncto use a new_setOrUpdateStatemethod. This ensures that forcollectionBasedstorage, the state is updated incrementally instead of being completely overwritten.
0.3.15+1 #
Bug fix on the FirebaseException handling.
0.3.15 #
Improvements #
- [NetworkStorage]: Enhanced
getQueryto catchFirebaseExceptionwith codeunavailableand throw aPlatformExceptionwith codeCONN_FAILUREfor better connection failure handling.
0.3.14 #
New Features #
- [NetworkStorage]: Added
defaultGetOptionstoNetworkStorageto control the default FirestoreSource(server/cache) for fetch operations. Defaults toSource.server. - [NetworkStorage]: Updated
getAllandgetQueryto accept customGetOptions. - [SyncManager]: Updated
getQueryFromNetworkto support passing customGetOptions. - [SyncedState]: Updated
getQueryFromNetworkto support passing customGetOptions.
0.3.13 #
New Features #
- [History]: Made
Historyobject immutable and addedupdateLastSyncWithNetworkFetchTime()method that returns a newHistoryinstance. - [SyncConfig]: Added
onHistoryUpdatecallback that is triggered whenever the history is updated inSyncedState. - [SyncedState]: Updated to use the immutable
Historypattern and invokeonHistoryUpdatecallback. - [SyncManager]: Updated to use the immutable
Historypattern and addedonHistoryUpdatecallback.
0.3.12 #
New Features #
- [History]: Added a new
Historyobject withlastSyncWithNetworkFetchTimeandupdateLastSyncWithNetworkFetchTime()to track the latest successful network fetch sync time. - [SyncManager]: Added
historyto tracklastSyncWithNetworkFetchTimewhenever network fetch/listen/query operations sync data to local storage. - [SyncedState]: Added
historyupdates inrefresh,keepAllInSync,keepQueryInSync, andgetQueryFromNetworkafter network data is applied to state.
0.3.11+1 #
- [NetworkStorage]: Fixed a bug in
writeRuleswhere on executingwriteRuelsit was throwing error, instead now it will only log.
0.3.11 #
- [NetworkStorage]: Added
writeRulesparameter toNetworkStorage. Allowing users to apply custom rules, to filter out records, that should not be synced to Network Storage.
0.3.10+1 #
Bug Fixes #
- [SyncedState]: Fixed a bug in
SyncedStatewhere subscriptions were not being added to the_subscriptionslist, causing them to not be properly disposed and leading to potential memory leaks.
0.3.10 #
New Features #
- [NetworkStorage]: Added
streamAllandstreamQuerymethods to support real-time data synchronization from Firestore. - [SyncManager]: Added
listenAllFromNetworkandlistenQueryFromNetworkmethods to subscribe to network changes and automatically synchronize with local storage. - [SyncedState]: Added
keepAllInSyncandkeepQueryInSyncmethods to simplify real-time UI updates from your state notifier. - [SyncedState]: Added
disposemethod to cancel all active subscriptions and prevent memory leaks.
0.3.9 #
- [SyncedState] Added
stateOnlyoption forremoveandclearfunction, if set to true, the update will not be applied to local and network storage.
0.3.8 #
- [SyncedState] Added
stateOnlyoption forupdatefunction, if set to true, the update will not be applied to local and network storage.
0.3.7 #
New Features #
-
[LocalStorage]: Added
LocalStorage.disabled()constructor anddisabledparameter, mirroringNetworkStorage.disabled. When disabled, read operations (getAll) throwPlatformExceptionwith codeSYNC_OBJ_LOCAL_DISABLED, and write operations (update,delete,clear) andinitialize()are no-ops. Use this for network-only sync with no local persistence. -
[SyncedState]:
refresh()now handles local read failure (e.g. when local storage is disabled) in the same way as network failure: a try/catch aroundallFromStoragesets state to empty on throw, then the existing try/catch aroundfetchAndSyncFromNetworkruns. Network-only setups work without special-casing in SyncManager.
0.3.6 #
New Features #
- [LocalStorage]: Added
initializeCallbackparameter that accepts an optionalFuture<void> Function()to be called after Hive box initialization. - The
initialize()method now calls the provided callback after completing the default initialization process.
0.3.5 #
New Features #
Custom Query Fetch Support
Added getQueryFromNetwork method for fetching data from network using custom Firestore queries.
-
[NetworkStorage]: Enhanced
getQuerymethod with optionalmaxGetAllDocsparameter to override the default limit per call. -
[SyncManager]: Added
getQueryFromNetwork(QueryFn<T> queryFn, [int? maxGetAllDocs])method that fetches data using a custom query and optionally syncs with local storage. -
[SyncedState]: Added
getQueryFromNetwork(QueryFn<T> queryFn, {int? maxGetAllDocs})method that fetches data using a custom query and updates state with new entries.
0.3.4 #
Added method isInitialized to both [SyncManager] and [LocalStorage] to check if they have been initialized.
0.3.3 #
New Features #
Batch Clear Support
Added batchClear method to perform clear operations within a Firestore write batch, complementing the existing batchUpdate and batchRemove operations.
-
[NetworkStorage]: Added
writeBatchClear(WriteBatch batch, [String? docPath])method:- For collection-based storage: fetches all documents and adds delete operations for each to the batch.
- For non-collection-based storage: adds a delete operation for the document at the given path.
- Note: This method is async as collection-based mode requires fetching document references.
-
[SyncManager]: Added
batchClear(SyncBatch syncBatch)method that queues clear operations on the network batch, waits for batch commit, then clears local storage. -
[SyncedState]: Added
batchClear(SyncBatch batch)method that queues a clear operation in the batch and clears local state. Note: Callbatch.commit()after all batch operations.
0.3.2 #
New Features #
Batch Operations Support
Added support for batch operations to perform multiple updates/deletes in a single Firestore write batch, improving performance and ensuring atomicity.
-
[SyncBatch]: New class wrapping Firestore
WriteBatchwith aCompleter<void>for async completion tracking.batch: The underlying FirestoreWriteBatch.completer: ACompleter<void>that completes when the batch is committed.commit(): Commits the batch and completes the completer.
-
[SyncManager]: Added batch operation methods:
batchUpdate(Dataset<T> data, SyncBatch syncBatch): Performs a batch update operation using the providedSyncBatch. Updates network first, waits for batch commit, then updates local storage.batchRemove(Dataset<T> data, SyncBatch syncBatch): Performs a batch remove operation using the providedSyncBatch. Deletes from network first, waits for batch commit, then deletes from local storage.
-
[SyncedState]: Added batch operation methods:
batchUpdate(T value, SyncBatch batch): Queues a value update in the batch and updates local state immediately. Note: Callbatch.commit()after all batch operations.batchRemoveAll(Iterable<String> ids, SyncBatch batch): Queues removal of multiple items by IDs in the batch and updates local state immediately.
0.3.1 #
Fixed bug of syncLocalWithNetworkOnFetch not working.
0.3.0 #
Breaking Changes #
- [NetworkStorage]: Renamed
defaultDocPathparameter topathfor better clarity and consistency.
New Features #
Collection-Based Storage Mode
Added support for collection-based storage in NetworkStorage, where each record is stored as a separate Firestore document instead of all records in a single document. This is useful for larger datasets or when you need to query individual records.
- New
collectionBasedparameter inNetworkStorageconstructor to enable collection-based mode. - New
NetworkStorageCollectionBasedConfig<T>class for configuring collection-based storage:getAllEnabled: Controls whethergetAllis allowed for collection-based storage (default:true).maxGetAllDocs: Maximum number of documents to fetch ingetAlloperations (default:10).defaultQuery: Default query function (QueryFn<T>) for filtering/ordering documents.
- New
QueryFn<T>typedef:Query<T> Function(Query<T> colRef)for custom query builders. - New
getQuerymethod inNetworkStoragefor querying collection-based storage with custom Firestore queries.
Sync Improvements
- [SyncManager]: Added
syncLocalWithNetworkOnFetchparameter (default:true) to control whether local storage should be synchronized with network data on fetch operations. - [SyncManager]: Added new
fetchAndSyncFromNetworkgetter that fetches data from the network and optionally clears and updates local storage to match. - [SyncedState]: The
refreshmethod now usesfetchAndSyncFromNetworkinstead ofallFromNetwork, ensuring local storage stays in sync with network data. - [SyncedState]: Changed
_paramsfromlate finaltolateto allow reassignment/reconfiguration.
Bug Fixes #
- [NetworkStorage.getAll]: Now returns an empty
IMap<String, T>if the Firestore document doesn't exist, instead of throwing a null error. - [NetworkStorage.writeBatchDelete]: Fixed return type to properly return
voidinstead of an unintended value.
Internal Changes #
- All
NetworkStoragemethods (update,transactionUpdate,writeBatchUpdate,delete,transactionDelete,writeBatchDelete,clear) now fully support collection-based mode. - Collection-based operations use
WriteBatchfor efficient bulk operations. - Added Firestore
withConvertersupport for type-safe document operations in collection-based mode.
0.2.7 #
Updated dependencies
0.2.6 #
Added new copyWith method to [StdObjParams].
0.2.5 #
Removed flutter_riverpod dependency. This should not be a Breaking Change, since none of the functionality actually depended on flutter_riverpod.
0.2.4 #
Added new refresh method in [SyncedState].
0.2.3 #
Fixed bug in [SyncedState]'s clear method, which now clears the state as well.
0.2.2 #
Fixed a bug in [SyncedState]'s update method, with sorting enabled, causing
the newly added last element in the sorted dataset, to not be visible in state.
0.2.1 #
Fixed a bug in [SyncedState]'s update method, with sorting enabled.
0.2.0 #
[Breaking Change]: Replaced [hive_flutter] with [hive_ce_flutter].
0.1.0 #
[Breaking Change]: Replaced Ref<Dataset<T>> in NotifierProviderRef<Dataset<T>> in [SyncedState].
0.0.1 #
Contain important classes like [LocalStorage], [NetworkStorage], [StdObj], [StdObjParams], [SyncManager], [Synced] etc.