Skip to content

Commit

Permalink
chore: split schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
dtscalac committed Jan 16, 2025
1 parent 10a62cb commit 39c73a9
Show file tree
Hide file tree
Showing 26 changed files with 1,328 additions and 1,119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ export 'document/document.dart';
export 'document/document_builder.dart';
export 'document/document_change.dart';
export 'document/document_node_id.dart';
export 'document/document_schema.dart';
export 'document/document_validator.dart';
export 'document/enums/document_content_media_type.dart';
export 'document/enums/document_property_format.dart';
export 'document/enums/document_property_type.dart';
export 'document/schema/document_schema.dart';
export 'document/schema/property/document_property_schema.dart';
export 'errors/errors.dart';
export 'file/voices_file.dart';
export 'markdown_data.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import 'package:catalyst_voices_models/src/document/document_builder.dart';
import 'package:catalyst_voices_models/src/document/document_schema.dart';
import 'package:catalyst_voices_models/src/document/document_validator.dart';
import 'package:catalyst_voices_models/src/document/schema/document_schema.dart';
import 'package:catalyst_voices_models/src/document/schema/property/document_property_schema.dart';
import 'package:collection/collection.dart';
import 'package:equatable/equatable.dart';

// TODO(dtscalac): tests

/// A class that represents the content described by a [DocumentSchema].
///
/// The document is immutable, in order to edit it make use
Expand Down Expand Up @@ -36,13 +35,24 @@ final class Document extends Equatable {
List<Object?> get props => [schemaUrl, schema, properties];
}

/// A property of the [Document].
///
/// See:
/// - [DocumentListProperty]
/// - [DocumentObjectProperty]
/// - [DocumentValueProperty].
sealed class DocumentProperty extends Equatable {
/// The default constructor for the [DocumentProperty].
const DocumentProperty();

/// The schema of the property.
DocumentPropertySchema get schema;

/// Returns true if the property (including children properties) are valid,
/// false otherwise.
bool get isValid;

/// Returns a builder that can update the property state.
DocumentPropertyBuilder toBuilder();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:catalyst_voices_models/src/document/document.dart';
import 'package:catalyst_voices_models/src/document/document_change.dart';
import 'package:catalyst_voices_models/src/document/document_node_id.dart';
import 'package:catalyst_voices_models/src/document/document_schema.dart';
import 'package:catalyst_voices_models/src/document/schema/document_schema.dart';
import 'package:catalyst_voices_models/src/document/schema/property/document_property_schema.dart';
import 'package:catalyst_voices_shared/catalyst_voices_shared.dart';

/// A mutable document builder that understands the [DocumentSchema].
Expand Down Expand Up @@ -86,6 +87,7 @@ final class DocumentBuilder implements DocumentNode {
}
}

/// A builder for a single [DocumentProperty].
sealed class DocumentPropertyBuilder implements DocumentNode {
/// The default constructor for the [DocumentPropertyBuilder].
const DocumentPropertyBuilder();
Expand Down Expand Up @@ -123,11 +125,12 @@ sealed class DocumentPropertyBuilder implements DocumentNode {
DocumentProperty build();
}

/// A [DocumentProperty] builder suited to work with [DocumentListProperty].
final class DocumentListPropertyBuilder extends DocumentPropertyBuilder {
/// The schema of the document property.
DocumentListSchema _schema;

/// The list of children.
/// The list of children properties.
List<DocumentPropertyBuilder> _properties;

/// The default constructor for the [DocumentListPropertyBuilder].
Expand Down Expand Up @@ -234,11 +237,12 @@ final class DocumentListPropertyBuilder extends DocumentPropertyBuilder {
}
}

/// A [DocumentProperty] builder suited to work with [DocumentObjectProperty].
final class DocumentObjectPropertyBuilder extends DocumentPropertyBuilder {
/// The schema of the document property.
DocumentObjectSchema _schema;

/// The list of children.
/// The list of children properties.
List<DocumentPropertyBuilder> _properties;

/// The default constructor for the [DocumentObjectPropertyBuilder].
Expand Down Expand Up @@ -296,6 +300,7 @@ final class DocumentObjectPropertyBuilder extends DocumentPropertyBuilder {
}
}

/// A [DocumentProperty] builder suited to work with [DocumentValueProperty].
final class DocumentValuePropertyBuilder<T extends Object>
extends DocumentPropertyBuilder {
/// The schema of the document property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ sealed class DocumentChange extends Equatable {
}

/// Describes an intent to change a property value in the document.
final class DocumentValueChange extends DocumentChange {
final class DocumentValueChange<T extends Object> extends DocumentChange {
/// The id of the document node to be updated.
@override
final DocumentNodeId nodeId;

/// The new value to be assigned to the [nodeId] in the [Document].
final Object? value;
final T? value;

/// The default constructor for the [DocumentValueChange].
const DocumentValueChange({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ final class DocumentNodeId extends NodeId {
paths: paths,
);

/// The most nested path id.
///
/// Effectively the string after the last dot.
String get lastPath => paths.isNotEmpty ? paths.last : '';

/// Returns a parent node.
Expand Down
Loading

0 comments on commit 39c73a9

Please sign in to comment.