Skip to content

Commit f5e0a59

Browse files
docs: documents sources interfaces documentation
1 parent a5e8acf commit f5e0a59

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/document/source/document_data_local_source.dart

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,45 @@
11
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
22
import '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].
58
abstract 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,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
22

3+
/// A base interface for retrieving document data from any source (Local, Remote, Memory).
34
abstract interface class DocumentDataSource {
5+
/// Retrieves a specific document by its unique reference.
6+
///
7+
/// Returns `null` if the document with the specific [DocumentRef.id] and
8+
/// [DocumentRef.version] is not found.
49
Future<DocumentData?> get(DocumentRef ref);
510

11+
/// Resolves the reference to the latest available version of a document chain.
12+
///
13+
/// If [ref] points to an older version, this returns the [DocumentRef]
14+
/// for the most recent version of that document ID.
15+
/// Returns `null` if the document ID does not exist in the source.
616
Future<DocumentRef?> getLatestRefOf(DocumentRef ref);
717
}

catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/document/source/local_document_data_local_source.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
22
import 'package:catalyst_voices_repositories/catalyst_voices_repositories.dart';
33

4+
/// Interface for accessing mutable draft documents.
5+
///
6+
/// Drafts are local-only, unsigned work-in-progress documents.
47
/// See [DatabaseDraftsDataSource].
58
abstract interface class DraftDataSource implements DocumentDataLocalSource {
9+
/// Deletes drafts matching the criteria.
10+
///
11+
/// * [ref]: If provided, deletes the specific draft.
12+
/// * [typeNotIn]: Deletes all drafts NOT matching these types (often used for cleanup).
613
@override
714
Future<int> delete({
815
DocumentRef? ref,
916
List<DocumentType>? typeNotIn,
1017
});
1118

19+
/// Updates the content of an existing draft identified by [ref].
20+
///
21+
/// This is distinct from [save] as it implies modifying the payload
22+
/// of an existing entity without necessarily creating a new version/ID.
1223
Future<void> update({
1324
required DraftRef ref,
1425
required DocumentDataContent content,

catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/document/source/signed_document_data_local_source.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
22
import 'package:catalyst_voices_repositories/catalyst_voices_repositories.dart';
33

4+
/// Interface for accessing immutable, cryptographically signed documents.
5+
///
6+
/// Signed documents are final and cannot be modified, only superseded by
7+
/// newer versions.
48
/// See [DatabaseDocumentsDataSource].
59
abstract interface class SignedDocumentDataSource implements DocumentDataLocalSource {
10+
/// Retrieves a single signed document matching the filters.
11+
///
12+
/// * [authorId]: Filters documents authored by a specific [CatalystId].
613
@override
714
Future<DocumentData?> getWhere({
815
DocumentType? type,
@@ -11,6 +18,9 @@ abstract interface class SignedDocumentDataSource implements DocumentDataLocalSo
1118
CatalystId? authorId,
1219
});
1320

21+
/// Watches for changes to a list of signed documents.
22+
///
23+
/// * [authorId]: Filters documents authored by a specific [CatalystId].
1424
@override
1525
Stream<List<DocumentData>> watchAll({
1626
DocumentType? type,

0 commit comments

Comments
 (0)