Refactor: changing namespace, imports, re-branding
This commit is contained in:
parent
b71744869d
commit
3865bd41df
307 changed files with 1137 additions and 1129 deletions
12
TODO.md
12
TODO.md
|
@ -1,12 +0,0 @@
|
||||||
# Development Blueprint
|
|
||||||
|
|
||||||
## Short Term Goal
|
|
||||||
|
|
||||||
* Update examples
|
|
||||||
* Update User Guide
|
|
||||||
|
|
||||||
## Long Term Goal
|
|
||||||
|
|
||||||
* Refactor Angel3 architecture for performance and security
|
|
||||||
* Improve ORM features
|
|
||||||
* Improve HTTP performance
|
|
|
@ -1,11 +1,11 @@
|
||||||
# Angel3 Anthentication
|
# Protevus Anthentication
|
||||||
|
|
||||||
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_auth?include_prereleases)
|
![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)
|
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
||||||
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
||||||
[![License](https://img.shields.io/github/license/dart-backend/angel)](https://github.com/dart-backend/angel/tree/master/packages/auth/LICENSE)
|
[![License](https://img.shields.io/github/license/dart-backend/protevus)](https://github.com/dart-backend/protevus/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).
|
A complete authentication plugin for Protevus. Inspired by Passport. More details in the [User Guide](https://angel3-docs.dukefirehawk.com/guides/authentication).
|
||||||
|
|
||||||
## Bundled Strategies
|
## Bundled Strategies
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import 'package:angel3_framework/angel3_framework.dart';
|
||||||
import 'package:angel3_framework/http.dart';
|
import 'package:angel3_framework/http.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
var app = Angel();
|
var app = Protevus();
|
||||||
var auth = AngelAuth<User>(
|
var auth = AngelAuth<User>(
|
||||||
serializer: (user) => user.id ?? '',
|
serializer: (user) => user.id ?? '',
|
||||||
deserializer: (id) => fetchAUserByIdSomehow(id));
|
deserializer: (id) => fetchAUserByIdSomehow(id));
|
||||||
|
@ -22,7 +22,7 @@ void main() async {
|
||||||
|
|
||||||
app.post('/auth/local', auth.authenticate('local'));
|
app.post('/auth/local', auth.authenticate('local'));
|
||||||
|
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
await http.startServer('127.0.0.1', 3000);
|
await http.startServer('127.0.0.1', 3000);
|
||||||
|
|
||||||
print('Listening at http://127.0.0.1:3000');
|
print('Listening at http://127.0.0.1:3000');
|
||||||
|
|
|
@ -36,8 +36,8 @@ class User extends Model {
|
||||||
void main() async {
|
void main() async {
|
||||||
hierarchicalLoggingEnabled = true;
|
hierarchicalLoggingEnabled = true;
|
||||||
|
|
||||||
Angel app = Angel(reflector: MirrorsReflector());
|
Protevus app = Protevus(reflector: MirrorsReflector());
|
||||||
AngelHttp angelHttp = AngelHttp(app);
|
ProtevusHttp angelHttp = ProtevusHttp(app);
|
||||||
app.use('/users', MapService());
|
app.use('/users', MapService());
|
||||||
|
|
||||||
var oldErrorHandler = app.errorHandler;
|
var oldErrorHandler = app.errorHandler;
|
||||||
|
|
|
@ -23,7 +23,7 @@ Future<Map<String, String>> verifier(String? username, String? password) async {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future wireAuth(Angel app) async {
|
Future wireAuth(Protevus app) async {
|
||||||
//auth.strategies['local'] = LocalAuthStrategy(verifier);
|
//auth.strategies['local'] = LocalAuthStrategy(verifier);
|
||||||
auth.strategies['local'] =
|
auth.strategies['local'] =
|
||||||
LocalAuthStrategy(verifier, forceBasic: true, realm: 'test');
|
LocalAuthStrategy(verifier, forceBasic: true, realm: 'test');
|
||||||
|
@ -34,8 +34,8 @@ Future wireAuth(Angel app) async {
|
||||||
* Backend for local test cases
|
* Backend for local test cases
|
||||||
*/
|
*/
|
||||||
void main() async {
|
void main() async {
|
||||||
Angel app = Angel(reflector: MirrorsReflector());
|
Protevus app = Protevus(reflector: MirrorsReflector());
|
||||||
AngelHttp angelHttp = AngelHttp(app, useZone: false);
|
ProtevusHttp angelHttp = ProtevusHttp(app, useZone: false);
|
||||||
await app.configure(wireAuth);
|
await app.configure(wireAuth);
|
||||||
|
|
||||||
app.get('/hello', (req, res) {
|
app.get('/hello', (req, res) {
|
||||||
|
|
|
@ -68,7 +68,7 @@ class AuthToken {
|
||||||
|
|
||||||
if (split.length != 3) {
|
if (split.length != 3) {
|
||||||
_log.warning('Invalid JWT');
|
_log.warning('Invalid JWT');
|
||||||
throw AngelHttpException.notAuthenticated(message: 'Invalid JWT.');
|
throw ProtevusHttpException.notAuthenticated(message: 'Invalid JWT.');
|
||||||
}
|
}
|
||||||
|
|
||||||
var payloadString = decodeBase64(split[1]);
|
var payloadString = decodeBase64(split[1]);
|
||||||
|
@ -81,7 +81,7 @@ class AuthToken {
|
||||||
|
|
||||||
if (split.length != 3) {
|
if (split.length != 3) {
|
||||||
_log.warning('Invalid JWT');
|
_log.warning('Invalid JWT');
|
||||||
throw AngelHttpException.notAuthenticated(message: 'Invalid JWT.');
|
throw ProtevusHttpException.notAuthenticated(message: 'Invalid JWT.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// var headerString = decodeBase64(split[0]);
|
// var headerString = decodeBase64(split[0]);
|
||||||
|
@ -91,7 +91,7 @@ class AuthToken {
|
||||||
|
|
||||||
if (signature != split[2]) {
|
if (signature != split[2]) {
|
||||||
_log.warning('JWT payload does not match hashed version');
|
_log.warning('JWT payload does not match hashed version');
|
||||||
throw AngelHttpException.notAuthenticated(
|
throw ProtevusHttpException.notAuthenticated(
|
||||||
message: 'JWT payload does not match hashed version.');
|
message: 'JWT payload does not match hashed version.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ RequestHandler forceBasicAuth<User>({String? realm}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
res.headers['www-authenticate'] = 'Basic realm="${realm ?? 'angel_auth'}"';
|
res.headers['www-authenticate'] = 'Basic realm="${realm ?? 'angel_auth'}"';
|
||||||
throw AngelHttpException.notAuthenticated();
|
throw ProtevusHttpException.notAuthenticated();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ RequestHandler requireAuthentication<User>() {
|
||||||
bool reject(ResponseContext res) {
|
bool reject(ResponseContext res) {
|
||||||
if (throwError) {
|
if (throwError) {
|
||||||
res.statusCode = 403;
|
res.statusCode = 403;
|
||||||
throw AngelHttpException.forbidden();
|
throw ProtevusHttpException.forbidden();
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ class AngelAuth<User> {
|
||||||
|
|
||||||
/// Configures an Angel server to decode and validate JSON Web tokens on demand,
|
/// Configures an Angel server to decode and validate JSON Web tokens on demand,
|
||||||
/// whenever an instance of [User] is injected.
|
/// whenever an instance of [User] is injected.
|
||||||
Future<void> configureServer(Angel app) async {
|
Future<void> configureServer(Protevus app) async {
|
||||||
/*
|
/*
|
||||||
if (serializer == null) {
|
if (serializer == null) {
|
||||||
throw StateError(
|
throw StateError(
|
||||||
|
@ -109,7 +109,7 @@ class AngelAuth<User> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (app.container == null) {
|
if (app.container == null) {
|
||||||
_log.severe('Angel3 container is null');
|
_log.severe('Protevus container is null');
|
||||||
throw StateError(
|
throw StateError(
|
||||||
'Angel.container is null. All authentication will fail.');
|
'Angel.container is null. All authentication will fail.');
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ class AngelAuth<User> {
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
_log.warning('JWT is null');
|
_log.warning('JWT is null');
|
||||||
throw AngelHttpException.forbidden();
|
throw ProtevusHttpException.forbidden();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ class AngelAuth<User> {
|
||||||
if (enforceIp) {
|
if (enforceIp) {
|
||||||
if (req.ip != token.ipAddress) {
|
if (req.ip != token.ipAddress) {
|
||||||
_log.warning('JWT cannot be accessed from this IP address');
|
_log.warning('JWT cannot be accessed from this IP address');
|
||||||
throw AngelHttpException.forbidden(
|
throw ProtevusHttpException.forbidden(
|
||||||
message: 'JWT cannot be accessed from this IP address.');
|
message: 'JWT cannot be accessed from this IP address.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ class AngelAuth<User> {
|
||||||
|
|
||||||
if (!expiry.isAfter(DateTime.now())) {
|
if (!expiry.isAfter(DateTime.now())) {
|
||||||
_log.warning('Expired JWT');
|
_log.warning('Expired JWT');
|
||||||
throw AngelHttpException.forbidden(message: 'Expired JWT.');
|
throw ProtevusHttpException.forbidden(message: 'Expired JWT.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,13 +308,13 @@ class AngelAuth<User> {
|
||||||
|
|
||||||
if (jwt == null) {
|
if (jwt == null) {
|
||||||
_log.warning('No JWT provided');
|
_log.warning('No JWT provided');
|
||||||
throw AngelHttpException.forbidden(message: 'No JWT provided');
|
throw ProtevusHttpException.forbidden(message: 'No JWT provided');
|
||||||
} else {
|
} else {
|
||||||
var token = AuthToken.validate(jwt, _hs256);
|
var token = AuthToken.validate(jwt, _hs256);
|
||||||
if (enforceIp) {
|
if (enforceIp) {
|
||||||
if (req.ip != token.ipAddress) {
|
if (req.ip != token.ipAddress) {
|
||||||
_log.warning('WT cannot be accessed from this IP address');
|
_log.warning('WT cannot be accessed from this IP address');
|
||||||
throw AngelHttpException.forbidden(
|
throw ProtevusHttpException.forbidden(
|
||||||
message: 'JWT cannot be accessed from this IP address.');
|
message: 'JWT cannot be accessed from this IP address.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -339,11 +339,11 @@ class AngelAuth<User> {
|
||||||
return {'data': data, 'token': token.serialize(_hs256)};
|
return {'data': data, 'token': token.serialize(_hs256)};
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e is AngelHttpException) {
|
if (e is ProtevusHttpException) {
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
_log.warning('Malformed JWT');
|
_log.warning('Malformed JWT');
|
||||||
throw AngelHttpException.badRequest(message: 'Malformed JWT');
|
throw ProtevusHttpException.badRequest(message: 'Malformed JWT');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,7 +452,7 @@ class AngelAuth<User> {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
_log.warning('Not authenticated');
|
_log.warning('Not authenticated');
|
||||||
throw AngelHttpException.notAuthenticated();
|
throw ProtevusHttpException.notAuthenticated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ class LocalAuthStrategy<User> extends AuthStrategy<User> {
|
||||||
await verifier(usrPassMatch.group(1), usrPassMatch.group(2));
|
await verifier(usrPassMatch.group(1), usrPassMatch.group(2));
|
||||||
} else {
|
} else {
|
||||||
_log.warning('Bad request: $invalidMessage');
|
_log.warning('Bad request: $invalidMessage');
|
||||||
throw AngelHttpException.badRequest(errors: [invalidMessage]);
|
throw ProtevusHttpException.badRequest(errors: [invalidMessage]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verificationResult == null) {
|
if (verificationResult == null) {
|
||||||
|
@ -108,7 +108,7 @@ class LocalAuthStrategy<User> extends AuthStrategy<User> {
|
||||||
}
|
}
|
||||||
|
|
||||||
_log.info('Not authenticated');
|
_log.info('Not authenticated');
|
||||||
throw AngelHttpException.notAuthenticated();
|
throw ProtevusHttpException.notAuthenticated();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (verificationResult is Map && verificationResult.isEmpty) {
|
if (verificationResult is Map && verificationResult.isEmpty) {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
name: angel3_auth
|
name: angel3_auth
|
||||||
description: A complete authentication plugin for Angel3. Includes support for stateless JWT tokens, Basic Auth, and more.
|
description: A complete authentication plugin for Protevus. Includes support for stateless JWT tokens, Basic Auth, and more.
|
||||||
version: 8.2.0
|
version: 8.2.0
|
||||||
homepage: https://angel3-framework.web.app/
|
homepage: https://angel3-framework.web.app/
|
||||||
repository: https://github.com/dart-backend/angel/tree/master/packages/auth
|
repository: https://github.com/dart-backend/protevus/tree/master/packages/auth
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.3.0 <4.0.0'
|
sdk: '>=3.3.0 <4.0.0'
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
|
@ -35,8 +35,8 @@ class User extends Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late Angel app;
|
late Protevus app;
|
||||||
late AngelHttp angelHttp;
|
late ProtevusHttp angelHttp;
|
||||||
AngelAuth<User> auth;
|
AngelAuth<User> auth;
|
||||||
http.Client? client;
|
http.Client? client;
|
||||||
HttpServer server;
|
HttpServer server;
|
||||||
|
@ -45,8 +45,8 @@ void main() {
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
hierarchicalLoggingEnabled = true;
|
hierarchicalLoggingEnabled = true;
|
||||||
app = Angel(reflector: MirrorsReflector());
|
app = Protevus(reflector: MirrorsReflector());
|
||||||
angelHttp = AngelHttp(app);
|
angelHttp = ProtevusHttp(app);
|
||||||
app.use('/users', MapService());
|
app.use('/users', MapService());
|
||||||
|
|
||||||
var oldErrorHandler = app.errorHandler;
|
var oldErrorHandler = app.errorHandler;
|
||||||
|
|
|
@ -26,7 +26,7 @@ Future<Map<String, String>> verifier(String? username, String? password) async {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future wireAuth(Angel app) async {
|
Future wireAuth(Protevus app) async {
|
||||||
//auth.serializer = (user) async => 1337;
|
//auth.serializer = (user) async => 1337;
|
||||||
//auth.deserializer = (id) async => sampleUser;
|
//auth.deserializer = (id) async => sampleUser;
|
||||||
|
|
||||||
|
@ -35,16 +35,16 @@ Future wireAuth(Angel app) async {
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
Angel app;
|
Protevus app;
|
||||||
late AngelHttp angelHttp;
|
late ProtevusHttp angelHttp;
|
||||||
late http.Client client;
|
late http.Client client;
|
||||||
String? url;
|
String? url;
|
||||||
String? basicAuthUrl;
|
String? basicAuthUrl;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
client = http.Client();
|
client = http.Client();
|
||||||
app = Angel(reflector: MirrorsReflector());
|
app = Protevus(reflector: MirrorsReflector());
|
||||||
angelHttp = AngelHttp(app, useZone: false);
|
angelHttp = ProtevusHttp(app, useZone: false);
|
||||||
await app.configure(wireAuth);
|
await app.configure(wireAuth);
|
||||||
|
|
||||||
app.get('/hello', (req, res) {
|
app.get('/hello', (req, res) {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
# Angel3 OAuth2 Handler
|
# Protevus OAuth2 Handler
|
||||||
|
|
||||||
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_auth_oauth2?include_prereleases)
|
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_auth_oauth2?include_prereleases)
|
||||||
![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)(<https://dart.dev/null-safety>)
|
![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)(<https://dart.dev/null-safety>)
|
||||||
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
||||||
[![License](https://img.shields.io/github/license/dart-backend/angel)](https://github.com/dart-backend/angel/tree/master/packages/auth_oauth2/LICENSE)
|
[![License](https://img.shields.io/github/license/dart-backend/protevus)](https://github.com/dart-backend/protevus/tree/master/packages/auth_oauth2/LICENSE)
|
||||||
|
|
||||||
Angel3 library for authenticating users with remote identity providers via OAuth2, i.e. Facebook, Google, Azure AD, etc.
|
Protevus library for authenticating users with remote identity providers via OAuth2, i.e. Facebook, Google, Azure AD, etc.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,9 @@ Map<String, dynamic> parseParamsFromGithub(MediaType contentType, String body) {
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
// Create the server instance.
|
// Create the server instance.
|
||||||
var app = Angel();
|
var app = Protevus();
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
app.logger = Logger('angel')
|
app.logger = Logger('protevus')
|
||||||
..onRecord.listen((rec) {
|
..onRecord.listen((rec) {
|
||||||
print(rec);
|
print(rec);
|
||||||
if (rec.error != null) print(rec.error);
|
if (rec.error != null) print(rec.error);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
name: angel3_auth_oauth2
|
name: angel3_auth_oauth2
|
||||||
version: 8.2.0
|
version: 8.2.0
|
||||||
description: Angel3 library for authenticating users with external identity providers via OAuth2.
|
description: Protevus library for authenticating users with external identity providers via OAuth2.
|
||||||
homepage: https://angel3-framework.web.app/
|
homepage: https://angel3-framework.web.app/
|
||||||
repository: https://github.com/dart-backend/angel/tree/master/packages/auth_oauth2
|
repository: https://github.com/dart-backend/protevus/tree/master/packages/auth_oauth2
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.3.0 <4.0.0'
|
sdk: '>=3.3.0 <4.0.0'
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
# Angel3 Twitter OAuth1
|
# Protevus Twitter OAuth1
|
||||||
|
|
||||||
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_auth_twitter?include_prereleases)
|
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_auth_twitter?include_prereleases)
|
||||||
![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](<https://dart.dev/null-safety>)
|
![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](<https://dart.dev/null-safety>)
|
||||||
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
||||||
[![License](https://img.shields.io/github/license/dart-backend/angel)](https://github.com/dart-backend/angel/tree/master/packages/auth_twitter/LICENSE)
|
[![License](https://img.shields.io/github/license/dart-backend/protevus)](https://github.com/dart-backend/protevus/tree/master/packages/auth_twitter/LICENSE)
|
||||||
|
|
||||||
**Not ready for release**
|
**Not ready for release**
|
||||||
Angel3 authentication strategy using Twitter OAuth 1.0a.
|
Protevus authentication strategy using Twitter OAuth 1.0a.
|
||||||
|
|
||||||
See the [example](example/example.dart);
|
See the [example](example/example.dart);
|
||||||
|
|
|
@ -15,8 +15,8 @@ class _User {
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
var app = Angel();
|
var app = Protevus();
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
var auth = AngelAuth<_User>(
|
var auth = AngelAuth<_User>(
|
||||||
jwtKey: 'AUTH_TWITTER_SECRET',
|
jwtKey: 'AUTH_TWITTER_SECRET',
|
||||||
allowCookie: false,
|
allowCookie: false,
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
name: "angel3_auth_twitter"
|
name: "angel3_auth_twitter"
|
||||||
description: Angel3 authentication strategy for Twitter login. Auto-signs requests.
|
description: Protevus authentication strategy for Twitter login. Auto-signs requests.
|
||||||
version: 8.0.0
|
version: 8.0.0
|
||||||
homepage: https://angel3-framework.web.app/
|
homepage: https://angel3-framework.web.app/
|
||||||
repository: https://github.com/dart-backend/angel/tree/master/packages/auth_twitter
|
repository: https://github.com/dart-backend/protevus/tree/master/packages/auth_twitter
|
||||||
publish_to: none
|
publish_to: none
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=3.3.0 <4.0.0"
|
sdk: ">=3.3.0 <4.0.0"
|
||||||
|
|
8
packages/cache/README.md
vendored
8
packages/cache/README.md
vendored
|
@ -1,11 +1,11 @@
|
||||||
# Angel3 HTTP Cache
|
# Protevus HTTP Cache
|
||||||
|
|
||||||
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_cache?include_prereleases)
|
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_cache?include_prereleases)
|
||||||
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
||||||
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
||||||
[![License](https://img.shields.io/github/license/dart-backend/angel)](https://github.com/dart-backend/angel/tree/master/packages/cache/LICENSE)
|
[![License](https://img.shields.io/github/license/dart-backend/protevus)](https://github.com/dart-backend/protevus/tree/master/packages/cache/LICENSE)
|
||||||
|
|
||||||
A service that provides HTTP caching to the response data for [Angel3 framework](https://pub.dev/packages/angel3).
|
A service that provides HTTP caching to the response data for [Protevus framework](https://pub.dev/packages/angel3).
|
||||||
|
|
||||||
## `CacheService`
|
## `CacheService`
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ void main() async {
|
||||||
|
|
||||||
## `ResponseCache`
|
## `ResponseCache`
|
||||||
|
|
||||||
A flexible response cache for Angel3.
|
A flexible response cache for Protevus.
|
||||||
|
|
||||||
Use this to improve real and perceived response of Web applications, as well as to memorize expensive responses.
|
Use this to improve real and perceived response of Web applications, as well as to memorize expensive responses.
|
||||||
|
|
||||||
|
|
4
packages/cache/example/cache_service.dart
vendored
4
packages/cache/example/cache_service.dart
vendored
|
@ -3,7 +3,7 @@ import 'package:angel3_framework/angel3_framework.dart';
|
||||||
import 'package:angel3_framework/http.dart';
|
import 'package:angel3_framework/http.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
var app = Angel();
|
var app = Protevus();
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
'/api/todos',
|
'/api/todos',
|
||||||
|
@ -18,7 +18,7 @@ void main() async {
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
var server = await http.startServer('127.0.0.1', 3000);
|
var server = await http.startServer('127.0.0.1', 3000);
|
||||||
print('Listening at http://${server.address.address}:${server.port}');
|
print('Listening at http://${server.address.address}:${server.port}');
|
||||||
}
|
}
|
||||||
|
|
6
packages/cache/example/main.dart
vendored
6
packages/cache/example/main.dart
vendored
|
@ -3,7 +3,7 @@ import 'package:angel3_framework/angel3_framework.dart';
|
||||||
import 'package:angel3_framework/http.dart';
|
import 'package:angel3_framework/http.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
var app = Angel();
|
var app = Protevus();
|
||||||
|
|
||||||
// Cache a glob
|
// Cache a glob
|
||||||
var cache = ResponseCache()
|
var cache = ResponseCache()
|
||||||
|
@ -21,7 +21,7 @@ void main() async {
|
||||||
// Support purging the cache.
|
// Support purging the cache.
|
||||||
app.addRoute('PURGE', '*', (req, res) {
|
app.addRoute('PURGE', '*', (req, res) {
|
||||||
if (req.ip != '127.0.0.1') {
|
if (req.ip != '127.0.0.1') {
|
||||||
throw AngelHttpException.forbidden();
|
throw ProtevusHttpException.forbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
cache.purge(req.uri!.path);
|
cache.purge(req.uri!.path);
|
||||||
|
@ -31,7 +31,7 @@ void main() async {
|
||||||
// The response finalizer that actually saves the content
|
// The response finalizer that actually saves the content
|
||||||
app.responseFinalizers.add(cache.responseFinalizer);
|
app.responseFinalizers.add(cache.responseFinalizer);
|
||||||
|
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
var server = await http.startServer('127.0.0.1', 3000);
|
var server = await http.startServer('127.0.0.1', 3000);
|
||||||
print('Listening at http://${server.address.address}:${server.port}');
|
print('Listening at http://${server.address.address}:${server.port}');
|
||||||
}
|
}
|
||||||
|
|
4
packages/cache/pubspec.yaml
vendored
4
packages/cache/pubspec.yaml
vendored
|
@ -1,8 +1,8 @@
|
||||||
name: angel3_cache
|
name: angel3_cache
|
||||||
version: 8.2.0
|
version: 8.2.0
|
||||||
description: A service that provides HTTP caching to the response data for Angel3
|
description: A service that provides HTTP caching to the response data for Protevus
|
||||||
homepage: https://angel3-framework.web.app/
|
homepage: https://angel3-framework.web.app/
|
||||||
repository: https://github.com/dart-backend/angel/tree/master/packages/cache
|
repository: https://github.com/dart-backend/protevus/tree/master/packages/cache
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.4.0 <4.0.0'
|
sdk: '>=3.4.0 <4.0.0'
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
2
packages/cache/test/cache_test.dart
vendored
2
packages/cache/test/cache_test.dart
vendored
|
@ -21,7 +21,7 @@ Future<void> main() async {
|
||||||
late http.Response response1, response2;
|
late http.Response response1, response2;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
var app = Angel();
|
var app = Protevus();
|
||||||
var cache = ResponseCache()
|
var cache = ResponseCache()
|
||||||
..patterns.addAll([
|
..patterns.addAll([
|
||||||
//Glob('/*.txt'), // Requires to create folders and files for testing
|
//Glob('/*.txt'), // Requires to create folders and files for testing
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
# Angel3 Client
|
# Protevus Client
|
||||||
|
|
||||||
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_client?include_prereleases)
|
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_client?include_prereleases)
|
||||||
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
||||||
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
||||||
[![License](https://img.shields.io/github/license/dart-backend/angel)](https://github.com/dart-backend/angel/tree/master/packages/client/LICENSE)
|
[![License](https://img.shields.io/github/license/dart-backend/protevus)](https://github.com/dart-backend/protevus/tree/master/packages/client/LICENSE)
|
||||||
|
|
||||||
A browser, mobile and command line based client that supports querying Angel3 backend.
|
A browser, mobile and command line based client that supports querying Protevus backend.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:angel3_client/io.dart' as c;
|
import 'package:angel3_client/io.dart' as c;
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
c.Angel client = c.Rest('http://localhost:3000');
|
c.Protevus client = c.Rest('http://localhost:3000');
|
||||||
|
|
||||||
const Map<String, String> user = {'username': 'foo', 'password': 'bar'};
|
const Map<String, String> user = {'username': 'foo', 'password': 'bar'};
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,8 @@ void main() async {
|
||||||
var localOpts =
|
var localOpts =
|
||||||
AngelAuthOptions<Map<String, String>>(canRespondWithJson: true);
|
AngelAuthOptions<Map<String, String>>(canRespondWithJson: true);
|
||||||
|
|
||||||
Angel app = Angel();
|
Protevus app = Protevus();
|
||||||
AngelHttp http = AngelHttp(app, useZone: false);
|
ProtevusHttp http = ProtevusHttp(app, useZone: false);
|
||||||
var auth = AngelAuth(
|
var auth = AngelAuth(
|
||||||
serializer: (_) async => 'baz', deserializer: (_) async => user);
|
serializer: (_) async => 'baz', deserializer: (_) async => user);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:angel3_client/angel3_client.dart';
|
import 'package:angel3_client/angel3_client.dart';
|
||||||
|
|
||||||
Future doSomething(Angel app) async {
|
Future doSomething(Protevus app) async {
|
||||||
var userService = app
|
var userService = app
|
||||||
.service<String, Map<String, dynamic>>('api/users')
|
.service<String, Map<String, dynamic>>('api/users')
|
||||||
.map(User.fromMap, User.toMap);
|
.map(User.fromMap, User.toMap);
|
||||||
|
|
|
@ -8,17 +8,17 @@ import 'package:http/http.dart' as http;
|
||||||
//import 'package:logging/logging.dart';
|
//import 'package:logging/logging.dart';
|
||||||
export 'package:angel3_http_exception/angel3_http_exception.dart';
|
export 'package:angel3_http_exception/angel3_http_exception.dart';
|
||||||
|
|
||||||
/// A function that configures an [Angel] client in some way.
|
/// A function that configures an [Protevus] client in some way.
|
||||||
typedef AngelConfigurer = FutureOr<void> Function(Angel app);
|
typedef ProtevusConfigurer = FutureOr<void> Function(Protevus app);
|
||||||
|
|
||||||
/// A function that deserializes data received from the server.
|
/// A function that deserializes data received from the server.
|
||||||
///
|
///
|
||||||
/// This is only really necessary in the browser, where `json_god`
|
/// This is only really necessary in the browser, where `json_god`
|
||||||
/// doesn't work.
|
/// doesn't work.
|
||||||
typedef AngelDeserializer<T> = T? Function(dynamic x);
|
typedef ProtevusDeserializer<T> = T? Function(dynamic x);
|
||||||
|
|
||||||
/// Represents an Angel server that we are querying.
|
/// Represents an Angel server that we are querying.
|
||||||
abstract class Angel extends http.BaseClient {
|
abstract class Protevus extends http.BaseClient {
|
||||||
//final _log = Logger('Angel');
|
//final _log = Logger('Angel');
|
||||||
|
|
||||||
/// A mutable member. When this is set, it holds a JSON Web Token
|
/// A mutable member. When this is set, it holds a JSON Web Token
|
||||||
|
@ -30,11 +30,11 @@ abstract class Angel extends http.BaseClient {
|
||||||
/// The root URL at which the target server.
|
/// The root URL at which the target server.
|
||||||
final Uri baseUrl;
|
final Uri baseUrl;
|
||||||
|
|
||||||
Angel(baseUrl)
|
Protevus(baseUrl)
|
||||||
: baseUrl = baseUrl is Uri ? baseUrl : Uri.parse(baseUrl.toString());
|
: baseUrl = baseUrl is Uri ? baseUrl : Uri.parse(baseUrl.toString());
|
||||||
|
|
||||||
/// Fired whenever a WebSocket is successfully authenticated.
|
/// Fired whenever a WebSocket is successfully authenticated.
|
||||||
Stream<AngelAuthResult> get onAuthenticated;
|
Stream<ProtevusAuthResult> get onAuthenticated;
|
||||||
|
|
||||||
/// Authenticates against the server.
|
/// Authenticates against the server.
|
||||||
///
|
///
|
||||||
|
@ -43,11 +43,11 @@ abstract class Angel extends http.BaseClient {
|
||||||
/// The [type] is appended to the [authEndpoint], ex. `local` becomes `/auth/local`.
|
/// The [type] is appended to the [authEndpoint], ex. `local` becomes `/auth/local`.
|
||||||
///
|
///
|
||||||
/// The given [credentials] are sent to server as-is; the request body is sent as JSON.
|
/// The given [credentials] are sent to server as-is; the request body is sent as JSON.
|
||||||
Future<AngelAuthResult> authenticate(
|
Future<ProtevusAuthResult> authenticate(
|
||||||
{required String type, credentials, String authEndpoint = '/auth'});
|
{required String type, credentials, String authEndpoint = '/auth'});
|
||||||
|
|
||||||
/// Shorthand for authenticating via a JWT string.
|
/// Shorthand for authenticating via a JWT string.
|
||||||
Future<AngelAuthResult> reviveJwt(String token,
|
Future<ProtevusAuthResult> reviveJwt(String token,
|
||||||
{String authEndpoint = '/auth'}) {
|
{String authEndpoint = '/auth'}) {
|
||||||
return authenticate(
|
return authenticate(
|
||||||
type: 'token',
|
type: 'token',
|
||||||
|
@ -62,8 +62,8 @@ abstract class Angel extends http.BaseClient {
|
||||||
@override
|
@override
|
||||||
Future<void> close();
|
Future<void> close();
|
||||||
|
|
||||||
/// Applies an [AngelConfigurer] to this instance.
|
/// Applies an [ProtevusConfigurer] to this instance.
|
||||||
Future<void> configure(AngelConfigurer configurer) async {
|
Future<void> configure(ProtevusConfigurer configurer) async {
|
||||||
await configurer(this);
|
await configurer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ abstract class Angel extends http.BaseClient {
|
||||||
/// You can pass a custom [deserializer], which is typically necessary in cases where
|
/// You can pass a custom [deserializer], which is typically necessary in cases where
|
||||||
/// `dart:mirrors` does not exist.
|
/// `dart:mirrors` does not exist.
|
||||||
Service<Id, Data> service<Id, Data>(String path,
|
Service<Id, Data> service<Id, Data>(String path,
|
||||||
{AngelDeserializer<Data>? deserializer});
|
{ProtevusDeserializer<Data>? deserializer});
|
||||||
|
|
||||||
//@override
|
//@override
|
||||||
//Future<http.Response> delete(url, {Map<String, String> headers});
|
//Future<http.Response> delete(url, {Map<String, String> headers});
|
||||||
|
@ -105,21 +105,21 @@ abstract class Angel extends http.BaseClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents the result of authentication with an Angel server.
|
/// Represents the result of authentication with an Angel server.
|
||||||
class AngelAuthResult {
|
class ProtevusAuthResult {
|
||||||
String? _token;
|
String? _token;
|
||||||
final Map<String, dynamic> data = {};
|
final Map<String, dynamic> data = {};
|
||||||
|
|
||||||
/// The JSON Web token that was sent with this response.
|
/// The JSON Web token that was sent with this response.
|
||||||
String? get token => _token;
|
String? get token => _token;
|
||||||
|
|
||||||
AngelAuthResult({String? token, Map<String, dynamic> data = const {}}) {
|
ProtevusAuthResult({String? token, Map<String, dynamic> data = const {}}) {
|
||||||
_token = token;
|
_token = token;
|
||||||
this.data.addAll(data);
|
this.data.addAll(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempts to deserialize a response from a [Map].
|
/// Attempts to deserialize a response from a [Map].
|
||||||
factory AngelAuthResult.fromMap(Map? data) {
|
factory ProtevusAuthResult.fromMap(Map? data) {
|
||||||
final result = AngelAuthResult();
|
final result = ProtevusAuthResult();
|
||||||
|
|
||||||
if (data is Map && data.containsKey('token') && data['token'] is String) {
|
if (data is Map && data.containsKey('token') && data['token'] is String) {
|
||||||
result._token = data['token'].toString();
|
result._token = data['token'].toString();
|
||||||
|
@ -141,8 +141,8 @@ class AngelAuthResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempts to deserialize a response from a [String].
|
/// Attempts to deserialize a response from a [String].
|
||||||
factory AngelAuthResult.fromJson(String s) =>
|
factory ProtevusAuthResult.fromJson(String s) =>
|
||||||
AngelAuthResult.fromMap(json.decode(s) as Map?);
|
ProtevusAuthResult.fromMap(json.decode(s) as Map?);
|
||||||
|
|
||||||
/// Converts this instance into a JSON-friendly representation.
|
/// Converts this instance into a JSON-friendly representation.
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
|
@ -171,7 +171,7 @@ abstract class Service<Id, Data> {
|
||||||
Stream<Data> get onRemoved;
|
Stream<Data> get onRemoved;
|
||||||
|
|
||||||
/// The Angel instance powering this service.
|
/// The Angel instance powering this service.
|
||||||
Angel get app;
|
Protevus get app;
|
||||||
|
|
||||||
Future close();
|
Future close();
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ class _MappedService<Id, Data, U> extends Service<Id, U> {
|
||||||
_MappedService(this.inner, this.encoder, this.decoder);
|
_MappedService(this.inner, this.encoder, this.decoder);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Angel get app => inner.app;
|
Protevus get app => inner.app;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future close() => Future.value();
|
Future close() => Future.value();
|
||||||
|
|
|
@ -18,22 +18,22 @@ Map<String, String> _buildQuery(Map<String, dynamic>? params) {
|
||||||
bool _invalid(Response response) =>
|
bool _invalid(Response response) =>
|
||||||
response.statusCode < 200 || response.statusCode >= 300;
|
response.statusCode < 200 || response.statusCode >= 300;
|
||||||
|
|
||||||
AngelHttpException failure(Response response,
|
ProtevusHttpException failure(Response response,
|
||||||
{error, String? message, StackTrace? stack}) {
|
{error, String? message, StackTrace? stack}) {
|
||||||
try {
|
try {
|
||||||
var v = json.decode(response.body);
|
var v = json.decode(response.body);
|
||||||
|
|
||||||
if (v is Map && (v['is_error'] == true) || v['isError'] == true) {
|
if (v is Map && (v['is_error'] == true) || v['isError'] == true) {
|
||||||
return AngelHttpException.fromMap(v as Map);
|
return ProtevusHttpException.fromMap(v as Map);
|
||||||
} else {
|
} else {
|
||||||
return AngelHttpException(
|
return ProtevusHttpException(
|
||||||
message: message ??
|
message: message ??
|
||||||
'Unhandled exception while connecting to Angel backend.',
|
'Unhandled exception while connecting to Angel backend.',
|
||||||
statusCode: response.statusCode,
|
statusCode: response.statusCode,
|
||||||
stackTrace: stack);
|
stackTrace: stack);
|
||||||
}
|
}
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
return AngelHttpException(
|
return ProtevusHttpException(
|
||||||
message: message ??
|
message: message ??
|
||||||
'Angel backend did not return JSON - an error likely occurred.',
|
'Angel backend did not return JSON - an error likely occurred.',
|
||||||
statusCode: response.statusCode,
|
statusCode: response.statusCode,
|
||||||
|
@ -41,22 +41,22 @@ AngelHttpException failure(Response response,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class BaseAngelClient extends Angel {
|
abstract class BaseProtevusClient extends Protevus {
|
||||||
final _log = Logger('BaseAngelClient');
|
final _log = Logger('BaseAngelClient');
|
||||||
final StreamController<AngelAuthResult> _onAuthenticated =
|
final StreamController<ProtevusAuthResult> _onAuthenticated =
|
||||||
StreamController<AngelAuthResult>();
|
StreamController<ProtevusAuthResult>();
|
||||||
final List<Service> _services = [];
|
final List<Service> _services = [];
|
||||||
final BaseClient client;
|
final BaseClient client;
|
||||||
|
|
||||||
final Context _p = Context(style: Style.url);
|
final Context _p = Context(style: Style.url);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Stream<AngelAuthResult> get onAuthenticated => _onAuthenticated.stream;
|
Stream<ProtevusAuthResult> get onAuthenticated => _onAuthenticated.stream;
|
||||||
|
|
||||||
BaseAngelClient(this.client, baseUrl) : super(baseUrl);
|
BaseProtevusClient(this.client, baseUrl) : super(baseUrl);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<AngelAuthResult> authenticate(
|
Future<ProtevusAuthResult> authenticate(
|
||||||
{String? type, credentials, String authEndpoint = '/auth'}) async {
|
{String? type, credentials, String authEndpoint = '/auth'}) async {
|
||||||
type ??= 'token';
|
type ??= 'token';
|
||||||
|
|
||||||
|
@ -87,14 +87,14 @@ abstract class BaseAngelClient extends Angel {
|
||||||
var v = jsonDecode(response.body);
|
var v = jsonDecode(response.body);
|
||||||
|
|
||||||
if (v is! Map || !v.containsKey('data') || !v.containsKey('token')) {
|
if (v is! Map || !v.containsKey('data') || !v.containsKey('token')) {
|
||||||
throw AngelHttpException.notAuthenticated(
|
throw ProtevusHttpException.notAuthenticated(
|
||||||
message: "Auth endpoint '$url' did not return a proper response.");
|
message: "Auth endpoint '$url' did not return a proper response.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var r = AngelAuthResult.fromMap(v);
|
var r = ProtevusAuthResult.fromMap(v);
|
||||||
_onAuthenticated.add(r);
|
_onAuthenticated.add(r);
|
||||||
return r;
|
return r;
|
||||||
} on AngelHttpException {
|
} on ProtevusHttpException {
|
||||||
rethrow;
|
rethrow;
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
_log.severe(st);
|
_log.severe(st);
|
||||||
|
@ -153,9 +153,9 @@ abstract class BaseAngelClient extends Angel {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Service<Id, Data> service<Id, Data>(String path,
|
Service<Id, Data> service<Id, Data>(String path,
|
||||||
{Type? type, AngelDeserializer<Data>? deserializer}) {
|
{Type? type, ProtevusDeserializer<Data>? deserializer}) {
|
||||||
var url = baseUrl.replace(path: _p.join(baseUrl.path, path));
|
var url = baseUrl.replace(path: _p.join(baseUrl.path, path));
|
||||||
var s = BaseAngelService<Id, Data>(client, this, url,
|
var s = BaseProtevusService<Id, Data>(client, this, url,
|
||||||
deserializer: deserializer);
|
deserializer: deserializer);
|
||||||
_services.add(s);
|
_services.add(s);
|
||||||
return s as Service<Id, Data>;
|
return s as Service<Id, Data>;
|
||||||
|
@ -201,14 +201,14 @@ abstract class BaseAngelClient extends Angel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BaseAngelService<Id, Data> extends Service<Id, Data?> {
|
class BaseProtevusService<Id, Data> extends Service<Id, Data?> {
|
||||||
final _log = Logger('BaseAngelService');
|
final _log = Logger('BaseProtevusService');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final BaseAngelClient app;
|
final BaseProtevusClient app;
|
||||||
final Uri baseUrl;
|
final Uri baseUrl;
|
||||||
final BaseClient client;
|
final BaseClient client;
|
||||||
final AngelDeserializer<Data>? deserializer;
|
final ProtevusDeserializer<Data>? deserializer;
|
||||||
|
|
||||||
final Context _p = Context(style: Style.url);
|
final Context _p = Context(style: Style.url);
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ class BaseAngelService<Id, Data> extends Service<Id, Data?> {
|
||||||
await _onRemoved.close();
|
await _onRemoved.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseAngelService(this.client, this.app, baseUrl, {this.deserializer})
|
BaseProtevusService(this.client, this.app, baseUrl, {this.deserializer})
|
||||||
: baseUrl = baseUrl is Uri ? baseUrl : Uri.parse(baseUrl.toString());
|
: baseUrl = baseUrl is Uri ? baseUrl : Uri.parse(baseUrl.toString());
|
||||||
|
|
||||||
Data? deserialize(x) {
|
Data? deserialize(x) {
|
||||||
|
|
|
@ -12,11 +12,11 @@ import 'base_angel_client.dart';
|
||||||
export 'angel3_client.dart';
|
export 'angel3_client.dart';
|
||||||
|
|
||||||
/// Queries an Angel server via REST.
|
/// Queries an Angel server via REST.
|
||||||
class Rest extends BaseAngelClient {
|
class Rest extends BaseProtevusClient {
|
||||||
Rest(String basePath) : super(http.BrowserClient(), basePath);
|
Rest(String basePath) : super(http.BrowserClient(), basePath);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<AngelAuthResult> authenticate(
|
Future<ProtevusAuthResult> authenticate(
|
||||||
{String? type, credentials, String authEndpoint = '/auth'}) async {
|
{String? type, credentials, String authEndpoint = '/auth'}) async {
|
||||||
if (type == null || type == 'token') {
|
if (type == null || type == 'token') {
|
||||||
if (!window.localStorage.containsKey('token')) {
|
if (!window.localStorage.containsKey('token')) {
|
||||||
|
@ -46,7 +46,7 @@ class Rest extends BaseAngelClient {
|
||||||
t = Timer.periodic(Duration(milliseconds: 500), (timer) {
|
t = Timer.periodic(Duration(milliseconds: 500), (timer) {
|
||||||
if (!ctrl.isClosed) {
|
if (!ctrl.isClosed) {
|
||||||
if (wnd.closed!) {
|
if (wnd.closed!) {
|
||||||
ctrl.addError(AngelHttpException.notAuthenticated(
|
ctrl.addError(ProtevusHttpException.notAuthenticated(
|
||||||
message:
|
message:
|
||||||
errorMessage ?? 'Authentication via popup window failed.'));
|
errorMessage ?? 'Authentication via popup window failed.'));
|
||||||
ctrl.close();
|
ctrl.close();
|
||||||
|
|
|
@ -7,7 +7,7 @@ import 'base_angel_client.dart';
|
||||||
export 'angel3_client.dart';
|
export 'angel3_client.dart';
|
||||||
|
|
||||||
/// Queries an Angel server via REST.
|
/// Queries an Angel server via REST.
|
||||||
class Rest extends BaseAngelClient {
|
class Rest extends BaseProtevusClient {
|
||||||
Rest(String basePath) : super(http.Client() as http.BaseClient, basePath);
|
Rest(String basePath) : super(http.Client() as http.BaseClient, basePath);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -11,7 +11,7 @@ import 'base_angel_client.dart';
|
||||||
export 'angel3_client.dart';
|
export 'angel3_client.dart';
|
||||||
|
|
||||||
/// Queries an Angel server via REST.
|
/// Queries an Angel server via REST.
|
||||||
class Rest extends BaseAngelClient {
|
class Rest extends BaseProtevusClient {
|
||||||
//final _log = Logger('REST');
|
//final _log = Logger('REST');
|
||||||
final List<Service> _services = [];
|
final List<Service> _services = [];
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ class Rest extends BaseAngelClient {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Service<Id, Data> service<Id, Data>(String path,
|
Service<Id, Data> service<Id, Data>(String path,
|
||||||
{Type? type, AngelDeserializer? deserializer}) {
|
{Type? type, ProtevusDeserializer? deserializer}) {
|
||||||
var url = baseUrl.replace(path: p.join(baseUrl.path, path));
|
var url = baseUrl.replace(path: p.join(baseUrl.path, path));
|
||||||
var s = RestService<Id, Data>(client, this, url, type);
|
var s = RestService<Id, Data>(client, this, url, type);
|
||||||
_services.add(s);
|
_services.add(s);
|
||||||
|
@ -43,7 +43,7 @@ class Rest extends BaseAngelClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Queries an Angel service via REST.
|
/// Queries an Angel service via REST.
|
||||||
class RestService<Id, Data> extends BaseAngelService<Id, Data> {
|
class RestService<Id, Data> extends BaseProtevusService<Id, Data> {
|
||||||
final _log = Logger('RestService');
|
final _log = Logger('RestService');
|
||||||
|
|
||||||
final Type? type;
|
final Type? type;
|
||||||
|
|
|
@ -15,18 +15,18 @@
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/angel-dart/angel_client.git"
|
"url": "git+https://github.com/protevus-dart/angel_client.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"angel",
|
"protevus",
|
||||||
"angel_client"
|
"angel_client"
|
||||||
],
|
],
|
||||||
"author": "Tobe O <thosakwe@gmail.com>",
|
"author": "Tobe O <thosakwe@gmail.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/angel-dart/angel_client/issues"
|
"url": "https://github.com/protevus-dart/angel_client/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/angel-dart/angel_client#readme",
|
"homepage": "https://github.com/protevus-dart/angel_client#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-cli": "^6.18.0",
|
"babel-cli": "^6.18.0",
|
||||||
"babel-plugin-add-module-exports": "^0.2.1",
|
"babel-plugin-add-module-exports": "^0.2.1",
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
name: angel3_client
|
name: angel3_client
|
||||||
version: 8.2.0
|
version: 8.2.0
|
||||||
description: A browser, mobile and command line based client that supports querying Angel3 servers
|
description: A browser, mobile and command line based client that supports querying Protevus servers
|
||||||
homepage: https://angel3-framework.web.app/
|
homepage: https://angel3-framework.web.app/
|
||||||
repository: https://github.com/dart-backend/angel/tree/master/packages/client
|
repository: https://github.com/dart-backend/protevus/tree/master/packages/client
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.3.0 <4.0.0'
|
sdk: '>=3.3.0 <4.0.0'
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
|
@ -9,13 +9,13 @@ const Map<String, String> user = {'username': 'foo', 'password': 'bar'};
|
||||||
var localOpts = AngelAuthOptions<Map<String, String>>(canRespondWithJson: true);
|
var localOpts = AngelAuthOptions<Map<String, String>>(canRespondWithJson: true);
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late Angel app;
|
late Protevus app;
|
||||||
late AngelHttp http;
|
late ProtevusHttp http;
|
||||||
late c.Angel client;
|
late c.Protevus client;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
app = Angel();
|
app = Protevus();
|
||||||
http = AngelHttp(app, useZone: false);
|
http = ProtevusHttp(app, useZone: false);
|
||||||
var auth = AngelAuth(
|
var auth = AngelAuth(
|
||||||
serializer: (_) async => 'baz', deserializer: (_) async => user);
|
serializer: (_) async => 'baz', deserializer: (_) async => user);
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import 'package:http/src/streamed_response.dart' as http;
|
||||||
Future<String> read(Stream<List<int>> stream) =>
|
Future<String> read(Stream<List<int>> stream) =>
|
||||||
stream.transform(utf8.decoder).join();
|
stream.transform(utf8.decoder).join();
|
||||||
|
|
||||||
class MockAngel extends BaseAngelClient {
|
class MockAngel extends BaseProtevusClient {
|
||||||
final SpecClient specClient = SpecClient();
|
final SpecClient specClient = SpecClient();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -10,13 +10,13 @@ import 'package:test/test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late HttpServer server;
|
late HttpServer server;
|
||||||
late c.Angel app;
|
late c.Protevus app;
|
||||||
late c.ServiceList list;
|
late c.ServiceList list;
|
||||||
late StreamQueue queue;
|
late StreamQueue queue;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
var serverApp = s.Angel(reflector: MirrorsReflector());
|
var serverApp = s.Protevus(reflector: MirrorsReflector());
|
||||||
var http = s.AngelHttp(serverApp);
|
var http = s.ProtevusHttp(serverApp);
|
||||||
serverApp.use('/api/todos', s.MapService(autoIdAndDateFields: false));
|
serverApp.use('/api/todos', s.MapService(autoIdAndDateFields: false));
|
||||||
server = await http.startServer();
|
server = await http.startServer();
|
||||||
|
|
||||||
|
|
|
@ -76,5 +76,5 @@ but instead throw an exception.
|
||||||
## 1.0.5
|
## 1.0.5
|
||||||
|
|
||||||
* Now using `package:merge_map` to merge configurations. Resolves
|
* Now using `package:merge_map` to merge configurations. Resolves
|
||||||
[#5](https://github.com/angel-dart/configuration/issues/5).
|
[#5](https://github.com/protevus-dart/configuration/issues/5).
|
||||||
* You can now specify a custom `envPath`.
|
* You can now specify a custom `envPath`.
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
# Angel3 Configuration Loader
|
# Protevus Configuration Loader
|
||||||
|
|
||||||
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_configuration?include_prereleases)
|
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_configuration?include_prereleases)
|
||||||
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
||||||
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
||||||
[![License](https://img.shields.io/github/license/dart-backend/angel)](https://github.com/dart-backend/angel/tree/master/packages/configuration/LICENSE)
|
[![License](https://img.shields.io/github/license/dart-backend/protevus)](https://github.com/dart-backend/protevus/tree/master/packages/configuration/LICENSE)
|
||||||
|
|
||||||
Automatic YAML configuration loader for [Angel3 framework](https://pub.dev/packages/angel3)
|
Automatic YAML configuration loader for [Protevus framework](https://pub.dev/packages/angel3)
|
||||||
|
|
||||||
## About
|
## About
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import 'package:angel3_framework/angel3_framework.dart';
|
||||||
import 'package:file/local.dart';
|
import 'package:file/local.dart';
|
||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
var app = Angel();
|
var app = Protevus();
|
||||||
var fs = const LocalFileSystem();
|
var fs = const LocalFileSystem();
|
||||||
await app.configure(configuration(fs));
|
await app.configure(configuration(fs));
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,11 +124,11 @@ Future<Map> loadStandaloneConfiguration(FileSystem fileSystem,
|
||||||
/// load from a [overrideEnvironmentName].
|
/// load from a [overrideEnvironmentName].
|
||||||
///
|
///
|
||||||
/// You can also specify a custom [envPath] to load system configuration from.
|
/// You can also specify a custom [envPath] to load system configuration from.
|
||||||
AngelConfigurer configuration(FileSystem fileSystem,
|
ProtevusConfigurer configuration(FileSystem fileSystem,
|
||||||
{String directoryPath = './config',
|
{String directoryPath = './config',
|
||||||
String? overrideEnvironmentName,
|
String? overrideEnvironmentName,
|
||||||
String? envPath}) {
|
String? envPath}) {
|
||||||
return (Angel app) async {
|
return (Protevus app) async {
|
||||||
var config = await loadStandaloneConfiguration(
|
var config = await loadStandaloneConfiguration(
|
||||||
fileSystem,
|
fileSystem,
|
||||||
directoryPath: directoryPath,
|
directoryPath: directoryPath,
|
||||||
|
|
|
@ -2,7 +2,7 @@ name: angel3_configuration
|
||||||
version: 8.2.0
|
version: 8.2.0
|
||||||
description: Automatic YAML application configuration loader for Angel 3, with .env support.
|
description: Automatic YAML application configuration loader for Angel 3, with .env support.
|
||||||
homepage: https://angel3-framework.web.app/
|
homepage: https://angel3-framework.web.app/
|
||||||
repository: https://github.com/dart-backend/angel/tree/master/packages/configuration
|
repository: https://github.com/dart-backend/protevus/tree/master/packages/configuration
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.3.0 <4.0.0'
|
sdk: '>=3.3.0 <4.0.0'
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
|
@ -12,7 +12,7 @@ Future<void> main() async {
|
||||||
Logger.root.onRecord.listen(prettyLog);
|
Logger.root.onRecord.listen(prettyLog);
|
||||||
|
|
||||||
// Note: Set ANGEL_ENV to 'development'
|
// Note: Set ANGEL_ENV to 'development'
|
||||||
var app = Angel(logger: Logger('angel_configuration'));
|
var app = Protevus(logger: Logger('angel_configuration'));
|
||||||
var fileSystem = const LocalFileSystem();
|
var fileSystem = const LocalFileSystem();
|
||||||
|
|
||||||
await app.configure(configuration(
|
await app.configure(configuration(
|
||||||
|
@ -30,7 +30,7 @@ Future<void> main() async {
|
||||||
);
|
);
|
||||||
print('Standalone: $config');
|
print('Standalone: $config');
|
||||||
expect(config, {
|
expect(config, {
|
||||||
'angel': {'framework': 'cool'},
|
'protevus': {'framework': 'cool'},
|
||||||
'must_be_null': null,
|
'must_be_null': null,
|
||||||
'artist': 'Timberlake',
|
'artist': 'Timberlake',
|
||||||
'included': true,
|
'included': true,
|
||||||
|
@ -56,7 +56,7 @@ Future<void> main() async {
|
||||||
|
|
||||||
test('will load .env if exists', () {
|
test('will load .env if exists', () {
|
||||||
expect(app.configuration['artist'], 'Timberlake');
|
expect(app.configuration['artist'], 'Timberlake');
|
||||||
expect(app.configuration['angel'], {'framework': 'cool'});
|
expect(app.configuration['protevus'], {'framework': 'cool'});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('non-existent environment defaults to null', () {
|
test('non-existent environment defaults to null', () {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
set_via: default
|
set_via: default
|
||||||
artist: $JUSTIN
|
artist: $JUSTIN
|
||||||
angel:
|
protevus:
|
||||||
framework: $ANGEL_FRAMEWORK
|
framework: $ANGEL_FRAMEWORK
|
||||||
must_be_null: $NONEXISTENT_KEY_FOO_BAR_BAZ_QUUX
|
must_be_null: $NONEXISTENT_KEY_FOO_BAR_BAZ_QUUX
|
||||||
merge:
|
merge:
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
# Angel3 Container
|
# Protevus Container
|
||||||
|
|
||||||
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_container?include_prereleases)
|
![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)
|
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
||||||
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
||||||
[![License](https://img.shields.io/github/license/dart-backend/angel)](https://github.com/dart-backend/angel/tree/master/packages/container/angel_container/LICENSE)
|
[![License](https://img.shields.io/github/license/dart-backend/protevus)](https://github.com/dart-backend/protevus/tree/master/packages/container/angel_container/LICENSE)
|
||||||
|
|
||||||
A better IoC container for Angel3, ultimately allowing Angel3 to be used with or without `dart:mirrors` package.
|
A better IoC container for Protevus, ultimately allowing Protevus to be used with or without `dart:mirrors` package.
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
import 'package:angel3_container/mirrors.dart';
|
import 'package:angel3_container/mirrors.dart';
|
||||||
|
@ -40,6 +40,6 @@ A better IoC container for Angel3, ultimately allowing Angel3 to be used with or
|
||||||
|
|
||||||
var http = AngelHttp(app);
|
var http = AngelHttp(app);
|
||||||
var server = await http.startServer('localhost', 3000);
|
var server = await http.startServer('localhost', 3000);
|
||||||
print("Angel3 server listening at ${http.uri}");
|
print("Protevus server listening at ${http.uri}");
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
name: angel3_container
|
name: angel3_container
|
||||||
version: 8.2.0
|
version: 8.2.0
|
||||||
description: Angel3 hierarchical DI container, and pluggable backends for reflection.
|
description: Protevus hierarchical DI container, and pluggable backends for reflection.
|
||||||
homepage: https://angel3-framework.web.app/
|
homepage: https://angel3-framework.web.app/
|
||||||
repository: https://github.com/dart-backend/angel/tree/master/packages/container/angel_container
|
repository: https://github.com/dart-backend/protevus/tree/master/packages/container/angel_container
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.3.0 <4.0.0'
|
sdk: '>=3.3.0 <4.0.0'
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
# Angel3 Container Generator
|
# Protevus Container Generator
|
||||||
|
|
||||||
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_container_generator?include_prereleases)
|
![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)
|
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
||||||
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
||||||
[![License](https://img.shields.io/github/license/dart-backend/angel)](https://github.com/dart-backend/angel/tree/master/packages/container/angel3_container_generator/LICENSE)
|
[![License](https://img.shields.io/github/license/dart-backend/protevus)](https://github.com/dart-backend/protevus/tree/master/packages/container/angel3_container_generator/LICENSE)
|
||||||
|
|
||||||
An alternative container for Angel3 that uses `reflectable` package instead of `dart:mirrors` for reflection. However, `reflectable` has more limited relfection capabilities when compared to `dart:mirrors`.
|
An alternative container for Protevus that uses `reflectable` package instead of `dart:mirrors` for reflection. However, `reflectable` has more limited relfection capabilities when compared to `dart:mirrors`.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ name: angel3_container_generator
|
||||||
version: 8.2.0
|
version: 8.2.0
|
||||||
description: Codegen support for using pkg:reflectable with pkg:angel3_container.
|
description: Codegen support for using pkg:reflectable with pkg:angel3_container.
|
||||||
homepage: https://angel3-framework.web.app/
|
homepage: https://angel3-framework.web.app/
|
||||||
repository: https://github.com/dart-backend/angel/tree/master/packages/container/angel_container_generator
|
repository: https://github.com/dart-backend/protevus/tree/master/packages/container/angel_container_generator
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.3.0 <4.0.0'
|
sdk: '>=3.3.0 <4.0.0'
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# Angel3 Http Exception
|
# Protevus Http Exception
|
||||||
|
|
||||||
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_http_exception?include_prereleases)
|
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_http_exception?include_prereleases)
|
||||||
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
||||||
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
||||||
[![License](https://img.shields.io/github/license/dart-backend/angel)](https://github.com/dart-backend/angel/tree/master/packages/http_exception/LICENSE)
|
[![License](https://img.shields.io/github/license/dart-backend/protevus)](https://github.com/dart-backend/protevus/tree/master/packages/http_exception/LICENSE)
|
||||||
|
|
||||||
Exception class that can be serialized to JSON and serialized to clients. Angel3's HTTP exception class.
|
Exception class that can be serialized to JSON and serialized to clients. Protevus's HTTP exception class.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import 'package:angel3_http_exception/angel3_http_exception.dart';
|
import 'package:angel3_http_exception/angel3_http_exception.dart';
|
||||||
|
|
||||||
void main() =>
|
void main() =>
|
||||||
throw AngelHttpException.notFound(message: "Can't find that page!");
|
throw ProtevusHttpException.notFound(message: "Can't find that page!");
|
||||||
|
|
|
@ -8,7 +8,7 @@ import 'dart:convert';
|
||||||
///
|
///
|
||||||
/// Originally inspired by
|
/// Originally inspired by
|
||||||
/// [feathers-errors](https://github.com/feathersjs/feathers-errors).
|
/// [feathers-errors](https://github.com/feathersjs/feathers-errors).
|
||||||
class AngelHttpException implements Exception {
|
class ProtevusHttpException implements Exception {
|
||||||
/// A list of errors that occurred when this exception was thrown.
|
/// A list of errors that occurred when this exception was thrown.
|
||||||
final List<String> errors = [];
|
final List<String> errors = [];
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ class AngelHttpException implements Exception {
|
||||||
/// An HTTP status code this exception will throw.
|
/// An HTTP status code this exception will throw.
|
||||||
int statusCode;
|
int statusCode;
|
||||||
|
|
||||||
AngelHttpException(
|
ProtevusHttpException(
|
||||||
{this.message = '500 Internal Server Error',
|
{this.message = '500 Internal Server Error',
|
||||||
this.stackTrace,
|
this.stackTrace,
|
||||||
this.statusCode = 500,
|
this.statusCode = 500,
|
||||||
|
@ -49,8 +49,8 @@ class AngelHttpException implements Exception {
|
||||||
return '$statusCode: $message';
|
return '$statusCode: $message';
|
||||||
}
|
}
|
||||||
|
|
||||||
factory AngelHttpException.fromMap(Map data) {
|
factory ProtevusHttpException.fromMap(Map data) {
|
||||||
return AngelHttpException(
|
return ProtevusHttpException(
|
||||||
statusCode: (data['status_code'] ?? data['statusCode'] ?? 500) as int,
|
statusCode: (data['status_code'] ?? data['statusCode'] ?? 500) as int,
|
||||||
message: data['message']?.toString() ?? 'Internal Server Error',
|
message: data['message']?.toString() ?? 'Internal Server Error',
|
||||||
errors: data['errors'] is Iterable
|
errors: data['errors'] is Iterable
|
||||||
|
@ -59,64 +59,65 @@ class AngelHttpException implements Exception {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
factory AngelHttpException.fromJson(String str) =>
|
factory ProtevusHttpException.fromJson(String str) =>
|
||||||
AngelHttpException.fromMap(json.decode(str) as Map);
|
ProtevusHttpException.fromMap(json.decode(str) as Map);
|
||||||
|
|
||||||
/// Throws a 400 Bad Request error, including an optional arrray of (validation?)
|
/// Throws a 400 Bad Request error, including an optional arrray of (validation?)
|
||||||
/// errors you specify.
|
/// errors you specify.
|
||||||
factory AngelHttpException.badRequest(
|
factory ProtevusHttpException.badRequest(
|
||||||
{String message = '400 Bad Request',
|
{String message = '400 Bad Request',
|
||||||
List<String> errors = const []}) =>
|
List<String> errors = const []}) =>
|
||||||
AngelHttpException(message: message, errors: errors, statusCode: 400);
|
ProtevusHttpException(message: message, errors: errors, statusCode: 400);
|
||||||
|
|
||||||
/// Throws a 401 Not Authenticated error.
|
/// Throws a 401 Not Authenticated error.
|
||||||
factory AngelHttpException.notAuthenticated(
|
factory ProtevusHttpException.notAuthenticated(
|
||||||
{String message = '401 Not Authenticated'}) =>
|
{String message = '401 Not Authenticated'}) =>
|
||||||
AngelHttpException(message: message, statusCode: 401);
|
ProtevusHttpException(message: message, statusCode: 401);
|
||||||
|
|
||||||
/// Throws a 402 Payment Required error.
|
/// Throws a 402 Payment Required error.
|
||||||
factory AngelHttpException.paymentRequired(
|
factory ProtevusHttpException.paymentRequired(
|
||||||
{String message = '402 Payment Required'}) =>
|
{String message = '402 Payment Required'}) =>
|
||||||
AngelHttpException(message: message, statusCode: 402);
|
ProtevusHttpException(message: message, statusCode: 402);
|
||||||
|
|
||||||
/// Throws a 403 Forbidden error.
|
/// Throws a 403 Forbidden error.
|
||||||
factory AngelHttpException.forbidden({String message = '403 Forbidden'}) =>
|
factory ProtevusHttpException.forbidden({String message = '403 Forbidden'}) =>
|
||||||
AngelHttpException(message: message, statusCode: 403);
|
ProtevusHttpException(message: message, statusCode: 403);
|
||||||
|
|
||||||
/// Throws a 404 Not Found error.
|
/// Throws a 404 Not Found error.
|
||||||
factory AngelHttpException.notFound({String message = '404 Not Found'}) =>
|
factory ProtevusHttpException.notFound({String message = '404 Not Found'}) =>
|
||||||
AngelHttpException(message: message, statusCode: 404);
|
ProtevusHttpException(message: message, statusCode: 404);
|
||||||
|
|
||||||
/// Throws a 405 Method Not Allowed error.
|
/// Throws a 405 Method Not Allowed error.
|
||||||
factory AngelHttpException.methodNotAllowed(
|
factory ProtevusHttpException.methodNotAllowed(
|
||||||
{String message = '405 Method Not Allowed'}) =>
|
{String message = '405 Method Not Allowed'}) =>
|
||||||
AngelHttpException(message: message, statusCode: 405);
|
ProtevusHttpException(message: message, statusCode: 405);
|
||||||
|
|
||||||
/// Throws a 406 Not Acceptable error.
|
/// Throws a 406 Not Acceptable error.
|
||||||
factory AngelHttpException.notAcceptable(
|
factory ProtevusHttpException.notAcceptable(
|
||||||
{String message = '406 Not Acceptable'}) =>
|
{String message = '406 Not Acceptable'}) =>
|
||||||
AngelHttpException(message: message, statusCode: 406);
|
ProtevusHttpException(message: message, statusCode: 406);
|
||||||
|
|
||||||
/// Throws a 408 Timeout error.
|
/// Throws a 408 Timeout error.
|
||||||
factory AngelHttpException.methodTimeout({String message = '408 Timeout'}) =>
|
factory ProtevusHttpException.methodTimeout(
|
||||||
AngelHttpException(message: message, statusCode: 408);
|
{String message = '408 Timeout'}) =>
|
||||||
|
ProtevusHttpException(message: message, statusCode: 408);
|
||||||
|
|
||||||
/// Throws a 409 Conflict error.
|
/// Throws a 409 Conflict error.
|
||||||
factory AngelHttpException.conflict({String message = '409 Conflict'}) =>
|
factory ProtevusHttpException.conflict({String message = '409 Conflict'}) =>
|
||||||
AngelHttpException(message: message, statusCode: 409);
|
ProtevusHttpException(message: message, statusCode: 409);
|
||||||
|
|
||||||
/// Throws a 422 Not Processable error.
|
/// Throws a 422 Not Processable error.
|
||||||
factory AngelHttpException.notProcessable(
|
factory ProtevusHttpException.notProcessable(
|
||||||
{String message = '422 Not Processable'}) =>
|
{String message = '422 Not Processable'}) =>
|
||||||
AngelHttpException(message: message, statusCode: 422);
|
ProtevusHttpException(message: message, statusCode: 422);
|
||||||
|
|
||||||
/// Throws a 501 Not Implemented error.
|
/// Throws a 501 Not Implemented error.
|
||||||
factory AngelHttpException.notImplemented(
|
factory ProtevusHttpException.notImplemented(
|
||||||
{String message = '501 Not Implemented'}) =>
|
{String message = '501 Not Implemented'}) =>
|
||||||
AngelHttpException(message: message, statusCode: 501);
|
ProtevusHttpException(message: message, statusCode: 501);
|
||||||
|
|
||||||
/// Throws a 503 Unavailable error.
|
/// Throws a 503 Unavailable error.
|
||||||
factory AngelHttpException.unavailable(
|
factory ProtevusHttpException.unavailable(
|
||||||
{String message = '503 Unavailable'}) =>
|
{String message = '503 Unavailable'}) =>
|
||||||
AngelHttpException(message: message, statusCode: 503);
|
ProtevusHttpException(message: message, statusCode: 503);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ name: angel3_http_exception
|
||||||
version: 8.2.0
|
version: 8.2.0
|
||||||
description: Exception class that can be serialized to JSON and serialized to clients.
|
description: Exception class that can be serialized to JSON and serialized to clients.
|
||||||
homepage: https://angel3-framework.web.app/
|
homepage: https://angel3-framework.web.app/
|
||||||
repository: https://github.com/dart-backend/angel/tree/master/packages/http_exception
|
repository: https://github.com/dart-backend/protevus/tree/master/packages/http_exception
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.3.0 <4.0.0'
|
sdk: '>=3.3.0 <4.0.0'
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
|
|
@ -61,7 +61,7 @@
|
||||||
|
|
||||||
* Require Dart >= 2.16
|
* Require Dart >= 2.16
|
||||||
* Updated `container` to non nullable
|
* Updated `container` to non nullable
|
||||||
* Updated `angel` to non nullable
|
* Updated `protevus` to non nullable
|
||||||
* Updated `logger` to non nullable
|
* Updated `logger` to non nullable
|
||||||
* Refactored error handler
|
* Refactored error handler
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@
|
||||||
## 4.2.2
|
## 4.2.2
|
||||||
|
|
||||||
* Added `Date` to response header
|
* Added `Date` to response header
|
||||||
* Updated `Server: Angel3` response header
|
* Updated `Server: Protevus` response header
|
||||||
|
|
||||||
## 4.2.1
|
## 4.2.1
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@
|
||||||
|
|
||||||
## 4.1.1
|
## 4.1.1
|
||||||
|
|
||||||
* Updated link to `Angel3` home page
|
* Updated link to `Protevus` home page
|
||||||
* Fixed pedantic warnings
|
* Fixed pedantic warnings
|
||||||
|
|
||||||
## 4.1.0
|
## 4.1.0
|
||||||
|
@ -145,14 +145,14 @@
|
||||||
* This release was originally planned to be `2.0.5`, but it adds several features, and has
|
* This release was originally planned to be `2.0.5`, but it adds several features, and has
|
||||||
therefore been bumped to `2.1.0`.
|
therefore been bumped to `2.1.0`.
|
||||||
* Fix a new (did not appear before 2.6/2.7) type error causing compilation to fail.
|
* Fix a new (did not appear before 2.6/2.7) type error causing compilation to fail.
|
||||||
<https://github.com/angel-dart/framework/issues/249>
|
<https://github.com/protevus-dart/framework/issues/249>
|
||||||
|
|
||||||
## 2.0.5-beta
|
## 2.0.5-beta
|
||||||
|
|
||||||
* Make `@Expose()` in `Controller` optional. <https://github.com/angel-dart/angel/issues/107>
|
* Make `@Expose()` in `Controller` optional. <https://github.com/protevus-dart/protevus/issues/107>
|
||||||
* Add `allowHttp1` to `AngelHttp2` constructors. <https://github.com/angel-dart/angel/issues/108>
|
* Add `allowHttp1` to `AngelHttp2` constructors. <https://github.com/protevus-dart/protevus/issues/108>
|
||||||
* Add `deserializeBody` and `decodeBody` to `RequestContext`. <https://github.com/angel-dart/angel/issues/109>
|
* 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/angel-dart/angel/issues/110>
|
* 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
|
* Default to using `ThrowingReflector`, instead of `EmptyReflector`. This will give a more descriptive
|
||||||
error when trying to use controllers, etc. without reflection enabled.
|
error when trying to use controllers, etc. without reflection enabled.
|
||||||
* `mountController` returns the mounted controller.
|
* `mountController` returns the mounted controller.
|
||||||
|
@ -167,12 +167,12 @@ error when trying to use controllers, etc. without reflection enabled.
|
||||||
* Prepare for Dart SDK change to `Stream<List<int>>` that are now
|
* Prepare for Dart SDK change to `Stream<List<int>>` that are now
|
||||||
`Stream<Uint8List>`.
|
`Stream<Uint8List>`.
|
||||||
* Accept any content type if accept header is missing. See
|
* Accept any content type if accept header is missing. See
|
||||||
[this PR](https://github.com/angel-dart/framework/pull/239).
|
[this PR](https://github.com/protevus-dart/framework/pull/239).
|
||||||
|
|
||||||
## 2.0.3
|
## 2.0.3
|
||||||
|
|
||||||
* Patch up a bug caused by an upstream change to Dart's stream semantics.
|
* Patch up a bug caused by an upstream change to Dart's stream semantics.
|
||||||
See more: <https://github.com/angel-dart/angel/issues/106#issuecomment-499564485>
|
See more: <https://github.com/protevus-dart/protevus/issues/106#issuecomment-499564485>
|
||||||
|
|
||||||
## 2.0.2+1
|
## 2.0.2+1
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ handlers to run, even after the response was closed.
|
||||||
|
|
||||||
## 2.0.0
|
## 2.0.0
|
||||||
|
|
||||||
* Angel 2! :angel: :rocket:
|
* Angel 2! :protevus: :rocket:
|
||||||
|
|
||||||
## 2.0.0-rc.10
|
## 2.0.0-rc.10
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
# Angel3 Framework
|
# Protevus Framework
|
||||||
|
|
||||||
[![Angel3 Framework](../../angel3_logo.png)](https://github.com/dart-backend/angel)
|
[![Protevus Framework](../../angel3_logo.png)](https://github.com/dart-backend/protevus)
|
||||||
|
|
||||||
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_framework?include_prereleases)
|
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_framework?include_prereleases)
|
||||||
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
||||||
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
||||||
[![License](https://img.shields.io/github/license/dart-backend/angel)](https://github.com/dart-backend/angel/tree/master/packages/framework/LICENSE)
|
[![License](https://img.shields.io/github/license/dart-backend/protevus)](https://github.com/dart-backend/protevus/tree/master/packages/framework/LICENSE)
|
||||||
[![melos](https://img.shields.io/badge/maintained%20with-melos-f700ff.svg?style=flat-square)](https://github.com/invertase/melos)
|
[![melos](https://img.shields.io/badge/maintained%20with-melos-f700ff.svg?style=flat-square)](https://github.com/invertase/melos)
|
||||||
|
|
||||||
Angel3 framework is a high-powered HTTP server with support for dependency injection, sophisticated routing, authentication, ORM, graphql etc. It is designed to keep the core minimal but extensible through a series of plugin packages. It won't dictate which features, databases or web templating engine to use. This flexibility enable Angel3 framework to grow with your application as new features can be added to handle the new use cases.
|
Protevus framework is a high-powered HTTP server with support for dependency injection, sophisticated routing, authentication, ORM, graphql etc. It is designed to keep the core minimal but extensible through a series of plugin packages. It won't dictate which features, databases or web templating engine to use. This flexibility enable Protevus framework to grow with your application as new features can be added to handle the new use cases.
|
||||||
|
|
||||||
This package is the core package of [Angel3](https://github.com/dart-backend/angel). For more information, visit us at [Angel3 Website](https://angel3-framework.web.app).
|
This package is the core package of [Protevus](https://github.com/dart-backend/protevus). For more information, visit us at [Protevus Website](https://angel3-framework.web.app).
|
||||||
|
|
||||||
## Installation and Setup
|
## Installation and Setup
|
||||||
|
|
||||||
|
@ -19,10 +19,10 @@ This package is the core package of [Angel3](https://github.com/dart-backend/ang
|
||||||
1. Download and install [Dart](https://dart.dev/get-dart)
|
1. Download and install [Dart](https://dart.dev/get-dart)
|
||||||
|
|
||||||
2. Clone one of the following starter projects:
|
2. Clone one of the following starter projects:
|
||||||
* [Angel3 Basic Template](https://github.com/dukefirehawk/boilerplates/tree/v7/angel3-basic)
|
* [Protevus Basic Template](https://github.com/dukefirehawk/boilerplates/tree/v7/angel3-basic)
|
||||||
* [Angel3 ORM Template](https://github.com/dukefirehawk/boilerplates/tree/v7/angel3-orm)
|
* [Protevus ORM Template](https://github.com/dukefirehawk/boilerplates/tree/v7/angel3-orm)
|
||||||
* [Angel3 ORM MySQL Template](https://github.com/dukefirehawk/boilerplates/tree/v7/angel3-orm-mysql)
|
* [Protevus ORM MySQL Template](https://github.com/dukefirehawk/boilerplates/tree/v7/angel3-orm-mysql)
|
||||||
* [Angel3 Graphql Template](https://github.com/dukefirehawk/boilerplates/tree/v7/angel3-graphql)
|
* [Protevus Graphql Template](https://github.com/dukefirehawk/boilerplates/tree/v7/angel3-graphql)
|
||||||
|
|
||||||
3. Run the project in development mode (*hot-reloaded* is enabled on file changes).
|
3. Run the project in development mode (*hot-reloaded* is enabled on file changes).
|
||||||
|
|
||||||
|
@ -38,11 +38,11 @@ This package is the core package of [Angel3](https://github.com/dart-backend/ang
|
||||||
|
|
||||||
5. Run as docker. Edit and build the image with the provided `Dockerfile` file.
|
5. Run as docker. Edit and build the image with the provided `Dockerfile` file.
|
||||||
|
|
||||||
### (Option 2) Create a new project with Angel3 CLI
|
### (Option 2) Create a new project with Protevus CLI
|
||||||
|
|
||||||
1. Download and install [Dart](https://dart.dev/get-dart)
|
1. Download and install [Dart](https://dart.dev/get-dart)
|
||||||
|
|
||||||
2. Install the [Angel3 CLI](https://pub.dev/packages/angel3_cli):
|
2. Install the [Protevus CLI](https://pub.dev/packages/angel3_cli):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
dart pub global activate angel3_cli
|
dart pub global activate angel3_cli
|
||||||
|
@ -74,9 +74,9 @@ The performance benchmark can be found at
|
||||||
|
|
||||||
[TechEmpower Framework Benchmarks Round 21](https://www.techempower.com/benchmarks/#section=data-r21&test=composite)
|
[TechEmpower Framework Benchmarks Round 21](https://www.techempower.com/benchmarks/#section=data-r21&test=composite)
|
||||||
|
|
||||||
### Migrating from Angel to Angel3
|
### Migrating from Angel to Protevus
|
||||||
|
|
||||||
Check out [Migrating to Angel3](https://angel3-docs.dukefirehawk.com/migration/angel-2.x.x-to-angel3/migration-guide-3)
|
Check out [Migrating to Protevus](https://angel3-docs.dukefirehawk.com/migration/protevus-2.x.x-to-angel3/migration-guide-3)
|
||||||
|
|
||||||
## Donation & Support
|
## Donation & Support
|
||||||
|
|
||||||
|
|
|
@ -8,14 +8,14 @@ void main() async {
|
||||||
Logger.root.onRecord.listen(print);
|
Logger.root.onRecord.listen(print);
|
||||||
|
|
||||||
// Create our server.
|
// Create our server.
|
||||||
var app = Angel(logger: Logger('angel'), reflector: MirrorsReflector());
|
var app = Protevus(logger: Logger('protevus'), reflector: MirrorsReflector());
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
|
|
||||||
await app.mountController<ArtistsController>();
|
await app.mountController<ArtistsController>();
|
||||||
|
|
||||||
// Simple fallback to throw a 404 on unknown paths.
|
// Simple fallback to throw a 404 on unknown paths.
|
||||||
app.fallback((req, res) {
|
app.fallback((req, res) {
|
||||||
throw AngelHttpException.notFound(
|
throw ProtevusHttpException.notFound(
|
||||||
message: 'Unknown path: "${req.uri!.path}"',
|
message: 'Unknown path: "${req.uri!.path}"',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,8 +6,8 @@ import 'package:angel3_framework/http.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
var app = Angel(reflector: MirrorsReflector())
|
var app = Protevus(reflector: MirrorsReflector())
|
||||||
..logger = (Logger('angel')
|
..logger = (Logger('protevus')
|
||||||
..onRecord.listen((rec) {
|
..onRecord.listen((rec) {
|
||||||
print(rec);
|
print(rec);
|
||||||
if (rec.error != null) print(rec.error);
|
if (rec.error != null) print(rec.error);
|
||||||
|
@ -18,7 +18,7 @@ void main() async {
|
||||||
app.fallback(
|
app.fallback(
|
||||||
(req, res) => Future.error('Throwing just because I feel like!'));
|
(req, res) => Future.error('Throwing just because I feel like!'));
|
||||||
|
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
HttpServer? server = await http.startServer('127.0.0.1', 3000);
|
HttpServer? server = await http.startServer('127.0.0.1', 3000);
|
||||||
var url = 'http://${server.address.address}:${server.port}';
|
var url = 'http://${server.address.address}:${server.port}';
|
||||||
print('Listening at $url');
|
print('Listening at $url');
|
||||||
|
|
|
@ -3,14 +3,14 @@ import 'package:angel3_framework/angel3_framework.dart';
|
||||||
import 'package:angel3_framework/http.dart';
|
import 'package:angel3_framework/http.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
|
|
||||||
Future<void> apiConfigurer(Angel app) async {
|
Future<void> apiConfigurer(Protevus app) async {
|
||||||
app.get('/', (req, res) => 'Hello, API!');
|
app.get('/', (req, res) => 'Hello, API!');
|
||||||
app.fallback((req, res) {
|
app.fallback((req, res) {
|
||||||
return 'fallback on ${req.uri} (within the API)';
|
return 'fallback on ${req.uri} (within the API)';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> frontendConfigurer(Angel app) async {
|
Future<void> frontendConfigurer(Protevus app) async {
|
||||||
app.fallback((req, res) => '(usually an index page would be shown here.)');
|
app.fallback((req, res) => '(usually an index page would be shown here.)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ void main() async {
|
||||||
hierarchicalLoggingEnabled = true;
|
hierarchicalLoggingEnabled = true;
|
||||||
//Logger.root.onRecord.listen(prettyLog);
|
//Logger.root.onRecord.listen(prettyLog);
|
||||||
|
|
||||||
var app = Angel(logger: Logger('angel'));
|
var app = Protevus(logger: Logger('protevus'));
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
var multiHost = HostnameRouter.configure({
|
var multiHost = HostnameRouter.configure({
|
||||||
'api.localhost:3000': apiConfigurer,
|
'api.localhost:3000': apiConfigurer,
|
||||||
'localhost:3000': frontendConfigurer,
|
'localhost:3000': frontendConfigurer,
|
||||||
|
|
|
@ -6,8 +6,8 @@ import 'package:file/local.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
var app = Angel();
|
var app = Protevus();
|
||||||
app.logger = Logger('angel')
|
app.logger = Logger('protevus')
|
||||||
..onRecord.listen((rec) {
|
..onRecord.listen((rec) {
|
||||||
print(rec);
|
print(rec);
|
||||||
if (rec.error != null) print(rec.error);
|
if (rec.error != null) print(rec.error);
|
||||||
|
@ -35,8 +35,8 @@ void main() async {
|
||||||
st);
|
st);
|
||||||
}
|
}
|
||||||
|
|
||||||
var http1 = AngelHttp(app);
|
var http1 = ProtevusHttp(app);
|
||||||
var http2 = AngelHttp2(app, ctx);
|
var http2 = ProtevusHttp2(app, ctx);
|
||||||
|
|
||||||
// HTTP/1.x requests will fallback to `AngelHttp`
|
// HTTP/1.x requests will fallback to `AngelHttp`
|
||||||
http2.onHttp1.listen(http1.handleRequest);
|
http2.onHttp1.listen(http1.handleRequest);
|
||||||
|
|
|
@ -6,16 +6,16 @@ import 'package:logging/logging.dart';
|
||||||
import 'common.dart';
|
import 'common.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
var app = Angel()
|
var app = Protevus()
|
||||||
..encoders.addAll({
|
..encoders.addAll({
|
||||||
'gzip': gzip.encoder,
|
'gzip': gzip.encoder,
|
||||||
'deflate': zlib.encoder,
|
'deflate': zlib.encoder,
|
||||||
});
|
});
|
||||||
app.logger = Logger('angel')..onRecord.listen(dumpError);
|
app.logger = Logger('protevus')..onRecord.listen(dumpError);
|
||||||
|
|
||||||
app.get('/', (req, res) => 'Hello HTTP/2!!!');
|
app.get('/', (req, res) => 'Hello HTTP/2!!!');
|
||||||
|
|
||||||
app.fallback((req, res) => throw AngelHttpException.notFound(
|
app.fallback((req, res) => throw ProtevusHttpException.notFound(
|
||||||
message: 'No file exists at ${req.uri}'));
|
message: 'No file exists at ${req.uri}'));
|
||||||
|
|
||||||
var ctx = SecurityContext()
|
var ctx = SecurityContext()
|
||||||
|
@ -32,8 +32,8 @@ void main() async {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var http1 = AngelHttp(app);
|
var http1 = ProtevusHttp(app);
|
||||||
var http2 = AngelHttp2(app, ctx);
|
var http2 = ProtevusHttp2(app, ctx);
|
||||||
|
|
||||||
// HTTP/1.x requests will fallback to `AngelHttp`
|
// HTTP/1.x requests will fallback to `AngelHttp`
|
||||||
http2.onHttp1.listen(http1.handleRequest);
|
http2.onHttp1.listen(http1.handleRequest);
|
||||||
|
|
|
@ -6,8 +6,8 @@ import 'package:file/local.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
var app = Angel();
|
var app = Protevus();
|
||||||
app.logger = Logger('angel')
|
app.logger = Logger('protevus')
|
||||||
..onRecord.listen((rec) {
|
..onRecord.listen((rec) {
|
||||||
print(rec);
|
print(rec);
|
||||||
if (rec.error != null) print(rec.error);
|
if (rec.error != null) print(rec.error);
|
||||||
|
@ -51,8 +51,8 @@ void main() async {
|
||||||
st);
|
st);
|
||||||
}
|
}
|
||||||
|
|
||||||
var http1 = AngelHttp(app);
|
var http1 = ProtevusHttp(app);
|
||||||
var http2 = AngelHttp2(app, ctx);
|
var http2 = ProtevusHttp2(app, ctx);
|
||||||
|
|
||||||
// HTTP/1.x requests will fallback to `AngelHttp`
|
// HTTP/1.x requests will fallback to `AngelHttp`
|
||||||
http2.onHttp1.listen(http1.handleRequest);
|
http2.onHttp1.listen(http1.handleRequest);
|
||||||
|
|
|
@ -31,9 +31,9 @@ void main() async {
|
||||||
}
|
}
|
||||||
|
|
||||||
void serverMain(_) async {
|
void serverMain(_) async {
|
||||||
var app = Angel();
|
var app = Protevus();
|
||||||
var http =
|
var http =
|
||||||
AngelHttp.custom(app, startShared, useZone: false); // Run a cluster
|
ProtevusHttp.custom(app, startShared, useZone: false); // Run a cluster
|
||||||
|
|
||||||
app.get('/', (req, res) {
|
app.get('/', (req, res) {
|
||||||
return res.serialize({
|
return res.serialize({
|
||||||
|
|
|
@ -8,8 +8,8 @@ void main() async {
|
||||||
//Logger.root.onRecord.listen(prettyLog);
|
//Logger.root.onRecord.listen(prettyLog);
|
||||||
|
|
||||||
// Create our server.
|
// Create our server.
|
||||||
var app = Angel(
|
var app = Protevus(
|
||||||
logger: Logger('angel'),
|
logger: Logger('protevus'),
|
||||||
reflector: MirrorsReflector(),
|
reflector: MirrorsReflector(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -41,12 +41,12 @@ void main() async {
|
||||||
|
|
||||||
// Simple fallback to throw a 404 on unknown paths.
|
// Simple fallback to throw a 404 on unknown paths.
|
||||||
app.fallback((req, res) {
|
app.fallback((req, res) {
|
||||||
throw AngelHttpException.notFound(
|
throw ProtevusHttpException.notFound(
|
||||||
message: 'Unknown path: "${req.uri!.path}"',
|
message: 'Unknown path: "${req.uri!.path}"',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
var server = await http.startServer('127.0.0.1', 3000);
|
var server = await http.startServer('127.0.0.1', 3000);
|
||||||
var url = 'http://${server.address.address}:${server.port}';
|
var url = 'http://${server.address.address}:${server.port}';
|
||||||
print('Listening at $url');
|
print('Listening at $url');
|
||||||
|
|
|
@ -8,15 +8,15 @@ void main() async {
|
||||||
Logger.root.onRecord.listen(print);
|
Logger.root.onRecord.listen(print);
|
||||||
|
|
||||||
// Create our server.
|
// Create our server.
|
||||||
var app = Angel(
|
var app = Protevus(
|
||||||
logger: Logger('angel'),
|
logger: Logger('protevus'),
|
||||||
reflector: MirrorsReflector(),
|
reflector: MirrorsReflector(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create a RESTful service that manages an in-memory collection.
|
// Create a RESTful service that manages an in-memory collection.
|
||||||
app.use('/api/todos', MapService());
|
app.use('/api/todos', MapService());
|
||||||
|
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
await http.startServer('127.0.0.1', 0);
|
await http.startServer('127.0.0.1', 0);
|
||||||
print('Listening at ${http.uri}');
|
print('Listening at ${http.uri}');
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@ import 'package:angel3_framework/angel3_framework.dart';
|
||||||
import 'package:angel3_framework/http.dart';
|
import 'package:angel3_framework/http.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
var app = Angel();
|
var app = Protevus();
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
|
|
||||||
app.fallback((req, res) {
|
app.fallback((req, res) {
|
||||||
res.statusCode = 304;
|
res.statusCode = 304;
|
||||||
|
|
|
@ -3,7 +3,7 @@ import 'package:angel3_framework/angel3_framework.dart';
|
||||||
import 'package:angel3_framework/http.dart';
|
import 'package:angel3_framework/http.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
var app = Angel(reflector: MirrorsReflector());
|
var app = Protevus(reflector: MirrorsReflector());
|
||||||
|
|
||||||
app.viewGenerator = (name, [data]) async =>
|
app.viewGenerator = (name, [data]) async =>
|
||||||
'View generator invoked with name $name and data: $data';
|
'View generator invoked with name $name and data: $data';
|
||||||
|
@ -11,7 +11,7 @@ void main() async {
|
||||||
// Index route. Returns JSON.
|
// Index route. Returns JSON.
|
||||||
app.get('/', (req, res) => res.render('index', {'foo': 'bar'}));
|
app.get('/', (req, res) => res.render('index', {'foo': 'bar'}));
|
||||||
|
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
var server = await http.startServer('127.0.0.1', 3000);
|
var server = await http.startServer('127.0.0.1', 3000);
|
||||||
var url = 'http://${server.address.address}:${server.port}';
|
var url = 'http://${server.address.address}:${server.port}';
|
||||||
print('Listening at $url');
|
print('Listening at $url');
|
||||||
|
|
|
@ -9,10 +9,10 @@ import '../core/core.dart';
|
||||||
|
|
||||||
/// Supports grouping routes with shared functionality.
|
/// Supports grouping routes with shared functionality.
|
||||||
class Controller {
|
class Controller {
|
||||||
Angel? _app;
|
Protevus? _app;
|
||||||
|
|
||||||
/// The [Angel] application powering this controller.
|
/// The [Protevus] application powering this controller.
|
||||||
Angel get app {
|
Protevus get app {
|
||||||
if (_app == null) {
|
if (_app == null) {
|
||||||
throw ArgumentError("Angel is not instantiated.");
|
throw ArgumentError("Angel is not instantiated.");
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ class Controller {
|
||||||
|
|
||||||
/// Applies routes, DI, and other configuration to an [app].
|
/// Applies routes, DI, and other configuration to an [app].
|
||||||
@mustCallSuper
|
@mustCallSuper
|
||||||
Future<void> configureServer(Angel app) async {
|
Future<void> configureServer(Protevus app) async {
|
||||||
_app = app;
|
_app = app;
|
||||||
|
|
||||||
if (injectSingleton != false) {
|
if (injectSingleton != false) {
|
||||||
|
|
|
@ -17,7 +17,7 @@ abstract class Driver<
|
||||||
Server extends Stream<Request>,
|
Server extends Stream<Request>,
|
||||||
RequestContextType extends RequestContext,
|
RequestContextType extends RequestContext,
|
||||||
ResponseContextType extends ResponseContext> {
|
ResponseContextType extends ResponseContext> {
|
||||||
final Angel app;
|
final Protevus app;
|
||||||
final bool useZone;
|
final bool useZone;
|
||||||
bool _closed = false;
|
bool _closed = false;
|
||||||
|
|
||||||
|
@ -170,23 +170,23 @@ abstract class Driver<
|
||||||
|
|
||||||
return f.catchError((e, StackTrace st) {
|
return f.catchError((e, StackTrace st) {
|
||||||
if (e is FormatException) {
|
if (e is FormatException) {
|
||||||
throw AngelHttpException.badRequest(message: e.message)
|
throw ProtevusHttpException.badRequest(message: e.message)
|
||||||
..stackTrace = st;
|
..stackTrace = st;
|
||||||
}
|
}
|
||||||
throw AngelHttpException(
|
throw ProtevusHttpException(
|
||||||
stackTrace: st,
|
stackTrace: st,
|
||||||
statusCode: (e is AngelHttpException) ? e.statusCode : 500,
|
statusCode: (e is ProtevusHttpException) ? e.statusCode : 500,
|
||||||
message: e?.toString() ?? '500 Internal Server Error');
|
message: e?.toString() ?? '500 Internal Server Error');
|
||||||
}, test: (e) => e is AngelHttpException).catchError(
|
}, test: (e) => e is ProtevusHttpException).catchError(
|
||||||
(ee, StackTrace st) {
|
(ee, StackTrace st) {
|
||||||
//print(">>>> Framework error: $ee");
|
//print(">>>> Framework error: $ee");
|
||||||
//var t = (st).runtimeType;
|
//var t = (st).runtimeType;
|
||||||
//print(">>>> StackTrace: $t");
|
//print(">>>> StackTrace: $t");
|
||||||
AngelHttpException e;
|
ProtevusHttpException e;
|
||||||
if (ee is AngelHttpException) {
|
if (ee is ProtevusHttpException) {
|
||||||
e = ee;
|
e = ee;
|
||||||
} else {
|
} else {
|
||||||
e = AngelHttpException(
|
e = ProtevusHttpException(
|
||||||
stackTrace: st,
|
stackTrace: st,
|
||||||
statusCode: 500,
|
statusCode: 500,
|
||||||
message: ee?.toString() ?? '500 Internal Server Error');
|
message: ee?.toString() ?? '500 Internal Server Error');
|
||||||
|
@ -196,7 +196,8 @@ abstract class Driver<
|
||||||
var trace = Trace.from(StackTrace.current).terse;
|
var trace = Trace.from(StackTrace.current).terse;
|
||||||
app.logger.severe(e.message, error, trace);
|
app.logger.severe(e.message, error, trace);
|
||||||
|
|
||||||
return handleAngelHttpException(e, st, req, res, request, response);
|
return handleProtevusHttpException(
|
||||||
|
e, st, req, res, request, response);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var zoneSpec = ZoneSpecification(
|
var zoneSpec = ZoneSpecification(
|
||||||
|
@ -208,20 +209,20 @@ abstract class Driver<
|
||||||
|
|
||||||
// TODO: To be revisited
|
// TODO: To be revisited
|
||||||
Future(() {
|
Future(() {
|
||||||
AngelHttpException e;
|
ProtevusHttpException e;
|
||||||
|
|
||||||
if (error is FormatException) {
|
if (error is FormatException) {
|
||||||
e = AngelHttpException.badRequest(message: error.message);
|
e = ProtevusHttpException.badRequest(message: error.message);
|
||||||
} else if (error is AngelHttpException) {
|
} else if (error is ProtevusHttpException) {
|
||||||
e = error;
|
e = error;
|
||||||
} else {
|
} else {
|
||||||
e = AngelHttpException(
|
e = ProtevusHttpException(
|
||||||
stackTrace: stackTrace, message: error.toString());
|
stackTrace: stackTrace, message: error.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
app.logger.severe(e.message, error, trace);
|
app.logger.severe(e.message, error, trace);
|
||||||
|
|
||||||
return handleAngelHttpException(
|
return handleProtevusHttpException(
|
||||||
e, trace, req, res, request, response);
|
e, trace, req, res, request, response);
|
||||||
}).catchError((e, StackTrace st) {
|
}).catchError((e, StackTrace st) {
|
||||||
var trace = Trace.from(st).terse;
|
var trace = Trace.from(st).terse;
|
||||||
|
@ -252,9 +253,9 @@ abstract class Driver<
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles an [AngelHttpException].
|
/// Handles an [ProtevusHttpException].
|
||||||
Future handleAngelHttpException(
|
Future handleProtevusHttpException(
|
||||||
AngelHttpException e,
|
ProtevusHttpException e,
|
||||||
StackTrace st,
|
StackTrace st,
|
||||||
RequestContext? req,
|
RequestContext? req,
|
||||||
ResponseContext? res,
|
ResponseContext? res,
|
||||||
|
@ -384,7 +385,7 @@ abstract class Driver<
|
||||||
MiddlewarePipelineIterator<RequestHandler> it,
|
MiddlewarePipelineIterator<RequestHandler> it,
|
||||||
RequestContextType req,
|
RequestContextType req,
|
||||||
ResponseContextType res,
|
ResponseContextType res,
|
||||||
Angel app) async {
|
Protevus app) async {
|
||||||
var broken = false;
|
var broken = false;
|
||||||
while (it.moveNext()) {
|
while (it.moveNext()) {
|
||||||
var current = it.current.handlers.iterator;
|
var current = it.current.handlers.iterator;
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
/// A constant instance of [AngelEnv].
|
/// A constant instance of [AngelEnv].
|
||||||
const AngelEnvironment angelEnv = AngelEnvironment();
|
const ProtevusEnvironment angelEnv = ProtevusEnvironment();
|
||||||
|
|
||||||
/// Queries the environment's `ANGEL_ENV` value.
|
/// Queries the environment's `ANGEL_ENV` value.
|
||||||
class AngelEnvironment {
|
class ProtevusEnvironment {
|
||||||
final String? _customValue;
|
final String? _customValue;
|
||||||
|
|
||||||
/// You can optionally provide a custom value, in order to override the system's
|
/// You can optionally provide a custom value, in order to override the system's
|
||||||
/// value.
|
/// value.
|
||||||
const AngelEnvironment([this._customValue]);
|
const ProtevusEnvironment([this._customValue]);
|
||||||
|
|
||||||
/// Returns the value of the `ANGEL_ENV` variable; defaults to `'development'`.
|
/// Returns the value of the `ANGEL_ENV` variable; defaults to `'development'`.
|
||||||
String get value =>
|
String get value =>
|
||||||
|
|
|
@ -98,7 +98,7 @@ class HookedService<Id, Data, T extends Service<Id, Data>>
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds hooks to this instance.
|
/// Adds hooks to this instance.
|
||||||
void addHooks(Angel app) {
|
void addHooks(Protevus app) {
|
||||||
var hooks = getAnnotation<Hooks>(inner, app.container.reflector);
|
var hooks = getAnnotation<Hooks>(inner, app.container.reflector);
|
||||||
var before = <HookedServiceEventListener<Id, Data, T>>[];
|
var before = <HookedServiceEventListener<Id, Data, T>>[];
|
||||||
var after = <HookedServiceEventListener<Id, Data, T>>[];
|
var after = <HookedServiceEventListener<Id, Data, T>>[];
|
||||||
|
|
|
@ -24,13 +24,13 @@ import 'server.dart';
|
||||||
/// * `example.*` -> `/example\./[^$]*`
|
/// * `example.*` -> `/example\./[^$]*`
|
||||||
/// * `example.+` -> `/example\./[^$]+`
|
/// * `example.+` -> `/example\./[^$]+`
|
||||||
class HostnameRouter {
|
class HostnameRouter {
|
||||||
final Map<Pattern, Angel> _apps = {};
|
final Map<Pattern, Protevus> _apps = {};
|
||||||
final Map<Pattern, FutureOr<Angel> Function()> _creators = {};
|
final Map<Pattern, FutureOr<Protevus> Function()> _creators = {};
|
||||||
final List<Pattern> _patterns = [];
|
final List<Pattern> _patterns = [];
|
||||||
|
|
||||||
HostnameRouter(
|
HostnameRouter(
|
||||||
{Map<Pattern, Angel> apps = const {},
|
{Map<Pattern, Protevus> apps = const {},
|
||||||
Map<Pattern, FutureOr<Angel> Function()> creators = const {}}) {
|
Map<Pattern, FutureOr<Protevus> Function()> creators = const {}}) {
|
||||||
Map<Pattern, V> parseMap<V>(Map<Pattern, V> map) {
|
Map<Pattern, V> parseMap<V>(Map<Pattern, V> map) {
|
||||||
return map.map((p, c) {
|
return map.map((p, c) {
|
||||||
Pattern pp;
|
Pattern pp;
|
||||||
|
@ -55,16 +55,16 @@ class HostnameRouter {
|
||||||
}
|
}
|
||||||
|
|
||||||
factory HostnameRouter.configure(
|
factory HostnameRouter.configure(
|
||||||
Map<Pattern, FutureOr<void> Function(Angel)> configurers,
|
Map<Pattern, FutureOr<void> Function(Protevus)> configurers,
|
||||||
{Reflector reflector = const EmptyReflector(),
|
{Reflector reflector = const EmptyReflector(),
|
||||||
AngelEnvironment environment = angelEnv,
|
ProtevusEnvironment environment = angelEnv,
|
||||||
Logger? logger,
|
Logger? logger,
|
||||||
bool allowMethodOverrides = true,
|
bool allowMethodOverrides = true,
|
||||||
FutureOr<String> Function(dynamic)? serializer,
|
FutureOr<String> Function(dynamic)? serializer,
|
||||||
ViewGenerator? viewGenerator}) {
|
ViewGenerator? viewGenerator}) {
|
||||||
var creators = configurers.map((p, c) {
|
var creators = configurers.map((p, c) {
|
||||||
return MapEntry(p, () async {
|
return MapEntry(p, () async {
|
||||||
var app = Angel(
|
var app = Protevus(
|
||||||
reflector: reflector,
|
reflector: reflector,
|
||||||
environment: environment,
|
environment: environment,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
|
|
|
@ -72,7 +72,7 @@ class MapService extends Service<String?, Map<String, dynamic>> {
|
||||||
Future<Map<String, dynamic>> read(String? id,
|
Future<Map<String, dynamic>> read(String? id,
|
||||||
[Map<String, dynamic>? params]) {
|
[Map<String, dynamic>? params]) {
|
||||||
return Future.value(items.firstWhere(_matchesId(id),
|
return Future.value(items.firstWhere(_matchesId(id),
|
||||||
orElse: (() => throw AngelHttpException.notFound(
|
orElse: (() => throw ProtevusHttpException.notFound(
|
||||||
message: 'No record found for ID $id'))));
|
message: 'No record found for ID $id'))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ class MapService extends Service<String?, Map<String, dynamic>> {
|
||||||
|
|
||||||
return read(id).then((old) {
|
return read(id).then((old) {
|
||||||
if (!items.remove(old)) {
|
if (!items.remove(old)) {
|
||||||
throw AngelHttpException.notFound(
|
throw ProtevusHttpException.notFound(
|
||||||
message: 'No record found for ID $id');
|
message: 'No record found for ID $id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ class MapService extends Service<String?, Map<String, dynamic>> {
|
||||||
// Remove everything...
|
// Remove everything...
|
||||||
if (!(allowRemoveAll == true ||
|
if (!(allowRemoveAll == true ||
|
||||||
params?.containsKey('provider') != true)) {
|
params?.containsKey('provider') != true)) {
|
||||||
throw AngelHttpException.forbidden(
|
throw ProtevusHttpException.forbidden(
|
||||||
message: 'Clients are not allowed to delete all items.');
|
message: 'Clients are not allowed to delete all items.');
|
||||||
} else {
|
} else {
|
||||||
items.clear();
|
items.clear();
|
||||||
|
@ -164,7 +164,7 @@ class MapService extends Service<String?, Map<String, dynamic>> {
|
||||||
if (items.remove(result)) {
|
if (items.remove(result)) {
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
throw AngelHttpException.notFound(
|
throw ProtevusHttpException.notFound(
|
||||||
message: 'No record found for ID $id');
|
message: 'No record found for ID $id');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -103,15 +103,15 @@ class Parameter {
|
||||||
/// Returns an error that can be thrown when the parameter is not present.
|
/// Returns an error that can be thrown when the parameter is not present.
|
||||||
Object? get error {
|
Object? get error {
|
||||||
if (cookie?.isNotEmpty == true) {
|
if (cookie?.isNotEmpty == true) {
|
||||||
return AngelHttpException.badRequest(
|
return ProtevusHttpException.badRequest(
|
||||||
message: 'Missing required cookie "$cookie".');
|
message: 'Missing required cookie "$cookie".');
|
||||||
}
|
}
|
||||||
if (header?.isNotEmpty == true) {
|
if (header?.isNotEmpty == true) {
|
||||||
return AngelHttpException.badRequest(
|
return ProtevusHttpException.badRequest(
|
||||||
message: 'Missing required header "$header".');
|
message: 'Missing required header "$header".');
|
||||||
}
|
}
|
||||||
if (query?.isNotEmpty == true) {
|
if (query?.isNotEmpty == true) {
|
||||||
return AngelHttpException.badRequest(
|
return ProtevusHttpException.badRequest(
|
||||||
message: 'Missing required query parameter "$query".');
|
message: 'Missing required query parameter "$query".');
|
||||||
}
|
}
|
||||||
if (session?.isNotEmpty == true) {
|
if (session?.isNotEmpty == true) {
|
||||||
|
|
|
@ -18,13 +18,13 @@ import 'package:logging/logging.dart';
|
||||||
import 'metadata.dart';
|
import 'metadata.dart';
|
||||||
import 'response_context.dart';
|
import 'response_context.dart';
|
||||||
import 'routable.dart';
|
import 'routable.dart';
|
||||||
import 'server.dart' show Angel;
|
import 'server.dart' show Protevus;
|
||||||
|
|
||||||
part 'injection.dart';
|
part 'injection.dart';
|
||||||
|
|
||||||
/// A convenience wrapper around an incoming [RawRequest].
|
/// A convenience wrapper around an incoming [RawRequest].
|
||||||
abstract class RequestContext<RawRequest> {
|
abstract class RequestContext<RawRequest> {
|
||||||
/// Similar to [Angel.shutdownHooks], allows for logic to be executed
|
/// Similar to [Protevus.shutdownHooks], allows for logic to be executed
|
||||||
/// when a [RequestContext] is done being processed.
|
/// when a [RequestContext] is done being processed.
|
||||||
final _log = Logger('RequestContext');
|
final _log = Logger('RequestContext');
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@ abstract class RequestContext<RawRequest> {
|
||||||
/// Additional params to be passed to services.
|
/// Additional params to be passed to services.
|
||||||
final Map<String, dynamic> serviceParams = {};
|
final Map<String, dynamic> serviceParams = {};
|
||||||
|
|
||||||
/// The [Angel] instance that is responding to this request.
|
/// The [Protevus] instance that is responding to this request.
|
||||||
Angel? app;
|
Protevus? app;
|
||||||
|
|
||||||
/// Any cookies sent with this request.
|
/// Any cookies sent with this request.
|
||||||
List<Cookie> get cookies => <Cookie>[];
|
List<Cookie> get cookies => <Cookie>[];
|
||||||
|
|
|
@ -13,7 +13,7 @@ import 'package:mime/mime.dart';
|
||||||
|
|
||||||
import 'controller.dart';
|
import 'controller.dart';
|
||||||
import 'request_context.dart';
|
import 'request_context.dart';
|
||||||
import 'server.dart' show Angel;
|
import 'server.dart' show Protevus;
|
||||||
|
|
||||||
final RegExp _straySlashes = RegExp(r'(^/+)|(/+$)');
|
final RegExp _straySlashes = RegExp(r'(^/+)|(/+$)');
|
||||||
|
|
||||||
|
@ -22,15 +22,15 @@ abstract class ResponseContext<RawResponse>
|
||||||
implements StreamConsumer<List<int>>, StreamSink<List<int>>, StringSink {
|
implements StreamConsumer<List<int>>, StreamSink<List<int>>, StringSink {
|
||||||
final Map properties = {};
|
final Map properties = {};
|
||||||
final CaseInsensitiveMap<String> _headers = CaseInsensitiveMap<String>.from(
|
final CaseInsensitiveMap<String> _headers = CaseInsensitiveMap<String>.from(
|
||||||
{'content-type': 'text/plain', 'server': 'Angel3'});
|
{'content-type': 'text/plain', 'server': 'Protevus'});
|
||||||
|
|
||||||
//final log = Logger('ResponseContext');
|
//final log = Logger('ResponseContext');
|
||||||
|
|
||||||
Completer? _done;
|
Completer? _done;
|
||||||
int _statusCode = 200;
|
int _statusCode = 200;
|
||||||
|
|
||||||
/// The [Angel] instance that is sending a response.
|
/// The [Protevus] instance that is sending a response.
|
||||||
Angel? app;
|
Protevus? app;
|
||||||
|
|
||||||
/// Is `Transfer-Encoding` chunked?
|
/// Is `Transfer-Encoding` chunked?
|
||||||
bool? chunked;
|
bool? chunked;
|
||||||
|
|
|
@ -21,20 +21,20 @@ import 'service.dart';
|
||||||
|
|
||||||
//final RegExp _straySlashes = RegExp(r'(^/+)|(/+$)');
|
//final RegExp _straySlashes = RegExp(r'(^/+)|(/+$)');
|
||||||
|
|
||||||
/// A function that configures an [Angel] server.
|
/// A function that configures an [Protevus] server.
|
||||||
typedef AngelConfigurer = FutureOr<void> Function(Angel app);
|
typedef ProtevusConfigurer = FutureOr<void> Function(Protevus app);
|
||||||
|
|
||||||
/// A function that asynchronously generates a view from the given path and data.
|
/// A function that asynchronously generates a view from the given path and data.
|
||||||
typedef ViewGenerator = FutureOr<String> Function(String path,
|
typedef ViewGenerator = FutureOr<String> Function(String path,
|
||||||
[Map<String, dynamic>? data]);
|
[Map<String, dynamic>? data]);
|
||||||
|
|
||||||
/// A function that handles error
|
/// A function that handles error
|
||||||
typedef AngelErrorHandler = dynamic Function(
|
typedef ProtevusErrorHandler = dynamic Function(
|
||||||
AngelHttpException e, RequestContext req, ResponseContext res);
|
ProtevusHttpException e, RequestContext req, ResponseContext res);
|
||||||
|
|
||||||
/// The default error handler for [Angel] server
|
/// The default error handler for [Protevus] server
|
||||||
Future<bool> _defaultErrorHandler(
|
Future<bool> _defaultErrorHandler(
|
||||||
AngelHttpException e, RequestContext req, ResponseContext res) async {
|
ProtevusHttpException e, RequestContext req, ResponseContext res) async {
|
||||||
if (!req.accepts('text/html', strict: true) &&
|
if (!req.accepts('text/html', strict: true) &&
|
||||||
(req.accepts('application/json') ||
|
(req.accepts('application/json') ||
|
||||||
req.accepts('application/javascript'))) {
|
req.accepts('application/javascript'))) {
|
||||||
|
@ -65,7 +65,7 @@ Logger _defaultLogger() {
|
||||||
|
|
||||||
if (rec.error != null) {
|
if (rec.error != null) {
|
||||||
var err = rec.error;
|
var err = rec.error;
|
||||||
if (err is AngelHttpException && err.statusCode != 500) return;
|
if (err is ProtevusHttpException && err.statusCode != 500) return;
|
||||||
print('${rec.message} \n');
|
print('${rec.message} \n');
|
||||||
print(rec.error);
|
print(rec.error);
|
||||||
if (rec.stackTrace != null) {
|
if (rec.stackTrace != null) {
|
||||||
|
@ -78,18 +78,18 @@ Logger _defaultLogger() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A powerful real-time/REST/MVC server class.
|
/// A powerful real-time/REST/MVC server class.
|
||||||
class Angel extends Routable {
|
class Protevus extends Routable {
|
||||||
static Future<String> _noViewEngineConfigured(String view, [Map? data]) =>
|
static Future<String> _noViewEngineConfigured(String view, [Map? data]) =>
|
||||||
Future.value('No view engine has been configured yet.');
|
Future.value('No view engine has been configured yet.');
|
||||||
|
|
||||||
final List<Angel> _children = [];
|
final List<Protevus> _children = [];
|
||||||
final Map<
|
final Map<
|
||||||
String,
|
String,
|
||||||
Tuple4<List, Map<String, dynamic>, ParseResult<RouteResult>,
|
Tuple4<List, Map<String, dynamic>, ParseResult<RouteResult>,
|
||||||
MiddlewarePipeline>> handlerCache = HashMap();
|
MiddlewarePipeline>> handlerCache = HashMap();
|
||||||
|
|
||||||
Router<RequestHandler>? _flattened;
|
Router<RequestHandler>? _flattened;
|
||||||
Angel? _parent;
|
Protevus? _parent;
|
||||||
|
|
||||||
/// A global Map of converters that can transform responses bodies.
|
/// A global Map of converters that can transform responses bodies.
|
||||||
final Map<String, Converter<List<int>, List<int>>> encoders = {};
|
final Map<String, Converter<List<int>, List<int>>> encoders = {};
|
||||||
|
@ -114,20 +114,20 @@ class Angel extends Routable {
|
||||||
bool allowMethodOverrides = true;
|
bool allowMethodOverrides = true;
|
||||||
|
|
||||||
/// All child application mounted on this instance.
|
/// All child application mounted on this instance.
|
||||||
List<Angel> get children => List<Angel>.unmodifiable(_children);
|
List<Protevus> get children => List<Protevus>.unmodifiable(_children);
|
||||||
|
|
||||||
final Map<Pattern, Controller> _controllers = {};
|
final Map<Pattern, Controller> _controllers = {};
|
||||||
|
|
||||||
/// A set of [Controller] objects that have been loaded into the application.
|
/// A set of [Controller] objects that have been loaded into the application.
|
||||||
Map<Pattern, Controller> get controllers => _controllers;
|
Map<Pattern, Controller> get controllers => _controllers;
|
||||||
|
|
||||||
/// The [AngelEnvironment] in which the application is running.
|
/// The [ProtevusEnvironment] in which the application is running.
|
||||||
///
|
///
|
||||||
/// By default, it is automatically inferred.
|
/// By default, it is automatically inferred.
|
||||||
final AngelEnvironment environment;
|
final ProtevusEnvironment environment;
|
||||||
|
|
||||||
/// Returns the parent instance of this application, if any.
|
/// Returns the parent instance of this application, if any.
|
||||||
Angel? get parent => _parent;
|
Protevus? get parent => _parent;
|
||||||
|
|
||||||
/// Outputs diagnostics and debug messages.
|
/// Outputs diagnostics and debug messages.
|
||||||
Logger _logger = _defaultLogger();
|
Logger _logger = _defaultLogger();
|
||||||
|
@ -145,12 +145,12 @@ class Angel extends Routable {
|
||||||
/// Plug-ins to be called right before server startup.
|
/// Plug-ins to be called right before server startup.
|
||||||
///
|
///
|
||||||
/// If the server is never started, they will never be called.
|
/// If the server is never started, they will never be called.
|
||||||
final List<AngelConfigurer> startupHooks = [];
|
final List<ProtevusConfigurer> startupHooks = [];
|
||||||
|
|
||||||
/// Plug-ins to be called right before server shutdown.
|
/// Plug-ins to be called right before server shutdown.
|
||||||
///
|
///
|
||||||
/// If the server is never [close]d, they will never be called.
|
/// If the server is never [close]d, they will never be called.
|
||||||
final List<AngelConfigurer> shutdownHooks = [];
|
final List<ProtevusConfigurer> shutdownHooks = [];
|
||||||
|
|
||||||
/// Always run before responses are sent.
|
/// Always run before responses are sent.
|
||||||
///
|
///
|
||||||
|
@ -162,8 +162,8 @@ class Angel extends Routable {
|
||||||
/// Called by [ResponseContext]@`render`.
|
/// Called by [ResponseContext]@`render`.
|
||||||
ViewGenerator? viewGenerator = _noViewEngineConfigured;
|
ViewGenerator? viewGenerator = _noViewEngineConfigured;
|
||||||
|
|
||||||
/// The handler currently configured to run on [AngelHttpException]s.
|
/// The handler currently configured to run on [ProtevusHttpException]s.
|
||||||
AngelErrorHandler errorHandler = _defaultErrorHandler;
|
ProtevusErrorHandler errorHandler = _defaultErrorHandler;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Route<RequestHandler> addRoute(
|
Route<RequestHandler> addRoute(
|
||||||
|
@ -189,7 +189,7 @@ class Angel extends Routable {
|
||||||
'This route will be ignored, and no requests will ever reach it.');
|
'This route will be ignored, and no requests will ever reach it.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (router is Angel) {
|
if (router is Protevus) {
|
||||||
router._parent = this;
|
router._parent = this;
|
||||||
_children.add(router);
|
_children.add(router);
|
||||||
}
|
}
|
||||||
|
@ -199,11 +199,11 @@ class Angel extends Routable {
|
||||||
|
|
||||||
/// Loads some base dependencies into the service container.
|
/// Loads some base dependencies into the service container.
|
||||||
void bootstrapContainer() {
|
void bootstrapContainer() {
|
||||||
if (runtimeType != Angel) {
|
if (runtimeType != Protevus) {
|
||||||
container.registerSingleton(this);
|
container.registerSingleton(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
container.registerSingleton<Angel>(this);
|
container.registerSingleton<Protevus>(this);
|
||||||
container.registerSingleton<Routable>(this);
|
container.registerSingleton<Routable>(this);
|
||||||
container.registerSingleton<Router>(this);
|
container.registerSingleton<Router>(this);
|
||||||
}
|
}
|
||||||
|
@ -358,8 +358,8 @@ class Angel extends Routable {
|
||||||
// return closureMirror.apply(args).reflectee;
|
// return closureMirror.apply(args).reflectee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies an [AngelConfigurer] to this instance.
|
/// Applies an [ProtevusConfigurer] to this instance.
|
||||||
Future configure(AngelConfigurer configurer) {
|
Future configure(ProtevusConfigurer configurer) {
|
||||||
return Future.sync(() => configurer(this));
|
return Future.sync(() => configurer(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,9 +394,9 @@ class Angel extends Routable {
|
||||||
'Features like controllers, constructor dependency injection, and `ioc` require reflection, '
|
'Features like controllers, constructor dependency injection, and `ioc` require reflection, '
|
||||||
'and will not work without it.\n\n'
|
'and will not work without it.\n\n'
|
||||||
'For more, see the documentation:\n'
|
'For more, see the documentation:\n'
|
||||||
'https://docs.angel-dart.dev/guides/dependency-injection#enabling-dart-mirrors-or-other-reflection';
|
'https://docs.protevus-dart.dev/guides/dependency-injection#enabling-dart-mirrors-or-other-reflection';
|
||||||
|
|
||||||
Angel(
|
Protevus(
|
||||||
{Reflector reflector =
|
{Reflector reflector =
|
||||||
const ThrowingReflector(errorMessage: _reflectionErrorMessage),
|
const ThrowingReflector(errorMessage: _reflectionErrorMessage),
|
||||||
this.environment = angelEnv,
|
this.environment = angelEnv,
|
||||||
|
|
|
@ -67,18 +67,18 @@ class Service<Id, Data> extends Routable {
|
||||||
/// Handlers that must run to ensure this service's functionality.
|
/// Handlers that must run to ensure this service's functionality.
|
||||||
List<RequestHandler> get bootstrappers => [];
|
List<RequestHandler> get bootstrappers => [];
|
||||||
|
|
||||||
/// The [Angel] app powering this service.
|
/// The [Protevus] app powering this service.
|
||||||
Angel? _app;
|
Protevus? _app;
|
||||||
|
|
||||||
Angel get app {
|
Protevus get app {
|
||||||
if (_app == null) {
|
if (_app == null) {
|
||||||
throw ArgumentError("Angel is not initialized");
|
throw ArgumentError("Angel is not initialized");
|
||||||
}
|
}
|
||||||
return _app!;
|
return _app!;
|
||||||
}
|
}
|
||||||
|
|
||||||
set app(Angel angel) {
|
set app(Protevus protevus) {
|
||||||
_app = angel;
|
_app = protevus;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get isAppActive => _app != null;
|
bool get isAppActive => _app != null;
|
||||||
|
@ -94,7 +94,7 @@ class Service<Id, Data> extends Routable {
|
||||||
|
|
||||||
_readData ??= (req, res) {
|
_readData ??= (req, res) {
|
||||||
if (req.bodyAsObject is! Data) {
|
if (req.bodyAsObject is! Data) {
|
||||||
throw AngelHttpException.badRequest(
|
throw ProtevusHttpException.badRequest(
|
||||||
message:
|
message:
|
||||||
'Invalid request body. Expected $Data; found ${req.bodyAsObject} instead.');
|
'Invalid request body. Expected $Data; found ${req.bodyAsObject} instead.');
|
||||||
} else {
|
} else {
|
||||||
|
@ -123,7 +123,7 @@ class Service<Id, Data> extends Routable {
|
||||||
String errorMessage = 'No record was found matching the given query.']) {
|
String errorMessage = 'No record was found matching the given query.']) {
|
||||||
return index(params).then((result) {
|
return index(params).then((result) {
|
||||||
if (result.isEmpty) {
|
if (result.isEmpty) {
|
||||||
throw AngelHttpException.notFound(message: errorMessage);
|
throw ProtevusHttpException.notFound(message: errorMessage);
|
||||||
} else {
|
} else {
|
||||||
return result.first;
|
return result.first;
|
||||||
}
|
}
|
||||||
|
@ -132,12 +132,12 @@ class Service<Id, Data> extends Routable {
|
||||||
|
|
||||||
/// Retrieves all resources.
|
/// Retrieves all resources.
|
||||||
Future<List<Data>> index([Map<String, dynamic>? params]) {
|
Future<List<Data>> index([Map<String, dynamic>? params]) {
|
||||||
throw AngelHttpException.methodNotAllowed();
|
throw ProtevusHttpException.methodNotAllowed();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves the desired resource.
|
/// Retrieves the desired resource.
|
||||||
Future<Data> read(Id id, [Map<String, dynamic>? params]) {
|
Future<Data> read(Id id, [Map<String, dynamic>? params]) {
|
||||||
throw AngelHttpException.methodNotAllowed();
|
throw ProtevusHttpException.methodNotAllowed();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads multiple resources at once.
|
/// Reads multiple resources at once.
|
||||||
|
@ -150,22 +150,22 @@ class Service<Id, Data> extends Routable {
|
||||||
|
|
||||||
/// Creates a resource.
|
/// Creates a resource.
|
||||||
Future<Data> create(Data data, [Map<String, dynamic>? params]) {
|
Future<Data> create(Data data, [Map<String, dynamic>? params]) {
|
||||||
throw AngelHttpException.methodNotAllowed();
|
throw ProtevusHttpException.methodNotAllowed();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Modifies a resource.
|
/// Modifies a resource.
|
||||||
Future<Data> modify(Id id, Data data, [Map<String, dynamic>? params]) {
|
Future<Data> modify(Id id, Data data, [Map<String, dynamic>? params]) {
|
||||||
throw AngelHttpException.methodNotAllowed();
|
throw ProtevusHttpException.methodNotAllowed();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Overwrites a resource.
|
/// Overwrites a resource.
|
||||||
Future<Data> update(Id id, Data data, [Map<String, dynamic>? params]) {
|
Future<Data> update(Id id, Data data, [Map<String, dynamic>? params]) {
|
||||||
throw AngelHttpException.methodNotAllowed();
|
throw ProtevusHttpException.methodNotAllowed();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the given resource.
|
/// Removes the given resource.
|
||||||
Future<Data> remove(Id id, [Map<String, dynamic>? params]) {
|
Future<Data> remove(Id id, [Map<String, dynamic>? params]) {
|
||||||
throw AngelHttpException.methodNotAllowed();
|
throw ProtevusHttpException.methodNotAllowed();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an [AnonymousService] that wraps over this one, and maps input and output
|
/// Creates an [AnonymousService] that wraps over this one, and maps input and output
|
||||||
|
@ -371,8 +371,8 @@ class Service<Id, Data> extends Routable {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// REST compliance
|
// REST compliance
|
||||||
put('/', (req, res) => throw AngelHttpException.notFound());
|
put('/', (req, res) => throw ProtevusHttpException.notFound());
|
||||||
patch('/', (req, res) => throw AngelHttpException.notFound());
|
patch('/', (req, res) => throw ProtevusHttpException.notFound());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Invoked when this service is wrapped within a [HookedService].
|
/// Invoked when this service is wrapped within a [HookedService].
|
||||||
|
|
|
@ -18,7 +18,7 @@ final RegExp _straySlashes = RegExp(r'(^/+)|(/+$)');
|
||||||
typedef ServerGeneratorType = Future<HttpServer> Function(dynamic, int);
|
typedef ServerGeneratorType = Future<HttpServer> Function(dynamic, int);
|
||||||
|
|
||||||
/// Adapts `dart:io`'s [HttpServer] to serve Angel.
|
/// Adapts `dart:io`'s [HttpServer] to serve Angel.
|
||||||
class AngelHttp extends Driver<HttpRequest, HttpResponse, HttpServer,
|
class ProtevusHttp extends Driver<HttpRequest, HttpResponse, HttpServer,
|
||||||
HttpRequestContext, HttpResponseContext> {
|
HttpRequestContext, HttpResponseContext> {
|
||||||
@override
|
@override
|
||||||
Uri get uri {
|
Uri get uri {
|
||||||
|
@ -26,22 +26,23 @@ class AngelHttp extends Driver<HttpRequest, HttpResponse, HttpServer,
|
||||||
scheme: 'http', host: server?.address.address, port: server?.port);
|
scheme: 'http', host: server?.address.address, port: server?.port);
|
||||||
}
|
}
|
||||||
|
|
||||||
AngelHttp._(super.app, super.serverGenerator, bool useZone)
|
ProtevusHttp._(super.app, super.serverGenerator, bool useZone)
|
||||||
: super(useZone: useZone);
|
: super(useZone: useZone);
|
||||||
|
|
||||||
factory AngelHttp(Angel app, {bool useZone = true}) {
|
factory ProtevusHttp(Protevus app, {bool useZone = true}) {
|
||||||
return AngelHttp._(app, HttpServer.bind, useZone);
|
return ProtevusHttp._(app, HttpServer.bind, useZone);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An instance mounted on a server started by the [serverGenerator].
|
/// An instance mounted on a server started by the [serverGenerator].
|
||||||
factory AngelHttp.custom(Angel app, ServerGeneratorType serverGenerator,
|
factory ProtevusHttp.custom(Protevus app, ServerGeneratorType serverGenerator,
|
||||||
{bool useZone = true, Map<String, String> headers = const {}}) {
|
{bool useZone = true, Map<String, String> headers = const {}}) {
|
||||||
return AngelHttp._(app, serverGenerator, useZone);
|
return ProtevusHttp._(app, serverGenerator, useZone);
|
||||||
}
|
}
|
||||||
|
|
||||||
factory AngelHttp.fromSecurityContext(Angel app, SecurityContext context,
|
factory ProtevusHttp.fromSecurityContext(
|
||||||
|
Protevus app, SecurityContext context,
|
||||||
{bool useZone = true}) {
|
{bool useZone = true}) {
|
||||||
return AngelHttp._(app, (address, int port) {
|
return ProtevusHttp._(app, (address, int port) {
|
||||||
return HttpServer.bindSecure(address, port, context);
|
return HttpServer.bindSecure(address, port, context);
|
||||||
}, useZone);
|
}, useZone);
|
||||||
}
|
}
|
||||||
|
@ -51,8 +52,8 @@ class AngelHttp extends Driver<HttpRequest, HttpResponse, HttpServer,
|
||||||
/// Provide paths to a certificate chain and server key (both .pem).
|
/// Provide paths to a certificate chain and server key (both .pem).
|
||||||
/// If no password is provided, a random one will be generated upon running
|
/// If no password is provided, a random one will be generated upon running
|
||||||
/// the server.
|
/// the server.
|
||||||
factory AngelHttp.secure(
|
factory ProtevusHttp.secure(
|
||||||
Angel app, String certificateChainPath, String serverKeyPath,
|
Protevus app, String certificateChainPath, String serverKeyPath,
|
||||||
{String? password, bool useZone = true}) {
|
{String? password, bool useZone = true}) {
|
||||||
var certificateChain =
|
var certificateChain =
|
||||||
Platform.script.resolve(certificateChainPath).toFilePath();
|
Platform.script.resolve(certificateChainPath).toFilePath();
|
||||||
|
@ -61,7 +62,8 @@ class AngelHttp extends Driver<HttpRequest, HttpResponse, HttpServer,
|
||||||
serverContext.useCertificateChain(certificateChain, password: password);
|
serverContext.useCertificateChain(certificateChain, password: password);
|
||||||
serverContext.usePrivateKey(serverKey, password: password);
|
serverContext.usePrivateKey(serverKey, password: password);
|
||||||
|
|
||||||
return AngelHttp.fromSecurityContext(app, serverContext, useZone: useZone);
|
return ProtevusHttp.fromSecurityContext(app, serverContext,
|
||||||
|
useZone: useZone);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future handleRequest(HttpRequest request) =>
|
Future handleRequest(HttpRequest request) =>
|
||||||
|
|
|
@ -77,7 +77,7 @@ class HttpRequestContext extends RequestContext<HttpRequest?> {
|
||||||
|
|
||||||
/// Magically transforms an [HttpRequest] into a [RequestContext].
|
/// Magically transforms an [HttpRequest] into a [RequestContext].
|
||||||
static Future<HttpRequestContext> from(
|
static Future<HttpRequestContext> from(
|
||||||
HttpRequest request, Angel app, String path) {
|
HttpRequest request, Protevus app, String path) {
|
||||||
var ctx = HttpRequestContext().._container = app.container.createChild();
|
var ctx = HttpRequestContext().._container = app.container.createChild();
|
||||||
|
|
||||||
var override = request.method;
|
var override = request.method;
|
||||||
|
|
|
@ -18,7 +18,7 @@ class HttpResponseContext extends ResponseContext<HttpResponse> {
|
||||||
final HttpRequestContext? _correspondingRequest;
|
final HttpRequestContext? _correspondingRequest;
|
||||||
bool _isDetached = false, _isClosed = false, _streamInitialized = false;
|
bool _isDetached = false, _isClosed = false, _streamInitialized = false;
|
||||||
|
|
||||||
HttpResponseContext(this.rawResponse, Angel? app,
|
HttpResponseContext(this.rawResponse, Protevus? app,
|
||||||
[this._correspondingRequest]) {
|
[this._correspondingRequest]) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,19 +16,19 @@ Future<SecureServerSocket> startSharedHttp2(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adapts `package:http2`'s [ServerTransportConnection] to serve Angel.
|
/// Adapts `package:http2`'s [ServerTransportConnection] to serve Angel.
|
||||||
class AngelHttp2 extends Driver<Socket, ServerTransportStream,
|
class ProtevusHttp2 extends Driver<Socket, ServerTransportStream,
|
||||||
SecureServerSocket, Http2RequestContext, Http2ResponseContext> {
|
SecureServerSocket, Http2RequestContext, Http2ResponseContext> {
|
||||||
final ServerSettings? settings;
|
final ServerSettings? settings;
|
||||||
late AngelHttp _http;
|
late ProtevusHttp _http;
|
||||||
final StreamController<HttpRequest> _onHttp1 = StreamController();
|
final StreamController<HttpRequest> _onHttp1 = StreamController();
|
||||||
final Map<String, MockHttpSession> _sessions = {};
|
final Map<String, MockHttpSession> _sessions = {};
|
||||||
final Uuid _uuid = Uuid();
|
final Uuid _uuid = Uuid();
|
||||||
_AngelHttp2ServerSocket? _artificial;
|
_ProtevusHttp2ServerSocket? _artificial;
|
||||||
|
|
||||||
SecureServerSocket? get socket => _artificial;
|
SecureServerSocket? get socket => _artificial;
|
||||||
|
|
||||||
AngelHttp2._(
|
ProtevusHttp2._(
|
||||||
Angel app,
|
Protevus app,
|
||||||
Future<SecureServerSocket> Function(dynamic, int) serverGenerator,
|
Future<SecureServerSocket> Function(dynamic, int) serverGenerator,
|
||||||
bool useZone,
|
bool useZone,
|
||||||
bool allowHttp1,
|
bool allowHttp1,
|
||||||
|
@ -39,21 +39,21 @@ class AngelHttp2 extends Driver<Socket, ServerTransportStream,
|
||||||
useZone: useZone,
|
useZone: useZone,
|
||||||
) {
|
) {
|
||||||
if (allowHttp1) {
|
if (allowHttp1) {
|
||||||
_http = AngelHttp(app, useZone: useZone);
|
_http = ProtevusHttp(app, useZone: useZone);
|
||||||
onHttp1.listen(_http.handleRequest);
|
onHttp1.listen(_http.handleRequest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
factory AngelHttp2(Angel app, SecurityContext securityContext,
|
factory ProtevusHttp2(Protevus app, SecurityContext securityContext,
|
||||||
{bool useZone = true,
|
{bool useZone = true,
|
||||||
bool allowHttp1 = false,
|
bool allowHttp1 = false,
|
||||||
ServerSettings? settings}) {
|
ServerSettings? settings}) {
|
||||||
return AngelHttp2.custom(app, securityContext, SecureServerSocket.bind,
|
return ProtevusHttp2.custom(app, securityContext, SecureServerSocket.bind,
|
||||||
allowHttp1: allowHttp1, settings: settings);
|
allowHttp1: allowHttp1, settings: settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
factory AngelHttp2.custom(
|
factory ProtevusHttp2.custom(
|
||||||
Angel app,
|
Protevus app,
|
||||||
SecurityContext ctx,
|
SecurityContext ctx,
|
||||||
Future<SecureServerSocket> Function(
|
Future<SecureServerSocket> Function(
|
||||||
InternetAddress? address, int port, SecurityContext ctx)
|
InternetAddress? address, int port, SecurityContext ctx)
|
||||||
|
@ -61,7 +61,7 @@ class AngelHttp2 extends Driver<Socket, ServerTransportStream,
|
||||||
{bool useZone = true,
|
{bool useZone = true,
|
||||||
bool allowHttp1 = false,
|
bool allowHttp1 = false,
|
||||||
ServerSettings? settings}) {
|
ServerSettings? settings}) {
|
||||||
return AngelHttp2._(app, (address, port) {
|
return ProtevusHttp2._(app, (address, port) {
|
||||||
var addr = address is InternetAddress
|
var addr = address is InternetAddress
|
||||||
? address
|
? address
|
||||||
: InternetAddress(address.toString());
|
: InternetAddress(address.toString());
|
||||||
|
@ -75,7 +75,7 @@ class AngelHttp2 extends Driver<Socket, ServerTransportStream,
|
||||||
@override
|
@override
|
||||||
Future<SecureServerSocket> generateServer([address, int? port]) async {
|
Future<SecureServerSocket> generateServer([address, int? port]) async {
|
||||||
var s = await serverGenerator(address ?? '127.0.0.1', port ?? 0);
|
var s = await serverGenerator(address ?? '127.0.0.1', port ?? 0);
|
||||||
return _artificial = _AngelHttp2ServerSocket(s, this);
|
return _artificial = _ProtevusHttp2ServerSocket(s, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -158,13 +158,13 @@ class AngelHttp2 extends Driver<Socket, ServerTransportStream,
|
||||||
}
|
}
|
||||||
|
|
||||||
class _FakeServerSocket extends Stream<Socket> implements ServerSocket {
|
class _FakeServerSocket extends Stream<Socket> implements ServerSocket {
|
||||||
final _AngelHttp2ServerSocket angel;
|
final _ProtevusHttp2ServerSocket protevus;
|
||||||
final _ctrl = StreamController<Socket>();
|
final _ctrl = StreamController<Socket>();
|
||||||
|
|
||||||
_FakeServerSocket(this.angel);
|
_FakeServerSocket(this.protevus);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InternetAddress get address => angel.address;
|
InternetAddress get address => protevus.address;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<ServerSocket> close() async {
|
Future<ServerSocket> close() async {
|
||||||
|
@ -173,7 +173,7 @@ class _FakeServerSocket extends Stream<Socket> implements ServerSocket {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get port => angel.port;
|
int get port => protevus.port;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
StreamSubscription<Socket> listen(void Function(Socket event)? onData,
|
StreamSubscription<Socket> listen(void Function(Socket event)? onData,
|
||||||
|
@ -183,15 +183,15 @@ class _FakeServerSocket extends Stream<Socket> implements ServerSocket {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _AngelHttp2ServerSocket extends Stream<SecureSocket>
|
class _ProtevusHttp2ServerSocket extends Stream<SecureSocket>
|
||||||
implements SecureServerSocket {
|
implements SecureServerSocket {
|
||||||
final SecureServerSocket socket;
|
final SecureServerSocket socket;
|
||||||
final AngelHttp2 driver;
|
final ProtevusHttp2 driver;
|
||||||
final _ctrl = StreamController<SecureSocket>();
|
final _ctrl = StreamController<SecureSocket>();
|
||||||
late _FakeServerSocket _fake;
|
late _FakeServerSocket _fake;
|
||||||
StreamSubscription? _sub;
|
StreamSubscription? _sub;
|
||||||
|
|
||||||
_AngelHttp2ServerSocket(this.socket, this.driver) {
|
_ProtevusHttp2ServerSocket(this.socket, this.driver) {
|
||||||
_fake = _FakeServerSocket(this);
|
_fake = _FakeServerSocket(this);
|
||||||
HttpServer.listenOn(_fake).pipe(driver._onHttp1);
|
HttpServer.listenOn(_fake).pipe(driver._onHttp1);
|
||||||
_sub = socket.listen(
|
_sub = socket.listen(
|
||||||
|
|
|
@ -31,7 +31,7 @@ class Http2RequestContext extends RequestContext<ServerTransportStream?> {
|
||||||
static Future<Http2RequestContext> from(
|
static Future<Http2RequestContext> from(
|
||||||
ServerTransportStream stream,
|
ServerTransportStream stream,
|
||||||
Socket socket,
|
Socket socket,
|
||||||
Angel app,
|
Protevus app,
|
||||||
Map<String, MockHttpSession> sessions,
|
Map<String, MockHttpSession> sessions,
|
||||||
Uuid uuid) {
|
Uuid uuid) {
|
||||||
var c = Completer<Http2RequestContext>();
|
var c = Completer<Http2RequestContext>();
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Http2ResponseContext extends ResponseContext<ServerTransportStream> {
|
||||||
|
|
||||||
Uri? _targetUri;
|
Uri? _targetUri;
|
||||||
|
|
||||||
Http2ResponseContext(Angel? app, this.stream, this._req) {
|
Http2ResponseContext(Protevus? app, this.stream, this._req) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
_targetUri = _req?.uri;
|
_targetUri = _req?.uri;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ import 'package:angel3_framework/angel3_framework.dart';
|
||||||
import 'package:angel3_framework/http.dart';
|
import 'package:angel3_framework/http.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
var app = Angel();
|
var app = Protevus();
|
||||||
var http = AngelHttp.custom(app, startShared, useZone: false);
|
var http = ProtevusHttp.custom(app, startShared, useZone: false);
|
||||||
|
|
||||||
app.get('/', (req, res) => res.write('Hello, world!'));
|
app.get('/', (req, res) => res.write('Hello, world!'));
|
||||||
app.optimizeForProduction(force: true);
|
app.optimizeForProduction(force: true);
|
||||||
|
|
|
@ -2,7 +2,7 @@ name: angel3_framework
|
||||||
version: 8.4.0
|
version: 8.4.0
|
||||||
description: A high-powered HTTP server extensible framework with dependency injection, routing and much more.
|
description: A high-powered HTTP server extensible framework with dependency injection, routing and much more.
|
||||||
homepage: https://angel3-framework.web.app/
|
homepage: https://angel3-framework.web.app/
|
||||||
repository: https://github.com/dart-backend/angel/tree/master/packages/framework
|
repository: https://github.com/dart-backend/protevus/tree/master/packages/framework
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.3.0 <4.0.0'
|
sdk: '>=3.3.0 <4.0.0'
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
|
@ -64,7 +64,7 @@ Future<RequestContext> acceptContentTypes(
|
||||||
var rq = MockHttpRequest('GET', endpoint, persistentConnection: false);
|
var rq = MockHttpRequest('GET', endpoint, persistentConnection: false);
|
||||||
rq.headers.set('accept', headerString);
|
rq.headers.set('accept', headerString);
|
||||||
rq.close();
|
rq.close();
|
||||||
var app = Angel(reflector: MirrorsReflector());
|
var app = Protevus(reflector: MirrorsReflector());
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
return http.createRequestContext(rq, rq.response);
|
return http.createRequestContext(rq, rq.response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,21 +23,21 @@ void main() {
|
||||||
var svc = AnonymousService();
|
var svc = AnonymousService();
|
||||||
await svc.read(1);
|
await svc.read(1);
|
||||||
throw 'Should have thrown 405!';
|
throw 'Should have thrown 405!';
|
||||||
} on AngelHttpException {
|
} on ProtevusHttpException {
|
||||||
// print('Ok!');
|
// print('Ok!');
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
var svc = AnonymousService();
|
var svc = AnonymousService();
|
||||||
await svc.modify(2, null);
|
await svc.modify(2, null);
|
||||||
throw 'Should have thrown 405!';
|
throw 'Should have thrown 405!';
|
||||||
} on AngelHttpException {
|
} on ProtevusHttpException {
|
||||||
// print('Ok!');
|
// print('Ok!');
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
var svc = AnonymousService();
|
var svc = AnonymousService();
|
||||||
await svc.update(3, null);
|
await svc.update(3, null);
|
||||||
throw 'Should have thrown 405!';
|
throw 'Should have thrown 405!';
|
||||||
} on AngelHttpException {
|
} on ProtevusHttpException {
|
||||||
// print('Ok!');
|
// print('Ok!');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,8 +7,8 @@ import 'package:angel3_mock_request/angel3_mock_request.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
var app = Angel();
|
var app = Protevus();
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
|
|
||||||
Future<RequestContext> request(
|
Future<RequestContext> request(
|
||||||
{bool asJson = true,
|
{bool asJson = true,
|
||||||
|
|
|
@ -70,7 +70,7 @@ bool bar(RequestContext req, ResponseContext res) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late Angel app;
|
late Protevus app;
|
||||||
late TodoController todoController;
|
late TodoController todoController;
|
||||||
late NoExposeController noExposeCtrl;
|
late NoExposeController noExposeCtrl;
|
||||||
late HttpServer server;
|
late HttpServer server;
|
||||||
|
@ -78,7 +78,7 @@ void main() {
|
||||||
String? url;
|
String? url;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
app = Angel(reflector: MirrorsReflector());
|
app = Protevus(reflector: MirrorsReflector());
|
||||||
app.get(
|
app.get(
|
||||||
'/redirect',
|
'/redirect',
|
||||||
(req, res) async =>
|
(req, res) async =>
|
||||||
|
@ -95,7 +95,7 @@ void main() {
|
||||||
noExposeCtrl = await app.mountController<NoExposeController>();
|
noExposeCtrl = await app.mountController<NoExposeController>();
|
||||||
|
|
||||||
// Place controller in group. The applyRoutes() call, however, is async.
|
// Place controller in group. The applyRoutes() call, however, is async.
|
||||||
// Until https://github.com/angel-dart/route/issues/28 is closed,
|
// Until https://github.com/protevus-dart/route/issues/28 is closed,
|
||||||
// this will need to be done by manually mounting the router.
|
// this will need to be done by manually mounting the router.
|
||||||
var subRouter = Router<RequestHandler>();
|
var subRouter = Router<RequestHandler>();
|
||||||
await todoController.applyRoutes(subRouter, app.container.reflector);
|
await todoController.applyRoutes(subRouter, app.container.reflector);
|
||||||
|
@ -104,7 +104,7 @@ void main() {
|
||||||
print(app.controllers);
|
print(app.controllers);
|
||||||
app.dumpTree();
|
app.dumpTree();
|
||||||
|
|
||||||
server = await AngelHttp(app).startServer();
|
server = await ProtevusHttp(app).startServer();
|
||||||
url = 'http://${server.address.address}:${server.port}';
|
url = 'http://${server.address.address}:${server.port}';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -118,20 +118,20 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('create dynamic handler', () async {
|
test('create dynamic handler', () async {
|
||||||
var app = Angel(reflector: MirrorsReflector());
|
var app = Protevus(reflector: MirrorsReflector());
|
||||||
app.get(
|
app.get(
|
||||||
'/foo',
|
'/foo',
|
||||||
ioc(({String? bar}) {
|
ioc(({String? bar}) {
|
||||||
return 2;
|
return 2;
|
||||||
}, optional: ['bar']));
|
}, optional: ['bar']));
|
||||||
var rq = MockHttpRequest('GET', Uri(path: 'foo'));
|
var rq = MockHttpRequest('GET', Uri(path: 'foo'));
|
||||||
await AngelHttp(app).handleRequest(rq);
|
await ProtevusHttp(app).handleRequest(rq);
|
||||||
var body = await utf8.decoder.bind(rq.response).join();
|
var body = await utf8.decoder.bind(rq.response).join();
|
||||||
expect(json.decode(body), 2);
|
expect(json.decode(body), 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('optional name', () async {
|
test('optional name', () async {
|
||||||
var app = Angel(reflector: MirrorsReflector());
|
var app = Protevus(reflector: MirrorsReflector());
|
||||||
await app.configure(NamedController().configureServer);
|
await app.configure(NamedController().configureServer);
|
||||||
expect(app.controllers['foo'], const IsInstanceOf<NamedController>());
|
expect(app.controllers['foo'], const IsInstanceOf<NamedController>());
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,11 +5,11 @@ import 'package:angel3_mock_request/angel3_mock_request.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late AngelHttp http;
|
late ProtevusHttp http;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
var app = Angel();
|
var app = Protevus();
|
||||||
http = AngelHttp(app);
|
http = ProtevusHttp(app);
|
||||||
|
|
||||||
app.get('/detach', (req, res) async {
|
app.get('/detach', (req, res) async {
|
||||||
if (res is HttpResponseContext) {
|
if (res is HttpResponseContext) {
|
||||||
|
|
|
@ -15,13 +15,13 @@ final String sampleText = 'make your bed';
|
||||||
final String sampleOver = 'never';
|
final String sampleOver = 'never';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late Angel app;
|
late Protevus app;
|
||||||
late http.Client client;
|
late http.Client client;
|
||||||
late HttpServer server;
|
late HttpServer server;
|
||||||
String? url;
|
String? url;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
app = Angel(reflector: MirrorsReflector());
|
app = Protevus(reflector: MirrorsReflector());
|
||||||
client = http.Client();
|
client = http.Client();
|
||||||
|
|
||||||
// Inject some todos
|
// Inject some todos
|
||||||
|
@ -41,7 +41,7 @@ void main() {
|
||||||
await app.configure(SingletonController().configureServer);
|
await app.configure(SingletonController().configureServer);
|
||||||
await app.configure(ErrandController().configureServer);
|
await app.configure(ErrandController().configureServer);
|
||||||
|
|
||||||
server = await AngelHttp(app).startServer();
|
server = await ProtevusHttp(app).startServer();
|
||||||
url = 'http://${server.address.host}:${server.port}';
|
url = 'http://${server.address.host}:${server.port}';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('runContained with custom container', () async {
|
test('runContained with custom container', () async {
|
||||||
var app = Angel();
|
var app = Protevus();
|
||||||
var c = Container(const MirrorsReflector());
|
var c = Container(const MirrorsReflector());
|
||||||
c.registerSingleton(Todo(text: 'Hey!'));
|
c.registerSingleton(Todo(text: 'Hey!'));
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ void main() {
|
||||||
var rq = MockHttpRequest('GET', Uri(path: '/'));
|
var rq = MockHttpRequest('GET', Uri(path: '/'));
|
||||||
await rq.close();
|
await rq.close();
|
||||||
var rs = rq.response;
|
var rs = rq.response;
|
||||||
await AngelHttp(app).handleRequest(rq);
|
await ProtevusHttp(app).handleRequest(rq);
|
||||||
var text = await rs.transform(utf8.decoder).join();
|
var text = await rs.transform(utf8.decoder).join();
|
||||||
expect(text, json.encode('Hey!'));
|
expect(text, json.encode('Hey!'));
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,10 +17,10 @@ Future<List<int>> getBody(MockHttpResponse rs) async {
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late Angel app;
|
late Protevus app;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
app = Angel(reflector: MirrorsReflector());
|
app = Protevus(reflector: MirrorsReflector());
|
||||||
app.encoders.addAll(
|
app.encoders.addAll(
|
||||||
{
|
{
|
||||||
'deflate': zlib.encoder,
|
'deflate': zlib.encoder,
|
||||||
|
@ -40,14 +40,14 @@ void main() {
|
||||||
encodingTests(() => app);
|
encodingTests(() => app);
|
||||||
}
|
}
|
||||||
|
|
||||||
void encodingTests(Angel Function() getApp) {
|
void encodingTests(Protevus Function() getApp) {
|
||||||
group('encoding', () {
|
group('encoding', () {
|
||||||
Angel app;
|
Protevus app;
|
||||||
late AngelHttp http;
|
late ProtevusHttp http;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
app = getApp();
|
app = getApp();
|
||||||
http = AngelHttp(app);
|
http = ProtevusHttp(app);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('sends plaintext if no accept-encoding', () async {
|
test('sends plaintext if no accept-encoding', () async {
|
||||||
|
|
|
@ -3,16 +3,17 @@ import 'package:angel3_framework/angel3_framework.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('custom value', () => expect(AngelEnvironment('hey').value, 'hey'));
|
test('custom value', () => expect(ProtevusEnvironment('hey').value, 'hey'));
|
||||||
|
|
||||||
test('lowercases', () => expect(AngelEnvironment('HeY').value, 'hey'));
|
test('lowercases', () => expect(ProtevusEnvironment('HeY').value, 'hey'));
|
||||||
test(
|
test(
|
||||||
'default to env or development',
|
'default to env or development',
|
||||||
() => expect(AngelEnvironment().value,
|
() => expect(ProtevusEnvironment().value,
|
||||||
(Platform.environment['ANGEL_ENV'] ?? 'development').toLowerCase()));
|
(Platform.environment['ANGEL_ENV'] ?? 'development').toLowerCase()));
|
||||||
test('isDevelopment',
|
test('isDevelopment',
|
||||||
() => expect(AngelEnvironment('development').isDevelopment, true));
|
() => expect(ProtevusEnvironment('development').isDevelopment, true));
|
||||||
test('isStaging', () => expect(AngelEnvironment('staging').isStaging, true));
|
test('isStaging',
|
||||||
|
() => expect(ProtevusEnvironment('staging').isStaging, true));
|
||||||
test('isDevelopment',
|
test('isDevelopment',
|
||||||
() => expect(AngelEnvironment('production').isProduction, true));
|
() => expect(ProtevusEnvironment('production').isProduction, true));
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,43 +4,46 @@ import 'package:test/test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('named constructors', () {
|
test('named constructors', () {
|
||||||
expect(
|
expect(ProtevusHttpException.badRequest(),
|
||||||
AngelHttpException.badRequest(), isException(400, '400 Bad Request'));
|
isException(400, '400 Bad Request'));
|
||||||
expect(AngelHttpException.notAuthenticated(),
|
expect(ProtevusHttpException.notAuthenticated(),
|
||||||
isException(401, '401 Not Authenticated'));
|
isException(401, '401 Not Authenticated'));
|
||||||
expect(AngelHttpException.paymentRequired(),
|
expect(ProtevusHttpException.paymentRequired(),
|
||||||
isException(402, '402 Payment Required'));
|
isException(402, '402 Payment Required'));
|
||||||
expect(AngelHttpException.forbidden(), isException(403, '403 Forbidden'));
|
|
||||||
expect(AngelHttpException.notFound(), isException(404, '404 Not Found'));
|
|
||||||
expect(AngelHttpException.methodNotAllowed(),
|
|
||||||
isException(405, '405 Method Not Allowed'));
|
|
||||||
expect(AngelHttpException.notAcceptable(),
|
|
||||||
isException(406, '406 Not Acceptable'));
|
|
||||||
expect(AngelHttpException.methodTimeout(), isException(408, '408 Timeout'));
|
|
||||||
expect(AngelHttpException.conflict(), isException(409, '409 Conflict'));
|
|
||||||
expect(AngelHttpException.notProcessable(),
|
|
||||||
isException(422, '422 Not Processable'));
|
|
||||||
expect(AngelHttpException.notImplemented(),
|
|
||||||
isException(501, '501 Not Implemented'));
|
|
||||||
expect(
|
expect(
|
||||||
AngelHttpException.unavailable(), isException(503, '503 Unavailable'));
|
ProtevusHttpException.forbidden(), isException(403, '403 Forbidden'));
|
||||||
|
expect(ProtevusHttpException.notFound(), isException(404, '404 Not Found'));
|
||||||
|
expect(ProtevusHttpException.methodNotAllowed(),
|
||||||
|
isException(405, '405 Method Not Allowed'));
|
||||||
|
expect(ProtevusHttpException.notAcceptable(),
|
||||||
|
isException(406, '406 Not Acceptable'));
|
||||||
|
expect(
|
||||||
|
ProtevusHttpException.methodTimeout(), isException(408, '408 Timeout'));
|
||||||
|
expect(ProtevusHttpException.conflict(), isException(409, '409 Conflict'));
|
||||||
|
expect(ProtevusHttpException.notProcessable(),
|
||||||
|
isException(422, '422 Not Processable'));
|
||||||
|
expect(ProtevusHttpException.notImplemented(),
|
||||||
|
isException(501, '501 Not Implemented'));
|
||||||
|
expect(ProtevusHttpException.unavailable(),
|
||||||
|
isException(503, '503 Unavailable'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('fromMap', () {
|
test('fromMap', () {
|
||||||
expect(AngelHttpException.fromMap({'status_code': -1, 'message': 'ok'}),
|
expect(ProtevusHttpException.fromMap({'status_code': -1, 'message': 'ok'}),
|
||||||
isException(-1, 'ok'));
|
isException(-1, 'ok'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('toMap = toJson', () {
|
test('toMap = toJson', () {
|
||||||
var exc = AngelHttpException.badRequest();
|
var exc = ProtevusHttpException.badRequest();
|
||||||
expect(exc.toMap(), exc.toJson());
|
expect(exc.toMap(), exc.toJson());
|
||||||
var json_ = json.encode(exc.toJson());
|
var json_ = json.encode(exc.toJson());
|
||||||
var exc2 = AngelHttpException.fromJson(json_);
|
var exc2 = ProtevusHttpException.fromJson(json_);
|
||||||
expect(exc2.toJson(), exc.toJson());
|
expect(exc2.toJson(), exc.toJson());
|
||||||
});
|
});
|
||||||
|
|
||||||
test('toString', () {
|
test('toString', () {
|
||||||
expect(AngelHttpException(statusCode: 420, message: 'Blaze It').toString(),
|
expect(
|
||||||
|
ProtevusHttpException(statusCode: 420, message: 'Blaze It').toString(),
|
||||||
'420: Blaze It');
|
'420: Blaze It');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -60,7 +63,7 @@ class _IsException extends Matcher {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool matches(item, Map matchState) {
|
bool matches(item, Map matchState) {
|
||||||
return item is AngelHttpException &&
|
return item is ProtevusHttpException &&
|
||||||
item.statusCode == statusCode &&
|
item.statusCode == statusCode &&
|
||||||
item.message == message;
|
item.message == message;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ void main() {
|
||||||
|
|
||||||
Future<RequestContext> makeRequest(String path) {
|
Future<RequestContext> makeRequest(String path) {
|
||||||
var rq = MockHttpRequest('GET', endpoint.replace(path: path))..close();
|
var rq = MockHttpRequest('GET', endpoint.replace(path: path))..close();
|
||||||
var app = Angel(reflector: MirrorsReflector());
|
var app = Protevus(reflector: MirrorsReflector());
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
return http.createRequestContext(rq, rq.response);
|
return http.createRequestContext(rq, rq.response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import 'common.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
var throwsAnAngelHttpException =
|
var throwsAnAngelHttpException =
|
||||||
throwsA(const IsInstanceOf<AngelHttpException>());
|
throwsA(const IsInstanceOf<ProtevusHttpException>());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
test('throw 404 on null', () {
|
test('throw 404 on null', () {
|
||||||
|
|
|
@ -7,18 +7,18 @@ import 'package:http/http.dart' as http;
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late Angel app;
|
late Protevus app;
|
||||||
late http.Client client;
|
late http.Client client;
|
||||||
late HttpServer server;
|
late HttpServer server;
|
||||||
late String url;
|
late String url;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
app = Angel(reflector: MirrorsReflector())
|
app = Protevus(reflector: MirrorsReflector())
|
||||||
..post('/foo', (req, res) => res.serialize({'hello': 'world'}))
|
..post('/foo', (req, res) => res.serialize({'hello': 'world'}))
|
||||||
..all('*', (req, res) => throw AngelHttpException.notFound());
|
..all('*', (req, res) => throw ProtevusHttpException.notFound());
|
||||||
client = http.Client();
|
client = http.Client();
|
||||||
|
|
||||||
server = await AngelHttp(app).startServer();
|
server = await ProtevusHttp(app).startServer();
|
||||||
url = 'http://${server.address.host}:${server.port}';
|
url = 'http://${server.address.host}:${server.port}';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -13,14 +13,14 @@ void main() {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
};
|
};
|
||||||
|
|
||||||
late Angel app;
|
late Protevus app;
|
||||||
late HttpServer server;
|
late HttpServer server;
|
||||||
late String url;
|
late String url;
|
||||||
late http.Client client;
|
late http.Client client;
|
||||||
late HookedService todoService;
|
late HookedService todoService;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
app = Angel(reflector: MirrorsReflector());
|
app = Protevus(reflector: MirrorsReflector());
|
||||||
client = http.Client();
|
client = http.Client();
|
||||||
app.use('/todos', MapService());
|
app.use('/todos', MapService());
|
||||||
app.use('/books', BookService());
|
app.use('/books', BookService());
|
||||||
|
@ -36,7 +36,7 @@ void main() {
|
||||||
throw e.error as Object;
|
throw e.error as Object;
|
||||||
};
|
};
|
||||||
|
|
||||||
server = await AngelHttp(app).startServer();
|
server = await ProtevusHttp(app).startServer();
|
||||||
url = 'http://${server.address.host}:${server.port}';
|
url = 'http://${server.address.host}:${server.port}';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ void main() {
|
||||||
..listen((HookedServiceEvent event) async {
|
..listen((HookedServiceEvent event) async {
|
||||||
// Hooks can be Futures ;)
|
// Hooks can be Futures ;)
|
||||||
event.cancel([
|
event.cancel([
|
||||||
{'angel': 'framework'}
|
{'protevus': 'framework'}
|
||||||
]);
|
]);
|
||||||
})
|
})
|
||||||
..listen((HookedServiceEvent event) {
|
..listen((HookedServiceEvent event) {
|
||||||
|
@ -93,13 +93,13 @@ void main() {
|
||||||
var response = await client.get(Uri.parse('$url/todos'));
|
var response = await client.get(Uri.parse('$url/todos'));
|
||||||
print(response.body);
|
print(response.body);
|
||||||
var result = json.decode(response.body) as List;
|
var result = json.decode(response.body) as List;
|
||||||
expect(result[0]['angel'], equals('framework'));
|
expect(result[0]['protevus'], equals('framework'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('asStream() fires', () async {
|
test('asStream() fires', () async {
|
||||||
var stream = todoService.afterCreated.asStream();
|
var stream = todoService.afterCreated.asStream();
|
||||||
await todoService.create({'angel': 'framework'});
|
await todoService.create({'protevus': 'framework'});
|
||||||
expect(await stream.first.then((e) => e.result['angel']), 'framework');
|
expect(await stream.first.then((e) => e.result['protevus']), 'framework');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('metadata', () async {
|
test('metadata', () async {
|
||||||
|
|
|
@ -25,14 +25,15 @@ Stream<List<int>> jfkStream() {
|
||||||
void main() {
|
void main() {
|
||||||
var client = Http2Client();
|
var client = Http2Client();
|
||||||
late IOClient h1c;
|
late IOClient h1c;
|
||||||
Angel app;
|
Protevus app;
|
||||||
late AngelHttp2 http2;
|
late ProtevusHttp2 http2;
|
||||||
late Uri serverRoot;
|
late Uri serverRoot;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
app = Angel(reflector: MirrorsReflector())..encoders['gzip'] = gzip.encoder;
|
app = Protevus(reflector: MirrorsReflector())
|
||||||
|
..encoders['gzip'] = gzip.encoder;
|
||||||
hierarchicalLoggingEnabled = true;
|
hierarchicalLoggingEnabled = true;
|
||||||
app.logger = Logger.detached('angel.http2')
|
app.logger = Logger.detached('protevus.http2')
|
||||||
..onRecord.listen((rec) {
|
..onRecord.listen((rec) {
|
||||||
print(rec);
|
print(rec);
|
||||||
if (rec.error == null) return;
|
if (rec.error == null) return;
|
||||||
|
@ -52,7 +53,7 @@ void main() {
|
||||||
app.get('/stream', (req, res) => jfkStream().pipe(res));
|
app.get('/stream', (req, res) => jfkStream().pipe(res));
|
||||||
|
|
||||||
app.get('/headers', (req, res) async {
|
app.get('/headers', (req, res) async {
|
||||||
res.headers.addAll({'foo': 'bar', 'x-angel': 'http2'});
|
res.headers.addAll({'foo': 'bar', 'x-protevus': 'http2'});
|
||||||
await res.close();
|
await res.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -105,7 +106,7 @@ void main() {
|
||||||
// Create an HTTP client that trusts our server.
|
// Create an HTTP client that trusts our server.
|
||||||
h1c = IOClient(HttpClient()..badCertificateCallback = (_, __, ___) => true);
|
h1c = IOClient(HttpClient()..badCertificateCallback = (_, __, ___) => true);
|
||||||
|
|
||||||
http2 = AngelHttp2(app, ctx, allowHttp1: true);
|
http2 = ProtevusHttp2(app, ctx, allowHttp1: true);
|
||||||
|
|
||||||
var server = await http2.startServer();
|
var server = await http2.startServer();
|
||||||
serverRoot = Uri.parse('https://127.0.0.1:${server.port}');
|
serverRoot = Uri.parse('https://127.0.0.1:${server.port}');
|
||||||
|
@ -183,7 +184,7 @@ void main() {
|
||||||
test('headers sent', () async {
|
test('headers sent', () async {
|
||||||
var response = await client.get(serverRoot.replace(path: '/headers'));
|
var response = await client.get(serverRoot.replace(path: '/headers'));
|
||||||
expect(response.headers['foo'], 'bar');
|
expect(response.headers['foo'], 'bar');
|
||||||
expect(response.headers['x-angel'], 'http2');
|
expect(response.headers['x-protevus'], 'http2');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('server push', () async {
|
test('server push', () async {
|
||||||
|
@ -287,7 +288,7 @@ void main() {
|
||||||
rq.fields['foo'] = 'bar';
|
rq.fields['foo'] = 'bar';
|
||||||
rq.files.add(http.MultipartFile(
|
rq.files.add(http.MultipartFile(
|
||||||
'file', Stream.fromIterable([utf8.encode('hello world')]), 11,
|
'file', Stream.fromIterable([utf8.encode('hello world')]), 11,
|
||||||
contentType: MediaType('angel', 'framework')));
|
contentType: MediaType('protevus', 'framework')));
|
||||||
|
|
||||||
var response = await client.send(rq);
|
var response = await client.send(rq);
|
||||||
var responseBody = await response.stream.transform(utf8.decoder).join();
|
var responseBody = await response.stream.transform(utf8.decoder).join();
|
||||||
|
@ -296,7 +297,7 @@ void main() {
|
||||||
responseBody,
|
responseBody,
|
||||||
json.encode([
|
json.encode([
|
||||||
11,
|
11,
|
||||||
'angel/framework',
|
'protevus/framework',
|
||||||
{'foo': 'bar'}
|
{'foo': 'bar'}
|
||||||
]));
|
]));
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,7 +9,7 @@ import 'pretty_log.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late http.IOClient client;
|
late http.IOClient client;
|
||||||
late AngelHttp driver;
|
late ProtevusHttp driver;
|
||||||
late Logger logger;
|
late Logger logger;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
|
@ -20,7 +20,7 @@ void main() {
|
||||||
..level = Level.ALL
|
..level = Level.ALL
|
||||||
..onRecord.listen(prettyLog);
|
..onRecord.listen(prettyLog);
|
||||||
|
|
||||||
var app = Angel(logger: logger);
|
var app = Protevus(logger: logger);
|
||||||
|
|
||||||
app.fallback(hello);
|
app.fallback(hello);
|
||||||
app.fallback(throw404);
|
app.fallback(throw404);
|
||||||
|
@ -40,7 +40,7 @@ void main() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
driver = AngelHttp(app);
|
driver = ProtevusHttp(app);
|
||||||
await driver.startServer();
|
await driver.startServer();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -76,5 +76,5 @@ Future<void> hello(RequestContext req, ResponseContext res) {
|
||||||
void throw404(RequestContext req, ResponseContext res) {
|
void throw404(RequestContext req, ResponseContext res) {
|
||||||
Zone.current
|
Zone.current
|
||||||
.handleUncaughtError('This 404 should not occur.', StackTrace.current);
|
.handleUncaughtError('This 404 should not occur.', StackTrace.current);
|
||||||
throw AngelHttpException.notFound();
|
throw ProtevusHttpException.notFound();
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue