diff --git a/packages/framework/.idea/dbnavigator.xml b/packages/framework/.idea/dbnavigator.xml deleted file mode 100644 index 11ef66c4..00000000 --- a/packages/framework/.idea/dbnavigator.xml +++ /dev/null @@ -1,451 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/framework/.idea/encodings.xml b/packages/framework/.idea/encodings.xml deleted file mode 100644 index 97626ba4..00000000 --- a/packages/framework/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/packages/framework/.idea/jsLibraryMappings.xml b/packages/framework/.idea/jsLibraryMappings.xml deleted file mode 100644 index f3e502d1..00000000 --- a/packages/framework/.idea/jsLibraryMappings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/packages/framework/.idea/libraries/Dart_Packages.xml b/packages/framework/.idea/libraries/Dart_Packages.xml deleted file mode 100644 index 088c8509..00000000 --- a/packages/framework/.idea/libraries/Dart_Packages.xml +++ /dev/null @@ -1,525 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/framework/.idea/libraries/Dart_SDK.xml b/packages/framework/.idea/libraries/Dart_SDK.xml deleted file mode 100644 index ed937c05..00000000 --- a/packages/framework/.idea/libraries/Dart_SDK.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/framework/.idea/misc.xml b/packages/framework/.idea/misc.xml deleted file mode 100644 index 1719e444..00000000 --- a/packages/framework/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/modules.xml b/packages/framework/.idea/modules.xml deleted file mode 100644 index e6494b43..00000000 --- a/packages/framework/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/All_Tests.xml b/packages/framework/.idea/runConfigurations/All_Tests.xml deleted file mode 100644 index dcd3564d..00000000 --- a/packages/framework/.idea/runConfigurations/All_Tests.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/All_Tests__PRODUCTION_.xml b/packages/framework/.idea/runConfigurations/All_Tests__PRODUCTION_.xml deleted file mode 100644 index 09ab904c..00000000 --- a/packages/framework/.idea/runConfigurations/All_Tests__PRODUCTION_.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/All_Tests__for_coverage_.xml b/packages/framework/.idea/runConfigurations/All_Tests__for_coverage_.xml deleted file mode 100644 index c5727acc..00000000 --- a/packages/framework/.idea/runConfigurations/All_Tests__for_coverage_.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/Controller_Tests.xml b/packages/framework/.idea/runConfigurations/Controller_Tests.xml deleted file mode 100644 index 16c24846..00000000 --- a/packages/framework/.idea/runConfigurations/Controller_Tests.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/DI_Tests.xml b/packages/framework/.idea/runConfigurations/DI_Tests.xml deleted file mode 100644 index 002c3572..00000000 --- a/packages/framework/.idea/runConfigurations/DI_Tests.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/Hooked_Tests.xml b/packages/framework/.idea/runConfigurations/Hooked_Tests.xml deleted file mode 100644 index 592565a1..00000000 --- a/packages/framework/.idea/runConfigurations/Hooked_Tests.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/Match_routes__even_with_query_params_in_routing_test_dart.xml b/packages/framework/.idea/runConfigurations/Match_routes__even_with_query_params_in_routing_test_dart.xml deleted file mode 100644 index 3df4dee3..00000000 --- a/packages/framework/.idea/runConfigurations/Match_routes__even_with_query_params_in_routing_test_dart.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/Middleware_via_metadata_in_routing_test_dart.xml b/packages/framework/.idea/runConfigurations/Middleware_via_metadata_in_routing_test_dart.xml deleted file mode 100644 index 41e6ad8d..00000000 --- a/packages/framework/.idea/runConfigurations/Middleware_via_metadata_in_routing_test_dart.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/Routing_Tests.xml b/packages/framework/.idea/runConfigurations/Routing_Tests.xml deleted file mode 100644 index 3790ba95..00000000 --- a/packages/framework/.idea/runConfigurations/Routing_Tests.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/can_fetch_data_in_services_test_dart.xml b/packages/framework/.idea/runConfigurations/can_fetch_data_in_services_test_dart.xml deleted file mode 100644 index 5dbab496..00000000 --- a/packages/framework/.idea/runConfigurations/can_fetch_data_in_services_test_dart.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/cannot_write_after_close_in_streaming_test_dart.xml b/packages/framework/.idea/runConfigurations/cannot_write_after_close_in_streaming_test_dart.xml deleted file mode 100644 index e0ee83ca..00000000 --- a/packages/framework/.idea/runConfigurations/cannot_write_after_close_in_streaming_test_dart.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/encoding_in_encoders_buffer_test_dart.xml b/packages/framework/.idea/runConfigurations/encoding_in_encoders_buffer_test_dart.xml deleted file mode 100644 index f13ca17d..00000000 --- a/packages/framework/.idea/runConfigurations/encoding_in_encoders_buffer_test_dart.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/encoding_in_streaming_test_dart.xml b/packages/framework/.idea/runConfigurations/encoding_in_streaming_test_dart.xml deleted file mode 100644 index f3885511..00000000 --- a/packages/framework/.idea/runConfigurations/encoding_in_streaming_test_dart.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/handle_error_dart.xml b/packages/framework/.idea/runConfigurations/handle_error_dart.xml deleted file mode 100644 index 5df40720..00000000 --- a/packages/framework/.idea/runConfigurations/handle_error_dart.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/injects_header_or_throws_in_parameter_meta_test_dart.xml b/packages/framework/.idea/runConfigurations/injects_header_or_throws_in_parameter_meta_test_dart.xml deleted file mode 100644 index 92114127..00000000 --- a/packages/framework/.idea/runConfigurations/injects_header_or_throws_in_parameter_meta_test_dart.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/injects_session_or_throws_in_parameter_meta_test_dart.xml b/packages/framework/.idea/runConfigurations/injects_session_or_throws_in_parameter_meta_test_dart.xml deleted file mode 100644 index 17a6c854..00000000 --- a/packages/framework/.idea/runConfigurations/injects_session_or_throws_in_parameter_meta_test_dart.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/json_dart.xml b/packages/framework/.idea/runConfigurations/json_dart.xml deleted file mode 100644 index 0c6db2aa..00000000 --- a/packages/framework/.idea/runConfigurations/json_dart.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/main_dart.xml b/packages/framework/.idea/runConfigurations/main_dart.xml deleted file mode 100644 index 750f7262..00000000 --- a/packages/framework/.idea/runConfigurations/main_dart.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/metadata_in_hooked_test_dart.xml b/packages/framework/.idea/runConfigurations/metadata_in_hooked_test_dart.xml deleted file mode 100644 index 618cdc73..00000000 --- a/packages/framework/.idea/runConfigurations/metadata_in_hooked_test_dart.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/only_match_route_with_matching_method_in_routing_test_dart.xml b/packages/framework/.idea/runConfigurations/only_match_route_with_matching_method_in_routing_test_dart.xml deleted file mode 100644 index f030feb7..00000000 --- a/packages/framework/.idea/runConfigurations/only_match_route_with_matching_method_in_routing_test_dart.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/performance__hello__DEV_.xml b/packages/framework/.idea/runConfigurations/performance__hello__DEV_.xml deleted file mode 100644 index 1925a88c..00000000 --- a/packages/framework/.idea/runConfigurations/performance__hello__DEV_.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/performance__hello__PRODUCTION_.xml b/packages/framework/.idea/runConfigurations/performance__hello__PRODUCTION_.xml deleted file mode 100644 index 56888d49..00000000 --- a/packages/framework/.idea/runConfigurations/performance__hello__PRODUCTION_.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/performance__hello__raw.xml b/packages/framework/.idea/runConfigurations/performance__hello__raw.xml deleted file mode 100644 index a13c2280..00000000 --- a/packages/framework/.idea/runConfigurations/performance__hello__raw.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/tests_in_find_one_test_dart.xml b/packages/framework/.idea/runConfigurations/tests_in_find_one_test_dart.xml deleted file mode 100644 index ad42b586..00000000 --- a/packages/framework/.idea/runConfigurations/tests_in_find_one_test_dart.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/tests_in_framework.xml b/packages/framework/.idea/runConfigurations/tests_in_framework.xml deleted file mode 100644 index 4278d0e6..00000000 --- a/packages/framework/.idea/runConfigurations/tests_in_framework.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/tests_in_framework__PRODUCTION_.xml b/packages/framework/.idea/runConfigurations/tests_in_framework__PRODUCTION_.xml deleted file mode 100644 index 263eac1e..00000000 --- a/packages/framework/.idea/runConfigurations/tests_in_framework__PRODUCTION_.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/tests_in_server_test_dart__PRODUCTION_.xml b/packages/framework/.idea/runConfigurations/tests_in_server_test_dart__PRODUCTION_.xml deleted file mode 100644 index 06ec9c23..00000000 --- a/packages/framework/.idea/runConfigurations/tests_in_server_test_dart__PRODUCTION_.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - \ No newline at end of file diff --git a/packages/framework/.idea/runConfigurations/view_dart.xml b/packages/framework/.idea/runConfigurations/view_dart.xml deleted file mode 100644 index de62a90c..00000000 --- a/packages/framework/.idea/runConfigurations/view_dart.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/framework/.idea/vcs.xml b/packages/framework/.idea/vcs.xml deleted file mode 100644 index 94a25f7f..00000000 --- a/packages/framework/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/packages/framework/.idea/workspace.xml b/packages/framework/.idea/workspace.xml deleted file mode 100644 index 4109bc84..00000000 --- a/packages/framework/.idea/workspace.xml +++ /dev/null @@ -1,1616 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - handleRe - get container - Parameter - log - mirrors - dart:mirror - dart:io - _Par - waterfall - wtf - errorHan - nested - _parent = - headers['content - skip - Provi - contentTy - abc - /chained - flatten - sendRe - enableB - Hooks - Middleware - /meta - complet - parseI - read( - as - serviceP - - - FutureOr - var body = await getBody(rs); - - = - { - 'accept' - 'content-type' - 403 - (RequestContext req, res) - headers: headers.cast<String, String>(), - this. - 'text/html' - 'application/json' - as $1 - as Map$1 - IsInstanceOf - [Iterable] - _foldStringDynamic(result) - Angel(MirrorsReflector()) - json.encode - Angel(reflector: M - dart:convert - dart:io - json.decode - rawRequest. - rawResponse. - )); - req - req.container - close() - - - C:\Users\thosa\Source\Angel\framework\lib - C:\Users\thosa\Source\Angel\framework\lib\src\http - C:\Users\thosa\Source\Angel\framework\test - $PROJECT_DIR$/lib/src - $PROJECT_DIR$/lib - $PROJECT_DIR$/test - $PROJECT_DIR$ - $PROJECT_DIR$/lib/src/core - - - - - - - - - - - - true - DEFINITION_ORDER - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - project - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1481236071442 - - - 1534732811445 - - - 1534732848038 - - - 1534732927698 - - - 1534733134792 - - - 1534733155846 - - - 1534733208240 - - - 1534733242302 - - - 1534733436519 - - - 1534733754509 - - - 1534733780470 - - - 1534734389546 - - - 1534735099537 - - - 1534735212786 - - - 1534735654118 - - - 1534735707304 - - - 1534735919739 - - - 1534736377619 - - - 1534736459394 - - - 1534736798816 - - - 1534737069329 - - - 1534738194991 - - - 1534738209023 - - - 1534794125343 - - - 1534794207777 - - - 1534794372882 - - - 1534794629985 - - - 1534794764995 - - - 1534794944288 - - - 1534795218407 - - - 1534796466854 - - - 1534797818435 - - - 1534798410411 - - - 1534798717707 - - - 1534812824990 - - - 1534813505067 - - - 1534813932227 - - - 1534814859355 - - - 1534815148128 - - - 1534815933898 - - - 1534816646962 - - - 1534819472503 - - - 1534861361523 - - - 1534861733989 - - - 1534877443455 - - - 1534877529522 - - - 1536696871863 - - - 1536697507787 - - - 1536698069495 - - - 1536698423774 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - No facets are configured - - - - - - - - jquery - - - - - - - - 1.8 - - - - - - - - framework - - - - - - - - Dart SDK - - - - - - - - \ No newline at end of file diff --git a/packages/framework/CHANGELOG.md b/packages/framework/CHANGELOG.md index ec19e706..57e594d2 100644 --- a/packages/framework/CHANGELOG.md +++ b/packages/framework/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## 4.1.1 + +* Updated link to `Angel3` home page +* Fixed pedantic warnings + ## 4.1.0 * Replaced `http_server` with `belatuk_http_server` diff --git a/packages/framework/README.md b/packages/framework/README.md index 034a8515..9f8fdd26 100644 --- a/packages/framework/README.md +++ b/packages/framework/README.md @@ -1,15 +1,14 @@ # Angel3 Framework -[![version](https://img.shields.io/badge/pub-v4.1.0-brightgreen)](https://pub.dartlang.org/packages/angel3_framework) +[![version](https://img.shields.io/badge/pub-v4.1.1-brightgreen)](https://pub.dartlang.org/packages/angel3_framework) [![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety) [![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion) [![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/framework/LICENSE) -A high-powered HTTP server with support for dependency injection, sophisticated routing and more. +A high-powered HTTP server with support for dependency injection, sophisticated routing and more. Angel3 is designed to keep the core minimal but extensible. Angel3 won't dictate which database or web templating engine to use. Everything is customizable, so that Angel3 can grow to support your application as your use cases increases in complexity. -This is the core of the [Angel3](https://github.com/dukefirehawk/angel/tree/angel3) framework. -To build real-world applications, please see the [homepage](https://angel-dart.dev). +This is the core of the [Angel3](https://github.com/dukefirehawk/angel/tree/angel3) framework. To build real-world applications, please see the [User Guide](https://angel3-docs.dukefirehawk.com). ```dart import 'package:angel3_container/mirrors.dart'; @@ -19,7 +18,7 @@ void main() async { var app = Angel(reflector: MirrorsReflector()); // Index route. Returns JSON. - app.get('/', (req, res) => res.write('Welcome to Angel!')); + app.get('/', (req, res) => res.write('Welcome to Angel3!')); // Accepts a URL like /greet/foo or /greet/bob. app.get( diff --git a/packages/framework/TODO.md b/packages/framework/TODO.md index ab388e20..bdb4dbef 100644 --- a/packages/framework/TODO.md +++ b/packages/framework/TODO.md @@ -1,8 +1,8 @@ -* Migrate http_server to shelf +# TO DO + +* Remove dependency on http_server * Support for [Trestle](https://github.com/dart-bridge/trestle), use this as default, set up migration system around this * Angel CLI * Angel bootstrap project * More docs * Make tutorials, videos -* Launch! -* Get a nice launch process, so we can pre-compile things before running. Also support a sort of hot-reload diff --git a/packages/framework/example/controller.dart b/packages/framework/example/controller.dart index d4de54d6..7cebbbb4 100644 --- a/packages/framework/example/controller.dart +++ b/packages/framework/example/controller.dart @@ -37,7 +37,7 @@ class ArtistsController extends Controller { } @Expose.post - form(RequestContext req) async { + Future form(RequestContext req) async { // Deserialize the body into an artist. var artist = await req.deserializeBody((m) { return Artist(name: m!['name'] as String? ?? '(unknown name)'); diff --git a/packages/framework/example/http2/body_parsing.dart b/packages/framework/example/http2/body_parsing.dart index 92bb9a25..bdb5052b 100644 --- a/packages/framework/example/http2/body_parsing.dart +++ b/packages/framework/example/http2/body_parsing.dart @@ -41,6 +41,6 @@ void main() async { // HTTP/1.x requests will fallback to `AngelHttp` http2.onHttp1.listen(http1.handleRequest); - SecureServerSocket server = await http2.startServer('127.0.0.1', 3000); + var server = await http2.startServer('127.0.0.1', 3000); print('Listening at https://${server.address.address}:${server.port}'); } diff --git a/packages/framework/example/http2/pretty_logging.dart b/packages/framework/example/http2/pretty_logging.dart deleted file mode 100644 index 14f55e3f..00000000 --- a/packages/framework/example/http2/pretty_logging.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:logging/logging.dart'; - -/// Prints the contents of a [LogRecord] with pretty colors. -void prettyLog(LogRecord record) { - print(record.toString()); - - if (record.error != null) print(record.error.toString()); - if (record.stackTrace != null) print(record.stackTrace.toString()); -} diff --git a/packages/framework/example/http2/server_push.dart b/packages/framework/example/http2/server_push.dart index e73c862d..4123e7b6 100644 --- a/packages/framework/example/http2/server_push.dart +++ b/packages/framework/example/http2/server_push.dart @@ -57,6 +57,6 @@ void main() async { // HTTP/1.x requests will fallback to `AngelHttp` http2.onHttp1.listen(http1.handleRequest); - SecureServerSocket server = await http2.startServer('127.0.0.1', 3000); + var server = await http2.startServer('127.0.0.1', 3000); print('Listening at https://${server.address.address}:${server.port}'); } diff --git a/packages/framework/example/json.dart b/packages/framework/example/json.dart index 4a820273..4ca5767a 100644 --- a/packages/framework/example/json.dart +++ b/packages/framework/example/json.dart @@ -5,10 +5,10 @@ import 'package:angel3_framework/angel3_framework.dart'; import 'package:angel3_framework/http.dart'; void main() async { - int x = 0; + var x = 0; var c = Completer(); var exit = ReceivePort(); - List isolates = []; + var isolates = []; exit.listen((_) { if (++x >= 50) { @@ -16,7 +16,7 @@ void main() async { } }); - for (int i = 1; i < Platform.numberOfProcessors; i++) { + for (var i = 1; i < Platform.numberOfProcessors; i++) { var isolate = await Isolate.spawn(serverMain, null); isolates.add(isolate); print('Spawned isolate #${i + 1}...'); @@ -30,16 +30,16 @@ void main() async { await c.future; } -serverMain(_) async { +void serverMain(_) async { var app = Angel(); var http = AngelHttp.custom(app, startShared, useZone: false); // Run a cluster app.get('/', (req, res) { return res.serialize({ - "foo": "bar", - "one": [2, "three"], - "bar": {"baz": "quux"} + 'foo': 'bar', + 'one': [2, 'three'], + 'bar': {'baz': 'quux'} }); }); @@ -48,6 +48,6 @@ serverMain(_) async { print(e.stackTrace); }; - HttpServer server = await http.startServer('127.0.0.1', 3000); + var server = await http.startServer('127.0.0.1', 3000); print('Listening at http://${server.address.address}:${server.port}'); } diff --git a/packages/framework/example/main.dart b/packages/framework/example/main.dart index a2a382ef..f0f7f3e2 100644 --- a/packages/framework/example/main.dart +++ b/packages/framework/example/main.dart @@ -49,7 +49,7 @@ void main() async { }); var http = AngelHttp(app); - HttpServer server = await http.startServer('127.0.0.1', 3000); + var server = await http.startServer('127.0.0.1', 3000); var url = 'http://${server.address.address}:${server.port}'; print('Listening at $url'); print('Visit these pages to see Angel in action:'); diff --git a/packages/framework/example/view.dart b/packages/framework/example/view.dart index 8502c4b6..dfac7d06 100644 --- a/packages/framework/example/view.dart +++ b/packages/framework/example/view.dart @@ -14,7 +14,7 @@ void main() async { app.get('/', (req, res) => res.render('index', {'foo': 'bar'})); var http = AngelHttp(app); - HttpServer server = await http.startServer('127.0.0.1', 3000); + var server = await http.startServer('127.0.0.1', 3000); var url = 'http://${server.address.address}:${server.port}'; print('Listening at $url'); } diff --git a/packages/framework/lib/src/core/anonymous_service.dart b/packages/framework/lib/src/core/anonymous_service.dart index a4c9e471..6c6c3ef1 100644 --- a/packages/framework/lib/src/core/anonymous_service.dart +++ b/packages/framework/lib/src/core/anonymous_service.dart @@ -33,30 +33,32 @@ class AnonymousService extends Service { } @override - index([Map? params]) => + Future> index([Map? params]) => Future.sync(() => _index != null ? _index!(params) : super.index(params)); @override - read(Id id, [Map? params]) => Future.sync( + Future read(Id id, [Map? params]) => Future.sync( () => _read != null ? _read!(id, params) : super.read(id, params)); @override - create(Data data, [Map? params]) => Future.sync(() => - _create != null ? _create!(data, params) : super.create(data, params)); + Future create(Data data, [Map? params]) => + Future.sync(() => _create != null + ? _create!(data, params) + : super.create(data, params)); @override - modify(Id id, Data data, [Map? params]) => + Future modify(Id id, Data data, [Map? params]) => Future.sync(() => _modify != null ? _modify!(id, data, params) : super.modify(id, data, params)); @override - update(Id id, Data data, [Map? params]) => + Future update(Id id, Data data, [Map? params]) => Future.sync(() => _update != null ? _update!(id, data, params) : super.update(id, data, params)); @override - remove(Id id, [Map? params]) => Future.sync( + Future remove(Id id, [Map? params]) => Future.sync( () => _remove != null ? _remove!(id, params) : super.remove(id, params)); } diff --git a/packages/framework/lib/src/core/controller.dart b/packages/framework/lib/src/core/controller.dart index fd29b0de..62cdcc46 100644 --- a/packages/framework/lib/src/core/controller.dart +++ b/packages/framework/lib/src/core/controller.dart @@ -51,10 +51,10 @@ class Controller { Router router, Reflector reflector) async { // Load global expose decl var classMirror = reflector.reflectClass(runtimeType)!; - Expose? exposeDecl = findExpose(reflector); + var exposeDecl = findExpose(reflector); if (exposeDecl == null) { - throw Exception("All controllers must carry an @Expose() declaration."); + throw Exception('All controllers must carry an @Expose() declaration.'); } var routable = Routable(); @@ -64,9 +64,7 @@ class Controller { // Pre-reflect methods var instanceMirror = reflector.reflectInstance(this); - final handlers = [] - ..addAll(exposeDecl.middleware!) - ..addAll(middleware); + final handlers = [...exposeDecl.middleware!, ...middleware]; final routeBuilder = _routeBuilder(reflector, instanceMirror, routable, handlers); await configureRoutes(routable); @@ -109,10 +107,11 @@ class Controller { var reflectedMethod = instanceMirror!.getField(methodName).reflectee as Function?; - var middleware = [] - ..addAll(handlers) - ..addAll(exposeDecl.middleware!); - String? name = + var middleware = [ + ...handlers, + ...exposeDecl.middleware! + ]; + var name = exposeDecl.as?.isNotEmpty == true ? exposeDecl.as : methodName; // Check if normal diff --git a/packages/framework/lib/src/core/driver.dart b/packages/framework/lib/src/core/driver.dart index 37432379..c22c999b 100644 --- a/packages/framework/lib/src/core/driver.dart +++ b/packages/framework/lib/src/core/driver.dart @@ -71,8 +71,8 @@ abstract class Driver< return Future.value(_server); }); }).catchError((error) { - log.severe("Failed to create server", error); - throw ArgumentError("[Driver]Failed to create server"); + log.severe('Failed to create server', error); + throw ArgumentError('[Driver]Failed to create server'); }); } @@ -125,7 +125,7 @@ abstract class Driver< Future handleRawRequest(Request request, Response response) { return createRequestContext(request, response).then((req) { return createResponseContext(request, response, req).then((res) { - handle() { + Future handle() { var path = req.path; if (path == '/') path = ''; @@ -334,7 +334,7 @@ abstract class Driver< if (!res.isBuffered) return res.close().then(_cleanup); - Future finalizers = ignoreFinalizers == true + var finalizers = ignoreFinalizers == true ? Future.value() : Future.forEach(app.responseFinalizers, (dynamic f) => f(req, res)); @@ -366,7 +366,7 @@ abstract class Driver< if (allowedEncodings != null) { for (var encodingName in allowedEncodings) { Converter, List>? encoder; - String key = encodingName; + var key = encodingName; if (res.encoders.containsKey(encodingName)) { encoder = res.encoders[encodingName]; diff --git a/packages/framework/lib/src/core/hooked_service.dart b/packages/framework/lib/src/core/hooked_service.dart index cb21e815..9b70723a 100644 --- a/packages/framework/lib/src/core/hooked_service.dart +++ b/packages/framework/lib/src/core/hooked_service.dart @@ -96,7 +96,8 @@ class HookedService> /// Adds hooks to this instance. void addHooks(Angel app) { var hooks = getAnnotation(inner, app.container!.reflector); - List> before = [], after = []; + var before = >[]; + var after = >[]; if (hooks != null) { before.addAll(hooks.before.cast()); @@ -106,9 +107,10 @@ class HookedService> void applyListeners( Function fn, HookedServiceEventDispatcher dispatcher, [bool? isAfter]) { - Hooks? hooks = getAnnotation(fn, app.container!.reflector); - final listeners = >[] - ..addAll(isAfter == true ? after : before); + var hooks = getAnnotation(fn, app.container!.reflector); + final listeners = >[ + ...isAfter == true ? after : before + ]; if (hooks != null) { listeners.addAll((isAfter == true ? hooks.after : hooks.before).cast()); diff --git a/packages/framework/lib/src/core/hostname_parser.dart b/packages/framework/lib/src/core/hostname_parser.dart index 8394b671..627e2397 100644 --- a/packages/framework/lib/src/core/hostname_parser.dart +++ b/packages/framework/lib/src/core/hostname_parser.dart @@ -4,7 +4,7 @@ import 'package:string_scanner/string_scanner.dart'; /// Parses a string into a [RegExp] that is matched against hostnames. class HostnameSyntaxParser { final SpanScanner _scanner; - final _safe = RegExp(r"[0-9a-zA-Z-_:]+"); + final _safe = RegExp(r'[0-9a-zA-Z-_:]+'); HostnameSyntaxParser(String hostname) : _scanner = SpanScanner(hostname, sourceUrl: hostname); @@ -33,7 +33,7 @@ class HostnameSyntaxParser { } } } else { - String part = _parseHostnamePart(); + var part = _parseHostnamePart(); if (part.isNotEmpty) { if (_scanner.scan('.')) { var subPart = _parseHostnamePart(shouldThrow: false); @@ -70,12 +70,12 @@ class HostnameSyntaxParser { } else if (_scanner.scan('+')) { return r'[^$]+'; } else if (_scanner.scan(_safe)) { - return _scanner.lastMatch?[0] ?? ""; + return _scanner.lastMatch?[0] ?? ''; } else if (!_scanner.isDone && shouldThrow) { var s = String.fromCharCode(_scanner.peekChar()!); throw _formatExc('Unexpected character "$s".'); } else { - return ""; + return ''; } } } diff --git a/packages/framework/lib/src/core/injection.dart b/packages/framework/lib/src/core/injection.dart index d5268a01..fce2a249 100644 --- a/packages/framework/lib/src/core/injection.dart +++ b/packages/framework/lib/src/core/injection.dart @@ -12,8 +12,7 @@ RequestHandler ioc(Function handler, {Iterable optional = const []}) { RequestHandler? contained; if (req.app?.container != null) { - InjectionRequest injection = - preInject(handler, req.app!.container!.reflector); + var injection = preInject(handler, req.app!.container!.reflector); //if (injection != null) { injection.optional.addAll(optional); contained = handleContained(handler, injection); @@ -104,9 +103,9 @@ RequestHandler handleContained(Function handler, InjectionRequest injection, injection.parameters.values.any((p) => p.match != null) && !suitableForInjection(req, res, injection)) return Future.value(true); - List args = []; + var args = []; - Map named = {}; + var named = {}; for (var r in injection.required) { args.add(await resolveInjection(r, injection, req, res, true, container)); diff --git a/packages/framework/lib/src/core/metadata.dart b/packages/framework/lib/src/core/metadata.dart index f2ee7b04..4d8004ee 100644 --- a/packages/framework/lib/src/core/metadata.dart +++ b/packages/framework/lib/src/core/metadata.dart @@ -58,7 +58,7 @@ class Expose { head = Expose(null, method: 'HEAD'); const Expose(this.path, - {this.method = "GET", + {this.method = 'GET', this.middleware = const [], this.as, this.allowNull = const []}); @@ -101,7 +101,7 @@ class Parameter { this.required}); /// Returns an error that can be thrown when the parameter is not present. - get error { + Object? get error { if (cookie?.isNotEmpty == true) { return AngelHttpException.badRequest( message: 'Missing required cookie "$cookie".'); @@ -120,7 +120,7 @@ class Parameter { } /// Obtains a value for this parameter from a [RequestContext]. - getValue(RequestContext req) { + dynamic getValue(RequestContext req) { if (cookie?.isNotEmpty == true) { return req.cookies.firstWhere((c) => c.name == cookie).value; } diff --git a/packages/framework/lib/src/core/request_context.dart b/packages/framework/lib/src/core/request_context.dart index c9b0f5ad..520df530 100644 --- a/packages/framework/lib/src/core/request_context.dart +++ b/packages/framework/lib/src/core/request_context.dart @@ -31,7 +31,7 @@ part 'injection.dart'; abstract class RequestContext { /// Similar to [Angel.shutdownHooks], allows for logic to be executed /// when a [RequestContext] is done being processed. - final log = Logger('RequestContext'); + final _log = Logger('RequestContext'); final List Function()> shutdownHooks = []; @@ -43,7 +43,7 @@ abstract class RequestContext { Map _bodyFields = {}; List _bodyList = []; List _uploadedFiles = []; - MediaType _contentType = MediaType("text", "plain"); + MediaType _contentType = MediaType('text', 'plain'); /// The underlying [RawRequest] provided by the driver. RawRequest get rawRequest; @@ -86,7 +86,7 @@ abstract class RequestContext { try { _contentType = MediaType.parse(headers!.contentType.toString()); } catch (e) { - log.warning( + _log.warning( 'Invalid media type [${headers!.contentType.toString()}]', e); } } @@ -101,7 +101,7 @@ abstract class RequestContext { /// Is this an **XMLHttpRequest**? bool get isXhr { - return headers?.value("X-Requested-With")?.trim().toLowerCase() == + return headers?.value('X-Requested-With')?.trim().toLowerCase() == 'xmlhttprequest'; } @@ -221,6 +221,7 @@ abstract class RequestContext { // Change to assert if (contentTypeString == null) { + _log.severe('RequestContext.accepts is null'); throw ArgumentError( 'RequestContext.accepts expects the `contentType` parameter to NOT be null.'); } @@ -259,9 +260,7 @@ abstract class RequestContext { if (!_hasParsedBody) { _hasParsedBody = true; - var contentBody = body; - //TODO: Relook at this - contentBody ??= Stream.empty(); + var contentBody = body ?? Stream.empty(); if (contentType.type == 'application' && contentType.subtype == 'json') { _uploadedFiles = []; @@ -332,7 +331,7 @@ class UploadedFile { final HttpMultipartFormData formData; final log = Logger('UploadedFile'); - MediaType _contentType = MediaType("multipart", "form-data"); + MediaType _contentType = MediaType('multipart', 'form-data'); UploadedFile(this.formData); diff --git a/packages/framework/lib/src/core/response_context.dart b/packages/framework/lib/src/core/response_context.dart index 1c7ff9a3..850c3037 100644 --- a/packages/framework/lib/src/core/response_context.dart +++ b/packages/framework/lib/src/core/response_context.dart @@ -146,7 +146,7 @@ abstract class ResponseContext Future download(File file, {String? filename}) async { if (!isOpen) throw closed(); - headers["Content-Disposition"] = + headers['Content-Disposition'] = 'attachment; filename="${filename ?? file.path}"'; contentType = MediaType.parse(lookupMimeType(file.path)!); headers['content-length'] = file.lengthSync().toString(); @@ -179,10 +179,10 @@ abstract class ResponseContext /// /// You can override the [contentType] sent; by default it is `application/javascript`. Future jsonp(value, - {String callbackName = "callback", MediaType? contentType}) { + {String callbackName = 'callback', MediaType? contentType}) { if (!isOpen) throw closed(); this.contentType = contentType ?? MediaType('application', 'javascript'); - write("$callbackName(${serializer(value)})"); + write('$callbackName(${serializer(value)})'); return close(); } @@ -238,7 +238,7 @@ abstract class ResponseContext Future redirectTo(String name, [Map? params, int? code]) async { if (!isOpen) throw closed(); Route? _findRoute(Router r) { - for (Route route in r.routes) { + for (var route in r.routes) { if (route is SymlinkRoute) { final m = _findRoute(route.router); @@ -249,7 +249,7 @@ abstract class ResponseContext return null; } - Route? matched = _findRoute(app!); + var matched = _findRoute(app!); if (matched != null) { await redirect( @@ -267,21 +267,20 @@ abstract class ResponseContext Future redirectToAction(String action, [Map? params, int? code]) { if (!isOpen) throw closed(); // UserController@show - List split = action.split("@"); + var split = action.split('@'); if (split.length < 2) { throw Exception( "Controller redirects must take the form of 'Controller@action'. You gave: $action"); } - Controller? controller = - app!.controllers[split[0].replaceAll(_straySlashes, '')]; + var controller = app!.controllers[split[0].replaceAll(_straySlashes, '')]; if (controller == null) { throw Exception("Could not find a controller named '${split[0]}'"); } - Route? matched = controller.routeMappings[split[1]]; + var matched = controller.routeMappings[split[1]]; if (matched == null) { throw Exception( @@ -293,7 +292,7 @@ abstract class ResponseContext .path .toString() .replaceAll(_straySlashes, ''); - String tail = ""; + var tail = ''; if (params != null) { tail = matched .makeUri(params.keys.fold>({}, (out, k) { @@ -349,7 +348,7 @@ abstract class ResponseContext if (stackTrace != null) { Zone.current.handleUncaughtError(error, stackTrace); } else { - log.warning("[ResponseContext] stackTrace is null"); + log.warning('[ResponseContext] stackTrace is null'); } } } @@ -380,13 +379,13 @@ abstract class ResponseContext } @override - void writeln([Object? obj = ""]) { + void writeln([Object? obj = '']) { write(obj.toString()); write('\r\n'); } @override - void writeAll(Iterable objects, [String separator = ""]) { + void writeAll(Iterable objects, [String separator = '']) { write(objects.join(separator)); } } diff --git a/packages/framework/lib/src/core/routable.dart b/packages/framework/lib/src/core/routable.dart index d4e9f72a..67e83925 100644 --- a/packages/framework/lib/src/core/routable.dart +++ b/packages/framework/lib/src/core/routable.dart @@ -101,7 +101,7 @@ class Routable extends Router { // Merge @Middleware declaration, if any var reflector = _container?.reflector; if (reflector != null && reflector is! ThrowingReflector) { - Middleware? middlewareDeclaration = + var middlewareDeclaration = getAnnotation(handler, _container?.reflector); if (middlewareDeclaration != null) { handlers.addAll(middlewareDeclaration.handlers); diff --git a/packages/framework/lib/src/core/server.dart b/packages/framework/lib/src/core/server.dart index 63f633f0..7fc9d592 100644 --- a/packages/framework/lib/src/core/server.dart +++ b/packages/framework/lib/src/core/server.dart @@ -137,14 +137,14 @@ class Angel extends Routable { res.contentType = MediaType('text', 'html', {'charset': 'utf8'}); res.statusCode = e.statusCode; // ?? 200; - res.write("${e.message}"); - res.write("

${e.message}

    "); + res.write('${e.message}'); + res.write('

    ${e.message}

      '); - for (String error in e.errors) { - res.write("
    • $error
    • "); + for (var error in e.errors) { + res.write('
    • $error
    • '); } - res.write("
    "); + res.write('
'); res.close(); }; @@ -164,7 +164,8 @@ class Angel extends Routable { } @override - mount(String path, Router router) { + SymlinkRoute mount( + String path, Router router) { if (_flattened != null) { logger?.warning( 'WARNING: You added mounted a child router ($path) on the router, after it had been optimized.'); @@ -284,7 +285,7 @@ class Angel extends Routable { } /// Attempts to find a property by the given name within this application. - findProperty(key) { + dynamic findProperty(key) { if (configuration.containsKey(key)) return configuration[key]; return parent != null ? parent?.findProperty(key) : null; @@ -344,7 +345,7 @@ class Angel extends Routable { /// /// If you are on `Dart >=2.0.0`, simply call `mountController()`. Future mountController([Type? type]) { - T controller = container!.make(type)!; + var controller = container!.make(type)!; return configure(controller.configureServer).then((_) => controller); } diff --git a/packages/framework/lib/src/core/service.dart b/packages/framework/lib/src/core/service.dart index f61edd87..f8993a94 100644 --- a/packages/framework/lib/src/core/service.dart +++ b/packages/framework/lib/src/core/service.dart @@ -23,9 +23,9 @@ class Providers { const Providers(this.via); - static const String viaRest = "rest"; - static const String viaWebsocket = "websocket"; - static const String viaGraphQL = "graphql"; + static const String viaRest = 'rest'; + static const String viaWebsocket = 'websocket'; + static const String viaGraphQL = 'graphql'; /// Represents a request via REST. static const Providers rest = Providers(viaRest); @@ -162,7 +162,7 @@ class Service extends Routable { Service map(U Function(Data) encoder, Data Function(U) decoder, {FutureOr Function(RequestContext, ResponseContext)? readData}) { readData ??= (req, res) async { - Data inner = await this.readData!(req, res)!; + var inner = await this.readData!(req, res)!; return encoder(inner); }; @@ -223,12 +223,11 @@ class Service extends Routable { var handlers = List.from(handlerss); // Add global middleware if declared on the instance itself - Middleware? before = - getAnnotation(service, app!.container!.reflector); + var before = getAnnotation(service, app!.container!.reflector); if (before != null) handlers.addAll(before.handlers); - Middleware? indexMiddleware = + var indexMiddleware = getAnnotation(service.index, app!.container!.reflector); get('/', (req, res) { return index(mergeMap([ @@ -236,14 +235,12 @@ class Service extends Routable { restProvider, req.serviceParams ])); - }, - middleware: [] - ..addAll(handlers) - ..addAll((indexMiddleware == null) - ? [] - : indexMiddleware.handlers.toList())); + }, middleware: [ + ...handlers, + ...(indexMiddleware == null) ? [] : indexMiddleware.handlers.toList() + ]); - Middleware? createMiddleware = + var createMiddleware = getAnnotation(service.create, app!.container!.reflector); post('/', (req, ResponseContext res) { return req.parseBody().then((_) async { @@ -258,14 +255,12 @@ class Service extends Routable { return r; }); }); - }, - middleware: [] - ..addAll(handlers) - ..addAll((createMiddleware == null) - ? [] - : createMiddleware.handlers.toList())); + }, middleware: [ + ...handlers, + ...(createMiddleware == null) ? [] : createMiddleware.handlers.toList() + ]); - Middleware? readMiddleware = + var readMiddleware = getAnnotation(service.read, app!.container!.reflector); get('/:id', (req, res) { @@ -276,14 +271,12 @@ class Service extends Routable { restProvider, req.serviceParams ])); - }, - middleware: [] - ..addAll(handlers) - ..addAll((readMiddleware == null) - ? [] - : readMiddleware.handlers.toList())); + }, middleware: [ + ...handlers, + ...(readMiddleware == null) ? [] : readMiddleware.handlers.toList() + ]); - Middleware? modifyMiddleware = + var modifyMiddleware = getAnnotation(service.modify, app!.container!.reflector); patch('/:id', (req, res) { @@ -297,14 +290,12 @@ class Service extends Routable { req.serviceParams ])); }); - }, - middleware: [] - ..addAll(handlers) - ..addAll((modifyMiddleware == null) - ? [] - : modifyMiddleware.handlers.toList())); + }, middleware: [ + ...handlers, + ...(modifyMiddleware == null) ? [] : modifyMiddleware.handlers.toList() + ]); - Middleware? updateMiddleware = + var updateMiddleware = getAnnotation(service.update, app!.container!.reflector); post('/:id', (req, res) { return req.parseBody().then((_) async { @@ -317,12 +308,10 @@ class Service extends Routable { req.serviceParams ])); }); - }, - middleware: [] - ..addAll(handlers) - ..addAll((updateMiddleware == null) - ? [] - : updateMiddleware.handlers.toList())); + }, middleware: [ + ...handlers, + ...(updateMiddleware == null) ? [] : updateMiddleware.handlers.toList() + ]); put('/:id', (req, res) { return req.parseBody().then((_) async { @@ -335,14 +324,12 @@ class Service extends Routable { req.serviceParams ])); }); - }, - middleware: [] - ..addAll(handlers) - ..addAll((updateMiddleware == null) - ? [] - : updateMiddleware.handlers.toList())); + }, middleware: [ + ...handlers, + ...(updateMiddleware == null) ? [] : updateMiddleware.handlers.toList() + ]); - Middleware? removeMiddleware = + var removeMiddleware = getAnnotation(service.remove, app!.container!.reflector); delete('/', (req, res) { return remove( @@ -352,12 +339,10 @@ class Service extends Routable { restProvider, req.serviceParams ])); - }, - middleware: [] - ..addAll(handlers) - ..addAll((removeMiddleware == null) - ? [] - : removeMiddleware.handlers.toList())); + }, middleware: [ + ...handlers, + ...(removeMiddleware == null) ? [] : removeMiddleware.handlers.toList() + ]); delete('/:id', (req, res) { return remove( @@ -367,12 +352,10 @@ class Service extends Routable { restProvider, req.serviceParams ])); - }, - middleware: [] - ..addAll(handlers) - ..addAll((removeMiddleware == null) - ? [] - : removeMiddleware.handlers.toList())); + }, middleware: [ + ...handlers, + ...(removeMiddleware == null) ? [] : removeMiddleware.handlers.toList() + ]); // REST compliance put('/', (req, res) => throw AngelHttpException.notFound()); diff --git a/packages/framework/lib/src/fast_name_from_symbol.dart b/packages/framework/lib/src/fast_name_from_symbol.dart index adca8e9b..6005ff15 100644 --- a/packages/framework/lib/src/fast_name_from_symbol.dart +++ b/packages/framework/lib/src/fast_name_from_symbol.dart @@ -2,9 +2,9 @@ final Map _cache = {}; String fastNameFromSymbol(Symbol s) { return _cache.putIfAbsent(s, () { - String str = s.toString(); - int open = str.indexOf('"'); - int close = str.lastIndexOf('"'); + var str = s.toString(); + var open = str.indexOf('"'); + var close = str.lastIndexOf('"'); return str.substring(open + 1, close); }); } diff --git a/packages/framework/lib/src/http/angel_http.dart b/packages/framework/lib/src/http/angel_http.dart index 3561aa30..a43c85fc 100644 --- a/packages/framework/lib/src/http/angel_http.dart +++ b/packages/framework/lib/src/http/angel_http.dart @@ -104,8 +104,7 @@ class AngelHttp extends Driver.value(context); diff --git a/packages/framework/lib/src/http/http_request_context.dart b/packages/framework/lib/src/http/http_request_context.dart index 63cf7691..63edaaeb 100644 --- a/packages/framework/lib/src/http/http_request_context.dart +++ b/packages/framework/lib/src/http/http_request_context.dart @@ -9,7 +9,7 @@ import '../core/core.dart'; /// An implementation of [RequestContext] that wraps a [HttpRequest]. class HttpRequestContext extends RequestContext { Container? _container; - MediaType _contentType = MediaType("text", "plain"); + MediaType _contentType = MediaType('text', 'plain'); HttpRequest? _io; String? _override; String _path = ''; @@ -34,7 +34,7 @@ class HttpRequestContext extends RequestContext { @override String get hostname { - return rawRequest?.headers.value('host') ?? "localhost"; + return rawRequest?.headers.value('host') ?? 'localhost'; } /// The underlying [HttpRequest] instance underneath this context. @@ -77,10 +77,9 @@ class HttpRequestContext extends RequestContext { /// Magically transforms an [HttpRequest] into a [RequestContext]. static Future from( HttpRequest request, Angel app, String path) { - HttpRequestContext ctx = HttpRequestContext() - .._container = app.container!.createChild(); + var ctx = HttpRequestContext().._container = app.container!.createChild(); - String override = request.method; + var override = request.method; if (app.allowMethodOverrides == true) { override = @@ -90,7 +89,7 @@ class HttpRequestContext extends RequestContext { ctx.app = app; ctx._contentType = request.headers.contentType == null - ? MediaType("text", "plain") + ? MediaType('text', 'plain') : MediaType.parse(request.headers.contentType.toString()); ctx._override = override; diff --git a/packages/framework/lib/src/http/http_response_context.dart b/packages/framework/lib/src/http/http_response_context.dart index a830c369..4f6602ac 100644 --- a/packages/framework/lib/src/http/http_response_context.dart +++ b/packages/framework/lib/src/http/http_response_context.dart @@ -104,7 +104,7 @@ class HttpResponseContext extends ResponseContext { if (_allowedEncodings != null) { for (var encodingName in _allowedEncodings!) { Converter, List>? encoder; - String key = encodingName; + var key = encodingName; if (encoders.containsKey(encodingName)) { encoder = encoders[encodingName]; @@ -132,13 +132,13 @@ class HttpResponseContext extends ResponseContext { if (_isClosed && isBuffered) throw ResponseContext.closed(); _openStream(); - Stream> output = stream; + var output = stream; if (encoders.isNotEmpty && correspondingRequest != null) { if (_allowedEncodings != null) { for (var encodingName in _allowedEncodings!) { Converter, List>? encoder; - String key = encodingName; + var key = encodingName; if (encoders.containsKey(encodingName)) { encoder = encoders[encodingName]; @@ -169,7 +169,7 @@ class HttpResponseContext extends ResponseContext { if (_allowedEncodings != null) { for (var encodingName in _allowedEncodings!) { Converter, List>? encoder; - String key = encodingName; + var key = encodingName; if (encoders.containsKey(encodingName)) { encoder = encoders[encodingName]; diff --git a/packages/framework/lib/src/http2/angel_http2.dart b/packages/framework/lib/src/http2/angel_http2.dart index caa4f551..30c79b35 100644 --- a/packages/framework/lib/src/http2/angel_http2.dart +++ b/packages/framework/lib/src/http2/angel_http2.dart @@ -55,8 +55,9 @@ class AngelHttp2 extends Driver serverGenerator( - address, int port, SecurityContext ctx), + Future Function( + InternetAddress? address, int port, SecurityContext ctx) + serverGenerator, {bool useZone = true, bool allowHttp1 = false, ServerSettings? settings}) { @@ -73,8 +74,7 @@ class AngelHttp2 extends Driver generateServer([address, int? port]) async { - SecureServerSocket s = - await serverGenerator(address ?? '127.0.0.1', port ?? 0); + var s = await serverGenerator(address ?? '127.0.0.1', port ?? 0); return _artificial = _AngelHttp2ServerSocket(s, this); } diff --git a/packages/framework/lib/src/http2/http2_response_context.dart b/packages/framework/lib/src/http2/http2_response_context.dart index 48daed21..7c1370d7 100644 --- a/packages/framework/lib/src/http2/http2_response_context.dart +++ b/packages/framework/lib/src/http2/http2_response_context.dart @@ -82,7 +82,7 @@ class Http2ResponseContext extends ResponseContext { if (_allowedEncodings != null) { for (var encodingName in _allowedEncodings!) { Converter, List>? encoder; - String key = encodingName; + var key = encodingName; if (encoders.containsKey(encodingName)) { encoder = encoders[encodingName]; @@ -136,13 +136,13 @@ class Http2ResponseContext extends ResponseContext { if (!isOpen && isBuffered) throw ResponseContext.closed(); _openStream(); - Stream> output = stream; + var output = stream; if (encoders.isNotEmpty && correspondingRequest != null) { if (_allowedEncodings != null) { for (var encodingName in _allowedEncodings!) { Converter, List>? encoder; - String key = encodingName; + var key = encodingName; if (encoders.containsKey(encodingName)) { encoder = encoders[encodingName]; @@ -173,7 +173,7 @@ class Http2ResponseContext extends ResponseContext { if (_allowedEncodings != null) { for (var encodingName in _allowedEncodings!) { Converter, List>? encoder; - String key = encodingName; + var key = encodingName; if (encoders.containsKey(encodingName)) { encoder = encoders[encodingName]; diff --git a/packages/framework/lib/src/util.dart b/packages/framework/lib/src/util.dart index fabd9f0f..77e22f85 100644 --- a/packages/framework/lib/src/util.dart +++ b/packages/framework/lib/src/util.dart @@ -3,7 +3,7 @@ import 'package:angel3_container/angel3_container.dart'; final RegExp straySlashes = RegExp(r'(^/+)|(/+$)'); T? matchingAnnotation(List metadata) { - for (ReflectedInstance metaDatum in metadata) { + for (var metaDatum in metadata) { if (metaDatum.type.reflectedType == T) { return metaDatum.reflectee as T?; } diff --git a/packages/framework/performance/hello/angel.md b/packages/framework/performance/hello/angel.md index e231e08c..4dc8c118 100644 --- a/packages/framework/performance/hello/angel.md +++ b/packages/framework/performance/hello/angel.md @@ -1,7 +1,9 @@ -# Angel Results +# Angel Performance Results + 5 consecutive trials run on a Windows 10 box with 4GB RAM, and several programs open in the background. Setup: + * Angel framework `1.0.8` * Running `wrk` 4.0.2.2 * 2 threads @@ -9,10 +11,11 @@ Setup: * 30 seconds Average: + * `11070.18` req/sec * `11.86` ms latency -``` +```bash tobe@LAPTOP-VBHCSVRH:/mnt/c/Users/thosa$ wrk -c 256 -d 30 -t 2 http://localhost:3000 Running 30s test @ http://localhost:3000 2 threads and 256 connections @@ -59,4 +62,4 @@ Running 30s test @ http://localhost:3000 Requests/sec: 11747.23 Transfer/sec: 2.27MB tobe@LAPTOP-VBHCSVRH:/mnt/c/Users/thosa$ -``` \ No newline at end of file +``` diff --git a/packages/framework/performance/hello/raw.dart b/packages/framework/performance/hello/raw.dart index 423ba843..ebbe2432 100644 --- a/packages/framework/performance/hello/raw.dart +++ b/packages/framework/performance/hello/raw.dart @@ -3,7 +3,7 @@ library performance.hello; import 'dart:io'; -main() { +Future main() { return HttpServer.bind('127.0.0.1', 3000, shared: true).then((server) { print('Listening at http://${server.address.address}:${server.port}'); diff --git a/packages/framework/performance/hello/raw.md b/packages/framework/performance/hello/raw.md index 0027da54..e16631ec 100644 --- a/packages/framework/performance/hello/raw.md +++ b/packages/framework/performance/hello/raw.md @@ -1,17 +1,20 @@ # `dart:io` Results + 5 consecutive trials run on a Windows 10 box with 4GB RAM, and several programs open in the background. Setup: + * Running `wrk` 4.0.2.2 * 2 threads * 256 connections * 30 seconds Average: + * `14598.16` req/sec * `8.88` ms latency -``` +```bash tobe@LAPTOP-VBHCSVRH:/mnt/c/Users/thosa$ wrk -c 256 -d 30 -t 2 http://localhost:3000 Running 30s test @ http://localhost:3000 2 threads and 256 connections @@ -57,4 +60,4 @@ Running 30s test @ http://localhost:3000 434674 requests in 30.09s, 85.39MB read Requests/sec: 14443.98 Transfer/sec: 2.84MB -``` \ No newline at end of file +``` diff --git a/packages/framework/pubspec.yaml b/packages/framework/pubspec.yaml index 76c66f94..3bb96f28 100644 --- a/packages/framework/pubspec.yaml +++ b/packages/framework/pubspec.yaml @@ -1,7 +1,8 @@ name: angel3_framework -version: 4.1.0 -description: A high-powered HTTP server with dependency injection, routing and much more. -homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/framework +version: 4.1.1 +description: A high-powered HTTP server extensible framework with dependency injection, routing and much more. +homepage: https://angel3-framework.web.app/ +repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/framework environment: sdk: '>=2.12.0 <3.0.0' dependencies: diff --git a/packages/framework/test/404_hole_test.dart b/packages/framework/test/404_hole_test.dart index cb7c7630..28bfaf5a 100644 --- a/packages/framework/test/404_hole_test.dart +++ b/packages/framework/test/404_hole_test.dart @@ -52,7 +52,7 @@ void main() { test('does not continue processing after streaming', () async { var url = driver.uri.replace(path: '/hey'); - for (int i = 0; i < 100; i++) { + for (var i = 0; i < 100; i++) { var r = await client.get(url); print('#$i: ${r.statusCode}: ${r.body}'); expect(r.statusCode, 200); diff --git a/packages/framework/test/accepts_test.dart b/packages/framework/test/accepts_test.dart index 122a3306..7f1ec930 100644 --- a/packages/framework/test/accepts_test.dart +++ b/packages/framework/test/accepts_test.dart @@ -37,7 +37,7 @@ void main() { }); test('strict', () async { - var req = await acceptContentTypes(['text/html', "*/*"]); + var req = await acceptContentTypes(['text/html', '*/*']); expect(req.accepts('text/html'), isTrue); //expect(req.accepts(ContentType.HTML), isTrue); //expect(req.accepts(ContentType.JSON, strict: true), isFalse); diff --git a/packages/framework/test/anonymous_service_test.dart b/packages/framework/test/anonymous_service_test.dart index 2deb3541..eb83e473 100644 --- a/packages/framework/test/anonymous_service_test.dart +++ b/packages/framework/test/anonymous_service_test.dart @@ -1,7 +1,7 @@ import 'package:angel3_framework/angel3_framework.dart'; import 'package:test/test.dart'; -main() { +void main() { test('custom methods', () async { var svc = AnonymousService( index: ([p]) async => ['index'], diff --git a/packages/framework/test/common.dart b/packages/framework/test/common.dart index b0de66b4..2ceecd87 100644 --- a/packages/framework/test/common.dart +++ b/packages/framework/test/common.dart @@ -19,7 +19,7 @@ class Todo extends Model { class BookService extends Service { @override - index([params]) async { + Future index([params]) async { print('Book params: $params'); return [ @@ -28,7 +28,7 @@ class BookService extends Service { } } -incrementTodoTimes(e) { +void incrementTodoTimes(e) { IncrementService.TIMES++; } @@ -38,7 +38,7 @@ class IncrementService extends Service { @override @Hooks(after: [incrementTodoTimes]) - index([params]) async => []; + Future index([params]) async => []; } class IsInstanceOf implements Matcher { diff --git a/packages/framework/test/controller_test.dart b/packages/framework/test/controller_test.dart index ae4383de..db29bce3 100644 --- a/packages/framework/test/controller_test.dart +++ b/packages/framework/test/controller_test.dart @@ -11,11 +11,11 @@ import 'package:test/test.dart'; import 'common.dart'; -@Expose("/todos", middleware: [foo]) +@Expose('/todos', middleware: [foo]) class TodoController extends Controller { - List todos = [Todo(text: "Hello", over: "world")]; + List todos = [Todo(text: 'Hello', over: 'world')]; - @Expose("/:id", middleware: [bar]) + @Expose('/:id', middleware: [bar]) Future fetchTodo( String id, RequestContext req, ResponseContext res) async { expect(req, isNotNull); @@ -23,7 +23,7 @@ class TodoController extends Controller { return todos[int.parse(id)]; } - @Expose("/namedRoute/:foo", as: "foo") + @Expose('/namedRoute/:foo', as: 'foo') Future someRandomRoute( RequestContext req, ResponseContext res) async { return "${req.params['foo']}!"; @@ -37,7 +37,7 @@ class NoExposeController extends Controller { String repeatName(String name, int times) { var b = StringBuffer(); - for (int i = 0; i < times; i++) { + for (var i = 0; i < times; i++) { b.writeln(name); } return b.toString(); @@ -56,33 +56,33 @@ class NoExposeController extends Controller { @Expose('/named', as: 'foo') class NamedController extends Controller { @Expose('/optional/:arg?', allowNull: ['arg']) - optional() => 2; + int optional() => 2; } bool foo(RequestContext req, ResponseContext res) { - res.write("Hello, "); + res.write('Hello, '); return true; } bool bar(RequestContext req, ResponseContext res) { - res.write("world!"); + res.write('world!'); return true; } -main() { +void main() { late Angel app; late TodoController todoController; late NoExposeController noExposeCtrl; late HttpServer server; - http.Client client = http.Client(); + var client = http.Client(); String? url; setUp(() async { app = Angel(reflector: MirrorsReflector()); app.get( - "/redirect", + '/redirect', (req, res) async => - res.redirectToAction("TodoController@foo", {"foo": "world"})); + res.redirectToAction('TodoController@foo', {'foo': 'world'})); // Register as a singleton, just for the purpose of this test if (!app.container!.has()) { @@ -136,36 +136,36 @@ main() { expect(app.controllers['foo'], const IsInstanceOf()); }); - test("middleware", () async { - var rgx = RegExp("^Hello, world!"); - var response = await client.get(Uri.parse("$url/todos/0")); + test('middleware', () async { + var rgx = RegExp('^Hello, world!'); + var response = await client.get(Uri.parse('$url/todos/0')); print('Response: ${response.body}'); expect(rgx.firstMatch(response.body)?.start, equals(0)); - var todo = json.decode(response.body.replaceAll(rgx, "")) as Map; - print("Todo: $todo"); - expect(todo['text'], equals("Hello")); - expect(todo['over'], equals("world")); + var todo = json.decode(response.body.replaceAll(rgx, '')) as Map; + print('Todo: $todo'); + expect(todo['text'], equals('Hello')); + expect(todo['over'], equals('world')); }); - test("controller in group", () async { - var rgx = RegExp("^Hello, world!"); - var response = await client.get(Uri.parse("$url/ctrl_group/todos/0")); + test('controller in group', () async { + var rgx = RegExp('^Hello, world!'); + var response = await client.get(Uri.parse('$url/ctrl_group/todos/0')); print('Response: ${response.body}'); expect(rgx.firstMatch(response.body)?.start, equals(0)); - var todo = json.decode(response.body.replaceAll(rgx, "")) as Map; - print("Todo: $todo"); - expect(todo['text'], equals("Hello")); - expect(todo['over'], equals("world")); + var todo = json.decode(response.body.replaceAll(rgx, '')) as Map; + print('Todo: $todo'); + expect(todo['text'], equals('Hello')); + expect(todo['over'], equals('world')); }); - test("named actions", () async { - var response = await client.get(Uri.parse("$url/redirect")); + test('named actions', () async { + var response = await client.get(Uri.parse('$url/redirect')); print('Response: ${response.body}'); - expect(response.body, equals("Hello, \"world!\"")); + expect(response.body, equals('Hello, \"world!\"')); }); group('optional expose', () { diff --git a/packages/framework/test/di_test.dart b/packages/framework/test/di_test.dart index ec6123a5..2ef29929 100644 --- a/packages/framework/test/di_test.dart +++ b/packages/framework/test/di_test.dart @@ -11,8 +11,8 @@ import 'package:test/test.dart'; import 'common.dart'; -final String TEXT = "make your bed"; -final String OVER = "never"; +final String TEXT = 'make your bed'; +final String OVER = 'never'; void main() { late Angel app; @@ -32,9 +32,9 @@ void main() { return Foo(text); }); - app.get("/errands", ioc((Todo singleton) => singleton)); + app.get('/errands', ioc((Todo singleton) => singleton)); app.get( - "/errands3", + '/errands3', ioc(({required Errand singleton, Todo? foo, RequestContext? req}) => singleton.text)); app.post('/async', ioc((Foo foo) => {'baz': foo.bar})); @@ -42,7 +42,7 @@ void main() { await app.configure(ErrandController().configureServer); server = await AngelHttp(app).startServer(); - url = "http://${server.address.host}:${server.port}"; + url = 'http://${server.address.host}:${server.port}'; }); tearDown(() async { @@ -68,22 +68,22 @@ void main() { expect(text, json.encode('Hey!')); }); - test("singleton in route", () async { - validateTodoSingleton(await client.get(Uri.parse("$url/errands"))); + test('singleton in route', () async { + validateTodoSingleton(await client.get(Uri.parse('$url/errands'))); }); - test("singleton in controller", () async { - validateTodoSingleton(await client.get(Uri.parse("$url/errands2"))); + test('singleton in controller', () async { + validateTodoSingleton(await client.get(Uri.parse('$url/errands2'))); }); - test("make in route", () async { - var response = await client.get(Uri.parse("$url/errands3")); + test('make in route', () async { + var response = await client.get(Uri.parse('$url/errands3')); var text = await json.decode(response.body) as String?; expect(text, equals(TEXT)); }); - test("make in controller", () async { - var response = await client.get(Uri.parse("$url/errands4")); + test('make in controller', () async { + var response = await client.get(Uri.parse('$url/errands4')); var text = await json.decode(response.body) as String?; expect(text, equals(TEXT)); }); @@ -102,26 +102,26 @@ void main() { void validateTodoSingleton(response) { var todo = json.decode(response.body.toString()) as Map; - expect(todo["id"], equals(null)); - expect(todo["text"], equals(TEXT)); - expect(todo["over"], equals(OVER)); + expect(todo['id'], equals(null)); + expect(todo['text'], equals(TEXT)); + expect(todo['over'], equals(OVER)); } -@Expose("/errands2") +@Expose('/errands2') class SingletonController extends Controller { - @Expose("/") - todo(Todo singleton) => singleton; + @Expose('/') + Todo todo(Todo singleton) => singleton; } -@Expose("/errands4") +@Expose('/errands4') class ErrandController extends Controller { - @Expose("/") - errand(Errand errand) { + @Expose('/') + String? errand(Errand errand) { return errand.text; } @Expose('/async', method: 'POST') - asyncResolve(Foo foo) { + Map asyncResolve(Foo foo) { return {'bar': foo.bar}; } } diff --git a/packages/framework/test/general_test.dart b/packages/framework/test/general_test.dart index 27e0262c..75da5d57 100644 --- a/packages/framework/test/general_test.dart +++ b/packages/framework/test/general_test.dart @@ -19,7 +19,7 @@ void main() { client = http.Client(); server = await AngelHttp(app).startServer(); - url = "http://${server.address.host}:${server.port}"; + url = 'http://${server.address.host}:${server.port}'; }); tearDown(() async { @@ -27,7 +27,7 @@ void main() { await server.close(force: true); }); - test("allow override of method", () async { + test('allow override of method', () async { var response = await client.get(Uri.parse('$url/foo'), headers: {'X-HTTP-Method-Override': 'POST'}); print('Response: ${response.body}'); diff --git a/packages/framework/test/hooked_test.dart b/packages/framework/test/hooked_test.dart index c4fda73a..622860e4 100644 --- a/packages/framework/test/hooked_test.dart +++ b/packages/framework/test/hooked_test.dart @@ -37,7 +37,7 @@ void main() { }; server = await AngelHttp(app).startServer(); - url = "http://${server.address.host}:${server.port}"; + url = 'http://${server.address.host}:${server.port}'; }); tearDown(() async { @@ -45,8 +45,8 @@ void main() { client.close(); }); - test("listen before and after", () async { - int count = 0; + test('listen before and after', () async { + var count = 0; todoService ..beforeIndexed.listen((_) { @@ -56,44 +56,44 @@ void main() { count++; }); - var response = await client.get(Uri.parse("$url/todos")); + var response = await client.get(Uri.parse('$url/todos')); print(response.body); expect(count, equals(2)); }); - test("cancel before", () async { + test('cancel before', () async { todoService.beforeCreated ..listen((HookedServiceEvent event) { - event.cancel({"hello": "hooked world"}); + event.cancel({'hello': 'hooked world'}); }) ..listen((HookedServiceEvent event) { - event.cancel({"this_hook": "should never run"}); + event.cancel({'this_hook': 'should never run'}); }); - var response = await client.post(Uri.parse("$url/todos"), - body: json.encode({"arbitrary": "data"}), + var response = await client.post(Uri.parse('$url/todos'), + body: json.encode({'arbitrary': 'data'}), headers: headers as Map); print(response.body); var result = json.decode(response.body) as Map; - expect(result["hello"], equals("hooked world")); + expect(result['hello'], equals('hooked world')); }); - test("cancel after", () async { + test('cancel after', () async { todoService.afterIndexed ..listen((HookedServiceEvent event) async { // Hooks can be Futures ;) event.cancel([ - {"angel": "framework"} + {'angel': 'framework'} ]); }) ..listen((HookedServiceEvent event) { - event.cancel({"this_hook": "should never run either"}); + event.cancel({'this_hook': 'should never run either'}); }); - var response = await client.get(Uri.parse("$url/todos")); + var response = await client.get(Uri.parse('$url/todos')); print(response.body); var result = json.decode(response.body) as List; - expect(result[0]["angel"], equals("framework")); + expect(result[0]['angel'], equals('framework')); }); test('asStream() fires', () async { @@ -111,7 +111,7 @@ void main() { }); test('inject request + response', () async { - HookedService books = app.findService('books') + var books = app.findService('books') as HookedService>; books.beforeIndexed.listen((e) { @@ -131,7 +131,7 @@ void main() { test('contains provider in before and after', () async { var svc = HookedService(AnonymousService(index: ([p]) async => [])); - ensureProviderIsPresent(HookedServiceEvent e) { + void ensureProviderIsPresent(HookedServiceEvent e) { var type = e.isBefore ? 'before' : 'after'; print('Params to $type ${e.eventName}: ${e.params}'); expect(e.params, isMap); diff --git a/packages/framework/test/parameter_meta_test.dart b/packages/framework/test/parameter_meta_test.dart index 2c3f90a0..23b7586d 100644 --- a/packages/framework/test/parameter_meta_test.dart +++ b/packages/framework/test/parameter_meta_test.dart @@ -5,6 +5,7 @@ import 'package:angel3_container/mirrors.dart'; import 'package:angel3_framework/angel3_framework.dart'; import 'package:angel3_framework/http.dart'; import 'package:angel3_mock_request/angel3_mock_request.dart'; +import 'package:logging/logging.dart'; import 'package:test/test.dart'; @@ -22,7 +23,7 @@ void main() { group('parameter_meta', parameterMetaTests); } -parameterMetaTests() { +void parameterMetaTests() { Angel app; late AngelHttp http; @@ -58,13 +59,12 @@ parameterMetaTests() { return 'DEFAULT $mode'; })); - /*app.logger = Logger('parameter_meta_test') + app.logger = Logger('parameter_meta_test') ..onRecord.listen((rec) { print(rec); if (rec.error != null) print(rec.error); if (rec.stackTrace != null) print(rec.stackTrace); }); - */ }); test('injects header or throws', () async { @@ -72,6 +72,7 @@ parameterMetaTests() { var rq = MockHttpRequest('GET', Uri.parse('/header')); await rq.close(); var rs = rq.response; + //TODO: Using await will hang. To be resolved. http.handleRequest(rq); await printResponse(rs); diff --git a/packages/framework/test/precontained_test.dart b/packages/framework/test/precontained_test.dart index 9a87c456..b3ae98b9 100644 --- a/packages/framework/test/precontained_test.dart +++ b/packages/framework/test/precontained_test.dart @@ -25,4 +25,4 @@ void main() { }, skip: 'Angel no longer has to preinject functions'); } -echoAppFoo(String foo) => foo; +String echoAppFoo(String foo) => foo; diff --git a/packages/framework/test/routing_test.dart b/packages/framework/test/routing_test.dart index ff91cd7c..f3d1e27c 100644 --- a/packages/framework/test/routing_test.dart +++ b/packages/framework/test/routing_test.dart @@ -12,15 +12,16 @@ import 'package:test/test.dart'; import 'common.dart'; @Middleware([interceptor]) -testMiddlewareMetadata(RequestContext req, ResponseContext res) async { - return "This should not be shown."; +Future testMiddlewareMetadata( + RequestContext req, ResponseContext res) async { + return 'This should not be shown.'; } @Middleware([interceptService]) class QueryService extends Service { @override @Middleware([interceptor]) - read(id, [Map? params]) async => params; + Future read(id, [Map? params]) async => params; } void interceptor(RequestContext req, ResponseContext res) { @@ -30,11 +31,11 @@ void interceptor(RequestContext req, ResponseContext res) { } bool interceptService(RequestContext req, ResponseContext res) { - res.write("Service with "); + res.write('Service with '); return true; } -main() { +void main() { late Angel app; late Angel nested; late Angel todos; @@ -88,8 +89,8 @@ main() { await res.redirectTo('Named routes', {'name': 'tests'}); }); app.get('/log', (RequestContext req, res) async { - print("Query: ${req.queryParameters}"); - return "Logged"; + print('Query: ${req.queryParameters}'); + return 'Logged'; }); app.get('/method', (req, res) => 'Only GET'); @@ -112,8 +113,8 @@ main() { //app.dumpTree(header: "DUMPING ROUTES:", showMatchers: true); client = http.Client(); - HttpServer server = await AngelHttp(app).startServer('127.0.0.1', 0); - url = "http://${server.address.host}:${server.port}"; + var server = await AngelHttp(app).startServer('127.0.0.1', 0); + url = 'http://${server.address.host}:${server.port}'; }); tearDown(() async { @@ -122,7 +123,7 @@ main() { }); test('Can match basic url', () async { - var response = await client.get(Uri.parse("$url/hello")); + var response = await client.get(Uri.parse('$url/hello')); expect(response.body, equals('"world"')); }); @@ -136,7 +137,7 @@ main() { }); test('Chained routes', () async { - var response = await client.get(Uri.parse("$url/chained")); + var response = await client.get(Uri.parse('$url/chained')); expect(response.body, equals('abc')); }); @@ -167,8 +168,8 @@ main() { test('Can serialize function result as JSON', () async { Map headers = {'Content-Type': 'application/json'}; - String postData = json.encode({'it': 'works'}); - var response = await client.post(Uri.parse("$url/lambda"), + var postData = json.encode({'it': 'works'}); + var response = await client.post(Uri.parse('$url/lambda'), headers: headers as Map, body: postData); print('Response: ${response.body}'); expect(json.decode(response.body)['it'], equals('works')); @@ -197,25 +198,25 @@ main() { test('Match routes, even with query params', () async { var response = await client - .get(Uri.parse("$url/log?foo=bar&bar=baz&baz.foo=bar&baz.bar=foo")); + .get(Uri.parse('$url/log?foo=bar&bar=baz&baz.foo=bar&baz.bar=foo')); print(response.body); expect(json.decode(response.body), equals('Logged')); - response = await client.get(Uri.parse("$url/query/foo?bar=baz")); + response = await client.get(Uri.parse('$url/query/foo?bar=baz')); print(response.body); - expect(response.body, equals("Service with Middleware")); + expect(response.body, equals('Service with Middleware')); }); test('only match route with matching method', () async { - var response = await client.get(Uri.parse("$url/method")); + var response = await client.get(Uri.parse('$url/method')); print(response.body); expect(response.body, '"Only GET"'); - response = await client.post(Uri.parse("$url/method")); + response = await client.post(Uri.parse('$url/method')); print(response.body); expect(response.body, '"Only POST"'); - response = await client.patch(Uri.parse("$url/method")); + response = await client.patch(Uri.parse('$url/method')); print(response.body); expect(response.body, '"MJ"'); }); diff --git a/packages/framework/test/serialize_test.dart b/packages/framework/test/serialize_test.dart index 3f4dfca0..92197227 100644 --- a/packages/framework/test/serialize_test.dart +++ b/packages/framework/test/serialize_test.dart @@ -23,7 +23,7 @@ void main() { client = http.Client(); server = await AngelHttp(app).startServer(); - url = "http://${server.address.host}:${server.port}"; + url = 'http://${server.address.host}:${server.port}'; }); tearDown(() async { @@ -31,7 +31,7 @@ void main() { await server.close(force: true); }); - test("correct content-type", () async { + test('correct content-type', () async { var response = await client.get(Uri.parse('$url/foo')); print('Response: ${response.body}'); expect(response.headers['content-type'], contains('application/json')); diff --git a/packages/framework/test/services_test.dart b/packages/framework/test/services_test.dart index 02797674..d787c05d 100644 --- a/packages/framework/test/services_test.dart +++ b/packages/framework/test/services_test.dart @@ -31,9 +31,9 @@ void main() { if (e.stackTrace != null) print(Chain.forTrace(e.stackTrace!).terse); }; - HttpServer server = await AngelHttp(app).startServer(); + var server = await AngelHttp(app).startServer(); client = http.Client(); - url = "http://${server.address.host}:${server.port}"; + url = 'http://${server.address.host}:${server.port}'; }); tearDown(() async { @@ -43,7 +43,7 @@ void main() { group('memory', () { test('can index an empty service', () async { - var response = await client.get(Uri.parse("$url/todos/")); + var response = await client.get(Uri.parse('$url/todos/')); print(response.body); expect(response.body, equals('[]')); print(response.body); @@ -51,8 +51,8 @@ void main() { }); test('can create data', () async { - String postData = json.encode({'text': 'Hello, world!'}); - var response = await client.post(Uri.parse("$url/todos"), + var postData = json.encode({'text': 'Hello, world!'}); + var response = await client.post(Uri.parse('$url/todos'), headers: headers as Map, body: postData); expect(response.statusCode, 201); var jsons = json.decode(response.body); @@ -61,10 +61,10 @@ void main() { }); test('can fetch data', () async { - String postData = json.encode({'text': 'Hello, world!'}); - await client.post(Uri.parse("$url/todos"), + var postData = json.encode({'text': 'Hello, world!'}); + await client.post(Uri.parse('$url/todos'), headers: headers as Map, body: postData); - var response = await client.get(Uri.parse("$url/todos/0")); + var response = await client.get(Uri.parse('$url/todos/0')); expect(response.statusCode, 200); var jsons = json.decode(response.body); print(jsons); @@ -72,12 +72,12 @@ void main() { }); test('can modify data', () async { - String postData = json.encode({'text': 'Hello, world!'}); - await client.post(Uri.parse("$url/todos"), + var postData = json.encode({'text': 'Hello, world!'}); + await client.post(Uri.parse('$url/todos'), headers: headers as Map, body: postData); postData = json.encode({'text': 'modified'}); - var response = await client.patch(Uri.parse("$url/todos/0"), + var response = await client.patch(Uri.parse('$url/todos/0'), headers: headers, body: postData); expect(response.statusCode, 200); var jsons = json.decode(response.body); @@ -86,12 +86,12 @@ void main() { }); test('can overwrite data', () async { - String postData = json.encode({'text': 'Hello, world!'}); - await client.post(Uri.parse("$url/todos"), + var postData = json.encode({'text': 'Hello, world!'}); + await client.post(Uri.parse('$url/todos'), headers: headers as Map, body: postData); postData = json.encode({'over': 'write'}); - var response = await client.post(Uri.parse("$url/todos/0"), + var response = await client.post(Uri.parse('$url/todos/0'), headers: headers, body: postData); expect(response.statusCode, 200); var jsons = json.decode(response.body); @@ -112,9 +112,9 @@ void main() { }); test('can delete data', () async { - String postData = json.encode({'text': 'Hello, world!'}); + var postData = json.encode({'text': 'Hello, world!'}); var created = await client - .post(Uri.parse("$url/todos"), + .post(Uri.parse('$url/todos'), headers: headers as Map, body: postData) .then((r) => json.decode(r.body)); var response = diff --git a/packages/framework/test/streaming_test.dart b/packages/framework/test/streaming_test.dart index f8664f5f..5ce772b2 100644 --- a/packages/framework/test/streaming_test.dart +++ b/packages/framework/test/streaming_test.dart @@ -75,7 +75,7 @@ void main() { tearDown(() => http.close()); - _expectHelloBye(String path) async { + void _expectHelloBye(String path) async { var rq = MockHttpRequest('GET', Uri.parse(path)); await (rq.close()); await http.handleRequest(rq); diff --git a/packages/static/README.md b/packages/static/README.md index 3a39df0a..52ff6684 100644 --- a/packages/static/README.md +++ b/packages/static/README.md @@ -66,11 +66,10 @@ app.fallback(vDir.pushState('index.html')); The `VirtualDirectory` API accepts a few named parameters: -- **source**: A `Directory` containing the files to be served. If left null, then Angel will serve either from `web` (in development) or +- **source**: A `Directory` containing the files to be served. If left null, then Angel3 will serve either from `web` (in development) or `build/web` (in production), depending on your `ANGEL_ENV`. - **indexFileNames**: A `List` of filenames that should be served as index pages. Default is `['index.html']`. - **publicPath**: To serve index files, you need to specify the virtual path under which - angel_static is serving your files. If you are not serving static files at the site root, + angel3_static is serving your files. If you are not serving static files at the site root, please include this. -- **callback**: Runs before sending a file to a client. Use this to set headers, etc. If it returns anything other than `null` or `true`, -then the callback's result will be sent to the user, instead of the file contents. +- **callback**: Runs before sending a file to a client. Use this to set headers, etc. If it returns anything other than `null` or `true`, then the callback's result will be sent to the user, instead of the file contents.