Updated serialize_generator
This commit is contained in:
parent
d09d08caad
commit
e88219da70
8 changed files with 56 additions and 61 deletions
23
packages/serialize/.gitignore
vendored
23
packages/serialize/.gitignore
vendored
|
@ -1,23 +0,0 @@
|
||||||
# Created by .ignore support plugin (hsz.mobi)
|
|
||||||
.idea/**/workspace.xml
|
|
||||||
.idea/**/tasks.xml
|
|
||||||
.idea/dictionaries
|
|
||||||
.idea/**/dataSources/
|
|
||||||
.idea/**/dataSources.ids
|
|
||||||
.idea/**/dataSources.xml
|
|
||||||
.idea/**/dataSources.local.xml
|
|
||||||
.idea/**/sqlDataSources.xml
|
|
||||||
.idea/**/dynamic.xml
|
|
||||||
.idea/**/uiDesigner.xml
|
|
||||||
.idea/**/gradle.xml
|
|
||||||
.idea/**/libraries
|
|
||||||
.idea/**/mongoSettings.xml
|
|
||||||
*.iws
|
|
||||||
/out/
|
|
||||||
.idea_modules/
|
|
||||||
atlassian-ide-plugin.xml
|
|
||||||
com_crashlytics_export_strings.xml
|
|
||||||
crashlytics.properties
|
|
||||||
crashlytics-build.properties
|
|
||||||
fabric.properties
|
|
||||||
.dart_tool
|
|
|
@ -1,5 +1,11 @@
|
||||||
# Change Log
|
# Change Log
|
||||||
|
|
||||||
|
## 4.2.0
|
||||||
|
|
||||||
|
* Fixed `toMap` method generation for non nullable Map
|
||||||
|
* Fixed `fromMap` method generation for non nullable Map
|
||||||
|
* Upgraded from `pendantic` to `lints` linter
|
||||||
|
|
||||||
## 4.1.2
|
## 4.1.2
|
||||||
|
|
||||||
* Fixed `toMap` method generation
|
* Fixed `toMap` method generation
|
||||||
|
|
|
@ -1,21 +1,29 @@
|
||||||
MIT License (MIT)
|
BSD 3-Clause License
|
||||||
|
|
||||||
Copyright (c) 2021 dukefirehawk.com
|
Copyright (c) 2021, dukefirehawk.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Redistribution and use in source and binary forms, with or without
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
modification, are permitted provided that the following conditions are met:
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
1. Redistributions of source code must retain the above copyright notice, this
|
||||||
copies or substantial portions of the Software.
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
this list of conditions and the following disclaimer in the documentation
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
and/or other materials provided with the distribution.
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
3. Neither the name of the copyright holder nor the names of its
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
contributors may be used to endorse or promote products derived from
|
||||||
SOFTWARE.
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Angel3 Serialize Generator
|
# Angel3 Serialize Generator
|
||||||
|
|
||||||
[](https://pub.dartlang.org/packages/angel3_serialize_generator)
|
[](https://pub.dartlang.org/packages/angel3_serialize_generator)
|
||||||
[](https://dart.dev/null-safety)
|
[](https://dart.dev/null-safety)
|
||||||
[](https://gitter.im/angel_dart/discussion)
|
[](https://gitter.im/angel_dart/discussion)
|
||||||
|
|
||||||
|
@ -8,4 +8,4 @@
|
||||||
|
|
||||||
The builder for Angel3 model serialization.
|
The builder for Angel3 model serialization.
|
||||||
|
|
||||||
Find documentation in the main project repo: <https://github.com/dukefirehawk/angel/tree/master/packages/serialize>
|
Find documentation in the main [serialize project repo](https://github.com/dukefirehawk/angel/tree/master/packages/serialize)
|
||||||
|
|
|
@ -1,8 +1 @@
|
||||||
include: package:pedantic/analysis_options.yaml
|
include: package:lints/recommended.yaml
|
||||||
analyzer:
|
|
||||||
strong-mode:
|
|
||||||
implicit-casts: false
|
|
||||||
linter:
|
|
||||||
rules:
|
|
||||||
- unnecessary_new
|
|
||||||
- unnecessary_const
|
|
|
@ -31,7 +31,7 @@ builders:
|
||||||
# - "test/models/with_enum.dart"
|
# - "test/models/with_enum.dart"
|
||||||
# $default:
|
# $default:
|
||||||
# dependencies:
|
# dependencies:
|
||||||
# - "angel_serialize_generator:_book"
|
# - "angel3_serialize_generator:_book"
|
||||||
# sources:
|
# sources:
|
||||||
# - "test/models/author.dart"
|
# - "test/models/author.dart"
|
||||||
# - "test/models/game_pad.dart"
|
# - "test/models/game_pad.dart"
|
||||||
|
|
|
@ -180,8 +180,7 @@ class ${pascal}Decoder extends Converter<Map, $pascal> {
|
||||||
// Serialize model classes via `XSerializer.toMap`
|
// Serialize model classes via `XSerializer.toMap`
|
||||||
else if (isModelClass(type)) {
|
else if (isModelClass(type)) {
|
||||||
var rc = ReCase(type.getDisplayString(withNullability: true));
|
var rc = ReCase(type.getDisplayString(withNullability: true));
|
||||||
serializedRepresentation =
|
serializedRepresentation = serializerToMap(rc, 'model.${field.name}');
|
||||||
'${serializerToMap(rc, 'model.${field.name}')}';
|
|
||||||
} else if (type is InterfaceType) {
|
} else if (type is InterfaceType) {
|
||||||
if (isListOfModelType(type)) {
|
if (isListOfModelType(type)) {
|
||||||
var name =
|
var name =
|
||||||
|
@ -201,8 +200,8 @@ class ${pascal}Decoder extends Converter<Map, $pascal> {
|
||||||
var rc = ReCase(
|
var rc = ReCase(
|
||||||
type.typeArguments[1].getDisplayString(withNullability: true));
|
type.typeArguments[1].getDisplayString(withNullability: true));
|
||||||
serializedRepresentation =
|
serializedRepresentation =
|
||||||
'''model.${field.name}.keys?.fold({}, (map, key) {
|
'''model.${field.name}.keys.fold({}, (map, key) {
|
||||||
return map..[key] =
|
return (map as Map<String,dynamic>?)?..[key] =
|
||||||
${serializerToMap(rc, 'model.${field.name}[key]')};
|
${serializerToMap(rc, 'model.${field.name}[key]')};
|
||||||
})''';
|
})''';
|
||||||
} else if (type.element.isEnum) {
|
} else if (type.element.isEnum) {
|
||||||
|
@ -270,11 +269,19 @@ class ${pascal}Decoder extends Converter<Map, $pascal> {
|
||||||
ctx.requiredFields.forEach((key, msg) {
|
ctx.requiredFields.forEach((key, msg) {
|
||||||
if (ctx.excluded[key]?.canDeserialize == false) return;
|
if (ctx.excluded[key]?.canDeserialize == false) return;
|
||||||
var name = ctx.resolveFieldName(key);
|
var name = ctx.resolveFieldName(key);
|
||||||
|
if (msg.contains("'")) {
|
||||||
buf.writeln('''
|
buf.writeln('''
|
||||||
if (map['$name'] == null) {
|
if (map['$name'] == null) {
|
||||||
throw FormatException("$msg");
|
throw FormatException("$msg");
|
||||||
}
|
}
|
||||||
''');
|
''');
|
||||||
|
} else {
|
||||||
|
buf.writeln('''
|
||||||
|
if (map['$name'] == null) {
|
||||||
|
throw FormatException('$msg');
|
||||||
|
}
|
||||||
|
''');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
buf.writeln('return ${ctx.modelClassName}(');
|
buf.writeln('return ${ctx.modelClassName}(');
|
||||||
|
@ -348,6 +355,10 @@ class ${pascal}Decoder extends Converter<Map, $pascal> {
|
||||||
' : $defaultValue';
|
' : $defaultValue';
|
||||||
} else if (isMapToModelType(type)) {
|
} else if (isMapToModelType(type)) {
|
||||||
// TODO: This requires refractoring
|
// TODO: This requires refractoring
|
||||||
|
if (defaultValue == 'null') {
|
||||||
|
defaultValue = '{}';
|
||||||
|
}
|
||||||
|
|
||||||
var rc = ReCase(
|
var rc = ReCase(
|
||||||
type.typeArguments[1].getDisplayString(withNullability: true));
|
type.typeArguments[1].getDisplayString(withNullability: true));
|
||||||
deserializedRepresentation = '''
|
deserializedRepresentation = '''
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: angel3_serialize_generator
|
name: angel3_serialize_generator
|
||||||
version: 4.1.2
|
version: 4.2.0
|
||||||
description: Angel3 model serialization generators, designed for use with Angel. Combine with angel_serialize for flexible modeling.
|
description: Angel3 model serialization generators, designed for use with Angel. Combine with angel_serialize for flexible modeling.
|
||||||
homepage: https://angel3-framework.web.app/
|
homepage: https://angel3-framework.web.app/
|
||||||
repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/serialize/angel_serialize_generator
|
repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/serialize/angel_serialize_generator
|
||||||
|
@ -22,5 +22,5 @@ dependencies:
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
build_runner: ^2.0.1
|
build_runner: ^2.0.1
|
||||||
collection: ^1.15.0
|
collection: ^1.15.0
|
||||||
pedantic: ^1.11.0
|
lints: ^1.0.0
|
||||||
test: ^1.17.4
|
test: ^1.17.4
|
||||||
|
|
Loading…
Reference in a new issue