DatumManager<T extends DatumEntityInterface> class
- Mixed-in types
- Available extensions
Constructors
-
DatumManager({required LocalAdapter<
T> localAdapter, required RemoteAdapter<T> remoteAdapter, DatumConflictResolver<T> ? conflictResolver, required DatumConnectivityChecker connectivity, DatumConfig<T> ? datumConfig, DatumLogger? logger, List<DatumObserver< ? localObservers, List<T> >DatumMiddleware< ? middlewares, List<T> >GlobalDatumObserver> ? globalObservers, DatumSyncRequestStrategy? syncRequestStrategy, String? deviceId, DatumPersistence? persistence, Stream<String?> ? userChangeStream})
Properties
- coldStartManager → ColdStartManager
-
Exposes the cold start manager for testing purposes.
no setter
-
config
→ DatumConfig<
T> -
final
- currentStatus → DatumSyncStatusSnapshot
-
The most recent snapshot of the manager's sync status.
no setter
- deviceId → String?
-
final
-
eventStream
→ Stream<
DatumSyncEvent< T> > -
Public event streams
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
-
health
→ Stream<
DatumHealth> -
A stream of the manager's current health status.
no setter
- isDisposed → bool
-
Returns
trueif the object has been disposed.no setterinherited - isInitialized → bool
-
no setter
- isSubscribedToRemoteChanges → bool
-
Whether the manager is currently subscribed to remote change events.
no setter
-
localAdapter
→ LocalAdapter<
T> -
final
-
onConflict
→ Stream<
ConflictDetectedEvent< T> > -
no setter
-
onDataChange
→ Stream<
DataChangeEvent< T> > -
no setter
-
onNextSyncTimeChanged
→ Stream<
DateTime?> -
no setter
-
onSyncCompleted
→ Stream<
DatumSyncCompletedEvent< T> > -
no setter
-
onSyncError
→ Stream<
DatumSyncErrorEvent< T> > -
no setter
-
onSyncProgress
→ Stream<
DatumSyncProgressEvent< T> > -
no setter
-
onSyncStarted
→ Stream<
DatumSyncStartedEvent< T> > -
no setter
-
onUserChanged
→ Stream<
String?> -
A stream that emits when the active user changes for this manager.
Reactive queries can listen to this to refresh their data when users switch.
no setter
-
onUserSwitched
→ Stream<
UserSwitchedEvent< T> > -
no setter
- persistence → DatumPersistence?
-
final
-
queueManager
→ QueueManager<
T> -
Exposes the queue manager for central orchestration.
no setter
-
remoteAdapter
→ RemoteAdapter<
T> -
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
statusStream
→ Stream<
DatumSyncStatusSnapshot> -
A stream of the manager's sync status snapshots.
no setter
-
watchNextSyncDuration
→ Stream<
Duration?> -
A stream that emits the Duration until the next scheduled auto-sync.
no setter
-
watchNextSyncTime
→ Stream<
DateTime?> -
The most recent snapshot of the manager's sync status.
no setter
Methods
-
cascadeDelete(
{required String id, required String userId, DataSource source = DataSource.local, bool forceRemoteSync = false}) → Future< CascadeDeleteResult< T> > - Deletes an entity with cascading behavior based on relationship configurations.
-
checkHealth(
) → Future< DatumHealth> - Performs a health check on the local and remote adapters and updates the health stream with the result.
-
clearCaches(
) → void - Clears all caches. Useful for testing or when data consistency is critical.
-
clearRelationshipCacheForType(
Type entityType) → void - Clears relationship caches for a specific entity type.
-
delete(
{required String id, required String userId, DataSource source = DataSource.local, bool forceRemoteSync = false, DeleteBehavior? behavior}) → Future< bool> - Deletes an entity by its ID from all local and remote adapters.
-
deleteAndSync(
{required String id, required String userId, DatumSyncOptions< T> ? syncOptions, DeleteBehavior? behavior}) → Future<(bool, DatumSyncResult< T> )> - Deletes an entity locally and immediately triggers a synchronization.
-
deleteCascade(
String entityId) → CascadeDeleteBuilder< T> - Creates a fluent API builder for cascade delete operations.
-
dispose(
) → Future< void> -
Releases all resources held by the manager and its adapters.
override
-
ensureNotDisposed(
) → void -
Throws a StateError if the object has been disposed.
inherited
-
executeCascadeDeleteWithOptions(
String entityId, String userId, CascadeOptions options) → Future< CascadeResult< T> > - Executes cascade delete with enhanced options (dry-run, progress, etc.).
-
fetchRelated<
R extends DatumEntityInterface> (T parent, String relationName, {DataSource source = DataSource.local}) → Future< List< R> > -
DEPRECATED: This method will be removed in a future version. Use the
withRelatedparameter in thequerymethod for eager loading, or thefetch()method on the relation object for lazy loading. Fetches related entities for a given parent entity. -
getCacheStats(
) → Map< String, int> - Gets cache statistics for monitoring and debugging.
-
getLastSyncResult(
String userId) → Future< DatumSyncResult< T> ?> - Retrieves the result of the last synchronization for a user from local storage.
-
getNextSyncDuration(
) → Future< Duration?> -
Available on DatumManager<
Gets the Duration until the next scheduled auto-sync as aT> , provided by the DatumManagerAutoSyncInfo extensionFuture. -
getNextSyncTime(
) → Future< DateTime?> -
Available on DatumManager<
Gets the DateTime of the next scheduled auto-sync as aT> , provided by the DatumManagerAutoSyncInfo extensionFuture. -
getPendingCount(
String userId) → Future< int> - Returns the number of pending synchronization operations for the user.
-
getPendingOperations(
String userId) → Future< List< DatumSyncOperation< >T> > - Returns a list of pending synchronization operations for the user.
-
getRemoteSyncMetadata(
String userId) → Future< DatumSyncMetadata?> - Fetches sync metadata from the remote server for this entity type.
-
getStorageSize(
{String? userId}) → Future< int> - Gets the current storage size in bytes from the local adapter.
-
initialize(
) → Future< void> - Initializes the manager and its adapters. Must be called before any other methods.
-
manageController(
StreamController controller) → void -
Registers a StreamController to be automatically closed on dispose.
inherited
-
manageSubscription(
StreamSubscription subscription) → void -
Registers a StreamSubscription to be automatically cancelled on dispose.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pauseSync(
) → void - Pauses all synchronization activity for this manager.
-
performDeleteWithoutEvents(
{required String id, required String userId, DataSource source = DataSource.local, bool forceRemoteSync = false}) → Future< bool> - Performs a delete without firing events (used internally for cascading).
-
push(
{required T item, required String userId, DataSource source = DataSource.local, bool forceRemoteSync = false}) → Future< T> -
pushAndSync(
{required T item, required String userId, DataSource source = DataSource.local, bool forceRemoteSync = false, DatumSyncOptions< T> ? syncOptions, DatumSyncScope? scope}) → Future<(T, DatumSyncResult< T> )> - Saves an entity locally and immediately triggers a synchronization.
-
query(
DatumQuery query, {required DataSource source, String? userId}) → Future< List< T> > - Executes a one-time query against the specified data source.
-
read(
String id, {String? userId}) → Future< T?> - Reads a single entity by its ID from the primary local adapter.
-
readAll(
{String? userId}) → Future< List< T> > - Reads all entities from the primary local adapter.
-
refreshStreams(
) → Future< void> - Refreshes all reactive streams by clearing caches and forcing streams to re-evaluate their data. This is useful when external state changes (like user switches) require all streams to refresh their data.
-
resubscribeToRemoteChanges(
) → Future< void> - Re-subscribes to remote change events.
-
resumeSync(
) → void - Resumes synchronization activity for this manager.
-
saveMany(
{required List< T> items, required String userId, bool andSync = false, DataSource source = DataSource.local, bool forceRemoteSync = false, DatumSyncOptions<T> ? syncOptions, DatumSyncScope? scope}) → Future<List< T> > -
startAutoSync(
String userId, {Duration? interval}) → void - Starts automatic periodic synchronization for the specified user.
-
stopAutoSync(
{String? userId}) → void - Stops automatic synchronization for one or all users.
-
switchUser(
{required String? oldUserId, required String newUserId, UserSwitchStrategy? strategy}) → Future< DatumUserSwitchResult> - Switches the active user with configurable handling of unsynced data.
-
synchronize(
String userId, {DatumSyncOptions< DatumEntityInterface> ? options, DatumSyncScope? scope}) → Future<DatumSyncResult< T> > -
toString(
) → String -
A string representation of this object.
inherited
-
unsubscribeFromRemoteChanges(
) → Future< void> - Unsubscribes from remote change events.
-
updateAndSync(
{required T item, required String userId, DataSource source = DataSource.local, bool forceRemoteSync = false, DatumSyncOptions< T> ? syncOptions, DatumSyncScope? scope}) → Future<(T, DatumSyncResult< T> )> - Updates an entity locally and immediately triggers a synchronization.
-
watchAll(
{String? userId, bool includeInitialData = true}) → Stream< List< ?T> > - Watches all entities from the local adapter, emitting a new list on any change.
-
watchAllPaginated(
PaginationConfig config, {String? userId}) → Stream< PaginatedResult< ?T> > - Watches a paginated list of items. Returns null if the adapter does not support reactive queries.
-
watchById(
String id, String? userId) → Stream< T?> ? - Watches a single entity by its ID, emitting the item on change or null if deleted. Returns null if the adapter does not support reactive queries.
-
watchQuery(
DatumQuery query, {String? userId}) → Stream< List< ?T> > - Watches a subset of items matching a query. Returns null if the adapter does not support reactive queries.
-
watchRelated<
R extends DatumEntityInterface> (T parent, String relationName) → Stream< List< ?R> > -
DEPRECATED: This method will be removed in a future version. Use the
withRelatedparameter in thequerymethod for eager loading, or thefetch()method on the relation object for lazy loading. Reactively watches related entities for a given parent entity. -
watchStorageSize(
{String? userId}) → Stream< int> - Reactively watches the storage size in bytes from the local adapter.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited