Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new class for getting info about sync #3

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [1.3.0] - 2023-12-12

* Added class `SyncStateInfo` describing the current synchronization state and errors.
* Add `state` getter.

## [1.2.1] - 2023-03-01

* Add `debugDoNotSendChanges()` method.
Expand Down
1 change: 1 addition & 0 deletions lib/in_sync_interface.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
library in_sync_interface;

export 'src/sync_repository.dart';
export 'src/sync_state_info.dart';
5 changes: 5 additions & 0 deletions lib/src/sync_repository.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:in_sync_interface/src/sync_state_info.dart';

/// The reposotory for work with synchronization.
///
/// By default the synchronization is off (see. [isEnabled]),
Expand Down Expand Up @@ -56,4 +58,7 @@ abstract class SyncRepository {

/// Used to release the memory allocated to variables when the repository is no longer in use.
Future<void> dispose();

/// Returns the synchronization job status stream.
Stream<SyncStateInfo> get state;
}
111 changes: 111 additions & 0 deletions lib/src/sync_state_info.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/// Synchronization status information, including errors.
class SyncStateInfo {
final SyncState state;
final SyncError? syncError;

const SyncStateInfo(
this.state, {
this.syncError,
});

/// Fatal error.
bool get isFatalError =>
syncError == SyncError.authIncorrectCriticalVersion ||
syncError == SyncError.syncIncorrectData ||
syncError == SyncError.syncFieldNotFound ||
syncError == SyncError.syncEmptyFile;

/// Temporary error.
bool get isTemporaryError =>
syncError == SyncError.syncBlocked ||
syncError == SyncError.syncTemporarilyImpossible ||
syncError == SyncError.networkError ||
syncError == SyncError.syncInternalSyncError ||
syncError == SyncError.temporaryServerError;
}

/// Synchronization error name.
enum SyncError {
/// Unsupported client version.
authIncorrectCriticalVersion,

/// The transmitted data is incorrect.
syncIncorrectData,

/// Synchronization is blocked.
///
/// Another client is synchronizing.
syncBlocked,

/// Error while saving data.
///
/// Internal error when saving on the server.
syncNotSaved,

/// The entity could not be found.
///
/// The creation event was not processed on the server
/// this entity, so it can't update.
syncEntityNotFound,

/// Could not find the field.
///
/// An entity field update was sent that the server does not know about.
syncFieldNotFound,

/// An empty file was transferred.
///
/// An attempt was made to load a file of zero size.
syncEmptyFile,

/// Internal synchronization error on the server.
syncInternalSyncError,

/// Synchronization is temporarily unavailable.
syncTemporarilyImpossible,

/// Error updating entities.
updateEntityError,

/// Error downloading files.
downloadFilesError,

/// Network error.
networkError,

/// Authorisation error.
authError,

/// Temporary server error.
temporaryServerError,

/// Internal error.
internalError,

/// Error updating links.
updateLinksExeption,

/// Unknown error.
unknown,
}

/// Sync status.
enum SyncState {
/// Initialization.
initializing,

/// Synchronization was completed successfully.
ok,

/// The last synchronization attempt failed with an error.
failed,

/// Synchronization is disabled.
disabled,

/// Synchronization in progress.
pending,

/// Waiting for first synchronization.
waiting,
}
Loading