diff --git a/packages/serinus/CHANGELOG.md b/packages/serinus/CHANGELOG.md index ad20cd73..dc421553 100644 --- a/packages/serinus/CHANGELOG.md +++ b/packages/serinus/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.6.2 + +- chore: update spanner to 1.0.3 + ## 0.6.1 - fix: fix exported providers diff --git a/packages/serinus/bin/serinus.dart b/packages/serinus/bin/serinus.dart index ebf0ec37..f8e10840 100644 --- a/packages/serinus/bin/serinus.dart +++ b/packages/serinus/bin/serinus.dart @@ -119,11 +119,7 @@ class HomeController extends Controller { HomeController({super.path = '/'}) { on(GetRoute(path: '/'), (context) async { return 'Hello world'; - }, - schema: AcanthisParseSchema( - query: object({ - 'test': string().encode(), - }).optionals(['test']))); + },); on(PostRoute(path: '/*'), (context) async { return '${context.request.getData('test')} ${context.params}'; }, diff --git a/packages/serinus/example/pubspec.lock b/packages/serinus/example/pubspec.lock index 92c6c7e6..662a8702 100644 --- a/packages/serinus/example/pubspec.lock +++ b/packages/serinus/example/pubspec.lock @@ -119,7 +119,7 @@ packages: path: ".." relative: true source: path - version: "0.6.0" + version: "0.6.1" shelf: dependency: transitive description: diff --git a/packages/serinus/lib/src/adapters/http_adapter.dart b/packages/serinus/lib/src/adapters/http_adapter.dart index 07cd18c7..0d1da83d 100644 --- a/packages/serinus/lib/src/adapters/http_adapter.dart +++ b/packages/serinus/lib/src/adapters/http_adapter.dart @@ -3,7 +3,16 @@ import '../core/core.dart'; import '../http/internal_request.dart'; import 'server_adapter.dart'; -/// The [RequestCallback] type is used to define the request callback. +/// The [HttpAdapter] class is used to create an HTTP server adapter. +/// +/// It extends the [Adapter] class and allows the developer to define the host, port, and powered by header. +/// +/// The class must be extended and the [init], [close], and [listen] methods must be implemented. +/// +/// Properties: +/// - [host]: The host of the server. +/// - [port]: The port of the server. +/// - [poweredByHeader]: The powered by header. abstract class HttpAdapter extends Adapter { /// The [host] property contains the host of the server. final String host; diff --git a/packages/serinus/lib/src/containers/module_container.dart b/packages/serinus/lib/src/containers/module_container.dart index 9d06fa41..b4b71731 100644 --- a/packages/serinus/lib/src/containers/module_container.dart +++ b/packages/serinus/lib/src/containers/module_container.dart @@ -63,15 +63,14 @@ final class ModulesContainer { Future registerModule(Module module, Type entrypoint, [ModuleInjectables? moduleInjectables]) async { final token = moduleToken(module); - final initializedModule = await module.registerAsync(config); + final initializedModule = _modules[token] = await module.registerAsync(config); if (initializedModule.runtimeType == entrypoint && initializedModule.exports.isNotEmpty) { throw InitializationError('The entrypoint module cannot have exports'); } - _modules[token] = initializedModule; - if (_moduleInjectables[token] != null) { - _moduleInjectables[token] = - moduleInjectables!.concatTo(_moduleInjectables[token]); + _providers[token] = []; + if (_moduleInjectables.containsKey(token)) { + _moduleInjectables[token] = moduleInjectables!.concatTo(_moduleInjectables[token]); } else { final newInjectables = ModuleInjectables( middlewares: {...module.middlewares}, @@ -79,19 +78,18 @@ final class ModulesContainer { _moduleInjectables[token] = moduleInjectables?.concatTo(newInjectables) ?? newInjectables; } - _providers[token] = []; final split = initializedModule.providers.splitBy(); for (final provider in split.notOfType) { await initIfUnregistered(provider); - _moduleInjectables[token] = _moduleInjectables[token]!.copyWith( - providers: {..._moduleInjectables[token]!.providers, provider}, - ); if (provider.isGlobal) { globalProviders.add(provider); } else { _providers[token]?.add(provider); } } + _moduleInjectables[token] = _moduleInjectables[token]!.copyWith( + providers: {..._moduleInjectables[token]!.providers, ...split.notOfType}, + ); _deferredProviders[token] = split.ofType; logger.info( '${initializedModule.runtimeType}${initializedModule.token.isNotEmpty ? '(${initializedModule.token})' : ''} dependencies initialized'); diff --git a/packages/serinus/lib/src/extensions/iterable_extansions.dart b/packages/serinus/lib/src/extensions/iterable_extansions.dart index 985c35b5..9535d47e 100644 --- a/packages/serinus/lib/src/extensions/iterable_extansions.dart +++ b/packages/serinus/lib/src/extensions/iterable_extansions.dart @@ -17,7 +17,14 @@ extension AddIfAbsent on Iterable { /// This method is used to add a list of elements to the list if they are not already present Iterable addAllIfAbsent(Iterable elements) { - return elements.fold(this, (acc, element) => acc.addIfAbsent(element)); + final elementsType = map((e) => e.runtimeType); + final currentElements = [...this]; + for(final element in elements) { + if (!elementsType.contains(element.runtimeType)) { + currentElements.add(element); + } + } + return currentElements; } } diff --git a/packages/serinus/lib/src/handlers/handler.dart b/packages/serinus/lib/src/handlers/handler.dart index 64befd5c..fda3e5c4 100644 --- a/packages/serinus/lib/src/handlers/handler.dart +++ b/packages/serinus/lib/src/handlers/handler.dart @@ -52,10 +52,10 @@ abstract class Handler { RequestContext buildRequestContext(Iterable providers, Request request, InternalResponse response) { return RequestContext( - providers.fold>({}, (acc, provider) { - acc[provider.runtimeType] = provider; - return acc; - }), + { + for (final provider in providers) + provider.runtimeType: provider + }, request, StreamableResponse(response), ); diff --git a/packages/serinus/lib/src/handlers/request_handler.dart b/packages/serinus/lib/src/handlers/request_handler.dart index ef216908..7a0c2d1c 100644 --- a/packages/serinus/lib/src/handlers/request_handler.dart +++ b/packages/serinus/lib/src/handlers/request_handler.dart @@ -50,7 +50,9 @@ class RequestHandler extends Handler { : request.path, request.method.toHttpMethod()); final routeData = routeLookup.route; - wrappedRequest.params = routeLookup.params; + if(routeLookup.params.isNotEmpty) { + wrappedRequest.params = routeLookup.params; + } if (routeData == null) { throw NotFoundException( message: diff --git a/packages/serinus/lib/src/http/internal_request.dart b/packages/serinus/lib/src/http/internal_request.dart index c81b6ca9..a9f91eb0 100644 --- a/packages/serinus/lib/src/http/internal_request.dart +++ b/packages/serinus/lib/src/http/internal_request.dart @@ -98,7 +98,7 @@ class InternalRequest { InternalRequest({ required this.headers, required this.original, - }) : id = '${original.hashCode}-${DateTime.timestamp().toIso8601String()}'; + }) : id = '${original.hashCode}-${DateTime.timestamp()}'; /// The [response] getter is used to get the response of the request InternalResponse get response { diff --git a/packages/serinus/pubspec.yaml b/packages/serinus/pubspec.yaml index 0e09713c..a0a4d621 100644 --- a/packages/serinus/pubspec.yaml +++ b/packages/serinus/pubspec.yaml @@ -4,7 +4,7 @@ description: Serinus is a framework written in Dart documentation: https://docs.serinus.app homepage: https://docs.serinus.app repository: https://github.com/francescovallone/serinus -version: 0.6.1 +version: 0.6.2 funding: - https://www.patreon.com/francescovallone - https://github.com/sponsors/francescovallone @@ -25,7 +25,7 @@ dependencies: logging: ^1.1.0 meta: ^1.9.1 mime: ^1.0.4 - spanner: ^1.0.2 + spanner: ^1.0.3 stream_channel: ^2.1.1 uuid: ^4.3.1 web_socket_channel: ^3.0.0 diff --git a/packages/serinus_frontier/.gitignore b/packages/serinus_frontier/.gitignore new file mode 100644 index 00000000..3a857904 --- /dev/null +++ b/packages/serinus_frontier/.gitignore @@ -0,0 +1,3 @@ +# https://dart.dev/guides/libraries/private-files +# Created by `dart pub` +.dart_tool/ diff --git a/packages/serinus_frontier/CHANGELOG.md b/packages/serinus_frontier/CHANGELOG.md new file mode 100644 index 00000000..effe43c8 --- /dev/null +++ b/packages/serinus_frontier/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial version. diff --git a/packages/serinus_frontier/README.md b/packages/serinus_frontier/README.md new file mode 100644 index 00000000..3816eca3 --- /dev/null +++ b/packages/serinus_frontier/README.md @@ -0,0 +1,2 @@ +A sample command-line application with an entrypoint in `bin/`, library code +in `lib/`, and example unit test in `test/`. diff --git a/packages/serinus_frontier/analysis_options.yaml b/packages/serinus_frontier/analysis_options.yaml new file mode 100644 index 00000000..dee8927a --- /dev/null +++ b/packages/serinus_frontier/analysis_options.yaml @@ -0,0 +1,30 @@ +# This file configures the static analysis results for your project (errors, +# warnings, and lints). +# +# This enables the 'recommended' set of lints from `package:lints`. +# This set helps identify many issues that may lead to problems when running +# or consuming Dart code, and enforces writing Dart using a single, idiomatic +# style and format. +# +# If you want a smaller set of lints you can change this to specify +# 'package:lints/core.yaml'. These are just the most critical lints +# (the recommended set includes the core lints). +# The core lints are also what is used by pub.dev for scoring packages. + +include: package:lints/recommended.yaml + +# Uncomment the following section to specify additional rules. + +# linter: +# rules: +# - camel_case_types + +# analyzer: +# exclude: +# - path/to/excluded/files/** + +# For more information about the core and recommended set of lints, see +# https://dart.dev/go/core-lints + +# For additional information about configuring this file, see +# https://dart.dev/guides/language/analysis-options diff --git a/packages/serinus_frontier/bin/serinus_frontier.dart b/packages/serinus_frontier/bin/serinus_frontier.dart new file mode 100644 index 00000000..8a98203d --- /dev/null +++ b/packages/serinus_frontier/bin/serinus_frontier.dart @@ -0,0 +1,5 @@ +import 'package:serinus_frontier/serinus_frontier.dart' as serinus_frontier; + +void main(List arguments) { + print('Hello world: ${serinus_frontier.calculate()}!'); +} diff --git a/packages/serinus_frontier/lib/serinus_frontier.dart b/packages/serinus_frontier/lib/serinus_frontier.dart new file mode 100644 index 00000000..f64ad726 --- /dev/null +++ b/packages/serinus_frontier/lib/serinus_frontier.dart @@ -0,0 +1,3 @@ +int calculate() { + return 6 * 7; +} diff --git a/packages/serinus_frontier/pubspec.lock b/packages/serinus_frontier/pubspec.lock new file mode 100644 index 00000000..a7588a87 --- /dev/null +++ b/packages/serinus_frontier/pubspec.lock @@ -0,0 +1,402 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + sha256: "5aaf60d96c4cd00fe7f21594b5ad6a1b699c80a27420f8a837f4d68473ef09e3" + url: "https://pub.dev" + source: hosted + version: "68.0.0" + _macros: + dependency: transitive + description: dart + source: sdk + version: "0.1.0" + analyzer: + dependency: transitive + description: + name: analyzer + sha256: "21f1d3720fd1c70316399d5e2bccaebb415c434592d778cce8acb967b8578808" + url: "https://pub.dev" + source: hosted + version: "6.5.0" + args: + dependency: transitive + description: + name: args + sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a" + url: "https://pub.dev" + source: hosted + version: "2.5.0" + async: + dependency: transitive + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + collection: + dependency: transitive + description: + name: collection + sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf + url: "https://pub.dev" + source: hosted + version: "1.19.0" + convert: + dependency: transitive + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" + source: hosted + version: "3.1.1" + coverage: + dependency: transitive + description: + name: coverage + sha256: "576aaab8b1abdd452e0f656c3e73da9ead9d7880e15bdc494189d9c1a1baf0db" + url: "https://pub.dev" + source: hosted + version: "1.9.0" + crypto: + dependency: transitive + description: + name: crypto + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + url: "https://pub.dev" + source: hosted + version: "3.0.3" + file: + dependency: transitive + description: + name: file + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + url: "https://pub.dev" + source: hosted + version: "7.0.0" + frontend_server_client: + dependency: transitive + description: + name: frontend_server_client + sha256: f64a0333a82f30b0cca061bc3d143813a486dc086b574bfb233b7c1372427694 + url: "https://pub.dev" + source: hosted + version: "4.0.0" + glob: + dependency: transitive + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" + url: "https://pub.dev" + source: hosted + version: "3.2.1" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "40f592dd352890c3b60fec1b68e786cefb9603e05ff303dbc4dda49b304ecdf4" + url: "https://pub.dev" + source: hosted + version: "4.1.0" + io: + dependency: transitive + description: + name: io + sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + js: + dependency: transitive + description: + name: js + sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf + url: "https://pub.dev" + source: hosted + version: "0.7.1" + lints: + dependency: "direct dev" + description: + name: lints + sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 + url: "https://pub.dev" + source: hosted + version: "3.0.0" + logging: + dependency: transitive + description: + name: logging + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + macros: + dependency: transitive + description: + name: macros + sha256: "12e8a9842b5a7390de7a781ec63d793527582398d16ea26c60fed58833c9ae79" + url: "https://pub.dev" + source: hosted + version: "0.1.0-main.0" + matcher: + dependency: transitive + description: + name: matcher + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + meta: + dependency: transitive + description: + name: meta + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 + url: "https://pub.dev" + source: hosted + version: "1.15.0" + mime: + dependency: transitive + description: + name: mime + sha256: "2e123074287cc9fd6c09de8336dae606d1ddb88d9ac47358826db698c176a1f2" + url: "https://pub.dev" + source: hosted + version: "1.0.5" + node_preamble: + dependency: transitive + description: + name: node_preamble + sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" + url: "https://pub.dev" + source: hosted + version: "2.0.2" + package_config: + dependency: transitive + description: + name: package_config + sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + path: + dependency: transitive + description: + name: path + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" + source: hosted + version: "1.9.0" + pool: + dependency: transitive + description: + name: pool + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" + source: hosted + version: "1.5.1" + pub_semver: + dependency: transitive + description: + name: pub_semver + sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + shelf: + dependency: transitive + description: + name: shelf + sha256: e7dd780a7ffb623c57850b33f43309312fc863fb6aa3d276a754bb299839ef12 + url: "https://pub.dev" + source: hosted + version: "1.4.2" + shelf_packages_handler: + dependency: transitive + description: + name: shelf_packages_handler + sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" + url: "https://pub.dev" + source: hosted + version: "3.0.2" + shelf_static: + dependency: transitive + description: + name: shelf_static + sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e + url: "https://pub.dev" + source: hosted + version: "1.1.2" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + sha256: "073c147238594ecd0d193f3456a5fe91c4b0abbcc68bf5cd95b36c4e194ac611" + url: "https://pub.dev" + source: hosted + version: "2.0.0" + source_map_stack_trace: + dependency: transitive + description: + name: source_map_stack_trace + sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + source_maps: + dependency: transitive + description: + name: source_maps + sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703" + url: "https://pub.dev" + source: hosted + version: "0.10.12" + source_span: + dependency: transitive + description: + name: source_span + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" + source: hosted + version: "1.10.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" + source: hosted + version: "1.11.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" + source: hosted + version: "2.1.2" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3" + url: "https://pub.dev" + source: hosted + version: "1.3.0" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test: + dependency: "direct dev" + description: + name: test + sha256: "713a8789d62f3233c46b4a90b174737b2c04cb6ae4500f2aa8b1be8f03f5e67f" + url: "https://pub.dev" + source: hosted + version: "1.25.8" + test_api: + dependency: transitive + description: + name: test_api + sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c" + url: "https://pub.dev" + source: hosted + version: "0.7.3" + test_core: + dependency: transitive + description: + name: test_core + sha256: "12391302411737c176b0b5d6491f466b0dd56d4763e347b6714efbaa74d7953d" + url: "https://pub.dev" + source: hosted + version: "0.6.5" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc + url: "https://pub.dev" + source: hosted + version: "14.2.4" + watcher: + dependency: transitive + description: + name: watcher + sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" + url: "https://pub.dev" + source: hosted + version: "1.1.0" + web: + dependency: transitive + description: + name: web + sha256: d43c1d6b787bf0afad444700ae7f4db8827f701bc61c255ac8d328c6f4d52062 + url: "https://pub.dev" + source: hosted + version: "1.0.0" + web_socket: + dependency: transitive + description: + name: web_socket + sha256: "3c12d96c0c9a4eec095246debcea7b86c0324f22df69893d538fcc6f1b8cce83" + url: "https://pub.dev" + source: hosted + version: "0.1.6" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + sha256: "9f187088ed104edd8662ca07af4b124465893caf063ba29758f97af57e61da8f" + url: "https://pub.dev" + source: hosted + version: "3.0.1" + webkit_inspection_protocol: + dependency: transitive + description: + name: webkit_inspection_protocol + sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572" + url: "https://pub.dev" + source: hosted + version: "1.2.1" + yaml: + dependency: transitive + description: + name: yaml + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" + url: "https://pub.dev" + source: hosted + version: "3.1.2" +sdks: + dart: ">=3.4.3 <4.0.0" diff --git a/packages/serinus_frontier/pubspec.yaml b/packages/serinus_frontier/pubspec.yaml new file mode 100644 index 00000000..97596bc3 --- /dev/null +++ b/packages/serinus_frontier/pubspec.yaml @@ -0,0 +1,16 @@ +name: serinus_frontier +description: A sample command-line application. +version: 1.0.0 +# repository: https://github.com/my_org/my_repo + +environment: + sdk: ^3.4.3 + +# Add regular dependencies here. +dependencies: + serinus: ^0.6.0 + frontier: ^0.0.1 + +dev_dependencies: + lints: ^3.0.0 + test: ^1.24.0 diff --git a/packages/serinus_frontier/test/serinus_frontier_test.dart b/packages/serinus_frontier/test/serinus_frontier_test.dart new file mode 100644 index 00000000..128a24e0 --- /dev/null +++ b/packages/serinus_frontier/test/serinus_frontier_test.dart @@ -0,0 +1,8 @@ +import 'package:serinus_frontier/serinus_frontier.dart'; +import 'package:test/test.dart'; + +void main() { + test('calculate', () { + expect(calculate(), 42); + }); +}