Updated serialize generator

This commit is contained in:
thomashii@dukefirehawk.com 2023-04-21 14:25:54 +08:00
parent 71b7d54763
commit cc7e3a255e
13 changed files with 1862 additions and 1901 deletions

View file

@ -21,7 +21,7 @@ jobs:
- uses: dart-lang/setup-dart@v1
with:
sdk: "2.18.0"
sdk: "2.19.0"
- id: angel3_container_upgrade
name: angel3_container; Upgrade depedencies
@ -87,7 +87,7 @@ jobs:
- uses: dart-lang/setup-dart@v1
with:
sdk: "2.18.0"
sdk: "2.19.0"
# Angel3 ORM
- id: angel3_orm_upgrade

View file

@ -30,8 +30,9 @@ class Todo extends Model {
class FoodItem {
final String name;
final num price;
final num qty;
FoodItem(this.name, this.price);
FoodItem(this.name, this.price, this.qty);
}
class Order {
@ -65,6 +66,7 @@ void main() async {
//await app.mountController<SalesController>();
var http = AngelHttp(app);
var server = await http.startServer('localhost', 3000);
print("Angel server listening at ${http.uri}");
}

View file

@ -2,10 +2,10 @@ name: example2
version: 0.0.1
description: Example 2.
environment:
sdk: '>=2.18.0 <3.0.0'
sdk: '>=2.19.0 <3.0.0'
dependencies:
angel3_container: ^7.0.0
angel3_container_generator: ^7.0.0
angel3_container: ^7.1.0-beta.1
angel3_container_generator: ^7.1.0-beta.1
angel3_http_exception: ^7.0.0
angel3_framework: ^7.0.0
angel3_model: ^7.0.0
@ -37,13 +37,13 @@ dev_dependencies:
io: ^1.0.0
test: ^1.21.0
lints: ^2.0.0
dependency_overrides:
angel3_container:
path: ../../../packages/container/angel_container
angel3_container_generator:
path: ../../../packages/container/angel_container_generator
angel3_framework:
path: ../../../packages/framework
# dependency_overrides:
# angel3_container:
# path: ../../../packages/container/angel_container
# angel3_container_generator:
# path: ../../../packages/container/angel_container_generator
# angel3_framework:
# path: ../../../packages/framework
# angel3_model:
# path: ../model
# angel3_route:

View file

@ -1,8 +1,13 @@
# Change Log
## 7.2.0-beta.1
* Require Dart >= 2.19
* Fixed `topMap` incorrect return
## 7.1.0
* [Breaking] Require Dart >= 2.18
* Require Dart >= 2.18
* Upgraded to `analyzer` 5.x.x
* Replaced deprecated `element2` with `element`

View file

@ -8,7 +8,10 @@ part of 'main.dart';
@generatedSerializable
class Todo extends _Todo {
Todo({this.text, this.completed});
Todo({
this.text,
this.completed,
});
@override
String? text;
@ -16,7 +19,10 @@ class Todo extends _Todo {
@override
bool? completed;
Todo copyWith({String? text, bool? completed}) {
Todo copyWith({
String? text,
bool? completed,
}) {
return Todo(
text: text ?? this.text, completed: completed ?? this.completed);
}
@ -28,7 +34,10 @@ class Todo extends _Todo {
@override
int get hashCode {
return hashObjects([text, completed]);
return hashObjects([
text,
completed,
]);
}
@override
@ -82,7 +91,10 @@ class TodoSerializer extends Codec<Todo, Map> {
}
abstract class TodoFields {
static const List<String> allFields = <String>[text, completed];
static const List<String> allFields = <String>[
text,
completed,
];
static const String text = 'text';

View file

@ -211,7 +211,7 @@ class ${pascal}Decoder extends Converter<Map, $pascal> {
type.typeArguments[1].getDisplayString(withNullability: true));
serializedRepresentation =
'''model.${field.name}.keys.fold({}, (map, key) {
return (map as Map<dynamic,dynamic>?)?..[key] =
return map..[key] =
${serializerToMap(rc, 'model.${field.name}[key]')};
})''';
} else if (type.element is Enum) {

View file

@ -1,10 +1,10 @@
name: angel3_serialize_generator
version: 7.1.0
version: 7.2.0-beta.1
description: Angel3 model serialization generators, designed for use with Angel. Combine with angel_serialize for flexible modeling.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/serialize/angel_serialize_generator
environment:
sdk: '>=2.18.0 <3.0.0'
sdk: '>=2.19.0 <3.0.0'
dependencies:
analyzer: ^5.0.0
angel3_model: ^7.0.0

View file

@ -10,8 +10,8 @@ part of angel_serialize.test.models.book;
@pragma('hello')
@SerializableField(alias: 'omg')
class Book extends _Book {
Book(
{this.id,
Book({
this.id,
this.createdAt,
this.updatedAt,
this.author,
@ -19,8 +19,8 @@ class Book extends _Book {
this.description,
this.pageCount,
List<double>? notModels = const [],
this.camelCaseString})
: notModels = List.unmodifiable(notModels ?? []);
this.camelCaseString,
}) : notModels = List.unmodifiable(notModels ?? []);
/// A unique identifier corresponding to this item.
@override
@ -53,8 +53,8 @@ class Book extends _Book {
@override
String? camelCaseString;
Book copyWith(
{String? id,
Book copyWith({
String? id,
DateTime? createdAt,
DateTime? updatedAt,
String? author,
@ -62,7 +62,8 @@ class Book extends _Book {
String? description,
int? pageCount,
List<double>? notModels,
String? camelCaseString}) {
String? camelCaseString,
}) {
return Book(
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
@ -101,7 +102,7 @@ class Book extends _Book {
description,
pageCount,
notModels,
camelCaseString
camelCaseString,
]);
}
@ -117,8 +118,8 @@ class Book extends _Book {
@generatedSerializable
class Author extends _Author {
Author(
{this.id,
Author({
this.id,
this.createdAt,
this.updatedAt,
required this.name,
@ -126,8 +127,8 @@ class Author extends _Author {
List<_Book> books = const [],
this.newestBook,
this.secret,
this.obscured})
: books = List.unmodifiable(books);
this.obscured,
}) : books = List.unmodifiable(books);
/// A unique identifier corresponding to this item.
@override
@ -160,8 +161,8 @@ class Author extends _Author {
@override
String? obscured;
Author copyWith(
{String? id,
Author copyWith({
String? id,
DateTime? createdAt,
DateTime? updatedAt,
String? name,
@ -169,7 +170,8 @@ class Author extends _Author {
List<_Book>? books,
_Book? newestBook,
String? secret,
String? obscured}) {
String? obscured,
}) {
return Author(
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
@ -208,7 +210,7 @@ class Author extends _Author {
books,
newestBook,
secret,
obscured
obscured,
]);
}
@ -224,12 +226,12 @@ class Author extends _Author {
@generatedSerializable
class Library extends _Library {
Library(
{this.id,
Library({
this.id,
this.createdAt,
this.updatedAt,
required Map<String, _Book> collection})
: collection = Map.unmodifiable(collection);
required Map<String, _Book> collection,
}) : collection = Map.unmodifiable(collection);
/// A unique identifier corresponding to this item.
@override
@ -246,11 +248,12 @@ class Library extends _Library {
@override
Map<String, _Book> collection;
Library copyWith(
{String? id,
Library copyWith({
String? id,
DateTime? createdAt,
DateTime? updatedAt,
Map<String, _Book>? collection}) {
Map<String, _Book>? collection,
}) {
return Library(
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
@ -272,7 +275,12 @@ class Library extends _Library {
@override
int get hashCode {
return hashObjects([id, createdAt, updatedAt, collection]);
return hashObjects([
id,
createdAt,
updatedAt,
collection,
]);
}
@override
@ -287,14 +295,15 @@ class Library extends _Library {
@generatedSerializable
class Bookmark extends _Bookmark {
Bookmark(_Book book,
{this.id,
Bookmark(
_Book book, {
this.id,
this.createdAt,
this.updatedAt,
List<int> history = const [],
required this.page,
this.comment})
: history = List.unmodifiable(history),
this.comment,
}) : history = List.unmodifiable(history),
super(book);
/// A unique identifier corresponding to this item.
@ -318,13 +327,15 @@ class Bookmark extends _Bookmark {
@override
String? comment;
Bookmark copyWith(_Book book,
{String? id,
Bookmark copyWith(
_Book book, {
String? id,
DateTime? createdAt,
DateTime? updatedAt,
List<int>? history,
int? page,
String? comment}) {
String? comment,
}) {
return Bookmark(book,
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
@ -348,7 +359,14 @@ class Bookmark extends _Bookmark {
@override
int get hashCode {
return hashObjects([id, createdAt, updatedAt, history, page, comment]);
return hashObjects([
id,
createdAt,
updatedAt,
history,
page,
comment,
]);
}
@override
@ -439,7 +457,7 @@ abstract class BookFields {
description,
pageCount,
notModels,
camelCaseString
camelCaseString,
];
static const String id = 'id';
@ -543,7 +561,7 @@ abstract class AuthorFields {
books,
newestBook,
secret,
obscured
obscured,
];
static const String id = 'id';
@ -620,8 +638,7 @@ class LibrarySerializer extends Codec<Library, Map> {
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String(),
'collection': model.collection.keys.fold({}, (map, key) {
return (map as Map<dynamic, dynamic>)
..[key] = BookSerializer.toMap(model.collection[key]);
return map..[key] = BookSerializer.toMap(model.collection[key]);
})
};
}
@ -632,7 +649,7 @@ abstract class LibraryFields {
id,
createdAt,
updatedAt,
collection
collection,
];
static const String id = 'id';
@ -645,7 +662,10 @@ abstract class LibraryFields {
}
abstract class BookmarkSerializer {
static Bookmark fromMap(Map map, _Book book) {
static Bookmark fromMap(
Map map,
_Book book,
) {
if (map['page'] == null) {
throw FormatException("Missing required field 'page' on Bookmark.");
}
@ -691,7 +711,7 @@ abstract class BookmarkFields {
updatedAt,
history,
page,
comment
comment,
];
static const String id = 'id';

View file

@ -8,7 +8,10 @@ part of 'game_pad_button.dart';
@generatedSerializable
class GamepadButton implements _GamepadButton {
GamepadButton({this.name, this.radius});
GamepadButton({
this.name,
this.radius,
});
@override
String? name;
@ -16,7 +19,10 @@ class GamepadButton implements _GamepadButton {
@override
int? radius;
GamepadButton copyWith({String? name, int? radius}) {
GamepadButton copyWith({
String? name,
int? radius,
}) {
return GamepadButton(
name: name ?? this.name, radius: radius ?? this.radius);
}
@ -30,7 +36,10 @@ class GamepadButton implements _GamepadButton {
@override
int get hashCode {
return hashObjects([name, radius]);
return hashObjects([
name,
radius,
]);
}
@override
@ -45,10 +54,10 @@ class GamepadButton implements _GamepadButton {
@generatedSerializable
class Gamepad extends _Gamepad {
Gamepad(
{List<_GamepadButton>? buttons = const [],
Map<String, dynamic>? dynamicMap})
: buttons = List.unmodifiable(buttons ?? []),
Gamepad({
List<_GamepadButton>? buttons = const [],
Map<String, dynamic>? dynamicMap,
}) : buttons = List.unmodifiable(buttons ?? []),
dynamicMap = Map.unmodifiable(dynamicMap ?? {});
@override
@ -57,8 +66,10 @@ class Gamepad extends _Gamepad {
@override
Map<String, dynamic>? dynamicMap;
Gamepad copyWith(
{List<_GamepadButton>? buttons, Map<String, dynamic>? dynamicMap}) {
Gamepad copyWith({
List<_GamepadButton>? buttons,
Map<String, dynamic>? dynamicMap,
}) {
return Gamepad(
buttons: buttons ?? this.buttons,
dynamicMap: dynamicMap ?? this.dynamicMap);
@ -76,7 +87,10 @@ class Gamepad extends _Gamepad {
@override
int get hashCode {
return hashObjects([buttons, dynamicMap]);
return hashObjects([
buttons,
dynamicMap,
]);
}
@override
@ -131,7 +145,10 @@ class GamepadButtonSerializer extends Codec<GamepadButton, Map> {
}
abstract class GamepadButtonFields {
static const List<String> allFields = <String>[name, radius];
static const List<String> allFields = <String>[
name,
radius,
];
static const String name = 'name';
@ -185,7 +202,10 @@ class GamepadSerializer extends Codec<Gamepad, Map> {
}
abstract class GamepadFields {
static const List<String> allFields = <String>[buttons, dynamicMap];
static const List<String> allFields = <String>[
buttons,
dynamicMap,
];
static const String buttons = 'buttons';

View file

@ -8,7 +8,10 @@ part of 'goat.dart';
@generatedSerializable
class Goat implements _Goat {
Goat({this.integer = 34, this.list = const [34, 35]});
Goat({
this.integer = 34,
this.list = const [34, 35],
});
@override
int integer;
@ -16,7 +19,10 @@ class Goat implements _Goat {
@override
List<int> list;
Goat copyWith({int? integer, List<int>? list}) {
Goat copyWith({
int? integer,
List<int>? list,
}) {
return Goat(integer: integer ?? this.integer, list: list ?? this.list);
}
@ -29,7 +35,10 @@ class Goat implements _Goat {
@override
int get hashCode {
return hashObjects([integer, list]);
return hashObjects([
integer,
list,
]);
}
@override
@ -86,7 +95,10 @@ class GoatSerializer extends Codec<Goat, Map> {
}
abstract class GoatFields {
static const List<String> allFields = <String>[integer, list];
static const List<String> allFields = <String>[
integer,
list,
];
static const String integer = 'integer';

View file

@ -8,7 +8,10 @@ part of 'subclass.dart';
@generatedSerializable
class Animal extends _Animal {
Animal({required this.genus, required this.species});
Animal({
required this.genus,
required this.species,
});
@override
String? genus;
@ -16,7 +19,10 @@ class Animal extends _Animal {
@override
String? species;
Animal copyWith({String? genus, String? species}) {
Animal copyWith({
String? genus,
String? species,
}) {
return Animal(genus: genus ?? this.genus, species: species ?? this.species);
}
@ -27,7 +33,10 @@ class Animal extends _Animal {
@override
int get hashCode {
return hashObjects([genus, species]);
return hashObjects([
genus,
species,
]);
}
@override
@ -42,7 +51,11 @@ class Animal extends _Animal {
@generatedSerializable
class Bird extends _Bird {
Bird({required this.genus, required this.species, this.isSparrow = false});
Bird({
required this.genus,
required this.species,
this.isSparrow = false,
});
@override
String? genus;
@ -53,7 +66,11 @@ class Bird extends _Bird {
@override
bool? isSparrow;
Bird copyWith({String? genus, String? species, bool? isSparrow}) {
Bird copyWith({
String? genus,
String? species,
bool? isSparrow,
}) {
return Bird(
genus: genus ?? this.genus,
species: species ?? this.species,
@ -70,7 +87,11 @@ class Bird extends _Bird {
@override
int get hashCode {
return hashObjects([genus, species, isSparrow]);
return hashObjects([
genus,
species,
isSparrow,
]);
}
@override
@ -132,7 +153,10 @@ class AnimalSerializer extends Codec<Animal, Map> {
}
abstract class AnimalFields {
static const List<String> allFields = <String>[genus, species];
static const List<String> allFields = <String>[
genus,
species,
];
static const String genus = 'genus';
@ -190,7 +214,11 @@ class BirdSerializer extends Codec<Bird, Map> {
}
abstract class BirdFields {
static const List<String> allFields = <String>[genus, species, isSparrow];
static const List<String> allFields = <String>[
genus,
species,
isSparrow,
];
static const String genus = 'genus';

View file

@ -8,8 +8,11 @@ part of 'with_enum.dart';
@generatedSerializable
class WithEnum implements _WithEnum {
WithEnum(
{this.type = WithEnumType.b, this.finalList = const [], this.imageBytes});
WithEnum({
this.type = WithEnumType.b,
this.finalList = const [],
this.imageBytes,
});
@override
WithEnumType? type;
@ -20,8 +23,11 @@ class WithEnum implements _WithEnum {
@override
Uint8List? imageBytes;
WithEnum copyWith(
{WithEnumType? type, List<int>? finalList, Uint8List? imageBytes}) {
WithEnum copyWith({
WithEnumType? type,
List<int>? finalList,
Uint8List? imageBytes,
}) {
return WithEnum(
type: type ?? this.type,
finalList: finalList ?? this.finalList,
@ -39,7 +45,11 @@ class WithEnum implements _WithEnum {
@override
int get hashCode {
return hashObjects([type, finalList, imageBytes]);
return hashObjects([
type,
finalList,
imageBytes,
]);
}
@override
@ -110,7 +120,11 @@ class WithEnumSerializer extends Codec<WithEnum, Map> {
}
abstract class WithEnumFields {
static const List<String> allFields = <String>[type, finalList, imageBytes];
static const List<String> allFields = <String>[
type,
finalList,
imageBytes,
];
static const String type = 'type';