From 91b695d6094e836c28a5c06ed71feaa70a1ad104 Mon Sep 17 00:00:00 2001 From: Jonas Finnemann Jensen Date: Tue, 3 Nov 2020 14:33:43 +0100 Subject: [PATCH] Seal classes in shelf_router and prepare 0.7.3 (#85) * Updated README.md, adding links to third-party tutorial :D * Prefer spread collections * Add @sealed route and bumped to 0.7.3 * Cleanup README --- pkgs/shelf_router/CHANGELOG.md | 4 ++++ pkgs/shelf_router/README.md | 18 ++++++++++++++++-- pkgs/shelf_router/lib/shelf_router.dart | 8 ++++---- pkgs/shelf_router/lib/src/route.dart | 4 +++- pkgs/shelf_router/lib/src/router.dart | 4 +++- pkgs/shelf_router/lib/src/router_entry.dart | 6 ++++-- pkgs/shelf_router/pubspec.yaml | 5 +++-- 7 files changed, 37 insertions(+), 12 deletions(-) diff --git a/pkgs/shelf_router/CHANGELOG.md b/pkgs/shelf_router/CHANGELOG.md index 08a1d6cc..f3e05695 100644 --- a/pkgs/shelf_router/CHANGELOG.md +++ b/pkgs/shelf_router/CHANGELOG.md @@ -1,3 +1,7 @@ +## v0.7.3 + + * Added `@sealed` annotation to `Router` and `Route`. + ## v0.7.2 * Always register a `HEAD` handler whenever a `GET` handler is registered. diff --git a/pkgs/shelf_router/README.md b/pkgs/shelf_router/README.md index 87addb8d..6738d159 100644 --- a/pkgs/shelf_router/README.md +++ b/pkgs/shelf_router/README.md @@ -1,12 +1,13 @@ # Web Request Router for Shelf -[Shelf](https://pub.dartlang.org/packages/shelf) makes it easy to build web +[Shelf][shelf] makes it easy to build web applications in Dart by composing request handlers. This package offers a request router for Shelf, matching request to handlers using route patterns. **Disclaimer:** This is not an officially supported Google product. -Also see the `shelf_router_generator` package for how to automatically generate +Also see the [`shelf_router_generator`][shelf_router_generator] package +for how to automatically generate a `Route` using the `Route` annotation in this package. ## Example @@ -31,3 +32,16 @@ var server = await io.serve(app.handler, 'localhost', 8080); See reference documentation of `Router` class for more information. +## See also + * Package [`shelf`][shelf] for which this package can create routers. + * Package [`shelf_router_generator`][shelf_router_generator] which can generate + a router using source code annotations. + * Third-party tutorial by [creativebracket.com]: + * Video: [Build RESTful Web APIs with shelf_router][1] + * Sample: [repository for tutorial][2] + +[shelf]: https://pub.dev/packages/shelf +[shelf_router_generator]: https://pub.dev/packages/shelf_router_generator +[creativebracket.com]: https://creativebracket.com/ +[1]: https://www.youtube.com/watch?v=v7FhaV9e3yY +[2]: https://github.com/graphicbeacon/shelf_router_api_tutorial diff --git a/pkgs/shelf_router/lib/shelf_router.dart b/pkgs/shelf_router/lib/shelf_router.dart index 9492ddab..dcf4f7dc 100644 --- a/pkgs/shelf_router/lib/shelf_router.dart +++ b/pkgs/shelf_router/lib/shelf_router.dart @@ -79,7 +79,7 @@ /// library shelf_router; -import 'src/router.dart'; -import 'src/route.dart'; -export 'src/router.dart'; -export 'src/route.dart'; +import 'package:shelf_router/src/router.dart'; +import 'package:shelf_router/src/route.dart'; +export 'package:shelf_router/src/router.dart'; +export 'package:shelf_router/src/route.dart'; diff --git a/pkgs/shelf_router/lib/src/route.dart b/pkgs/shelf_router/lib/src/route.dart index 10a81043..62da18f7 100644 --- a/pkgs/shelf_router/lib/src/route.dart +++ b/pkgs/shelf_router/lib/src/route.dart @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -import 'router.dart'; +import 'package:meta/meta.dart' show sealed; +import 'package:shelf_router/src/router.dart'; /// Annotation for handler methods that requests should be routed when using /// package `shelf_router_generator`. @@ -45,6 +46,7 @@ import 'router.dart'; /// /// It is also permitted to annotate public members, the only requirement is /// that the member has a signature accepted by [Router] as `handler`. +@sealed class Route { /// HTTP verb for requests routed to the annotated method. final String verb; diff --git a/pkgs/shelf_router/lib/src/router.dart b/pkgs/shelf_router/lib/src/router.dart index a6b87110..a3102cd6 100644 --- a/pkgs/shelf_router/lib/src/router.dart +++ b/pkgs/shelf_router/lib/src/router.dart @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -import 'router_entry.dart' show RouterEntry; +import 'package:meta/meta.dart' show sealed; +import 'package:shelf_router/src/router_entry.dart' show RouterEntry; import 'package:shelf/shelf.dart'; import 'package:http_methods/http_methods.dart'; @@ -84,6 +85,7 @@ final _removeBody = createMiddleware(responseHandler: (r) { /// will be attempted. /// /// +@sealed class Router { final List _routes = []; diff --git a/pkgs/shelf_router/lib/src/router_entry.dart b/pkgs/shelf_router/lib/src/router_entry.dart index 5130f502..d2ef901b 100644 --- a/pkgs/shelf_router/lib/src/router_entry.dart +++ b/pkgs/shelf_router/lib/src/router_entry.dart @@ -103,8 +103,10 @@ class RouterEntry { if (_handler is Handler || _params.isEmpty) { return await _handler(request); } - return await Function.apply( - _handler, [request]..addAll(_params.map((n) => params[n]))); + return await Function.apply(_handler, [ + request, + ..._params.map((n) => params[n]), + ]); })(request); } } diff --git a/pkgs/shelf_router/pubspec.yaml b/pkgs/shelf_router/pubspec.yaml index 1b02b1a2..c0befeb3 100644 --- a/pkgs/shelf_router/pubspec.yaml +++ b/pkgs/shelf_router/pubspec.yaml @@ -1,5 +1,5 @@ name: shelf_router -version: 0.7.2 +version: 0.7.3 description: | A convinent request router for the shelf web-framework, with support for URL-parameters, nested routers and routers generated from source annotations. @@ -7,6 +7,7 @@ homepage: https://github.com/google/dart-neats/tree/master/shelf_router repository: https://github.com/google/dart-neats.git issue_tracker: https://github.com/google/dart-neats/labels/pkg:shelf_router dependencies: + meta: ^1.1.7 shelf: ^0.7.3 http_methods: ^1.0.0 dev_dependencies: @@ -14,4 +15,4 @@ dev_dependencies: pedantic: ^1.4.0 http: ^0.12.0+1 environment: - sdk: '>=2.0.0 <3.0.0' + sdk: '>=2.3.0 <3.0.0'