diff --git a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/dio_cat_gateway_service.dart b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/dio_cat_gateway_service.dart index e05832b5173..ec44d5db3c2 100644 --- a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/dio_cat_gateway_service.dart +++ b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/dio_cat_gateway_service.dart @@ -17,8 +17,8 @@ import 'package:dio/dio.dart'; /// # Catalyst Gateway API. /// The Catalyst Gateway API provides realtime data for all prior, current and future Catalyst Voices voting events. /// -/// Based on OpenAPI Catalyst Gateway API version 0.7.0 -/// catalyst-openapi/v0.7.0 - https://github.com/input-output-hk/catalyst-voices/releases/tag/catalyst-openapi%2Fv0.7.0 +/// Based on OpenAPI Catalyst Gateway API version 0.8.0 +/// catalyst-openapi/v0.8.0 - https://github.com/input-output-hk/catalyst-voices/releases/tag/catalyst-openapi%2Fv0.8.0 abstract interface class CatGatewayService { factory CatGatewayService.dio({ required String baseUrl, @@ -36,7 +36,7 @@ abstract interface class CatGatewayService { void close(); - /// Post A Signed Document Index Query for Newer Versions of v0.0.4. + /// Post A Signed Document Index Query (v2). /// Produces a summary of signed documents that meet the criteria /// defined in the request body for new signed document versions of v0.0.4. /// diff --git a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/document_chain.dart b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/document_chain.dart new file mode 100644 index 00000000000..f9d22157460 --- /dev/null +++ b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/document_chain.dart @@ -0,0 +1,23 @@ +import 'package:catalyst_voices_repositories/src/api/models/document_reference.dart'; +import 'package:json_annotation/json_annotation.dart'; + +part 'document_chain.g.dart'; + +/// A reference to the previous signed document in a sequence. +@JsonSerializable() +final class DocumentChain { + /// A document height + /// A consecutive sequence number of the current document in the chain. + final int height; + + /// Document Reference for filtered Documents. + /// A reference to a single signed document. + @JsonKey(name: 'document_ref') + final DocumentReference? documentRef; + + const DocumentChain({required this.height, this.documentRef}); + + factory DocumentChain.fromJson(Map json) => _$DocumentChainFromJson(json); + + Map toJson() => _$DocumentChainToJson(this); +} diff --git a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/document_index_query_filter.dart b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/document_index_query_filter.dart index c90f257c305..7dfade2208e 100644 --- a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/document_index_query_filter.dart +++ b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/document_index_query_filter.dart @@ -1,6 +1,6 @@ -import 'package:catalyst_voices_repositories/src/api/models/eq_or_ranged_id.dart'; -import 'package:catalyst_voices_repositories/src/api/models/eq_or_ranged_ver.dart'; import 'package:catalyst_voices_repositories/src/api/models/id_and_ver_ref.dart'; +import 'package:catalyst_voices_repositories/src/api/models/id_selector.dart'; +import 'package:catalyst_voices_repositories/src/api/models/ver_selector.dart'; import 'package:json_annotation/json_annotation.dart'; part 'document_index_query_filter.g.dart'; @@ -24,21 +24,15 @@ final class DocumentIndexQueryFilter { /// Max items 10 final List? type; - /// ## Document ID + /// Document ID Selector /// - /// Either an absolute single Document ID or a range of - /// [Document IDs](https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/spec/#id) - /// - /// Max items 10 - final List? id; + /// Either a absolute single Document ID or a range of Document IDs + final IdSelector? id; - /// ## Document Version + /// Document Version Selector /// - /// Either an absolute single Document Version or a range of - /// [Document Versions](https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/spec/#ver) - /// - /// Max items 10 - final List? ver; + /// Either a absolute single Document Version or a range of Document Versions + final VerSelector? ver; /// ## Document Reference /// diff --git a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/eq_or_ranged_id.dart b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/eq_or_ranged_id.dart deleted file mode 100644 index e5d4cb38492..00000000000 --- a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/eq_or_ranged_id.dart +++ /dev/null @@ -1,30 +0,0 @@ -import 'package:json_annotation/json_annotation.dart'; - -part 'eq_or_ranged_id.g.dart'; - -/// Either a Single Document ID, or a Range of Document IDs -@JsonSerializable(createFactory: false, includeIfNull: false) -final class EqOrRangedId { - /// Signed Document ID - /// The exact Document ID to match against. - final String? eq; - - /// Signed Document ID - /// Minimum Document ID to find (inclusive) - final String? min; - - /// Signed Document ID - /// Maximum Document ID to find (inclusive) - final String? max; - - /// A single Document IDs. - const EqOrRangedId.eq(String this.eq) : min = null, max = null; - - /// A range of Document IDs. - const EqOrRangedId.range({ - required String this.min, - required String this.max, - }) : eq = null; - - Map toJson() => _$EqOrRangedIdToJson(this); -} diff --git a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/eq_or_ranged_ver.dart b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/eq_or_ranged_ver.dart deleted file mode 100644 index 763c6f2d19e..00000000000 --- a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/eq_or_ranged_ver.dart +++ /dev/null @@ -1,35 +0,0 @@ -import 'package:json_annotation/json_annotation.dart'; - -part 'eq_or_ranged_ver.g.dart'; - -/// Document or Range of Documents -/// -/// Either a Single Document Version, or a Range of Document Versions -@JsonSerializable(createFactory: false, includeIfNull: false) -final class EqOrRangedVer { - /// Signed Document Version - /// The exact Document ID to match against. - final String? eq; - - /// Signed Document Version - /// Minimum Document Version to find (inclusive) - final String? min; - - /// Signed Document Version - /// Maximum Document Version to find (inclusive) - final String? max; - - /// A single Document IDs. - /// The exact Document ID to match against. - const EqOrRangedVer.eq(String this.eq) : min = null, max = null; - - /// Version Range - /// - /// A Range of document versions from minimum to maximum inclusive. - const EqOrRangedVer.range({ - required String this.min, - required String this.max, - }) : eq = null; - - Map toJson() => _$EqOrRangedVerToJson(this); -} diff --git a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/id_and_ver_ref.dart b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/id_and_ver_ref.dart index a9a44f23e9d..83488546fde 100644 --- a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/id_and_ver_ref.dart +++ b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/id_and_ver_ref.dart @@ -1,5 +1,5 @@ -import 'package:catalyst_voices_repositories/src/api/models/eq_or_ranged_id.dart'; -import 'package:catalyst_voices_repositories/src/api/models/eq_or_ranged_ver.dart'; +import 'package:catalyst_voices_repositories/src/api/models/id_selector.dart'; +import 'package:catalyst_voices_repositories/src/api/models/ver_selector.dart'; import 'package:json_annotation/json_annotation.dart'; part 'id_and_ver_ref.g.dart'; @@ -12,18 +12,18 @@ final class IdAndVerRef { /// /// This will match any document that matches the defined Document ID only. /// The Document Version is not considered, and will match any version. - final EqOrRangedId? id; + final IdSelector? id; /// Document Version Selector /// Document Version, or Range of Document Versions - final EqOrRangedVer? ver; + final VerSelector? ver; /// Document ID Reference /// A Reference to the Document ID Only. /// /// This will match any document that matches the defined Document ID only. /// The Document Version is not considered, and will match any version. - const IdAndVerRef.idOnly(EqOrRangedId this.id) : ver = null; + const IdAndVerRef.idOnly(IdSelector this.id) : ver = null; /// A Reference to the Document Version, and optionally also the Document ID. /// @@ -32,7 +32,7 @@ final class IdAndVerRef { /// If the Document ID is not specified, then all documents that match the version will be /// returned in the index. const IdAndVerRef.verWithOptionalId({ - required EqOrRangedVer this.ver, + required VerSelector this.ver, this.id, }); diff --git a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/id_selector.dart b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/id_selector.dart new file mode 100644 index 00000000000..fbe598965b6 --- /dev/null +++ b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/id_selector.dart @@ -0,0 +1,43 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'id_selector.g.dart'; + +/// Either a Single Document ID, or a Range of Document IDs +@JsonSerializable(createFactory: false, includeIfNull: false) +final class IdSelector { + /// Signed Document ID + /// The exact Document ID to match against. + final String? eq; + + /// Signed Document ID + /// Minimum Document ID to find (inclusive) + final String? min; + + /// Signed Document ID + /// Maximum Document ID to find (inclusive) + final String? max; + + /// Signed Document ID + /// Document IDs from the list. + @JsonKey(name: 'in') + final List? inside; + + /// A specific single + /// [Document ID](https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/spec/#id). + const IdSelector.eq(String this.eq) : min = null, max = null, inside = null; + + /// Document IDs from the list. + /// A list of + /// [Document IDs](https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/spec/#id). + const IdSelector.inside(List this.inside) : eq = null, min = null, max = null; + + /// A range of + /// [Document IDs](https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/spec/#id). + const IdSelector.range({ + required String this.min, + required String this.max, + }) : eq = null, + inside = null; + + Map toJson() => _$IdSelectorToJson(this); +} diff --git a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/indexed_document_version.dart b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/indexed_document_version.dart index 674e3940e4d..e1f4c4d1128 100644 --- a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/indexed_document_version.dart +++ b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/indexed_document_version.dart @@ -1,3 +1,4 @@ +import 'package:catalyst_voices_repositories/src/api/models/document_chain.dart'; import 'package:catalyst_voices_repositories/src/api/models/document_reference.dart'; import 'package:json_annotation/json_annotation.dart'; @@ -14,6 +15,10 @@ final class IndexedDocumentVersion { /// Document Type that matches the filter final String type; + /// Signed Document ID + /// A unique document identifier that matches the filter. + final String id; + /// Document Reference that matches the filter /// Max items 10 final List? ref; @@ -31,13 +36,25 @@ final class IndexedDocumentVersion { @JsonKey(name: 'doc_parameters') final List? parameters; + /// A list of collaborators who can participate in drafting and submitting a document + /// that matches the filter. + /// Catalyst identifier in string format + final List? collaborators; + + /// A reference to the previous signed document in a sequence. + /// A link to a previous document in a chained sequence that matches the filter. + final DocumentChain? chain; + IndexedDocumentVersion({ required this.ver, required this.type, + required this.id, this.ref, this.reply, this.template, this.parameters, + this.collaborators, + this.chain, }); factory IndexedDocumentVersion.fromJson(Map json) => diff --git a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/ver_selector.dart b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/ver_selector.dart new file mode 100644 index 00000000000..2a3de2765a5 --- /dev/null +++ b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/ver_selector.dart @@ -0,0 +1,48 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'ver_selector.g.dart'; + +/// Document or Range of Documents +/// +/// Either a Single Document Version, or a Range of Document Versions +@JsonSerializable(createFactory: false, includeIfNull: false) +final class VerSelector { + /// Signed Document Version + /// The exact Document ID to match against. + final String? eq; + + /// Signed Document Version + /// Minimum Document Version to find (inclusive) + final String? min; + + /// Signed Document Version + /// Maximum Document Version to find (inclusive) + final String? max; + + /// Signed Document Version + /// Document versions from the list. + @JsonKey(name: 'in') + final List? inside; + + /// Version Equals + /// A specific single + /// [Document Version](https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/spec/#ver). + const VerSelector.eq(String this.eq) : min = null, max = null, inside = null; + + /// Document versions from the list. + /// A list of + /// [Document IDs](https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/spec/#id). + const VerSelector.inside(List this.inside) : eq = null, min = null, max = null; + + /// Version Range + /// + /// A range of + /// [Document Version](https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/spec/#ver). + const VerSelector.range({ + required String this.min, + required String this.max, + }) : eq = null, + inside = null; + + Map toJson() => _$VerSelectorToJson(this); +} diff --git a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/document/source/document_data_remote_source.dart b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/document/source/document_data_remote_source.dart index e5ca7a6d263..f4e3a6a345b 100644 --- a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/document/source/document_data_remote_source.dart +++ b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/document/source/document_data_remote_source.dart @@ -3,8 +3,8 @@ import 'package:catalyst_voices_repositories/catalyst_voices_repositories.dart'; import 'package:catalyst_voices_repositories/src/api/models/document_index_list.dart'; import 'package:catalyst_voices_repositories/src/api/models/document_index_query_filter.dart'; import 'package:catalyst_voices_repositories/src/api/models/document_reference.dart'; -import 'package:catalyst_voices_repositories/src/api/models/eq_or_ranged_id.dart'; import 'package:catalyst_voices_repositories/src/api/models/id_and_ver_ref.dart'; +import 'package:catalyst_voices_repositories/src/api/models/id_selector.dart'; import 'package:catalyst_voices_repositories/src/common/future_response_mapper.dart'; import 'package:catalyst_voices_repositories/src/document/document_data_factory.dart'; import 'package:collection/collection.dart'; @@ -49,7 +49,7 @@ final class CatGatewayDocumentDataSource implements DocumentDataRemoteSource { try { final index = await _api.gateway .documentIndex( - filter: DocumentIndexQueryFilter(id: [EqOrRangedId.eq(id)]), + filter: DocumentIndexQueryFilter(id: IdSelector.eq(id)), limit: 1, ) .successBodyOrThrow(); @@ -102,13 +102,9 @@ final class CatGatewayDocumentDataSource implements DocumentDataRemoteSource { required int limit, required Campaign campaign, }) async { - assert(campaign.categories.length <= 10, 'Max 10 categories are allowed in the filter.'); - - final categoryFilter = campaign.categories - .take(10) - .map((e) => IdAndVerRef.idOnly(EqOrRangedId.eq(e.selfRef.id))) - .toList(); - final documentFilter = DocumentIndexQueryFilter(category: categoryFilter); + final categoryIds = campaign.categories.map((e) => e.selfRef.id).toList(); + final categoryFilter = IdAndVerRef.idOnly(IdSelector.inside(categoryIds)); + final documentFilter = DocumentIndexQueryFilter(category: [categoryFilter]); return _api.gateway .documentIndex( diff --git a/catalyst_voices/packages/internal/catalyst_voices_repositories/test/src/document/source/document_data_remote_source_test.dart b/catalyst_voices/packages/internal/catalyst_voices_repositories/test/src/document/source/document_data_remote_source_test.dart index c68abc2c56f..9dbf219fb32 100644 --- a/catalyst_voices/packages/internal/catalyst_voices_repositories/test/src/document/source/document_data_remote_source_test.dart +++ b/catalyst_voices/packages/internal/catalyst_voices_repositories/test/src/document/source/document_data_remote_source_test.dart @@ -105,6 +105,7 @@ void main() { return IndexedDocumentVersion( ver: e.version!, type: DocumentType.proposalDocument.uuid, + id: '01944e87-e68c-7f22-9df1-816863cfa5ff', template: [ DocumentReference( id: templateRef.id, @@ -155,6 +156,7 @@ IndexedDocument _buildDocumentIndexList({ return IndexedDocumentVersion( ver: DocumentRefFactory.randomUuidV7(), type: DocumentRefFactory.randomUuidV7(), + id: DocumentRefFactory.randomUuidV7(), template: template, ref: ref, );