From cb56b31d102582c0f91840801017d4766c1a4d63 Mon Sep 17 00:00:00 2001 From: thomashii Date: Sun, 21 Mar 2021 09:40:22 +0800 Subject: [PATCH] Fixed null safety --- CHANGELOG.md | 8 ++++---- packages/framework/lib/src/core/controller.dart | 6 +++--- packages/framework/lib/src/core/hooked_service.dart | 4 ++-- packages/framework/lib/src/core/hostname_router.dart | 2 -- packages/framework/lib/src/core/injection.dart | 2 +- packages/framework/lib/src/core/metadata.dart | 3 +-- packages/framework/lib/src/core/routable.dart | 7 +++++-- packages/framework/lib/src/core/server.dart | 12 ++++++------ packages/framework/lib/src/http/http.dart | 4 ++-- .../lib/src/http/http_response_context.dart | 6 +++--- .../lib/src/http2/http2_response_context.dart | 6 +++--- 11 files changed, 30 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8f598be..06dbba6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,14 +5,14 @@ * Moved angel_cli to https://github.com/dukefirehawk/cli * Added code_buffer and updated to 2.0.0 * Added combinator and updated to 2.0.0 -* Updated angel_route to 5.0.0 +* Updated angel_route to 5.0.0 * Updated angel_model to 3.0.0 * Updated angel_container to 3.0.0 * Added merge_map and updated to 2.0.0 * Added mock_request and updated to 2.0.0 -* Updated angel_framework to 4.0.0 (Revisit TODO) -* Updated angel_auth to 4.0.0 -* Updated angel_configuration to 4.0.0 (todo) +* Updated angel_framework to 4.0.0 (Revisit TODO, Fix failed tests) +* Updated angel_auth to 4.0.0 (In progress) +* Updated angel_configuration to 4.0.0 (In progress) # 3.0.0 (Non NNBD) * Changed Dart SDK requirements for all packages to ">=2.10.0 <3.0.0" diff --git a/packages/framework/lib/src/core/controller.dart b/packages/framework/lib/src/core/controller.dart index d9b3efb6..d1a83ba6 100644 --- a/packages/framework/lib/src/core/controller.dart +++ b/packages/framework/lib/src/core/controller.dart @@ -128,13 +128,13 @@ class Controller { var injection = preInject(reflectedMethod!, reflector); - if (exposeDecl?.allowNull?.isNotEmpty == true) { - injection.optional?.addAll(exposeDecl.allowNull); + if (exposeDecl.allowNull.isNotEmpty == true) { + injection.optional.addAll(exposeDecl.allowNull); } // If there is no path, reverse-engineer one. var path = exposeDecl.path; - var httpMethod = exposeDecl.method ?? 'GET'; + var httpMethod = exposeDecl.method; if (path == null) { // Try to build a route path by finding all potential // path segments, and then joining them. diff --git a/packages/framework/lib/src/core/hooked_service.dart b/packages/framework/lib/src/core/hooked_service.dart index adb63df0..9b6f404f 100644 --- a/packages/framework/lib/src/core/hooked_service.dart +++ b/packages/framework/lib/src/core/hooked_service.dart @@ -471,7 +471,7 @@ class HookedService> HookedServiceEvent event, [HookedServiceEventListener? callback]) { Future? f; - if (callback != null && event?._canceled != true) { + if (callback != null && event._canceled != true) { f = Future.sync(() => callback(event)); } f ??= Future.value(); @@ -560,7 +560,7 @@ class HookedServiceEventDispatcher> { /// Fires an event, and returns it once it is either canceled, or all listeners have run. Future> _emit( HookedServiceEvent event) { - if (event?._canceled == true || event == null || listeners.isEmpty) { + if (event._canceled == true || listeners.isEmpty) { return Future.value(event); } diff --git a/packages/framework/lib/src/core/hostname_router.dart b/packages/framework/lib/src/core/hostname_router.dart index 00f8900a..c568287c 100644 --- a/packages/framework/lib/src/core/hostname_router.dart +++ b/packages/framework/lib/src/core/hostname_router.dart @@ -45,8 +45,6 @@ class HostnameRouter { }); } - apps ??= {}; - creators ??= {}; apps = _parseMap(apps); creators = _parseMap(creators); var patterns = apps.keys.followedBy(creators.keys).toSet().toList(); diff --git a/packages/framework/lib/src/core/injection.dart b/packages/framework/lib/src/core/injection.dart index 28189c2b..92ef801e 100644 --- a/packages/framework/lib/src/core/injection.dart +++ b/packages/framework/lib/src/core/injection.dart @@ -26,7 +26,7 @@ resolveInjection(requirement, InjectionRequest? injection, RequestContext req, ResponseContext res, bool throwOnUnresolved, [Container? container]) async { var propFromApp; - container ??= req?.container ?? res?.app?.container; + container ??= req.container ?? res.app?.container; if (requirement == RequestContext) { return req; diff --git a/packages/framework/lib/src/core/metadata.dart b/packages/framework/lib/src/core/metadata.dart index 56bb9fee..0012b340 100644 --- a/packages/framework/lib/src/core/metadata.dart +++ b/packages/framework/lib/src/core/metadata.dart @@ -122,8 +122,7 @@ class Parameter { /// Obtains a value for this parameter from a [RequestContext]. getValue(RequestContext req) { if (cookie?.isNotEmpty == true) { - return req.cookies!.firstWhere((c) => c.name == cookie)?.value ?? - defaultValue; + return req.cookies!.firstWhere((c) => c.name == cookie).value; } if (header?.isNotEmpty == true) { return req.headers!.value(header!) ?? defaultValue; diff --git a/packages/framework/lib/src/core/routable.dart b/packages/framework/lib/src/core/routable.dart index c01d4bee..b63a27a5 100644 --- a/packages/framework/lib/src/core/routable.dart +++ b/packages/framework/lib/src/core/routable.dart @@ -24,7 +24,7 @@ RequestHandler chain(Iterable handlers) { Future Function()? runPipeline; for (var handler in handlers) { - if (handler == null) break; + //if (handler == null) break; if (runPipeline == null) { runPipeline = () => Future.sync(() => handler(req, res)); @@ -108,7 +108,10 @@ class Routable extends Router { } final handlerSequence = []; - handlerSequence.addAll(middleware as Iterable? Function(RequestContext, ResponseContext)>? ?? []); + handlerSequence.addAll(middleware as Iterable< + FutureOr? Function( + RequestContext, ResponseContext)>? ?? + []); handlerSequence.addAll(handlers); return super.addRoute(method, path.toString(), handler, diff --git a/packages/framework/lib/src/core/server.dart b/packages/framework/lib/src/core/server.dart index 52c9e157..97ec3efa 100644 --- a/packages/framework/lib/src/core/server.dart +++ b/packages/framework/lib/src/core/server.dart @@ -159,7 +159,7 @@ class Angel extends Routable { 'This route will be ignored, and no requests will ever reach it.'); } - return super.addRoute(method, path, handler, middleware: middleware ?? []); + return super.addRoute(method, path, handler, middleware: middleware); } @override @@ -225,21 +225,21 @@ class Angel extends Routable { _flattened!.dumpTree( callback: callback, - header: header?.isNotEmpty == true + header: header.isNotEmpty == true ? header : (environment.isProduction ? 'Dumping flattened route tree:' : 'Dumping route tree:'), - tab: tab ?? ' '); + tab: tab); } else { super.dumpTree( callback: callback, - header: header?.isNotEmpty == true + header: header.isNotEmpty == true ? header : (environment.isProduction ? 'Dumping flattened route tree:' : 'Dumping route tree:'), - tab: tab ?? ' '); + tab: tab); } } @@ -319,7 +319,7 @@ class Angel extends Routable { /// Runs with DI, and *always* reflects. Prefer [runContained]. Future runReflected(Function handler, RequestContext req, ResponseContext res, [Container? container]) { - container ??= req?.container ?? res?.app?.container; + container ??= req.container ?? res.app?.container; var h = handleContained( handler, _preContained[handler] = preInject(handler, container!.reflector), diff --git a/packages/framework/lib/src/http/http.dart b/packages/framework/lib/src/http/http.dart index 44ab4cdb..d4ea40b1 100644 --- a/packages/framework/lib/src/http/http.dart +++ b/packages/framework/lib/src/http/http.dart @@ -9,11 +9,11 @@ export 'http_response_context.dart'; /// Boots a shared server instance. Use this if launching multiple isolates. Future startShared(address, int port) => - HttpServer.bind(address ?? '127.0.0.1', port ?? 0, shared: true); + HttpServer.bind(address ?? '127.0.0.1', port, shared: true); Future Function(dynamic, int) startSharedSecure( SecurityContext securityContext) { return (address, int port) => HttpServer.bindSecure( - address ?? '127.0.0.1', port ?? 0, securityContext, + address ?? '127.0.0.1', port, securityContext, shared: true); } diff --git a/packages/framework/lib/src/http/http_response_context.dart b/packages/framework/lib/src/http/http_response_context.dart index 5ddc8cb8..6cef2527 100644 --- a/packages/framework/lib/src/http/http_response_context.dart +++ b/packages/framework/lib/src/http/http_response_context.dart @@ -60,9 +60,9 @@ class HttpResponseContext extends ResponseContext { return __allowedEncodings ??= correspondingRequest!.headers! .value('accept-encoding') ?.split(',') - ?.map((s) => s.trim()) - ?.where((s) => s.isNotEmpty) - ?.map((str) { + .map((s) => s.trim()) + .where((s) => s.isNotEmpty) + .map((str) { // Ignore quality specifications in accept-encoding // ex. gzip;q=0.8 if (!str.contains(';')) return str; diff --git a/packages/framework/lib/src/http2/http2_response_context.dart b/packages/framework/lib/src/http2/http2_response_context.dart index 4014bd1b..a5911784 100644 --- a/packages/framework/lib/src/http2/http2_response_context.dart +++ b/packages/framework/lib/src/http2/http2_response_context.dart @@ -119,9 +119,9 @@ class Http2ResponseContext extends ResponseContext { return __allowedEncodings ??= correspondingRequest!.headers! .value('accept-encoding') ?.split(',') - ?.map((s) => s.trim()) - ?.where((s) => s.isNotEmpty) - ?.map((str) { + .map((s) => s.trim()) + .where((s) => s.isNotEmpty) + .map((str) { // Ignore quality specifications in accept-encoding // ex. gzip;q=0.8 if (!str.contains(';')) return str;