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:
.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:
*.iws
@ -78,11 +60,8 @@ crashlytics-build.properties
fabric.properties
### VSCode template
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.vscode/
.metals/
logs/
*.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 'package:angel/src/pretty_logging.dart';
import 'package:pretty_logging/pretty_logging.dart';
import 'package:angel/angel.dart';
import 'package:angel_container/mirrors.dart';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_hot/angel_hot.dart';
import 'package:logging/logging.dart';
main() async {
void main() async {
// Watch the config/ and web/ directories for changes, and hot-reload the server.
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:
//
// https://gitter.im/angel_dart/discussion
main(List<String> args) =>
void main(List<String> args) =>
Runner('{{angel}}', configureServer, reflector: MirrorsReflector())
.run(args);

View file

@ -5,7 +5,7 @@ part 'todo.g.dart';
@graphQLClass
@serializable
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});
@override
final String id;
final String? id;
@override
final String text;
final String? text;
@override
final bool isComplete;
final bool? isComplete;
@override
final DateTime createdAt;
final DateTime? createdAt;
@override
final DateTime updatedAt;
final DateTime? updatedAt;
Todo copyWith(
{String id,
String text,
bool isComplete,
DateTime createdAt,
DateTime updatedAt}) {
{String? id,
String? text,
bool? isComplete,
DateTime? createdAt,
DateTime? updatedAt}) {
return Todo(
id: id ?? this.id,
text: text ?? this.text,
@ -39,6 +39,7 @@ class Todo extends _Todo {
updatedAt: updatedAt ?? this.updatedAt);
}
@override
bool operator ==(other) {
return other is _Todo &&
other.id == id &&
@ -55,7 +56,7 @@ class Todo extends _Todo {
@override
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() {
@ -87,30 +88,27 @@ class TodoSerializer extends Codec<Todo, Map> {
const TodoSerializer();
@override
get encoder => const TodoEncoder();
TodoEncoder get encoder => const TodoEncoder();
@override
get decoder => const TodoDecoder();
TodoDecoder get decoder => const TodoDecoder();
static Todo fromMap(Map map) {
return Todo(
id: map['id'] as String,
text: map['text'] as String,
isComplete: map['is_complete'] as bool,
id: map['id'] as String?,
text: map['text'] as String?,
isComplete: map['is_complete'] as bool?,
createdAt: map['created_at'] != null
? (map['created_at'] is DateTime
? (map['created_at'] as DateTime)
? (map['created_at'] as DateTime?)
: DateTime.parse(map['created_at'].toString()))
: null,
updatedAt: map['updated_at'] != null
? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime)
? (map['updated_at'] as DateTime?)
: DateTime.parse(map['updated_at'].toString()))
: null);
}
static Map<String, dynamic> toMap(_Todo model) {
if (model == null) {
return null;
}
return {
'id': model.id,
'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';
/// Find or create an in-memory Todo store.
MapService _getTodoService(Angel app) {
MapService? _getTodoService(Angel app) {
const key = 'todoService';
// If there is already an existing singleton, return it.
if (app.container.hasNamed(key)) {
return app.container.findByName<MapService>(key);
if (app.container!.hasNamed(key)) {
return app.container!.findByName<MapService>(key);
}
// 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,
// so that we do not inadvertently create another instance.
app.container.registerNamedSingleton(key, mapService);
app.container!.registerNamedSingleton(key, mapService);
return mapService;
}
/// Returns fields to be inserted into the query type.
Iterable<GraphQLObjectField> todoQueryFields(Angel app) {
var todoService = _getTodoService(app);
var todoService = _getTodoService(app)!;
// Here, we use special resolvers to read data from our store.
return [
@ -47,7 +47,7 @@ Iterable<GraphQLObjectField> todoQueryFields(Angel app) {
/// Returns fields to be inserted into the query type.
Iterable<GraphQLObjectField> todoMutationFields(Angel app) {
var todoService = _getTodoService(app);
var todoService = _getTodoService(app)!;
var todoInputType = todoGraphQLType.toInputObject('TodoInput');
// This time, we use resolvers to modify the data in the store.

View file

@ -1,85 +1,77 @@
name: angel
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:
sdk: '>=2.0.0-dev <3.0.0'
homepage: https://github.com/angel-dart/angel
sdk: '>=2.12.0 <3.0.0'
homepage: https://github.com/dukefirehawk/boilerplates
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:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x
ref: sdk-2.12.x_nnbd
path: packages/auth
angel_configuration:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x
ref: sdk-2.12.x_nnbd
path: packages/configuration
angel_framework:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x
ref: sdk-2.12.x_nnbd
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:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x
ref: sdk-2.12.x_nnbd
path: packages/jael/angel_jael
angel_production:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x
ref: sdk-2.12.x_nnbd
path: packages/production
angel_static:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x
ref: sdk-2.12.x_nnbd
path: packages/static
angel_validate:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x
ref: sdk-2.12.x_nnbd
path: packages/validate
dev_dependencies:
angel_hot:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x
ref: sdk-2.12.x_nnbd
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:
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
graphql_generator:
angel_test:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x
path: packages/graphql/graphql_generator
ref: sdk-2.12.x_nnbd
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:
// https://github.com/dart-lang/test
main() async {
TestClient client;
void main() async {
late TestClient client;
setUp(() async {
var app = Angel();
@ -35,7 +35,7 @@ main() async {
test('index returns 200', () async {
// Request a resource at the given path.
var response = await client.get('/');
var response = await client.get(Uri.parse('/'));
// Expect a 200 response.
expect(response, hasStatus(200));