Migrated to NNBD

This commit is contained in:
thomashii 2021-06-14 09:28:20 +08:00
parent 77b61d30ed
commit 9d9a94965e
15 changed files with 70 additions and 213 deletions

3
.github/FUNDING.yml vendored
View file

@ -1,3 +0,0 @@
# These are supported funding model platforms
github: [thosakwe]

25
.gitignore vendored
View file

@ -37,25 +37,7 @@ pubspec.lock
# User-specific stuff: # User-specific stuff:
.idea/workspace.xml .idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml
# Sensitive or high-churn files:
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml
# Gradle:
.idea/gradle.xml
.idea/libraries
# Mongo Explorer plugin:
.idea/mongoSettings.xml
## File-based project format: ## File-based project format:
*.iws *.iws
@ -78,11 +60,8 @@ crashlytics-build.properties
fabric.properties fabric.properties
### VSCode template ### VSCode template
.vscode/* .vscode/
!.vscode/settings.json .metals/
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
logs/ logs/
*.pem *.pem

View file

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>

View file

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectInspectionProfilesVisibleTreeState">
<entry key="Project Default">
<profile-state>
<expanded-state>
<State>
<id />
</State>
<State>
<id>General</id>
</State>
<State>
<id>XPath</id>
</State>
</expanded-state>
<selected-state>
<State>
<id>AngularJS</id>
</State>
</selected-state>
</profile-state>
</entry>
</component>
</project>

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/angel.iml" filepath="$PROJECT_DIR$/.idea/angel.iml" />
</modules>
</component>
</project>

View file

@ -1,8 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="dev.dart" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" singleton="true" nameIsGenerated="true">
<option name="VMOptions" value="--observe" />
<option name="filePath" value="$PROJECT_DIR$/bin/dev.dart" />
<option name="workingDirectory" value="$PROJECT_DIR$" />
<method />
</configuration>
</component>

View file

@ -1,11 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="prod.dart" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" singleton="true" nameIsGenerated="true">
<option name="checkedMode" value="false" />
<option name="envs">
<entry key="ANGEL_ENV" value="production" />
</option>
<option name="filePath" value="$PROJECT_DIR$/bin/prod.dart" />
<option name="workingDirectory" value="$PROJECT_DIR$" />
<method />
</configuration>
</component>

View file

@ -1,12 +1,12 @@
import 'dart:io'; import 'dart:io';
import 'package:angel/src/pretty_logging.dart'; import 'package:pretty_logging/pretty_logging.dart';
import 'package:angel/angel.dart'; import 'package:angel/angel.dart';
import 'package:angel_container/mirrors.dart'; import 'package:angel_container/mirrors.dart';
import 'package:angel_framework/angel_framework.dart'; import 'package:angel_framework/angel_framework.dart';
import 'package:angel_hot/angel_hot.dart'; import 'package:angel_hot/angel_hot.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
main() async { void main() async {
// Watch the config/ and web/ directories for changes, and hot-reload the server. // Watch the config/ and web/ directories for changes, and hot-reload the server.
hierarchicalLoggingEnabled = true; hierarchicalLoggingEnabled = true;

View file

@ -25,6 +25,6 @@ import 'package:angel_production/angel_production.dart';
// so in the meantime, visit the Angel chat for further questions: // so in the meantime, visit the Angel chat for further questions:
// //
// https://gitter.im/angel_dart/discussion // https://gitter.im/angel_dart/discussion
main(List<String> args) => void main(List<String> args) =>
Runner('{{angel}}', configureServer, reflector: MirrorsReflector()) Runner('{{angel}}', configureServer, reflector: MirrorsReflector())
.run(args); .run(args);

View file

@ -5,7 +5,7 @@ part 'todo.g.dart';
@graphQLClass @graphQLClass
@serializable @serializable
abstract class _Todo extends Model { abstract class _Todo extends Model {
String get text; String? get text;
bool get isComplete; bool? get isComplete;
} }

View file

@ -11,26 +11,26 @@ class Todo extends _Todo {
Todo({this.id, this.text, this.isComplete, this.createdAt, this.updatedAt}); Todo({this.id, this.text, this.isComplete, this.createdAt, this.updatedAt});
@override @override
final String id; final String? id;
@override @override
final String text; final String? text;
@override @override
final bool isComplete; final bool? isComplete;
@override @override
final DateTime createdAt; final DateTime? createdAt;
@override @override
final DateTime updatedAt; final DateTime? updatedAt;
Todo copyWith( Todo copyWith(
{String id, {String? id,
String text, String? text,
bool isComplete, bool? isComplete,
DateTime createdAt, DateTime? createdAt,
DateTime updatedAt}) { DateTime? updatedAt}) {
return Todo( return Todo(
id: id ?? this.id, id: id ?? this.id,
text: text ?? this.text, text: text ?? this.text,
@ -39,6 +39,7 @@ class Todo extends _Todo {
updatedAt: updatedAt ?? this.updatedAt); updatedAt: updatedAt ?? this.updatedAt);
} }
@override
bool operator ==(other) { bool operator ==(other) {
return other is _Todo && return other is _Todo &&
other.id == id && other.id == id &&
@ -55,7 +56,7 @@ class Todo extends _Todo {
@override @override
String toString() { String toString() {
return "Todo(id=$id, text=$text, isComplete=$isComplete, createdAt=$createdAt, updatedAt=$updatedAt)"; return 'Todo(id=$id, text=$text, isComplete=$isComplete, createdAt=$createdAt, updatedAt=$updatedAt)';
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -87,30 +88,27 @@ class TodoSerializer extends Codec<Todo, Map> {
const TodoSerializer(); const TodoSerializer();
@override @override
get encoder => const TodoEncoder(); TodoEncoder get encoder => const TodoEncoder();
@override @override
get decoder => const TodoDecoder(); TodoDecoder get decoder => const TodoDecoder();
static Todo fromMap(Map map) { static Todo fromMap(Map map) {
return Todo( return Todo(
id: map['id'] as String, id: map['id'] as String?,
text: map['text'] as String, text: map['text'] as String?,
isComplete: map['is_complete'] as bool, isComplete: map['is_complete'] as bool?,
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? (map['created_at'] is DateTime ? (map['created_at'] is DateTime
? (map['created_at'] as DateTime) ? (map['created_at'] as DateTime?)
: DateTime.parse(map['created_at'].toString())) : DateTime.parse(map['created_at'].toString()))
: null, : null,
updatedAt: map['updated_at'] != null updatedAt: map['updated_at'] != null
? (map['updated_at'] is DateTime ? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime) ? (map['updated_at'] as DateTime?)
: DateTime.parse(map['updated_at'].toString())) : DateTime.parse(map['updated_at'].toString()))
: null); : null);
} }
static Map<String, dynamic> toMap(_Todo model) { static Map<String, dynamic> toMap(_Todo model) {
if (model == null) {
return null;
}
return { return {
'id': model.id, 'id': model.id,
'text': model.text, 'text': model.text,

View file

@ -1,38 +0,0 @@
import 'package:angel_http_exception/angel_http_exception.dart';
import 'package:logging/logging.dart';
import 'package:io/ansi.dart';
/// Prints the contents of a [LogRecord] with pretty colors.
void prettyLog(LogRecord record) {
var code = chooseLogColor(record.level);
if (record.error == null) print(code.wrap(record.toString()));
if (record.error != null) {
var err = record.error;
if (err is AngelHttpException && err.statusCode != 500) return;
print(code.wrap(record.toString() + '\n'));
print(code.wrap(err.toString()));
if (record.stackTrace != null) {
print(code.wrap(record.stackTrace.toString()));
}
}
}
/// Chooses a color based on the logger [level].
AnsiCode chooseLogColor(Level level) {
if (level == Level.SHOUT)
return backgroundRed;
else if (level == Level.SEVERE)
return red;
else if (level == Level.WARNING)
return yellow;
else if (level == Level.INFO)
return cyan;
else if (level == Level.CONFIG ||
level == Level.FINE ||
level == Level.FINER ||
level == Level.FINEST) return lightGray;
return resetAll;
}

View file

@ -4,12 +4,12 @@ import 'package:angel_graphql/angel_graphql.dart';
import 'package:graphql_schema/graphql_schema.dart'; import 'package:graphql_schema/graphql_schema.dart';
/// Find or create an in-memory Todo store. /// Find or create an in-memory Todo store.
MapService _getTodoService(Angel app) { MapService? _getTodoService(Angel app) {
const key = 'todoService'; const key = 'todoService';
// If there is already an existing singleton, return it. // If there is already an existing singleton, return it.
if (app.container.hasNamed(key)) { if (app.container!.hasNamed(key)) {
return app.container.findByName<MapService>(key); return app.container!.findByName<MapService>(key);
} }
// Create an in-memory service. We will use this // Create an in-memory service. We will use this
@ -18,14 +18,14 @@ MapService _getTodoService(Angel app) {
// Register this service as a named singleton in the app container, // Register this service as a named singleton in the app container,
// so that we do not inadvertently create another instance. // so that we do not inadvertently create another instance.
app.container.registerNamedSingleton(key, mapService); app.container!.registerNamedSingleton(key, mapService);
return mapService; return mapService;
} }
/// Returns fields to be inserted into the query type. /// Returns fields to be inserted into the query type.
Iterable<GraphQLObjectField> todoQueryFields(Angel app) { Iterable<GraphQLObjectField> todoQueryFields(Angel app) {
var todoService = _getTodoService(app); var todoService = _getTodoService(app)!;
// Here, we use special resolvers to read data from our store. // Here, we use special resolvers to read data from our store.
return [ return [
@ -47,7 +47,7 @@ Iterable<GraphQLObjectField> todoQueryFields(Angel app) {
/// Returns fields to be inserted into the query type. /// Returns fields to be inserted into the query type.
Iterable<GraphQLObjectField> todoMutationFields(Angel app) { Iterable<GraphQLObjectField> todoMutationFields(Angel app) {
var todoService = _getTodoService(app); var todoService = _getTodoService(app)!;
var todoInputType = todoGraphQLType.toInputObject('TodoInput'); var todoInputType = todoGraphQLType.toInputObject('TodoInput');
// This time, we use resolvers to modify the data in the store. // This time, we use resolvers to modify the data in the store.

View file

@ -1,85 +1,77 @@
name: angel name: angel
description: An app that's going to be amazing pretty soon. description: An app that's going to be amazing pretty soon.
publish_to: none # Ensure we don't accidentally publish our private code! ;) publish_to: none
environment: environment:
sdk: '>=2.0.0-dev <3.0.0' sdk: '>=2.12.0 <3.0.0'
homepage: https://github.com/angel-dart/angel homepage: https://github.com/dukefirehawk/boilerplates
dependencies: dependencies:
angel_auth: ^2.0.0 # Supports stateless authentication via JWT
angel_configuration: ^2.0.0 # Loads application configuration, along with support for .env files.
angel_framework: ^2.0.0 # The core server library.
angel_graphql: ^1.0.0 # Infrastructure for serving GraphQL.
angel_jael: ^2.0.0 # Server-side templating engine
angel_production: ^1.0.0 # Production application runner.
angel_static: ^2.0.0 # Static file server
angel_validate: ^2.0.0 # Allows for validation of input data
dev_dependencies:
angel_hot: ^2.0.0 # Hot-reloading support. :)
angel_serialize_generator: # Generates serialization code, and more.
angel_test: ^2.0.0 # Utilities for testing Angel servers.
build_runner: ^1.0.0 # Runs code builders.
graphql_generator: ^1.0.0 # Generates GraphQL schemas statically.
io: ^0.3.2 # For pretty printing.
pedantic: ^1.0.0 # Enforces Dart style conventions.
test: ^1.0.0 # For unit testing.
dependency_overrides:
angel_auth: angel_auth:
git: git:
url: https://github.com/dukefirehawk/angel.git url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x ref: sdk-2.12.x_nnbd
path: packages/auth path: packages/auth
angel_configuration: angel_configuration:
git: git:
url: https://github.com/dukefirehawk/angel.git url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x ref: sdk-2.12.x_nnbd
path: packages/configuration path: packages/configuration
angel_framework: angel_framework:
git: git:
url: https://github.com/dukefirehawk/angel.git url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x ref: sdk-2.12.x_nnbd
path: packages/framework path: packages/framework
angel_graphql:
git:
url: https://github.com/dukefirehawk/graphql_dart.git
ref: sdk-2.12.x_nnbd
path: angel_graphql
angel_jael: angel_jael:
git: git:
url: https://github.com/dukefirehawk/angel.git url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x ref: sdk-2.12.x_nnbd
path: packages/jael/angel_jael path: packages/jael/angel_jael
angel_production: angel_production:
git: git:
url: https://github.com/dukefirehawk/angel.git url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x ref: sdk-2.12.x_nnbd
path: packages/production path: packages/production
angel_static: angel_static:
git: git:
url: https://github.com/dukefirehawk/angel.git url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x ref: sdk-2.12.x_nnbd
path: packages/static path: packages/static
angel_validate: angel_validate:
git: git:
url: https://github.com/dukefirehawk/angel.git url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x ref: sdk-2.12.x_nnbd
path: packages/validate path: packages/validate
dev_dependencies:
angel_hot: angel_hot:
git: git:
url: https://github.com/dukefirehawk/angel.git url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x ref: sdk-2.12.x_nnbd
path: packages/hot path: packages/hot
angel_test:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x
path: packages/test
angel_graphql:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x
path: packages/graphql/angel_graphql
angel_serialize_generator: angel_serialize_generator:
git: git:
url: https://github.com/dukefirehawk/angel.git url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x ref: sdk-2.12.x_nnbd
path: packages/serialize/angel_serialize_generator path: packages/serialize/angel_serialize_generator
graphql_generator: angel_test:
git: git:
url: https://github.com/dukefirehawk/angel.git url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x ref: sdk-2.12.x_nnbd
path: packages/graphql/graphql_generator path: packages/test
pretty_logging:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x_nnbd
path: packages/pretty_logging
graphql_generator:
git:
url: https://github.com/dukefirehawk/graphql_dart.git
ref: sdk-2.12.x_nnbd
path: graphql_generator
build_runner: ^2.0.4
io: ^1.0.0
pedantic: ^1.11.0
test: ^1.17.7

View file

@ -19,8 +19,8 @@ import 'package:test/test.dart';
// here: // here:
// https://github.com/dart-lang/test // https://github.com/dart-lang/test
main() async { void main() async {
TestClient client; late TestClient client;
setUp(() async { setUp(() async {
var app = Angel(); var app = Angel();
@ -35,7 +35,7 @@ main() async {
test('index returns 200', () async { test('index returns 200', () async {
// Request a resource at the given path. // Request a resource at the given path.
var response = await client.get('/'); var response = await client.get(Uri.parse('/'));
// Expect a 200 response. // Expect a 200 response.
expect(response, hasStatus(200)); expect(response, hasStatus(200));