@@ -3,30 +3,47 @@ import 'sync_entry.dart';
33
44/// Base class for all sync lifecycle events.
55sealed class SyncEvent {
6+ /// Creates a [SyncEvent] with the given [timestamp] .
67 const SyncEvent ({required this .timestamp});
8+
9+ /// The time at which this event occurred.
710 final DateTime timestamp;
811}
912
13+ /// Emitted when the local outbound queue has been fully drained.
1014class SyncDrainComplete extends SyncEvent {
15+ /// Creates a [SyncDrainComplete] event.
1116 const SyncDrainComplete ({required super .timestamp});
1217}
1318
19+ /// Emitted when a pull operation for a table completes successfully.
1420class SyncPullComplete extends SyncEvent {
21+ /// Creates a [SyncPullComplete] event.
1522 const SyncPullComplete ({
1623 required super .timestamp,
1724 required this .table,
1825 required this .rowCount,
1926 });
27+
28+ /// The name of the table that was pulled.
2029 final String table;
30+
31+ /// The number of rows received during the pull.
2132 final int rowCount;
2233}
2334
35+ /// Emitted when the remote server rejects the request due to authentication.
2436class SyncAuthRequired extends SyncEvent {
37+ /// Creates a [SyncAuthRequired] event.
2538 const SyncAuthRequired ({required super .timestamp, required this .error});
39+
40+ /// The underlying authentication error.
2641 final Object error;
2742}
2843
44+ /// Emitted when a conflict between local and remote data is detected and resolved.
2945class SyncConflict extends SyncEvent {
46+ /// Creates a [SyncConflict] event.
3047 const SyncConflict ({
3148 required super .timestamp,
3249 required this .table,
@@ -36,35 +53,63 @@ class SyncConflict extends SyncEvent {
3653 required this .resolvedVersion,
3754 required this .strategyUsed,
3855 });
56+
57+ /// The table in which the conflict occurred.
3958 final String table;
59+
60+ /// The identifier of the conflicting record.
4061 final String recordId;
62+
63+ /// The local version of the record before resolution.
4164 final Map <String , dynamic > localVersion;
65+
66+ /// The remote version of the record before resolution.
4267 final Map <String , dynamic > remoteVersion;
68+
69+ /// The final merged version of the record after resolution.
4370 final Map <String , dynamic > resolvedVersion;
71+
72+ /// The conflict resolution strategy that was applied.
4473 final ConflictStrategy strategyUsed;
4574}
4675
76+ /// Emitted when a sync entry exceeds its maximum retry count and is discarded.
4777class SyncPoisonPill extends SyncEvent {
78+ /// Creates a [SyncPoisonPill] event.
4879 const SyncPoisonPill ({required super .timestamp, required this .entry});
80+
81+ /// The sync entry that was permanently discarded.
4982 final SyncEntry entry;
5083}
5184
85+ /// Emitted when a failed sync entry is scheduled for a later retry.
5286class SyncRetryScheduled extends SyncEvent {
87+ /// Creates a [SyncRetryScheduled] event.
5388 const SyncRetryScheduled ({
5489 required super .timestamp,
5590 required this .entry,
5691 required this .nextRetryAt,
5792 });
93+
94+ /// The sync entry that will be retried.
5895 final SyncEntry entry;
96+
97+ /// The scheduled time for the next retry attempt.
5998 final DateTime nextRetryAt;
6099}
61100
101+ /// Emitted when an unexpected error occurs during a sync operation.
62102class SyncError extends SyncEvent {
103+ /// Creates a [SyncError] event.
63104 const SyncError ({
64105 required super .timestamp,
65106 required this .error,
66107 required this .context,
67108 });
109+
110+ /// The underlying error object.
68111 final Object error;
112+
113+ /// A human-readable description of where the error occurred.
69114 final String context;
70115}
0 commit comments