From adad0c9fff8410db7e3436cc776c544759fc927c Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Wed, 28 Jun 2023 18:10:45 +0200 Subject: [PATCH 01/31] Created module.dart where it will be possible to configure the dartness server by different parameters in a flexible way --- packages/dartness_server/lib/modules.dart | 7 ++ .../dartness_server/lib/src/dartness.dart | 85 +++++++++---------- .../lib/src/modules/module.dart | 7 ++ .../lib/src/modules/module_metadata.dart | 37 ++++++++ .../server/dartness_application_options.dart | 21 +++++ .../test/lib/src/app_module.dart | 5 ++ .../src/bind/annotation/controller_test.dart | 20 +++-- .../annotation/catch_handler_test.dart | 36 +++++--- .../exception/http_status_exception_test.dart | 19 +++-- .../src/server/dartness_interceptor_test.dart | 32 ++++--- .../src/server/dartness_middleware_test.dart | 28 ++++-- 11 files changed, 208 insertions(+), 89 deletions(-) create mode 100644 packages/dartness_server/lib/modules.dart create mode 100644 packages/dartness_server/lib/src/modules/module.dart create mode 100644 packages/dartness_server/lib/src/modules/module_metadata.dart create mode 100644 packages/dartness_server/lib/src/server/dartness_application_options.dart create mode 100644 packages/dartness_server/test/lib/src/app_module.dart diff --git a/packages/dartness_server/lib/modules.dart b/packages/dartness_server/lib/modules.dart new file mode 100644 index 00000000..9dea4224 --- /dev/null +++ b/packages/dartness_server/lib/modules.dart @@ -0,0 +1,7 @@ +/// The modules libraries of the Dartness framework. +/// +/// See documentation guides at https://ricardorb.github.io/dartness/#/. +library modules; + +export 'src/modules/module.dart'; +export 'src/modules/module_metadata.dart'; diff --git a/packages/dartness_server/lib/src/dartness.dart b/packages/dartness_server/lib/src/dartness.dart index babd4489..26b87e7a 100644 --- a/packages/dartness_server/lib/src/dartness.dart +++ b/packages/dartness_server/lib/src/dartness.dart @@ -1,7 +1,10 @@ import 'dart:io'; -import 'route/dartness_controller.dart'; +import 'package:dartness_server/modules.dart'; + import 'exception/dartness_error_handler.dart'; +import 'route/dartness_controller.dart'; +import 'server/dartness_application_options.dart'; import 'server/dartness_interceptor.dart'; import 'server/dartness_middleware.dart'; import 'server/dartness_server.dart'; @@ -13,56 +16,46 @@ import 'server/log_requests_interceptor.dart'; class Dartness { /// The [DartnessServer] that is listening for connections and requests. late final DartnessServer _server; - - /// Creates a [DefaultDartnessServer] that listens on the specified [port] and - /// [internetAddress]. - /// - /// You can also add controllers by using [controllers] optional parameter or - /// [middlewares] and [interceptors]. - Dartness({ - final int port = 8080, - final InternetAddress? internetAddress, - final Iterable controllers = const [], - final Iterable middlewares = const [], - final Iterable interceptors = const [], - final Iterable errorHandlers = const [], - }) { - _server = DefaultDartnessServer(port, internetAddress: internetAddress); - for (final controller in controllers) { - addController(controller); - } - for (final middleware in middlewares) { - addMiddleware(middleware); - } - for (final interceptor in interceptors) { - addInterceptor(interceptor); - } - for (final errorHandler in errorHandlers) { - addErrorHandler(errorHandler); - } - } + late final DartnessApplicationOptions _options; /// Starts the [_server]. /// /// If [logRequest] is true prints the time of the request, the elapsed time for the /// inner handlers, the response's status code and the request URI. - Future create({ - final bool logRequest = false, + Future create( + final Module module, { + final DartnessApplicationOptions? options, }) async { - if (logRequest) { - addInterceptor(LogRequestsInterceptor()); + _options = options ?? DartnessApplicationOptions(); + + _server = DefaultDartnessServer( + _options.port, + internetAddress: _options.internetAddress, + ); + for (final controller in module.metadata.controllers) { + _addController(controller); + } + + for (final provider in module.metadata.providers) { + if (provider is DartnessMiddleware) { + _addMiddleware(provider); + } + + if (provider is DartnessInterceptor) { + _addInterceptor(provider); + } + + if (provider is DartnessErrorHandler) { + _addErrorHandler(provider); + } + } + + if (options?.logRequest == true) { + _addInterceptor(LogRequestsInterceptor()); } await _server.start(); print('Server listening on port ${_server.getPort()}'); - } - - /// Permanently stops the [Dartness] server from listening for new - /// connections. This closes the [Stream] of [HttpRequest]s with a - /// done event. - /// - /// If [force] is `true`, active connections will be closed immediately. - Future? close({bool force = false}) { - return _server.stop(force: force); + return _server; } /// Add [controller] into [Dartness] and handles @@ -79,22 +72,22 @@ class Dartness { /// implement a [Head] handler the method must be created before the [Get] handler. /// /// throws [ArgumentError] if [controller] is not annotated with [Controller] - void addController(final DartnessController controller) { + void _addController(final DartnessController controller) { _server.addController(controller); } /// Adds a middleware in order to listen before the http request - void addMiddleware(final DartnessMiddleware middleware) { + void _addMiddleware(final DartnessMiddleware middleware) { _server.addMiddleware(middleware); } /// Adds an interceptor in order to listen between an http request - void addInterceptor(final DartnessInterceptor interceptor) { + void _addInterceptor(final DartnessInterceptor interceptor) { _server.addInterceptor(interceptor); } /// Adds an interceptor in order to listen between an http request - void addErrorHandler(final DartnessErrorHandler errorHandler) { + void _addErrorHandler(final DartnessErrorHandler errorHandler) { _server.addErrorHandler(errorHandler); } } diff --git a/packages/dartness_server/lib/src/modules/module.dart b/packages/dartness_server/lib/src/modules/module.dart new file mode 100644 index 00000000..c2cda82b --- /dev/null +++ b/packages/dartness_server/lib/src/modules/module.dart @@ -0,0 +1,7 @@ +import 'module_metadata.dart'; + +abstract class Module { + final ModuleMetadata metadata; + + const Module(this.metadata); +} diff --git a/packages/dartness_server/lib/src/modules/module_metadata.dart b/packages/dartness_server/lib/src/modules/module_metadata.dart new file mode 100644 index 00000000..03142cbc --- /dev/null +++ b/packages/dartness_server/lib/src/modules/module_metadata.dart @@ -0,0 +1,37 @@ +import 'package:dartness_server/route.dart'; + +class ModuleMetadata { + /// Optional list of imported modules that export the providers which are + /// required in this module. + final Iterable _imports; + + Iterable get imports => _imports; + + /// Optional list of controllers defined in this module which have to be + /// instantiated. + final Iterable _controllers; + + Iterable get controllers => _controllers; + + /// Optional list of providers that will be instantiated by the Dartness injector + /// and that may be shared at least across this module. + final Iterable _providers; + + Iterable get providers => _providers; + + /// Optional list of the subset of providers that are provided by this module + /// and should be available in other modules which import this module. + final Iterable _exports; + + Iterable get exports => _exports; + + const ModuleMetadata({ + final Iterable? imports, + final Iterable? controllers, + final Iterable? providers, + final Iterable? exports, + }) : _imports = imports ?? const [], + _controllers = controllers ?? const [], + _providers = providers ?? const [], + _exports = exports ?? const []; +} diff --git a/packages/dartness_server/lib/src/server/dartness_application_options.dart b/packages/dartness_server/lib/src/server/dartness_application_options.dart new file mode 100644 index 00000000..6001c8b2 --- /dev/null +++ b/packages/dartness_server/lib/src/server/dartness_application_options.dart @@ -0,0 +1,21 @@ +import 'dart:io'; + +class DartnessApplicationOptions { + final bool _logRequest; + + bool get logRequest => _logRequest; + final int _port; + + int get port => _port; + final InternetAddress _internetAddress; + + InternetAddress get internetAddress => _internetAddress; + + DartnessApplicationOptions({ + final bool logRequest = false, + final int port = 8080, + final InternetAddress? internetAddress, + }) : _logRequest = logRequest, + _port = port, + _internetAddress = internetAddress ?? InternetAddress.anyIPv4; +} diff --git a/packages/dartness_server/test/lib/src/app_module.dart b/packages/dartness_server/test/lib/src/app_module.dart new file mode 100644 index 00000000..493ed810 --- /dev/null +++ b/packages/dartness_server/test/lib/src/app_module.dart @@ -0,0 +1,5 @@ +import 'package:dartness_server/modules.dart'; + +class AppModule extends Module { + AppModule(super.metadata); +} diff --git a/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart b/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart index 8764b760..03bb00b7 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart @@ -2,9 +2,13 @@ import 'dart:convert'; import 'dart:io'; import 'package:dartness_server/dartness.dart'; +import 'package:dartness_server/modules.dart'; import 'package:dartness_server/route.dart'; +import 'package:dartness_server/server.dart'; +import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; +import '../../app_module.dart'; import 'class_controller.dart'; import 'delete_controller_class.dart'; import 'get_controller_class.dart'; @@ -47,7 +51,7 @@ void main() { }); group('http tests', () { - late Dartness dartness; + late DartnessServer dartness; const int port = 1432; late HttpClient httpClient; @@ -60,16 +64,20 @@ void main() { PutDartnessControllerClass(PutControllerClass.instance), DeleteDartnessControllerClass(DeleteControllerClass.instance), ]; + httpClient = HttpClient(); - dartness = Dartness( - port: port, - controllers: controllers, + dartness = await Dartness().create( + AppModule(ModuleMetadata( + controllers: controllers, + )), + options: DartnessApplicationOptions( + port: port, + ), ); - await dartness.create(); }); tearDown(() async { - await dartness.close(); + await dartness.stop(); }); group('GET method tests', () { diff --git a/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart b/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart index 6ac4aa09..5ad5a7bb 100644 --- a/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart +++ b/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart @@ -1,34 +1,48 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; +import 'package:dartness_server/modules.dart'; +import 'package:dartness_server/server.dart'; +import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; import 'custom_error_handler.dart'; import 'get_controller_class.dart'; +class AppModule extends Module { + AppModule(super.metadata); +} + void main() { group('http tests', () { - late Dartness dartness; + late DartnessServer dartness; const int port = 8434; late HttpClient httpClient; setUp(() async { + final controllers = [ + GetDartnessControllerClass(GetControllerClass.instance), + ]; + + final errorHandlers = [ + CustomDartnessErrorHandler(CustomErrorHandler.instance) + ]; httpClient = HttpClient(); - dartness = Dartness( - port: port, - controllers: [ - GetDartnessControllerClass(GetControllerClass.instance), - ], - errorHandlers: [ - CustomDartnessErrorHandler(CustomErrorHandler.instance) - ], + + dartness = await Dartness().create( + AppModule(ModuleMetadata( + controllers: controllers, + providers: errorHandlers, + )), + options: DartnessApplicationOptions( + port: port, + ), ); - await dartness.create(); }); tearDown(() async { - await dartness.close(); + await dartness.stop(); }); test( diff --git a/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart b/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart index 1c67920b..00fd8025 100644 --- a/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart +++ b/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart @@ -1,29 +1,32 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; +import 'package:dartness_server/modules.dart'; +import 'package:dartness_server/server.dart'; +import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; -import 'get_controller_class.dart'; +import '../app_module.dart'; void main() { group('http tests', () { - late Dartness dartness; + late DartnessServer dartness; const int port = 2314; late HttpClient httpClient; setUp(() async { httpClient = HttpClient(); - dartness = Dartness( - port: port, + dartness = await Dartness().create( + AppModule(ModuleMetadata()), + options: DartnessApplicationOptions( + port: port, + ), ); - dartness.addController( - GetDartnessControllerClass(GetControllerClass.instance)); - await dartness.create(); }); tearDown(() async { - await dartness.close(); + await dartness.stop(); }); test( diff --git a/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart b/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart index 9e12debe..d6469fd1 100644 --- a/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart +++ b/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart @@ -1,36 +1,46 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; +import 'package:dartness_server/modules.dart'; import 'package:dartness_server/server.dart'; +import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; +import '../app_module.dart'; import 'test_controller.dart'; void main() { - late Dartness dartness; + late DartnessServer dartness; const int port = 1453; late HttpClient httpClient; setUp(() async { + final controllers = [ + TestDartnessController(TestController.instance), + ]; + + final interceptors = [ + TestInterceptor(), + ]; TestInterceptor.isOnErrorCalled = false; TestInterceptor.isOnRequestCalled = false; TestInterceptor.isOnResponseCalled = false; httpClient = HttpClient(); - dartness = Dartness( - port: port, - controllers: [ - TestDartnessController(TestController.instance), - ], - interceptors: [ - TestInterceptor(), - ], + + dartness = await Dartness().create( + AppModule(ModuleMetadata( + controllers: controllers, + providers: interceptors, + )), + options: DartnessApplicationOptions( + port: port, + ), ); - await dartness.create(); }); tearDown(() async { - await dartness.close(); + await dartness.stop(); }); test( diff --git a/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart b/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart index d5c40750..7499ebf7 100644 --- a/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart +++ b/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart @@ -1,29 +1,43 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; +import 'package:dartness_server/modules.dart'; +import 'package:dartness_server/server.dart'; +import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; +import '../app_module.dart'; import 'test_controller.dart'; import 'test_middleware.dart'; void main() { - late Dartness dartness; + late DartnessServer dartness; const int port = 1243; late HttpClient httpClient; setUp(() async { + final controllers = [ + TestDartnessController(TestController.instance), + ]; + + final interceptors = [ + TestMiddleware(), + ]; httpClient = HttpClient(); - dartness = Dartness( - port: port, - controllers: [TestDartnessController(TestController.instance)], - middlewares: [TestMiddleware()], + dartness = await Dartness().create( + AppModule(ModuleMetadata( + controllers: controllers, + providers: interceptors, + )), + options: DartnessApplicationOptions( + port: port, + ), ); - await dartness.create(); }); tearDown(() async { - await dartness.close(); + await dartness.stop(); }); test( From dcea925d8372748da602c4dd1cca02b74eeb760e Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Thu, 29 Jun 2023 20:31:52 +0200 Subject: [PATCH 02/31] Init modules and defined provider.dart --- .../dartness_server/lib/src/dartness.dart | 27 ++++++++++++++----- .../src/exception/dartness_error_handler.dart | 3 ++- .../lib/src/modules/module.dart | 1 + .../lib/src/modules/module_metadata.dart | 8 +++--- .../dartness_server/lib/src/provider.dart | 1 + .../lib/src/server/dartness_interceptor.dart | 3 ++- .../lib/src/server/dartness_middleware.dart | 3 ++- 7 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 packages/dartness_server/lib/src/provider.dart diff --git a/packages/dartness_server/lib/src/dartness.dart b/packages/dartness_server/lib/src/dartness.dart index 26b87e7a..4a12143c 100644 --- a/packages/dartness_server/lib/src/dartness.dart +++ b/packages/dartness_server/lib/src/dartness.dart @@ -32,10 +32,30 @@ class Dartness { _options.port, internetAddress: _options.internetAddress, ); + _initModule(module); + + if (options?.logRequest == true) { + _addInterceptor(LogRequestsInterceptor()); + } + await _server.start(); + print('Server listening on port ${_server.getPort()}'); + return _server; + } + + /// Initializes the given [module] and its dependencies. + void _initModule(final Module module) { + for (final import in module.metadata.imports) { + _initModule(import); + } + for (final controller in module.metadata.controllers) { _addController(controller); } + _addProviders(module); + } + + void _addProviders(Module module) { for (final provider in module.metadata.providers) { if (provider is DartnessMiddleware) { _addMiddleware(provider); @@ -49,13 +69,6 @@ class Dartness { _addErrorHandler(provider); } } - - if (options?.logRequest == true) { - _addInterceptor(LogRequestsInterceptor()); - } - await _server.start(); - print('Server listening on port ${_server.getPort()}'); - return _server; } /// Add [controller] into [Dartness] and handles diff --git a/packages/dartness_server/lib/src/exception/dartness_error_handler.dart b/packages/dartness_server/lib/src/exception/dartness_error_handler.dart index 0e9fb615..517a53bf 100644 --- a/packages/dartness_server/lib/src/exception/dartness_error_handler.dart +++ b/packages/dartness_server/lib/src/exception/dartness_error_handler.dart @@ -1,9 +1,10 @@ +import '../provider.dart'; import 'dartness_catch_handler.dart'; /// A wrapper class in order to retrieve the error handler instance from the /// annotation [ErrorHandler] and the data required to handle it internally by the /// Dartness framework. -class DartnessErrorHandler { +class DartnessErrorHandler implements Provider { DartnessErrorHandler(this.errorHandler, this.catchErrors); /// The controller instance. diff --git a/packages/dartness_server/lib/src/modules/module.dart b/packages/dartness_server/lib/src/modules/module.dart index c2cda82b..db6dc4be 100644 --- a/packages/dartness_server/lib/src/modules/module.dart +++ b/packages/dartness_server/lib/src/modules/module.dart @@ -1,5 +1,6 @@ import 'module_metadata.dart'; +/// Module class that accepts different metadata abstract class Module { final ModuleMetadata metadata; diff --git a/packages/dartness_server/lib/src/modules/module_metadata.dart b/packages/dartness_server/lib/src/modules/module_metadata.dart index 03142cbc..057a112a 100644 --- a/packages/dartness_server/lib/src/modules/module_metadata.dart +++ b/packages/dartness_server/lib/src/modules/module_metadata.dart @@ -1,11 +1,13 @@ +import 'package:dartness_server/modules.dart'; import 'package:dartness_server/route.dart'; +/// Module's metadata class class ModuleMetadata { /// Optional list of imported modules that export the providers which are /// required in this module. - final Iterable _imports; + final Iterable _imports; - Iterable get imports => _imports; + Iterable get imports => _imports; /// Optional list of controllers defined in this module which have to be /// instantiated. @@ -26,7 +28,7 @@ class ModuleMetadata { Iterable get exports => _exports; const ModuleMetadata({ - final Iterable? imports, + final Iterable? imports, final Iterable? controllers, final Iterable? providers, final Iterable? exports, diff --git a/packages/dartness_server/lib/src/provider.dart b/packages/dartness_server/lib/src/provider.dart new file mode 100644 index 00000000..997ccbc8 --- /dev/null +++ b/packages/dartness_server/lib/src/provider.dart @@ -0,0 +1 @@ +abstract class Provider {} diff --git a/packages/dartness_server/lib/src/server/dartness_interceptor.dart b/packages/dartness_server/lib/src/server/dartness_interceptor.dart index 06036127..8e2cb0a2 100644 --- a/packages/dartness_server/lib/src/server/dartness_interceptor.dart +++ b/packages/dartness_server/lib/src/server/dartness_interceptor.dart @@ -1,9 +1,10 @@ +import '../provider.dart'; import 'dartness_request.dart'; import 'dartness_response.dart'; /// DartnessInterceptor is an interface in order to handle the request before it is executed /// and handle the response after the request is executed. -abstract class DartnessInterceptor { +abstract class DartnessInterceptor implements Provider { /// This method is called before the request is executed. void onRequest(final DartnessRequest request); diff --git a/packages/dartness_server/lib/src/server/dartness_middleware.dart b/packages/dartness_server/lib/src/server/dartness_middleware.dart index 902b049d..086298ee 100644 --- a/packages/dartness_server/lib/src/server/dartness_middleware.dart +++ b/packages/dartness_server/lib/src/server/dartness_middleware.dart @@ -1,8 +1,9 @@ +import '../provider.dart'; import 'dartness_request.dart'; /// DartnessInterceptor is an interface in order to handle the request before it is executed /// this can be helpful if you want to log the request or do something else before the request is executed. -abstract class DartnessMiddleware { +abstract class DartnessMiddleware implements Provider { /// This method is called before the request is executed. void handle(final DartnessRequest request); } From 06b47dc0f7d4c61fa2605ca6a3b512fef3d96b5b Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Thu, 29 Jun 2023 20:32:15 +0200 Subject: [PATCH 03/31] Code formatted --- .../dartness_server/lib/src/route/default_dartness_router.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/dartness_server/lib/src/route/default_dartness_router.dart b/packages/dartness_server/lib/src/route/default_dartness_router.dart index 9d8c3f1a..7d4dde5f 100644 --- a/packages/dartness_server/lib/src/route/default_dartness_router.dart +++ b/packages/dartness_server/lib/src/route/default_dartness_router.dart @@ -4,7 +4,6 @@ import 'controller_route.dart'; import 'dartness_router.dart'; import 'dartness_router_handler.dart'; - /// A router that can be used to handle requests. class DefaultDartnessRouter implements DartnessRouter { DefaultDartnessRouter({ From 0445bf2c885b3483a18a3453dd18ad155fe6f515 Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Sat, 8 Jul 2023 17:19:04 +0200 Subject: [PATCH 04/31] Moved libraries to their packages --- .../apps/my_app/.gitignore | 1 - packages/dartness_server/lib/exception.dart | 9 ------- packages/dartness_server/lib/route.dart | 26 ------------------- packages/dartness_server/lib/server.dart | 12 --------- .../dartness_server/lib/src/dartness.dart | 2 +- .../lib/src/exception/exception.dart | 9 +++++++ .../lib/src/modules/module_metadata.dart | 4 +-- .../lib/{ => src/modules}/modules.dart | 4 +-- .../dartness_server/lib/src/route/route.dart | 26 +++++++++++++++++++ .../lib/src/server/server.dart | 12 +++++++++ .../test/lib/src/app_module.dart | 2 +- .../src/bind/annotation/class_controller.dart | 2 +- .../src/bind/annotation/controller_test.dart | 6 ++--- .../annotation/delete_controller_class.dart | 2 +- .../bind/annotation/get_controller_class.dart | 2 +- .../annotation/post_controller_class.dart | 2 +- .../bind/annotation/put_controller_class.dart | 2 +- .../annotation/catch_handler_test.dart | 4 +-- .../annotation/custom_error_handler.dart | 4 +-- .../annotation/get_controller_class.dart | 2 +- .../example_custom_http_status_exception.dart | 2 +- .../src/exception/get_controller_class.dart | 2 +- .../exception/http_status_exception_test.dart | 4 +-- .../src/server/dartness_interceptor_test.dart | 4 +-- .../src/server/dartness_middleware_test.dart | 4 +-- .../test/lib/src/server/test_controller.dart | 2 +- .../test/lib/src/server/test_middleware.dart | 2 +- 27 files changed, 76 insertions(+), 77 deletions(-) delete mode 100644 packages/dartness_server/lib/exception.dart delete mode 100644 packages/dartness_server/lib/route.dart delete mode 100644 packages/dartness_server/lib/server.dart create mode 100644 packages/dartness_server/lib/src/exception/exception.dart rename packages/dartness_server/lib/{ => src/modules}/modules.dart (65%) create mode 100644 packages/dartness_server/lib/src/route/route.dart create mode 100644 packages/dartness_server/lib/src/server/server.dart diff --git a/examples/dartness_flutter_melos/apps/my_app/.gitignore b/examples/dartness_flutter_melos/apps/my_app/.gitignore index a8e938c0..1eab1a22 100644 --- a/examples/dartness_flutter_melos/apps/my_app/.gitignore +++ b/examples/dartness_flutter_melos/apps/my_app/.gitignore @@ -33,7 +33,6 @@ migrate_working_dir/ /build/ # Web related -lib/generated_plugin_registrant.dart # Symbolication related app.*.symbols diff --git a/packages/dartness_server/lib/exception.dart b/packages/dartness_server/lib/exception.dart deleted file mode 100644 index 31cf6acb..00000000 --- a/packages/dartness_server/lib/exception.dart +++ /dev/null @@ -1,9 +0,0 @@ -/// Library that exposes the API for the exceptions -library exception; - -export 'src/exception/annotation/catch_error.dart'; -export 'src/exception/annotation/error_handler.dart'; -export 'src/exception/dartness_catch_handler.dart'; -export 'src/exception/dartness_error_handler.dart'; -export 'src/exception/dartness_error_handler_register.dart'; -export 'src/exception/http_status_exception.dart'; diff --git a/packages/dartness_server/lib/route.dart b/packages/dartness_server/lib/route.dart deleted file mode 100644 index ec23688e..00000000 --- a/packages/dartness_server/lib/route.dart +++ /dev/null @@ -1,26 +0,0 @@ -/// Library that exposes the API for the route -library route; - -export 'src/bind/annotation/bind.dart'; -export 'src/bind/annotation/body.dart'; -export 'src/bind/annotation/connect.dart'; -export 'src/bind/annotation/controller.dart'; -export 'src/bind/annotation/delete.dart'; -export 'src/bind/annotation/get.dart'; -export 'src/bind/annotation/head.dart'; -export 'src/bind/annotation/header.dart'; -export 'src/bind/annotation/headers.dart'; -export 'src/bind/annotation/http_status.dart'; -export 'src/bind/annotation/options.dart'; -export 'src/bind/annotation/patch.dart'; -export 'src/bind/annotation/path_param.dart'; -export 'src/bind/annotation/post.dart'; -export 'src/bind/annotation/put.dart'; -export 'src/bind/annotation/query_param.dart'; -export 'src/bind/annotation/trace.dart'; -export 'src/route/controller_route.dart'; -export 'src/route/dartness_controller.dart'; -export 'src/route/dartness_param.dart'; -export 'src/route/dartness_router.dart'; -export 'src/route/dartness_router_handler.dart'; -export 'src/route/default_dartness_router.dart'; diff --git a/packages/dartness_server/lib/server.dart b/packages/dartness_server/lib/server.dart deleted file mode 100644 index 88c98fe6..00000000 --- a/packages/dartness_server/lib/server.dart +++ /dev/null @@ -1,12 +0,0 @@ -/// Library that exposes the API for the server -library server; - -export 'src/server/dartness_interceptor.dart'; -export 'src/server/dartness_middleware.dart'; -export 'src/server/dartness_pipeline.dart'; -export 'src/server/dartness_request.dart'; -export 'src/server/dartness_response.dart'; -export 'src/server/dartness_server.dart'; -export 'src/server/default_dartness_pipeline.dart'; -export 'src/server/default_dartness_server.dart'; -export 'src/server/log_requests_interceptor.dart'; diff --git a/packages/dartness_server/lib/src/dartness.dart b/packages/dartness_server/lib/src/dartness.dart index 4a12143c..5a16e3f7 100644 --- a/packages/dartness_server/lib/src/dartness.dart +++ b/packages/dartness_server/lib/src/dartness.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'package:dartness_server/modules.dart'; +import 'package:dartness_server/src/modules/modules.dart'; import 'exception/dartness_error_handler.dart'; import 'route/dartness_controller.dart'; diff --git a/packages/dartness_server/lib/src/exception/exception.dart b/packages/dartness_server/lib/src/exception/exception.dart new file mode 100644 index 00000000..59522abd --- /dev/null +++ b/packages/dartness_server/lib/src/exception/exception.dart @@ -0,0 +1,9 @@ +/// Library that exposes the API for the exceptions +library exception; + +export 'annotation/catch_error.dart'; +export 'annotation/error_handler.dart'; +export 'dartness_catch_handler.dart'; +export 'dartness_error_handler.dart'; +export 'dartness_error_handler_register.dart'; +export 'http_status_exception.dart'; diff --git a/packages/dartness_server/lib/src/modules/module_metadata.dart b/packages/dartness_server/lib/src/modules/module_metadata.dart index 057a112a..665f8ef3 100644 --- a/packages/dartness_server/lib/src/modules/module_metadata.dart +++ b/packages/dartness_server/lib/src/modules/module_metadata.dart @@ -1,5 +1,5 @@ -import 'package:dartness_server/modules.dart'; -import 'package:dartness_server/route.dart'; +import 'package:dartness_server/src/modules/modules.dart'; +import 'package:dartness_server/src/route/route.dart'; /// Module's metadata class class ModuleMetadata { diff --git a/packages/dartness_server/lib/modules.dart b/packages/dartness_server/lib/src/modules/modules.dart similarity index 65% rename from packages/dartness_server/lib/modules.dart rename to packages/dartness_server/lib/src/modules/modules.dart index 9dea4224..40982fa6 100644 --- a/packages/dartness_server/lib/modules.dart +++ b/packages/dartness_server/lib/src/modules/modules.dart @@ -3,5 +3,5 @@ /// See documentation guides at https://ricardorb.github.io/dartness/#/. library modules; -export 'src/modules/module.dart'; -export 'src/modules/module_metadata.dart'; +export 'module.dart'; +export 'module_metadata.dart'; diff --git a/packages/dartness_server/lib/src/route/route.dart b/packages/dartness_server/lib/src/route/route.dart new file mode 100644 index 00000000..c73a3dcb --- /dev/null +++ b/packages/dartness_server/lib/src/route/route.dart @@ -0,0 +1,26 @@ +/// Library that exposes the API for the route +library route; + +export '../bind/annotation/bind.dart'; +export '../bind/annotation/body.dart'; +export '../bind/annotation/connect.dart'; +export '../bind/annotation/controller.dart'; +export '../bind/annotation/delete.dart'; +export '../bind/annotation/get.dart'; +export '../bind/annotation/head.dart'; +export '../bind/annotation/header.dart'; +export '../bind/annotation/headers.dart'; +export '../bind/annotation/http_status.dart'; +export '../bind/annotation/options.dart'; +export '../bind/annotation/patch.dart'; +export '../bind/annotation/path_param.dart'; +export '../bind/annotation/post.dart'; +export '../bind/annotation/put.dart'; +export '../bind/annotation/query_param.dart'; +export '../bind/annotation/trace.dart'; +export 'controller_route.dart'; +export 'dartness_controller.dart'; +export 'dartness_param.dart'; +export 'dartness_router.dart'; +export 'dartness_router_handler.dart'; +export 'default_dartness_router.dart'; diff --git a/packages/dartness_server/lib/src/server/server.dart b/packages/dartness_server/lib/src/server/server.dart new file mode 100644 index 00000000..330dc7e1 --- /dev/null +++ b/packages/dartness_server/lib/src/server/server.dart @@ -0,0 +1,12 @@ +/// Library that exposes the API for the server +library server; + +export 'dartness_interceptor.dart'; +export 'dartness_middleware.dart'; +export 'dartness_pipeline.dart'; +export 'dartness_request.dart'; +export 'dartness_response.dart'; +export 'dartness_server.dart'; +export 'default_dartness_pipeline.dart'; +export 'default_dartness_server.dart'; +export 'log_requests_interceptor.dart'; diff --git a/packages/dartness_server/test/lib/src/app_module.dart b/packages/dartness_server/test/lib/src/app_module.dart index 493ed810..c829b9b5 100644 --- a/packages/dartness_server/test/lib/src/app_module.dart +++ b/packages/dartness_server/test/lib/src/app_module.dart @@ -1,4 +1,4 @@ -import 'package:dartness_server/modules.dart'; +import 'package:dartness_server/src/modules/modules.dart'; class AppModule extends Module { AppModule(super.metadata); diff --git a/packages/dartness_server/test/lib/src/bind/annotation/class_controller.dart b/packages/dartness_server/test/lib/src/bind/annotation/class_controller.dart index 082b8dbc..e1628470 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/class_controller.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/class_controller.dart @@ -1,4 +1,4 @@ -import 'package:dartness_server/route.dart'; +import 'package:dartness_server/src/route/route.dart'; part 'class_controller.g.dart'; diff --git a/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart b/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart index 03bb00b7..b6409e6c 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart @@ -2,9 +2,9 @@ import 'dart:convert'; import 'dart:io'; import 'package:dartness_server/dartness.dart'; -import 'package:dartness_server/modules.dart'; -import 'package:dartness_server/route.dart'; -import 'package:dartness_server/server.dart'; +import 'package:dartness_server/src/modules/modules.dart'; +import 'package:dartness_server/src/route/route.dart'; +import 'package:dartness_server/src/server/server.dart'; import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; diff --git a/packages/dartness_server/test/lib/src/bind/annotation/delete_controller_class.dart b/packages/dartness_server/test/lib/src/bind/annotation/delete_controller_class.dart index 26063ce1..c6ca17ab 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/delete_controller_class.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/delete_controller_class.dart @@ -1,4 +1,4 @@ -import 'package:dartness_server/route.dart'; +import 'package:dartness_server/src/route/route.dart'; import 'foo.dart'; diff --git a/packages/dartness_server/test/lib/src/bind/annotation/get_controller_class.dart b/packages/dartness_server/test/lib/src/bind/annotation/get_controller_class.dart index 8b8bbc97..544baf7e 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/get_controller_class.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/get_controller_class.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'package:dartness_server/route.dart'; +import 'package:dartness_server/src/route/route.dart'; import 'foo.dart'; diff --git a/packages/dartness_server/test/lib/src/bind/annotation/post_controller_class.dart b/packages/dartness_server/test/lib/src/bind/annotation/post_controller_class.dart index 631f222a..e3629722 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/post_controller_class.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/post_controller_class.dart @@ -1,4 +1,4 @@ -import 'package:dartness_server/route.dart'; +import 'package:dartness_server/src/route/route.dart'; import 'foo.dart'; diff --git a/packages/dartness_server/test/lib/src/bind/annotation/put_controller_class.dart b/packages/dartness_server/test/lib/src/bind/annotation/put_controller_class.dart index b0416a54..d393ede5 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/put_controller_class.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/put_controller_class.dart @@ -1,4 +1,4 @@ -import 'package:dartness_server/route.dart'; +import 'package:dartness_server/src/route/route.dart'; import 'foo.dart'; diff --git a/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart b/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart index 5ad5a7bb..f35052ab 100644 --- a/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart +++ b/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart @@ -1,8 +1,8 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; -import 'package:dartness_server/modules.dart'; -import 'package:dartness_server/server.dart'; +import 'package:dartness_server/src/modules/modules.dart'; +import 'package:dartness_server/src/server/server.dart'; import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; diff --git a/packages/dartness_server/test/lib/src/exception/annotation/custom_error_handler.dart b/packages/dartness_server/test/lib/src/exception/annotation/custom_error_handler.dart index 2ff4972f..17462fd4 100644 --- a/packages/dartness_server/test/lib/src/exception/annotation/custom_error_handler.dart +++ b/packages/dartness_server/test/lib/src/exception/annotation/custom_error_handler.dart @@ -1,7 +1,7 @@ import 'dart:io'; -import 'package:dartness_server/exception.dart'; -import 'package:dartness_server/server.dart'; +import 'package:dartness_server/src/exception/exception.dart'; +import 'package:dartness_server/src/server/server.dart'; part 'custom_error_handler.g.dart'; diff --git a/packages/dartness_server/test/lib/src/exception/annotation/get_controller_class.dart b/packages/dartness_server/test/lib/src/exception/annotation/get_controller_class.dart index f5a58713..5710928b 100644 --- a/packages/dartness_server/test/lib/src/exception/annotation/get_controller_class.dart +++ b/packages/dartness_server/test/lib/src/exception/annotation/get_controller_class.dart @@ -1,4 +1,4 @@ -import 'package:dartness_server/route.dart'; +import 'package:dartness_server/src/route/route.dart'; part 'get_controller_class.g.dart'; diff --git a/packages/dartness_server/test/lib/src/exception/example_custom_http_status_exception.dart b/packages/dartness_server/test/lib/src/exception/example_custom_http_status_exception.dart index 32d7eeed..80372efd 100644 --- a/packages/dartness_server/test/lib/src/exception/example_custom_http_status_exception.dart +++ b/packages/dartness_server/test/lib/src/exception/example_custom_http_status_exception.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'package:dartness_server/exception.dart'; +import 'package:dartness_server/src/exception/exception.dart'; class ExampleCustomHttpStatusException extends HttpStatusException { const ExampleCustomHttpStatusException(String message) diff --git a/packages/dartness_server/test/lib/src/exception/get_controller_class.dart b/packages/dartness_server/test/lib/src/exception/get_controller_class.dart index 8c9fe860..e4f89d70 100644 --- a/packages/dartness_server/test/lib/src/exception/get_controller_class.dart +++ b/packages/dartness_server/test/lib/src/exception/get_controller_class.dart @@ -1,4 +1,4 @@ -import 'package:dartness_server/route.dart'; +import 'package:dartness_server/src/route/route.dart'; import 'example_custom_http_status_exception.dart'; diff --git a/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart b/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart index 00fd8025..f47b6806 100644 --- a/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart +++ b/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart @@ -1,8 +1,8 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; -import 'package:dartness_server/modules.dart'; -import 'package:dartness_server/server.dart'; +import 'package:dartness_server/src/modules/modules.dart'; +import 'package:dartness_server/src/server/server.dart'; import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; diff --git a/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart b/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart index d6469fd1..6993ee8b 100644 --- a/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart +++ b/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart @@ -1,8 +1,8 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; -import 'package:dartness_server/modules.dart'; -import 'package:dartness_server/server.dart'; +import 'package:dartness_server/src/modules/modules.dart'; +import 'package:dartness_server/src/server/server.dart'; import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; diff --git a/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart b/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart index 7499ebf7..d13d7b60 100644 --- a/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart +++ b/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart @@ -1,8 +1,8 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; -import 'package:dartness_server/modules.dart'; -import 'package:dartness_server/server.dart'; +import 'package:dartness_server/src/modules/modules.dart'; +import 'package:dartness_server/src/server/server.dart'; import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; diff --git a/packages/dartness_server/test/lib/src/server/test_controller.dart b/packages/dartness_server/test/lib/src/server/test_controller.dart index 616d1cad..f8fb0f58 100644 --- a/packages/dartness_server/test/lib/src/server/test_controller.dart +++ b/packages/dartness_server/test/lib/src/server/test_controller.dart @@ -1,4 +1,4 @@ -import 'package:dartness_server/route.dart'; +import 'package:dartness_server/src/route/route.dart'; part 'test_controller.g.dart'; diff --git a/packages/dartness_server/test/lib/src/server/test_middleware.dart b/packages/dartness_server/test/lib/src/server/test_middleware.dart index 26ca8adb..492d8068 100644 --- a/packages/dartness_server/test/lib/src/server/test_middleware.dart +++ b/packages/dartness_server/test/lib/src/server/test_middleware.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'package:dartness_server/server.dart'; +import 'package:dartness_server/src/server/server.dart'; class TestMiddleware implements DartnessMiddleware { @override From 4f34f2c6a940c1060b470d409a8593f3ab739a5c Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Tue, 11 Jul 2023 16:30:28 +0200 Subject: [PATCH 05/31] - Updated dependencies - Updated example simple - Moved library to root - Builders into builder.dart --- examples/dartness_simple/bin/example.dart | 26 +------- examples/dartness_simple/lib/src/app.dart | 27 ++++++++ .../src/controllers/city_controller.g.dart | 63 +++++++++++++------ .../example_error_handler.g.dart | 11 +++- examples/dartness_simple/pubspec.yaml | 10 +-- packages/dartness_generator/build.yaml | 8 +-- packages/dartness_generator/lib/builder.dart | 11 ++++ .../lib/dartness_generator.dart | 12 +--- packages/dartness_generator/pubspec.yaml | 16 ++--- packages/dartness_server/lib/exception.dart | 9 +++ .../lib/{src/modules => }/modules.dart | 4 +- packages/dartness_server/lib/route.dart | 26 ++++++++ packages/dartness_server/lib/server.dart | 12 ++++ .../lib/src/bind/annotation/controller.dart | 2 +- .../dartness_server/lib/src/dartness.dart | 2 +- .../lib/src/exception/exception.dart | 9 --- .../lib/src/modules/module_metadata.dart | 4 +- .../dartness_server/lib/src/route/route.dart | 26 -------- .../lib/src/server/server.dart | 12 ---- packages/dartness_server/pubspec.yaml | 7 ++- .../test/lib/src/app_module.dart | 2 +- .../src/bind/annotation/class_controller.dart | 2 +- .../src/bind/annotation/controller_test.dart | 6 +- .../annotation/delete_controller_class.dart | 2 +- .../bind/annotation/get_controller_class.dart | 2 +- .../annotation/post_controller_class.dart | 2 +- .../bind/annotation/put_controller_class.dart | 2 +- .../annotation/catch_handler_test.dart | 4 +- .../annotation/custom_error_handler.dart | 4 +- .../annotation/get_controller_class.dart | 2 +- .../example_custom_http_status_exception.dart | 2 +- .../src/exception/get_controller_class.dart | 2 +- .../exception/http_status_exception_test.dart | 4 +- .../src/server/dartness_interceptor_test.dart | 4 +- .../src/server/dartness_middleware_test.dart | 4 +- .../test/lib/src/server/test_controller.dart | 2 +- .../test/lib/src/server/test_middleware.dart | 2 +- 37 files changed, 193 insertions(+), 152 deletions(-) create mode 100644 examples/dartness_simple/lib/src/app.dart create mode 100644 packages/dartness_generator/lib/builder.dart create mode 100644 packages/dartness_server/lib/exception.dart rename packages/dartness_server/lib/{src/modules => }/modules.dart (65%) create mode 100644 packages/dartness_server/lib/route.dart create mode 100644 packages/dartness_server/lib/server.dart delete mode 100644 packages/dartness_server/lib/src/exception/exception.dart delete mode 100644 packages/dartness_server/lib/src/route/route.dart delete mode 100644 packages/dartness_server/lib/src/server/server.dart diff --git a/examples/dartness_simple/bin/example.dart b/examples/dartness_simple/bin/example.dart index a0381c34..46576e19 100644 --- a/examples/dartness_simple/bin/example.dart +++ b/examples/dartness_simple/bin/example.dart @@ -1,27 +1,5 @@ -import 'package:dartness_server/dartness.dart'; -import 'package:example/src/controllers/city_controller.dart'; -import 'package:example/src/error_handlers/example_error_handler.dart'; -import 'package:example/src/interceptors/example_interceptor.dart'; -import 'package:example/src/middlewares/example_middleware.dart'; -import 'package:example/src/services/city_service.dart'; +import 'package:example/src/app.dart'; void main(List args) async { - final controllers = [ - CityDartnessController(CityController(CityService())), - ]; - final errorHandlers = [ - ExampleDartnessErrorHandler(ExampleErrorHandler()), - ]; - final app = Dartness( - port: 3000, - controllers: controllers, - errorHandlers: errorHandlers, - middlewares: [ - ExampleMiddleware(), - ], - interceptors: [ - ExampleInterceptor(), - ], - ); - app.create(); + await App().main(); } diff --git a/examples/dartness_simple/lib/src/app.dart b/examples/dartness_simple/lib/src/app.dart new file mode 100644 index 00000000..6b734a7a --- /dev/null +++ b/examples/dartness_simple/lib/src/app.dart @@ -0,0 +1,27 @@ +import 'package:dartness_server/dartness.dart'; +import 'package:dartness_server/modules.dart'; + +import 'controllers/city_controller.dart'; +import 'error_handlers/example_error_handler.dart'; +import 'services/city_service.dart'; + +class App { + Future main() async { + final app = Dartness(); + await app.create(AppModule()); + } +} + +class AppModule implements Module { + @override + ModuleMetadata get metadata => ModuleMetadata( + controllers: [ + CityDartnessController(CityController(CityService())), + ], + providers: [ + ExampleDartnessErrorHandler(ExampleErrorHandler()), + ], + exports: [], + imports: [], + ); +} diff --git a/examples/dartness_simple/lib/src/controllers/city_controller.g.dart b/examples/dartness_simple/lib/src/controllers/city_controller.g.dart index 72abd8fd..23adc595 100644 --- a/examples/dartness_simple/lib/src/controllers/city_controller.g.dart +++ b/examples/dartness_simple/lib/src/controllers/city_controller.g.dart @@ -10,30 +10,55 @@ extension CityControllerRoutes on CityController { List getRoutes() { final routes = []; routes.add(ControllerRoute( - 'GET', - '/cities', - getCities, - [ - DartnessParam('offset', true, false, false, true, false, true, int, - defaultValue: '100', fromJson: null) - ], - httpCode: 202, - headers: {})); + 'GET', + '/cities', + getCities, + [ + DartnessParam( + 'offset', + true, + false, + false, + true, + false, + true, + int, + defaultValue: '100', + fromJson: null, + ) + ], + httpCode: 202, + headers: {}, + )); routes.add(ControllerRoute( - 'GET', - '/cities/', - getCity, - [ - DartnessParam('id', false, true, false, false, true, false, int, - defaultValue: null, fromJson: null) - ], - httpCode: null, - headers: {'content-type': 'application/json'})); + 'GET', + '/cities/', + getCity, + [ + DartnessParam( + 'id', + false, + true, + false, + false, + true, + false, + int, + defaultValue: null, + fromJson: null, + ) + ], + httpCode: null, + headers: {'content-type': 'application/json'}, + )); return routes; } } class CityDartnessController extends DartnessController { CityDartnessController(CityController controller) - : super(controller, controller.getRoutes()); + : super( + controller, + controller.getRoutes(), + ); } diff --git a/examples/dartness_simple/lib/src/error_handlers/example_error_handler.g.dart b/examples/dartness_simple/lib/src/error_handlers/example_error_handler.g.dart index dda11ba6..15abaaec 100644 --- a/examples/dartness_simple/lib/src/error_handlers/example_error_handler.g.dart +++ b/examples/dartness_simple/lib/src/error_handlers/example_error_handler.g.dart @@ -9,13 +9,18 @@ part of 'example_error_handler.dart'; extension ExampleErrorHandlerCatchers on ExampleErrorHandler { List getCatchErrors() { final catchErrorHandlers = []; - catchErrorHandlers - .add(DartnessCatchError([NotFoundException], handleNotFoundException)); + catchErrorHandlers.add(DartnessCatchError( + [NotFoundException], + handleNotFoundException, + )); return catchErrorHandlers; } } class ExampleDartnessErrorHandler extends DartnessErrorHandler { ExampleDartnessErrorHandler(ExampleErrorHandler errorHandler) - : super(errorHandler, errorHandler.getCatchErrors()); + : super( + errorHandler, + errorHandler.getCatchErrors(), + ); } diff --git a/examples/dartness_simple/pubspec.yaml b/examples/dartness_simple/pubspec.yaml index 9ed8a8dd..e441302c 100644 --- a/examples/dartness_simple/pubspec.yaml +++ b/examples/dartness_simple/pubspec.yaml @@ -9,10 +9,12 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: - dartness_server: ^0.4.4-alpha + dartness_server: + path: ../../packages/dartness_server dev_dependencies: lints: ^2.1.1 - test: ^1.24.3 - build_runner: ^2.4.5 - dartness_generator: ^0.1.1-alpha + test: ^1.24.4 + build_runner: ^2.4.6 + dartness_generator: + path: ../../packages/dartness_generator diff --git a/packages/dartness_generator/build.yaml b/packages/dartness_generator/build.yaml index fa0b6273..15a2abd4 100644 --- a/packages/dartness_generator/build.yaml +++ b/packages/dartness_generator/build.yaml @@ -1,17 +1,17 @@ builders: controller: target: ":controller_generator" - import: "package:dartness_generator/dartness_generator.dart" + import: "package:dartness_generator/builder.dart" builder_factories: [ "controller" ] - build_extensions: { ".dart": [ ".dartness.g.part" ] } + build_extensions: { ".dart": [ ".g.part" ] } auto_apply: dependents build_to: cache applies_builders: [ "source_gen|combining_builder" ] error_handler: target: ":error_handler_generator" - import: "package:dartness_generator/dartness_generator.dart" + import: "package:dartness_generator/builder.dart" builder_factories: [ "errorHandler" ] - build_extensions: { ".dart": [ ".dartness.g.part" ] } + build_extensions: { ".dart": [ ".g.part" ] } auto_apply: dependents build_to: cache applies_builders: [ "source_gen|combining_builder" ] \ No newline at end of file diff --git a/packages/dartness_generator/lib/builder.dart b/packages/dartness_generator/lib/builder.dart new file mode 100644 index 00000000..1ceb411b --- /dev/null +++ b/packages/dartness_generator/lib/builder.dart @@ -0,0 +1,11 @@ +import 'package:build/build.dart'; +import 'package:source_gen/source_gen.dart'; + +import 'src/controller_generator.dart'; +import 'src/error_handler_generator.dart'; + +Builder controller(BuilderOptions options) => + SharedPartBuilder([ControllerGenerator()], 'controller'); + +Builder errorHandler(BuilderOptions options) => + SharedPartBuilder([ErrorHandlerGenerator()], 'error_handler'); diff --git a/packages/dartness_generator/lib/dartness_generator.dart b/packages/dartness_generator/lib/dartness_generator.dart index 1ceb411b..0823b4ff 100644 --- a/packages/dartness_generator/lib/dartness_generator.dart +++ b/packages/dartness_generator/lib/dartness_generator.dart @@ -1,11 +1 @@ -import 'package:build/build.dart'; -import 'package:source_gen/source_gen.dart'; - -import 'src/controller_generator.dart'; -import 'src/error_handler_generator.dart'; - -Builder controller(BuilderOptions options) => - SharedPartBuilder([ControllerGenerator()], 'controller'); - -Builder errorHandler(BuilderOptions options) => - SharedPartBuilder([ErrorHandlerGenerator()], 'error_handler'); +library dartness_generator; diff --git a/packages/dartness_generator/pubspec.yaml b/packages/dartness_generator/pubspec.yaml index 03a70237..1e36e4b1 100644 --- a/packages/dartness_generator/pubspec.yaml +++ b/packages/dartness_generator/pubspec.yaml @@ -1,6 +1,6 @@ name: dartness_generator description: Dartness generator provides the generator classes that are used to run dartness_server -version: 0.1.2-alpha +version: 0.4.6-alpha homepage: https://ricardorb.github.io/dartness/ repository: https://github.com/RicardoRB/dartness issue_tracker: https://github.com/RicardoRB/dartness/issues @@ -10,13 +10,15 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: - build: ^2.4.0 - source_gen: ^1.3.2 - analyzer: ^5.13.0 + build: ^2.4.1 + source_gen: ^1.4.0 + analyzer: ^6.0.0 code_builder: ^4.5.0 - dartness_server: 0.4.5-alpha + dartness_server: + path: ../dartness_server dev_dependencies: lints: ^2.1.1 - build_runner: ^2.4.5 - test: ^1.24.3 + build_runner: ^2.4.6 + test: ^1.24.4 + source_gen_test: ^1.0.6 diff --git a/packages/dartness_server/lib/exception.dart b/packages/dartness_server/lib/exception.dart new file mode 100644 index 00000000..31cf6acb --- /dev/null +++ b/packages/dartness_server/lib/exception.dart @@ -0,0 +1,9 @@ +/// Library that exposes the API for the exceptions +library exception; + +export 'src/exception/annotation/catch_error.dart'; +export 'src/exception/annotation/error_handler.dart'; +export 'src/exception/dartness_catch_handler.dart'; +export 'src/exception/dartness_error_handler.dart'; +export 'src/exception/dartness_error_handler_register.dart'; +export 'src/exception/http_status_exception.dart'; diff --git a/packages/dartness_server/lib/src/modules/modules.dart b/packages/dartness_server/lib/modules.dart similarity index 65% rename from packages/dartness_server/lib/src/modules/modules.dart rename to packages/dartness_server/lib/modules.dart index 40982fa6..9dea4224 100644 --- a/packages/dartness_server/lib/src/modules/modules.dart +++ b/packages/dartness_server/lib/modules.dart @@ -3,5 +3,5 @@ /// See documentation guides at https://ricardorb.github.io/dartness/#/. library modules; -export 'module.dart'; -export 'module_metadata.dart'; +export 'src/modules/module.dart'; +export 'src/modules/module_metadata.dart'; diff --git a/packages/dartness_server/lib/route.dart b/packages/dartness_server/lib/route.dart new file mode 100644 index 00000000..ec23688e --- /dev/null +++ b/packages/dartness_server/lib/route.dart @@ -0,0 +1,26 @@ +/// Library that exposes the API for the route +library route; + +export 'src/bind/annotation/bind.dart'; +export 'src/bind/annotation/body.dart'; +export 'src/bind/annotation/connect.dart'; +export 'src/bind/annotation/controller.dart'; +export 'src/bind/annotation/delete.dart'; +export 'src/bind/annotation/get.dart'; +export 'src/bind/annotation/head.dart'; +export 'src/bind/annotation/header.dart'; +export 'src/bind/annotation/headers.dart'; +export 'src/bind/annotation/http_status.dart'; +export 'src/bind/annotation/options.dart'; +export 'src/bind/annotation/patch.dart'; +export 'src/bind/annotation/path_param.dart'; +export 'src/bind/annotation/post.dart'; +export 'src/bind/annotation/put.dart'; +export 'src/bind/annotation/query_param.dart'; +export 'src/bind/annotation/trace.dart'; +export 'src/route/controller_route.dart'; +export 'src/route/dartness_controller.dart'; +export 'src/route/dartness_param.dart'; +export 'src/route/dartness_router.dart'; +export 'src/route/dartness_router_handler.dart'; +export 'src/route/default_dartness_router.dart'; diff --git a/packages/dartness_server/lib/server.dart b/packages/dartness_server/lib/server.dart new file mode 100644 index 00000000..88c98fe6 --- /dev/null +++ b/packages/dartness_server/lib/server.dart @@ -0,0 +1,12 @@ +/// Library that exposes the API for the server +library server; + +export 'src/server/dartness_interceptor.dart'; +export 'src/server/dartness_middleware.dart'; +export 'src/server/dartness_pipeline.dart'; +export 'src/server/dartness_request.dart'; +export 'src/server/dartness_response.dart'; +export 'src/server/dartness_server.dart'; +export 'src/server/default_dartness_pipeline.dart'; +export 'src/server/default_dartness_server.dart'; +export 'src/server/log_requests_interceptor.dart'; diff --git a/packages/dartness_server/lib/src/bind/annotation/controller.dart b/packages/dartness_server/lib/src/bind/annotation/controller.dart index 971425bb..56ccd271 100644 --- a/packages/dartness_server/lib/src/bind/annotation/controller.dart +++ b/packages/dartness_server/lib/src/bind/annotation/controller.dart @@ -8,7 +8,7 @@ /// ```dart /// @Controller('/') /// class ExampleController { -/// @Bind.get() +/// @Get() /// String get() { /// return 'Hello World!'; /// } diff --git a/packages/dartness_server/lib/src/dartness.dart b/packages/dartness_server/lib/src/dartness.dart index 5a16e3f7..4a12143c 100644 --- a/packages/dartness_server/lib/src/dartness.dart +++ b/packages/dartness_server/lib/src/dartness.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'package:dartness_server/src/modules/modules.dart'; +import 'package:dartness_server/modules.dart'; import 'exception/dartness_error_handler.dart'; import 'route/dartness_controller.dart'; diff --git a/packages/dartness_server/lib/src/exception/exception.dart b/packages/dartness_server/lib/src/exception/exception.dart deleted file mode 100644 index 59522abd..00000000 --- a/packages/dartness_server/lib/src/exception/exception.dart +++ /dev/null @@ -1,9 +0,0 @@ -/// Library that exposes the API for the exceptions -library exception; - -export 'annotation/catch_error.dart'; -export 'annotation/error_handler.dart'; -export 'dartness_catch_handler.dart'; -export 'dartness_error_handler.dart'; -export 'dartness_error_handler_register.dart'; -export 'http_status_exception.dart'; diff --git a/packages/dartness_server/lib/src/modules/module_metadata.dart b/packages/dartness_server/lib/src/modules/module_metadata.dart index 665f8ef3..057a112a 100644 --- a/packages/dartness_server/lib/src/modules/module_metadata.dart +++ b/packages/dartness_server/lib/src/modules/module_metadata.dart @@ -1,5 +1,5 @@ -import 'package:dartness_server/src/modules/modules.dart'; -import 'package:dartness_server/src/route/route.dart'; +import 'package:dartness_server/modules.dart'; +import 'package:dartness_server/route.dart'; /// Module's metadata class class ModuleMetadata { diff --git a/packages/dartness_server/lib/src/route/route.dart b/packages/dartness_server/lib/src/route/route.dart deleted file mode 100644 index c73a3dcb..00000000 --- a/packages/dartness_server/lib/src/route/route.dart +++ /dev/null @@ -1,26 +0,0 @@ -/// Library that exposes the API for the route -library route; - -export '../bind/annotation/bind.dart'; -export '../bind/annotation/body.dart'; -export '../bind/annotation/connect.dart'; -export '../bind/annotation/controller.dart'; -export '../bind/annotation/delete.dart'; -export '../bind/annotation/get.dart'; -export '../bind/annotation/head.dart'; -export '../bind/annotation/header.dart'; -export '../bind/annotation/headers.dart'; -export '../bind/annotation/http_status.dart'; -export '../bind/annotation/options.dart'; -export '../bind/annotation/patch.dart'; -export '../bind/annotation/path_param.dart'; -export '../bind/annotation/post.dart'; -export '../bind/annotation/put.dart'; -export '../bind/annotation/query_param.dart'; -export '../bind/annotation/trace.dart'; -export 'controller_route.dart'; -export 'dartness_controller.dart'; -export 'dartness_param.dart'; -export 'dartness_router.dart'; -export 'dartness_router_handler.dart'; -export 'default_dartness_router.dart'; diff --git a/packages/dartness_server/lib/src/server/server.dart b/packages/dartness_server/lib/src/server/server.dart deleted file mode 100644 index 330dc7e1..00000000 --- a/packages/dartness_server/lib/src/server/server.dart +++ /dev/null @@ -1,12 +0,0 @@ -/// Library that exposes the API for the server -library server; - -export 'dartness_interceptor.dart'; -export 'dartness_middleware.dart'; -export 'dartness_pipeline.dart'; -export 'dartness_request.dart'; -export 'dartness_response.dart'; -export 'dartness_server.dart'; -export 'default_dartness_pipeline.dart'; -export 'default_dartness_server.dart'; -export 'log_requests_interceptor.dart'; diff --git a/packages/dartness_server/pubspec.yaml b/packages/dartness_server/pubspec.yaml index efa74c02..fb0a08ad 100644 --- a/packages/dartness_server/pubspec.yaml +++ b/packages/dartness_server/pubspec.yaml @@ -19,10 +19,11 @@ dependencies: shelf: ^1.4.1 shelf_plus: ^1.7.0 shelf_router: ^1.1.4 + injector: ^3.0.0 dev_dependencies: - http: ^0.13.5 + http: ^1.1.0 lints: ^2.1.1 - test: ^1.24.3 - build_runner: ^2.4.5 + test: ^1.24.4 + build_runner: ^2.4.6 dartness_generator: ^0.1.0-alpha \ No newline at end of file diff --git a/packages/dartness_server/test/lib/src/app_module.dart b/packages/dartness_server/test/lib/src/app_module.dart index c829b9b5..493ed810 100644 --- a/packages/dartness_server/test/lib/src/app_module.dart +++ b/packages/dartness_server/test/lib/src/app_module.dart @@ -1,4 +1,4 @@ -import 'package:dartness_server/src/modules/modules.dart'; +import 'package:dartness_server/modules.dart'; class AppModule extends Module { AppModule(super.metadata); diff --git a/packages/dartness_server/test/lib/src/bind/annotation/class_controller.dart b/packages/dartness_server/test/lib/src/bind/annotation/class_controller.dart index e1628470..082b8dbc 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/class_controller.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/class_controller.dart @@ -1,4 +1,4 @@ -import 'package:dartness_server/src/route/route.dart'; +import 'package:dartness_server/route.dart'; part 'class_controller.g.dart'; diff --git a/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart b/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart index b6409e6c..03bb00b7 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart @@ -2,9 +2,9 @@ import 'dart:convert'; import 'dart:io'; import 'package:dartness_server/dartness.dart'; -import 'package:dartness_server/src/modules/modules.dart'; -import 'package:dartness_server/src/route/route.dart'; -import 'package:dartness_server/src/server/server.dart'; +import 'package:dartness_server/modules.dart'; +import 'package:dartness_server/route.dart'; +import 'package:dartness_server/server.dart'; import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; diff --git a/packages/dartness_server/test/lib/src/bind/annotation/delete_controller_class.dart b/packages/dartness_server/test/lib/src/bind/annotation/delete_controller_class.dart index c6ca17ab..26063ce1 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/delete_controller_class.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/delete_controller_class.dart @@ -1,4 +1,4 @@ -import 'package:dartness_server/src/route/route.dart'; +import 'package:dartness_server/route.dart'; import 'foo.dart'; diff --git a/packages/dartness_server/test/lib/src/bind/annotation/get_controller_class.dart b/packages/dartness_server/test/lib/src/bind/annotation/get_controller_class.dart index 544baf7e..8b8bbc97 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/get_controller_class.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/get_controller_class.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'package:dartness_server/src/route/route.dart'; +import 'package:dartness_server/route.dart'; import 'foo.dart'; diff --git a/packages/dartness_server/test/lib/src/bind/annotation/post_controller_class.dart b/packages/dartness_server/test/lib/src/bind/annotation/post_controller_class.dart index e3629722..631f222a 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/post_controller_class.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/post_controller_class.dart @@ -1,4 +1,4 @@ -import 'package:dartness_server/src/route/route.dart'; +import 'package:dartness_server/route.dart'; import 'foo.dart'; diff --git a/packages/dartness_server/test/lib/src/bind/annotation/put_controller_class.dart b/packages/dartness_server/test/lib/src/bind/annotation/put_controller_class.dart index d393ede5..b0416a54 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/put_controller_class.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/put_controller_class.dart @@ -1,4 +1,4 @@ -import 'package:dartness_server/src/route/route.dart'; +import 'package:dartness_server/route.dart'; import 'foo.dart'; diff --git a/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart b/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart index f35052ab..5ad5a7bb 100644 --- a/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart +++ b/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart @@ -1,8 +1,8 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; -import 'package:dartness_server/src/modules/modules.dart'; -import 'package:dartness_server/src/server/server.dart'; +import 'package:dartness_server/modules.dart'; +import 'package:dartness_server/server.dart'; import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; diff --git a/packages/dartness_server/test/lib/src/exception/annotation/custom_error_handler.dart b/packages/dartness_server/test/lib/src/exception/annotation/custom_error_handler.dart index 17462fd4..2ff4972f 100644 --- a/packages/dartness_server/test/lib/src/exception/annotation/custom_error_handler.dart +++ b/packages/dartness_server/test/lib/src/exception/annotation/custom_error_handler.dart @@ -1,7 +1,7 @@ import 'dart:io'; -import 'package:dartness_server/src/exception/exception.dart'; -import 'package:dartness_server/src/server/server.dart'; +import 'package:dartness_server/exception.dart'; +import 'package:dartness_server/server.dart'; part 'custom_error_handler.g.dart'; diff --git a/packages/dartness_server/test/lib/src/exception/annotation/get_controller_class.dart b/packages/dartness_server/test/lib/src/exception/annotation/get_controller_class.dart index 5710928b..f5a58713 100644 --- a/packages/dartness_server/test/lib/src/exception/annotation/get_controller_class.dart +++ b/packages/dartness_server/test/lib/src/exception/annotation/get_controller_class.dart @@ -1,4 +1,4 @@ -import 'package:dartness_server/src/route/route.dart'; +import 'package:dartness_server/route.dart'; part 'get_controller_class.g.dart'; diff --git a/packages/dartness_server/test/lib/src/exception/example_custom_http_status_exception.dart b/packages/dartness_server/test/lib/src/exception/example_custom_http_status_exception.dart index 80372efd..32d7eeed 100644 --- a/packages/dartness_server/test/lib/src/exception/example_custom_http_status_exception.dart +++ b/packages/dartness_server/test/lib/src/exception/example_custom_http_status_exception.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'package:dartness_server/src/exception/exception.dart'; +import 'package:dartness_server/exception.dart'; class ExampleCustomHttpStatusException extends HttpStatusException { const ExampleCustomHttpStatusException(String message) diff --git a/packages/dartness_server/test/lib/src/exception/get_controller_class.dart b/packages/dartness_server/test/lib/src/exception/get_controller_class.dart index e4f89d70..8c9fe860 100644 --- a/packages/dartness_server/test/lib/src/exception/get_controller_class.dart +++ b/packages/dartness_server/test/lib/src/exception/get_controller_class.dart @@ -1,4 +1,4 @@ -import 'package:dartness_server/src/route/route.dart'; +import 'package:dartness_server/route.dart'; import 'example_custom_http_status_exception.dart'; diff --git a/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart b/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart index f47b6806..00fd8025 100644 --- a/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart +++ b/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart @@ -1,8 +1,8 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; -import 'package:dartness_server/src/modules/modules.dart'; -import 'package:dartness_server/src/server/server.dart'; +import 'package:dartness_server/modules.dart'; +import 'package:dartness_server/server.dart'; import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; diff --git a/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart b/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart index 6993ee8b..d6469fd1 100644 --- a/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart +++ b/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart @@ -1,8 +1,8 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; -import 'package:dartness_server/src/modules/modules.dart'; -import 'package:dartness_server/src/server/server.dart'; +import 'package:dartness_server/modules.dart'; +import 'package:dartness_server/server.dart'; import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; diff --git a/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart b/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart index d13d7b60..7499ebf7 100644 --- a/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart +++ b/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart @@ -1,8 +1,8 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; -import 'package:dartness_server/src/modules/modules.dart'; -import 'package:dartness_server/src/server/server.dart'; +import 'package:dartness_server/modules.dart'; +import 'package:dartness_server/server.dart'; import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; diff --git a/packages/dartness_server/test/lib/src/server/test_controller.dart b/packages/dartness_server/test/lib/src/server/test_controller.dart index f8fb0f58..616d1cad 100644 --- a/packages/dartness_server/test/lib/src/server/test_controller.dart +++ b/packages/dartness_server/test/lib/src/server/test_controller.dart @@ -1,4 +1,4 @@ -import 'package:dartness_server/src/route/route.dart'; +import 'package:dartness_server/route.dart'; part 'test_controller.g.dart'; diff --git a/packages/dartness_server/test/lib/src/server/test_middleware.dart b/packages/dartness_server/test/lib/src/server/test_middleware.dart index 492d8068..26ca8adb 100644 --- a/packages/dartness_server/test/lib/src/server/test_middleware.dart +++ b/packages/dartness_server/test/lib/src/server/test_middleware.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'package:dartness_server/src/server/server.dart'; +import 'package:dartness_server/server.dart'; class TestMiddleware implements DartnessMiddleware { @override From 7c624e89bb1748c89cc9b126308c624ce44692d1 Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Tue, 11 Jul 2023 16:48:59 +0200 Subject: [PATCH 06/31] Updated class attributes and generator --- .../src/controllers/city_controller.g.dart | 48 +- .../lib/src/controller_generator.dart | 32 +- .../lib/src/route/controller_route.dart | 10 +- .../lib/src/route/dartness_param.dart | 18 +- packages/dartness_server/pubspec.yaml | 3 +- .../bind/annotation/class_controller.g.dart | 45 +- .../annotation/delete_controller_class.g.dart | 74 ++- .../annotation/get_controller_class.g.dart | 456 +++++++++++++----- .../annotation/post_controller_class.g.dart | 103 ++-- .../annotation/put_controller_class.g.dart | 74 ++- .../annotation/custom_error_handler.g.dart | 16 +- .../annotation/get_controller_class.g.dart | 24 +- .../src/exception/get_controller_class.g.dart | 14 +- .../lib/src/server/test_controller.g.dart | 25 +- 14 files changed, 685 insertions(+), 257 deletions(-) diff --git a/examples/dartness_simple/lib/src/controllers/city_controller.g.dart b/examples/dartness_simple/lib/src/controllers/city_controller.g.dart index 23adc595..594e5a1c 100644 --- a/examples/dartness_simple/lib/src/controllers/city_controller.g.dart +++ b/examples/dartness_simple/lib/src/controllers/city_controller.g.dart @@ -10,19 +10,19 @@ extension CityControllerRoutes on CityController { List getRoutes() { final routes = []; routes.add(ControllerRoute( - 'GET', - '/cities', - getCities, - [ + method: 'GET', + path: '/cities', + handler: getCities, + params: [ DartnessParam( - 'offset', - true, - false, - false, - true, - false, - true, - int, + name: 'offset', + isQuery: true, + isPath: false, + isBody: false, + isNamed: true, + isPositional: false, + isOptional: true, + type: int, defaultValue: '100', fromJson: null, ) @@ -31,19 +31,19 @@ extension CityControllerRoutes on CityController { headers: {}, )); routes.add(ControllerRoute( - 'GET', - '/cities/', - getCity, - [ + method: 'GET', + path: '/cities/', + handler: getCity, + params: [ DartnessParam( - 'id', - false, - true, - false, - false, - true, - false, - int, + name: 'id', + isQuery: false, + isPath: true, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: int, defaultValue: null, fromJson: null, ) diff --git a/packages/dartness_generator/lib/src/controller_generator.dart b/packages/dartness_generator/lib/src/controller_generator.dart index a5d0a018..911366fd 100644 --- a/packages/dartness_generator/lib/src/controller_generator.dart +++ b/packages/dartness_generator/lib/src/controller_generator.dart @@ -115,12 +115,11 @@ class ControllerGenerator extends GeneratorForAnnotation { final paramRefer = _paramElementToParamRef(param); arguments.add(paramRefer); } - final methodRef = refer((ControllerRoute).toString()).newInstance([ - literalString(bindMethod), - literalString(path), - refer(methodElement.name), - literalList(arguments), - ], { + final methodRef = refer((ControllerRoute).toString()).newInstance([], { + 'method': literalString(bindMethod), + 'path': literalString(path), + 'handler': refer(methodElement.name), + 'params': literalList(arguments), 'httpCode': literal(httpCode), 'headers': literalMap(headers), }); @@ -216,19 +215,18 @@ class ControllerGenerator extends GeneratorForAnnotation { name = param.name; } return refer((DartnessParam).toString()).newInstance( - [ - literalString(name), - literalBool(isQuery), - literalBool(isPath), - literalBool(isBody), - literalBool(param.isNamed), - literalBool(param.isPositional), - literalBool(param.isOptional), - CodeExpression(Code(param.type.getDisplayString( + [], + { + 'name': literalString(name), + 'isQuery': literalBool(isQuery), + 'isPath': literalBool(isPath), + 'isBody': literalBool(isBody), + 'isNamed': literalBool(param.isNamed), + 'isPositional': literalBool(param.isPositional), + 'isOptional': literalBool(param.isOptional), + 'type': CodeExpression(Code(param.type.getDisplayString( withNullability: false, ))), - ], - { 'defaultValue': literal(param.defaultValueCode), 'fromJson': isBody ? refer(param.type.getDisplayString( diff --git a/packages/dartness_server/lib/src/route/controller_route.dart b/packages/dartness_server/lib/src/route/controller_route.dart index de0a9422..2fed9da2 100644 --- a/packages/dartness_server/lib/src/route/controller_route.dart +++ b/packages/dartness_server/lib/src/route/controller_route.dart @@ -3,11 +3,11 @@ import 'dartness_param.dart'; /// The data required to handle the class annotated with [Controller] /// internally by the Dartness framework. class ControllerRoute { - const ControllerRoute( - this.method, - this.path, - this.handler, - this.params, { + const ControllerRoute({ + required this.method, + required this.path, + required this.handler, + required this.params, this.httpCode, this.headers, }); diff --git a/packages/dartness_server/lib/src/route/dartness_param.dart b/packages/dartness_server/lib/src/route/dartness_param.dart index 52bc39e5..be052358 100644 --- a/packages/dartness_server/lib/src/route/dartness_param.dart +++ b/packages/dartness_server/lib/src/route/dartness_param.dart @@ -1,15 +1,15 @@ /// The param data from the route method required to handle the class /// annotated with [Controller] internally by the Dartness framework. class DartnessParam { - DartnessParam( - this.name, - this.isQuery, - this.isPath, - this.isBody, - this.isNamed, - this.isPositional, - this.isOptional, - this.type, { + DartnessParam({ + required this.name, + required this.isQuery, + required this.isPath, + required this.isBody, + required this.isNamed, + required this.isPositional, + required this.isOptional, + required this.type, this.defaultValue, this.fromJson, }); diff --git a/packages/dartness_server/pubspec.yaml b/packages/dartness_server/pubspec.yaml index fb0a08ad..2500c124 100644 --- a/packages/dartness_server/pubspec.yaml +++ b/packages/dartness_server/pubspec.yaml @@ -26,4 +26,5 @@ dev_dependencies: lints: ^2.1.1 test: ^1.24.4 build_runner: ^2.4.6 - dartness_generator: ^0.1.0-alpha \ No newline at end of file + dartness_generator: + path: ../dartness_generator \ No newline at end of file diff --git a/packages/dartness_server/test/lib/src/bind/annotation/class_controller.g.dart b/packages/dartness_server/test/lib/src/bind/annotation/class_controller.g.dart index 836ae13a..8d0a53d1 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/class_controller.g.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/class_controller.g.dart @@ -9,19 +9,46 @@ part of 'class_controller.dart'; extension ClassControllerRoutes on ClassController { List getRoutes() { final routes = []; - routes.add( - ControllerRoute('GET', '/', getEmpty, [], httpCode: null, headers: {})); - routes.add(ControllerRoute('POST', '/', postEmpty, [], - httpCode: null, headers: {})); - routes.add( - ControllerRoute('PUT', '/', putEmpty, [], httpCode: null, headers: {})); - routes.add(ControllerRoute('DELETE', '/', deleteEmpty, [], - httpCode: null, headers: {})); + routes.add(ControllerRoute( + method: 'GET', + path: '/', + handler: getEmpty, + params: [], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'POST', + path: '/', + handler: postEmpty, + params: [], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'PUT', + path: '/', + handler: putEmpty, + params: [], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'DELETE', + path: '/', + handler: deleteEmpty, + params: [], + httpCode: null, + headers: {}, + )); return routes; } } class ClassDartnessController extends DartnessController { ClassDartnessController(ClassController controller) - : super(controller, controller.getRoutes()); + : super( + controller, + controller.getRoutes(), + ); } diff --git a/packages/dartness_server/test/lib/src/bind/annotation/delete_controller_class.g.dart b/packages/dartness_server/test/lib/src/bind/annotation/delete_controller_class.g.dart index 66ff6802..277a51cd 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/delete_controller_class.g.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/delete_controller_class.g.dart @@ -9,29 +9,67 @@ part of 'delete_controller_class.dart'; extension DeleteControllerClassRoutes on DeleteControllerClass { List getRoutes() { final routes = []; - routes.add(ControllerRoute('DELETE', '/delete/double', deleteDouble, [], - httpCode: null, headers: {})); - routes.add(ControllerRoute('DELETE', '/delete/null', deleteNull, [], - httpCode: null, headers: {})); - routes.add(ControllerRoute('DELETE', '/delete/class', deleteClass, [], - httpCode: null, headers: {})); - routes.add(ControllerRoute('DELETE', '/delete/future', deleteFuture, [], - httpCode: null, headers: {})); routes.add(ControllerRoute( - 'DELETE', - '/delete/ids/', - deleteParam, - [ - DartnessParam('id', false, true, false, false, true, false, int, - defaultValue: null, fromJson: null) - ], - httpCode: null, - headers: {})); + method: 'DELETE', + path: '/delete/double', + handler: deleteDouble, + params: [], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'DELETE', + path: '/delete/null', + handler: deleteNull, + params: [], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'DELETE', + path: '/delete/class', + handler: deleteClass, + params: [], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'DELETE', + path: '/delete/future', + handler: deleteFuture, + params: [], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'DELETE', + path: '/delete/ids/', + handler: deleteParam, + params: [ + DartnessParam( + name: 'id', + isQuery: false, + isPath: true, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: int, + defaultValue: null, + fromJson: null, + ) + ], + httpCode: null, + headers: {}, + )); return routes; } } class DeleteDartnessControllerClass extends DartnessController { DeleteDartnessControllerClass(DeleteControllerClass controller) - : super(controller, controller.getRoutes()); + : super( + controller, + controller.getRoutes(), + ); } diff --git a/packages/dartness_server/test/lib/src/bind/annotation/get_controller_class.g.dart b/packages/dartness_server/test/lib/src/bind/annotation/get_controller_class.g.dart index cfbdcf08..8faae33c 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/get_controller_class.g.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/get_controller_class.g.dart @@ -9,130 +9,362 @@ part of 'get_controller_class.dart'; extension GetControllerClassRoutes on GetControllerClass { List getRoutes() { final routes = []; - routes.add(ControllerRoute('GET', '/get/double', getDouble, [], - httpCode: null, headers: {})); - routes.add(ControllerRoute('GET', '/get/null', getNull, [], - httpCode: null, headers: {})); - routes.add(ControllerRoute('GET', '/get/class', getClass, [], - httpCode: null, headers: {})); - routes.add(ControllerRoute('GET', '/get/future', getFuture, [], - httpCode: null, headers: {})); routes.add(ControllerRoute( - 'GET', - '/get/ids/', - getParam, - [ - DartnessParam('id', false, true, false, false, true, false, int, - defaultValue: null, fromJson: null) - ], - httpCode: null, - headers: {})); + method: 'GET', + path: '/get/double', + handler: getDouble, + params: [], + httpCode: null, + headers: {}, + )); routes.add(ControllerRoute( - 'GET', - '/get/query', - getQuery, - [ - DartnessParam('id', true, false, false, false, true, false, int, - defaultValue: null, fromJson: null) - ], - httpCode: null, - headers: {})); + method: 'GET', + path: '/get/null', + handler: getNull, + params: [], + httpCode: null, + headers: {}, + )); routes.add(ControllerRoute( - 'GET', - '/get/queries', - getQueries, - [ - DartnessParam('id', true, false, false, false, true, false, int, - defaultValue: null, fromJson: null), - DartnessParam('id2', true, false, false, false, true, false, int, - defaultValue: null, fromJson: null) - ], - httpCode: null, - headers: {})); + method: 'GET', + path: '/get/class', + handler: getClass, + params: [], + httpCode: null, + headers: {}, + )); routes.add(ControllerRoute( - 'GET', - '/get/paths/', - getPaths, - [ - DartnessParam('id', false, true, false, false, true, false, int, - defaultValue: null, fromJson: null), - DartnessParam('query', true, false, false, false, true, false, int, - defaultValue: null, fromJson: null) - ], - httpCode: null, - headers: {})); + method: 'GET', + path: '/get/future', + handler: getFuture, + params: [], + httpCode: null, + headers: {}, + )); routes.add(ControllerRoute( - 'GET', - '/get/paths//another/', - getPathsAnotherPaths, - [ - DartnessParam('path1', false, true, false, false, true, false, int, - defaultValue: null, fromJson: null), - DartnessParam('query', true, false, false, false, true, false, int, - defaultValue: null, fromJson: null), - DartnessParam('path2', false, true, false, false, true, false, int, - defaultValue: null, fromJson: null), - DartnessParam('query2', true, false, false, false, true, false, int, - defaultValue: null, fromJson: null) - ], - httpCode: null, - headers: {})); + method: 'GET', + path: '/get/ids/', + handler: getParam, + params: [ + DartnessParam( + name: 'id', + isQuery: false, + isPath: true, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: int, + defaultValue: null, + fromJson: null, + ) + ], + httpCode: null, + headers: {}, + )); routes.add(ControllerRoute( - 'GET', - '/get/types', - getTypes, - [ - DartnessParam('bool', true, false, false, false, true, false, bool, - defaultValue: null, fromJson: null), - DartnessParam('int', true, false, false, false, true, false, int, - defaultValue: null, fromJson: null), - DartnessParam( - 'double', true, false, false, false, true, false, double, - defaultValue: null, fromJson: null), - DartnessParam( - 'string', true, false, false, false, true, false, String, - defaultValue: null, fromJson: null), - DartnessParam( - 'list', true, false, false, false, true, false, List, - defaultValue: null, fromJson: null) - ], - httpCode: null, - headers: {})); + method: 'GET', + path: '/get/query', + handler: getQuery, + params: [ + DartnessParam( + name: 'id', + isQuery: true, + isPath: false, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: int, + defaultValue: null, + fromJson: null, + ) + ], + httpCode: null, + headers: {}, + )); routes.add(ControllerRoute( - 'GET', - '/get/optional', - getOptional, - [ - DartnessParam('bool', true, false, false, false, true, false, bool, - defaultValue: null, fromJson: null), - DartnessParam('int', true, false, false, true, false, true, int, - defaultValue: '1', fromJson: null) - ], - httpCode: null, - headers: {})); + method: 'GET', + path: '/get/queries', + handler: getQueries, + params: [ + DartnessParam( + name: 'id', + isQuery: true, + isPath: false, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: int, + defaultValue: null, + fromJson: null, + ), + DartnessParam( + name: 'id2', + isQuery: true, + isPath: false, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: int, + defaultValue: null, + fromJson: null, + ), + ], + httpCode: null, + headers: {}, + )); routes.add(ControllerRoute( - 'GET', - '/get/names/', - getNames, - [ - DartnessParam( - 'namePath', false, true, false, false, true, false, String, - defaultValue: null, fromJson: null), - DartnessParam( - 'nameQuery', true, false, false, false, true, false, String, - defaultValue: null, fromJson: null) - ], - httpCode: null, - headers: {})); - routes.add(ControllerRoute('GET', '/get/statuscodes', getStatusCode, [], - httpCode: 202, headers: {})); - routes.add(ControllerRoute('GET', '/get/headers', getHeader, [], - httpCode: null, headers: {'test': 'test'})); + method: 'GET', + path: '/get/paths/', + handler: getPaths, + params: [ + DartnessParam( + name: 'id', + isQuery: false, + isPath: true, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: int, + defaultValue: null, + fromJson: null, + ), + DartnessParam( + name: 'query', + isQuery: true, + isPath: false, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: int, + defaultValue: null, + fromJson: null, + ), + ], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'GET', + path: '/get/paths//another/', + handler: getPathsAnotherPaths, + params: [ + DartnessParam( + name: 'path1', + isQuery: false, + isPath: true, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: int, + defaultValue: null, + fromJson: null, + ), + DartnessParam( + name: 'query', + isQuery: true, + isPath: false, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: int, + defaultValue: null, + fromJson: null, + ), + DartnessParam( + name: 'path2', + isQuery: false, + isPath: true, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: int, + defaultValue: null, + fromJson: null, + ), + DartnessParam( + name: 'query2', + isQuery: true, + isPath: false, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: int, + defaultValue: null, + fromJson: null, + ), + ], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'GET', + path: '/get/types', + handler: getTypes, + params: [ + DartnessParam( + name: 'bool', + isQuery: true, + isPath: false, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: bool, + defaultValue: null, + fromJson: null, + ), + DartnessParam( + name: 'int', + isQuery: true, + isPath: false, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: int, + defaultValue: null, + fromJson: null, + ), + DartnessParam( + name: 'double', + isQuery: true, + isPath: false, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: double, + defaultValue: null, + fromJson: null, + ), + DartnessParam( + name: 'string', + isQuery: true, + isPath: false, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: String, + defaultValue: null, + fromJson: null, + ), + DartnessParam( + name: 'list', + isQuery: true, + isPath: false, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: List, + defaultValue: null, + fromJson: null, + ), + ], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'GET', + path: '/get/optional', + handler: getOptional, + params: [ + DartnessParam( + name: 'bool', + isQuery: true, + isPath: false, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: bool, + defaultValue: null, + fromJson: null, + ), + DartnessParam( + name: 'int', + isQuery: true, + isPath: false, + isBody: false, + isNamed: true, + isPositional: false, + isOptional: true, + type: int, + defaultValue: '1', + fromJson: null, + ), + ], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'GET', + path: '/get/names/', + handler: getNames, + params: [ + DartnessParam( + name: 'namePath', + isQuery: false, + isPath: true, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: String, + defaultValue: null, + fromJson: null, + ), + DartnessParam( + name: 'nameQuery', + isQuery: true, + isPath: false, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: String, + defaultValue: null, + fromJson: null, + ), + ], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'GET', + path: '/get/statuscodes', + handler: getStatusCode, + params: [], + httpCode: 202, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'GET', + path: '/get/headers', + handler: getHeader, + params: [], + httpCode: null, + headers: {'test': 'test'}, + )); return routes; } } class GetDartnessControllerClass extends DartnessController { GetDartnessControllerClass(GetControllerClass controller) - : super(controller, controller.getRoutes()); + : super( + controller, + controller.getRoutes(), + ); } diff --git a/packages/dartness_server/test/lib/src/bind/annotation/post_controller_class.g.dart b/packages/dartness_server/test/lib/src/bind/annotation/post_controller_class.g.dart index fcaa88c7..7fa47558 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/post_controller_class.g.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/post_controller_class.g.dart @@ -9,39 +9,88 @@ part of 'post_controller_class.dart'; extension PostControllerClassRoutes on PostControllerClass { List getRoutes() { final routes = []; - routes.add(ControllerRoute('POST', '/post/double', postDouble, [], - httpCode: null, headers: {})); - routes.add(ControllerRoute('POST', '/post/null', postNull, [], - httpCode: null, headers: {})); - routes.add(ControllerRoute('POST', '/post/class', postClass, [], - httpCode: null, headers: {})); - routes.add(ControllerRoute('POST', '/post/future', postFuture, [], - httpCode: null, headers: {})); routes.add(ControllerRoute( - 'POST', - '/post/ids/', - postParam, - [ - DartnessParam('id', false, true, false, false, true, false, int, - defaultValue: null, fromJson: null) - ], - httpCode: null, - headers: {})); + method: 'POST', + path: '/post/double', + handler: postDouble, + params: [], + httpCode: null, + headers: {}, + )); routes.add(ControllerRoute( - 'POST', - '/post/body', - postBody, - [ - DartnessParam('body', false, false, true, false, true, false, Foo, - defaultValue: null, fromJson: Foo.fromJson) - ], - httpCode: null, - headers: {})); + method: 'POST', + path: '/post/null', + handler: postNull, + params: [], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'POST', + path: '/post/class', + handler: postClass, + params: [], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'POST', + path: '/post/future', + handler: postFuture, + params: [], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'POST', + path: '/post/ids/', + handler: postParam, + params: [ + DartnessParam( + name: 'id', + isQuery: false, + isPath: true, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: int, + defaultValue: null, + fromJson: null, + ) + ], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'POST', + path: '/post/body', + handler: postBody, + params: [ + DartnessParam( + name: 'body', + isQuery: false, + isPath: false, + isBody: true, + isNamed: false, + isPositional: true, + isOptional: false, + type: Foo, + defaultValue: null, + fromJson: Foo.fromJson, + ) + ], + httpCode: null, + headers: {}, + )); return routes; } } class PostDartnessControllerClass extends DartnessController { PostDartnessControllerClass(PostControllerClass controller) - : super(controller, controller.getRoutes()); + : super( + controller, + controller.getRoutes(), + ); } diff --git a/packages/dartness_server/test/lib/src/bind/annotation/put_controller_class.g.dart b/packages/dartness_server/test/lib/src/bind/annotation/put_controller_class.g.dart index 9f7ad5db..725e76f6 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/put_controller_class.g.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/put_controller_class.g.dart @@ -9,29 +9,67 @@ part of 'put_controller_class.dart'; extension PutControllerClassRoutes on PutControllerClass { List getRoutes() { final routes = []; - routes.add(ControllerRoute('PUT', '/put/double', putDouble, [], - httpCode: null, headers: {})); - routes.add(ControllerRoute('PUT', '/put/null', putNull, [], - httpCode: null, headers: {})); - routes.add(ControllerRoute('PUT', '/put/class', putClass, [], - httpCode: null, headers: {})); - routes.add(ControllerRoute('PUT', '/put/future', putFuture, [], - httpCode: null, headers: {})); routes.add(ControllerRoute( - 'PUT', - '/put/ids/', - putParam, - [ - DartnessParam('id', false, true, false, false, true, false, int, - defaultValue: null, fromJson: null) - ], - httpCode: null, - headers: {})); + method: 'PUT', + path: '/put/double', + handler: putDouble, + params: [], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'PUT', + path: '/put/null', + handler: putNull, + params: [], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'PUT', + path: '/put/class', + handler: putClass, + params: [], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'PUT', + path: '/put/future', + handler: putFuture, + params: [], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'PUT', + path: '/put/ids/', + handler: putParam, + params: [ + DartnessParam( + name: 'id', + isQuery: false, + isPath: true, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: int, + defaultValue: null, + fromJson: null, + ) + ], + httpCode: null, + headers: {}, + )); return routes; } } class PutDartnessControllerClass extends DartnessController { PutDartnessControllerClass(PutControllerClass controller) - : super(controller, controller.getRoutes()); + : super( + controller, + controller.getRoutes(), + ); } diff --git a/packages/dartness_server/test/lib/src/exception/annotation/custom_error_handler.g.dart b/packages/dartness_server/test/lib/src/exception/annotation/custom_error_handler.g.dart index 382442b6..7595a19d 100644 --- a/packages/dartness_server/test/lib/src/exception/annotation/custom_error_handler.g.dart +++ b/packages/dartness_server/test/lib/src/exception/annotation/custom_error_handler.g.dart @@ -9,14 +9,22 @@ part of 'custom_error_handler.dart'; extension CustomErrorHandlerCatchers on CustomErrorHandler { List getCatchErrors() { final catchErrorHandlers = []; - catchErrorHandlers - .add(DartnessCatchError([ArgumentError], argumentErrorHandler)); - catchErrorHandlers.add(DartnessCatchError([RangeError], rangeErrorHandler)); + catchErrorHandlers.add(DartnessCatchError( + [ArgumentError], + argumentErrorHandler, + )); + catchErrorHandlers.add(DartnessCatchError( + [RangeError], + rangeErrorHandler, + )); return catchErrorHandlers; } } class CustomDartnessErrorHandler extends DartnessErrorHandler { CustomDartnessErrorHandler(CustomErrorHandler errorHandler) - : super(errorHandler, errorHandler.getCatchErrors()); + : super( + errorHandler, + errorHandler.getCatchErrors(), + ); } diff --git a/packages/dartness_server/test/lib/src/exception/annotation/get_controller_class.g.dart b/packages/dartness_server/test/lib/src/exception/annotation/get_controller_class.g.dart index 3fce106f..3696e9a6 100644 --- a/packages/dartness_server/test/lib/src/exception/annotation/get_controller_class.g.dart +++ b/packages/dartness_server/test/lib/src/exception/annotation/get_controller_class.g.dart @@ -10,15 +10,29 @@ extension GetControllerClassRoutes on GetControllerClass { List getRoutes() { final routes = []; routes.add(ControllerRoute( - 'GET', '/get/argument_error', getArgumentException, [], - httpCode: null, headers: {})); - routes.add(ControllerRoute('GET', '/get/range_error', getRangeError, [], - httpCode: null, headers: {})); + method: 'GET', + path: '/get/argument_error', + handler: getArgumentException, + params: [], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'GET', + path: '/get/range_error', + handler: getRangeError, + params: [], + httpCode: null, + headers: {}, + )); return routes; } } class GetDartnessControllerClass extends DartnessController { GetDartnessControllerClass(GetControllerClass controller) - : super(controller, controller.getRoutes()); + : super( + controller, + controller.getRoutes(), + ); } diff --git a/packages/dartness_server/test/lib/src/exception/get_controller_class.g.dart b/packages/dartness_server/test/lib/src/exception/get_controller_class.g.dart index 8695631b..7ecf8a1e 100644 --- a/packages/dartness_server/test/lib/src/exception/get_controller_class.g.dart +++ b/packages/dartness_server/test/lib/src/exception/get_controller_class.g.dart @@ -10,13 +10,21 @@ extension GetControllerClassRoutes on GetControllerClass { List getRoutes() { final routes = []; routes.add(ControllerRoute( - 'GET', '/get/custom_exception', getCustomException, [], - httpCode: null, headers: {})); + method: 'GET', + path: '/get/custom_exception', + handler: getCustomException, + params: [], + httpCode: null, + headers: {}, + )); return routes; } } class GetDartnessControllerClass extends DartnessController { GetDartnessControllerClass(GetControllerClass controller) - : super(controller, controller.getRoutes()); + : super( + controller, + controller.getRoutes(), + ); } diff --git a/packages/dartness_server/test/lib/src/server/test_controller.g.dart b/packages/dartness_server/test/lib/src/server/test_controller.g.dart index dd4ebe85..2a3d54d3 100644 --- a/packages/dartness_server/test/lib/src/server/test_controller.g.dart +++ b/packages/dartness_server/test/lib/src/server/test_controller.g.dart @@ -9,15 +9,30 @@ part of 'test_controller.dart'; extension TestControllerRoutes on TestController { List getRoutes() { final routes = []; - routes.add( - ControllerRoute('GET', '/auth', get, [], httpCode: null, headers: {})); - routes.add(ControllerRoute('GET', '/auth/error', getError, [], - httpCode: null, headers: {})); + routes.add(ControllerRoute( + method: 'GET', + path: '/auth', + handler: get, + params: [], + httpCode: null, + headers: {}, + )); + routes.add(ControllerRoute( + method: 'GET', + path: '/auth/error', + handler: getError, + params: [], + httpCode: null, + headers: {}, + )); return routes; } } class TestDartnessController extends DartnessController { TestDartnessController(TestController controller) - : super(controller, controller.getRoutes()); + : super( + controller, + controller.getRoutes(), + ); } From 346be0cc6d0f123a37c950f8529d230616be2dd5 Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Wed, 12 Jul 2023 14:39:44 +0200 Subject: [PATCH 07/31] Init dependencies topologically into inject register --- examples/dartness_simple/bin/example.dart | 2 +- examples/dartness_simple/build.dart | 54 ++++++++ examples/dartness_simple/lib/app_module.dart | 12 ++ examples/dartness_simple/lib/src/app.dart | 38 +++--- examples/dartness_simple/lib/src/app.g.dart | 18 +++ packages/dartness_generator/build.yaml | 8 ++ packages/dartness_generator/lib/builder.dart | 4 + .../lib/src/application_generator.dart | 115 ++++++++++++++++++ packages/dartness_generator/pubspec.yaml | 1 + packages/dartness_server/lib/dartness.dart | 2 + .../lib/src/app/application.dart | 12 ++ .../lib/src/app/instance_register.dart | 35 ++++++ .../dartness_server/lib/src/dartness.dart | 60 +++++---- .../lib/src/modules/module.dart | 4 +- .../lib/src/modules/module_metadata.dart | 31 ++--- .../server/dartness_application_options.dart | 9 +- .../test/lib/src/app_module.dart | 2 +- .../src/bind/annotation/controller_test.dart | 10 +- .../annotation/catch_handler_test.dart | 15 +-- .../exception/http_status_exception_test.dart | 6 +- .../src/server/dartness_interceptor_test.dart | 12 +- .../src/server/dartness_middleware_test.dart | 12 +- 22 files changed, 354 insertions(+), 108 deletions(-) create mode 100644 examples/dartness_simple/build.dart create mode 100644 examples/dartness_simple/lib/app_module.dart create mode 100644 examples/dartness_simple/lib/src/app.g.dart create mode 100644 packages/dartness_generator/lib/src/application_generator.dart create mode 100644 packages/dartness_server/lib/src/app/application.dart create mode 100644 packages/dartness_server/lib/src/app/instance_register.dart diff --git a/examples/dartness_simple/bin/example.dart b/examples/dartness_simple/bin/example.dart index 46576e19..ac2a9137 100644 --- a/examples/dartness_simple/bin/example.dart +++ b/examples/dartness_simple/bin/example.dart @@ -1,5 +1,5 @@ import 'package:example/src/app.dart'; void main(List args) async { - await App().main(); + // await App().main(); } diff --git a/examples/dartness_simple/build.dart b/examples/dartness_simple/build.dart new file mode 100644 index 00000000..408090d6 --- /dev/null +++ b/examples/dartness_simple/build.dart @@ -0,0 +1,54 @@ +// ignore_for_file: directives_ordering +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:build_runner_core/build_runner_core.dart' as _i1; +import 'package:dartness_generator/builder.dart' as _i2; +import 'package:source_gen/builder.dart' as _i3; +import 'dart:isolate' as _i4; +import 'package:build_runner/build_runner.dart' as _i5; +import 'dart:io' as _i6; + +final _builders = <_i1.BuilderApplication>[ + _i1.apply( + r'dartness_generator:error_handler', + [_i2.errorHandler], + _i1.toDependentsOf(r'dartness_generator'), + hideOutput: true, + appliesBuilders: const [r'source_gen:combining_builder'], + ), + _i1.apply( + r'dartness_generator:controller', + [_i2.controller], + _i1.toDependentsOf(r'dartness_generator'), + hideOutput: true, + appliesBuilders: const [r'source_gen:combining_builder'], + ), + _i1.apply( + r'dartness_generator:application', + [_i2.application], + _i1.toDependentsOf(r'dartness_generator'), + hideOutput: true, + appliesBuilders: const [r'source_gen:combining_builder'], + ), + _i1.apply( + r'source_gen:combining_builder', + [_i3.combiningBuilder], + _i1.toNoneByDefault(), + hideOutput: false, + appliesBuilders: const [r'source_gen:part_cleanup'], + ), + _i1.applyPostProcess( + r'source_gen:part_cleanup', + _i3.partCleanup, + ), +]; +void main( + List args, [ + _i4.SendPort? sendPort, +]) async { + var result = await _i5.run( + args, + _builders, + ); + sendPort?.send(result); + _i6.exitCode = result; +} diff --git a/examples/dartness_simple/lib/app_module.dart b/examples/dartness_simple/lib/app_module.dart new file mode 100644 index 00000000..1984ab73 --- /dev/null +++ b/examples/dartness_simple/lib/app_module.dart @@ -0,0 +1,12 @@ +import 'package:dartness_server/modules.dart'; +import 'package:example/src/services/city_service.dart'; + +import 'src/controllers/city_controller.dart'; + +@Module( + metadata: ModuleMetadata( + controllers: [CityController], + providers: [CityService], + ), +) +class AppModule {} diff --git a/examples/dartness_simple/lib/src/app.dart b/examples/dartness_simple/lib/src/app.dart index 6b734a7a..dded74d0 100644 --- a/examples/dartness_simple/lib/src/app.dart +++ b/examples/dartness_simple/lib/src/app.dart @@ -1,27 +1,25 @@ import 'package:dartness_server/dartness.dart'; import 'package:dartness_server/modules.dart'; +import 'package:example/src/services/city_service.dart'; import 'controllers/city_controller.dart'; import 'error_handlers/example_error_handler.dart'; -import 'services/city_service.dart'; -class App { - Future main() async { - final app = Dartness(); - await app.create(AppModule()); - } -} +part 'app.g.dart'; -class AppModule implements Module { - @override - ModuleMetadata get metadata => ModuleMetadata( - controllers: [ - CityDartnessController(CityController(CityService())), - ], - providers: [ - ExampleDartnessErrorHandler(ExampleErrorHandler()), - ], - exports: [], - imports: [], - ); -} +@Application( + module: Module( + metadata: ModuleMetadata( + controllers: [ + CityController, + ], + providers: [ + CityService, + ExampleErrorHandler, + ], + exports: [], + imports: [], + ), + ), +) +class App {} diff --git a/examples/dartness_simple/lib/src/app.g.dart b/examples/dartness_simple/lib/src/app.g.dart new file mode 100644 index 00000000..928b1afe --- /dev/null +++ b/examples/dartness_simple/lib/src/app.g.dart @@ -0,0 +1,18 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'app.dart'; + +// ************************************************************************** +// ApplicationGenerator +// ************************************************************************** + +extension AppExtension on App { + initDependencies() { + final injectRegister = InstanceRegister.instance; + injectRegister.register(CityService()); + injectRegister.register(CityController( + injectRegister.resolve(), + )); + injectRegister.register(ExampleErrorHandler()); + } +} diff --git a/packages/dartness_generator/build.yaml b/packages/dartness_generator/build.yaml index 15a2abd4..614d21f3 100644 --- a/packages/dartness_generator/build.yaml +++ b/packages/dartness_generator/build.yaml @@ -14,4 +14,12 @@ builders: build_extensions: { ".dart": [ ".g.part" ] } auto_apply: dependents build_to: cache + applies_builders: [ "source_gen|combining_builder" ] + application: + target: ":error_handler_generator" + import: "package:dartness_generator/builder.dart" + builder_factories: [ "application" ] + build_extensions: { ".dart": [ ".g.part" ] } + auto_apply: dependents + build_to: cache applies_builders: [ "source_gen|combining_builder" ] \ No newline at end of file diff --git a/packages/dartness_generator/lib/builder.dart b/packages/dartness_generator/lib/builder.dart index 1ceb411b..74dbbcfa 100644 --- a/packages/dartness_generator/lib/builder.dart +++ b/packages/dartness_generator/lib/builder.dart @@ -1,6 +1,7 @@ import 'package:build/build.dart'; import 'package:source_gen/source_gen.dart'; +import 'src/application_generator.dart'; import 'src/controller_generator.dart'; import 'src/error_handler_generator.dart'; @@ -9,3 +10,6 @@ Builder controller(BuilderOptions options) => Builder errorHandler(BuilderOptions options) => SharedPartBuilder([ErrorHandlerGenerator()], 'error_handler'); + +Builder application(BuilderOptions options) => + SharedPartBuilder([ApplicationGenerator()], 'application'); diff --git a/packages/dartness_generator/lib/src/application_generator.dart b/packages/dartness_generator/lib/src/application_generator.dart new file mode 100644 index 00000000..c6fd3b0a --- /dev/null +++ b/packages/dartness_generator/lib/src/application_generator.dart @@ -0,0 +1,115 @@ +import 'package:analyzer/dart/constant/value.dart'; +import 'package:analyzer/dart/element/element.dart'; +import 'package:build/build.dart'; +import 'package:dartness_server/dartness.dart'; +import 'package:source_gen/source_gen.dart'; + +class ApplicationGenerator extends GeneratorForAnnotation { + static final _applicationType = TypeChecker.fromRuntime(Application); + + @override + String? generateForAnnotatedElement( + Element element, + ConstantReader annotation, + BuildStep buildStep, + ) { + if (element is ClassElement) { + final buffer = StringBuffer(); + buffer.writeln('extension ${element.name}Extension on ${element.name} {'); + buffer.writeln('initDependencies(){'); + + buffer.writeln('final injectRegister = InstanceRegister.instance;'); + final applicationModule = annotation.read('module').objectValue; + final moduleMetadata = applicationModule.getField('metadata'); + final controllers = + moduleMetadata?.getField('controllers')?.toListValue() ?? []; + final providers = + moduleMetadata?.getField('providers')?.toListValue() ?? []; + final List allInstances = []; + allInstances.addAll(controllers); + allInstances.addAll(providers); + final classElementControllers = allInstances + .map((e) => e.toTypeValue()?.element) + .whereType() + .toList(); + + final topologicalControllers = _topologicalSort(classElementControllers); + + for (final controllerElement in topologicalControllers) { + final constructors = controllerElement.constructors; + + if (constructors.length > 1) { + throw Exception( + '${controllerElement.name} has more than 1 constructor.' + '@$_applicationType do not allow multiple constructors currently'); + } + + final constructor = constructors.first; + if (constructor.isPrivate) { + throw Exception('${controllerElement.name}\' constructor is private.' + 'A public constructor is required in order ' + 'to create an instance of the class'); + } + + buffer.writeln('injectRegister.register<${controllerElement.name}>('); + buffer.writeln('${controllerElement.name}('); + + for (final constructorParam in constructor.parameters) { + buffer.writeln('injectRegister.resolve<${constructorParam.type}>(),'); + } + + buffer.writeln('));'); + } + + // initDependencies method end + buffer.writeln('}'); + // class end + buffer.writeln('}'); + return buffer.toString(); + } + + return null; + } + + List _topologicalSort(List dependencies) { + final visited = {}; + final sorted = []; + + void visit(ClassElement dependency) { + if (visited.contains(dependency)) return; + visited.add(dependency); + + final dependencies = _getDependencies(dependency); + + for (final dep in dependencies) { + visit(dep); + } + + sorted.add(dependency); + } + + for (final dependency in dependencies) { + visit(dependency); + } + + sorted.reversed.toList(); + return sorted; + } + + List _getDependencies(ClassElement dependency) { + final dependencies = []; + + final constructor = dependency.unnamedConstructor; + if (constructor != null) { + final parameters = constructor.parameters; + for (final param in parameters) { + final paramElement = param.type.element; + if (paramElement is ClassElement) { + dependencies.add(paramElement); + } + } + } + + return dependencies; + } +} diff --git a/packages/dartness_generator/pubspec.yaml b/packages/dartness_generator/pubspec.yaml index 1e36e4b1..6aae576f 100644 --- a/packages/dartness_generator/pubspec.yaml +++ b/packages/dartness_generator/pubspec.yaml @@ -14,6 +14,7 @@ dependencies: source_gen: ^1.4.0 analyzer: ^6.0.0 code_builder: ^4.5.0 + graphs: ^2.3.1 dartness_server: path: ../dartness_server diff --git a/packages/dartness_server/lib/dartness.dart b/packages/dartness_server/lib/dartness.dart index 4b9f88d9..dc1bafab 100644 --- a/packages/dartness_server/lib/dartness.dart +++ b/packages/dartness_server/lib/dartness.dart @@ -3,4 +3,6 @@ /// See documentation guides at https://ricardorb.github.io/dartness/#/. library dartness; +export 'src/app/application.dart'; +export 'src/app/instance_register.dart'; export 'src/dartness.dart'; diff --git a/packages/dartness_server/lib/src/app/application.dart b/packages/dartness_server/lib/src/app/application.dart new file mode 100644 index 00000000..fc9267df --- /dev/null +++ b/packages/dartness_server/lib/src/app/application.dart @@ -0,0 +1,12 @@ +import '../modules/module.dart'; +import '../server/dartness_application_options.dart'; + +abstract class Application { + final Module module; + final DartnessApplicationOptions options; + + const Application({ + required this.module, + final DartnessApplicationOptions? options, + }) : options = options ?? const DartnessApplicationOptions(); +} diff --git a/packages/dartness_server/lib/src/app/instance_register.dart b/packages/dartness_server/lib/src/app/instance_register.dart new file mode 100644 index 00000000..f5c26f56 --- /dev/null +++ b/packages/dartness_server/lib/src/app/instance_register.dart @@ -0,0 +1,35 @@ +class InstanceRegister { + static final InstanceRegister instance = InstanceRegister._(); + static final Map> _dependencies = {}; + static final Map _singletons = {}; + + InstanceRegister._(); + + T resolve({String name = '', bool singleton = false}) { + if (singleton && _singletons.containsKey(T)) { + return _singletons[T] as T; + } + if (_dependencies.containsKey(T)) { + final dependencies = _dependencies[T]!; + if (dependencies.containsKey(name)) { + final instance = dependencies[name]!; + if (singleton) { + _singletons[T] = instance; + } + return instance as T; + } + throw Exception("Dependency not registered with name '$name': $T"); + } + throw Exception("Dependency not registered: $T"); + } + + void register(T instance, {String name = '', bool singleton = false}) { + if (!_dependencies.containsKey(T)) { + _dependencies[T] = {}; + } + _dependencies[T]![name] = instance; + if (singleton) { + _singletons[T] = instance; + } + } +} diff --git a/packages/dartness_server/lib/src/dartness.dart b/packages/dartness_server/lib/src/dartness.dart index 4a12143c..6e0d34d2 100644 --- a/packages/dartness_server/lib/src/dartness.dart +++ b/packages/dartness_server/lib/src/dartness.dart @@ -1,6 +1,5 @@ import 'dart:io'; -import 'package:dartness_server/modules.dart'; import 'exception/dartness_error_handler.dart'; import 'route/dartness_controller.dart'; @@ -22,8 +21,7 @@ class Dartness { /// /// If [logRequest] is true prints the time of the request, the elapsed time for the /// inner handlers, the response's status code and the request URI. - Future create( - final Module module, { + Future create({ final DartnessApplicationOptions? options, }) async { _options = options ?? DartnessApplicationOptions(); @@ -32,7 +30,7 @@ class Dartness { _options.port, internetAddress: _options.internetAddress, ); - _initModule(module); + // _initModule(module); if (options?.logRequest == true) { _addInterceptor(LogRequestsInterceptor()); @@ -43,33 +41,33 @@ class Dartness { } /// Initializes the given [module] and its dependencies. - void _initModule(final Module module) { - for (final import in module.metadata.imports) { - _initModule(import); - } - - for (final controller in module.metadata.controllers) { - _addController(controller); - } - - _addProviders(module); - } - - void _addProviders(Module module) { - for (final provider in module.metadata.providers) { - if (provider is DartnessMiddleware) { - _addMiddleware(provider); - } - - if (provider is DartnessInterceptor) { - _addInterceptor(provider); - } - - if (provider is DartnessErrorHandler) { - _addErrorHandler(provider); - } - } - } + // void _initModule(final Module module) { + // for (final import in module.metadata.imports) { + // _initModule(import); + // } + // + // for (final controller in module.metadata.controllers) { + // _addController(controller); + // } + // + // _addProviders(module); + // } + // + // void _addProviders(Module module) { + // for (final provider in module.metadata.providers) { + // if (provider is DartnessMiddleware) { + // _addMiddleware(provider); + // } + // + // if (provider is DartnessInterceptor) { + // _addInterceptor(provider); + // } + // + // if (provider is DartnessErrorHandler) { + // _addErrorHandler(provider); + // } + // } + // } /// Add [controller] into [Dartness] and handles /// the methods annotated with [Bind] children to [Controller] and [Bind.method]. diff --git a/packages/dartness_server/lib/src/modules/module.dart b/packages/dartness_server/lib/src/modules/module.dart index db6dc4be..fff6e3eb 100644 --- a/packages/dartness_server/lib/src/modules/module.dart +++ b/packages/dartness_server/lib/src/modules/module.dart @@ -1,8 +1,8 @@ import 'module_metadata.dart'; /// Module class that accepts different metadata -abstract class Module { +class Module { final ModuleMetadata metadata; - const Module(this.metadata); + const Module({required this.metadata}); } diff --git a/packages/dartness_server/lib/src/modules/module_metadata.dart b/packages/dartness_server/lib/src/modules/module_metadata.dart index 057a112a..8dde8ea5 100644 --- a/packages/dartness_server/lib/src/modules/module_metadata.dart +++ b/packages/dartness_server/lib/src/modules/module_metadata.dart @@ -1,39 +1,30 @@ import 'package:dartness_server/modules.dart'; -import 'package:dartness_server/route.dart'; /// Module's metadata class class ModuleMetadata { /// Optional list of imported modules that export the providers which are /// required in this module. - final Iterable _imports; - - Iterable get imports => _imports; + final Iterable imports; /// Optional list of controllers defined in this module which have to be /// instantiated. - final Iterable _controllers; - - Iterable get controllers => _controllers; + final Iterable controllers; /// Optional list of providers that will be instantiated by the Dartness injector /// and that may be shared at least across this module. - final Iterable _providers; - - Iterable get providers => _providers; + final Iterable providers; /// Optional list of the subset of providers that are provided by this module /// and should be available in other modules which import this module. - final Iterable _exports; - - Iterable get exports => _exports; + final Iterable exports; const ModuleMetadata({ final Iterable? imports, - final Iterable? controllers, - final Iterable? providers, - final Iterable? exports, - }) : _imports = imports ?? const [], - _controllers = controllers ?? const [], - _providers = providers ?? const [], - _exports = exports ?? const []; + final Iterable? controllers, + final Iterable? providers, + final Iterable? exports, + }) : imports = imports ?? const [], + controllers = controllers ?? const [], + providers = providers ?? const [], + exports = exports ?? const []; } diff --git a/packages/dartness_server/lib/src/server/dartness_application_options.dart b/packages/dartness_server/lib/src/server/dartness_application_options.dart index 6001c8b2..7a031701 100644 --- a/packages/dartness_server/lib/src/server/dartness_application_options.dart +++ b/packages/dartness_server/lib/src/server/dartness_application_options.dart @@ -7,15 +7,16 @@ class DartnessApplicationOptions { final int _port; int get port => _port; - final InternetAddress _internetAddress; + final InternetAddress? _internetAddress; - InternetAddress get internetAddress => _internetAddress; + InternetAddress get internetAddress => + _internetAddress ?? InternetAddress.anyIPv4; - DartnessApplicationOptions({ + const DartnessApplicationOptions({ final bool logRequest = false, final int port = 8080, final InternetAddress? internetAddress, }) : _logRequest = logRequest, _port = port, - _internetAddress = internetAddress ?? InternetAddress.anyIPv4; + _internetAddress = internetAddress; } diff --git a/packages/dartness_server/test/lib/src/app_module.dart b/packages/dartness_server/test/lib/src/app_module.dart index 493ed810..7902b640 100644 --- a/packages/dartness_server/test/lib/src/app_module.dart +++ b/packages/dartness_server/test/lib/src/app_module.dart @@ -1,5 +1,5 @@ import 'package:dartness_server/modules.dart'; class AppModule extends Module { - AppModule(super.metadata); + AppModule({required super.metadata}); } diff --git a/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart b/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart index 03bb00b7..3037213a 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart @@ -2,13 +2,11 @@ import 'dart:convert'; import 'dart:io'; import 'package:dartness_server/dartness.dart'; -import 'package:dartness_server/modules.dart'; import 'package:dartness_server/route.dart'; import 'package:dartness_server/server.dart'; import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; -import '../../app_module.dart'; import 'class_controller.dart'; import 'delete_controller_class.dart'; import 'get_controller_class.dart'; @@ -67,9 +65,11 @@ void main() { httpClient = HttpClient(); dartness = await Dartness().create( - AppModule(ModuleMetadata( - controllers: controllers, - )), + // AppModule( + // metadata: ModuleMetadata( + // controllers: controllers, + // ), + // ), options: DartnessApplicationOptions( port: port, ), diff --git a/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart b/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart index 5ad5a7bb..5d03d9a8 100644 --- a/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart +++ b/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart @@ -1,7 +1,6 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; -import 'package:dartness_server/modules.dart'; import 'package:dartness_server/server.dart'; import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; @@ -9,10 +8,6 @@ import 'package:test/test.dart'; import 'custom_error_handler.dart'; import 'get_controller_class.dart'; -class AppModule extends Module { - AppModule(super.metadata); -} - void main() { group('http tests', () { late DartnessServer dartness; @@ -31,10 +26,12 @@ void main() { httpClient = HttpClient(); dartness = await Dartness().create( - AppModule(ModuleMetadata( - controllers: controllers, - providers: errorHandlers, - )), + // AppModule( + // metadata: ModuleMetadata( + // controllers: controllers, + // providers: errorHandlers, + // ), + // ), options: DartnessApplicationOptions( port: port, ), diff --git a/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart b/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart index 00fd8025..a4d8a163 100644 --- a/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart +++ b/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart @@ -1,12 +1,10 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; -import 'package:dartness_server/modules.dart'; import 'package:dartness_server/server.dart'; import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; -import '../app_module.dart'; void main() { group('http tests', () { @@ -18,7 +16,9 @@ void main() { setUp(() async { httpClient = HttpClient(); dartness = await Dartness().create( - AppModule(ModuleMetadata()), + // AppModule( + // metadata: ModuleMetadata(), + // ), options: DartnessApplicationOptions( port: port, ), diff --git a/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart b/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart index d6469fd1..a6e9e5a8 100644 --- a/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart +++ b/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart @@ -1,12 +1,10 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; -import 'package:dartness_server/modules.dart'; import 'package:dartness_server/server.dart'; import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; -import '../app_module.dart'; import 'test_controller.dart'; void main() { @@ -29,10 +27,12 @@ void main() { httpClient = HttpClient(); dartness = await Dartness().create( - AppModule(ModuleMetadata( - controllers: controllers, - providers: interceptors, - )), + // AppModule( + // metadata: ModuleMetadata( + // controllers: controllers, + // providers: interceptors, + // ), + // ), options: DartnessApplicationOptions( port: port, ), diff --git a/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart b/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart index 7499ebf7..20096efb 100644 --- a/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart +++ b/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart @@ -1,12 +1,10 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; -import 'package:dartness_server/modules.dart'; import 'package:dartness_server/server.dart'; import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; -import '../app_module.dart'; import 'test_controller.dart'; import 'test_middleware.dart'; @@ -26,10 +24,12 @@ void main() { ]; httpClient = HttpClient(); dartness = await Dartness().create( - AppModule(ModuleMetadata( - controllers: controllers, - providers: interceptors, - )), + // AppModule( + // metadata: ModuleMetadata( + // controllers: controllers, + // providers: interceptors, + // ), + // ), options: DartnessApplicationOptions( port: port, ), From 3dee84fe0df9379b04f312e25fea96e5896a2d22 Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Wed, 12 Jul 2023 15:24:46 +0200 Subject: [PATCH 08/31] Removed builder.dart --- packages/dartness_generator/lib/builder.dart | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 packages/dartness_generator/lib/builder.dart diff --git a/packages/dartness_generator/lib/builder.dart b/packages/dartness_generator/lib/builder.dart deleted file mode 100644 index 74dbbcfa..00000000 --- a/packages/dartness_generator/lib/builder.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:build/build.dart'; -import 'package:source_gen/source_gen.dart'; - -import 'src/application_generator.dart'; -import 'src/controller_generator.dart'; -import 'src/error_handler_generator.dart'; - -Builder controller(BuilderOptions options) => - SharedPartBuilder([ControllerGenerator()], 'controller'); - -Builder errorHandler(BuilderOptions options) => - SharedPartBuilder([ErrorHandlerGenerator()], 'error_handler'); - -Builder application(BuilderOptions options) => - SharedPartBuilder([ApplicationGenerator()], 'application'); From 80057382542efff4edae3865c9ae1dc100db9f6b Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Wed, 12 Jul 2023 15:26:22 +0200 Subject: [PATCH 09/31] Removed build.dart --- examples/dartness_simple/build.dart | 54 ----------------------------- 1 file changed, 54 deletions(-) delete mode 100644 examples/dartness_simple/build.dart diff --git a/examples/dartness_simple/build.dart b/examples/dartness_simple/build.dart deleted file mode 100644 index 408090d6..00000000 --- a/examples/dartness_simple/build.dart +++ /dev/null @@ -1,54 +0,0 @@ -// ignore_for_file: directives_ordering -// ignore_for_file: no_leading_underscores_for_library_prefixes -import 'package:build_runner_core/build_runner_core.dart' as _i1; -import 'package:dartness_generator/builder.dart' as _i2; -import 'package:source_gen/builder.dart' as _i3; -import 'dart:isolate' as _i4; -import 'package:build_runner/build_runner.dart' as _i5; -import 'dart:io' as _i6; - -final _builders = <_i1.BuilderApplication>[ - _i1.apply( - r'dartness_generator:error_handler', - [_i2.errorHandler], - _i1.toDependentsOf(r'dartness_generator'), - hideOutput: true, - appliesBuilders: const [r'source_gen:combining_builder'], - ), - _i1.apply( - r'dartness_generator:controller', - [_i2.controller], - _i1.toDependentsOf(r'dartness_generator'), - hideOutput: true, - appliesBuilders: const [r'source_gen:combining_builder'], - ), - _i1.apply( - r'dartness_generator:application', - [_i2.application], - _i1.toDependentsOf(r'dartness_generator'), - hideOutput: true, - appliesBuilders: const [r'source_gen:combining_builder'], - ), - _i1.apply( - r'source_gen:combining_builder', - [_i3.combiningBuilder], - _i1.toNoneByDefault(), - hideOutput: false, - appliesBuilders: const [r'source_gen:part_cleanup'], - ), - _i1.applyPostProcess( - r'source_gen:part_cleanup', - _i3.partCleanup, - ), -]; -void main( - List args, [ - _i4.SendPort? sendPort, -]) async { - var result = await _i5.run( - args, - _builders, - ); - sendPort?.send(result); - _i6.exitCode = result; -} From e88e38f1527d6bf94e71f6b47a2bf8bd0b86018c Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Wed, 12 Jul 2023 18:52:52 +0200 Subject: [PATCH 10/31] - Fixed generate main() - Fixed @Application, removed abstract --- examples/dartness_simple/bin/example.dart | 2 +- examples/dartness_simple/lib/src/app.dart | 7 + examples/dartness_simple/lib/src/app.g.dart | 5 + .../lib/src/application_generator.dart | 131 ++++++++++++------ packages/dartness_server/lib/server.dart | 1 + .../lib/src/app/application.dart | 2 +- 6 files changed, 101 insertions(+), 47 deletions(-) diff --git a/examples/dartness_simple/bin/example.dart b/examples/dartness_simple/bin/example.dart index ac2a9137..46576e19 100644 --- a/examples/dartness_simple/bin/example.dart +++ b/examples/dartness_simple/bin/example.dart @@ -1,5 +1,5 @@ import 'package:example/src/app.dart'; void main(List args) async { - // await App().main(); + await App().main(); } diff --git a/examples/dartness_simple/lib/src/app.dart b/examples/dartness_simple/lib/src/app.dart index dded74d0..e9cbe8a3 100644 --- a/examples/dartness_simple/lib/src/app.dart +++ b/examples/dartness_simple/lib/src/app.dart @@ -1,5 +1,6 @@ import 'package:dartness_server/dartness.dart'; import 'package:dartness_server/modules.dart'; +import 'package:dartness_server/server.dart'; import 'package:example/src/services/city_service.dart'; import 'controllers/city_controller.dart'; @@ -21,5 +22,11 @@ part 'app.g.dart'; imports: [], ), ), + options: DartnessApplicationOptions( + port: int.fromEnvironment( + 'port', + defaultValue: 8080, + ), + ), ) class App {} diff --git a/examples/dartness_simple/lib/src/app.g.dart b/examples/dartness_simple/lib/src/app.g.dart index 928b1afe..5fdff5fc 100644 --- a/examples/dartness_simple/lib/src/app.g.dart +++ b/examples/dartness_simple/lib/src/app.g.dart @@ -15,4 +15,9 @@ extension AppExtension on App { )); injectRegister.register(ExampleErrorHandler()); } + + Future main() async { + final app = Dartness(); + await app.create(options: DartnessApplicationOptions()); + } } diff --git a/packages/dartness_generator/lib/src/application_generator.dart b/packages/dartness_generator/lib/src/application_generator.dart index c6fd3b0a..5bb8f96f 100644 --- a/packages/dartness_generator/lib/src/application_generator.dart +++ b/packages/dartness_generator/lib/src/application_generator.dart @@ -16,53 +16,10 @@ class ApplicationGenerator extends GeneratorForAnnotation { if (element is ClassElement) { final buffer = StringBuffer(); buffer.writeln('extension ${element.name}Extension on ${element.name} {'); - buffer.writeln('initDependencies(){'); - - buffer.writeln('final injectRegister = InstanceRegister.instance;'); - final applicationModule = annotation.read('module').objectValue; - final moduleMetadata = applicationModule.getField('metadata'); - final controllers = - moduleMetadata?.getField('controllers')?.toListValue() ?? []; - final providers = - moduleMetadata?.getField('providers')?.toListValue() ?? []; - final List allInstances = []; - allInstances.addAll(controllers); - allInstances.addAll(providers); - final classElementControllers = allInstances - .map((e) => e.toTypeValue()?.element) - .whereType() - .toList(); - - final topologicalControllers = _topologicalSort(classElementControllers); - - for (final controllerElement in topologicalControllers) { - final constructors = controllerElement.constructors; - - if (constructors.length > 1) { - throw Exception( - '${controllerElement.name} has more than 1 constructor.' - '@$_applicationType do not allow multiple constructors currently'); - } - - final constructor = constructors.first; - if (constructor.isPrivate) { - throw Exception('${controllerElement.name}\' constructor is private.' - 'A public constructor is required in order ' - 'to create an instance of the class'); - } - - buffer.writeln('injectRegister.register<${controllerElement.name}>('); - buffer.writeln('${controllerElement.name}('); - for (final constructorParam in constructor.parameters) { - buffer.writeln('injectRegister.resolve<${constructorParam.type}>(),'); - } - - buffer.writeln('));'); - } + _createInitDependencies(buffer, annotation); - // initDependencies method end - buffer.writeln('}'); + _createMain(buffer, annotation); // class end buffer.writeln('}'); return buffer.toString(); @@ -71,6 +28,58 @@ class ApplicationGenerator extends GeneratorForAnnotation { return null; } + void _createInitDependencies( + final StringBuffer buffer, + final ConstantReader annotation, + ) { + buffer.writeln('initDependencies(){'); + + buffer.writeln('final injectRegister = InstanceRegister.instance;'); + final applicationModule = annotation.read('module').objectValue; + final moduleMetadata = applicationModule.getField('metadata'); + final controllers = + moduleMetadata?.getField('controllers')?.toListValue() ?? []; + final providers = + moduleMetadata?.getField('providers')?.toListValue() ?? []; + final List allInstances = []; + allInstances.addAll(controllers); + allInstances.addAll(providers); + final classElementControllers = allInstances + .map((e) => e.toTypeValue()?.element) + .whereType() + .toList(); + + final topologicalControllers = _topologicalSort(classElementControllers); + + for (final controllerElement in topologicalControllers) { + final constructors = controllerElement.constructors; + + if (constructors.length > 1) { + throw Exception('${controllerElement.name} has more than 1 constructor.' + '@$_applicationType do not allow multiple constructors currently'); + } + + final constructor = constructors.first; + if (constructor.isPrivate) { + throw Exception('${controllerElement.name}\' constructor is private.' + 'A public constructor is required in order ' + 'to create an instance of the class'); + } + + buffer.writeln('injectRegister.register<${controllerElement.name}>('); + buffer.writeln('${controllerElement.name}('); + + for (final constructorParam in constructor.parameters) { + buffer.writeln('injectRegister.resolve<${constructorParam.type}>(),'); + } + + buffer.writeln('));'); + } + + // initDependencies method end + buffer.writeln('}'); + } + List _topologicalSort(List dependencies) { final visited = {}; final sorted = []; @@ -112,4 +121,36 @@ class ApplicationGenerator extends GeneratorForAnnotation { return dependencies; } + + void _createMain(StringBuffer buffer, ConstantReader annotation) { + buffer.writeln('Future main() async {'); + buffer.writeln('final app = Dartness();'); + + final applicationOptions = annotation.read('options').objectValue; + if (applicationOptions.isNull) { + buffer.writeln('await app.create();'); + } else { + final logRequest = + applicationOptions.getField('logRequest')?.toBoolValue(); + final port = applicationOptions.getField('port')?.toIntValue(); + final internetAddress = + applicationOptions.getField('internetAddress')?.toTypeValue(); + buffer.writeln('await app.create(' + 'options: DartnessApplicationOptions('); + if (logRequest != null) { + buffer.writeln('logRequest: $logRequest,'); + } + if (port != null) { + buffer.writeln('port: $port,'); + } + if (internetAddress != null) { + buffer.writeln('internetAddress: $internetAddress,'); + } + buffer.writeln(')'); + buffer.writeln(');'); + } + + // main end method + buffer.writeln('}'); + } } diff --git a/packages/dartness_server/lib/server.dart b/packages/dartness_server/lib/server.dart index 88c98fe6..798f495b 100644 --- a/packages/dartness_server/lib/server.dart +++ b/packages/dartness_server/lib/server.dart @@ -1,6 +1,7 @@ /// Library that exposes the API for the server library server; +export 'src/server/dartness_application_options.dart'; export 'src/server/dartness_interceptor.dart'; export 'src/server/dartness_middleware.dart'; export 'src/server/dartness_pipeline.dart'; diff --git a/packages/dartness_server/lib/src/app/application.dart b/packages/dartness_server/lib/src/app/application.dart index fc9267df..aadea7af 100644 --- a/packages/dartness_server/lib/src/app/application.dart +++ b/packages/dartness_server/lib/src/app/application.dart @@ -1,7 +1,7 @@ import '../modules/module.dart'; import '../server/dartness_application_options.dart'; -abstract class Application { +class Application { final Module module; final DartnessApplicationOptions options; From f7060ff9042b4f6155f9b69b86343f8de318bca5 Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Wed, 12 Jul 2023 18:59:19 +0200 Subject: [PATCH 11/31] string_utils.dart to string_extension.dart --- .../src/route/dartness_router_handler.dart | 9 +- .../lib/src/string_extension.dart | 106 ++++++++++++++++ .../dartness_server/lib/src/string_utils.dart | 113 ------------------ 3 files changed, 110 insertions(+), 118 deletions(-) create mode 100644 packages/dartness_server/lib/src/string_extension.dart delete mode 100644 packages/dartness_server/lib/src/string_utils.dart diff --git a/packages/dartness_server/lib/src/route/dartness_router_handler.dart b/packages/dartness_server/lib/src/route/dartness_router_handler.dart index b110099b..ccacd855 100644 --- a/packages/dartness_server/lib/src/route/dartness_router_handler.dart +++ b/packages/dartness_server/lib/src/route/dartness_router_handler.dart @@ -4,7 +4,6 @@ import 'dart:io'; import 'package:shelf_plus/shelf_plus.dart'; import '../exception/http_status_exception.dart'; -import '../string_utils.dart'; import 'controller_route.dart'; import 'dartness_param.dart'; @@ -24,11 +23,11 @@ class DartnessRouterHandler { if (param.isPositional) { if (param.isPath) { final pathParam = _getPathParam(request, param); - final value = stringToType(pathParam, param.type); + final value = pathParam.stringToType(param.type); positionalArguments.add(value); } else if (param.isQuery) { final queryParam = _getQueryParam(request, param); - final value = stringToType(queryParam, param.type); + final value = queryParam.stringToType(param.type); positionalArguments.add(value); } else { final bodyJson = await request.body.asJson; @@ -38,11 +37,11 @@ class DartnessRouterHandler { } else { if (param.isPath) { final pathParam = _getPathParam(request, param); - final value = stringToType(pathParam, param.type); + final value = pathParam.stringToType(param.type); namedArguments[Symbol(param.name)] = value; } else { final queryParam = _getQueryParam(request, param); - final value = stringToType(queryParam, param.type); + final value = queryParam.stringToType(param.type); namedArguments[Symbol(param.name)] = value; } } diff --git a/packages/dartness_server/lib/src/string_extension.dart b/packages/dartness_server/lib/src/string_extension.dart new file mode 100644 index 00000000..c0b1c691 --- /dev/null +++ b/packages/dartness_server/lib/src/string_extension.dart @@ -0,0 +1,106 @@ +import 'package:collection/collection.dart'; + +extension StringExtension on String { + /// Generates an [Iterable] of a specified conversion way by [toElement] + /// from a [String] with a [json array structure](https://www.w3schools.com/js/js_json_arrays.asp) + /// + /// Example: + /// ```dart + /// String array = '[1,2]' + /// List list = stringToIterable(array, (element) => int.parse(element)).toList(); + /// ``` + Iterable stringToIterable(final T Function(String e) toElement) { + return replaceAll("[", "").replaceAll("]", "").split(",").map(toElement); + } + + /// Generates an [Iterable] of [int] + /// from a [String] with a [json array structure](https://www.w3schools.com/js/js_json_arrays.asp) + /// + /// Example: + /// ```dart + /// String array = '[1,2]' + /// List list = stringToIterableInt(array).toList(); + /// ``` + Iterable stringToIterableInt() => stringToIterable((e) => int.parse(e)); + + /// Generates an [Iterable] of [double] + /// from a [String] with a [json array structure](https://www.w3schools.com/js/js_json_arrays.asp) + /// + /// Example: + /// ```dart + /// String array = '[1.1, 2.1]' + /// List list = stringToIterableDouble(array).toList(); + /// ``` + Iterable stringToIterableDouble() => + stringToIterable((e) => double.parse(e)); + + /// Generates an [Iterable] of [num] + /// from a [String] with a [json array structure](https://www.w3schools.com/js/js_json_arrays.asp) + /// + /// Example: + /// ```dart + /// String array = '[1.1, 2]' + /// List list = stringToIterableDouble(array).toList(); + /// ``` + Iterable stringToIterableNum(final String value) => + stringToIterable((e) => num.parse(e)); + + /// Generates an [Iterable] of [String] + /// from a [String] with a [json array structure](https://www.w3schools.com/js/js_json_arrays.asp) + /// + /// Example: + /// ```dart + /// String array = '["string1", "string2"]' + /// List list = stringToIterableString(array).toList(); + /// ``` + Iterable stringToIterableString() => + stringToIterable((e) => e.toString()); + + /// Generates an [Iterable] of [bool] + /// from a [String] with a [json array structure](https://www.w3schools.com/js/js_json_arrays.asp) + /// + /// Example: + /// ```dart + /// String array = '[true, false]' + /// List list = stringToIterableBool(array).toList(); + /// ``` + Iterable stringToIterableBool() => + stringToIterable((e) => bool.tryParse(e)).whereNotNull(); + + /// Returns the [type] with the correct type. + dynamic stringToType(final Type type) { + if (type == num) { + return num.parse(this); + } else if (type == int) { + return int.parse(this); + } else if (type == double) { + return double.parse(this); + } else if (type == bool) { + return bool.tryParse(this); + } else if (type == DateTime) { + return DateTime.parse(this); + } else if (type == List) { + return stringToIterableInt().toList(); + } else if (type == List) { + return stringToIterableDouble().toList(); + } else if (type == List) { + return stringToIterableBool().toList(); + } else if (type == List) { + return stringToIterableString().toList(); + } else if (type == List) { + return stringToIterableString().toList(); + } else if (type == Set) { + return stringToIterableInt().toSet(); + } else if (type == Set) { + return stringToIterableDouble().toSet(); + } else if (type == Set) { + return stringToIterableBool().toSet(); + } else if (type == Set) { + return stringToIterableString().toSet(); + } else if (type == Set) { + return stringToIterableString().toSet(); + } else { + return this; + } + } +} diff --git a/packages/dartness_server/lib/src/string_utils.dart b/packages/dartness_server/lib/src/string_utils.dart deleted file mode 100644 index a24ae0a7..00000000 --- a/packages/dartness_server/lib/src/string_utils.dart +++ /dev/null @@ -1,113 +0,0 @@ -/// Generates an [Iterable] of a specified conversion way by [toElement] -/// from a [String] with a [json array structure](https://www.w3schools.com/js/js_json_arrays.asp) -/// -/// Example: -/// ```dart -/// String array = '[1,2]' -/// List list = stringToIterable(array, (element) => int.parse(element)).toList(); -/// ``` -Iterable stringToIterable( - final String value, - final T Function(String e) toElement, -) { - return value - .replaceAll("[", "") - .replaceAll("]", "") - .split(",") - .map(toElement); -} - -/// Generates an [Iterable] of [int] -/// from a [String] with a [json array structure](https://www.w3schools.com/js/js_json_arrays.asp) -/// -/// Example: -/// ```dart -/// String array = '[1,2]' -/// List list = stringToIterableInt(array).toList(); -/// ``` -Iterable stringToIterableInt(final String value) => - stringToIterable(value, (e) => int.parse(e)); - -/// Generates an [Iterable] of [double] -/// from a [String] with a [json array structure](https://www.w3schools.com/js/js_json_arrays.asp) -/// -/// Example: -/// ```dart -/// String array = '[1.1, 2.1]' -/// List list = stringToIterableDouble(array).toList(); -/// ``` -Iterable stringToIterableDouble(final String value) => - stringToIterable(value, (e) => double.parse(e)); - -/// Generates an [Iterable] of [num] -/// from a [String] with a [json array structure](https://www.w3schools.com/js/js_json_arrays.asp) -/// -/// Example: -/// ```dart -/// String array = '[1.1, 2]' -/// List list = stringToIterableDouble(array).toList(); -/// ``` -Iterable stringToIterableNum(final String value) => - stringToIterable(value, (e) => num.parse(e)); - -/// Generates an [Iterable] of [String] -/// from a [String] with a [json array structure](https://www.w3schools.com/js/js_json_arrays.asp) -/// -/// Example: -/// ```dart -/// String array = '["string1", "string2"]' -/// List list = stringToIterableString(array).toList(); -/// ``` -Iterable stringToIterableString(final String value) => - stringToIterable(value, (e) => e.toString()); - -/// Generates an [Iterable] of [bool] -/// from a [String] with a [json array structure](https://www.w3schools.com/js/js_json_arrays.asp) -/// -/// Example: -/// ```dart -/// String array = '[true, false]' -/// List list = stringToIterableBool(array).toList(); -/// ``` -Iterable stringToIterableBool(final String value) => - stringToIterable(value, (e) => e == 'true'); - -/// Given a [value] with a [type] return the value with the correct type. -dynamic stringToType(final String? value, final Type type) { - if (value == null) { - return null; - } - if (type == num) { - return num.parse(value); - } else if (type == int) { - return int.parse(value); - } else if (type == double) { - return double.parse(value); - } else if (type == bool) { - return value == 'true'; - } else if (type == DateTime) { - return DateTime.parse(value); - } else if (type == List) { - return stringToIterableInt(value).toList(); - } else if (type == List) { - return stringToIterableDouble(value).toList(); - } else if (type == List) { - return stringToIterableBool(value).toList(); - } else if (type == List) { - return stringToIterableString(value).toList(); - } else if (type == List) { - return stringToIterableString(value).toList(); - } else if (type == Set) { - return stringToIterableInt(value).toSet(); - } else if (type == Set) { - return stringToIterableDouble(value).toSet(); - } else if (type == Set) { - return stringToIterableBool(value).toSet(); - } else if (type == Set) { - return stringToIterableString(value).toSet(); - } else if (type == Set) { - return stringToIterableString(value).toSet(); - } else { - return value; - } -} From 2b135a525dae500b670890e5ce84cf43838b79b6 Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Wed, 12 Jul 2023 20:18:47 +0200 Subject: [PATCH 12/31] Added builder again to generator --- packages/dartness_generator/lib/builder.dart | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 packages/dartness_generator/lib/builder.dart diff --git a/packages/dartness_generator/lib/builder.dart b/packages/dartness_generator/lib/builder.dart new file mode 100644 index 00000000..74dbbcfa --- /dev/null +++ b/packages/dartness_generator/lib/builder.dart @@ -0,0 +1,15 @@ +import 'package:build/build.dart'; +import 'package:source_gen/source_gen.dart'; + +import 'src/application_generator.dart'; +import 'src/controller_generator.dart'; +import 'src/error_handler_generator.dart'; + +Builder controller(BuilderOptions options) => + SharedPartBuilder([ControllerGenerator()], 'controller'); + +Builder errorHandler(BuilderOptions options) => + SharedPartBuilder([ErrorHandlerGenerator()], 'error_handler'); + +Builder application(BuilderOptions options) => + SharedPartBuilder([ApplicationGenerator()], 'application'); From 852f05897f23cc26b53c99951fd441044cf3d4e2 Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Wed, 12 Jul 2023 20:39:59 +0200 Subject: [PATCH 13/31] - Init dependencies before starting the server - Init dartness controllers --- examples/dartness_simple/lib/src/app.g.dart | 9 +++- .../lib/src/controllers/city_controller.dart | 4 +- .../src/controllers/city_controller.g.dart | 4 +- .../lib/src/application_generator.dart | 42 ++++++++++++++-- .../dartness_server/lib/src/dartness.dart | 48 +++++++------------ .../src/route/dartness_router_handler.dart | 5 +- .../lib/src/server/dartness_server.dart | 2 +- 7 files changed, 71 insertions(+), 43 deletions(-) diff --git a/examples/dartness_simple/lib/src/app.g.dart b/examples/dartness_simple/lib/src/app.g.dart index 5fdff5fc..2445e8d3 100644 --- a/examples/dartness_simple/lib/src/app.g.dart +++ b/examples/dartness_simple/lib/src/app.g.dart @@ -17,7 +17,14 @@ extension AppExtension on App { } Future main() async { + initDependencies(); + final injectRegister = InstanceRegister.instance; final app = Dartness(); - await app.create(options: DartnessApplicationOptions()); + await app.create( + controllers: [ + CityDartnessController(injectRegister.resolve()), + ], + options: DartnessApplicationOptions(), + ); } } diff --git a/examples/dartness_simple/lib/src/controllers/city_controller.dart b/examples/dartness_simple/lib/src/controllers/city_controller.dart index 3c836ce7..bde2698a 100644 --- a/examples/dartness_simple/lib/src/controllers/city_controller.dart +++ b/examples/dartness_simple/lib/src/controllers/city_controller.dart @@ -8,6 +8,7 @@ import '../services/city_service.dart'; part 'city_controller.g.dart'; @Controller('/cities') +@Header(HttpHeaders.contentTypeHeader, 'application/json') class CityController { CityController(this._cityService); @@ -16,12 +17,11 @@ class CityController { @HttpCode(202) @Get() List getCities({ - @QueryParam() int? offset = 100, + @QueryParam() int? offset, }) { return _cityService.getCities(offset); } - @Header(HttpHeaders.contentTypeHeader, 'application/json') @Get('/') CityDto getCity(@PathParam() int id) { return _cityService.getCity(id); diff --git a/examples/dartness_simple/lib/src/controllers/city_controller.g.dart b/examples/dartness_simple/lib/src/controllers/city_controller.g.dart index 594e5a1c..3ca3e74c 100644 --- a/examples/dartness_simple/lib/src/controllers/city_controller.g.dart +++ b/examples/dartness_simple/lib/src/controllers/city_controller.g.dart @@ -23,12 +23,12 @@ extension CityControllerRoutes on CityController { isPositional: false, isOptional: true, type: int, - defaultValue: '100', + defaultValue: null, fromJson: null, ) ], httpCode: 202, - headers: {}, + headers: {'content-type': 'application/json'}, )); routes.add(ControllerRoute( method: 'GET', diff --git a/packages/dartness_generator/lib/src/application_generator.dart b/packages/dartness_generator/lib/src/application_generator.dart index 5bb8f96f..8294dfcb 100644 --- a/packages/dartness_generator/lib/src/application_generator.dart +++ b/packages/dartness_generator/lib/src/application_generator.dart @@ -20,6 +20,7 @@ class ApplicationGenerator extends GeneratorForAnnotation { _createInitDependencies(buffer, annotation); _createMain(buffer, annotation); + // class end buffer.writeln('}'); return buffer.toString(); @@ -124,19 +125,34 @@ class ApplicationGenerator extends GeneratorForAnnotation { void _createMain(StringBuffer buffer, ConstantReader annotation) { buffer.writeln('Future main() async {'); + + buffer.writeln('initDependencies();'); + buffer.writeln('final injectRegister = InstanceRegister.instance;'); buffer.writeln('final app = Dartness();'); + final applicationModule = annotation.read('module').objectValue; + final moduleMetadata = applicationModule.getField('metadata'); + final controllers = + moduleMetadata?.getField('controllers')?.toListValue() ?? []; + final controllerElements = controllers + .map((e) => e.toTypeValue()?.element) + .whereType() + .toList(); final applicationOptions = annotation.read('options').objectValue; + if (applicationOptions.isNull) { - buffer.writeln('await app.create();'); + buffer.writeln('await app.create('); + _generateControllers(controllerElements, buffer); + buffer.writeln(');'); } else { final logRequest = applicationOptions.getField('logRequest')?.toBoolValue(); final port = applicationOptions.getField('port')?.toIntValue(); final internetAddress = applicationOptions.getField('internetAddress')?.toTypeValue(); - buffer.writeln('await app.create(' - 'options: DartnessApplicationOptions('); + buffer.writeln('await app.create('); + _generateControllers(controllerElements, buffer); + buffer.writeln('options: DartnessApplicationOptions('); if (logRequest != null) { buffer.writeln('logRequest: $logRequest,'); } @@ -146,11 +162,29 @@ class ApplicationGenerator extends GeneratorForAnnotation { if (internetAddress != null) { buffer.writeln('internetAddress: $internetAddress,'); } - buffer.writeln(')'); + buffer.writeln('),'); buffer.writeln(');'); } // main end method buffer.writeln('}'); } + + void _generateControllers( + List controllerElements, + StringBuffer buffer, + ) { + buffer.writeln('controllers: ['); + for (final controllerElement in controllerElements) { + final className = controllerElement.name.contains('Controller') + ? controllerElement.name + .replaceAll('Controller', 'DartnessController') + : '${controllerElement.name}DartnessController'; + + buffer.writeln( + '$className(injectRegister.resolve<${controllerElement.name}>()),'); + } + + buffer.writeln('],'); + } } diff --git a/packages/dartness_server/lib/src/dartness.dart b/packages/dartness_server/lib/src/dartness.dart index 6e0d34d2..d3f127e7 100644 --- a/packages/dartness_server/lib/src/dartness.dart +++ b/packages/dartness_server/lib/src/dartness.dart @@ -1,6 +1,5 @@ import 'dart:io'; - import 'exception/dartness_error_handler.dart'; import 'route/dartness_controller.dart'; import 'server/dartness_application_options.dart'; @@ -22,6 +21,10 @@ class Dartness { /// If [logRequest] is true prints the time of the request, the elapsed time for the /// inner handlers, the response's status code and the request URI. Future create({ + final Iterable controllers = const [], + final Iterable middlewares = const [], + final Iterable interceptors = const [], + final Iterable errorHandlers = const [], final DartnessApplicationOptions? options, }) async { _options = options ?? DartnessApplicationOptions(); @@ -30,7 +33,19 @@ class Dartness { _options.port, internetAddress: _options.internetAddress, ); - // _initModule(module); + + for (final controller in controllers) { + _addController(controller); + } + for (final middleware in middlewares) { + _addMiddleware(middleware); + } + for (final interceptor in interceptors) { + _addInterceptor(interceptor); + } + for (final errorHandler in errorHandlers) { + _addErrorHandler(errorHandler); + } if (options?.logRequest == true) { _addInterceptor(LogRequestsInterceptor()); @@ -40,35 +55,6 @@ class Dartness { return _server; } - /// Initializes the given [module] and its dependencies. - // void _initModule(final Module module) { - // for (final import in module.metadata.imports) { - // _initModule(import); - // } - // - // for (final controller in module.metadata.controllers) { - // _addController(controller); - // } - // - // _addProviders(module); - // } - // - // void _addProviders(Module module) { - // for (final provider in module.metadata.providers) { - // if (provider is DartnessMiddleware) { - // _addMiddleware(provider); - // } - // - // if (provider is DartnessInterceptor) { - // _addInterceptor(provider); - // } - // - // if (provider is DartnessErrorHandler) { - // _addErrorHandler(provider); - // } - // } - // } - /// Add [controller] into [Dartness] and handles /// the methods annotated with [Bind] children to [Controller] and [Bind.method]. /// diff --git a/packages/dartness_server/lib/src/route/dartness_router_handler.dart b/packages/dartness_server/lib/src/route/dartness_router_handler.dart index ccacd855..1df9fe08 100644 --- a/packages/dartness_server/lib/src/route/dartness_router_handler.dart +++ b/packages/dartness_server/lib/src/route/dartness_router_handler.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'dart:io'; +import 'package:dartness_server/src/string_extension.dart'; import 'package:shelf_plus/shelf_plus.dart'; import '../exception/http_status_exception.dart'; @@ -40,8 +41,8 @@ class DartnessRouterHandler { final value = pathParam.stringToType(param.type); namedArguments[Symbol(param.name)] = value; } else { - final queryParam = _getQueryParam(request, param); - final value = queryParam.stringToType(param.type); + final String? queryParam = _getQueryParam(request, param); + final value = queryParam?.stringToType(param.type); namedArguments[Symbol(param.name)] = value; } } diff --git a/packages/dartness_server/lib/src/server/dartness_server.dart b/packages/dartness_server/lib/src/server/dartness_server.dart index 6ba4acf6..61be0047 100644 --- a/packages/dartness_server/lib/src/server/dartness_server.dart +++ b/packages/dartness_server/lib/src/server/dartness_server.dart @@ -1,7 +1,7 @@ import 'dart:io'; -import '../route/dartness_controller.dart'; import '../exception/dartness_error_handler.dart'; +import '../route/dartness_controller.dart'; import 'dartness_interceptor.dart'; import 'dartness_middleware.dart'; From 27d68bf6d629f547b33ad4cec62f272bcd8285aa Mon Sep 17 00:00:00 2001 From: Ricardo Romero Date: Sat, 29 Jul 2023 13:35:01 +0200 Subject: [PATCH 14/31] Created provider_metadata.dart --- examples/dartness_simple/lib/app_module.dart | 12 ++++++++-- examples/dartness_simple/lib/src/app.dart | 12 +++++++--- examples/dartness_simple/lib/src/app.g.dart | 9 +------- .../lib/src/application_generator.dart | 23 +++++++++++-------- packages/dartness_server/lib/modules.dart | 1 + .../lib/src/modules/module_metadata.dart | 12 +++++----- .../lib/src/modules/provider_metadata.dart | 9 ++++++++ .../src/bind/annotation/controller_test.dart | 1 - .../annotation/catch_handler_test.dart | 1 - .../exception/http_status_exception_test.dart | 1 - .../src/server/dartness_interceptor_test.dart | 1 - .../src/server/dartness_middleware_test.dart | 1 - 12 files changed, 49 insertions(+), 34 deletions(-) create mode 100644 packages/dartness_server/lib/src/modules/provider_metadata.dart diff --git a/examples/dartness_simple/lib/app_module.dart b/examples/dartness_simple/lib/app_module.dart index 1984ab73..e4290b34 100644 --- a/examples/dartness_simple/lib/app_module.dart +++ b/examples/dartness_simple/lib/app_module.dart @@ -5,8 +5,16 @@ import 'src/controllers/city_controller.dart'; @Module( metadata: ModuleMetadata( - controllers: [CityController], - providers: [CityService], + controllers: [ + ProviderMetadata( + classType: CityController, + ), + ], + providers: [ + ProviderMetadata( + classType: CityService, + ), + ], ), ) class AppModule {} diff --git a/examples/dartness_simple/lib/src/app.dart b/examples/dartness_simple/lib/src/app.dart index e9cbe8a3..5b8ae694 100644 --- a/examples/dartness_simple/lib/src/app.dart +++ b/examples/dartness_simple/lib/src/app.dart @@ -12,11 +12,17 @@ part 'app.g.dart'; module: Module( metadata: ModuleMetadata( controllers: [ - CityController, + ProviderMetadata( + classType: CityController, + ), ], providers: [ - CityService, - ExampleErrorHandler, + ProviderMetadata( + classType: CityService, + ), + ProviderMetadata( + classType: ExampleErrorHandler, + ), ], exports: [], imports: [], diff --git a/examples/dartness_simple/lib/src/app.g.dart b/examples/dartness_simple/lib/src/app.g.dart index 2445e8d3..a1ca2cea 100644 --- a/examples/dartness_simple/lib/src/app.g.dart +++ b/examples/dartness_simple/lib/src/app.g.dart @@ -9,11 +9,6 @@ part of 'app.dart'; extension AppExtension on App { initDependencies() { final injectRegister = InstanceRegister.instance; - injectRegister.register(CityService()); - injectRegister.register(CityController( - injectRegister.resolve(), - )); - injectRegister.register(ExampleErrorHandler()); } Future main() async { @@ -21,9 +16,7 @@ extension AppExtension on App { final injectRegister = InstanceRegister.instance; final app = Dartness(); await app.create( - controllers: [ - CityDartnessController(injectRegister.resolve()), - ], + controllers: [], options: DartnessApplicationOptions(), ); } diff --git a/packages/dartness_generator/lib/src/application_generator.dart b/packages/dartness_generator/lib/src/application_generator.dart index 8294dfcb..5a8a3185 100644 --- a/packages/dartness_generator/lib/src/application_generator.dart +++ b/packages/dartness_generator/lib/src/application_generator.dart @@ -45,30 +45,30 @@ class ApplicationGenerator extends GeneratorForAnnotation { final List allInstances = []; allInstances.addAll(controllers); allInstances.addAll(providers); - final classElementControllers = allInstances + final allProviderElements = allInstances .map((e) => e.toTypeValue()?.element) .whereType() .toList(); - final topologicalControllers = _topologicalSort(classElementControllers); + final topologicalProviderElements = _topologicalSort(allProviderElements); - for (final controllerElement in topologicalControllers) { - final constructors = controllerElement.constructors; + for (final providerElement in topologicalProviderElements) { + final constructors = providerElement.constructors; if (constructors.length > 1) { - throw Exception('${controllerElement.name} has more than 1 constructor.' + throw Exception('${providerElement.name} has more than 1 constructor.' '@$_applicationType do not allow multiple constructors currently'); } final constructor = constructors.first; if (constructor.isPrivate) { - throw Exception('${controllerElement.name}\' constructor is private.' + throw Exception('${providerElement.name}\' constructor is private.' 'A public constructor is required in order ' 'to create an instance of the class'); } - buffer.writeln('injectRegister.register<${controllerElement.name}>('); - buffer.writeln('${controllerElement.name}('); + buffer.writeln('injectRegister.register<${providerElement.name}>('); + buffer.writeln('${providerElement.name}('); for (final constructorParam in constructor.parameters) { buffer.writeln('injectRegister.resolve<${constructorParam.type}>(),'); @@ -81,12 +81,15 @@ class ApplicationGenerator extends GeneratorForAnnotation { buffer.writeln('}'); } - List _topologicalSort(List dependencies) { + List _topologicalSort(final List dependencies) { final visited = {}; final sorted = []; void visit(ClassElement dependency) { - if (visited.contains(dependency)) return; + if (visited.contains(dependency)) { + return; + } + visited.add(dependency); final dependencies = _getDependencies(dependency); diff --git a/packages/dartness_server/lib/modules.dart b/packages/dartness_server/lib/modules.dart index 9dea4224..b78db3a8 100644 --- a/packages/dartness_server/lib/modules.dart +++ b/packages/dartness_server/lib/modules.dart @@ -5,3 +5,4 @@ library modules; export 'src/modules/module.dart'; export 'src/modules/module_metadata.dart'; +export 'src/modules/provider_metadata.dart'; diff --git a/packages/dartness_server/lib/src/modules/module_metadata.dart b/packages/dartness_server/lib/src/modules/module_metadata.dart index 8dde8ea5..13ba8c0a 100644 --- a/packages/dartness_server/lib/src/modules/module_metadata.dart +++ b/packages/dartness_server/lib/src/modules/module_metadata.dart @@ -8,21 +8,21 @@ class ModuleMetadata { /// Optional list of controllers defined in this module which have to be /// instantiated. - final Iterable controllers; + final Iterable controllers; /// Optional list of providers that will be instantiated by the Dartness injector /// and that may be shared at least across this module. - final Iterable providers; + final Iterable providers; /// Optional list of the subset of providers that are provided by this module /// and should be available in other modules which import this module. - final Iterable exports; + final Iterable exports; const ModuleMetadata({ final Iterable? imports, - final Iterable? controllers, - final Iterable? providers, - final Iterable? exports, + final Iterable? controllers, + final Iterable? providers, + final Iterable? exports, }) : imports = imports ?? const [], controllers = controllers ?? const [], providers = providers ?? const [], diff --git a/packages/dartness_server/lib/src/modules/provider_metadata.dart b/packages/dartness_server/lib/src/modules/provider_metadata.dart new file mode 100644 index 00000000..2e02d926 --- /dev/null +++ b/packages/dartness_server/lib/src/modules/provider_metadata.dart @@ -0,0 +1,9 @@ +class ProviderMetadata { + final String? name; + final Type classType; + + const ProviderMetadata({ + this.name, + required this.classType, + }); +} diff --git a/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart b/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart index 3037213a..aa0cab14 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart @@ -4,7 +4,6 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; import 'package:dartness_server/route.dart'; import 'package:dartness_server/server.dart'; -import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; import 'class_controller.dart'; diff --git a/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart b/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart index 5d03d9a8..de2524a4 100644 --- a/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart +++ b/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart @@ -2,7 +2,6 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; import 'package:dartness_server/server.dart'; -import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; import 'custom_error_handler.dart'; diff --git a/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart b/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart index a4d8a163..415cc4db 100644 --- a/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart +++ b/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart @@ -2,7 +2,6 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; import 'package:dartness_server/server.dart'; -import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; diff --git a/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart b/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart index a6e9e5a8..86d2c7cc 100644 --- a/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart +++ b/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart @@ -2,7 +2,6 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; import 'package:dartness_server/server.dart'; -import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; import 'test_controller.dart'; diff --git a/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart b/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart index 20096efb..3d81fcce 100644 --- a/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart +++ b/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart @@ -2,7 +2,6 @@ import 'dart:io'; import 'package:dartness_server/dartness.dart'; import 'package:dartness_server/server.dart'; -import 'package:dartness_server/src/server/dartness_application_options.dart'; import 'package:test/test.dart'; import 'test_controller.dart'; From 3ba16c38f2a796e279f8eaba49615607837d30b4 Mon Sep 17 00:00:00 2001 From: Ricardo Romero Date: Tue, 8 Aug 2023 11:54:42 +0200 Subject: [PATCH 15/31] Removed name instance creation, it will be available for the next version --- examples/dartness_simple/lib/src/app.dart | 3 +++ .../dartness_server/lib/src/modules/provider_metadata.dart | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/dartness_simple/lib/src/app.dart b/examples/dartness_simple/lib/src/app.dart index 5b8ae694..cd3e4845 100644 --- a/examples/dartness_simple/lib/src/app.dart +++ b/examples/dartness_simple/lib/src/app.dart @@ -17,6 +17,9 @@ part 'app.g.dart'; ), ], providers: [ + ProviderMetadata( + classType: CityService, + ), ProviderMetadata( classType: CityService, ), diff --git a/packages/dartness_server/lib/src/modules/provider_metadata.dart b/packages/dartness_server/lib/src/modules/provider_metadata.dart index 2e02d926..13cc74d9 100644 --- a/packages/dartness_server/lib/src/modules/provider_metadata.dart +++ b/packages/dartness_server/lib/src/modules/provider_metadata.dart @@ -1,9 +1,10 @@ class ProviderMetadata { - final String? name; + // It will be available in the next version + // final String? name; final Type classType; const ProviderMetadata({ - this.name, + // this.name, required this.classType, }); } From 6bf836dcff9a18f418fd7a915a41520c3c56655f Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Thu, 12 Oct 2023 16:58:53 +0200 Subject: [PATCH 16/31] Updated pubspec --- .../dartness_flutter_melos/apps/my_app/pubspec.yaml | 6 +++--- .../servers/my_server/pubspec.yaml | 10 +++++----- examples/dartness_simple/pubspec.yaml | 2 +- packages/dartness_generator/pubspec.yaml | 6 +++--- packages/dartness_server/pubspec.yaml | 4 ++-- pubspec.yaml | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/examples/dartness_flutter_melos/apps/my_app/pubspec.yaml b/examples/dartness_flutter_melos/apps/my_app/pubspec.yaml index 4306341f..d580a277 100644 --- a/examples/dartness_flutter_melos/apps/my_app/pubspec.yaml +++ b/examples/dartness_flutter_melos/apps/my_app/pubspec.yaml @@ -11,13 +11,13 @@ environment: dependencies: flutter: sdk: flutter - cupertino_icons: ^1.0.5 - http: ^1.0.0 + cupertino_icons: ^1.0.6 + http: ^1.1.0 dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^2.0.1 + flutter_lints: ^2.0.3 flutter: uses-material-design: true diff --git a/examples/dartness_flutter_melos/servers/my_server/pubspec.yaml b/examples/dartness_flutter_melos/servers/my_server/pubspec.yaml index 54cf9d05..4da1e0e6 100644 --- a/examples/dartness_flutter_melos/servers/my_server/pubspec.yaml +++ b/examples/dartness_flutter_melos/servers/my_server/pubspec.yaml @@ -9,10 +9,10 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: - dartness_server: ^0.4.4-alpha + dartness_server: ^0.4.6-alpha dev_dependencies: - lints: ^2.0.0 - test: ^1.21.4 - build_runner: ^2.2.0 - dartness_generator: ^0.1.0-alpha + lints: ^2.1.1 + test: ^1.24.7 + build_runner: ^2.4.6 + dartness_generator: ^0.1.3-alpha diff --git a/examples/dartness_simple/pubspec.yaml b/examples/dartness_simple/pubspec.yaml index e441302c..43784980 100644 --- a/examples/dartness_simple/pubspec.yaml +++ b/examples/dartness_simple/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: dev_dependencies: lints: ^2.1.1 - test: ^1.24.4 + test: ^1.24.7 build_runner: ^2.4.6 dartness_generator: path: ../../packages/dartness_generator diff --git a/packages/dartness_generator/pubspec.yaml b/packages/dartness_generator/pubspec.yaml index 6aae576f..950cbc41 100644 --- a/packages/dartness_generator/pubspec.yaml +++ b/packages/dartness_generator/pubspec.yaml @@ -12,8 +12,8 @@ environment: dependencies: build: ^2.4.1 source_gen: ^1.4.0 - analyzer: ^6.0.0 - code_builder: ^4.5.0 + analyzer: ^6.3.0 + code_builder: ^4.7.0 graphs: ^2.3.1 dartness_server: path: ../dartness_server @@ -21,5 +21,5 @@ dependencies: dev_dependencies: lints: ^2.1.1 build_runner: ^2.4.6 - test: ^1.24.4 + test: ^1.24.7 source_gen_test: ^1.0.6 diff --git a/packages/dartness_server/pubspec.yaml b/packages/dartness_server/pubspec.yaml index 2500c124..772edad9 100644 --- a/packages/dartness_server/pubspec.yaml +++ b/packages/dartness_server/pubspec.yaml @@ -15,7 +15,7 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: - collection: ^1.17.2 + collection: ^1.18.0 shelf: ^1.4.1 shelf_plus: ^1.7.0 shelf_router: ^1.1.4 @@ -24,7 +24,7 @@ dependencies: dev_dependencies: http: ^1.1.0 lints: ^2.1.1 - test: ^1.24.4 + test: ^1.24.7 build_runner: ^2.4.6 dartness_generator: path: ../dartness_generator \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index dad97c2c..130fa14b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,4 +10,4 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: - melos: ^3.1.0 + melos: ^3.1.1 From a4eb3aef785763020de1c50e584c5e0210872f0d Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Sun, 15 Oct 2023 15:07:42 +0200 Subject: [PATCH 17/31] Fixed generating topological instance register --- examples/dartness_simple/lib/src/app.g.dart | 5 +++ .../lib/src/application_generator.dart | 38 ++++++++++--------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/examples/dartness_simple/lib/src/app.g.dart b/examples/dartness_simple/lib/src/app.g.dart index a1ca2cea..6ec17925 100644 --- a/examples/dartness_simple/lib/src/app.g.dart +++ b/examples/dartness_simple/lib/src/app.g.dart @@ -9,6 +9,11 @@ part of 'app.dart'; extension AppExtension on App { initDependencies() { final injectRegister = InstanceRegister.instance; + injectRegister.register(CityService()); + injectRegister.register(CityController( + injectRegister.resolve(), + )); + injectRegister.register(ExampleErrorHandler()); } Future main() async { diff --git a/packages/dartness_generator/lib/src/application_generator.dart b/packages/dartness_generator/lib/src/application_generator.dart index 5a8a3185..a816d65f 100644 --- a/packages/dartness_generator/lib/src/application_generator.dart +++ b/packages/dartness_generator/lib/src/application_generator.dart @@ -46,7 +46,8 @@ class ApplicationGenerator extends GeneratorForAnnotation { allInstances.addAll(controllers); allInstances.addAll(providers); final allProviderElements = allInstances - .map((e) => e.toTypeValue()?.element) + .map((e) => e.getField('classType')) + .map((e) => e?.toTypeValue()?.element) .whereType() .toList(); @@ -71,7 +72,10 @@ class ApplicationGenerator extends GeneratorForAnnotation { buffer.writeln('${providerElement.name}('); for (final constructorParam in constructor.parameters) { - buffer.writeln('injectRegister.resolve<${constructorParam.type}>(),'); + buffer.writeln( + 'injectRegister.resolve<${constructorParam.type.getDisplayString( + withNullability: false, + )}>(),'); } buffer.writeln('));'); @@ -85,28 +89,28 @@ class ApplicationGenerator extends GeneratorForAnnotation { final visited = {}; final sorted = []; - void visit(ClassElement dependency) { - if (visited.contains(dependency)) { - return; - } + for (final dependency in dependencies) { + _visit(dependency, visited, sorted); + } - visited.add(dependency); + return sorted.toList(); + } - final dependencies = _getDependencies(dependency); + void _visit(final ClassElement dependency, final Set visited, + final List sorted) { + if (visited.contains(dependency)) { + return; + } - for (final dep in dependencies) { - visit(dep); - } + visited.add(dependency); - sorted.add(dependency); - } + final dependencies = _getDependencies(dependency); - for (final dependency in dependencies) { - visit(dependency); + for (final dep in dependencies) { + _visit(dep, visited, sorted); } - sorted.reversed.toList(); - return sorted; + sorted.add(dependency); } List _getDependencies(ClassElement dependency) { From efef87f0b48f2fdb952b944edc9b537e12d899fb Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Sun, 15 Oct 2023 15:07:45 +0200 Subject: [PATCH 18/31] Fixed generating topological instance register --- .../test/lib/src/exception/http_status_exception_test.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart b/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart index 415cc4db..c82aa5d5 100644 --- a/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart +++ b/packages/dartness_server/test/lib/src/exception/http_status_exception_test.dart @@ -4,7 +4,6 @@ import 'package:dartness_server/dartness.dart'; import 'package:dartness_server/server.dart'; import 'package:test/test.dart'; - void main() { group('http tests', () { late DartnessServer dartness; From 114ccfa053d0436a201b84431c2361826138ce7c Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Sun, 15 Oct 2023 15:19:15 +0200 Subject: [PATCH 19/31] Fixed created controllers --- examples/dartness_simple/lib/src/app.g.dart | 4 +++- .../dartness_generator/lib/src/application_generator.dart | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/dartness_simple/lib/src/app.g.dart b/examples/dartness_simple/lib/src/app.g.dart index 6ec17925..2445e8d3 100644 --- a/examples/dartness_simple/lib/src/app.g.dart +++ b/examples/dartness_simple/lib/src/app.g.dart @@ -21,7 +21,9 @@ extension AppExtension on App { final injectRegister = InstanceRegister.instance; final app = Dartness(); await app.create( - controllers: [], + controllers: [ + CityDartnessController(injectRegister.resolve()), + ], options: DartnessApplicationOptions(), ); } diff --git a/packages/dartness_generator/lib/src/application_generator.dart b/packages/dartness_generator/lib/src/application_generator.dart index a816d65f..ffb00d58 100644 --- a/packages/dartness_generator/lib/src/application_generator.dart +++ b/packages/dartness_generator/lib/src/application_generator.dart @@ -141,8 +141,10 @@ class ApplicationGenerator extends GeneratorForAnnotation { final moduleMetadata = applicationModule.getField('metadata'); final controllers = moduleMetadata?.getField('controllers')?.toListValue() ?? []; + final controllerElements = controllers - .map((e) => e.toTypeValue()?.element) + .map((e) => e.getField('classType')) + .map((e) => e?.toTypeValue()?.element) .whereType() .toList(); final applicationOptions = annotation.read('options').objectValue; @@ -178,8 +180,8 @@ class ApplicationGenerator extends GeneratorForAnnotation { } void _generateControllers( - List controllerElements, - StringBuffer buffer, + final List controllerElements, + final StringBuffer buffer, ) { buffer.writeln('controllers: ['); for (final controllerElement in controllerElements) { From c9128c0f8d5205f83d2ebf34a27c9f6ef08ad2af Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Sun, 15 Oct 2023 16:08:45 +0200 Subject: [PATCH 20/31] Fixed generating options --- examples/dartness_simple/lib/src/app.g.dart | 5 ++++- .../dartness_generator/lib/src/application_generator.dart | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/dartness_simple/lib/src/app.g.dart b/examples/dartness_simple/lib/src/app.g.dart index 2445e8d3..e22736d0 100644 --- a/examples/dartness_simple/lib/src/app.g.dart +++ b/examples/dartness_simple/lib/src/app.g.dart @@ -24,7 +24,10 @@ extension AppExtension on App { controllers: [ CityDartnessController(injectRegister.resolve()), ], - options: DartnessApplicationOptions(), + options: DartnessApplicationOptions( + logRequest: false, + port: 8080, + ), ); } } diff --git a/packages/dartness_generator/lib/src/application_generator.dart b/packages/dartness_generator/lib/src/application_generator.dart index ffb00d58..81686b1a 100644 --- a/packages/dartness_generator/lib/src/application_generator.dart +++ b/packages/dartness_generator/lib/src/application_generator.dart @@ -155,10 +155,10 @@ class ApplicationGenerator extends GeneratorForAnnotation { buffer.writeln(');'); } else { final logRequest = - applicationOptions.getField('logRequest')?.toBoolValue(); - final port = applicationOptions.getField('port')?.toIntValue(); + applicationOptions.getField('_logRequest')?.toBoolValue(); + final port = applicationOptions.getField('_port')?.toIntValue(); final internetAddress = - applicationOptions.getField('internetAddress')?.toTypeValue(); + applicationOptions.getField('_internetAddress')?.toTypeValue(); buffer.writeln('await app.create('); _generateControllers(controllerElements, buffer); buffer.writeln('options: DartnessApplicationOptions('); From 2ddcb31a5c221958413b90f59199b3eb0be66453 Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Sun, 15 Oct 2023 19:26:03 +0200 Subject: [PATCH 21/31] - Fixed generator to generate the controllers in the register - Improved simple example in order to provide a simple project split by modules --- examples/dartness_simple/lib/app_module.dart | 2 +- examples/dartness_simple/lib/src/app.dart | 13 +++- examples/dartness_simple/lib/src/app.g.dart | 4 ++ .../{ => city}/city_controller.dart | 4 +- .../{ => city}/city_controller.g.dart | 0 .../lib/src/controllers/city/city_module.dart | 13 ++++ .../src/controllers/health_controller.dart | 15 +++++ .../src/controllers/health_controller.g.dart | 30 +++++++++ .../src/controllers/user/user_controller.dart | 17 +++++ .../controllers/user/user_controller.g.dart | 43 +++++++++++++ .../lib/src/controllers/user/user_module.dart | 13 ++++ .../lib/src/application_generator.dart | 63 +++++++++++++------ packages/dartness_generator/pubspec.yaml | 1 + 13 files changed, 192 insertions(+), 26 deletions(-) rename examples/dartness_simple/lib/src/controllers/{ => city}/city_controller.dart (86%) rename examples/dartness_simple/lib/src/controllers/{ => city}/city_controller.g.dart (100%) create mode 100644 examples/dartness_simple/lib/src/controllers/city/city_module.dart create mode 100644 examples/dartness_simple/lib/src/controllers/health_controller.dart create mode 100644 examples/dartness_simple/lib/src/controllers/health_controller.g.dart create mode 100644 examples/dartness_simple/lib/src/controllers/user/user_controller.dart create mode 100644 examples/dartness_simple/lib/src/controllers/user/user_controller.g.dart create mode 100644 examples/dartness_simple/lib/src/controllers/user/user_module.dart diff --git a/examples/dartness_simple/lib/app_module.dart b/examples/dartness_simple/lib/app_module.dart index e4290b34..5b001e87 100644 --- a/examples/dartness_simple/lib/app_module.dart +++ b/examples/dartness_simple/lib/app_module.dart @@ -1,7 +1,7 @@ import 'package:dartness_server/modules.dart'; import 'package:example/src/services/city_service.dart'; -import 'src/controllers/city_controller.dart'; +import 'src/controllers/city/city_controller.dart'; @Module( metadata: ModuleMetadata( diff --git a/examples/dartness_simple/lib/src/app.dart b/examples/dartness_simple/lib/src/app.dart index cd3e4845..bcba05c9 100644 --- a/examples/dartness_simple/lib/src/app.dart +++ b/examples/dartness_simple/lib/src/app.dart @@ -1,9 +1,13 @@ import 'package:dartness_server/dartness.dart'; import 'package:dartness_server/modules.dart'; import 'package:dartness_server/server.dart'; +import 'package:example/src/controllers/city/city_module.dart'; +import 'package:example/src/controllers/user/user_module.dart'; import 'package:example/src/services/city_service.dart'; -import 'controllers/city_controller.dart'; +import 'controllers/city/city_controller.dart'; +import 'controllers/health_controller.dart'; +import 'controllers/user/user_controller.dart'; import 'error_handlers/example_error_handler.dart'; part 'app.g.dart'; @@ -13,7 +17,7 @@ part 'app.g.dart'; metadata: ModuleMetadata( controllers: [ ProviderMetadata( - classType: CityController, + classType: HealthController, ), ], providers: [ @@ -28,7 +32,10 @@ part 'app.g.dart'; ), ], exports: [], - imports: [], + imports: [ + userModule, + cityModule, + ], ), ), options: DartnessApplicationOptions( diff --git a/examples/dartness_simple/lib/src/app.g.dart b/examples/dartness_simple/lib/src/app.g.dart index e22736d0..a45c732c 100644 --- a/examples/dartness_simple/lib/src/app.g.dart +++ b/examples/dartness_simple/lib/src/app.g.dart @@ -9,10 +9,12 @@ part of 'app.dart'; extension AppExtension on App { initDependencies() { final injectRegister = InstanceRegister.instance; + injectRegister.register(UserController()); injectRegister.register(CityService()); injectRegister.register(CityController( injectRegister.resolve(), )); + injectRegister.register(HealthController()); injectRegister.register(ExampleErrorHandler()); } @@ -22,7 +24,9 @@ extension AppExtension on App { final app = Dartness(); await app.create( controllers: [ + UserDartnessController(injectRegister.resolve()), CityDartnessController(injectRegister.resolve()), + HealthDartnessController(injectRegister.resolve()), ], options: DartnessApplicationOptions( logRequest: false, diff --git a/examples/dartness_simple/lib/src/controllers/city_controller.dart b/examples/dartness_simple/lib/src/controllers/city/city_controller.dart similarity index 86% rename from examples/dartness_simple/lib/src/controllers/city_controller.dart rename to examples/dartness_simple/lib/src/controllers/city/city_controller.dart index bde2698a..ca6f03ab 100644 --- a/examples/dartness_simple/lib/src/controllers/city_controller.dart +++ b/examples/dartness_simple/lib/src/controllers/city/city_controller.dart @@ -2,8 +2,8 @@ import 'dart:io'; import 'package:dartness_server/route.dart'; -import '../dtos/city_dto.dart'; -import '../services/city_service.dart'; +import '../../dtos/city_dto.dart'; +import '../../services/city_service.dart'; part 'city_controller.g.dart'; diff --git a/examples/dartness_simple/lib/src/controllers/city_controller.g.dart b/examples/dartness_simple/lib/src/controllers/city/city_controller.g.dart similarity index 100% rename from examples/dartness_simple/lib/src/controllers/city_controller.g.dart rename to examples/dartness_simple/lib/src/controllers/city/city_controller.g.dart diff --git a/examples/dartness_simple/lib/src/controllers/city/city_module.dart b/examples/dartness_simple/lib/src/controllers/city/city_module.dart new file mode 100644 index 00000000..0af28b6c --- /dev/null +++ b/examples/dartness_simple/lib/src/controllers/city/city_module.dart @@ -0,0 +1,13 @@ +import 'package:dartness_server/modules.dart'; + +import 'city_controller.dart'; + +const cityModule = Module( + metadata: ModuleMetadata( + controllers: [ + ProviderMetadata( + classType: CityController, + ), + ], + ), +); diff --git a/examples/dartness_simple/lib/src/controllers/health_controller.dart b/examples/dartness_simple/lib/src/controllers/health_controller.dart new file mode 100644 index 00000000..5fd59739 --- /dev/null +++ b/examples/dartness_simple/lib/src/controllers/health_controller.dart @@ -0,0 +1,15 @@ +import 'dart:io'; + +import 'package:dartness_server/route.dart'; + +part 'health_controller.g.dart'; + +@Controller('/health') +@Header(HttpHeaders.contentTypeHeader, 'application/json') +class HealthController { + @HttpCode(202) + @Get() + bool getAlive() { + return true; + } +} diff --git a/examples/dartness_simple/lib/src/controllers/health_controller.g.dart b/examples/dartness_simple/lib/src/controllers/health_controller.g.dart new file mode 100644 index 00000000..26528a21 --- /dev/null +++ b/examples/dartness_simple/lib/src/controllers/health_controller.g.dart @@ -0,0 +1,30 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'health_controller.dart'; + +// ************************************************************************** +// ControllerGenerator +// ************************************************************************** + +extension HealthControllerRoutes on HealthController { + List getRoutes() { + final routes = []; + routes.add(ControllerRoute( + method: 'GET', + path: '/health', + handler: getAlive, + params: [], + httpCode: 202, + headers: {'content-type': 'application/json'}, + )); + return routes; + } +} + +class HealthDartnessController extends DartnessController { + HealthDartnessController(HealthController controller) + : super( + controller, + controller.getRoutes(), + ); +} diff --git a/examples/dartness_simple/lib/src/controllers/user/user_controller.dart b/examples/dartness_simple/lib/src/controllers/user/user_controller.dart new file mode 100644 index 00000000..26968d2b --- /dev/null +++ b/examples/dartness_simple/lib/src/controllers/user/user_controller.dart @@ -0,0 +1,17 @@ +import 'dart:io'; + +import 'package:dartness_server/route.dart'; + +part 'user_controller.g.dart'; + +@Controller('/users') +@Header(HttpHeaders.contentTypeHeader, 'application/json') +class UserController { + @HttpCode(202) + @Get() + List getCities({ + @QueryParam() int? offset, + }) { + return ['user1', 'user2']; + } +} diff --git a/examples/dartness_simple/lib/src/controllers/user/user_controller.g.dart b/examples/dartness_simple/lib/src/controllers/user/user_controller.g.dart new file mode 100644 index 00000000..f90ea1c9 --- /dev/null +++ b/examples/dartness_simple/lib/src/controllers/user/user_controller.g.dart @@ -0,0 +1,43 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'user_controller.dart'; + +// ************************************************************************** +// ControllerGenerator +// ************************************************************************** + +extension UserControllerRoutes on UserController { + List getRoutes() { + final routes = []; + routes.add(ControllerRoute( + method: 'GET', + path: '/users', + handler: getCities, + params: [ + DartnessParam( + name: 'offset', + isQuery: true, + isPath: false, + isBody: false, + isNamed: true, + isPositional: false, + isOptional: true, + type: int, + defaultValue: null, + fromJson: null, + ) + ], + httpCode: 202, + headers: {'content-type': 'application/json'}, + )); + return routes; + } +} + +class UserDartnessController extends DartnessController { + UserDartnessController(UserController controller) + : super( + controller, + controller.getRoutes(), + ); +} diff --git a/examples/dartness_simple/lib/src/controllers/user/user_module.dart b/examples/dartness_simple/lib/src/controllers/user/user_module.dart new file mode 100644 index 00000000..55d5dbd4 --- /dev/null +++ b/examples/dartness_simple/lib/src/controllers/user/user_module.dart @@ -0,0 +1,13 @@ +import 'package:dartness_server/modules.dart'; + +import '../user/user_controller.dart'; + +const userModule = Module( + metadata: ModuleMetadata( + controllers: [ + ProviderMetadata( + classType: UserController, + ), + ], + ), +); diff --git a/packages/dartness_generator/lib/src/application_generator.dart b/packages/dartness_generator/lib/src/application_generator.dart index 81686b1a..68c4c6ee 100644 --- a/packages/dartness_generator/lib/src/application_generator.dart +++ b/packages/dartness_generator/lib/src/application_generator.dart @@ -38,12 +38,21 @@ class ApplicationGenerator extends GeneratorForAnnotation { buffer.writeln('final injectRegister = InstanceRegister.instance;'); final applicationModule = annotation.read('module').objectValue; final moduleMetadata = applicationModule.getField('metadata'); - final controllers = + final imports = moduleMetadata?.getField('imports')?.toListValue() ?? []; + final List importControllers = imports + .map((e) => e.getField('metadata')) + .expand( + (e) => e?.getField('controllers')?.toListValue() ?? []) + .toList(); + final List controllers = moduleMetadata?.getField('controllers')?.toListValue() ?? []; + + final List allControllers = importControllers + controllers; + final providers = moduleMetadata?.getField('providers')?.toListValue() ?? []; final List allInstances = []; - allInstances.addAll(controllers); + allInstances.addAll(allControllers); allInstances.addAll(providers); final allProviderElements = allInstances .map((e) => e.getField('classType')) @@ -130,7 +139,7 @@ class ApplicationGenerator extends GeneratorForAnnotation { return dependencies; } - void _createMain(StringBuffer buffer, ConstantReader annotation) { + void _createMain(final StringBuffer buffer, final ConstantReader annotation) { buffer.writeln('Future main() async {'); buffer.writeln('initDependencies();'); @@ -139,10 +148,17 @@ class ApplicationGenerator extends GeneratorForAnnotation { final applicationModule = annotation.read('module').objectValue; final moduleMetadata = applicationModule.getField('metadata'); + final imports = moduleMetadata?.getField('imports')?.toListValue() ?? []; + final importControllers = imports + .map((e) => e.getField('metadata')) + .expand( + (e) => e?.getField('controllers')?.toListValue() ?? []) + .toList(); final controllers = moduleMetadata?.getField('controllers')?.toListValue() ?? []; + final allControllers = importControllers + controllers; - final controllerElements = controllers + final controllerElements = allControllers .map((e) => e.getField('classType')) .map((e) => e?.toTypeValue()?.element) .whereType() @@ -154,24 +170,9 @@ class ApplicationGenerator extends GeneratorForAnnotation { _generateControllers(controllerElements, buffer); buffer.writeln(');'); } else { - final logRequest = - applicationOptions.getField('_logRequest')?.toBoolValue(); - final port = applicationOptions.getField('_port')?.toIntValue(); - final internetAddress = - applicationOptions.getField('_internetAddress')?.toTypeValue(); buffer.writeln('await app.create('); _generateControllers(controllerElements, buffer); - buffer.writeln('options: DartnessApplicationOptions('); - if (logRequest != null) { - buffer.writeln('logRequest: $logRequest,'); - } - if (port != null) { - buffer.writeln('port: $port,'); - } - if (internetAddress != null) { - buffer.writeln('internetAddress: $internetAddress,'); - } - buffer.writeln('),'); + _generateOptions(applicationOptions, buffer); buffer.writeln(');'); } @@ -179,6 +180,28 @@ class ApplicationGenerator extends GeneratorForAnnotation { buffer.writeln('}'); } + void _generateOptions( + final DartObject applicationOptions, + final StringBuffer buffer, + ) { + final logRequest = + applicationOptions.getField('_logRequest')?.toBoolValue(); + final port = applicationOptions.getField('_port')?.toIntValue(); + final internetAddress = + applicationOptions.getField('_internetAddress')?.toTypeValue(); + buffer.writeln('options: DartnessApplicationOptions('); + if (logRequest != null) { + buffer.writeln('logRequest: $logRequest,'); + } + if (port != null) { + buffer.writeln('port: $port,'); + } + if (internetAddress != null) { + buffer.writeln('internetAddress: $internetAddress,'); + } + buffer.writeln('),'); + } + void _generateControllers( final List controllerElements, final StringBuffer buffer, diff --git a/packages/dartness_generator/pubspec.yaml b/packages/dartness_generator/pubspec.yaml index 950cbc41..a278d13b 100644 --- a/packages/dartness_generator/pubspec.yaml +++ b/packages/dartness_generator/pubspec.yaml @@ -10,6 +10,7 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: + collection: ^1.18.0 build: ^2.4.1 source_gen: ^1.4.0 analyzer: ^6.3.0 From b7c98f80253cb8187179c706303b6f2e13934c6f Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Sun, 15 Oct 2023 19:26:21 +0200 Subject: [PATCH 22/31] Added build in .gitignore --- examples/dartness_simple/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/dartness_simple/.gitignore b/examples/dartness_simple/.gitignore index 65c34dc8..4c1d3c7f 100644 --- a/examples/dartness_simple/.gitignore +++ b/examples/dartness_simple/.gitignore @@ -8,3 +8,4 @@ build/ # Omit committing pubspec.lock for library packages; see # https://dart.dev/guides/libraries/private-files#pubspeclock. pubspec.lock +/build.dart From 2499fc6e5242690d347c5dd56615f856055f9b3d Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Tue, 17 Oct 2023 19:45:30 +0200 Subject: [PATCH 23/31] Added comments and recursive providers --- .../lib/src/application_generator.dart | 71 ++++++++++++------- .../lib/src/app/application.dart | 4 ++ .../lib/src/modules/module.dart | 1 + 3 files changed, 51 insertions(+), 25 deletions(-) diff --git a/packages/dartness_generator/lib/src/application_generator.dart b/packages/dartness_generator/lib/src/application_generator.dart index 68c4c6ee..99bedb9f 100644 --- a/packages/dartness_generator/lib/src/application_generator.dart +++ b/packages/dartness_generator/lib/src/application_generator.dart @@ -29,6 +29,7 @@ class ApplicationGenerator extends GeneratorForAnnotation { return null; } + /// Creates 'initDependencies' method void _createInitDependencies( final StringBuffer buffer, final ConstantReader annotation, @@ -38,22 +39,12 @@ class ApplicationGenerator extends GeneratorForAnnotation { buffer.writeln('final injectRegister = InstanceRegister.instance;'); final applicationModule = annotation.read('module').objectValue; final moduleMetadata = applicationModule.getField('metadata'); - final imports = moduleMetadata?.getField('imports')?.toListValue() ?? []; - final List importControllers = imports - .map((e) => e.getField('metadata')) - .expand( - (e) => e?.getField('controllers')?.toListValue() ?? []) - .toList(); - final List controllers = - moduleMetadata?.getField('controllers')?.toListValue() ?? []; + final List allControllers = _getAllControllers(moduleMetadata); + final List allProviders = _getAllProviders(moduleMetadata); - final List allControllers = importControllers + controllers; - - final providers = - moduleMetadata?.getField('providers')?.toListValue() ?? []; final List allInstances = []; allInstances.addAll(allControllers); - allInstances.addAll(providers); + allInstances.addAll(allProviders); final allProviderElements = allInstances .map((e) => e.getField('classType')) .map((e) => e?.toTypeValue()?.element) @@ -94,6 +85,39 @@ class ApplicationGenerator extends GeneratorForAnnotation { buffer.writeln('}'); } + /// Obtains all the controllers from [moduleMetadata] + List _getAllControllers(final DartObject? moduleMetadata) { + return _getAllFieldFromModuleMetadata(moduleMetadata, 'controllers'); + } + + /// Obtains all the providers from [moduleMetadata] + List _getAllProviders(final DartObject? moduleMetadata) { + return _getAllFieldFromModuleMetadata(moduleMetadata, 'providers'); + } + + List _getAllFieldFromModuleMetadata( + final DartObject? moduleMetadata, + final String field, + ) { + if (moduleMetadata == null) { + return []; + } + + final List imports = + moduleMetadata.getField('imports')?.toListValue() ?? []; + final metadataList = imports + .map((e) => e.getField('metadata')) + .expand((e) => _getAllFieldFromModuleMetadata(e, field)) + .toList(); + + final List controllers = + moduleMetadata.getField(field)?.toListValue() ?? []; + + return metadataList + controllers; + } + + /// Sort the dependencies by a topological sort to add the dependencies + /// for each class that requires as inversion control List _topologicalSort(final List dependencies) { final visited = {}; final sorted = []; @@ -105,6 +129,8 @@ class ApplicationGenerator extends GeneratorForAnnotation { return sorted.toList(); } + /// Marks the [dependency] as visited in [visited] set and add it also in + /// [sorted] list void _visit(final ClassElement dependency, final Set visited, final List sorted) { if (visited.contains(dependency)) { @@ -122,10 +148,11 @@ class ApplicationGenerator extends GeneratorForAnnotation { sorted.add(dependency); } - List _getDependencies(ClassElement dependency) { + /// Obtains the dependencies of a class by his constructor + List _getDependencies(final ClassElement clazz) { final dependencies = []; - final constructor = dependency.unnamedConstructor; + final constructor = clazz.unnamedConstructor; if (constructor != null) { final parameters = constructor.parameters; for (final param in parameters) { @@ -139,6 +166,8 @@ class ApplicationGenerator extends GeneratorForAnnotation { return dependencies; } + /// Creates the 'main' method into the [buffer] by [annotation] that must be + /// [Application] void _createMain(final StringBuffer buffer, final ConstantReader annotation) { buffer.writeln('Future main() async {'); @@ -147,16 +176,8 @@ class ApplicationGenerator extends GeneratorForAnnotation { buffer.writeln('final app = Dartness();'); final applicationModule = annotation.read('module').objectValue; - final moduleMetadata = applicationModule.getField('metadata'); - final imports = moduleMetadata?.getField('imports')?.toListValue() ?? []; - final importControllers = imports - .map((e) => e.getField('metadata')) - .expand( - (e) => e?.getField('controllers')?.toListValue() ?? []) - .toList(); - final controllers = - moduleMetadata?.getField('controllers')?.toListValue() ?? []; - final allControllers = importControllers + controllers; + final rootModuleMetadata = applicationModule.getField('metadata'); + final allControllers = _getAllControllers(rootModuleMetadata); final controllerElements = allControllers .map((e) => e.getField('classType')) diff --git a/packages/dartness_server/lib/src/app/application.dart b/packages/dartness_server/lib/src/app/application.dart index aadea7af..19dc0fca 100644 --- a/packages/dartness_server/lib/src/app/application.dart +++ b/packages/dartness_server/lib/src/app/application.dart @@ -1,8 +1,12 @@ import '../modules/module.dart'; import '../server/dartness_application_options.dart'; +/// App annotation in order to create an application class Application { + /// Root module final Module module; + + /// Application options final DartnessApplicationOptions options; const Application({ diff --git a/packages/dartness_server/lib/src/modules/module.dart b/packages/dartness_server/lib/src/modules/module.dart index fff6e3eb..18c1e8d3 100644 --- a/packages/dartness_server/lib/src/modules/module.dart +++ b/packages/dartness_server/lib/src/modules/module.dart @@ -2,6 +2,7 @@ import 'module_metadata.dart'; /// Module class that accepts different metadata class Module { + /// Module's metadata final ModuleMetadata metadata; const Module({required this.metadata}); From 34b1e1ce6f48f33f06c65c5ef22af3e458d277ef Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Tue, 17 Oct 2023 19:59:24 +0200 Subject: [PATCH 24/31] Fixed tests --- .../lib/src/route/dartness_router_handler.dart | 16 ++++++++++++---- .../lib/src/bind/annotation/controller_test.dart | 8 +++----- .../exception/annotation/catch_handler_test.dart | 8 ++------ .../src/server/dartness_interceptor_test.dart | 8 ++------ .../lib/src/server/dartness_middleware_test.dart | 10 +++------- 5 files changed, 22 insertions(+), 28 deletions(-) diff --git a/packages/dartness_server/lib/src/route/dartness_router_handler.dart b/packages/dartness_server/lib/src/route/dartness_router_handler.dart index 1df9fe08..bc84898f 100644 --- a/packages/dartness_server/lib/src/route/dartness_router_handler.dart +++ b/packages/dartness_server/lib/src/route/dartness_router_handler.dart @@ -24,12 +24,20 @@ class DartnessRouterHandler { if (param.isPositional) { if (param.isPath) { final pathParam = _getPathParam(request, param); - final value = pathParam.stringToType(param.type); - positionalArguments.add(value); + if (pathParam is String) { + final value = pathParam.stringToType(param.type); + positionalArguments.add(value); + } else { + positionalArguments.add(pathParam); + } } else if (param.isQuery) { final queryParam = _getQueryParam(request, param); - final value = queryParam.stringToType(param.type); - positionalArguments.add(value); + if (queryParam is String) { + final value = queryParam.stringToType(param.type); + positionalArguments.add(value); + } else { + positionalArguments.add(queryParam); + } } else { final bodyJson = await request.body.asJson; final bodyInstance = param.fromJson?.call(bodyJson); diff --git a/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart b/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart index aa0cab14..8e1417d1 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart @@ -2,10 +2,12 @@ import 'dart:convert'; import 'dart:io'; import 'package:dartness_server/dartness.dart'; +import 'package:dartness_server/modules.dart'; import 'package:dartness_server/route.dart'; import 'package:dartness_server/server.dart'; import 'package:test/test.dart'; +import '../../app_module.dart'; import 'class_controller.dart'; import 'delete_controller_class.dart'; import 'get_controller_class.dart'; @@ -64,11 +66,7 @@ void main() { httpClient = HttpClient(); dartness = await Dartness().create( - // AppModule( - // metadata: ModuleMetadata( - // controllers: controllers, - // ), - // ), + controllers: controllers, options: DartnessApplicationOptions( port: port, ), diff --git a/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart b/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart index de2524a4..6a78fb73 100644 --- a/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart +++ b/packages/dartness_server/test/lib/src/exception/annotation/catch_handler_test.dart @@ -25,12 +25,8 @@ void main() { httpClient = HttpClient(); dartness = await Dartness().create( - // AppModule( - // metadata: ModuleMetadata( - // controllers: controllers, - // providers: errorHandlers, - // ), - // ), + controllers: controllers, + errorHandlers: errorHandlers, options: DartnessApplicationOptions( port: port, ), diff --git a/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart b/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart index 86d2c7cc..8d6e555c 100644 --- a/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart +++ b/packages/dartness_server/test/lib/src/server/dartness_interceptor_test.dart @@ -26,12 +26,8 @@ void main() { httpClient = HttpClient(); dartness = await Dartness().create( - // AppModule( - // metadata: ModuleMetadata( - // controllers: controllers, - // providers: interceptors, - // ), - // ), + controllers: controllers, + interceptors: interceptors, options: DartnessApplicationOptions( port: port, ), diff --git a/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart b/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart index 3d81fcce..0ed45fbc 100644 --- a/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart +++ b/packages/dartness_server/test/lib/src/server/dartness_middleware_test.dart @@ -18,17 +18,13 @@ void main() { TestDartnessController(TestController.instance), ]; - final interceptors = [ + final middlewares = [ TestMiddleware(), ]; httpClient = HttpClient(); dartness = await Dartness().create( - // AppModule( - // metadata: ModuleMetadata( - // controllers: controllers, - // providers: interceptors, - // ), - // ), + controllers: controllers, + middlewares: middlewares, options: DartnessApplicationOptions( port: port, ), From cab03a0adb90dc8fee224ca88fc3ad4e118568e9 Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Tue, 17 Oct 2023 19:59:48 +0200 Subject: [PATCH 25/31] Removed unused imports --- .../test/lib/src/bind/annotation/controller_test.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart b/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart index 8e1417d1..c935e232 100644 --- a/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart +++ b/packages/dartness_server/test/lib/src/bind/annotation/controller_test.dart @@ -2,12 +2,10 @@ import 'dart:convert'; import 'dart:io'; import 'package:dartness_server/dartness.dart'; -import 'package:dartness_server/modules.dart'; import 'package:dartness_server/route.dart'; import 'package:dartness_server/server.dart'; import 'package:test/test.dart'; -import '../../app_module.dart'; import 'class_controller.dart'; import 'delete_controller_class.dart'; import 'get_controller_class.dart'; From d3818e10f7800751279dddd3f1bacba91dc700ea Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Wed, 18 Oct 2023 14:22:50 +0200 Subject: [PATCH 26/31] Changed 'main' to 'init' --- examples/dartness_simple/bin/example.dart | 2 +- examples/dartness_simple/lib/src/app.g.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/dartness_simple/bin/example.dart b/examples/dartness_simple/bin/example.dart index 46576e19..872f0713 100644 --- a/examples/dartness_simple/bin/example.dart +++ b/examples/dartness_simple/bin/example.dart @@ -1,5 +1,5 @@ import 'package:example/src/app.dart'; void main(List args) async { - await App().main(); + await App().init(); } diff --git a/examples/dartness_simple/lib/src/app.g.dart b/examples/dartness_simple/lib/src/app.g.dart index a45c732c..4f5c5dea 100644 --- a/examples/dartness_simple/lib/src/app.g.dart +++ b/examples/dartness_simple/lib/src/app.g.dart @@ -18,7 +18,7 @@ extension AppExtension on App { injectRegister.register(ExampleErrorHandler()); } - Future main() async { + Future init() async { initDependencies(); final injectRegister = InstanceRegister.instance; final app = Dartness(); From 70384494463672fa862735cfd32740eff71560d4 Mon Sep 17 00:00:00 2001 From: RicardoRB Date: Wed, 18 Oct 2023 14:23:44 +0200 Subject: [PATCH 27/31] Updated docs --- .../doc/api/__404error.html | 10 +- .../doc/api/builder/application.html | 128 ++ .../api/builder/builder-library-sidebar.html | 14 + .../doc/api/builder/builder-library.html | 170 +++ .../doc/api/builder/controller.html | 128 ++ .../doc/api/builder/errorHandler.html | 128 ++ .../dartness_generator-library-sidebar.html | 10 + .../dartness_generator-library.html | 64 +- .../dartness_generator/doc/api/index.html | 19 +- .../dartness_generator/doc/api/index.json | 2 +- .../dartness_generator/doc/api/search.html | 12 +- .../doc/api/static-assets/highlight.pack.js | 1347 +++++++++-------- .../dartness_server/doc/api/__404error.html | 8 +- .../dartness/Application-class-sidebar.html | 25 + .../doc/api/dartness/Application-class.html | 241 +++ .../api/dartness/Application/Application.html | 125 ++ .../doc/api/dartness/Application/module.html | 127 ++ .../doc/api/dartness/Application/options.html | 127 ++ .../api/dartness/Dartness-class-sidebar.html | 24 + .../doc/api/dartness/Dartness-class.html | 138 +- .../doc/api/dartness/Dartness/Dartness.html | 86 +- .../doc/api/dartness/Dartness/create.html | 88 +- .../InstanceRegister-class-sidebar.html | 25 + .../api/dartness/InstanceRegister-class.html | 246 +++ .../dartness/InstanceRegister/instance.html | 124 ++ .../dartness/InstanceRegister/register.html | 138 ++ .../dartness/InstanceRegister/resolve.html | 145 ++ .../dartness/dartness-library-sidebar.html | 14 + .../doc/api/dartness/dartness-library.html | 45 +- .../exception/CatchError-class-sidebar.html | 24 + .../doc/api/exception/CatchError-class.html | 62 +- .../api/exception/CatchError/CatchError.html | 44 +- .../doc/api/exception/CatchError/errors.html | 42 +- .../DartnessCatchError-class-sidebar.html | 26 + .../exception/DartnessCatchError-class.html | 64 +- .../DartnessCatchError.html | 46 +- .../DartnessCatchError/canHandle.html | 44 +- .../DartnessCatchError/errorTypes.html | 44 +- .../exception/DartnessCatchError/handler.html | 44 +- ...tnessCatchErrorRegister-class-sidebar.html | 25 + .../DartnessCatchErrorRegister-class.html | 63 +- .../DartnessCatchErrorRegister.html | 43 +- .../addCatchError.html | 43 +- .../DartnessCatchErrorRegister/handle.html | 43 +- .../DartnessErrorHandler-class-sidebar.html | 25 + .../exception/DartnessErrorHandler-class.html | 63 +- .../DartnessErrorHandler.html | 45 +- .../DartnessErrorHandler/catchErrors.html | 43 +- .../DartnessErrorHandler/errorHandler.html | 43 +- .../exception/ErrorHandler-class-sidebar.html | 23 + .../doc/api/exception/ErrorHandler-class.html | 61 +- .../exception/ErrorHandler/ErrorHandler.html | 43 +- .../HttpStatusException-class-sidebar.html | 25 + .../exception/HttpStatusException-class.html | 63 +- .../HttpStatusException.html | 45 +- .../HttpStatusException/message.html | 43 +- .../HttpStatusException/statusCode.html | 43 +- .../exception/exception-library-sidebar.html | 18 + .../doc/api/exception/exception-library.html | 35 +- packages/dartness_server/doc/api/index.html | 17 +- packages/dartness_server/doc/api/index.json | 2 +- .../doc/api/modules/Module-class-sidebar.html | 24 + .../doc/api/modules/Module-class.html | 230 +++ .../doc/api/modules/Module/Module.html | 124 ++ .../doc/api/modules/Module/metadata.html | 127 ++ .../modules/ModuleMetadata-class-sidebar.html | 27 + .../doc/api/modules/ModuleMetadata-class.html | 267 ++++ .../ModuleMetadata/ModuleMetadata.html | 127 ++ .../modules/ModuleMetadata/controllers.html | 128 ++ .../api/modules/ModuleMetadata/exports.html | 128 ++ .../api/modules/ModuleMetadata/imports.html | 128 ++ .../api/modules/ModuleMetadata/providers.html | 128 ++ .../ProviderMetadata-class-sidebar.html | 24 + .../api/modules/ProviderMetadata-class.html | 227 +++ .../ProviderMetadata/ProviderMetadata.html | 124 ++ .../modules/ProviderMetadata/classType.html | 124 ++ .../api/modules/modules-library-sidebar.html | 14 + .../doc/api/modules/modules-library.html | 162 ++ .../doc/api/route/Bind-class-sidebar.html | 25 + .../doc/api/route/Bind-class.html | 79 +- .../doc/api/route/Bind/Bind.html | 45 +- .../doc/api/route/Bind/method.html | 43 +- .../doc/api/route/Bind/path.html | 43 +- .../doc/api/route/Body-class-sidebar.html | 23 + .../doc/api/route/Body-class.html | 77 +- .../doc/api/route/Body/Body.html | 43 +- .../doc/api/route/Connect-class-sidebar.html | 25 + .../doc/api/route/Connect-class.html | 79 +- .../doc/api/route/Connect/Connect.html | 45 +- .../api/route/Controller-class-sidebar.html | 24 + .../doc/api/route/Controller-class.html | 80 +- .../doc/api/route/Controller/Controller.html | 44 +- .../doc/api/route/Controller/path.html | 42 +- .../route/ControllerRoute-class-sidebar.html | 29 + .../doc/api/route/ControllerRoute-class.html | 85 +- .../ControllerRoute/ControllerRoute.html | 66 +- .../api/route/ControllerRoute/handler.html | 47 +- .../api/route/ControllerRoute/headers.html | 47 +- .../api/route/ControllerRoute/httpCode.html | 47 +- .../doc/api/route/ControllerRoute/method.html | 47 +- .../doc/api/route/ControllerRoute/params.html | 47 +- .../doc/api/route/ControllerRoute/path.html | 47 +- .../DartnessController-class-sidebar.html | 25 + .../api/route/DartnessController-class.html | 79 +- .../DartnessController.html | 45 +- .../route/DartnessController/controller.html | 43 +- .../api/route/DartnessController/routes.html | 43 +- .../route/DartnessParam-class-sidebar.html | 33 + .../doc/api/route/DartnessParam-class.html | 89 +- .../route/DartnessParam/DartnessParam.html | 82 +- .../api/route/DartnessParam/defaultValue.html | 51 +- .../doc/api/route/DartnessParam/fromJson.html | 51 +- .../doc/api/route/DartnessParam/isBody.html | 51 +- .../doc/api/route/DartnessParam/isNamed.html | 51 +- .../api/route/DartnessParam/isOptional.html | 51 +- .../doc/api/route/DartnessParam/isPath.html | 51 +- .../api/route/DartnessParam/isPositional.html | 51 +- .../doc/api/route/DartnessParam/isQuery.html | 51 +- .../doc/api/route/DartnessParam/name.html | 51 +- .../doc/api/route/DartnessParam/type.html | 51 +- .../route/DartnessRouter-class-sidebar.html | 25 + .../doc/api/route/DartnessRouter-class.html | 79 +- .../route/DartnessRouter/DartnessRouter.html | 43 +- .../doc/api/route/DartnessRouter/add.html | 43 +- .../doc/api/route/DartnessRouter/router.html | 43 +- .../DartnessRouterHandler-class-sidebar.html | 24 + .../route/DartnessRouterHandler-class.html | 78 +- .../DartnessRouterHandler.html | 44 +- .../DartnessRouterHandler/handleRoute.html | 64 +- .../DefaultDartnessRouter-class-sidebar.html | 25 + .../route/DefaultDartnessRouter-class.html | 79 +- .../DefaultDartnessRouter.html | 47 +- .../api/route/DefaultDartnessRouter/add.html | 43 +- .../route/DefaultDartnessRouter/router.html | 43 +- .../doc/api/route/Delete-class-sidebar.html | 25 + .../doc/api/route/Delete-class.html | 79 +- .../doc/api/route/Delete/Delete.html | 45 +- .../doc/api/route/Get-class-sidebar.html | 25 + .../doc/api/route/Get-class.html | 79 +- .../doc/api/route/Get/Get.html | 45 +- .../doc/api/route/Head-class-sidebar.html | 25 + .../doc/api/route/Head-class.html | 79 +- .../doc/api/route/Head/Head.html | 45 +- .../doc/api/route/Header-class-sidebar.html | 25 + .../doc/api/route/Header-class.html | 79 +- .../doc/api/route/Header/Header.html | 45 +- .../doc/api/route/Header/key.html | 43 +- .../doc/api/route/Header/value.html | 43 +- .../doc/api/route/Headers-class-sidebar.html | 24 + .../doc/api/route/Headers-class.html | 78 +- .../doc/api/route/Headers/Headers.html | 44 +- .../doc/api/route/Headers/values.html | 42 +- .../doc/api/route/HttpCode-class-sidebar.html | 24 + .../doc/api/route/HttpCode-class.html | 78 +- .../doc/api/route/HttpCode/HttpCode.html | 44 +- .../doc/api/route/HttpCode/code.html | 42 +- .../doc/api/route/Options-class-sidebar.html | 25 + .../doc/api/route/Options-class.html | 79 +- .../doc/api/route/Options/Options.html | 45 +- .../doc/api/route/Patch-class-sidebar.html | 25 + .../doc/api/route/Patch-class.html | 79 +- .../doc/api/route/Patch/Patch.html | 45 +- .../api/route/PathParam-class-sidebar.html | 24 + .../doc/api/route/PathParam-class.html | 78 +- .../doc/api/route/PathParam/PathParam.html | 44 +- .../doc/api/route/PathParam/name.html | 42 +- .../doc/api/route/Post-class-sidebar.html | 25 + .../doc/api/route/Post-class.html | 79 +- .../doc/api/route/Post/Post.html | 45 +- .../doc/api/route/Put-class-sidebar.html | 25 + .../doc/api/route/Put-class.html | 79 +- .../doc/api/route/Put/Put.html | 45 +- .../api/route/QueryParam-class-sidebar.html | 24 + .../doc/api/route/QueryParam-class.html | 78 +- .../doc/api/route/QueryParam/QueryParam.html | 44 +- .../doc/api/route/QueryParam/name.html | 42 +- .../doc/api/route/Trace-class-sidebar.html | 25 + .../doc/api/route/Trace-class.html | 79 +- .../doc/api/route/Trace/Trace.html | 45 +- .../doc/api/route/route-library-sidebar.html | 34 + .../doc/api/route/route-library.html | 51 +- packages/dartness_server/doc/api/search.html | 10 +- ...tnessApplicationOptions-class-sidebar.html | 26 + .../DartnessApplicationOptions-class.html | 249 +++ .../DartnessApplicationOptions.html | 126 ++ .../internetAddress.html | 132 ++ .../logRequest.html | 131 ++ .../DartnessApplicationOptions/port.html | 131 ++ .../DartnessInterceptor-class-sidebar.html | 26 + .../api/server/DartnessInterceptor-class.html | 66 +- .../DartnessInterceptor.html | 44 +- .../server/DartnessInterceptor/onError.html | 44 +- .../server/DartnessInterceptor/onRequest.html | 44 +- .../DartnessInterceptor/onResponse.html | 44 +- .../DartnessMiddleware-class-sidebar.html | 24 + .../api/server/DartnessMiddleware-class.html | 64 +- .../DartnessMiddleware.html | 42 +- .../api/server/DartnessMiddleware/handle.html | 42 +- .../DartnessPipeline-class-sidebar.html | 27 + .../api/server/DartnessPipeline-class.html | 67 +- .../DartnessPipeline/DartnessPipeline.html | 45 +- .../DartnessPipeline/addErrorHandler.html | 45 +- .../server/DartnessPipeline/addHandler.html | 45 +- .../DartnessPipeline/addInterceptor.html | 45 +- .../DartnessPipeline/addMiddleware.html | 45 +- .../server/DartnessRequest-class-sidebar.html | 30 + .../doc/api/server/DartnessRequest-class.html | 70 +- .../DartnessRequest.fromShelf.html | 48 +- .../DartnessRequest/DartnessRequest.html | 64 +- .../doc/api/server/DartnessRequest/body.html | 48 +- .../doc/api/server/DartnessRequest/bytes.html | 48 +- .../api/server/DartnessRequest/headers.html | 48 +- .../api/server/DartnessRequest/method.html | 48 +- .../server/DartnessRequest/requestedUri.html | 48 +- .../doc/api/server/DartnessRequest/url.html | 48 +- .../DartnessResponse-class-sidebar.html | 28 + .../api/server/DartnessResponse-class.html | 68 +- .../DartnessResponse.fromShelf.html | 46 +- .../DartnessResponse/DartnessResponse.html | 60 +- .../doc/api/server/DartnessResponse/body.html | 46 +- .../api/server/DartnessResponse/bytes.html | 46 +- .../api/server/DartnessResponse/headers.html | 46 +- .../server/DartnessResponse/statusCode.html | 46 +- .../server/DartnessServer-class-sidebar.html | 31 + .../doc/api/server/DartnessServer-class.html | 71 +- .../server/DartnessServer/DartnessServer.html | 49 +- .../server/DartnessServer/addController.html | 49 +- .../DartnessServer/addErrorHandler.html | 49 +- .../server/DartnessServer/addInterceptor.html | 49 +- .../server/DartnessServer/addMiddleware.html | 49 +- .../api/server/DartnessServer/getAddress.html | 49 +- .../api/server/DartnessServer/getPort.html | 49 +- .../doc/api/server/DartnessServer/start.html | 49 +- .../doc/api/server/DartnessServer/stop.html | 49 +- ...DefaultDartnessPipeline-class-sidebar.html | 27 + .../server/DefaultDartnessPipeline-class.html | 67 +- .../DefaultDartnessPipeline.html | 52 +- .../addErrorHandler.html | 45 +- .../DefaultDartnessPipeline/addHandler.html | 45 +- .../addInterceptor.html | 45 +- .../addMiddleware.html | 45 +- .../DefaultDartnessServer-class-sidebar.html | 33 + .../server/DefaultDartnessServer-class.html | 73 +- .../DefaultDartnessServer.html | 56 +- .../DefaultDartnessServer/addController.html | 51 +- .../addErrorHandler.html | 51 +- .../DefaultDartnessServer/addInterceptor.html | 51 +- .../DefaultDartnessServer/addMiddleware.html | 51 +- .../DefaultDartnessServer/controllers.html | 51 +- .../DefaultDartnessServer/getAddress.html | 51 +- .../server/DefaultDartnessServer/getPort.html | 51 +- .../DefaultDartnessServer/isStarted.html | 51 +- .../server/DefaultDartnessServer/start.html | 51 +- .../server/DefaultDartnessServer/stop.html | 51 +- .../LogRequestsInterceptor-class-sidebar.html | 30 + .../server/LogRequestsInterceptor-class.html | 70 +- .../LogRequestsInterceptor.html | 48 +- .../server/LogRequestsInterceptor/method.html | 48 +- .../LogRequestsInterceptor/onError.html | 48 +- .../LogRequestsInterceptor/onRequest.html | 48 +- .../LogRequestsInterceptor/onResponse.html | 48 +- .../LogRequestsInterceptor/startTime.html | 48 +- .../server/LogRequestsInterceptor/uri.html | 48 +- .../server/LogRequestsInterceptor/watch.html | 48 +- .../api/server/server-library-sidebar.html | 21 + .../doc/api/server/server-library.html | 45 +- .../doc/api/static-assets/highlight.pack.js | 1347 +++++++++-------- 267 files changed, 9400 insertions(+), 8725 deletions(-) create mode 100644 packages/dartness_generator/doc/api/builder/application.html create mode 100644 packages/dartness_generator/doc/api/builder/builder-library-sidebar.html create mode 100644 packages/dartness_generator/doc/api/builder/builder-library.html create mode 100644 packages/dartness_generator/doc/api/builder/controller.html create mode 100644 packages/dartness_generator/doc/api/builder/errorHandler.html create mode 100644 packages/dartness_generator/doc/api/dartness_generator/dartness_generator-library-sidebar.html create mode 100644 packages/dartness_server/doc/api/dartness/Application-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/dartness/Application-class.html create mode 100644 packages/dartness_server/doc/api/dartness/Application/Application.html create mode 100644 packages/dartness_server/doc/api/dartness/Application/module.html create mode 100644 packages/dartness_server/doc/api/dartness/Application/options.html create mode 100644 packages/dartness_server/doc/api/dartness/Dartness-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/dartness/InstanceRegister-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/dartness/InstanceRegister-class.html create mode 100644 packages/dartness_server/doc/api/dartness/InstanceRegister/instance.html create mode 100644 packages/dartness_server/doc/api/dartness/InstanceRegister/register.html create mode 100644 packages/dartness_server/doc/api/dartness/InstanceRegister/resolve.html create mode 100644 packages/dartness_server/doc/api/dartness/dartness-library-sidebar.html create mode 100644 packages/dartness_server/doc/api/exception/CatchError-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/exception/DartnessCatchError-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/exception/DartnessCatchErrorRegister-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/exception/DartnessErrorHandler-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/exception/ErrorHandler-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/exception/HttpStatusException-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/exception/exception-library-sidebar.html create mode 100644 packages/dartness_server/doc/api/modules/Module-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/modules/Module-class.html create mode 100644 packages/dartness_server/doc/api/modules/Module/Module.html create mode 100644 packages/dartness_server/doc/api/modules/Module/metadata.html create mode 100644 packages/dartness_server/doc/api/modules/ModuleMetadata-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/modules/ModuleMetadata-class.html create mode 100644 packages/dartness_server/doc/api/modules/ModuleMetadata/ModuleMetadata.html create mode 100644 packages/dartness_server/doc/api/modules/ModuleMetadata/controllers.html create mode 100644 packages/dartness_server/doc/api/modules/ModuleMetadata/exports.html create mode 100644 packages/dartness_server/doc/api/modules/ModuleMetadata/imports.html create mode 100644 packages/dartness_server/doc/api/modules/ModuleMetadata/providers.html create mode 100644 packages/dartness_server/doc/api/modules/ProviderMetadata-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/modules/ProviderMetadata-class.html create mode 100644 packages/dartness_server/doc/api/modules/ProviderMetadata/ProviderMetadata.html create mode 100644 packages/dartness_server/doc/api/modules/ProviderMetadata/classType.html create mode 100644 packages/dartness_server/doc/api/modules/modules-library-sidebar.html create mode 100644 packages/dartness_server/doc/api/modules/modules-library.html create mode 100644 packages/dartness_server/doc/api/route/Bind-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/Body-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/Connect-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/Controller-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/ControllerRoute-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/DartnessController-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/DartnessParam-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/DartnessRouter-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/DartnessRouterHandler-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/DefaultDartnessRouter-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/Delete-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/Get-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/Head-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/Header-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/Headers-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/HttpCode-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/Options-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/Patch-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/PathParam-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/Post-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/Put-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/QueryParam-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/Trace-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/route/route-library-sidebar.html create mode 100644 packages/dartness_server/doc/api/server/DartnessApplicationOptions-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/server/DartnessApplicationOptions-class.html create mode 100644 packages/dartness_server/doc/api/server/DartnessApplicationOptions/DartnessApplicationOptions.html create mode 100644 packages/dartness_server/doc/api/server/DartnessApplicationOptions/internetAddress.html create mode 100644 packages/dartness_server/doc/api/server/DartnessApplicationOptions/logRequest.html create mode 100644 packages/dartness_server/doc/api/server/DartnessApplicationOptions/port.html create mode 100644 packages/dartness_server/doc/api/server/DartnessInterceptor-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/server/DartnessMiddleware-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/server/DartnessPipeline-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/server/DartnessRequest-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/server/DartnessResponse-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/server/DartnessServer-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/server/DefaultDartnessPipeline-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/server/DefaultDartnessServer-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/server/LogRequestsInterceptor-class-sidebar.html create mode 100644 packages/dartness_server/doc/api/server/server-library-sidebar.html diff --git a/packages/dartness_generator/doc/api/__404error.html b/packages/dartness_generator/doc/api/__404error.html index 2dae4d3a..cc5f1874 100644 --- a/packages/dartness_generator/doc/api/__404error.html +++ b/packages/dartness_generator/doc/api/__404error.html @@ -4,7 +4,7 @@ - + dartness_generator - Dart API docs @@ -65,20 +65,22 @@

404: Something's gone wrong :-(