Updated container generator
This commit is contained in:
parent
0d4c3e0f85
commit
7652c02183
25 changed files with 85 additions and 111 deletions
|
@ -34,7 +34,7 @@ class AuthToken {
|
|||
String? ipAddress;
|
||||
late DateTime issuedAt;
|
||||
num lifeSpan;
|
||||
var userId;
|
||||
dynamic userId;
|
||||
Map<String, dynamic> payload = {};
|
||||
|
||||
AuthToken(
|
||||
|
|
|
@ -235,7 +235,7 @@ class AngelAuth<User> {
|
|||
}
|
||||
}
|
||||
|
||||
var user = await deserializer(token.userId as Object);
|
||||
var user = await deserializer(token.userId);
|
||||
_apply(req, res, token, user);
|
||||
return _AuthResult(user, token);
|
||||
}
|
||||
|
@ -332,7 +332,7 @@ class AngelAuth<User> {
|
|||
_addProtectedCookie(res, 'token', token.serialize(_hs256));
|
||||
}
|
||||
|
||||
final data = await deserializer(token.userId as Object);
|
||||
final data = await deserializer(token.userId);
|
||||
return {'data': data, 'token': token.serialize(_hs256)};
|
||||
}
|
||||
} catch (e) {
|
||||
|
@ -458,7 +458,7 @@ class AngelAuth<User> {
|
|||
|
||||
/// Log a user in on-demand.
|
||||
Future login(AuthToken token, RequestContext req, ResponseContext res) async {
|
||||
var user = await deserializer(token.userId as Object);
|
||||
var user = await deserializer(token.userId);
|
||||
_apply(req, res, token, user);
|
||||
_onLogin.add(user);
|
||||
|
||||
|
@ -468,7 +468,8 @@ class AngelAuth<User> {
|
|||
}
|
||||
|
||||
/// Log a user in on-demand.
|
||||
Future loginById(userId, RequestContext req, ResponseContext res) async {
|
||||
Future loginById(
|
||||
dynamic userId, RequestContext req, ResponseContext res) async {
|
||||
var user = await deserializer(userId as Object);
|
||||
var token =
|
||||
AuthToken(userId: userId, lifeSpan: _jwtLifeSpan, ipAddress: req.ip);
|
||||
|
|
|
@ -22,4 +22,4 @@ dev_dependencies:
|
|||
lints: ^1.0.0
|
||||
#dependency_overrides:
|
||||
# angel3_container:
|
||||
# path: ../container/angel_container
|
||||
# path: ../container/angel_container
|
||||
|
|
|
@ -15,17 +15,16 @@ dependencies:
|
|||
logging: ^1.0.0
|
||||
dev_dependencies:
|
||||
angel3_framework: ^4.2.0
|
||||
angel3_model: ^3.0.0
|
||||
angel3_model: ^3.1.0
|
||||
angel3_mock_request: ^2.0.0
|
||||
angel3_container: ^3.0.0
|
||||
angel3_auth: ^4.0.0
|
||||
angel3_container: ^3.1.0
|
||||
angel3_auth: ^4.1.0
|
||||
async: ^2.6.1
|
||||
build_runner: ^1.12.2
|
||||
build_web_compilers: ^2.16.5
|
||||
test: ^1.17.5
|
||||
lints: ^1.0.0
|
||||
#dependency_overrides:
|
||||
# angel3_framework:
|
||||
# path: ../framework
|
||||
# angel3_route:
|
||||
# path: ../route
|
||||
# angel3_container:
|
||||
# path: ../container/angel_container
|
||||
|
|
@ -1,5 +1,9 @@
|
|||
# Change Log
|
||||
|
||||
## 3.1.1
|
||||
|
||||
* Updated `_ReflectedMethodMirror` to have optional `returnType` parameter
|
||||
|
||||
## 3.1.0
|
||||
|
||||
* Updated linter to `package:lints`
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
|
||||
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/master/packages/container/angel_container/LICENSE)
|
||||
|
||||
A better IoC container for Angel3, ultimately allowing Angel3 to be used without `dart:mirrors` package.
|
||||
An better IoC container for Angel3, ultimately allowing Angel3 to be used without `dart:mirrors` package.
|
||||
|
||||
```dart
|
||||
import 'package:angel3_container/angel3_container.dart';
|
||||
|
|
|
@ -15,7 +15,7 @@ class EmptyReflector extends Reflector {
|
|||
@override
|
||||
String? getName(Symbol symbol) {
|
||||
return _symbolNames.putIfAbsent(
|
||||
symbol, () => symbolRegex.firstMatch(symbol.toString())!.group(1));
|
||||
symbol, () => symbolRegex.firstMatch(symbol.toString())?.group(1));
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -75,7 +75,8 @@ class _EmptyReflectedType extends ReflectedType {
|
|||
@override
|
||||
ReflectedInstance newInstance(
|
||||
String constructorName, List positionalArguments,
|
||||
[Map<String, dynamic>? namedArguments, List<Type>? typeArguments]) {
|
||||
[Map<String, dynamic> namedArguments = const {},
|
||||
List<Type> typeArguments = const []]) {
|
||||
throw UnsupportedError(
|
||||
'Types reflected via an EmptyReflector cannot be instantiated.');
|
||||
}
|
||||
|
@ -113,10 +114,10 @@ class _EmptyReflectedFunction extends ReflectedFunction {
|
|||
'(empty)',
|
||||
const <ReflectedTypeParameter>[],
|
||||
const <ReflectedInstance>[],
|
||||
const _EmptyReflectedType(),
|
||||
const <ReflectedParameter>[],
|
||||
false,
|
||||
false);
|
||||
false,
|
||||
returnType: const _EmptyReflectedType());
|
||||
|
||||
@override
|
||||
ReflectedInstance invoke(Invocation invocation) {
|
||||
|
|
|
@ -179,11 +179,9 @@ class _ReflectedClassMirror extends ReflectedClass {
|
|||
}
|
||||
|
||||
class _ReflectedDeclarationMirror extends ReflectedDeclaration {
|
||||
@override
|
||||
final String name;
|
||||
final dart.MethodMirror mirror;
|
||||
|
||||
_ReflectedDeclarationMirror(this.name, this.mirror)
|
||||
_ReflectedDeclarationMirror(String name, this.mirror)
|
||||
: super(name, mirror.isStatic, null);
|
||||
|
||||
@override
|
||||
|
@ -217,13 +215,13 @@ class _ReflectedMethodMirror extends ReflectedFunction {
|
|||
mirror.metadata
|
||||
.map((mirror) => _ReflectedInstanceMirror(mirror))
|
||||
.toList(),
|
||||
!mirror.returnType.hasReflectedType
|
||||
? const MirrorsReflector().reflectType(dynamic)
|
||||
: const MirrorsReflector()
|
||||
.reflectType(mirror.returnType.reflectedType),
|
||||
mirror.parameters.map(_reflectParameter).toList(),
|
||||
mirror.isGetter,
|
||||
mirror.isSetter);
|
||||
mirror.isSetter,
|
||||
returnType: !mirror.returnType.hasReflectedType
|
||||
? const MirrorsReflector().reflectType(dynamic)
|
||||
: const MirrorsReflector()
|
||||
.reflectType(mirror.returnType.reflectedType));
|
||||
|
||||
static ReflectedParameter _reflectParameter(dart.ParameterMirror mirror) {
|
||||
return ReflectedParameter(
|
||||
|
|
|
@ -56,7 +56,8 @@ abstract class ReflectedType {
|
|||
|
||||
ReflectedInstance newInstance(
|
||||
String constructorName, List positionalArguments,
|
||||
[Map<String, dynamic>? namedArguments, List<Type>? typeArguments]);
|
||||
[Map<String, dynamic> namedArguments = const {},
|
||||
List<Type> typeArguments = const []]);
|
||||
|
||||
bool isAssignableTo(ReflectedType? other);
|
||||
}
|
||||
|
@ -113,12 +114,13 @@ abstract class ReflectedFunction {
|
|||
final String name;
|
||||
final List<ReflectedTypeParameter> typeParameters;
|
||||
final List<ReflectedInstance> annotations;
|
||||
final ReflectedType returnType;
|
||||
final ReflectedType? returnType;
|
||||
final List<ReflectedParameter> parameters;
|
||||
final bool isGetter, isSetter;
|
||||
|
||||
const ReflectedFunction(this.name, this.typeParameters, this.annotations,
|
||||
this.returnType, this.parameters, this.isGetter, this.isSetter);
|
||||
this.parameters, this.isGetter, this.isSetter,
|
||||
{this.returnType});
|
||||
|
||||
@override
|
||||
int get hashCode => hashObjects([
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: angel3_container
|
||||
version: 3.1.0
|
||||
version: 3.1.1
|
||||
description: A hierarchical DI container, and pluggable backends for reflection.
|
||||
homepage: https://angel3-framework.web.app/
|
||||
repository: https://github.com/dukefirehawk/angel/tree/master/packages/container/angel_container
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
# Change Log
|
||||
|
||||
## 3.0.0
|
||||
|
||||
* Fixed NNBD issues
|
||||
* All 9 test cases passed
|
||||
|
||||
## 3.0.0-beta.1
|
||||
|
||||
* Migrated to support Dart SDK 2.12.x NNBD
|
||||
|
|
|
@ -5,4 +5,4 @@
|
|||
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
|
||||
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/master/packages/container/angel3_container_generator/LICENSE)
|
||||
|
||||
A better IoC container for Angel3, ultimately allowing Angel3 to be used without `dart:mirrors`.
|
||||
A better IoC container generator for Angel3, ultimately allowing Angel3 to be used without `dart:mirrors`.
|
||||
|
|
|
@ -15,7 +15,7 @@ class ContainedReflectable extends Reflectable {
|
|||
newInstanceCapability,
|
||||
reflectedTypeCapability,
|
||||
typeRelationsCapability,
|
||||
typeCapability,
|
||||
typingCapability,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,8 @@ class _GeneratedReflectedType extends ReflectedType {
|
|||
@override
|
||||
ReflectedInstance newInstance(
|
||||
String constructorName, List positionalArguments,
|
||||
[Map<String, dynamic>? namedArguments, List<Type>? typeArguments]) {
|
||||
[Map<String, dynamic> namedArguments = const {},
|
||||
List<Type> typeArguments = const []]) {
|
||||
throw UnsupportedError('Cannot create a new instance of $reflectedType.');
|
||||
}
|
||||
}
|
||||
|
@ -178,17 +179,14 @@ class _GeneratedReflectedFunction extends ReflectedFunction {
|
|||
mirror.simpleName,
|
||||
[],
|
||||
[],
|
||||
/*
|
||||
!mirror.isRegularMethod
|
||||
? null
|
||||
: _GeneratedReflectedType(mirror.returnType),
|
||||
*/
|
||||
_GeneratedReflectedType(mirror.returnType),
|
||||
mirror.parameters
|
||||
.map((p) => _convertParameter(p, reflector))
|
||||
.toList(),
|
||||
mirror.isGetter,
|
||||
mirror.isSetter);
|
||||
mirror.isSetter,
|
||||
returnType: !mirror.isRegularMethod
|
||||
? null
|
||||
: _GeneratedReflectedType(mirror.returnType));
|
||||
|
||||
@override
|
||||
List<ReflectedInstance> get annotations => mirror.metadata
|
||||
|
@ -247,8 +245,10 @@ ReflectedParameter _convertParameter(
|
|||
ParameterMirror mirror, Reflector reflector) {
|
||||
return ReflectedParameter(
|
||||
mirror.simpleName,
|
||||
mirror.metadata.map(reflector.reflectInstance).toList()
|
||||
as List<ReflectedInstance>,
|
||||
mirror.metadata
|
||||
.map(reflector.reflectInstance)
|
||||
.whereType<ReflectedInstance>()
|
||||
.toList(),
|
||||
reflector.reflectType(mirror.type.reflectedType)!,
|
||||
!mirror.isOptional,
|
||||
mirror.isNamed);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: angel3_container_generator
|
||||
version: 3.0.0-beta.1
|
||||
version: 3.0.0
|
||||
description: Codegen support for using pkg:reflectable with pkg:angel3_container.
|
||||
homepage: https://angel3-framework.web.app/
|
||||
repository: https://github.com/dukefirehawk/angel/tree/master/packages/container/angel_container_generator
|
||||
|
@ -13,6 +13,6 @@ dev_dependencies:
|
|||
build_test: ^2.1.3
|
||||
test: ^1.17.5
|
||||
lints: ^1.0.1
|
||||
#dependency_overrides:
|
||||
# angel3_container:
|
||||
# path: ../angel_container
|
||||
dependency_overrides:
|
||||
angel3_container:
|
||||
path: ../angel_container
|
|
@ -57,24 +57,24 @@ void testReflector(Reflector reflector) {
|
|||
var mirror = reflector.reflectFunction(returnVoidFromAFunction);
|
||||
|
||||
test('void return type returns dynamic', () {
|
||||
expect(mirror.returnType, reflector.reflectType(dynamic));
|
||||
expect(mirror?.returnType, reflector.reflectType(dynamic));
|
||||
});
|
||||
|
||||
test('counts parameters', () {
|
||||
expect(mirror.parameters, hasLength(1));
|
||||
expect(mirror?.parameters, hasLength(1));
|
||||
});
|
||||
|
||||
test('counts types parameters', () {
|
||||
expect(mirror.typeParameters, isEmpty);
|
||||
expect(mirror?.typeParameters, isEmpty);
|
||||
});
|
||||
|
||||
test('correctly reflects parameter types', () {
|
||||
var p = mirror.parameters[0];
|
||||
expect(p.name, 'x');
|
||||
expect(p.isRequired, true);
|
||||
expect(p.isNamed, false);
|
||||
expect(p.annotations, isEmpty);
|
||||
expect(p.type, reflector.reflectType(int));
|
||||
var p = mirror?.parameters[0];
|
||||
expect(p?.name, 'x');
|
||||
expect(p?.isRequired, true);
|
||||
expect(p?.isNamed, false);
|
||||
expect(p?.annotations, isEmpty);
|
||||
expect(p?.type, reflector.reflectType(int));
|
||||
});
|
||||
}, skip: 'pkg:reflectable cannot reflect on closures at all (yet)');
|
||||
*/
|
||||
|
|
|
@ -35,6 +35,6 @@ dev_dependencies:
|
|||
io: ^1.0.0
|
||||
test: ^1.17.5
|
||||
lints: ^1.0.0
|
||||
dependency_overrides:
|
||||
angel3_route:
|
||||
path: ../route
|
||||
#dependency_overrides:
|
||||
# angel3_container:
|
||||
# path: ../container/angel_container
|
||||
|
|
|
@ -6,11 +6,14 @@ repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/productio
|
|||
environment:
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
dependencies:
|
||||
angel3_container: ^3.0.0
|
||||
angel3_container: ^3.1.0
|
||||
angel3_framework: ^4.1.0
|
||||
belatuk_pub_sub: ^4.0.0
|
||||
args: ^2.1.0
|
||||
io: ^1.0.0
|
||||
logging: ^1.0.1
|
||||
dev_dependencies:
|
||||
lints: ^1.0.1
|
||||
lints: ^1.0.1
|
||||
#dependency_overrides:
|
||||
# angel3_container:
|
||||
# path: ../container/angel_container
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/shelf.iml" filepath="$PROJECT_DIR$/.idea/shelf.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -1,6 +0,0 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="All Tests (coverage)" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" singleton="true">
|
||||
<option name="filePath" value="$PROJECT_DIR$/test/all.dart" />
|
||||
<method />
|
||||
</configuration>
|
||||
</component>
|
|
@ -1,8 +0,0 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="tests in shelf" type="DartTestRunConfigurationType" factoryName="Dart Test" singleton="true" nameIsGenerated="true">
|
||||
<option name="filePath" value="$PROJECT_DIR$" />
|
||||
<option name="scope" value="FOLDER" />
|
||||
<option name="testRunnerOptions" value="-j 4" />
|
||||
<method />
|
||||
</configuration>
|
||||
</component>
|
|
@ -1,16 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.pub" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Dart SDK" level="project" />
|
||||
<orderEntry type="library" name="Dart Packages" level="project" />
|
||||
</component>
|
||||
</module>
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -7,7 +7,7 @@ environment:
|
|||
sdk: '>=2.12.0 <3.0.0'
|
||||
dependencies:
|
||||
angel3_framework: ^4.2.0
|
||||
angel3_container: ^3.0.0
|
||||
angel3_container: ^3.1.0
|
||||
angel3_mock_request: ^2.0.0
|
||||
path: ^1.8.0
|
||||
shelf: ^1.1.4
|
||||
|
@ -21,3 +21,6 @@ dev_dependencies:
|
|||
shelf_static: ^1.0.0
|
||||
test: ^1.17.5
|
||||
lints: ^1.0.0
|
||||
#dependency_overrides:
|
||||
# angel3_container:
|
||||
# path: ../container/angel_container
|
||||
|
|
|
@ -12,11 +12,14 @@ dependencies:
|
|||
angel3_validate: ^4.0.0
|
||||
angel3_websocket: ^4.1.0
|
||||
angel3_mock_request: ^2.0.0
|
||||
angel3_container: ^3.0.0
|
||||
angel3_container: ^3.1.0
|
||||
http: ^0.13.1
|
||||
matcher: ^0.12.10
|
||||
web_socket_channel: ^2.0.0
|
||||
dev_dependencies:
|
||||
test: ^1.17.5
|
||||
lints: ^1.0.0
|
||||
#dependency_overrides:
|
||||
# angel3_container:
|
||||
# path: ../container/angel_container
|
||||
|
||||
|
|
|
@ -18,12 +18,11 @@ dependencies:
|
|||
collection: ^1.15.0
|
||||
logging: ^1.0.1
|
||||
dev_dependencies:
|
||||
angel3_container: ^3.0.0
|
||||
angel3_model: ^3.0.0
|
||||
angel3_container: ^3.1.0
|
||||
angel3_model: ^3.1.0
|
||||
test: ^1.17.5
|
||||
lints: ^1.0.0
|
||||
#dependency_overrides:
|
||||
# angel3_framework:
|
||||
# path: ../framework
|
||||
|
||||
# angel3_container:
|
||||
# path: ../container/angel_container
|
||||
|
Loading…
Reference in a new issue