Merge pull request #94 from dukefirehawk/bug-fix/container

Bug fix/container
This commit is contained in:
Thomas Hii 2023-01-28 10:56:52 +08:00 committed by GitHub
commit 9b85007072
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 877 additions and 4726 deletions

View file

@ -1,5 +1,9 @@
# Change Log # Change Log
## 7.1.0
* Require Dart >= 2.18
## 7.0.0 ## 7.0.0
* Require Dart >= 2.17 * Require Dart >= 2.17

View file

@ -97,7 +97,7 @@ class Container {
/// In contexts where a static generic type cannot be used, use /// In contexts where a static generic type cannot be used, use
/// the [type] argument, instead of [T]. /// the [type] argument, instead of [T].
T make<T>([Type? type]) { T make<T>([Type? type]) {
var t2 = T; Type t2 = T;
if (type != null) { if (type != null) {
t2 = type; t2 = type;
} }
@ -118,7 +118,7 @@ class Container {
var reflectedType = reflector.reflectType(t2); var reflectedType = reflector.reflectType(t2);
var positional = []; var positional = [];
var named = <String, dynamic>{}; var named = <String, Object>{};
if (reflectedType is ReflectedClass) { if (reflectedType is ReflectedClass) {
bool isDefault(String name) { bool isDefault(String name) {

View file

@ -1,10 +1,10 @@
name: angel3_container name: angel3_container
version: 7.0.0 version: 7.1.0
description: Angel3 hierarchical DI container, and pluggable backends for reflection. description: Angel3 hierarchical DI container, and pluggable backends for reflection.
homepage: https://angel3-framework.web.app/ homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/container/angel_container repository: https://github.com/dukefirehawk/angel/tree/master/packages/container/angel_container
environment: environment:
sdk: '>=2.17.0 <3.0.0' sdk: '>=2.18.0 <3.0.0'
dependencies: dependencies:
collection: ^1.15.0 collection: ^1.15.0
quiver: ^3.0.1 quiver: ^3.0.1

View file

@ -0,0 +1,299 @@
// This file has been generated by the reflectable package.
// https://github.com/dart-lang/reflectable.
import 'dart:core';
import 'package:angel3_container_generator/angel3_container_generator.dart'
as prefix0;
import 'package:reflectable/capability.dart' as prefix1;
import 'package:reflectable/mirrors.dart' as prefix2;
// ignore_for_file: camel_case_types
// ignore_for_file: implementation_imports
// ignore_for_file: prefer_adjacent_string_concatenation
// ignore_for_file: prefer_collection_literals
// ignore_for_file: unnecessary_const
// ignore:unused_import
import 'package:reflectable/mirrors.dart' as m;
// ignore:unused_import
import 'package:reflectable/src/reflectable_builder_based.dart' as r;
// ignore:unused_import
import 'package:reflectable/reflectable.dart' as r show Reflectable;
final _data = <r.Reflectable, r.ReflectorData>{
const prefix0.ContainedReflectable(): r.ReflectorData(
<m.TypeMirror>[
r.NonGenericClassMirrorImpl(
r'ContainedReflectable',
r'.ContainedReflectable',
134217735,
0,
const prefix0.ContainedReflectable(),
const <int>[0],
const <int>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
const <int>[],
-1,
{},
{},
{r'': (bool b) => () => b ? prefix0.ContainedReflectable() : null},
0,
0,
const <int>[],
const <Object>[prefix0.contained],
null)
],
<m.DeclarationMirror>[
r.MethodMirrorImpl(r'', 128, 0, -1, 0, 0, const <int>[], const <int>[],
const prefix0.ContainedReflectable(), const []),
r.MethodMirrorImpl(r'==', 2097154, -1, -1, 1, 1, const <int>[],
const <int>[0], const prefix0.ContainedReflectable(), const []),
r.MethodMirrorImpl(r'toString', 2097154, -1, -1, 2, 2, const <int>[],
const <int>[], const prefix0.ContainedReflectable(), const []),
r.MethodMirrorImpl(
r'noSuchMethod',
524290,
-1,
-1,
-1,
-1,
const <int>[],
const <int>[1],
const prefix0.ContainedReflectable(),
const []),
r.MethodMirrorImpl(r'hashCode', 2097155, -1, -1, 3, 3, const <int>[],
const <int>[], const prefix0.ContainedReflectable(), const []),
r.MethodMirrorImpl(r'runtimeType', 2097155, -1, -1, 4, 4, const <int>[],
const <int>[], const prefix0.ContainedReflectable(), const []),
r.MethodMirrorImpl(
r'capabilities',
35651587,
-1,
-1,
6,
7,
const <int>[5],
const <int>[],
const prefix0.ContainedReflectable(),
const []),
r.MethodMirrorImpl(
r'canReflect',
2097154,
-1,
-1,
1,
1,
const <int>[],
const <int>[2],
const prefix0.ContainedReflectable(),
const <Object>[override]),
r.MethodMirrorImpl(
r'reflect',
2097154,
-1,
-1,
8,
8,
const <int>[],
const <int>[3],
const prefix0.ContainedReflectable(),
const <Object>[override]),
r.MethodMirrorImpl(
r'canReflectType',
2097154,
-1,
-1,
1,
1,
const <int>[],
const <int>[4],
const prefix0.ContainedReflectable(),
const <Object>[override]),
r.MethodMirrorImpl(
r'reflectType',
2097154,
-1,
-1,
9,
9,
const <int>[],
const <int>[5],
const prefix0.ContainedReflectable(),
const <Object>[override]),
r.MethodMirrorImpl(
r'findLibrary',
2097154,
-1,
-1,
10,
10,
const <int>[],
const <int>[6],
const prefix0.ContainedReflectable(),
const <Object>[override]),
r.MethodMirrorImpl(
r'libraries',
35651587,
-1,
-1,
12,
13,
const <int>[11, 10],
const <int>[],
const prefix0.ContainedReflectable(),
const <Object>[override]),
r.MethodMirrorImpl(
r'annotatedClasses',
35651587,
-1,
-1,
15,
16,
const <int>[14],
const <int>[],
const prefix0.ContainedReflectable(),
const <Object>[override])
],
<m.ParameterMirror>[
r.ParameterMirrorImpl(
r'other',
134348806,
1,
const prefix0.ContainedReflectable(),
-1,
17,
17,
const <int>[],
const [],
null,
null),
r.ParameterMirrorImpl(
r'invocation',
134348806,
3,
const prefix0.ContainedReflectable(),
-1,
18,
18,
const <int>[],
const [],
null,
null),
r.ParameterMirrorImpl(
r'reflectee',
134348806,
7,
const prefix0.ContainedReflectable(),
-1,
17,
17,
const <int>[],
const [],
null,
null),
r.ParameterMirrorImpl(
r'reflectee',
134348806,
8,
const prefix0.ContainedReflectable(),
-1,
17,
17,
const <int>[],
const [],
null,
null),
r.ParameterMirrorImpl(
r'type',
134348806,
9,
const prefix0.ContainedReflectable(),
-1,
4,
4,
const <int>[],
const [],
null,
null),
r.ParameterMirrorImpl(
r'type',
134348806,
10,
const prefix0.ContainedReflectable(),
-1,
4,
4,
const <int>[],
const [],
null,
null),
r.ParameterMirrorImpl(
r'libraryName',
134348806,
11,
const prefix0.ContainedReflectable(),
-1,
2,
2,
const <int>[],
const [],
null,
null)
],
<Type>[
prefix0.ContainedReflectable,
bool,
String,
int,
Type,
prefix1.ReflectCapability,
const m.TypeValue<List<prefix1.ReflectCapability>>().type,
List,
prefix2.InstanceMirror,
prefix2.TypeMirror,
prefix2.LibraryMirror,
Uri,
const m.TypeValue<Map<Uri, prefix2.LibraryMirror>>().type,
Map,
prefix2.ClassMirror,
const m.TypeValue<Iterable<prefix2.ClassMirror>>().type,
Iterable,
Object,
Invocation
],
1,
{
r'==': (dynamic instance) => (x) => instance == x,
r'toString': (dynamic instance) => instance.toString,
r'noSuchMethod': (dynamic instance) => instance.noSuchMethod,
r'hashCode': (dynamic instance) => instance.hashCode,
r'runtimeType': (dynamic instance) => instance.runtimeType,
r'capabilities': (dynamic instance) => instance.capabilities,
r'canReflect': (dynamic instance) => instance.canReflect,
r'reflect': (dynamic instance) => instance.reflect,
r'canReflectType': (dynamic instance) => instance.canReflectType,
r'reflectType': (dynamic instance) => instance.reflectType,
r'findLibrary': (dynamic instance) => instance.findLibrary,
r'libraries': (dynamic instance) => instance.libraries,
r'annotatedClasses': (dynamic instance) => instance.annotatedClasses
},
{},
<m.LibraryMirror>[
r.LibraryMirrorImpl(
r'',
Uri.parse(r'reflectable://0/'),
const prefix0.ContainedReflectable(),
const <int>[],
{},
{},
const [],
null)
],
[])
};
final _memberSymbolMap = null;
void initializeReflectable() {
r.data = _data;
r.memberSymbolMap = _memberSymbolMap;
}

View file

@ -8,15 +8,15 @@ const Reflectable contained = ContainedReflectable();
class ContainedReflectable extends Reflectable { class ContainedReflectable extends Reflectable {
const ContainedReflectable() const ContainedReflectable()
: super( : super(
declarationsCapability, topLevelInvokeCapability,
instanceInvokeCapability, typeAnnotationQuantifyCapability,
invokingCapability, superclassQuantifyCapability,
metadataCapability, instanceInvokeCapability,
newInstanceCapability, libraryCapability,
reflectedTypeCapability, invokingCapability,
typeRelationsCapability, newInstanceCapability,
typingCapability, reflectedTypeCapability,
); typingCapability);
} }
/// A [Reflector] instance that uses a [Reflectable] to reflect upon data. /// A [Reflector] instance that uses a [Reflectable] to reflect upon data.

View file

@ -13,6 +13,6 @@ dev_dependencies:
build_test: ^2.1.3 build_test: ^2.1.3
test: ^1.21.0 test: ^1.21.0
lints: ^2.0.0 lints: ^2.0.0
# dependency_overrides: dependency_overrides:
# angel3_container: angel3_container:
# path: ../angel_container path: ../angel_container

View file

@ -1,15 +1,12 @@
import 'package:angel3_container/angel3_container.dart'; import 'package:angel3_container/angel3_container.dart';
import 'package:angel3_container_generator/angel3_container_generator.dart'; import 'package:angel3_container_generator/angel3_container_generator.dart';
@GlobalQuantifyCapability(
r'^dart\.core\.(Iterable|List|String|int|Object)', contained)
import 'package:reflectable/reflectable.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import 'reflector_test.reflectable.dart'; import 'reflector_test.reflectable.dart';
void main() { void main() {
initializeReflectable(); initializeReflectable();
var reflector = const GeneratedReflector(); var reflector = const GeneratedReflector();
late Container container; late Container container;
@ -52,7 +49,7 @@ void testReflector(Reflector reflector) {
expect(blazikenMirror.getField('type').reflectee, blaziken.type); expect(blazikenMirror.getField('type').reflectee, blaziken.type);
}); });
/* /*
group('reflectFunction', () { group('reflectFunction', () {
var mirror = reflector.reflectFunction(returnVoidFromAFunction); var mirror = reflector.reflectFunction(returnVoidFromAFunction);
@ -76,8 +73,8 @@ void testReflector(Reflector reflector) {
expect(p?.annotations, isEmpty); expect(p?.annotations, isEmpty);
expect(p?.type, reflector.reflectType(int)); expect(p?.type, reflector.reflectType(int));
}); });
}, skip: 'pkg:reflectable cannot reflect on closures at all (yet)'); }, skip: 'pkg:reflectable cannot reflect on closures at all (yet)');
*/ */
test('make on singleton type returns singleton', () { test('make on singleton type returns singleton', () {
expect(container.make(Pokemon), blaziken); expect(container.make(Pokemon), blaziken);
@ -112,10 +109,11 @@ void testReflector(Reflector reflector) {
var kantoPokemonType = container.reflector.reflectType(KantoPokemon)!; var kantoPokemonType = container.reflector.reflectType(KantoPokemon)!;
expect(kantoPokemonType.isAssignableTo(pokemonType), true); expect(kantoPokemonType.isAssignableTo(pokemonType), true);
expect( expect(
kantoPokemonType () => kantoPokemonType
.isAssignableTo(container.reflector.reflectType(String)), .isAssignableTo(container.reflector.reflectType(String)),
false); throwsUnsupportedError);
}); });
} }
@ -153,12 +151,12 @@ enum PokemonType { water, fire, grass, ice, poison, flying }
@contained @contained
class Artist { class Artist {
final String? name; final String name;
Artist({this.name}); Artist({required this.name});
String get lowerName { String get lowerName {
return name!.toLowerCase(); return name.toLowerCase();
} }
} }
@ -178,5 +176,5 @@ class AlbumLength {
AlbumLength(this.artist, this.album); AlbumLength(this.artist, this.album);
int get totalLength => artist.name!.length + album.title.length; int get totalLength => artist.name.length + album.title.length;
} }

View file

@ -1,5 +1,9 @@
# Change Log # Change Log
## 7.1.1
* Added `exclusive` parameter to `createSync`
## 7.1.0 ## 7.1.0
* Upgraded to `analyzer` 5.x.x * Upgraded to `analyzer` 5.x.x

View file

@ -158,7 +158,8 @@ class BuildSystemFile extends File {
throw _unsupported(); throw _unsupported();
@override @override
void createSync({bool recursive = false}) => throw _unsupported(); void createSync({bool exclusive = false, bool recursive = false}) =>
throw _unsupported();
@override @override
Future<FileSystemEntity> delete({bool recursive = false}) => Future<FileSystemEntity> delete({bool recursive = false}) =>

View file

@ -1,5 +1,5 @@
name: jael3_web name: jael3_web
version: 7.1.0 version: 7.1.1
description: Experimental virtual DOM/SPA engine built on Jael3. Supports SSR. description: Experimental virtual DOM/SPA engine built on Jael3. Supports SSR.
publish_to: none publish_to: none
environment: environment:

View file

@ -1,5 +1,11 @@
# Change Log # Change Log
## 7.1.0
* Return -1 instead of throwing exception when id is null
* Added `idAsString` to return id or "" if null
* Added `AuditableModel`
## 7.0.0 ## 7.0.0
* Require Dart >= 2.17 * Require Dart >= 2.17

View file

@ -1,14 +1,19 @@
# Angel3 Basic Data Model # Angel3 Data Model
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_model?include_prereleases) ![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_model?include_prereleases)
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety) [![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion) [![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/model/LICENSE) [![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/master/packages/model/LICENSE)
Angel3 basic data model class, no longer with the added weight of the whole framework. The basic data models for Angel3 framework.
```dart ```dart
import 'package:angel3_model/angel3_model.dart'; import 'package:angel3_model/angel3_model.dart';
``` ```
This package was created to prevent dependency collisions with third-party packages. The available data models are:
* `Model` class
* A basic data model
* `AuditableModel` class
* A basic data model with audit log feature

View file

@ -1,6 +1,4 @@
//library angel3_model; /// Represents a generic data model with an ID and timestamps.
/// Represents arbitrary data, with an associated ID and timestamps.
class Model { class Model {
/// A unique identifier corresponding to this item. /// A unique identifier corresponding to this item.
String? id; String? id;
@ -14,5 +12,24 @@ class Model {
Model({this.id, this.createdAt, this.updatedAt}); Model({this.id, this.createdAt, this.updatedAt});
/// Returns the [id], parsed as an [int]. /// Returns the [id], parsed as an [int].
int get idAsInt => id != null ? int.tryParse(id!) ?? -1 : -1; int get idAsInt => id != null ? int.tryParse(id ?? "-1") ?? -1 : -1;
/// Returns the [id] or "" if null.
String get idAsString => id ?? "";
}
/// Represents a generic data model with audit log feature.
class AuditableModel extends Model {
/// The authorized user who created the record.
String? createdBy;
/// The user who updated the record last time.
String? updatedBy;
AuditableModel(
{super.id,
super.createdAt,
this.createdBy,
super.updatedAt,
this.updatedBy});
} }

View file

@ -1,5 +1,5 @@
name: angel3_model name: angel3_model
version: 7.0.0 version: 7.1.0
description: Angel3 basic data model class, no longer with the added weight of the whole framework. description: Angel3 basic data model class, no longer with the added weight of the whole framework.
homepage: https://angel3-framework.web.app/ homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/model repository: https://github.com/dukefirehawk/angel/tree/master/packages/model

View file

@ -19,7 +19,7 @@ dev_dependencies:
angel3_framework: ^7.0.0 angel3_framework: ^7.0.0
build_runner: ^2.0.1 build_runner: ^2.0.1
lints: ^2.0.0 lints: ^2.0.0
dependency_overrides: # dependency_overrides:
# angel3_container: # angel3_container:
# path: ../../container/angel_container # path: ../../container/angel_container
# angel3_framework: # angel3_framework:
@ -40,5 +40,5 @@ dependency_overrides:
# path: ../angel_orm # path: ../angel_orm
# angel3_migration: # angel3_migration:
# path: ../angel_migration # path: ../angel_migration
angel3_orm_generator: # angel3_orm_generator:
path: ../angel_orm_generator # path: ../angel_orm_generator