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

View file

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

View file

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

View file

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

View file

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

View file

@ -211,7 +211,7 @@ class ${pascal}Decoder extends Converter<Map, $pascal> {
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 as Map<dynamic,dynamic>?)?..[key] = return map..[key] =
${serializerToMap(rc, 'model.${field.name}[key]')}; ${serializerToMap(rc, 'model.${field.name}[key]')};
})'''; })''';
} else if (type.element is Enum) { } else if (type.element is Enum) {

View file

@ -1,10 +1,10 @@
name: angel3_serialize_generator 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. 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/master/packages/serialize/angel_serialize_generator repository: https://github.com/dukefirehawk/angel/tree/master/packages/serialize/angel_serialize_generator
environment: environment:
sdk: '>=2.18.0 <3.0.0' sdk: '>=2.19.0 <3.0.0'
dependencies: dependencies:
analyzer: ^5.0.0 analyzer: ^5.0.0
angel3_model: ^7.0.0 angel3_model: ^7.0.0
@ -27,5 +27,5 @@ dev_dependencies:
# dependency_overrides: # dependency_overrides:
# angel3_model: # angel3_model:
# path: ../../model # path: ../../model
# angel3_serialize: # angel3_serialize:
# path: ../angel_serialize # path: ../angel_serialize

View file

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

View file

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

View file

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

View file

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

View file

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