From 190fe10b3bbddaf7159b89c8a8b96159186c964d Mon Sep 17 00:00:00 2001 From: Kilian Schulte Date: Mon, 8 May 2023 15:40:35 +0200 Subject: [PATCH] [bump] version 3.0.0 --- packages/dart_mappable/CHANGELOG.md | 124 ++++++++++++++---- packages/dart_mappable/analysis_options.yaml | 5 +- packages/dart_mappable/doc/polymorphism.md | 4 +- packages/dart_mappable/pubspec.yaml | 6 +- packages/dart_mappable_builder/CHANGELOG.md | 124 +++++++++++++++--- .../analysis_options.yaml | 5 +- packages/dart_mappable_builder/pubspec.yaml | 6 +- 7 files changed, 216 insertions(+), 58 deletions(-) diff --git a/packages/dart_mappable/CHANGELOG.md b/packages/dart_mappable/CHANGELOG.md index cf63009c..8a96870c 100644 --- a/packages/dart_mappable/CHANGELOG.md +++ b/packages/dart_mappable/CHANGELOG.md @@ -1,40 +1,118 @@ -# 3.0.0-dev.5 +# 3.0.0 -- Make delta copy-with null aware. -- Add `renameMethods` to build options. +- **Breaking**: Generated mappers no longer have a `.container` property. This was removed in favor + of the new `MapperContainer.globals` container. -# 3.0.0-dev.4 + ```dart + // Instead of this: + var value = MyClassMapper.container.fromValue(...); + // Do this: + var value = MapperContainer.globals.fromValue(...); + ``` -- Chore: Improved docs and tests. -- Copy-With now supports classes that implement multiple interfaces. -- Added support for serializing fields that are not part of the constructor - when annotated with `@MappableField()`. + Mapper initialization and usage is now simplified to the following: -# 3.0.0-dev.3 + 1. When used explicitly (e.g. through `MyClassMapper.fromMap` or `myClass.toMap()`) no additional + initialization is needed. + 2. When used implicitly (through a generic type e.g. `MapperContainer.globals.fromMap()`) the + mapper needs to be initialized once before being used with `MyClassMapper.ensureInitialized()`. -- Fixed bug with null in encoding hook. -# 3.0.0-dev.2 +- **Breaking**: Changed internal mapper implementation which causes any custom mapper to break. + - Removed `MapperElementBase` class. + - Added `MappingContext` being passed to mapper methods. -- Performance improvements & bug fixes. + *See docs on how to use custom mappers in v3.* -# 3.0.0-dev.1 -- Bug fixes. +- **Breaking**: Removed `@MappableLib.createCombinedContainer` in favor of `@MappableLib.generateInitializerForScope`. -# 3.0.0-dev.0 + Instead of generating a new container, v3 generates an initialization function for all mappers. Use it early on in your + application: -- Simplified internal mapper implementation and removed `MapperElementBase` class. -- Added `MappingContext` being passed to mapper methods. + ```dart + @MappableLib(generateInitializerForScope: InitializerScope.package) + library main; + + import 'main.init.dart'; + + void main() { + initializeMappers(); + ... + } + ``` + + +- **Breaking**: Improved support and features for `.copyWith`. + + - Copy-With now supports classes that implement multiple interfaces. + - Renamed `.copyWith.apply()` method to `.copyWith.$update()`. + - Added `.copyWith.$merge()` and `.copyWith.$delta()`. + + You can now use `.copyWith` with either an existing instance using `.$merge` or a map of values using `.$delta`. + + ```dart + @MappableClass() + class A with AMappable { + A(this.a, this.b); + + int? a; + int? b; + } + + void main() { + var a = A(1, null); + + var c = a.copyWith.$merge(A(null, 2)); + assert(c == A(1, 2)); + + var d = a.copyWith.$delta({'b': 2}); + assert(d == A(1, 2)); + } + ``` + + +- **Breaking**: Removed `CheckTypesHook` in favor of discriminator functions. + + You can now use a custom predicate function as the `discriminatorValue` of a class. This function can check + whether the encoded value should be decoded to this subclass and return a boolean. + + ```dart + @MappableClass() + abstract class A with AMappable { + A(); + } + + @MappableClass(discriminatorValue: B.checkType) + class B extends A with BMappable { + B(); + + /// checks if [value] should be decoded to [B] + static bool checkType(value) { + return value is Map && value['isB'] == true; + } + } + + @MappableClass(discriminatorValue: C.checkType) + class C extends A with CMappable { + C(); + + /// checks if [value] should be decoded to [C] + static bool checkType(value) { + return value is Map && value['isWhat'] == 'C'; + } + } + ``` + + +- Added support for serializing fields that are not part of the constructor + when annotated with `@MappableField()`. - Added `EncodingOptions` to `toValue` method. - Added support for third-party models by using annotated `typedef`s. -- Removed `Mapper.container` in favor of `MapperContainer.globals`. -- Removed `@MappableLib.createCombinedContainer` in favor of `@MappableLib.generateInitializerForScope`. -- Renamed `.copyWith.apply()` method to `.copyWith.$update()`. -- Removed `CheckTypesHook` in favor of discriminator functions. -- Added `.copyWith.$merge()` and `.copyWith.$delta()`. +- Added `renameMethods` to build options. +- Improved performance of generated encoding and decoding methods. - For a detailed migration guide, see [this issue](https://github.com/schultek/dart_mappable/issues/71). +For a detailed migration guide, see [this issue](https://github.com/schultek/dart_mappable/issues/71). # 2.0.3 diff --git a/packages/dart_mappable/analysis_options.yaml b/packages/dart_mappable/analysis_options.yaml index 4d510cf4..b072080a 100644 --- a/packages/dart_mappable/analysis_options.yaml +++ b/packages/dart_mappable/analysis_options.yaml @@ -1,9 +1,8 @@ include: package:lints/recommended.yaml analyzer: - strong-mode: - implicit-casts: false - implicit-dynamic: true + language: + strict-casts: true linter: rules: diff --git a/packages/dart_mappable/doc/polymorphism.md b/packages/dart_mappable/doc/polymorphism.md index db6d0ced..eed4aefa 100644 --- a/packages/dart_mappable/doc/polymorphism.md +++ b/packages/dart_mappable/doc/polymorphism.md @@ -38,9 +38,9 @@ two problems arise: - When deserializing, we need to make sure that the correct subclass is chosen and instantiated, and - when serializing, we need to make sure that the subclass information isn't lost. -To solve these, we need to add a **discriminator property**, that keeps track of the specific *(sub)*-type of the `pet`. +To solve these, we add a **discriminator property**, that keeps track of the specific *(sub)*-type of the `pet`. -By default no discriminator is applied, but you can change this by setting the `discriminatorKey` annotation property (or globally in the build configuration). +By default, no discriminator is applied, but you can change this by setting the `discriminatorKey` annotation property (or globally in the build configuration). The value of this property will default to the name of the class, but you can change this as well with the `discriminatorValue` annotation property. diff --git a/packages/dart_mappable/pubspec.yaml b/packages/dart_mappable/pubspec.yaml index c0a6b52c..d0af77f8 100644 --- a/packages/dart_mappable/pubspec.yaml +++ b/packages/dart_mappable/pubspec.yaml @@ -1,6 +1,6 @@ name: dart_mappable description: Improved json serialization and data classes with full support for generics, inheritance, customization and more. -version: 3.0.0-dev.5 +version: 3.0.0 repository: https://github.com/schultek/dart_mappable issue_tracker: https://github.com/schultek/dart_mappable/issues documentation: https://pub.dev/documentation/dart_mappable/latest/topics/Introduction-topic.html @@ -8,7 +8,7 @@ funding: - https://github.com/sponsors/schultek environment: - sdk: '>=2.17.0 <3.0.0' + sdk: '>=2.17.0 <4.0.0' dependencies: collection: ^1.15.0 @@ -17,6 +17,6 @@ dependencies: dev_dependencies: build_runner: ^2.2.0 - dart_mappable_builder: ^3.0.0-dev.5 + dart_mappable_builder: ^3.0.0 lints: '>=1.0.0 <3.0.0' test: ^1.20.1 diff --git a/packages/dart_mappable_builder/CHANGELOG.md b/packages/dart_mappable_builder/CHANGELOG.md index 9aaea4e5..8d27a7e7 100644 --- a/packages/dart_mappable_builder/CHANGELOG.md +++ b/packages/dart_mappable_builder/CHANGELOG.md @@ -1,36 +1,118 @@ -# 3.0.0-dev.5 +# 3.0.0 -- Make delta copy-with null aware. -- Add `renameMethods` to build options. +- **Breaking**: Generated mappers no longer have a `.container` property. This was removed in favor + of the new `MapperContainer.globals` container. -# 3.0.0-dev.4 + ```dart + // Instead of this: + var value = MyClassMapper.container.fromValue(...); + // Do this: + var value = MapperContainer.globals.fromValue(...); + ``` -- Chore: Improved docs and tests. -- Copy-With now supports classes that implement multiple interfaces. -- Added support for serializing fields that are not part of the constructor - when annotated with `@MappableField()`. + Mapper initialization and usage is now simplified to the following: + + 1. When used explicitly (e.g. through `MyClassMapper.fromMap` or `myClass.toMap()`) no additional + initialization is needed. + 2. When used implicitly (through a generic type e.g. `MapperContainer.globals.fromMap()`) the + mapper needs to be initialized once before being used with `MyClassMapper.ensureInitialized()`. + + +- **Breaking**: Changed internal mapper implementation which causes any custom mapper to break. + - Removed `MapperElementBase` class. + - Added `MappingContext` being passed to mapper methods. + + *See docs on how to use custom mappers in v3.* -# 3.0.0-dev.2 -- Performance improvements & bug fixes +- **Breaking**: Removed `@MappableLib.createCombinedContainer` in favor of `@MappableLib.generateInitializerForScope`. -# 3.0.0-dev.1 + Instead of generating a new container, v3 generates an initialization function for all mappers. Use it early on in your + application: -- Bug fixes + ```dart + @MappableLib(generateInitializerForScope: InitializerScope.package) + library main; + + import 'main.init.dart'; + + void main() { + initializeMappers(); + ... + } + ``` -# 3.0.0-dev.0 -- Simplified internal mapper implementation and removed `MapperElementBase` class. -- Added `MappingContext` being passed to mapper methods. +- **Breaking**: Improved support and features for `.copyWith`. + + - Copy-With now supports classes that implement multiple interfaces. + - Renamed `.copyWith.apply()` method to `.copyWith.$update()`. + - Added `.copyWith.$merge()` and `.copyWith.$delta()`. + + You can now use `.copyWith` with either an existing instance using `.$merge` or a map of values using `.$delta`. + + ```dart + @MappableClass() + class A with AMappable { + A(this.a, this.b); + + int? a; + int? b; + } + + void main() { + var a = A(1, null); + + var c = a.copyWith.$merge(A(null, 2)); + assert(c == A(1, 2)); + + var d = a.copyWith.$delta({'b': 2}); + assert(d == A(1, 2)); + } + ``` + + +- **Breaking**: Removed `CheckTypesHook` in favor of discriminator functions. + + You can now use a custom predicate function as the `discriminatorValue` of a class. This function can check + whether the encoded value should be decoded to this subclass and return a boolean. + + ```dart + @MappableClass() + abstract class A with AMappable { + A(); + } + + @MappableClass(discriminatorValue: B.checkType) + class B extends A with BMappable { + B(); + + /// checks if [value] should be decoded to [B] + static bool checkType(value) { + return value is Map && value['isB'] == true; + } + } + + @MappableClass(discriminatorValue: C.checkType) + class C extends A with CMappable { + C(); + + /// checks if [value] should be decoded to [C] + static bool checkType(value) { + return value is Map && value['isWhat'] == 'C'; + } + } + ``` + + +- Added support for serializing fields that are not part of the constructor + when annotated with `@MappableField()`. - Added `EncodingOptions` to `toValue` method. - Added support for third-party models by using annotated `typedef`s. -- Removed `Mapper.container` in favor of `MapperContainer.globals`. -- Removed `@MappableLib.createCombinedContainer` in favor of `@MappableLib.generateInitializerForScope`. -- Renamed `.copyWith.apply()` method to `.copyWith.$update()`. -- Removed `CheckTypesHook` in favor of discriminator functions. -- Added `.copyWith.$merge()` and `.copyWith.$delta()`. +- Added `renameMethods` to build options. +- Improved performance of generated encoding and decoding methods. - For a detailed migration guide, see [this issue](https://github.com/schultek/dart_mappable/issues/71). +For a detailed migration guide, see [this issue](https://github.com/schultek/dart_mappable/issues/71). # 2.0.2 diff --git a/packages/dart_mappable_builder/analysis_options.yaml b/packages/dart_mappable_builder/analysis_options.yaml index 1af90484..4764670d 100644 --- a/packages/dart_mappable_builder/analysis_options.yaml +++ b/packages/dart_mappable_builder/analysis_options.yaml @@ -1,9 +1,8 @@ include: package:lints/recommended.yaml analyzer: - strong-mode: - implicit-casts: false - implicit-dynamic: true + language: + strict-casts: true linter: rules: diff --git a/packages/dart_mappable_builder/pubspec.yaml b/packages/dart_mappable_builder/pubspec.yaml index 007adff9..944ed95a 100644 --- a/packages/dart_mappable_builder/pubspec.yaml +++ b/packages/dart_mappable_builder/pubspec.yaml @@ -1,20 +1,20 @@ name: dart_mappable_builder description: Improved json serialization and data classes with full support for generics, inheritance, customization and more. -version: 3.0.0-dev.5 +version: 3.0.0 repository: https://github.com/schultek/dart_mappable issue_tracker: https://github.com/schultek/dart_mappable/issues funding: - https://github.com/sponsors/schultek environment: - sdk: '>=2.17.0 <3.0.0' + sdk: '>=2.17.0 <4.0.0' dependencies: analyzer: ^5.2.0 ansicolor: ^2.0.1 build: ^2.0.0 collection: ^1.15.0 - dart_mappable: ^3.0.0-dev.5 + dart_mappable: ^3.0.0 dart_style: ^2.2.4 glob: ^2.1.0 path: ^1.8.0