2.0.8, frozen

This commit is contained in:
Tobe O 2018-06-23 00:52:46 -04:00
parent 4511a14ea4
commit 403e2e600e
7 changed files with 31 additions and 12 deletions

View file

@ -2,10 +2,12 @@
<module type="WEB_MODULE" version="4"> <module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$/angel_serialize"> <content url="file://$MODULE_DIR$/angel_serialize">
<excludeFolder url="file://$MODULE_DIR$/angel_serialize/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/angel_serialize/.pub" /> <excludeFolder url="file://$MODULE_DIR$/angel_serialize/.pub" />
<excludeFolder url="file://$MODULE_DIR$/angel_serialize/build" /> <excludeFolder url="file://$MODULE_DIR$/angel_serialize/build" />
</content> </content>
<content url="file://$MODULE_DIR$/angel_serialize_generator"> <content url="file://$MODULE_DIR$/angel_serialize_generator">
<excludeFolder url="file://$MODULE_DIR$/angel_serialize_generator/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/angel_serialize_generator/.pub" /> <excludeFolder url="file://$MODULE_DIR$/angel_serialize_generator/.pub" />
<excludeFolder url="file://$MODULE_DIR$/angel_serialize_generator/build" /> <excludeFolder url="file://$MODULE_DIR$/angel_serialize_generator/build" />
</content> </content>

View file

@ -1,3 +1,6 @@
# 2.0.8
* Generate a `fromMap` with typecasting, for Dart 2's sake.
# 2.0.7 # 2.0.7
* Create unmodifiable Lists and Maps. * Create unmodifiable Lists and Maps.
* Support `@required` on fields. * Support `@required` on fields.

View file

@ -79,3 +79,16 @@ bool isMapToModelType(InterfaceType t) {
t.typeArguments.length == 2 && t.typeArguments.length == 2 &&
isModelClass(t.typeArguments[1]); isModelClass(t.typeArguments[1]);
} }
/// Compute a [String] representation of a [type].
String typeToString(DartType type) {
if (type is InterfaceType) {
if (type.typeArguments.isEmpty) return type.name;
return type.name +
'<' +
type.typeArguments.map(typeToString).join(', ') +
'>';
} else {
return type.name;
}
}

View file

@ -172,12 +172,13 @@ class SerializerGenerator extends GeneratorForAnnotation<Serializable> {
if (i++ > 0) buf.write(', '); if (i++ > 0) buf.write(', ');
String deserializedRepresentation = "map['$alias']"; String deserializedRepresentation = "map['$alias'] as ${typeToString(
field.type)}";
// Deserialize dates // Deserialize dates
if (dateTimeTypeChecker.isAssignableFromType(field.type)) if (dateTimeTypeChecker.isAssignableFromType(field.type))
deserializedRepresentation = "map['$alias'] != null ? " deserializedRepresentation = "map['$alias'] != null ? "
"(map['$alias'] is DateTime ? map['$alias'] : DateTime.parse(map['$alias']))" "(map['$alias'] is DateTime ? (map['$alias'] as DateTime) : DateTime.parse(map['$alias']))"
" : null"; " : null";
// Serialize model classes via `XSerializer.toMap` // Serialize model classes via `XSerializer.toMap`
@ -192,16 +193,16 @@ class SerializerGenerator extends GeneratorForAnnotation<Serializable> {
if (isListModelType(t)) { if (isListModelType(t)) {
var rc = new ReCase(t.typeArguments[0].name); var rc = new ReCase(t.typeArguments[0].name);
deserializedRepresentation = "map['$alias'] is Iterable" deserializedRepresentation = "map['$alias'] is Iterable"
" ? new List.unmodifiable(map['$alias'].map(${rc " ? new List.unmodifiable((map['$alias'] as Iterable).whereType<Map>().map(${rc
.pascalCase}Serializer.fromMap))" .pascalCase}Serializer.fromMap))"
" : null"; " : null";
} else if (isMapToModelType(t)) { } else if (isMapToModelType(t)) {
var rc = new ReCase(t.typeArguments[1].name); var rc = new ReCase(t.typeArguments[1].name);
deserializedRepresentation = ''' deserializedRepresentation = '''
map['$alias'] is Map map['$alias'] is Map
? new Map.unmodifiable(map['$alias'].keys.fold({}, (out, key) { ? new Map.unmodifiable((map['$alias'] as Map).keys.fold({}, (out, key) {
return out..[key] = ${rc return out..[key] = ${rc
.pascalCase}Serializer.fromMap(map['$alias'][key]); .pascalCase}Serializer.fromMap((map['$alias'] as Map)[key]);
})) }))
: null : null
'''; ''';

View file

@ -1,11 +1,12 @@
name: angel_serialize_generator name: angel_serialize_generator
version: 2.0.7 version: 2.0.8
description: Model serialization generators, designed for use with Angel. Combine with angel_serialize for flexible modeling. description: Model serialization generators, designed for use with Angel. Combine with angel_serialize for flexible modeling.
author: Tobe O <thosakwe@gmail.com> author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/serialize homepage: https://github.com/angel-dart/serialize
environment: environment:
sdk: '>=2.0.0-dev.1.2 <2.0.0' sdk: '>=2.0.0-dev.1.2 <3.0.0'
dependencies: dependencies:
angel_model: ^1.0.0
angel_serialize: ^2.0.0-alpha angel_serialize: ^2.0.0-alpha
build_config: ">=0.2.4 <2.0.0" build_config: ">=0.2.4 <2.0.0"
code_buffer: ^1.0.0 code_buffer: ^1.0.0
@ -15,6 +16,5 @@ dependencies:
recase: ^1.0.0 recase: ^1.0.0
source_gen: ^0.7.0 source_gen: ^0.7.0
dev_dependencies: dev_dependencies:
angel_framework: ^1.0.0 build_runner: ^0.9.0
build_runner: ^0.7.0 test: ^1.0.0
test: ">= 0.12.13 < 0.13.0"

View file

@ -1,6 +1,6 @@
library angel_serialize.test.models.author; library angel_serialize.test.models.author;
import 'package:angel_framework/common.dart'; import 'package:angel_model/angel_model.dart';
import 'package:angel_serialize/angel_serialize.dart'; import 'package:angel_serialize/angel_serialize.dart';
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';

View file

@ -1,6 +1,6 @@
library angel_serialize.test.models.book; library angel_serialize.test.models.book;
import 'package:angel_framework/common.dart'; import 'package:angel_model/angel_model.dart';
import 'package:angel_serialize/angel_serialize.dart'; import 'package:angel_serialize/angel_serialize.dart';
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
part 'book.g.dart'; part 'book.g.dart';