From 697d17b559ccaa02d67a286f762cc29c91d832e1 Mon Sep 17 00:00:00 2001 From: Kiril Tijsma Date: Thu, 19 Feb 2026 11:33:23 +0100 Subject: [PATCH 1/2] chore: extract serializer model to external pacakge --- lib/dart_frog_utils.dart | 1 + lib/src/serializers/base_serializer.dart | 99 ------------------------ pubspec.yaml | 2 +- 3 files changed, 2 insertions(+), 100 deletions(-) diff --git a/lib/dart_frog_utils.dart b/lib/dart_frog_utils.dart index 3a94f52..95b8963 100644 --- a/lib/dart_frog_utils.dart +++ b/lib/dart_frog_utils.dart @@ -7,6 +7,7 @@ export "package:dart_iconica_utilities/dart_iconica_utilities.dart" show CustomValidator, MapValidator, + Serializer, ValidationException, ValidatorJsonRepresentation, ValueValidator; diff --git a/lib/src/serializers/base_serializer.dart b/lib/src/serializers/base_serializer.dart index 68f6fca..3da5f7d 100644 --- a/lib/src/serializers/base_serializer.dart +++ b/lib/src/serializers/base_serializer.dart @@ -1,104 +1,5 @@ import "package:dart_frog/dart_frog.dart"; import "package:dart_frog_utils/dart_frog_utils.dart"; -import "package:dart_iconica_utilities/dart_iconica_utilities.dart"; - -/// -class Serializer { - /// - Serializer({ - required this.fromMap, - required this.toMap, - this.validators = const {}, - this.fieldPaths = const [], - this.data, - }); - - /// - factory Serializer.readOnly({ - required Map Function(T object) toMap, - required Map validators, - List fieldPaths = const [], - Map? data, - }) => - Serializer( - fromMap: (_) => throw SerializerReadOnlyException(), - toMap: toMap, - validators: validators, - fieldPaths: fieldPaths, - data: data, - ); - - /// - factory Serializer.writeOnly({ - required T Function(Map map) fromMap, - required Map validators, - List fieldPaths = const [], - Map? data, - }) => - Serializer( - fromMap: fromMap, - toMap: (_) => throw SerializerWriteOnlyException(), - validators: validators, - fieldPaths: fieldPaths, - data: data, - ); - - /// - final Map validators; - - /// - final T Function(Map map) fromMap; - - /// - final Map Function(T object) toMap; - - /// - final Map? data; - - /// - final List fieldPaths; - - /// - bool validate({ - bool raiseException = false, - }) { - try { - validators.validate(this.data ?? {}); - return true; - } on ValidationException { - if (raiseException) rethrow; - return false; - } - } - - /// - Serializer withData(Map data) => Serializer( - toMap: toMap, - fromMap: fromMap, - validators: validators, - data: data, - fieldPaths: fieldPaths, - ); - - /// - Serializer withObject(T object) => withData(toMap(object)); - - /// - Map serialize() { - final data = this.data ?? {}; - if (fieldPaths.isEmpty) { - return data; - } - - return data.select(fieldPaths); - } -} - -/// -class SerializerWriteOnlyException implements Exception {} - -/// -class SerializerReadOnlyException implements Exception {} /// extension ToResponse on Serializer { diff --git a/pubspec.yaml b/pubspec.yaml index 99cde4d..3c65090 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -13,7 +13,7 @@ dependencies: dart_frog: ^1.0.0 dart_iconica_utilities: hosted: https://forgejo.internal.iconica.nl/api/packages/internal/pub - version: ^0.0.2 + version: ^0.0.3 dev_dependencies: test: ^1.24.0 From fc4c4c319964dee6fb4d02d4911ceb6d6bdffb99 Mon Sep 17 00:00:00 2001 From: Kiril Tijsma Date: Thu, 19 Feb 2026 11:33:36 +0100 Subject: [PATCH 2/2] chore: increment version to 1.1.2 --- CHANGELOG.md | 5 +++++ pubspec.yaml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0b4804..81b3d14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.1.2 + +- Move Serializer to seperate dart_iconica_utilities package + + ## 1.1.1 - Move value validators to seperate dart_iconica_utilities package diff --git a/pubspec.yaml b/pubspec.yaml index 3c65090..9885b8c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: dart_frog_utils description: A starting point for Dart libraries or applications. -version: 1.1.1 +version: 1.1.2 repository: https://github.com/Iconica-Development/dart_frog_utils publish_to: https://forgejo.internal.iconica.nl/api/packages/internal/pub/