diff --git a/.idea/runConfigurations/build_dart.xml b/.idea/runConfigurations/build_dart.xml new file mode 100644 index 00000000..c2cc1300 --- /dev/null +++ b/.idea/runConfigurations/build_dart.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/tests_in_angel_serialize_generator.xml b/.idea/runConfigurations/tests_in_angel_serialize_generator.xml new file mode 100644 index 00000000..e61b9017 --- /dev/null +++ b/.idea/runConfigurations/tests_in_angel_serialize_generator.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/.idea/serialize.iml b/.idea/serialize.iml index 017e6a01..17e06bc2 100644 --- a/.idea/serialize.iml +++ b/.idea/serialize.iml @@ -4,15 +4,10 @@ - - - - - diff --git a/angel_serialize/.packages b/angel_serialize/.packages index 8c0f9b06..fe880de1 100644 --- a/angel_serialize/.packages +++ b/angel_serialize/.packages @@ -1,2 +1,2 @@ -# Generated by pub on 2017-07-10 11:01:13.581030. +# Generated by pub on 2017-12-07 02:04:15.968150. angel_serialize:lib/ diff --git a/angel_serialize/pubspec.yaml b/angel_serialize/pubspec.yaml index 27460c78..169f4ce8 100644 --- a/angel_serialize/pubspec.yaml +++ b/angel_serialize/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_serialize -version: 1.0.0-alpha+1 +version: 1.0.0 description: Static annotations powering Angel model serialization. author: Tobe O homepage: https://github.com/angel-dart/serialize \ No newline at end of file diff --git a/angel_serialize_generator/pubspec.yaml b/angel_serialize_generator/pubspec.yaml index 1ae3d643..844df7ba 100644 --- a/angel_serialize_generator/pubspec.yaml +++ b/angel_serialize_generator/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_serialize_generator -version: 1.0.0-alpha+3 +version: 1.0.0 description: Model serialization generators, designed for use with Angel. author: Tobe O homepage: https://github.com/angel-dart/serialize diff --git a/angel_serialize_generator/test/book_test.dart b/angel_serialize_generator/test/book_test.dart index 8be18ec2..8edd638f 100644 --- a/angel_serialize_generator/test/book_test.dart +++ b/angel_serialize_generator/test/book_test.dart @@ -1,5 +1,6 @@ import 'dart:convert'; import 'package:test/test.dart'; +import 'models/author.dart'; import 'models/book.dart'; const String DEATHLY_HALLOWS_ISBN = '0-545-01022-5'; diff --git a/angel_serialize_generator/test/models/author.dart b/angel_serialize_generator/test/models/author.dart new file mode 100644 index 00000000..66ecac61 --- /dev/null +++ b/angel_serialize_generator/test/models/author.dart @@ -0,0 +1,21 @@ +library angel_serialize.test.models.author; + +import 'package:angel_framework/common.dart'; +import 'package:angel_serialize/angel_serialize.dart'; +import 'book.dart'; +part 'author.g.dart'; + +@serializable +abstract class _Author extends Model { + String name; + int age; + List books; + Book newestBook; + @exclude + String secret; +} + +@serializable +abstract class _Library extends Model { + Map collection; +} \ No newline at end of file diff --git a/angel_serialize_generator/test/models/author.g.dart b/angel_serialize_generator/test/models/author.g.dart new file mode 100644 index 00000000..9aa6dd76 --- /dev/null +++ b/angel_serialize_generator/test/models/author.g.dart @@ -0,0 +1,137 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_serialize.test.models.author; + +// ************************************************************************** +// Generator: JsonModelGenerator +// ************************************************************************** + +class Author extends _Author { + @override + String id; + + @override + String name; + + @override + int age; + + @override + List books; + + @override + Book newestBook; + + @override + DateTime createdAt; + + @override + DateTime updatedAt; + + Author( + {this.id, + this.name, + this.age, + this.books, + this.newestBook, + this.createdAt, + this.updatedAt}); + + factory Author.fromJson(Map data) { + return new Author( + id: data['id'], + name: data['name'], + age: data['age'], + books: data['books'] is List + ? data['books'] + .map((x) => + x == null ? null : (x is Book ? x : new Book.fromJson(x))) + .toList() + : null, + newestBook: data['newest_book'] == null + ? null + : (data['newest_book'] is Book + ? data['newest_book'] + : new Book.fromJson(data['newest_book'])), + createdAt: data['created_at'] is DateTime + ? data['created_at'] + : (data['created_at'] is String + ? DateTime.parse(data['created_at']) + : null), + updatedAt: data['updated_at'] is DateTime + ? data['updated_at'] + : (data['updated_at'] is String + ? DateTime.parse(data['updated_at']) + : null)); + } + + Map toJson() => { + 'id': id, + 'name': name, + 'age': age, + 'books': books, + 'newest_book': newestBook, + 'created_at': createdAt == null ? null : createdAt.toIso8601String(), + 'updated_at': updatedAt == null ? null : updatedAt.toIso8601String() + }; + + static Author parse(Map map) => new Author.fromJson(map); + + Author clone() { + return new Author.fromJson(toJson()); + } +} + +class Library extends _Library { + @override + String id; + + @override + Map collection; + + @override + DateTime createdAt; + + @override + DateTime updatedAt; + + Library({this.id, this.collection, this.createdAt, this.updatedAt}); + + factory Library.fromJson(Map data) { + return new Library( + id: data['id'], + collection: data['collection'] is Map + ? data['collection'].keys.fold({}, (out, k) { + out[k] = data['collection'][k] == null + ? null + : (data['collection'][k] is Book + ? data['collection'][k] + : new Book.fromJson(data['collection'][k])); + return out; + }) + : null, + createdAt: data['created_at'] is DateTime + ? data['created_at'] + : (data['created_at'] is String + ? DateTime.parse(data['created_at']) + : null), + updatedAt: data['updated_at'] is DateTime + ? data['updated_at'] + : (data['updated_at'] is String + ? DateTime.parse(data['updated_at']) + : null)); + } + + Map toJson() => { + 'id': id, + 'collection': collection, + 'created_at': createdAt == null ? null : createdAt.toIso8601String(), + 'updated_at': updatedAt == null ? null : updatedAt.toIso8601String() + }; + + static Library parse(Map map) => new Library.fromJson(map); + + Library clone() { + return new Library.fromJson(toJson()); + } +} diff --git a/angel_serialize_generator/test/models/book.dart b/angel_serialize_generator/test/models/book.dart index e3558df4..11b66345 100644 --- a/angel_serialize_generator/test/models/book.dart +++ b/angel_serialize_generator/test/models/book.dart @@ -8,19 +8,4 @@ part 'book.g.dart'; abstract class _Book extends Model { String author, title, description; int pageCount; -} - -@serializable -abstract class _Author extends Model { - String name; - int age; - List<_Book> books; - _Book newestBook; - @exclude - String secret; -} - -@serializable -abstract class _Library extends Model { - Map collection; } \ No newline at end of file diff --git a/angel_serialize_generator/test/models/book.g.dart b/angel_serialize_generator/test/models/book.g.dart index 47ceab7c..7385a354 100644 --- a/angel_serialize_generator/test/models/book.g.dart +++ b/angel_serialize_generator/test/models/book.g.dart @@ -72,131 +72,3 @@ class Book extends _Book { return new Book.fromJson(toJson()); } } - -class Author extends _Author { - @override - String id; - - @override - String name; - - @override - int age; - - @override - List<_Book> books; - - @override - _Book newestBook; - - @override - DateTime createdAt; - - @override - DateTime updatedAt; - - Author( - {this.id, - this.name, - this.age, - this.books, - this.newestBook, - this.createdAt, - this.updatedAt}); - - factory Author.fromJson(Map data) { - return new Author( - id: data['id'], - name: data['name'], - age: data['age'], - books: data['books'] is List - ? data['books'] - .map((x) => - x == null ? null : (x is Book ? x : new Book.fromJson(x))) - .toList() - : null, - newestBook: data['newest_book'] is Book - ? data['newest_book'] - : new Book.fromJson(data['newest_book']), - createdAt: data['created_at'] is DateTime - ? data['created_at'] - : (data['created_at'] is String - ? DateTime.parse(data['created_at']) - : null), - updatedAt: data['updated_at'] is DateTime - ? data['updated_at'] - : (data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : null)); - } - - Map toJson() => { - 'id': id, - 'name': name, - 'age': age, - 'books': books, - 'newest_book': newestBook.toJson(), - 'created_at': createdAt == null ? null : createdAt.toIso8601String(), - 'updated_at': updatedAt == null ? null : updatedAt.toIso8601String() - }; - - static Author parse(Map map) => new Author.fromJson(map); - - Author clone() { - return new Author.fromJson(toJson()); - } -} - -class Library extends _Library { - @override - String id; - - @override - Map collection; - - @override - DateTime createdAt; - - @override - DateTime updatedAt; - - Library({this.id, this.collection, this.createdAt, this.updatedAt}); - - factory Library.fromJson(Map data) { - return new Library( - id: data['id'], - collection: data['collection'] is Map - ? data['collection'].keys.fold({}, (out, k) { - out[k] = data['collection'][k] == null - ? null - : (data['collection'][k] is Book - ? data['collection'][k] - : new Book.fromJson(data['collection'][k])); - return out; - }) - : null, - createdAt: data['created_at'] is DateTime - ? data['created_at'] - : (data['created_at'] is String - ? DateTime.parse(data['created_at']) - : null), - updatedAt: data['updated_at'] is DateTime - ? data['updated_at'] - : (data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : null)); - } - - Map toJson() => { - 'id': id, - 'collection': collection, - 'created_at': createdAt == null ? null : createdAt.toIso8601String(), - 'updated_at': updatedAt == null ? null : updatedAt.toIso8601String() - }; - - static Library parse(Map map) => new Library.fromJson(map); - - Library clone() { - return new Library.fromJson(toJson()); - } -} diff --git a/angel_serialize_generator/tool/actions.dart b/angel_serialize_generator/tool/actions.dart index cf31ddc1..cb9bbb3f 100644 --- a/angel_serialize_generator/tool/actions.dart +++ b/angel_serialize_generator/tool/actions.dart @@ -3,7 +3,18 @@ import 'package:source_gen/source_gen.dart'; import 'package:angel_serialize_generator/angel_serialize_generator.dart'; final List actions = [ - new BuildAction(new PartBuilder([const JsonModelGenerator()]), - 'angel_serialize_generator', - inputs: const ['test/models/*.dart']) + new BuildAction( + new PartBuilder([const JsonModelGenerator()]), + 'angel_serialize_generator', + inputs: const [ + 'test/models/book.dart', + ], + ), + new BuildAction( + new PartBuilder([const JsonModelGenerator()]), + 'angel_serialize_generator', + inputs: const [ + 'test/models/author.dart', + ], + ), ];