Skip to content

Commit

Permalink
Merge pull request #70 from francescovallone/develop
Browse files Browse the repository at this point in the history
chore: update spanner version
  • Loading branch information
francescovallone authored Aug 25, 2024
2 parents b072539 + b4afe23 commit bb7f86c
Show file tree
Hide file tree
Showing 19 changed files with 513 additions and 25 deletions.
4 changes: 4 additions & 0 deletions packages/serinus/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.6.2

- chore: update spanner to 1.0.3

## 0.6.1

- fix: fix exported providers
Expand Down
6 changes: 1 addition & 5 deletions packages/serinus/bin/serinus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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}';
},
Expand Down
2 changes: 1 addition & 1 deletion packages/serinus/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.6.0"
version: "0.6.1"
shelf:
dependency: transitive
description:
Expand Down
11 changes: 10 additions & 1 deletion packages/serinus/lib/src/adapters/http_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<TServer> extends Adapter<TServer> {
/// The [host] property contains the host of the server.
final String host;
Expand Down
16 changes: 7 additions & 9 deletions packages/serinus/lib/src/containers/module_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,35 +63,33 @@ final class ModulesContainer {
Future<void> 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},
);
_moduleInjectables[token] =
moduleInjectables?.concatTo(newInjectables) ?? newInjectables;
}
_providers[token] = [];
final split = initializedModule.providers.splitBy<DeferredProvider>();
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');
Expand Down
9 changes: 8 additions & 1 deletion packages/serinus/lib/src/extensions/iterable_extansions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ extension AddIfAbsent<T> on Iterable<T> {

/// This method is used to add a list of elements to the list if they are not already present
Iterable<T> addAllIfAbsent(Iterable<T> 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;
}
}

Expand Down
8 changes: 4 additions & 4 deletions packages/serinus/lib/src/handlers/handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ abstract class Handler {
RequestContext buildRequestContext(Iterable<Provider> providers,
Request request, InternalResponse response) {
return RequestContext(
providers.fold<Map<Type, Provider>>({}, (acc, provider) {
acc[provider.runtimeType] = provider;
return acc;
}),
{
for (final provider in providers)
provider.runtimeType: provider
},
request,
StreamableResponse(response),
);
Expand Down
4 changes: 3 additions & 1 deletion packages/serinus/lib/src/handlers/request_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion packages/serinus/lib/src/http/internal_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions packages/serinus/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions packages/serinus_frontier/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/
3 changes: 3 additions & 0 deletions packages/serinus_frontier/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0

- Initial version.
2 changes: 2 additions & 0 deletions packages/serinus_frontier/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A sample command-line application with an entrypoint in `bin/`, library code
in `lib/`, and example unit test in `test/`.
30 changes: 30 additions & 0 deletions packages/serinus_frontier/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions packages/serinus_frontier/bin/serinus_frontier.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:serinus_frontier/serinus_frontier.dart' as serinus_frontier;

void main(List<String> arguments) {
print('Hello world: ${serinus_frontier.calculate()}!');
}
3 changes: 3 additions & 0 deletions packages/serinus_frontier/lib/serinus_frontier.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int calculate() {
return 6 * 7;
}
Loading

0 comments on commit bb7f86c

Please sign in to comment.