Merge pull request #7 from dukefirehawk/angel3

Updated auth, model, container and container generator
This commit is contained in:
Thomas Hii 2021-09-26 14:58:11 +08:00 committed by GitHub
commit 4a632451dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 487 additions and 320 deletions

View file

@ -1,5 +1,9 @@
# Change Log
## 4.1.0
* Updated linter to `package:lints`
## 4.0.5
* Added support for verifier function to return an empty Map instead of null

View file

@ -1,21 +1,29 @@
MIT License (MIT)
BSD 3-Clause License
Copyright (c) 2021 dukefirehawk.com
Copyright (c) 2021, dukefirehawk.com
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View file

@ -1,10 +1,9 @@
# Angel3 Anthentication
[![version](https://img.shields.io/badge/pub-v4.0.5-brightgreen)](https://pub.dev/packages/angel3_auth)
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_auth?include_prereleases)
[![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)
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/auth/LICENSE)
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/master/packages/auth/LICENSE)
A complete authentication plugin for Angel3. Inspired by Passport. More details in the [User Guide](https://angel3-docs.dukefirehawk.com/guides/authentication).
@ -52,7 +51,7 @@ configureServer(Angel app) async {
## Default Authentication Callback
A frequent use case within SPA's is opening OAuth login endpoints in a separate window. [`angel3_client`](https://github.com/dukefirehawk/angel/tree/angel3/packages/client) provides a facility for this, which works perfectly with the default callback provided in this package.
A frequent use case within SPA's is opening OAuth login endpoints in a separate window. [`angel3_client`](https://pub.dev/packages/angel3_client) provides a facility for this, which works perfectly with the default callback provided in this package.
```dart
configureServer(Angel app) async {
@ -75,7 +74,7 @@ configureServer(Angel app) async {
}
```
This renders a simple HTML page that fires the user's JWT as a `token` event in `window.opener`. `angel3_client` [exposes this as a Stream](https://github.com/dukefirehawk/angel/tree/angel3/packages/client#authentication):
This renders a simple HTML page that fires the user's JWT as a `token` event in `window.opener`. `angel3_client` [exposes this as a Stream](https://pub.dev/documentation/angel3_client/latest/):
```dart
app.authenticateViaPopup('/auth/google').listen((jwt) {

View file

@ -1,4 +1,2 @@
include: package:pedantic/analysis_options.yaml
analyzer:
strong-mode:
implicit-casts: false
include: package:lints/recommended.yaml

View file

@ -1,12 +1,12 @@
name: angel3_auth
description: A complete authentication plugin for Angel. Includes support for stateless JWT tokens, Basic Auth, and more.
version: 4.0.5
description: A complete authentication plugin for Angel3. Includes support for stateless JWT tokens, Basic Auth, and more.
version: 4.1.0
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/auth
repository: https://github.com/dukefirehawk/angel/tree/master/packages/auth
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
angel3_framework: ^4.0.0
angel3_framework: ^4.2.0
charcode: ^1.2.0
collection: ^1.15.0
crypto: ^3.0.0
@ -15,9 +15,11 @@ dependencies:
quiver: ^3.0.0
logging: ^1.0.0
dev_dependencies:
angel3_container: ^3.0.0
angel3_container: ^3.1.0
http: ^0.13.1
io: ^1.0.0
pedantic: ^1.11.0
test: ^1.17.4
lints: ^1.0.0
dependency_overrides:
angel3_container:
path: ../container/angel_container

View file

@ -19,7 +19,7 @@ typedef AngelDeserializer<T> = T? Function(dynamic x);
/// Represents an Angel server that we are querying.
abstract class Angel extends http.BaseClient {
final _log = Logger('Angel');
//final _log = Logger('Angel');
/// A mutable member. When this is set, it holds a JSON Web Token
/// that is automatically attached to every request sent.

View file

@ -1,16 +1,27 @@
# 3.0.2
# Change Log
## 3.1.0
* Updated linter to `package:lints`
## 3.0.2
* Resolved static analysis warnings
# 3.0.1
## 3.0.1
* Updated README
# 3.0.0
## 3.0.0
* Migrated to support Dart SDK 2.12.x NNBD
# 2.0.0
## 2.0.0
* Migrated to work with Dart SDK 2.12.x Non NNBD
# 1.1.0
## 1.1.0
* `pedantic` lints.
* Add `ThrowingReflector`, which throws on all operations.
* `EmptyReflector` uses `Object` instead of `dynamic` as its returned
@ -18,60 +29,77 @@ type, as the `dynamic` type is (apparently?) no longer a valid constant value.
* `registerSingleton` now returns the provided `object`.
* `registerFactory` and `registerLazySingleton` now return the provided function `f`.
# 1.0.4
## 1.0.4
* Slight patch to prevent annoying segfault.
# 1.0.3
## 1.0.3
* Added `Future` support to `Reflector`.
# 1.0.2
## 1.0.2
* Added `makeAsync<T>`.
# 1.0.1
## 1.0.1
* Added `hasNamed`.
# 1.0.0
## 1.0.0
* Removed `@GenerateReflector`.
# 1.0.0-alpha.12
## 1.0.0-alpha.12
* `StaticReflector` now defaults to empty arguments.
# 1.0.0-alpha.11
## 1.0.0-alpha.11
* Added `StaticReflector`.
# 1.0.0-alpha.10
## 1.0.0-alpha.10
* Added `Container.registerLazySingleton<T>`.
* Added named singleton support.
# 1.0.0-alpha.9
## 1.0.0-alpha.9
* Added `Container.has<T>`.
# 1.0.0-alpha.8
## 1.0.0-alpha.8
* Fixed a bug where `_ReflectedTypeInstance.isAssignableTo` always failed.
* Added `@GenerateReflector` annotation.
# 1.0.0-alpha.7
## 1.0.0-alpha.7
* Add `EmptyReflector`.
* `ReflectedType.newInstance` now returns a `ReflectedInstance`.
* Moved `ReflectedInstance.invoke` to `ReflectedFunction.invoke`.
# 1.0.0-alpha.6
## 1.0.0-alpha.6
* Add `getField` to `ReflectedInstance`.
# 1.0.0-alpha.5
## 1.0.0-alpha.5
* Remove concrete type from `ReflectedTypeParameter`.
# 1.0.0-alpha.4
## 1.0.0-alpha.4
* Safely handle `void` return types of methods.
# 1.0.0-alpha.3
## 1.0.0-alpha.3
* Reflecting `void` in `MirrorsReflector` now forwards to `dynamic`.
# 1.0.0-alpha.2
## 1.0.0-alpha.2
* Added `ReflectedInstance.reflectee`.
# 1.0.0-alpha.1
## 1.0.0-alpha.1
* Allow omission of the first argument of `Container.make`, to use
a generic type argument instead.
* `singleton` -> `registerSingleton`
* Add `createChild`, and support hierarchical containers.
* Add `createChild`, and support hierarchical containers.

View file

@ -1,21 +1,29 @@
MIT License (MIT)
BSD 3-Clause License
Copyright (c) 2021 dukefirehawk.com
Copyright (c) 2021, dukefirehawk.com
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View file

@ -1,12 +1,12 @@
# angel3_container
[![version](https://img.shields.io/badge/pub-v3.0.2-brightgreen)](https://pub.dartlang.org/packages/angel3_container)
# Angel3 Container
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_container?include_prereleases)
[![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)
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/master/packages/container/angel_container/LICENSE)
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/container/angel_container/LICENSE)
A better IoC container for Angel, ultimately allowing Angel to be used without dart:mirrors.
A better IoC container for Angel3, ultimately allowing Angel3 to be used without dart:mirrors.
```dart
import 'package:angel3_container/angel3_container.dart';
```
```

View file

@ -1,4 +1 @@
include: package:pedantic/analysis_options.yaml
analyzer:
strong-mode:
implicit-casts: false
include: package:lints/recommended.yaml

View file

@ -17,27 +17,27 @@ Future<void> main() async {
// Register a factory that creates a truck.
container.registerFactory<Truck>((container) {
return _TruckImpl(container.make<Engine>());
return _TruckImpl(container.make<Engine>()!);
});
// Use `make` to create an instance.
var truck = container.make<Truck>()!;
var truck = container.make<Truck>();
// You can also resolve injections asynchronously.
container.registerFactory<Future<int>>((_) async => 24);
print(await container.makeAsync<int>());
// Asynchronous resolution also works for plain objects.
await container.makeAsync<Truck>()!.then((t) => t.drive());
await container.makeAsync<Truck>()?.then((t) => t.drive());
// Register a named singleton.
container.registerNamedSingleton('the_truck', truck);
// Should print: 'Vroom! I have 40 horsepower in my engine.'
truck.drive();
truck?.drive();
// Should print the same.
container.findByName<Truck>('the_truck')!.drive();
container.findByName<Truck>('the_truck')?.drive();
// We can make a child container with its own factory.
var childContainer = container.createChild();
@ -47,10 +47,10 @@ Future<void> main() async {
});
// Make a truck with 5666 HP.
childContainer.make<Truck>()!.drive();
childContainer.make<Truck>()?.drive();
// However, calling `make<Engine>` will return the Engine singleton we created above.
print(childContainer.make<Engine>()!.horsePower);
print(childContainer.make<Engine>()?.horsePower);
}
abstract class Truck {
@ -64,12 +64,12 @@ class Engine {
}
class _TruckImpl implements Truck {
final Engine? engine;
final Engine engine;
_TruckImpl(this.engine);
@override
void drive() {
print('Vroom! I have ${engine!.horsePower} horsepower in my engine.');
print('Vroom! I have ${engine.horsePower} horsepower in my engine.');
}
}

View file

@ -1,12 +1,13 @@
name: angel3_container
version: 3.0.2
version: 3.1.0
description: A hierarchical DI container, and pluggable backends for reflection.
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/container/angel_container
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/container/angel_container
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
collection: ^1.15.0
quiver: ^3.0.1
dev_dependencies:
pedantic: ^1.11.0
test: ^1.17.4
test: ^1.17.5
lints: ^1.0.0

View file

@ -1,2 +1,15 @@
# 1.0.1
* Update for `pkg:angel_container@1.0.3`.
# Change Log
## 3.0.0-beta.1
* Migrated to support Dart SDK 2.12.x NNBD
* Updated linter to `package:lints`
* Updated to use `angel3_` packages
## 2.0.0
* Migrated to work with Dart SDK 2.12.x Non NNBD
## 1.0.1
* Update for `pkg:angel_container@1.0.3`.

View file

@ -1,21 +1,29 @@
MIT License (MIT)
BSD 3-Clause License
Copyright (c) 2021 dukefirehawk.com
Copyright (c) 2021, dukefirehawk.com
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View file

@ -1,2 +1,8 @@
# container
A better IoC container for Angel, ultimately allowing Angel to be used without dart:mirrors.
# Angel3 Container Generator
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_container_generator?include_prereleases)
[![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)
[![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`.

View file

@ -1,3 +1 @@
analyzer:
#strong-mode:
#implicit-casts: false
include: package:lints/recommended.yaml

View file

@ -0,0 +1,76 @@
import 'dart:async';
import 'package:angel3_container/angel3_container.dart';
import 'package:angel3_container_generator/angel3_container_generator.dart';
Future<void> main() async {
// Create a container instance.
var reflector = const GeneratedReflector();
Container container = Container(reflector);
// Register a singleton.
container.registerSingleton<Engine>(Engine(40));
// You can also omit the type annotation, in which the object's runtime type will be used.
// If you're injecting an abstract class, prefer the type annotation.
//
// container.registerSingleton(Engine(40));
// Register a factory that creates a truck.
container.registerFactory<Truck>((container) {
return _TruckImpl(container.make<Engine>()!);
});
// Use `make` to create an instance.
var truck = container.make<Truck>();
// You can also resolve injections asynchronously.
container.registerFactory<Future<int>>((_) async => 24);
print(await container.makeAsync<int>());
// Asynchronous resolution also works for plain objects.
await container.makeAsync<Truck>()?.then((t) => t.drive());
// Register a named singleton.
container.registerNamedSingleton('the_truck', truck);
// Should print: 'Vroom! I have 40 horsepower in my engine.'
truck?.drive();
// Should print the same.
container.findByName<Truck>('the_truck')?.drive();
// We can make a child container with its own factory.
var childContainer = container.createChild();
childContainer.registerFactory<Truck>((container) {
return _TruckImpl(Engine(5666));
});
// Make a truck with 5666 HP.
childContainer.make<Truck>()?.drive();
// However, calling `make<Engine>` will return the Engine singleton we created above.
print(childContainer.make<Engine>()?.horsePower);
}
abstract class Truck {
void drive();
}
class Engine {
final int horsePower;
Engine(this.horsePower);
}
class _TruckImpl implements Truck {
final Engine engine;
_TruckImpl(this.engine);
@override
void drive() {
print('Vroom! I have ${engine.horsePower} horsepower in my engine.');
}
}

View file

@ -1,8 +1,8 @@
import 'package:angel_container/angel_container.dart';
import 'package:angel3_container/angel3_container.dart';
import 'package:reflectable/reflectable.dart';
/// A [Reflectable] instance that can be used as an annotation on types to generate metadata for them.
const Reflectable contained = const ContainedReflectable();
const Reflectable contained = ContainedReflectable();
@contained
class ContainedReflectable extends Reflectable {
@ -38,37 +38,37 @@ class GeneratedReflector extends Reflector {
@override
ReflectedFunction reflectFunction(Function function) {
if (!reflectable.canReflect(function)) {
throw new UnsupportedError('Cannot reflect $function.');
throw UnsupportedError('Cannot reflect $function.');
}
var mirror = reflectable.reflect(function);
if (mirror is ClosureMirror) {
return new _GeneratedReflectedFunction(mirror.function, this, mirror);
return _GeneratedReflectedFunction(mirror.function, this, mirror);
} else {
throw new ArgumentError('$function is not a Function.');
throw ArgumentError('$function is not a Function.');
}
}
@override
ReflectedInstance reflectInstance(Object object) {
if (!reflectable.canReflect(object)) {
throw new UnsupportedError('Cannot reflect $object.');
throw UnsupportedError('Cannot reflect $object.');
} else {
var mirror = reflectable.reflect(object);
return new _GeneratedReflectedInstance(mirror, this);
return _GeneratedReflectedInstance(mirror, this);
}
}
@override
ReflectedType reflectType(Type type) {
if (!reflectable.canReflectType(type)) {
throw new UnsupportedError('Cannot reflect $type.');
throw UnsupportedError('Cannot reflect $type.');
} else {
var mirror = reflectable.reflectType(type);
return mirror is ClassMirror
? new _GeneratedReflectedClass(mirror, this)
: new _GeneratedReflectedType(mirror);
? _GeneratedReflectedClass(mirror, this)
: _GeneratedReflectedType(mirror);
}
}
}
@ -78,17 +78,17 @@ class _GeneratedReflectedInstance extends ReflectedInstance {
final GeneratedReflector reflector;
_GeneratedReflectedInstance(this.mirror, this.reflector)
: super(null, new _GeneratedReflectedClass(mirror.type, reflector),
mirror.reflectee);
: super(_GeneratedReflectedType(mirror.type),
_GeneratedReflectedClass(mirror.type, reflector), mirror.reflectee);
@override
ReflectedType get type => clazz;
@override
ReflectedInstance getField(String name) {
var result = mirror.invokeGetter(name);
var result = mirror.invokeGetter(name)!;
var instance = reflector.reflectable.reflect(result);
return new _GeneratedReflectedInstance(instance, reflector);
return _GeneratedReflectedInstance(instance, reflector);
}
}
@ -97,7 +97,7 @@ class _GeneratedReflectedClass extends ReflectedClass {
final Reflector reflector;
_GeneratedReflectedClass(this.mirror, this.reflector)
: super(mirror.simpleName, null, null, null, null, mirror.reflectedType);
: super(mirror.simpleName, [], [], [], [], mirror.reflectedType);
@override
List<ReflectedTypeParameter> get typeParameters =>
@ -112,11 +112,13 @@ class _GeneratedReflectedClass extends ReflectedClass {
_declarationsOf(mirror.declarations, reflector);
@override
List<ReflectedInstance> get annotations =>
mirror.metadata.map(reflector.reflectInstance).toList();
List<ReflectedInstance> get annotations => mirror.metadata
.map(reflector.reflectInstance)
.whereType<ReflectedInstance>()
.toList();
@override
bool isAssignableTo(ReflectedType other) {
bool isAssignableTo(ReflectedType? other) {
if (other is _GeneratedReflectedClass) {
return mirror.isAssignableTo(other.mirror);
} else if (other is _GeneratedReflectedType) {
@ -129,11 +131,11 @@ class _GeneratedReflectedClass extends ReflectedClass {
@override
ReflectedInstance newInstance(
String constructorName, List positionalArguments,
[Map<String, dynamic> namedArguments, List<Type> typeArguments]) {
[Map<String, dynamic>? namedArguments, List<Type>? typeArguments]) {
namedArguments ??= {};
var result = mirror.newInstance(constructorName, positionalArguments,
namedArguments.map((k, v) => new MapEntry(new Symbol(k), v)));
return reflector.reflectInstance(result);
namedArguments.map((k, v) => MapEntry(Symbol(k), v)));
return reflector.reflectInstance(result)!;
}
}
@ -141,14 +143,14 @@ class _GeneratedReflectedType extends ReflectedType {
final TypeMirror mirror;
_GeneratedReflectedType(this.mirror)
: super(mirror.simpleName, null, mirror.reflectedType);
: super(mirror.simpleName, [], mirror.reflectedType);
@override
List<ReflectedTypeParameter> get typeParameters =>
mirror.typeVariables.map(_convertTypeVariable).toList();
@override
bool isAssignableTo(ReflectedType other) {
bool isAssignableTo(ReflectedType? other) {
if (other is _GeneratedReflectedClass) {
return mirror.isAssignableTo(other.mirror);
} else if (other is _GeneratedReflectedType) {
@ -161,25 +163,27 @@ class _GeneratedReflectedType extends ReflectedType {
@override
ReflectedInstance newInstance(
String constructorName, List positionalArguments,
[Map<String, dynamic> namedArguments, List<Type> typeArguments]) {
throw new UnsupportedError(
'Cannot create a new instance of $reflectedType.');
[Map<String, dynamic>? namedArguments, List<Type>? typeArguments]) {
throw UnsupportedError('Cannot create a new instance of $reflectedType.');
}
}
class _GeneratedReflectedFunction extends ReflectedFunction {
final MethodMirror mirror;
final Reflector reflector;
final ClosureMirror closure;
final ClosureMirror? closure;
_GeneratedReflectedFunction(this.mirror, this.reflector, [this.closure])
: super(
mirror.simpleName,
[],
null,
[],
/*
!mirror.isRegularMethod
? null
: new _GeneratedReflectedType(mirror.returnType),
: _GeneratedReflectedType(mirror.returnType),
*/
_GeneratedReflectedType(mirror.returnType),
mirror.parameters
.map((p) => _convertParameter(p, reflector))
.toList(),
@ -187,16 +191,18 @@ class _GeneratedReflectedFunction extends ReflectedFunction {
mirror.isSetter);
@override
List<ReflectedInstance> get annotations =>
mirror.metadata.map(reflector.reflectInstance).toList();
List<ReflectedInstance> get annotations => mirror.metadata
.map(reflector.reflectInstance)
.whereType<ReflectedInstance>()
.toList();
@override
ReflectedInstance invoke(Invocation invocation) {
if (closure != null) {
throw new UnsupportedError('Only closures can be invoked directly.');
throw UnsupportedError('Only closures can be invoked directly.');
} else {
var result = closure.delegate(invocation);
return reflector.reflectInstance(result);
var result = closure!.delegate(invocation)!;
return reflector.reflectInstance(result)!;
}
}
}
@ -207,7 +213,7 @@ List<ReflectedFunction> _constructorsOf(
var v = entry.value;
if (v is MethodMirror && v.isConstructor) {
return out..add(new _GeneratedReflectedFunction(v, reflector));
return out..add(_GeneratedReflectedFunction(v, reflector));
} else {
return out;
}
@ -220,12 +226,12 @@ List<ReflectedDeclaration> _declarationsOf(
var v = entry.value;
if (v is VariableMirror) {
var decl = new ReflectedDeclaration(v.simpleName, v.isStatic, null);
var decl = ReflectedDeclaration(v.simpleName, v.isStatic, null);
return out..add(decl);
}
if (v is MethodMirror) {
var decl = new ReflectedDeclaration(v.simpleName, v.isStatic,
new _GeneratedReflectedFunction(v, reflector));
var decl = ReflectedDeclaration(
v.simpleName, v.isStatic, _GeneratedReflectedFunction(v, reflector));
return out..add(decl);
} else {
return out;
@ -234,15 +240,16 @@ List<ReflectedDeclaration> _declarationsOf(
}
ReflectedTypeParameter _convertTypeVariable(TypeVariableMirror mirror) {
return new ReflectedTypeParameter(mirror.simpleName);
return ReflectedTypeParameter(mirror.simpleName);
}
ReflectedParameter _convertParameter(
ParameterMirror mirror, Reflector reflector) {
return new ReflectedParameter(
return ReflectedParameter(
mirror.simpleName,
mirror.metadata.map(reflector.reflectInstance).toList(),
reflector.reflectType(mirror.type.reflectedType),
mirror.metadata.map(reflector.reflectInstance).toList()
as List<ReflectedInstance>,
reflector.reflectType(mirror.type.reflectedType)!,
!mirror.isOptional,
mirror.isNamed);
}

View file

@ -1,18 +1,19 @@
name: angel_container_generator
version: 2.0.0
description: Codegen support for using pkg:reflectable with pkg:angel_container.
homepage: https://github.com/angel-dart/container.git
name: angel3_container_generator
version: 3.0.0-beta.1
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
publish_to: none
environment:
sdk: ">=2.10.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'
dependencies:
angel_container:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x
path: packages/container/angel_container
reflectable: ^2.2.9
angel3_container: ^3.1.0
reflectable: ^3.0.4
dev_dependencies:
build_runner: ^1.11.1
build_test: ^1.3.6
test: ^1.16.5
build_runner: ^2.1.2
build_test: ^2.1.3
test: ^1.17.5
lints: ^1.0.1
dependency_overrides:
angel3_container:
path: ../angel_container

View file

@ -1,5 +1,5 @@
import 'package:angel_container/angel_container.dart';
import 'package:angel_container_generator/angel_container_generator.dart';
import 'package:angel3_container/angel3_container.dart';
import 'package:angel3_container_generator/angel3_container_generator.dart';
@GlobalQuantifyCapability(
r'^dart\.core\.(Iterable|List|String|int|Object)', contained)
@ -11,11 +11,11 @@ import 'reflector_test.reflectable.dart';
void main() {
initializeReflectable();
var reflector = const GeneratedReflector();
Container container;
late Container container;
setUp(() {
container = new Container(reflector);
container.registerSingleton(new Artist(name: 'Stevie Wonder'));
container = Container(reflector);
container.registerSingleton(Artist(name: 'Stevie Wonder'));
});
group('reflectClass', () {
@ -27,7 +27,7 @@ void main() {
});
test('inject constructor parameters', () {
var album = container.make<Album>();
var album = container.make<Album>()!;
print(album.title);
expect(album.title, 'flowers by stevie wonder');
});
@ -39,16 +39,16 @@ void main() {
void returnVoidFromAFunction(int x) {}
void testReflector(Reflector reflector) {
var blaziken = new Pokemon('Blaziken', PokemonType.fire);
Container container;
var blaziken = Pokemon('Blaziken', PokemonType.fire);
late Container container;
setUp(() {
container = new Container(reflector);
container = Container(reflector);
container.registerSingleton(blaziken);
});
test('get field', () {
var blazikenMirror = reflector.reflectInstance(blaziken);
var blazikenMirror = reflector.reflectInstance(blaziken)!;
expect(blazikenMirror.getField('type').reflectee, blaziken.type);
});
@ -93,12 +93,12 @@ void testReflector(Reflector reflector) {
});
test('constructor injects singleton', () {
var lower = container.make<LowerPokemon>();
var lower = container.make<LowerPokemon>()!;
expect(lower.lowercaseName, blaziken.name.toLowerCase());
});
test('newInstance works', () {
var type = container.reflector.reflectType(Pokemon);
var type = container.reflector.reflectType(Pokemon)!;
var instance =
type.newInstance('changeName', [blaziken, 'Charizard']).reflectee
as Pokemon;
@ -109,7 +109,7 @@ void testReflector(Reflector reflector) {
test('isAssignableTo', () {
var pokemonType = container.reflector.reflectType(Pokemon);
var kantoPokemonType = container.reflector.reflectType(KantoPokemon);
var kantoPokemonType = container.reflector.reflectType(KantoPokemon)!;
expect(kantoPokemonType.isAssignableTo(pokemonType), true);
expect(
@ -136,7 +136,7 @@ class Pokemon {
Pokemon(this.name, this.type);
factory Pokemon.changeName(Pokemon other, String name) {
return new Pokemon(name, other.type);
return Pokemon(name, other.type);
}
@override
@ -153,12 +153,12 @@ enum PokemonType { water, fire, grass, ice, poison, flying }
@contained
class Artist {
final String name;
final String? name;
Artist({this.name});
String get lowerName {
return name.toLowerCase();
return name!.toLowerCase();
}
}
@ -178,5 +178,5 @@ class AlbumLength {
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

@ -3,7 +3,7 @@
import "dart:core";
import 'dart:math' as prefix4;
import 'package:angel_container_generator/angel_container_generator.dart'
import 'package:angel3_container_generator/angel3_container_generator.dart'
as prefix0;
import 'package:reflectable/capability.dart' as prefix2;
import 'package:reflectable/mirrors.dart' as prefix3;
@ -395,13 +395,13 @@ final _data = <r.Reflectable, r.ReflectorData>{
? (length == null ? [] : []
..length)
: null,
r"filled": (b) => (length, fill, {growable: false}) =>
r"filled": (b) => (length, fill, {growable = false}) =>
b ? List.filled(length, fill, growable: growable) : null,
r"from": (b) => (elements, {growable: true}) =>
r"from": (b) => (elements, {growable = true}) =>
b ? List.from(elements, growable: growable) : null,
r"of": (b) => (elements, {growable: true}) =>
r"of": (b) => (elements, {growable = true}) =>
b ? List.of(elements, growable: growable) : null,
r"generate": (b) => (length, generator, {growable: true}) => b
r"generate": (b) => (length, generator, {growable = true}) => b
? List.generate(length, generator, growable: growable)
: null,
r"unmodifiable": (b) =>
@ -431,7 +431,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
-1,
11,
const <int>[],
const <Object>[const pragma("vm:entry-point")],
const <Object>[pragma("vm:entry-point")],
null),
r.NonGenericClassMirrorImpl(
r"String",
@ -717,13 +717,13 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"noSuchMethod",
65538,
11,
null,
null,
null,
0,
0,
0,
const <int>[],
const <int>[2],
const prefix0.ContainedReflectable(),
const <Object>[const pragma("vm:entry-point")]),
const <Object>[pragma("vm:entry-point")]),
r.MethodMirrorImpl(
r"hashCode",
131075,
@ -915,7 +915,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r.MethodMirrorImpl(
r"capabilities",
4325379,
null,
0,
10,
19,
10,
@ -926,7 +926,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r.MethodMirrorImpl(
r"canReflect",
131074,
null,
0,
-1,
16,
16,
@ -937,7 +937,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r.MethodMirrorImpl(
r"reflect",
131074,
null,
0,
-1,
20,
20,
@ -948,7 +948,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r.MethodMirrorImpl(
r"canReflectType",
131074,
null,
0,
-1,
16,
16,
@ -959,7 +959,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r.MethodMirrorImpl(
r"reflectType",
131074,
null,
0,
-1,
21,
21,
@ -970,7 +970,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r.MethodMirrorImpl(
r"findLibrary",
131074,
null,
0,
-1,
22,
22,
@ -981,7 +981,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r.MethodMirrorImpl(
r"libraries",
4325379,
null,
0,
-1,
24,
25,
@ -992,7 +992,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r.MethodMirrorImpl(
r"annotatedClasses",
4325379,
null,
0,
9,
27,
9,
@ -1404,7 +1404,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"forEach",
262146,
9,
null,
0,
-1,
-1,
const <int>[],
@ -1676,7 +1676,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"copyRange",
262162,
10,
null,
0,
-1,
-1,
const <int>[],
@ -1687,7 +1687,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"writeIterable",
262162,
10,
null,
0,
-1,
-1,
const <int>[],
@ -1720,7 +1720,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"[]=",
262658,
10,
null,
0,
-1,
-1,
const <int>[],
@ -1731,7 +1731,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"add",
262658,
10,
null,
0,
-1,
-1,
const <int>[],
@ -1742,7 +1742,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"addAll",
262658,
10,
null,
0,
-1,
-1,
const <int>[],
@ -1753,7 +1753,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"sort",
262658,
10,
null,
0,
-1,
-1,
const <int>[],
@ -1764,7 +1764,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"shuffle",
262658,
10,
null,
0,
-1,
-1,
const <int>[],
@ -1819,7 +1819,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"clear",
262658,
10,
null,
0,
-1,
-1,
const <int>[],
@ -1830,7 +1830,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"insert",
262658,
10,
null,
0,
-1,
-1,
const <int>[],
@ -1841,7 +1841,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"insertAll",
262658,
10,
null,
0,
-1,
-1,
const <int>[],
@ -1852,7 +1852,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"setAll",
262658,
10,
null,
0,
-1,
-1,
const <int>[],
@ -1896,7 +1896,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"removeWhere",
262658,
10,
null,
0,
-1,
-1,
const <int>[],
@ -1907,7 +1907,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"retainWhere",
262658,
10,
null,
0,
-1,
-1,
const <int>[],
@ -1942,7 +1942,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"setRange",
262658,
10,
null,
0,
-1,
-1,
const <int>[],
@ -1953,7 +1953,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"removeRange",
262658,
10,
null,
0,
-1,
-1,
const <int>[],
@ -1964,7 +1964,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"fillRange",
262658,
10,
null,
0,
-1,
-1,
const <int>[],
@ -1975,7 +1975,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"replaceRange",
262658,
10,
null,
0,
-1,
-1,
const <int>[],
@ -1997,7 +1997,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"first=",
262660,
10,
null,
0,
-1,
-1,
const <int>[],
@ -2008,7 +2008,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"last=",
262660,
10,
null,
0,
-1,
-1,
const <int>[],
@ -2030,7 +2030,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"length=",
262660,
10,
null,
0,
-1,
-1,
const <int>[],
@ -2505,7 +2505,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"write",
262146,
13,
null,
0,
-1,
-1,
const <int>[],
@ -2516,7 +2516,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"writeCharCode",
262146,
13,
null,
0,
-1,
-1,
const <int>[],
@ -2527,7 +2527,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"writeAll",
262146,
13,
null,
0,
-1,
-1,
const <int>[],
@ -2538,7 +2538,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"writeln",
262146,
13,
null,
0,
-1,
-1,
const <int>[],
@ -2549,7 +2549,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"clear",
262146,
13,
null,
0,
-1,
-1,
const <int>[],
@ -2615,7 +2615,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"write",
262658,
14,
null,
0,
-1,
-1,
const <int>[],
@ -2626,7 +2626,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"writeAll",
262658,
14,
null,
0,
-1,
-1,
const <int>[],
@ -2637,7 +2637,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"writeln",
262658,
14,
null,
0,
-1,
-1,
const <int>[],
@ -2648,7 +2648,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
r"writeCharCode",
262658,
14,
null,
0,
-1,
-1,
const <int>[],
@ -2676,9 +2676,9 @@ final _data = <r.Reflectable, r.ReflectorData>{
16390,
18,
const prefix0.ContainedReflectable(),
null,
null,
null,
0,
0,
0,
const <int>[],
const <Object>[],
null,
@ -3048,7 +3048,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
12294,
80,
const prefix0.ContainedReflectable(),
null,
0,
50,
50,
const <int>[],
@ -3128,13 +3128,13 @@ final _data = <r.Reflectable, r.ReflectorData>{
null,
null),
r.ParameterMirrorImpl(r"f", 6, 90, const prefix0.ContainedReflectable(),
null, 52, 52, null, const <Object>[], null, null),
0, 52, 52, null, const <Object>[], null, null),
r.ParameterMirrorImpl(
r"test",
6,
91,
const prefix0.ContainedReflectable(),
null,
0,
53,
53,
null,
@ -3142,7 +3142,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
null,
null),
r.ParameterMirrorImpl(r"f", 6, 93, const prefix0.ContainedReflectable(),
null, 54, 54, null, const <Object>[], null, null),
0, 54, 54, null, const <Object>[], null, null),
r.ParameterMirrorImpl(
r"element",
32774,
@ -3156,13 +3156,13 @@ final _data = <r.Reflectable, r.ReflectorData>{
null,
null),
r.ParameterMirrorImpl(r"f", 6, 95, const prefix0.ContainedReflectable(),
null, 55, 55, null, const <Object>[], null, null),
0, 55, 55, null, const <Object>[], null, null),
r.ParameterMirrorImpl(
r"combine",
6,
96,
const prefix0.ContainedReflectable(),
null,
0,
56,
56,
null,
@ -3174,7 +3174,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
97,
const prefix0.ContainedReflectable(),
null,
0,
-1,
-1,
const <int>[],
@ -3186,7 +3186,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
97,
const prefix0.ContainedReflectable(),
null,
0,
57,
57,
null,
@ -3198,7 +3198,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
98,
const prefix0.ContainedReflectable(),
null,
0,
53,
53,
null,
@ -3222,7 +3222,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
100,
const prefix0.ContainedReflectable(),
null,
0,
53,
53,
null,
@ -3258,7 +3258,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
104,
const prefix0.ContainedReflectable(),
null,
0,
53,
53,
null,
@ -3282,7 +3282,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
106,
const prefix0.ContainedReflectable(),
null,
0,
53,
53,
null,
@ -3294,7 +3294,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
107,
const prefix0.ContainedReflectable(),
null,
0,
53,
53,
null,
@ -3306,7 +3306,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
12294,
107,
const prefix0.ContainedReflectable(),
null,
0,
58,
58,
null,
@ -3318,7 +3318,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
108,
const prefix0.ContainedReflectable(),
null,
0,
53,
53,
null,
@ -3330,7 +3330,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
12294,
108,
const prefix0.ContainedReflectable(),
null,
0,
58,
58,
null,
@ -3342,7 +3342,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
109,
const prefix0.ContainedReflectable(),
null,
0,
53,
53,
null,
@ -3354,7 +3354,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
12294,
109,
const prefix0.ContainedReflectable(),
null,
0,
58,
58,
null,
@ -3390,7 +3390,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
4102,
120,
const prefix0.ContainedReflectable(),
null,
0,
59,
59,
null,
@ -3534,7 +3534,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
127,
const prefix0.ContainedReflectable(),
null,
0,
-1,
-1,
const <int>[],
@ -3546,7 +3546,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
128,
const prefix0.ContainedReflectable(),
null,
0,
-1,
-1,
const <int>[],
@ -3570,7 +3570,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
4102,
130,
const prefix0.ContainedReflectable(),
null,
0,
64,
64,
null,
@ -3594,7 +3594,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
132,
const prefix0.ContainedReflectable(),
null,
0,
-1,
-1,
const <int>[],
@ -3618,7 +3618,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
133,
const prefix0.ContainedReflectable(),
null,
0,
66,
66,
null,
@ -3642,7 +3642,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
134,
const prefix0.ContainedReflectable(),
null,
0,
66,
66,
null,
@ -3666,7 +3666,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
135,
const prefix0.ContainedReflectable(),
null,
0,
-1,
-1,
const <int>[],
@ -3702,7 +3702,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
137,
const prefix0.ContainedReflectable(),
null,
0,
-1,
-1,
const <int>[],
@ -3786,7 +3786,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
143,
const prefix0.ContainedReflectable(),
null,
0,
66,
66,
null,
@ -3798,7 +3798,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
144,
const prefix0.ContainedReflectable(),
null,
0,
66,
66,
null,
@ -3966,7 +3966,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
4102,
150,
const prefix0.ContainedReflectable(),
null,
0,
-1,
-1,
const <int>[],
@ -4038,7 +4038,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
159,
const prefix0.ContainedReflectable(),
null,
0,
-1,
-1,
const <int>[],
@ -4122,7 +4122,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
162,
const prefix0.ContainedReflectable(),
null,
0,
68,
68,
null,
@ -4158,7 +4158,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
153,
const prefix0.ContainedReflectable(),
null,
0,
-1,
-1,
const <int>[],
@ -4170,7 +4170,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
154,
const prefix0.ContainedReflectable(),
null,
0,
-1,
-1,
const <int>[],
@ -4494,7 +4494,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
183,
const prefix0.ContainedReflectable(),
null,
0,
70,
70,
const <int>[],
@ -4554,7 +4554,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
6,
185,
const prefix0.ContainedReflectable(),
null,
0,
70,
70,
const <int>[],
@ -4626,7 +4626,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
12294,
188,
const prefix0.ContainedReflectable(),
null,
0,
70,
70,
const <int>[],
@ -4638,7 +4638,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
12294,
188,
const prefix0.ContainedReflectable(),
null,
0,
71,
71,
const <int>[],
@ -4990,7 +4990,7 @@ final _data = <r.Reflectable, r.ReflectorData>{
[])
};
final _memberSymbolMap = null;
final dynamic _memberSymbolMap = null;
initializeReflectable() {
r.data = _data;

View file

@ -1,21 +1,23 @@
# angel3_json_god
[![version](https://img.shields.io/badge/pub-v4.0.3-brightgreen)](https://pub.dartlang.org/packages/angel3_json_god)
[![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)
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/json_god/LICENSE)
**DEPRECATED: Replaced by [`belatuk_json_serializer`](https://pub.dartlang.org/packages/belatuk_json_serializer) package**
The ***new and improved*** definitive solution for JSON in Dart. It supports synchronously transform an object into a JSON string and also deserialize a JSON string back into an instance of any type.
## Installation
# Installation
dependencies:
angel3_json_god: ^4.0.0
dependencies:
angel3_json_god: ^4.0.0
# Usage
## Usage
It is recommended to import the library under an alias, i.e., `god`.
It is recommended to import the library under an alias, i.e., `god`.
```dart
import 'package:angel3_json_god/angel3_json_god.dart' as god;
@ -25,6 +27,7 @@ import 'package:angel3_json_god/angel3_json_god.dart' as god;
Simply call `god.serialize(x)` to synchronously transform an object into a JSON
string.
```dart
Map map = {"foo": "bar", "numbers": [1, 2, {"three": 4}]};
@ -34,6 +37,7 @@ print(json);
```
You can easily serialize classes, too. JSON God also supports classes as members.
```dart
class A {
@ -62,6 +66,7 @@ If a class has a `toJson` method, it will be called instead.
## Deserializing JSON
Deserialization is equally easy, and is provided through `god.deserialize`.
```dart
Map map = god.deserialize('{"hello":"world"}');
int three = god.deserialize("3");
@ -92,7 +97,7 @@ main() {
```
**Any JSON-deserializable classes must initializable without parameters.
If ` Foo()` would throw an error, then you can't use Foo with JSON.**
If `Foo()` would throw an error, then you can't use Foo with JSON.**
This allows for validation of a sort, as only fields you have declared will be
accepted.
@ -105,4 +110,3 @@ HasAnInt invalid = god.deserialize('["some invalid input"]', HasAnInt);
```
An exception will be thrown if validation fails.

View file

@ -1,5 +1,9 @@
# Change Log
## 3.1.0
* Updated linter to `package:lints`
## 3.0.2
* Updated README

View file

@ -1,21 +1,29 @@
MIT License (MIT)
BSD 3-Clause License
Copyright (c) 2021 dukefirehawk.com
Copyright (c) 2021, dukefirehawk.com
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View file

@ -1,10 +1,9 @@
# Angel3 Basic Model
# Angel3 Basic Data Model
[![version](https://img.shields.io/badge/pub-v3.0.2-brightgreen)](https://pub.dartlang.org/packages/angel3_model)
![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)
[![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/angel3/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.

View file

@ -1,4 +1,2 @@
include: package:pedantic/analysis_options.yaml
analyzer:
strong-mode:
implicit-casts: false
include: package:lints/recommended.yaml

View file

@ -1,9 +1,9 @@
name: angel3_model
version: 3.0.2
version: 3.1.0
description: Angel3 basic data model class, no longer with the added weight of the whole framework.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/model
repository: https://github.com/dukefirehawk/angel/tree/master/packages/model
environment:
sdk: '>=2.12.0 <3.0.0'
dev_dependencies:
pedantic: ^1.11.0
lints: ^1.0.0

View file

@ -7,7 +7,7 @@
## 3.0.0-dev.1
* Migrated to support Dart SDK 2.12.x NNBD
* Upgraded from `pendantic` to `lints` linter
* Updated linter to `package:lints`
## 2.1.0