11import 'package:catalyst_voices_models/catalyst_voices_models.dart' ;
22import 'package:catalyst_voices_repositories/catalyst_voices_repositories.dart' ;
33
4- /// Base interface to interact with locally document data.
4+ /// Base interface to interact with locally stored document data (Database/Storage).
5+ ///
6+ /// This interface handles common CRUD operations and reactive streams for
7+ /// both [SignedDocumentDataSource] and [DraftDataSource] .
58abstract interface class DocumentDataLocalSource implements DocumentDataSource {
9+ /// Counts the number of documents matching the provided filters.
10+ ///
11+ /// * [type] : Filter by the [DocumentType] (e.g., Proposal, Comment).
12+ /// * [ref] : Filter by the specific identity of the document (ID/Version).
13+ /// * [refTo] : Filter for documents that reference *this* target [refTo] .
14+ /// (e.g., Find all comments pointing to Proposal X).
615 Future <int > count ({
716 DocumentType ? type,
817 DocumentRef ? ref,
918 DocumentRef ? refTo,
1019 });
1120
21+ /// Deletes documents matching the provided filters.
22+ ///
23+ /// * [typeNotIn] : If provided, deletes all documents *except* those
24+ /// matching the types in this list.
25+ ///
26+ /// Returns the number of records deleted.
1227 Future <int > delete ({
1328 List <DocumentType >? typeNotIn,
1429 });
1530
31+ /// Checks if a specific document exists in local storage.
1632 Future <bool > exists ({required DocumentRef ref});
1733
34+ /// Checks a list of [refs] and returns a subset list containing only
35+ /// the references that actually exist in the local storage.
1836 Future <List <DocumentRef >> filterExisting (List <DocumentRef > refs);
1937
38+ /// Retrieves a list of documents matching the provided filters.
39+ ///
40+ /// * [latestOnly] : If `true` , only the most recent version of each
41+ /// document ID is returned.
42+ /// * [limit] and [offset] : Used for pagination.
2043 Future <List <DocumentData >> getAll ({
2144 DocumentType ? type,
2245 DocumentRef ? ref,
@@ -26,22 +49,36 @@ abstract interface class DocumentDataLocalSource implements DocumentDataSource {
2649 int offset,
2750 });
2851
52+ /// Retrieves a single document matching the provided filters.
53+ ///
54+ /// Returns `null` if no document matches or if multiple match (depending on impl).
55+ /// Generally used when the filter is expected to yield a unique result.
2956 Future <DocumentData ?> getWhere ({
3057 DocumentType ? type,
3158 DocumentRef ? ref,
3259 DocumentRef ? refTo,
3360 });
3461
62+ /// Persists a single [DocumentData] object to local storage.
63+ ///
64+ /// If the document already exists, it should be updated (upsert).
3565 Future <void > save ({required DocumentData data});
3666
67+ /// Persists multiple [DocumentData] objects to local storage in a batch.
3768 Future <void > saveAll (Iterable <DocumentData > data);
3869
70+ /// Watches for changes to a single document matching the filters.
71+ ///
72+ /// Emits a new value whenever the matching document is updated or inserted.
3973 Stream <DocumentData ?> watch ({
4074 DocumentType ? type,
4175 DocumentRef ? ref,
4276 DocumentRef ? refTo,
4377 });
4478
79+ /// Watches for changes to a list of documents matching the filters.
80+ ///
81+ /// Emits a new list whenever any document matching the criteria changes.
4582 Stream <List <DocumentData >> watchAll ({
4683 DocumentType ? type,
4784 DocumentRef ? ref,
@@ -51,6 +88,7 @@ abstract interface class DocumentDataLocalSource implements DocumentDataSource {
5188 int offset,
5289 });
5390
91+ /// Watches the count of documents matching the filters.
5492 Stream <int > watchCount ({
5593 DocumentType ? type,
5694 DocumentRef ? ref,
0 commit comments