Skip to content

Commit

Permalink
Merge pull request #169 from netglade/feat/168-extends-custom-mapping
Browse files Browse the repository at this point in the history
Support zero argument function in custom mapping
  • Loading branch information
petrnymsa authored Feb 13, 2024
2 parents 6dd33a0 + 5029850 commit f1cc704
Show file tree
Hide file tree
Showing 44 changed files with 163 additions and 68 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"yaml.schemaStore.enable": false
}
10 changes: 6 additions & 4 deletions examples/drift/lib/db.drift.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ class $TodosTable extends Todos with TableInfo<$TodosTable, Todo> {
@override
List<GeneratedColumn> get $columns => [id, title, content, category];
@override
String get aliasedName => _alias ?? 'todos';
String get aliasedName => _alias ?? actualTableName;
@override
String get actualTableName => 'todos';
String get actualTableName => $name;
static const String $name = 'todos';
@override
VerificationContext validateIntegrity(Insertable<Todo> instance,
{bool isInserting = false}) {
Expand Down Expand Up @@ -278,9 +279,10 @@ class $CategoriesTable extends Categories
@override
List<GeneratedColumn> get $columns => [id, description];
@override
String get aliasedName => _alias ?? 'categories';
String get aliasedName => _alias ?? actualTableName;
@override
String get actualTableName => 'categories';
String get actualTableName => $name;
static const String $name = 'categories';
@override
VerificationContext validateIntegrity(Insertable<Category> instance,
{bool isInserting = false}) {
Expand Down
1 change: 1 addition & 0 deletions examples/drift/lib/mappr.auto_mappr.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/drift/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ dev_dependencies:
auto_mappr: ^2.0.0
build_runner: ^2.0.0
drift_dev: ^2.7.0
netglade_analysis: ^6.0.0
netglade_analysis: ^8.0.0
test: ^1.16.0
1 change: 1 addition & 0 deletions examples/example/lib/enum.auto_mappr.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/example/lib/equatable.auto_mappr.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/example/lib/nested.auto_mappr.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/example/lib/nullable.auto_mappr.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/example/lib/rename.auto_mappr.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ dependencies:
dev_dependencies:
auto_mappr: ^2.0.0
build_runner: ^2.0.0
netglade_analysis: ^6.0.0
netglade_analysis: ^8.0.0
test: ^1.16.0
1 change: 1 addition & 0 deletions examples/freezed/lib/freezed_example.auto_mappr.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 19 additions & 18 deletions examples/freezed/lib/freezed_example.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ part of 'freezed_example.dart';
T _$identity<T>(T value) => value;

final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');

/// @nodoc
mixin _$UserInfoUnion {
Expand Down Expand Up @@ -79,11 +79,11 @@ class _$UserInfoUnionCopyWithImpl<$Res, $Val extends UserInfoUnion>
}

/// @nodoc
abstract class _$$UserInfoCopyWith<$Res>
abstract class _$$UserInfoImplCopyWith<$Res>
implements $UserInfoUnionCopyWith<$Res> {
factory _$$UserInfoCopyWith(
_$UserInfo value, $Res Function(_$UserInfo) then) =
__$$UserInfoCopyWithImpl<$Res>;
factory _$$UserInfoImplCopyWith(
_$UserInfoImpl value, $Res Function(_$UserInfoImpl) then) =
__$$UserInfoImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
Expand All @@ -94,10 +94,11 @@ abstract class _$$UserInfoCopyWith<$Res>
}

/// @nodoc
class __$$UserInfoCopyWithImpl<$Res>
extends _$UserInfoUnionCopyWithImpl<$Res, _$UserInfo>
implements _$$UserInfoCopyWith<$Res> {
__$$UserInfoCopyWithImpl(_$UserInfo _value, $Res Function(_$UserInfo) _then)
class __$$UserInfoImplCopyWithImpl<$Res>
extends _$UserInfoUnionCopyWithImpl<$Res, _$UserInfoImpl>
implements _$$UserInfoImplCopyWith<$Res> {
__$$UserInfoImplCopyWithImpl(
_$UserInfoImpl _value, $Res Function(_$UserInfoImpl) _then)
: super(_value, _then);

@pragma('vm:prefer-inline')
Expand All @@ -108,7 +109,7 @@ class __$$UserInfoCopyWithImpl<$Res>
Object? updatedAt = null,
Object? primarySectionId = null,
}) {
return _then(_$UserInfo(
return _then(_$UserInfoImpl(
email: null == email
? _value.email
: email // ignore: cast_nullable_to_non_nullable
Expand All @@ -131,8 +132,8 @@ class __$$UserInfoCopyWithImpl<$Res>

/// @nodoc
class _$UserInfo implements UserInfo {
_$UserInfo(
class _$UserInfoImpl implements UserInfo {
_$UserInfoImpl(
{required this.email,
required this.loginIdentifier,
required this.updatedAt,
Expand All @@ -154,10 +155,10 @@ class _$UserInfo implements UserInfo {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$UserInfo &&
other is _$UserInfoImpl &&
(identical(other.email, email) || other.email == email) &&
(identical(other.loginIdentifier, loginIdentifier) ||
other.loginIdentifier == loginIdentifier) &&
Expand All @@ -174,16 +175,16 @@ class _$UserInfo implements UserInfo {
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$UserInfoCopyWith<_$UserInfo> get copyWith =>
__$$UserInfoCopyWithImpl<_$UserInfo>(this, _$identity);
_$$UserInfoImplCopyWith<_$UserInfoImpl> get copyWith =>
__$$UserInfoImplCopyWithImpl<_$UserInfoImpl>(this, _$identity);
}

abstract class UserInfo implements UserInfoUnion {
factory UserInfo(
{required final String email,
required final String loginIdentifier,
required final DateTime updatedAt,
final int primarySectionId}) = _$UserInfo;
final int primarySectionId}) = _$UserInfoImpl;

@override
String get email;
Expand All @@ -195,6 +196,6 @@ abstract class UserInfo implements UserInfoUnion {
int get primarySectionId;
@override
@JsonKey(ignore: true)
_$$UserInfoCopyWith<_$UserInfo> get copyWith =>
_$$UserInfoImplCopyWith<_$UserInfoImpl> get copyWith =>
throw _privateConstructorUsedError;
}
2 changes: 1 addition & 1 deletion examples/freezed/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ dev_dependencies:
auto_mappr: ^2.0.0
build_runner: ^2.0.0
freezed: ^2.3.2
netglade_analysis: ^6.0.0
netglade_analysis: ^8.0.0
test: ^1.16.0
3 changes: 1 addition & 2 deletions examples/injectable/lib/getit.config.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/injectable/lib/mappr.auto_mappr.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/injectable/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ dev_dependencies:
auto_mappr: ^2.0.0
build_runner: ^2.0.0
injectable_generator: ^2.1.5
netglade_analysis: ^6.0.0
netglade_analysis: ^8.0.0
test: ^1.16.0

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/json_serializable/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ dev_dependencies:
auto_mappr: ^2.0.0
build_runner: ^2.0.0
json_serializable: ^6.6.1
netglade_analysis: ^6.0.0
netglade_analysis: ^8.0.0
test: ^1.16.0

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/auto_mappr/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[//]: # (## Unreleased)

## 2.3.0
- Support zero argument function in custom mapping [#169](https://github.com/netglade/auto_mappr/pull/169)

## 2.2.0
- Improve error messages. [#147](https://github.com/netglade/auto_mappr/pull/147)
- When the source is not null, `TypeConverter<Object, Object>` and `TypeConverter<Object, Object?>` now support mapping of source field `Object?` -> target field `Object?`. [#142](https://github.com/netglade/auto_mappr/pull/142)
Expand Down
16 changes: 8 additions & 8 deletions packages/auto_mappr/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<a href="https://github.com/netglade">
<picture >
<source media="(prefers-color-scheme: dark)" height='120px' srcset="https://raw.githubusercontent.com/netglade/auto_mappr/main/packages/auto_mappr/doc/badge_light.png">
<source media="(prefers-color-scheme: light)" height='120px' srcset="https://raw.githubusercontent.com/netglade/auto_mappr/main/packages/auto_mappr/doc/badge_dark.png">
<img alt="netglade" height='120px' src="https://raw.githubusercontent.com/netglade/auto_mappr/main/packages/auto_mappr/doc/badge_dark.png">
</picture>
<a href="https://github.com/netglade">
<img alt="netglade" height='120px' src="https://raw.githubusercontent.com/netglade/auto_mappr/main/packages/auto_mappr/doc/badge.png">
</a>

Developed with 💚 by [netglade][netglade_link]
Expand Down Expand Up @@ -281,8 +277,11 @@ When you need to assign a custom function or a const value as a value for given
you can use the `custom` argument in a `Field` mapping.
Alternatively, you can use the `Field.custom()` constructor
which hides other then-invalid parameters.
Provide `const Target` value or custom mapping function.

You can set up `Target Function(Source dto)` function or `const Target` value.
The custom function has to follow one of these formals:
- has `Source` model argument - `Target Function(Source dto)`
- has exactly zero arguments and returns `Target`

```dart
@AutoMappr([
Expand All @@ -298,7 +297,8 @@ class Mappr extends $Mappr {
static String mapName(UserDto dto) => dto.name.toUpperCase();
}
int mapAge(UserDto _) => 42;
/// Return always 42
int mapAge() => 42;
```

### Ignore mapping
Expand Down
Binary file added packages/auto_mappr/doc/badge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed packages/auto_mappr/doc/badge_dark.png
Binary file not shown.
Binary file removed packages/auto_mappr/doc/badge_light.png
Binary file not shown.
34 changes: 34 additions & 0 deletions packages/auto_mappr/example/lib/mappr.auto_mappr.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f1cc704

Please sign in to comment.