Refactor: changing namespace, imports, re-branding

This commit is contained in:
Patrick Stewart 2024-10-12 19:17:24 -07:00
parent f4abaf2474
commit 2ea69f2cde
64 changed files with 179 additions and 171 deletions

View file

@ -135,9 +135,9 @@
## 2.0.0
* Made `AuthStrategy` generic.
* `AngelAuth.strategies` is now a `Map<String, AuthStrategy<User>>`.
* `ProtevusAuth.strategies` is now a `Map<String, AuthStrategy<User>>`.
* Removed `AuthStrategy.canLogout`.
* Made `AngelAuthTokenCallback` generic.
* Made `ProtevusAuthTokenCallback` generic.
## 2.0.0-alpha

View file

@ -18,7 +18,7 @@ Ensure you have read the [User Guide](https://protevus-docs.dukefirehawk.com/gui
```dart
configureServer(Protevus app) async {
var auth = AngelAuth<User>(
var auth = ProtevusAuth<User>(
serializer: (user) => user.id ?? '',
deserializer: (id) => fetchAUserByIdSomehow(id
);
@ -58,7 +58,7 @@ A frequent use case within SPA's is opening OAuth login endpoints in a separate
configureServer(Protevus app) async {
var handler = auth.authenticate(
'facebook',
AngelAuthOptions(callback: confirmPopupAuthentication()));
ProtevusAuthOptions(callback: confirmPopupAuthentication()));
app.get('/auth/facebook', handler);
// Use a comma to try multiple strategies!!!

View file

@ -5,7 +5,7 @@ import 'package:protevus_framework/http.dart';
void main() async {
var app = Protevus();
var auth = AngelAuth<User>(
var auth = ProtevusAuth<User>(
serializer: (user) => user.id ?? '',
deserializer: (id) => fetchAUserByIdSomehow(id));

View file

@ -64,7 +64,7 @@ void main() async {
.findService('users')
?.create({'username': 'jdoe1', 'password': 'password'});
var auth = AngelAuth<User>(
var auth = ProtevusAuth<User>(
serializer: (u) => u.id ?? '',
deserializer: (id) async =>
await app.findService('users')?.read(id) as User);
@ -88,7 +88,8 @@ void main() async {
app.post(
'/login',
auth.authenticate('local', AngelAuthOptions(callback: (req, res, token) {
auth.authenticate('local',
ProtevusAuthOptions(callback: (req, res, token) {
res
..write('Hello!')
..close();

View file

@ -7,13 +7,15 @@ import 'package:logging/logging.dart';
final Map<String, String> sampleUser = {'hello': 'world'};
final AngelAuth<Map<String, String>> auth = AngelAuth<Map<String, String>>(
serializer: (user) async => '1337', deserializer: (id) async => sampleUser);
final ProtevusAuth<Map<String, String>> auth =
ProtevusAuth<Map<String, String>>(
serializer: (user) async => '1337',
deserializer: (id) async => sampleUser);
//var headers = <String, String>{'accept': 'application/json'};
var localOpts = AngelAuthOptions<Map<String, String>>(
var localOpts = ProtevusAuthOptions<Map<String, String>>(
failureRedirect: '/failure', successRedirect: '/success');
var localOpts2 =
AngelAuthOptions<Map<String, String>>(canRespondWithJson: false);
ProtevusAuthOptions<Map<String, String>>(canRespondWithJson: false);
Future<Map<String, String>> verifier(String? username, String? password) async {
if (username == 'username' && password == 'password') {

View file

@ -3,15 +3,15 @@ import 'dart:async';
import 'package:protevus_framework/protevus_framework.dart';
import 'auth_token.dart';
typedef AngelAuthCallback = FutureOr Function(
typedef ProtevusAuthCallback = FutureOr Function(
RequestContext req, ResponseContext res, String token);
typedef AngelAuthTokenCallback<User> = FutureOr Function(
typedef ProtevusAuthTokenCallback<User> = FutureOr Function(
RequestContext req, ResponseContext res, AuthToken token, User user);
class AngelAuthOptions<User> {
AngelAuthCallback? callback;
AngelAuthTokenCallback<User>? tokenCallback;
class ProtevusAuthOptions<User> {
ProtevusAuthCallback? callback;
ProtevusAuthTokenCallback<User>? tokenCallback;
String? successRedirect;
String? failureRedirect;
@ -21,7 +21,7 @@ class AngelAuthOptions<User> {
/// Works well with `Basic` authentication.
bool canRespondWithJson;
AngelAuthOptions(
ProtevusAuthOptions(
{this.callback,
this.tokenCallback,
this.canRespondWithJson = true,

View file

@ -10,8 +10,8 @@ import 'options.dart';
import 'strategy.dart';
/// Handles authentication within an Protevus application.
class AngelAuth<User> {
final _log = Logger('AngelAuth');
class ProtevusAuth<User> {
final _log = Logger('ProtevusAuth');
late Hmac _hs256;
late int _jwtLifeSpan;
@ -78,7 +78,7 @@ class AngelAuth<User> {
}
/// `jwtLifeSpan` - should be in *milliseconds*.
AngelAuth(
ProtevusAuth(
{String? jwtKey,
required this.serializer,
required this.deserializer,
@ -101,11 +101,11 @@ class AngelAuth<User> {
/*
if (serializer == null) {
throw StateError(
'An `AngelAuth` plug-in was called without its `serializer` being set. All authentication will fail.');
'An `ProtevusAuth` plug-in was called without its `serializer` being set. All authentication will fail.');
}
if (deserializer == null) {
throw StateError(
'An `AngelAuth` plug-in was called without its `deserializer` being set. All authentication will fail.');
'An `ProtevusAuth` plug-in was called without its `deserializer` being set. All authentication will fail.');
}
if (app.container == null) {
@ -117,8 +117,8 @@ class AngelAuth<User> {
var appContainer = app.container;
appContainer.registerSingleton(this);
if (runtimeType != AngelAuth) {
appContainer.registerSingleton(this, as: AngelAuth);
if (runtimeType != ProtevusAuth) {
appContainer.registerSingleton(this, as: ProtevusAuth);
}
if (!appContainer.has<_AuthResult<User>>()) {
@ -128,7 +128,7 @@ class AngelAuth<User> {
var res = container.make<ResponseContext>();
//if (req == null || res == null) {
// _log.warning('RequestContext or responseContext is null');
// throw AngelHttpException.forbidden();
// throw ProtevusHttpException.forbidden();
//}
var result = await _decodeJwt(req, res);
@ -187,7 +187,7 @@ class AngelAuth<User> {
/// `makeAsync<User>`, or Protevus's injections directly:
///
/// ```dart
/// var auth = AngelAuth<User>(...);
/// var auth = ProtevusAuth<User>(...);
/// await app.configure(auth.configureServer);
///
/// app.get('/hmm', (User user) async {
@ -355,9 +355,9 @@ class AngelAuth<User> {
/// or a `401 Not Authenticated` is thrown, if it is the last one.
///
/// Any other result is considered an authenticated user, and terminates the loop.
RequestHandler authenticate(type, [AngelAuthOptions<User>? opt]) {
RequestHandler authenticate(type, [ProtevusAuthOptions<User>? opt]) {
return (RequestContext req, ResponseContext res) async {
var authOption = opt ?? AngelAuthOptions<User>();
var authOption = opt ?? ProtevusAuthOptions<User>();
var names = <String>[];
@ -485,7 +485,7 @@ class AngelAuth<User> {
}
/// Log an authenticated user out.
RequestHandler logout([AngelAuthOptions<User>? options]) {
RequestHandler logout([ProtevusAuthOptions<User>? options]) {
return (RequestContext req, ResponseContext res) async {
if (req.container?.has<User>() == true) {
var user = req.container?.make<User>();

View file

@ -4,7 +4,7 @@ import 'package:http_parser/http_parser.dart';
import 'options.dart';
/// Displays a default callback page to confirm authentication via popups.
AngelAuthCallback confirmPopupAuthentication({String eventName = 'token'}) {
ProtevusAuthCallback confirmPopupAuthentication({String eventName = 'token'}) {
return (req, ResponseContext res, String jwt) {
var evt = json.encode(eventName);
var detail = json.encode({'detail': jwt});

View file

@ -36,8 +36,8 @@ class LocalAuthStrategy<User> extends AuthStrategy<User> {
@override
Future<User?> authenticate(RequestContext req, ResponseContext res,
[AngelAuthOptions? options]) async {
var localOptions = options ?? AngelAuthOptions();
[ProtevusAuthOptions? options]) async {
var localOptions = options ?? ProtevusAuthOptions();
User? verificationResult;
if (allowBasic) {
@ -129,7 +129,7 @@ class LocalAuthStrategy<User> extends AuthStrategy<User> {
return verificationResult;
} else {
_log.info('Not authenticated');
throw AngelHttpException.notAuthenticated();
throw ProtevusHttpException.notAuthenticated();
}
*/
}

View file

@ -6,5 +6,5 @@ import 'options.dart';
abstract class AuthStrategy<User> {
/// Authenticates or rejects an incoming user.
FutureOr<User?> authenticate(RequestContext req, ResponseContext res,
[AngelAuthOptions<User>? options]);
[ProtevusAuthOptions<User>? options]);
}

View file

@ -37,7 +37,7 @@ class User extends Model {
void main() {
late Protevus app;
late ProtevusHttp angelHttp;
AngelAuth<User> auth;
ProtevusAuth<User> auth;
http.Client? client;
HttpServer server;
String? url;
@ -73,7 +73,7 @@ void main() {
.findService('users')
?.create({'username': 'jdoe1', 'password': 'password'});
auth = AngelAuth<User>(
auth = ProtevusAuth<User>(
serializer: (u) => u.id ?? '',
deserializer: (id) async =>
await app.findService('users')?.read(id) as User);
@ -98,7 +98,7 @@ void main() {
app.post(
'/login',
auth.authenticate('local',
AngelAuthOptions(callback: (req, res, token) {
ProtevusAuthOptions(callback: (req, res, token) {
res
..write('Hello!')
..close();

View file

@ -8,13 +8,15 @@ import 'package:http/http.dart' as http;
import 'package:logging/logging.dart';
import 'package:test/test.dart';
final AngelAuth<Map<String, String>> auth = AngelAuth<Map<String, String>>(
serializer: (user) async => '1337', deserializer: (id) async => sampleUser);
final ProtevusAuth<Map<String, String>> auth =
ProtevusAuth<Map<String, String>>(
serializer: (user) async => '1337',
deserializer: (id) async => sampleUser);
//var headers = <String, String>{'accept': 'application/json'};
var localOpts = AngelAuthOptions<Map<String, String>>(
var localOpts = ProtevusAuthOptions<Map<String, String>>(
failureRedirect: '/failure', successRedirect: '/success');
var localOpts2 =
AngelAuthOptions<Map<String, String>>(canRespondWithJson: false);
ProtevusAuthOptions<Map<String, String>>(canRespondWithJson: false);
Map<String, String> sampleUser = {'hello': 'world'};

View file

@ -7,7 +7,7 @@ const Duration threeDays = Duration(days: 3);
void main() {
late Cookie defaultCookie;
var auth = AngelAuth(
var auth = ProtevusAuth(
secureCookies: true,
cookieDomain: 'SECURE',
jwtLifeSpan: threeDays.inMilliseconds,

View file

@ -71,4 +71,4 @@
## 1.0.2
Added `getParameters` to `AngelOAuth2Options`.
Added `getParameters` to `ProtevusOAuth2Options`.

View file

@ -71,7 +71,7 @@ configureServer(Protevus app) {
}
```
Lastly, connect it to an `AngelAuth` instance, and wire it up to an `Protevus` server. Set up two routes:
Lastly, connect it to an `ProtevusAuth` instance, and wire it up to an `Protevus` server. Set up two routes:
1. Redirect users to the external provider
2. Acts as a callback and handles an access code
@ -81,7 +81,7 @@ In the case of the callback route, you may want to display an HTML page that clo
```dart
configureServer(Protevus app) async {
// ...
var auth = AngelAuth<User>();
var auth = ProtevusAuth<User>();
auth.strategies['github'] = oauth2Strategy;
// Redirect
@ -90,7 +90,7 @@ configureServer(Protevus app) async {
// Callback
app.get('/auth/github/callback', auth.authenticate(
'github',
AngelAuthOptions(callback: confirmPopupAuthentication())
ProtevusAuthOptions(callback: confirmPopupAuthentication())
));
// Connect the plug-in!!!

View file

@ -47,7 +47,7 @@ void main() async {
var mappedUserService = userService.map(User.parse, User.serialize);
// Set up the authenticator plugin.
var auth = AngelAuth<User>(
var auth = ProtevusAuth<User>(
serializer: (user) async => user.id ?? '',
deserializer: (id) => mappedUserService.read(id),
jwtKey: 'oauth2 example secret',
@ -94,7 +94,7 @@ void main() async {
app.get(
'/auth/github/callback',
auth.authenticate('github',
AngelAuthOptions(callback: (req, res, jwt) async {
ProtevusAuthOptions(callback: (req, res, jwt) async {
// In real-life, you might include a pop-up callback script.
//
// Use `confirmPopupAuthentication`, which is bundled with

View file

@ -47,7 +47,7 @@ class OAuth2Strategy<User> implements AuthStrategy<User> {
@override
FutureOr<User?> authenticate(RequestContext req, ResponseContext res,
[AngelAuthOptions<User>? options]) async {
[ProtevusAuthOptions<User>? options]) async {
if (options != null) {
var result = await authenticateCallback(req, res, options);
if (result is User) {
@ -71,7 +71,7 @@ class OAuth2Strategy<User> implements AuthStrategy<User> {
/// The endpoint that is invoked by the third-party after successful authentication.
Future<dynamic> authenticateCallback(RequestContext req, ResponseContext res,
[AngelAuthOptions? options]) async {
[ProtevusAuthOptions? options]) async {
var grant = _createGrant();
grant.getAuthorizationUrl(this.options.redirectUri,
scopes: this.options.scopes);

View file

@ -17,7 +17,7 @@ class _User {
void main() async {
var app = Protevus();
var http = ProtevusHttp(app);
var auth = AngelAuth<_User>(
var auth = ProtevusAuth<_User>(
jwtKey: 'AUTH_TWITTER_SECRET',
allowCookie: false,
serializer: (user) async => user.handle,
@ -59,7 +59,7 @@ void main() async {
'/auth/twitter/callback',
auth.authenticate(
'twitter',
AngelAuthOptions(
ProtevusAuthOptions(
callback: (req, res, jwt) {
return res.redirect('/home?token=$jwt');
},

View file

@ -119,7 +119,7 @@ class TwitterStrategy<User> extends AuthStrategy<User> {
@override
Future<User?> authenticate(RequestContext req, ResponseContext res,
[AngelAuthOptions? options]) async {
[ProtevusAuthOptions? options]) async {
try {
if (options != null) {
var result = await authenticateCallback(req, res, options);
@ -145,8 +145,8 @@ class TwitterStrategy<User> extends AuthStrategy<User> {
}
}
Future authenticateCallback(
RequestContext req, ResponseContext res, AngelAuthOptions options) async {
Future authenticateCallback(RequestContext req, ResponseContext res,
ProtevusAuthOptions options) async {
try {
if (req.queryParameters.containsKey('denied')) {
throw TwitterAuthorizationException(

View file

@ -84,7 +84,7 @@ Some servers expect a reverse proxy or caching layer to support `PURGE` requests
Future configureServer(Protevus app) async {
app.addRoute('PURGE', '*', (req, res) {
if (req.ip != '127.0.0.1')
throw AngelHttpException.forbidden();
throw ProtevusHttpException.forbidden();
return cache.purge(req.uri.path);
});
}

View file

@ -72,7 +72,7 @@
## 2.0.1
* Change `BaseAngelClient` constructor to accept `dynamic` instead of `String` for `baseUrl.
* Change `BaseProtevusClient` constructor to accept `dynamic` instead of `String` for `baseUrl.
## 2.0.0

View file

@ -65,7 +65,7 @@ print(auth.data); // User object
Revive an existing jwt:
```dart
Future<AngelAuthResult> reviveJwt(String jwt) {
Future<ProtevusAuthResult> reviveJwt(String jwt) {
return app.authenticate(credentials: {'token': jwt});
}
```

View file

@ -6,11 +6,11 @@ import 'package:logging/logging.dart';
void main() async {
const Map<String, String> user = {'username': 'foo', 'password': 'bar'};
var localOpts =
AngelAuthOptions<Map<String, String>>(canRespondWithJson: true);
ProtevusAuthOptions<Map<String, String>>(canRespondWithJson: true);
Protevus app = Protevus();
ProtevusHttp http = ProtevusHttp(app, useZone: false);
var auth = AngelAuth(
var auth = ProtevusAuth(
serializer: (_) async => 'baz', deserializer: (_) async => user);
auth.strategies['local'] = LocalAuthStrategy((username, password) async {

View file

@ -42,7 +42,7 @@ ProtevusHttpException failure(Response response,
}
abstract class BaseProtevusClient extends Protevus {
final _log = Logger('BaseAngelClient');
final _log = Logger('BaseProtevusClient');
final StreamController<ProtevusAuthResult> _onAuthenticated =
StreamController<ProtevusAuthResult>();
final List<Service> _services = [];

View file

@ -3,7 +3,7 @@ import 'package:test/test.dart';
import 'common.dart';
void main() {
var app = MockAngel();
var app = MockProtevus();
var todoService = app.service('api/todos');
test('sets method,body,headers,path', () async {

View file

@ -6,7 +6,8 @@ import 'package:logging/logging.dart';
import 'package:test/test.dart';
const Map<String, String> user = {'username': 'foo', 'password': 'bar'};
var localOpts = AngelAuthOptions<Map<String, String>>(canRespondWithJson: true);
var localOpts =
ProtevusAuthOptions<Map<String, String>>(canRespondWithJson: true);
void main() {
late Protevus app;
@ -16,7 +17,7 @@ void main() {
setUp(() async {
app = Protevus();
http = ProtevusHttp(app, useZone: false);
var auth = AngelAuth(
var auth = ProtevusAuth(
serializer: (_) async => 'baz', deserializer: (_) async => user);
auth.strategies['local'] = LocalAuthStrategy(

View file

@ -8,13 +8,13 @@ import 'package:http/src/streamed_response.dart' as http;
Future<String> read(Stream<List<int>> stream) =>
stream.transform(utf8.decoder).join();
class MockAngel extends BaseProtevusClient {
class MockProtevus extends BaseProtevusClient {
final SpecClient specClient = SpecClient();
@override
get client => specClient;
MockAngel() : super(SpecClient(), 'http://localhost:3000');
MockProtevus() : super(SpecClient(), 'http://localhost:3000');
@override
Stream<String> authenticateViaPopup(String url,

View file

@ -38,7 +38,7 @@ A better IoC container for Protevus, ultimately allowing Protevus to be used wit
app.container.registerSingleton<SalesController>(SalesController());
await app.mountController<SalesController>();
var http = AngelHttp(app);
var http = ProtevusHttp(app);
var server = await http.startServer('localhost', 3000);
print("Protevus server listening at ${http.uri}");
}

View file

@ -29,7 +29,7 @@
## 6.0.0
* Require Dart >= 2.16
* [**Breaking**] `error` for `AngelHttpException` is no longer mandatory
* [**Breaking**] `error` for `ProtevusHttpException` is no longer mandatory
## 5.0.0

View file

@ -20,8 +20,8 @@
## 8.2.0
* Add `addResponseHeader` to `AngelHttp` to add headers to HTTP default response
* Add `removeResponseHeader` to `AngelHttp` to remove headers from HTTP default response
* Add `addResponseHeader` to `ProtevusHttp` to add headers to HTTP default response
* Add `removeResponseHeader` to `ProtevusHttp` to remove headers from HTTP default response
## 8.1.1
@ -138,7 +138,7 @@
## 2.1.1
* `AngelHttp.uri` now returns an empty `Uri` if the server is not listening.
* `ProtevusHttp.uri` now returns an empty `Uri` if the server is not listening.
## 2.1.0
@ -150,7 +150,7 @@ therefore been bumped to `2.1.0`.
## 2.0.5-beta
* Make `@Expose()` in `Controller` optional. <https://github.com/protevus-dart/protevus/issues/107>
* Add `allowHttp1` to `AngelHttp2` constructors. <https://github.com/protevus-dart/protevus/issues/108>
* Add `allowHttp1` to `ProtevusHttp2` constructors. <https://github.com/protevus-dart/protevus/issues/108>
* Add `deserializeBody` and `decodeBody` to `RequestContext`. <https://github.com/protevus-dart/protevus/issues/109>
* Add `HostnameRouter`, which allows for routing based on hostname. <https://github.com/protevus-dart/protevus/issues/110>
* Default to using `ThrowingReflector`, instead of `EmptyReflector`. This will give a more descriptive
@ -189,7 +189,7 @@ See more: <https://github.com/protevus-dart/protevus/issues/106#issuecomment-499
handlers to run, even after the response was closed.
* Add `RequestContext.shutdownHooks`.
* Call `RequestContext.close` in `Driver.sendResponse`.
* AngelConfigurer is now `FutureOr<void>`, instead of just `FutureOr`.
* ProtevusConfigurer is now `FutureOr<void>`, instead of just `FutureOr`.
* Use a `Container.has<Stopwatch>` check in `Driver.sendResponse`.
* Remove unnecessary `new` and `const`.
@ -199,7 +199,7 @@ handlers to run, even after the response was closed.
## 2.0.0-rc.10
* Fix an error that prevented `AngelHttp2.custom` from working properly.
* Fix an error that prevented `ProtevusHttp2.custom` from working properly.
* Add `startSharedHttp2`.
## 2.0.0-rc.9
@ -246,7 +246,7 @@ the outputs of `before` events.
## 2.0.0-rc.0
* Log a warning when no `reflector` is provided.
* Add `AngelEnvironment` class.
* Add `ProtevusEnvironment` class.
* Add `Protevus.environment`.
* Deprecated `app.isProduction` in favor of `app.environment.isProduction`.
* Allow setting of `bodyAsObject`, `bodyAsMap`, or `bodyAsList` **exactly once**.

View file

@ -38,7 +38,7 @@ void main() async {
var http1 = ProtevusHttp(app);
var http2 = ProtevusHttp2(app, ctx);
// HTTP/1.x requests will fallback to `AngelHttp`
// HTTP/1.x requests will fallback to `ProtevusHttp`
http2.onHttp1.listen(http1.handleRequest);
var server = await http2.startServer('127.0.0.1', 3000);

View file

@ -35,7 +35,7 @@ void main() async {
var http1 = ProtevusHttp(app);
var http2 = ProtevusHttp2(app, ctx);
// HTTP/1.x requests will fallback to `AngelHttp`
// HTTP/1.x requests will fallback to `ProtevusHttp`
http2.onHttp1.listen(http1.handleRequest);
await http2.startServer('127.0.0.1', 3000);

View file

@ -54,7 +54,7 @@ void main() async {
var http1 = ProtevusHttp(app);
var http2 = ProtevusHttp2(app, ctx);
// HTTP/1.x requests will fallback to `AngelHttp`
// HTTP/1.x requests will fallback to `ProtevusHttp`
http2.onHttp1.listen(http1.handleRequest);
var server = await http2.startServer('127.0.0.1', 3000);

View file

@ -10,7 +10,7 @@ import 'core.dart';
/// Base driver class for Protevus implementations.
///
/// Powers both AngelHttp and AngelHttp2.
/// Powers both ProtevusHttp and ProtevusHttp2.
abstract class Driver<
Request,
Response,

View file

@ -1,6 +1,6 @@
import 'dart:io';
/// A constant instance of [AngelEnv].
/// A constant instance of [ProtevusEnv].
const ProtevusEnvironment angelEnv = ProtevusEnvironment();
/// Queries the environment's `ANGEL_ENV` value.

View file

@ -96,7 +96,7 @@ class MapService extends Service<String?, Map<String, dynamic>> {
Future<Map<String, dynamic>> modify(String? id, Map<String, dynamic> data,
[Map<String, dynamic>? params]) {
//if (data is! Map) {
// throw AngelHttpException.badRequest(
// throw ProtevusHttpException.badRequest(
// message:
// 'MapService does not support `modify` with ${data.runtimeType}.');
//}
@ -119,7 +119,7 @@ class MapService extends Service<String?, Map<String, dynamic>> {
Future<Map<String, dynamic>> update(String? id, Map<String, dynamic> data,
[Map<String, dynamic>? params]) {
//if (data is! Map) {
// throw AngelHttpException.badRequest(
// throw ProtevusHttpException.badRequest(
// message:
// 'MapService does not support `update` with ${data.runtimeType}.');
//}

View file

@ -111,7 +111,7 @@ class Service<Id, Data> extends Routable {
/// Retrieves the first object from the result of calling [index] with the given [params].
///
/// If the result of [index] is `null`, OR an empty [Iterable], a 404 `AngelHttpException` will be thrown.
/// If the result of [index] is `null`, OR an empty [Iterable], a 404 `ProtevusHttpException` will be thrown.
///
/// If the result is both non-null and NOT an [Iterable], it will be returned as-is.
///

View file

@ -206,7 +206,7 @@ class _ProtevusHttp2ServerSocket extends Stream<SecureSocket>
} else {
socket.destroy();
throw Exception(
'AngelHttp2 does not support ${socket.selectedProtocol} as an ALPN protocol.');
'ProtevusHttp2 does not support ${socket.selectedProtocol} as an ALPN protocol.');
}
},
onDone: _ctrl.close,

View file

@ -3,19 +3,19 @@ import 'package:test/test.dart';
import 'common.dart';
void main() {
var throwsAnAngelHttpException =
var throwsAnProtevusHttpException =
throwsA(const IsInstanceOf<ProtevusHttpException>());
/*
test('throw 404 on null', () {
var service = AnonymousService(index: ([p]) => null);
expect(() => service.findOne(), throwsAnAngelHttpException);
expect(() => service.findOne(), throwsAnProtevusHttpException);
});
*/
test('throw 404 on empty iterable', () {
var service = AnonymousService(index: ([p]) => []);
expect(() => service.findOne(), throwsAnAngelHttpException);
expect(() => service.findOne(), throwsAnProtevusHttpException);
});
test('return first element of iterable', () async {

View file

@ -154,7 +154,7 @@ void main() {
});
});
group('handleAngelHttpException', () {
group('handleProtevusHttpException', () {
late Protevus app;
late ProtevusHttp http;

View file

@ -20,7 +20,7 @@ void main() {
return res.serialize(req.ip == InternetAddress.loopbackIPv4.address);
});
var http = AngelHttp(app);
var http = ProtevusHttp(app);
test('receive a response', () async {
var rq = MockHttpRequest('GET', uri.resolve('/foo'));

View file

@ -58,7 +58,7 @@ Future<Protevus> createServer() async {
app.get('/', (req, res) => {'hello': 'hot world!'});
app.get('/foo', (req, res) => Foo(bar: 'baz'));
app.fallback((req, res) => throw AngelHttpException.notFound());
app.fallback((req, res) => throw ProtevusHttpException.notFound());
app.encoders.addAll({
'gzip': gzip.encoder,

View file

@ -25,7 +25,7 @@ import 'package:protevus_framework/protevus_framework.dart';
import 'package:protevus_jael/protevus_jael.dart';
import 'package:file/file.dart';
AngelConfigurer myPlugin(FileSystem fileSystem) {
ProtevusConfigurer myPlugin(FileSystem fileSystem) {
return (Protevus app) async {
// Connect Jael to your server...
await app.configure(
@ -62,7 +62,7 @@ void main() async {
// Render the contents of views/index.jael
app.get('/', (res) => res.render('index', {'title': 'ESKETTIT'}));
app.use(() => throw AngelHttpException.notFound());
app.use(() => throw ProtevusHttpException.notFound());
app.logger = Logger('protevus')
..onRecord.listen((rec) {

View file

@ -18,7 +18,7 @@ import 'package:path/path.dart' as p;
void main() async {
var app = Protevus();
var http = AngelHttp(app);
var http = ProtevusHttp(app);
var viewsDir = p.join(
p.dirname(
p.fromUri(Platform.script),

View file

@ -25,7 +25,7 @@
## 6.0.1
* Fixed AngelHttpException error
* Fixed ProtevusHttpException error
* [Breaking] Renamed `error` to `authError` for `AuthorizationException`
## 6.0.0

View file

@ -80,7 +80,7 @@ simply just not extend `Model`:
```dart
@Serializable
abstract class _ThisIsNotAnAngelModel {
abstract class _ThisIsNotAnProtevusModel {
@primaryKey
String get username;
}
@ -97,7 +97,7 @@ import 'car.dart';
import 'car.orm.g.dart';
/// Returns an Protevus plug-in that connects to a database, and sets up a controller connected to it...
AngelConfigurer connectToCarsTable(QueryExecutor executor) {
ProtevusConfigurer connectToCarsTable(QueryExecutor executor) {
return (Protevus app) async {
// Register the connection with Protevus's dependency injection system.
//

View file

@ -45,5 +45,5 @@
## 2.0.0
* Dart2 + Angel2 update.
* Dart2 + Protevus2 update.

View file

@ -283,7 +283,7 @@ class Runner {
await driver.startServer(args.options.hostname, args.options.port);
// Only apply the headers to AngelHttp instance
// Only apply the headers to ProtevusHttp instance
if (driver is ProtevusHttp) {
driver.addResponseHeader(args.options.responseHeaders);
driver.removeResponseHeader(args.options.removeResponseHeaders);

View file

@ -24,7 +24,7 @@
## 6.0.1
* Fixed AngelHttpException error
* Fixed ProtevusHttpException error
## 6.0.0

View file

@ -32,11 +32,11 @@ import 'package:file/local.dart';
void main() async {
var app = Protevus()..lazyParseBodies = true;
var fs = const LocalFileSystem();
var http = AngelHttp(app);
var http = ProtevusHttp(app);
app.responseFinalizers.add(inlineAssets(fs.directory('web')));
app.use(() => throw AngelHttpException.notFound());
app.use(() => throw ProtevusHttpException.notFound());
var server = await http.startServer('127.0.0.1', 3000);
print('Listening at http://${server.address.address}:${server.port}');
@ -56,7 +56,7 @@ import 'package:file/local.dart';
void main() async {
var app = Protevus()..lazyParseBodies = true;
var fs = const LocalFileSystem();
var http = AngelHttp(app);
var http = ProtevusHttp(app);
var vDir = inlineAssets(
VirtualDirectory(
@ -68,7 +68,7 @@ void main() async {
app.use(vDir.handleRequest);
app.use(() => throw AngelHttpException.notFound());
app.use(() => throw ProtevusHttpException.notFound());
var server = await http.startServer('127.0.0.1', 3000);
print('Listening at http://${server.address.address}:${server.port}');

View file

@ -17,7 +17,7 @@
## 6.0.0-beta.2
* Fixed AngelHttpException error
* Fixed ProtevusHttpException error
## 6.0.0-beta.1
@ -47,7 +47,7 @@
## 2.1.0
* `pedantic` lints.
* Add the `AngelShelf` driver class, which allows you to embed Protevus within shelf.
* Add the `ProtevusShelf` driver class, which allows you to embed Protevus within shelf.
## 2.0.0

View file

@ -13,7 +13,7 @@ Shelf interop with Protevus. This package lets you run `package:shelf` handlers
- [Usage](#usage)
- [embedShelf](#embedshelf)
- [Communicating with Protevus with embedShelf](#communicating-with-protevus-with-embedshelf)
- [AngelShelf](#angelshelf)
- [ProtevusShelf](#angelshelf)
## Usage
@ -31,7 +31,7 @@ import 'api/api.dart';
void main() async {
var app = Protevus();
var http = AngelHttp(app);
var http = ProtevusHttp(app);
// Protevus routes on top
await app.mountController<ApiController>();
@ -70,24 +70,24 @@ handleRequest(shelf.Request request) {
}
```
### AngelShelf
### ProtevusShelf
Protevus brought about the generic `Driver` class, which is implemented by `AngelHttp`, `AngelHttp2`, `AngelGopher`, etc., and provides the core infrastructure for request handling in Protevus. `AngelShelf` is an implementation that wraps shelf requests and responses in their Protevus equivalents. Using it is as simple using as using `AngelHttp`, or any other driver:
Protevus brought about the generic `Driver` class, which is implemented by `ProtevusHttp`, `ProtevusHttp2`, `ProtevusGopher`, etc., and provides the core infrastructure for request handling in Protevus. `ProtevusShelf` is an implementation that wraps shelf requests and responses in their Protevus equivalents. Using it is as simple using as using `ProtevusHttp`, or any other driver:
```dart
// Create an AngelShelf driver.
// Create an ProtevusShelf driver.
// If we have startup hooks we want to run, we need to call
// `startServer`. Otherwise, it can be omitted.
// Of course, if you call `startServer`, know that to run
// shutdown/cleanup logic, you need to call `close` eventually,
// too.
var angelShelf = AngelShelf(app);
var angelShelf = ProtevusShelf(app);
await angelShelf.startServer();
await shelf_io.serve(angelShelf.handler, InternetAddress.loopbackIPv4, 8081);
```
You can also use the `AngelShelf` driver as a shelf middleware - just use
You can also use the `ProtevusShelf` driver as a shelf middleware - just use
`angelShelf.middleware` instead of `angelShelf.handler`. When used as a middleware,
if the Protevus response context is still open after all handlers run (i.e. no routes were
matched), the next shelf handler will be called.

View file

@ -40,7 +40,7 @@ void main() async {
app.fallback(vDir.handleRequest);
// Start your server!!!
await AngelHttp(app).startServer();
await ProtevusHttp(app).startServer();
}
```

View file

@ -9,10 +9,10 @@ Easily synchronize and scale WebSockets using [belatuk_pub_sub](<https://pub.dev
## Usage
This package exposes `PubSubSynchronizationChannel`, which can simply be dropped into any `AngelWebSocket` constructor. Once you've set that up, instances of your application will automatically fire events in-sync. That's all you have to do to scale a real-time application with Protevus!
This package exposes `PubSubSynchronizationChannel`, which can simply be dropped into any `ProtevusWebSocket` constructor. Once you've set that up, instances of your application will automatically fire events in-sync. That's all you have to do to scale a real-time application with Protevus!
```dart
await app.configure(AngelWebSocket(
await app.configure(ProtevusWebSocket(
synchronizationChannel: PubSubSynchronizationChannel(
pub_sub.IsolateClient('<client-id>', adapter.receivePort.sendPort),
),

View file

@ -102,4 +102,4 @@
## 1.1.0+1
* Dart 2/strong mode fixes.
* Pass a `useZone` flag to `AngelHttp` through `TestServer`.
* Pass a `useZone` flag to `ProtevusHttp` through `TestServer`.

View file

@ -41,8 +41,8 @@ void test('foo', () async {
void test('error', () async {
var res = await client.get('/error');
expect(res, isAngelHttpException());
expect(res, isAngelHttpException(statusCode: 404, message: ..., errors: [...])) // Optional
expect(res, isProtevusHttpException());
expect(res, isProtevusHttpException(statusCode: 404, message: ..., errors: [...])) // Optional
});
```

View file

@ -93,5 +93,5 @@
## 1.0.4
* `isNonEmptyString` trims strings.
* `ValidationException` extends `AngelHttpException`.
* `ValidationException` extends `ProtevusHttpException`.
* Added `requireField` and `requireFields`.

View file

@ -260,7 +260,7 @@ main() {
`server.dart` exposes seven helper middleware:
- `validate(validator)`: Validates and filters `req.bodyAsMap`, and throws an `AngelHttpException.BadRequest` if data is invalid.
- `validate(validator)`: Validates and filters `req.bodyAsMap`, and throws an `ProtevusHttpException.BadRequest` if data is invalid.
- `validateEvent(validator)`: Sets `e.data` to the result of validation on a service event.
- `validateQuery(validator)`: Same as `validate`, but operates on `req.query`.
- `autoParseBody(fields)`: Auto-parses numbers in `req.bodyAsMap`.

View file

@ -114,7 +114,7 @@ HookedServiceEventListener validateEvent(Validator validator,
};
}
/// Asynchronously apply a [validator], running any [AngelMatcher]s.
/// Asynchronously apply a [validator], running any [ProtevusMatcher]s.
Future<ValidationResult> asyncApplyValidator(
Validator validator, Map data, Protevus app) async {
var result = validator.check(data);
@ -127,8 +127,9 @@ Future<ValidationResult> asyncApplyValidator(
var description = StringDescription("'$key': expected ");
for (var rule in validator.rules[key]!) {
if (rule is AngelMatcher) {
var r = await rule.matchesWithAngel(value, key, result.data, {}, app);
if (rule is ProtevusMatcher) {
var r =
await rule.matchesWithProtevus(value, key, result.data, {}, app);
if (!r) {
errors.add(rule.describe(description).toString().trim());

View file

@ -3,60 +3,61 @@ import 'package:protevus_framework/protevus_framework.dart';
import 'package:matcher/matcher.dart';
import 'context_aware.dart';
/// Returns an [AngelMatcher] that uses an arbitrary function that returns
/// Returns an [ProtevusMatcher] that uses an arbitrary function that returns
/// true or false for the actual value.
///
/// Analogous to the synchronous [predicate] matcher.
AngelMatcher predicateWithAngel(
ProtevusMatcher predicateWithProtevus(
FutureOr<bool> Function(String, Object, Protevus) f,
[String description = 'satisfies function']) =>
_PredicateWithAngel(f, description);
_PredicateWithProtevus(f, description);
/// Returns an [AngelMatcher] that applies an asynchronously-created [Matcher]
/// Returns an [ProtevusMatcher] that applies an asynchronously-created [Matcher]
/// to the input.
///
/// Use this to match values against configuration, injections, etc.
AngelMatcher matchWithAngel(FutureOr<Matcher> Function(Object, Map, Protevus) f,
ProtevusMatcher matchWithProtevus(
FutureOr<Matcher> Function(Object, Map, Protevus) f,
[String description = 'satisfies asynchronously created matcher']) =>
_MatchWithAngel(f, description);
_MatchWithProtevus(f, description);
/// Calls [matchWithAngel] without the initial parameter.
AngelMatcher matchWithAngelBinary(
/// Calls [matchWithProtevus] without the initial parameter.
ProtevusMatcher matchWithProtevusBinary(
FutureOr<Matcher> Function(Map context, Protevus) f,
[String description = 'satisfies asynchronously created matcher']) =>
matchWithAngel((_, context, app) => f(context, app));
matchWithProtevus((_, context, app) => f(context, app));
/// Calls [matchWithAngel] without the initial two parameters.
AngelMatcher matchWithAngelUnary(FutureOr<Matcher> Function(Protevus) f,
/// Calls [matchWithProtevus] without the initial two parameters.
ProtevusMatcher matchWithProtevusUnary(FutureOr<Matcher> Function(Protevus) f,
[String description = 'satisfies asynchronously created matcher']) =>
matchWithAngelBinary((_, app) => f(app));
matchWithProtevusBinary((_, app) => f(app));
/// Calls [matchWithAngel] without any parameters.
AngelMatcher matchWithAngelNullary(FutureOr<Matcher> Function() f,
/// Calls [matchWithProtevus] without any parameters.
ProtevusMatcher matchWithProtevusNullary(FutureOr<Matcher> Function() f,
[String description = 'satisfies asynchronously created matcher']) =>
matchWithAngelUnary((_) => f());
matchWithProtevusUnary((_) => f());
/// Returns an [AngelMatcher] that represents [x].
/// Returns an [ProtevusMatcher] that represents [x].
///
/// If [x] is an [AngelMatcher], then it is returned, unmodified.
AngelMatcher wrapAngelMatcher(x) {
if (x is AngelMatcher) return x;
if (x is ContextAwareMatcher) return _WrappedAngelMatcher(x);
return wrapAngelMatcher(wrapContextAwareMatcher(x));
/// If [x] is an [ProtevusMatcher], then it is returned, unmodified.
ProtevusMatcher wrapProtevusMatcher(x) {
if (x is ProtevusMatcher) return x;
if (x is ContextAwareMatcher) return _WrappedProtevusMatcher(x);
return wrapProtevusMatcher(wrapContextAwareMatcher(x));
}
/// Returns an [AngelMatcher] that asynchronously resolves a [feature], builds a [matcher], and executes it.
AngelMatcher matchAsync(FutureOr<Matcher> Function(String, Object) matcher,
/// Returns an [ProtevusMatcher] that asynchronously resolves a [feature], builds a [matcher], and executes it.
ProtevusMatcher matchAsync(FutureOr<Matcher> Function(String, Object) matcher,
FutureOr Function() feature,
[String description = 'satisfies asynchronously created matcher']) {
return _MatchAsync(matcher, feature, description);
}
/// Returns an [AngelMatcher] that verifies that an item with the given [idField]
/// Returns an [ProtevusMatcher] that verifies that an item with the given [idField]
/// exists in the service at [servicePath], without throwing a `404` or returning `null`.
AngelMatcher idExistsInService(String servicePath,
ProtevusMatcher idExistsInService(String servicePath,
{String idField = 'id', String? description}) {
return predicateWithAngel(
return predicateWithProtevus(
(key, item, app) async {
try {
var result = await app.findService(servicePath)?.read(item);
@ -74,8 +75,8 @@ AngelMatcher idExistsInService(String servicePath,
}
/// An asynchronous [Matcher] that runs in the context of an [Protevus] app.
abstract class AngelMatcher extends ContextAwareMatcher {
Future<bool> matchesWithAngel(
abstract class ProtevusMatcher extends ContextAwareMatcher {
Future<bool> matchesWithProtevus(
item, String key, Map context, Map matchState, Protevus app);
@override
@ -84,34 +85,34 @@ abstract class AngelMatcher extends ContextAwareMatcher {
}
}
class _WrappedAngelMatcher extends AngelMatcher {
class _WrappedProtevusMatcher extends ProtevusMatcher {
final ContextAwareMatcher matcher;
_WrappedAngelMatcher(this.matcher);
_WrappedProtevusMatcher(this.matcher);
@override
Description describe(Description description) =>
matcher.describe(description);
@override
Future<bool> matchesWithAngel(
Future<bool> matchesWithProtevus(
item, String key, Map context, Map matchState, Protevus app) async {
return matcher.matchesWithContext(item, key, context, matchState);
}
}
class _MatchWithAngel extends AngelMatcher {
class _MatchWithProtevus extends ProtevusMatcher {
final FutureOr<Matcher> Function(Object, Map, Protevus) f;
final String description;
_MatchWithAngel(this.f, this.description);
_MatchWithProtevus(this.f, this.description);
@override
Description describe(Description description) =>
description.add(this.description);
@override
Future<bool> matchesWithAngel(
Future<bool> matchesWithProtevus(
item, String key, Map context, Map matchState, Protevus app) {
return Future.sync(() => f(item as Object, context, app)).then((result) {
return result.matches(item, matchState);
@ -119,24 +120,24 @@ class _MatchWithAngel extends AngelMatcher {
}
}
class _PredicateWithAngel extends AngelMatcher {
class _PredicateWithProtevus extends ProtevusMatcher {
final FutureOr<bool> Function(String, Object, Protevus) predicate;
final String description;
_PredicateWithAngel(this.predicate, this.description);
_PredicateWithProtevus(this.predicate, this.description);
@override
Description describe(Description description) =>
description.add(this.description);
@override
Future<bool> matchesWithAngel(
Future<bool> matchesWithProtevus(
item, String key, Map context, Map matchState, Protevus app) {
return Future<bool>.sync(() => predicate(key, item as Object, app));
}
}
class _MatchAsync extends AngelMatcher {
class _MatchAsync extends ProtevusMatcher {
final FutureOr<Matcher> Function(String, Object) matcher;
final FutureOr Function() feature;
final String description;
@ -148,11 +149,11 @@ class _MatchAsync extends AngelMatcher {
description.add(this.description);
@override
Future<bool> matchesWithAngel(
Future<bool> matchesWithProtevus(
item, String key, Map context, Map matchState, Protevus app) async {
var f = await feature();
var m = await matcher(key, f as Object);
var c = wrapAngelMatcher(m);
return await c.matchesWithAngel(item, key, context, matchState, app);
var c = wrapProtevusMatcher(m);
return await c.matchesWithProtevus(item, key, context, matchState, app);
}
}

View file

@ -39,7 +39,7 @@
## 4.1.1
* Fixed issue with type casting
* Changed `app` parameter of `AngelWebSocket` to non-nullable
* Changed `app` parameter of `ProtevusWebSocket` to non-nullable
## 4.1.0
@ -124,7 +124,7 @@
* Dart 2 updates.
* Added `handleClient`, which is nice for external implementations
that plug into `AngelWebSocket`.
that plug into `ProtevusWebSocket`.
## 1.1.1

View file

@ -5,7 +5,7 @@
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
[![License](https://img.shields.io/github/license/dart-backend/protevus)](https://github.com/dart-backend/protevus/tree/master/packages/websocket/LICENSE)
WebSocket plugin for Protevus framework. This plugin broadcasts events from hooked services via WebSockets. In addition, it adds itself to the app's IoC container as `AngelWebSocket`, so that it can be used in controllers as well.
WebSocket plugin for Protevus framework. This plugin broadcasts events from hooked services via WebSockets. In addition, it adds itself to the app's IoC container as `ProtevusWebSocket`, so that it can be used in controllers as well.
WebSocket contexts are add to `req.properties` as `'socket'`.
@ -20,7 +20,7 @@ import "package:protevus_websocket/server.dart";
void main() async {
var app = Protevus();
var ws = AngelWebSocket();
var ws = ProtevusWebSocket();
// This is a plug-in. It hooks all your services,
// to automatically broadcast events.
@ -56,7 +56,7 @@ import "package:protevus_websocket/server.dart";
@Expose("/")
class MyController extends WebSocketController {
// A reference to the WebSocket plug-in is required.
MyController(AngelWebSocket ws):super(ws);
MyController(ProtevusWebSocket ws):super(ws);
@override
void onConnect(WebSocketContext socket) {

View file

@ -274,7 +274,7 @@ class ProtevusWebSocket {
action.params['query'] is Map &&
action.params['query']['jwt'] is String) {
try {
var auth = socket.request.container!.make<AngelAuth>();
var auth = socket.request.container!.make<ProtevusAuth>();
var jwt = action.params['query']['jwt'] as String;
AuthToken token;

View file

@ -18,7 +18,7 @@ void main() {
setUp(() async {
app = Protevus();
http = ProtevusHttp(app, useZone: false);
var auth = AngelAuth(
var auth = ProtevusAuth(
serializer: (_) async => 'baz', deserializer: (_) async => user);
auth.strategies['local'] = LocalAuthStrategy(