Skip to content

Commit

Permalink
Merge pull request #3 from ShishkinDaniil/feature/add-stream-sync-sta…
Browse files Browse the repository at this point in the history
…te-info

Add new class for getting info about sync
  • Loading branch information
greymag committed Dec 12, 2023
2 parents 31d4b56 + 54cf05e commit 6f48655
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 50 deletions.
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

0 comments on commit 6f48655

Please sign in to comment.