Skip to content

Commit 9884f5d

Browse files
committed
Adapt to routingkit v4.0.0 version
version: v5.1.0
1 parent 873834f commit 9884f5d

File tree

14 files changed

+1925
-41
lines changed

14 files changed

+1925
-41
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
## 5.1.0
2+
3+
Adapt to `routingkit` v4.0.0 version
4+
15
## 5.0.2
26

3-
* Remove `http_parser` package.
7+
- Remove `http_parser` package.
48

59
## 5.0.1
610

7-
* Change the `meta` package version to `>=1.12.0 <2.0.0`
11+
- Change the `meta` package version to `>=1.12.0 <2.0.0`

bun.lockb

-48.6 KB
Binary file not shown.

example/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Spry Examples
2+
3+
- [Bun.js] example see 👉 https://spry.fun/adapters/bun
4+
- [`dart:io`] example see 👉 https://spry.fun/adapters/io

lib/io.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Future<void> Function(HttpRequest request) toIOHandler(Spry app) {
1313

1414
return (httpRequest) async {
1515
final spryRequest = Request(
16-
method: httpRequest.method,
16+
method: httpRequest.method.toLowerCase(),
1717
uri: httpRequest.requestedUri,
1818
headers: _createSpryHeaders(httpRequest.headers),
1919
body: httpRequest,

lib/src/types.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ abstract interface class Routes {
3030
abstract interface class Spry implements Routes {
3131
/// The [RouterContext] bound to the current [Spry] application
3232
@internal
33-
Router<Handler> get router;
33+
RouterContext<Handler> get router;
3434

3535
/// Stack handler in Spry application.
3636
@internal

lib/src/utils/create_spry.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import 'package:routingkit/routingkit.dart';
33
import '../types.dart';
44

55
/// Creates a new [Spry] application.
6-
Spry createSpry({Router<Handler>? router, Iterable<Handler>? stack}) {
6+
Spry createSpry({RouterContext<Handler>? router, Iterable<Handler>? stack}) {
77
return _SpryImpl(
88
router: switch (router) {
9-
Router<Handler> router => router,
9+
RouterContext<Handler> router => router,
1010
_ => createRouter<Handler>(),
1111
},
1212
stack: [...?stack],
@@ -17,14 +17,14 @@ class _SpryImpl implements Spry {
1717
const _SpryImpl({required this.router, required this.stack});
1818

1919
@override
20-
final Router<Handler> router;
20+
final RouterContext<Handler> router;
2121

2222
@override
2323
final List<Handler> stack;
2424

2525
@override
2626
void on<T>(String? method, String path, Handler<T> handler) {
27-
router.add(method, path, handler);
27+
addRoute(router, method ?? '', path, handler);
2828
}
2929

3030
@override

lib/src/utils/request_utils.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'package:routingkit/routingkit.dart';
2-
31
import '../_constants.dart';
42
import '../http/headers.dart';
53
import '../http/request.dart';
@@ -38,9 +36,9 @@ void setClientAddress(Event event, String address) {
3836
Uri useRequestURI(Event event) => useRequest(event).uri;
3937

4038
/// Returns the request [Event] matched route params.
41-
Params useParams(Event event) {
39+
Map<String, String> useParams(Event event) {
4240
return switch (event.get(kParams)) {
43-
Params params => params,
44-
_ => const <String, String>{} as Params,
41+
Map<String, String> params => params,
42+
_ => <String, String>{},
4543
};
4644
}

lib/src/utils/to_handler.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'package:routingkit/routingkit.dart';
1+
import 'package:routingkit/routingkit.dart' as routingkit;
22

33
import '../_constants.dart';
44
import '../http/response.dart';
@@ -20,7 +20,7 @@ Handler<Response> toHandler(Spry app) {
2020
return (event) => createResponseWith(event, handler(event));
2121
}
2222

23-
Handler _createRouterHandler(Router<Handler> router) {
23+
Handler _createRouterHandler(routingkit.RouterContext<Handler> router) {
2424
return (event) {
2525
final request = useRequest(event);
2626
final route = _lookup(router, request.method, request.uri.path);
@@ -35,19 +35,19 @@ Handler _createRouterHandler(Router<Handler> router) {
3535
};
3636
}
3737

38-
MatchedRoute<Handler>? _lookup(
39-
Router<Handler> router, String method, String path) {
40-
MatchedRoute<Handler>? findRoute(String? method) {
41-
return router.find(method, path);
38+
routingkit.MatchedRoute<Handler>? _lookup(
39+
routingkit.RouterContext<Handler> router, String method, String path) {
40+
routingkit.MatchedRoute<Handler>? findRoute(String? method) {
41+
return routingkit.findRoute(router, method ?? '', path);
4242
}
4343

4444
return switch (method) {
4545
'HEAD' => switch (findRoute('HEAD')) {
46-
MatchedRoute<Handler> route => route,
46+
routingkit.MatchedRoute<Handler> route => route,
4747
_ => _lookup(router, 'GET', path),
4848
},
4949
String method => switch (findRoute(method)) {
50-
MatchedRoute<Handler> route => route,
50+
routingkit.MatchedRoute<Handler> route => route,
5151
_ => findRoute(null),
5252
},
5353
};

lib/web.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'spry.dart';
1010
/// Create a new [Event] for web.
1111
Event createWebEvent(Spry app, web.Request request) {
1212
final spryRequest = Request(
13-
method: request.method,
13+
method: request.method.toUpperCase(),
1414
uri: Uri.parse(request.url),
1515
headers: toSpryHeaders(request.headers),
1616
body: _getWebRequestBody(request),

0 commit comments

Comments
 (0)