Skip to content

Commit

Permalink
Adapt to routingkit v4.0.0 version
Browse files Browse the repository at this point in the history
version: v5.1.0
  • Loading branch information
medz committed Sep 8, 2024
1 parent 873834f commit 9884f5d
Show file tree
Hide file tree
Showing 14 changed files with 1,925 additions and 41 deletions.
12 changes: 0 additions & 12 deletions .github/dependabot.yml

This file was deleted.

8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## 5.1.0

Adapt to `routingkit` v4.0.0 version

## 5.0.2

* Remove `http_parser` package.
- Remove `http_parser` package.

## 5.0.1

* Change the `meta` package version to `>=1.12.0 <2.0.0`
- Change the `meta` package version to `>=1.12.0 <2.0.0`
Binary file removed bun.lockb
Binary file not shown.
4 changes: 4 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Spry Examples

- [Bun.js] example see 👉 https://spry.fun/adapters/bun
- [`dart:io`] example see 👉 https://spry.fun/adapters/io
2 changes: 1 addition & 1 deletion lib/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Future<void> Function(HttpRequest request) toIOHandler(Spry app) {

return (httpRequest) async {
final spryRequest = Request(
method: httpRequest.method,
method: httpRequest.method.toLowerCase(),
uri: httpRequest.requestedUri,
headers: _createSpryHeaders(httpRequest.headers),
body: httpRequest,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract interface class Routes {
abstract interface class Spry implements Routes {
/// The [RouterContext] bound to the current [Spry] application
@internal
Router<Handler> get router;
RouterContext<Handler> get router;

/// Stack handler in Spry application.
@internal
Expand Down
8 changes: 4 additions & 4 deletions lib/src/utils/create_spry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import 'package:routingkit/routingkit.dart';
import '../types.dart';

/// Creates a new [Spry] application.
Spry createSpry({Router<Handler>? router, Iterable<Handler>? stack}) {
Spry createSpry({RouterContext<Handler>? router, Iterable<Handler>? stack}) {
return _SpryImpl(
router: switch (router) {
Router<Handler> router => router,
RouterContext<Handler> router => router,
_ => createRouter<Handler>(),
},
stack: [...?stack],
Expand All @@ -17,14 +17,14 @@ class _SpryImpl implements Spry {
const _SpryImpl({required this.router, required this.stack});

@override
final Router<Handler> router;
final RouterContext<Handler> router;

@override
final List<Handler> stack;

@override
void on<T>(String? method, String path, Handler<T> handler) {
router.add(method, path, handler);
addRoute(router, method ?? '', path, handler);
}

@override
Expand Down
8 changes: 3 additions & 5 deletions lib/src/utils/request_utils.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'package:routingkit/routingkit.dart';

import '../_constants.dart';
import '../http/headers.dart';
import '../http/request.dart';
Expand Down Expand Up @@ -38,9 +36,9 @@ void setClientAddress(Event event, String address) {
Uri useRequestURI(Event event) => useRequest(event).uri;

/// Returns the request [Event] matched route params.
Params useParams(Event event) {
Map<String, String> useParams(Event event) {
return switch (event.get(kParams)) {
Params params => params,
_ => const <String, String>{} as Params,
Map<String, String> params => params,
_ => <String, String>{},
};
}
16 changes: 8 additions & 8 deletions lib/src/utils/to_handler.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:routingkit/routingkit.dart';
import 'package:routingkit/routingkit.dart' as routingkit;

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

Handler _createRouterHandler(Router<Handler> router) {
Handler _createRouterHandler(routingkit.RouterContext<Handler> router) {
return (event) {
final request = useRequest(event);
final route = _lookup(router, request.method, request.uri.path);
Expand All @@ -35,19 +35,19 @@ Handler _createRouterHandler(Router<Handler> router) {
};
}

MatchedRoute<Handler>? _lookup(
Router<Handler> router, String method, String path) {
MatchedRoute<Handler>? findRoute(String? method) {
return router.find(method, path);
routingkit.MatchedRoute<Handler>? _lookup(
routingkit.RouterContext<Handler> router, String method, String path) {
routingkit.MatchedRoute<Handler>? findRoute(String? method) {
return routingkit.findRoute(router, method ?? '', path);
}

return switch (method) {
'HEAD' => switch (findRoute('HEAD')) {
MatchedRoute<Handler> route => route,
routingkit.MatchedRoute<Handler> route => route,
_ => _lookup(router, 'GET', path),
},
String method => switch (findRoute(method)) {
MatchedRoute<Handler> route => route,
routingkit.MatchedRoute<Handler> route => route,
_ => findRoute(null),
},
};
Expand Down
2 changes: 1 addition & 1 deletion lib/web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'spry.dart';
/// Create a new [Event] for web.
Event createWebEvent(Spry app, web.Request request) {
final spryRequest = Request(
method: request.method,
method: request.method.toUpperCase(),
uri: Uri.parse(request.url),
headers: toSpryHeaders(request.headers),
body: _getWebRequestBody(request),
Expand Down
4 changes: 2 additions & 2 deletions lib/ws.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ abstract interface class Peer implements Event {

/// The peer protocol.
///
/// TODO
/// TODO all adapter support, current only `dart:io`
String? get protocol;

/// Returns the peer extensions.
Expand Down Expand Up @@ -112,7 +112,7 @@ Future<bool> upgrade(Event event, Hooks hooks) async {
extension RoutesWS on Routes {
/// Register a websocket handler with [hooks].
void ws<T>(String path, Hooks hooks, [Handler<T>? fallback]) {
on('get', path, (event) async {
return get(path, (event) async {
if (await upgrade(event, hooks)) {
return Response(null, status: 101);
}
Expand Down
Loading

0 comments on commit 9884f5d

Please sign in to comment.