From 49da5f76b10f4d58dd9c36932228672fc9515763 Mon Sep 17 00:00:00 2001 From: thomashii Date: Tue, 22 Feb 2022 08:07:01 +0800 Subject: [PATCH] Updated websocket,test and static --- packages/static/CHANGELOG.md | 8 +++ .../static/lib/src/virtual_directory.dart | 17 ++++--- packages/static/pubspec.yaml | 27 +++++++++- packages/test/CHANGELOG.md | 8 +++ packages/test/lib/src/client.dart | 6 +-- packages/test/lib/src/matchers.dart | 9 ++-- packages/test/pubspec.yaml | 36 ++++++++++--- packages/websocket/CHANGELOG.md | 8 +++ packages/websocket/example/main.dart | 2 +- packages/websocket/lib/angel3_websocket.dart | 8 +-- .../websocket/lib/base_websocket_client.dart | 11 ++-- packages/websocket/lib/browser.dart | 1 - packages/websocket/lib/constants.dart | 51 ------------------- packages/websocket/lib/hooks.dart | 4 +- packages/websocket/lib/server.dart | 40 +++++++-------- packages/websocket/lib/websocket_context.dart | 6 +-- .../websocket/lib/websocket_controller.dart | 2 +- packages/websocket/pubspec.yaml | 34 +++++++++---- 18 files changed, 152 insertions(+), 126 deletions(-) diff --git a/packages/static/CHANGELOG.md b/packages/static/CHANGELOG.md index c8207f95..11c797a6 100644 --- a/packages/static/CHANGELOG.md +++ b/packages/static/CHANGELOG.md @@ -1,5 +1,13 @@ # Change Log +## 6.0.0 + +* Updated to min SDK 2.15.x + +## 5.0.0 + +* No release. Skipped + ## 4.1.0 * Updated to use `belatuk_range_header` package diff --git a/packages/static/lib/src/virtual_directory.dart b/packages/static/lib/src/virtual_directory.dart index d2e6477f..0bcda945 100644 --- a/packages/static/lib/src/virtual_directory.dart +++ b/packages/static/lib/src/virtual_directory.dart @@ -265,10 +265,11 @@ class VirtualDirectory { if (!acceptable) { _log.severe('Mime type [$value] is not supported'); throw AngelHttpException( - UnsupportedError( - 'Client requested $value, but server wanted to send $mimeType.'), - statusCode: 406, - message: '406 Not Acceptable'); + //UnsupportedError( + // 'Client requested $value, but server wanted to send $mimeType.'), + errors: [ + 'Client requested $value, but server wanted to send $mimeType.' + ], statusCode: 406, message: '406 Not Acceptable'); } } @@ -320,7 +321,8 @@ class VirtualDirectory { if (invalid) { throw AngelHttpException( - Exception('Semantically invalid, or unbounded range.'), + //Exception('Semantically invalid, or unbounded range.'), + errors: ['Semantically invalid, or unbounded range.'], statusCode: 416, message: 'Semantically invalid, or unbounded range.'); } @@ -328,14 +330,15 @@ class VirtualDirectory { // Ensure it's within range. if (item.start >= totalFileSize || item.end >= totalFileSize) { throw AngelHttpException( - Exception('Given range $item is out of bounds.'), + //Exception('Given range $item is out of bounds.'), + errors: ['Given range $item is out of bounds.'], statusCode: 416, message: 'Given range $item is out of bounds.'); } } if (header.items.isEmpty) { - throw AngelHttpException(null, + throw AngelHttpException( statusCode: 416, message: '`Range` header may not be empty.'); } else if (header.items.length == 1) { var item = header.items[0]; diff --git a/packages/static/pubspec.yaml b/packages/static/pubspec.yaml index 9a5c8538..6963401e 100644 --- a/packages/static/pubspec.yaml +++ b/packages/static/pubspec.yaml @@ -6,7 +6,7 @@ repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/static environment: sdk: '>=2.15.0 <3.0.0' dependencies: - angel3_framework: ^4.1.0 + angel3_framework: ^6.0.0 belatuk_range_header: ^4.0.0 convert: ^3.0.0 crypto: ^3.0.1 @@ -15,9 +15,32 @@ dependencies: path: ^1.8.0 logging: ^1.0.1 dev_dependencies: - angel3_test: ^4.0.0 + angel3_test: ^6.0.0 http: ^0.13.2 matcher: ^0.12.10 lints: ^1.0.0 test: ^1.17.4 +dependency_overrides: + angel3_container: + path: ../container/angel_container + angel3_framework: + path: ../framework + angel3_http_exception: + path: ../http_exception + angel3_model: + path: ../model + angel3_route: + path: ../route + angel3_mock_request: + path: ../mock_request + angel3_auth: + path: ../auth + angel3_client: + path: ../client + angel3_websocket: + path: ../websocket + angel3_validate: + path: ../validate + angel3_test: + path: ../test diff --git a/packages/test/CHANGELOG.md b/packages/test/CHANGELOG.md index 446f118c..32511c31 100644 --- a/packages/test/CHANGELOG.md +++ b/packages/test/CHANGELOG.md @@ -1,5 +1,13 @@ # Change Log +## 6.0.0 + +* Updated to min SDK 2.15.x + +## 5.0.0 + +* No release. Skipped + ## 4.1.1 * Fixed NNBD issues diff --git a/packages/test/lib/src/client.dart b/packages/test/lib/src/client.dart index 29bf8e19..e7120fbd 100644 --- a/packages/test/lib/src/client.dart +++ b/packages/test/lib/src/client.dart @@ -2,7 +2,6 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; import 'package:angel3_client/base_angel_client.dart' as client; -import 'package:angel3_client/io.dart' as client; import 'package:angel3_framework/angel3_framework.dart'; import 'package:angel3_framework/http.dart'; import 'package:angel3_websocket/io.dart' as client; @@ -57,9 +56,6 @@ class TestClient extends client.BaseAngelClient { /// The server instance to mock. final Angel server; - @override - String? authToken; - late AngelHttp _http; TestClient(this.server, {this.autoDecodeGzip = true, bool useZone = false}) @@ -149,7 +145,7 @@ class TestClient extends client.BaseAngelClient { reasonPhrase: rs.reasonPhrase); } - @override + //@override late String basePath; @override diff --git a/packages/test/lib/src/matchers.dart b/packages/test/lib/src/matchers.dart index 86114b9f..9384f84f 100644 --- a/packages/test/lib/src/matchers.dart +++ b/packages/test/lib/src/matchers.dart @@ -1,7 +1,6 @@ import 'dart:convert'; import 'dart:io'; import 'package:http/http.dart' as http; -import 'package:matcher/matcher.dart'; import 'package:angel3_http_exception/angel3_http_exception.dart'; import 'package:angel3_validate/angel3_validate.dart'; @@ -43,7 +42,7 @@ Matcher hasStatus(int status) => _HasStatus(status); Matcher hasValidBody(Validator validator) => _HasValidBody(validator); class _IsJson extends Matcher { - var value; + dynamic value; _IsJson(this.value); @@ -59,7 +58,7 @@ class _IsJson extends Matcher { } class _HasBody extends Matcher { - final body; + final dynamic body; _HasBody(this.body); @@ -83,7 +82,7 @@ class _HasBody extends Matcher { } class _HasContentType extends Matcher { - var contentType; + dynamic contentType; _HasContentType(this.contentType); @@ -116,7 +115,7 @@ class _HasContentType extends Matcher { class _HasHeader extends Matcher { final String key; - final value; + final dynamic value; _HasHeader(this.key, this.value); diff --git a/packages/test/pubspec.yaml b/packages/test/pubspec.yaml index 97dcb9f2..1561afe9 100644 --- a/packages/test/pubspec.yaml +++ b/packages/test/pubspec.yaml @@ -6,17 +6,37 @@ repository: https://github.com/dukefirehawk/angel/tree/master/packages/test environment: sdk: '>=2.15.0 <3.0.0' dependencies: - angel3_client: ^4.1.0 - angel3_framework: ^4.2.0 - angel3_http_exception: ^3.0.0 - angel3_validate: ^4.0.0 - angel3_websocket: ^4.1.0 - angel3_mock_request: ^2.0.0 - angel3_container: ^3.1.0 + angel3_client: ^6.0.0 + angel3_framework: ^6.0.0 + angel3_http_exception: ^6.0.0 + angel3_validate: ^6.0.0 + angel3_websocket: ^6.0.0 + angel3_mock_request: ^6.0.0 + angel3_container: ^6.0.0 http: ^0.13.1 matcher: ^0.12.10 web_socket_channel: ^2.0.0 dev_dependencies: test: ^1.17.5 lints: ^1.0.0 - \ No newline at end of file +dependency_overrides: + angel3_container: + path: ../container/angel_container + angel3_framework: + path: ../framework + angel3_http_exception: + path: ../http_exception + angel3_model: + path: ../model + angel3_route: + path: ../route + angel3_mock_request: + path: ../mock_request + angel3_auth: + path: ../auth + angel3_client: + path: ../client + angel3_websocket: + path: ../websocket + angel3_validate: + path: ../validate \ No newline at end of file diff --git a/packages/websocket/CHANGELOG.md b/packages/websocket/CHANGELOG.md index 8e1a2c7e..7b0f06ea 100644 --- a/packages/websocket/CHANGELOG.md +++ b/packages/websocket/CHANGELOG.md @@ -1,5 +1,13 @@ # Change Log +## 6.0.0 + +* Updated to min SDK 2.15.x + +## 5.0.0 + +* No release. Skipped + ## 4.1.2 * Updated `package:angel3_container` diff --git a/packages/websocket/example/main.dart b/packages/websocket/example/main.dart index 6c9502c6..a3b3f721 100644 --- a/packages/websocket/example/main.dart +++ b/packages/websocket/example/main.dart @@ -38,7 +38,7 @@ void main(List args) async { try { ctx.setAlpnProtocols(['h2'], true); } catch (e, st) { - app.logger!.severe( + app.logger.severe( 'Cannot set ALPN protocol on server to `h2`. The server will only serve HTTP/1.x.', e, st, diff --git a/packages/websocket/lib/angel3_websocket.dart b/packages/websocket/lib/angel3_websocket.dart index 5aa38192..8b0979c0 100644 --- a/packages/websocket/lib/angel3_websocket.dart +++ b/packages/websocket/lib/angel3_websocket.dart @@ -28,16 +28,16 @@ class WebSocketEvent { class WebSocketAction { String? id; String? eventName; - var data; - Map? params; + dynamic data; + Map params; - WebSocketAction({this.id, this.eventName, this.data, this.params}); + WebSocketAction({this.id, this.eventName, this.data, this.params = const {}}); factory WebSocketAction.fromJson(Map data) => WebSocketAction( id: data['id'].toString(), eventName: data['eventName'].toString(), data: data['data'], - params: data['params'] as Map?); + params: data['params'] as Map? ?? {}); Map toJson() { return {'id': id, 'eventName': eventName, 'data': data, 'params': params}; diff --git a/packages/websocket/lib/base_websocket_client.dart b/packages/websocket/lib/base_websocket_client.dart index 6615b934..eb35446d 100644 --- a/packages/websocket/lib/base_websocket_client.dart +++ b/packages/websocket/lib/base_websocket_client.dart @@ -3,7 +3,6 @@ import 'dart:collection'; import 'dart:convert'; import 'package:angel3_client/angel3_client.dart'; import 'package:angel3_client/base_angel_client.dart'; -import 'package:angel3_http_exception/angel3_http_exception.dart'; import 'package:http/src/base_client.dart' as http; import 'package:web_socket_channel/web_socket_channel.dart'; import 'package:web_socket_channel/status.dart' as status; @@ -219,7 +218,7 @@ abstract class BaseWebSocketClient extends BaseAngelClient { _socket = null; if (reconnectOnClose == true) { Timer.periodic(reconnectInterval!, (Timer timer) async { - var result; + WebSocketChannel? result; try { result = await connect(timeout: reconnectInterval); @@ -434,10 +433,6 @@ class WebSocketsService extends Service { params: params ?? {})); return null; } - - /// No longer necessary. - @deprecated - Service unwrap() => this; } /// Contains a dynamic Map of [WebSocketEvent] streams. @@ -461,6 +456,8 @@ class WebSocketExtraneousEventHandler { } void _close() { - _events.values.forEach((s) => s.close()); + for (var s in _events.values) { + s.close(); + } } } diff --git a/packages/websocket/lib/browser.dart b/packages/websocket/lib/browser.dart index c79a9561..d69a5129 100644 --- a/packages/websocket/lib/browser.dart +++ b/packages/websocket/lib/browser.dart @@ -4,7 +4,6 @@ library angel3_websocket.browser; import 'dart:async'; import 'dart:html'; import 'package:angel3_client/angel3_client.dart'; -import 'package:angel3_http_exception/angel3_http_exception.dart'; import 'package:http/browser_client.dart' as http; import 'package:web_socket_channel/web_socket_channel.dart'; import 'package:web_socket_channel/html.dart'; diff --git a/packages/websocket/lib/constants.dart b/packages/websocket/lib/constants.dart index 7d455468..71d935f6 100644 --- a/packages/websocket/lib/constants.dart +++ b/packages/websocket/lib/constants.dart @@ -6,27 +6,6 @@ const String modifyAction = 'modify'; const String updateAction = 'update'; const String removeAction = 'remove'; -@deprecated -const String ACTION_AUTHENTICATE = authenticateAction; - -@deprecated -const String ACTION_INDEX = indexAction; - -@deprecated -const String ACTION_READ = readAction; - -@deprecated -const String ACTION_CREATE = createAction; - -@deprecated -const String ACTION_MODIFY = modifyAction; - -@deprecated -const String ACTION_UPDATE = updateAction; - -@deprecated -const String ACTION_REMOVE = removeAction; - const String authenticatedEvent = 'authenticated'; const String errorEvent = 'error'; const String indexedEvent = 'indexed'; @@ -36,30 +15,6 @@ const String modifiedEvent = 'modified'; const String updatedEvent = 'updated'; const String removedEvent = 'removed'; -@deprecated -const String EVENT_AUTHENTICATED = authenticatedEvent; - -@deprecated -const String EVENT_ERROR = errorEvent; - -@deprecated -const String EVENT_INDEXED = indexedEvent; - -@deprecated -const String EVENT_READ = readEvent; - -@deprecated -const String EVENT_CREATED = createdEvent; - -@deprecated -const String EVENT_MODIFIED = modifiedEvent; - -@deprecated -const String EVENT_UPDATED = updatedEvent; - -@deprecated -const String EVENT_REMOVED = removedEvent; - /// The standard Angel service actions. const List actions = [ indexAction, @@ -70,9 +25,6 @@ const List actions = [ removeAction ]; -@deprecated -const List ACTIONS = actions; - /// The standard Angel service events. const List events = [ indexedEvent, @@ -82,6 +34,3 @@ const List events = [ updatedEvent, removedEvent ]; - -@deprecated -const List EVENTS = events; diff --git a/packages/websocket/lib/hooks.dart b/packages/websocket/lib/hooks.dart index 0a87f931..61b9c307 100644 --- a/packages/websocket/lib/hooks.dart +++ b/packages/websocket/lib/hooks.dart @@ -6,8 +6,8 @@ import 'package:angel3_framework/angel3_framework.dart'; /// If [provider] is `null`, any provider will be blocked. HookedServiceEventListener doNotBroadcast([provider]) { return (HookedServiceEvent e) { - if (e.params != null && e.params!.containsKey('provider')) { - var eParam = e.params!; + if (e.params.containsKey('provider')) { + var eParam = e.params; var deny = false; var providers = provider is Iterable ? provider : [provider]; diff --git a/packages/websocket/lib/server.dart b/packages/websocket/lib/server.dart index fd293cba..c1cad069 100644 --- a/packages/websocket/lib/server.dart +++ b/packages/websocket/lib/server.dart @@ -10,11 +10,11 @@ import 'package:angel3_framework/angel3_framework.dart'; import 'package:angel3_framework/http.dart'; import 'package:angel3_framework/http2.dart'; import 'package:belatuk_merge_map/belatuk_merge_map.dart'; +import 'package:logging/logging.dart'; import 'package:stream_channel/stream_channel.dart'; import 'package:web_socket_channel/io.dart'; import 'package:web_socket_channel/web_socket_channel.dart'; import 'package:collection/collection.dart' show IterableExtension; -import 'package:logging/logging.dart'; import 'angel3_websocket.dart'; import 'constants.dart'; export 'angel3_websocket.dart'; @@ -27,8 +27,6 @@ typedef WebSocketResponseSerializer = String Function(dynamic data); /// Broadcasts events from [HookedService]s, and handles incoming [WebSocketAction]s. class AngelWebSocket { - final _log = Logger('AngelWebSocket'); - final List _clients = []; final List _servicesAlreadyWired = []; @@ -65,6 +63,8 @@ class AngelWebSocket { List get servicesAlreadyWired => List.unmodifiable(_servicesAlreadyWired); + Logger get _log => app.logger; + /// Used to notify other nodes of an event's firing. Good for scaled applications. final StreamChannel? synchronizationChannel; @@ -152,7 +152,7 @@ class AngelWebSocket { FutureOr Function(HookedServiceEvent e) serviceHook(String path) { return (HookedServiceEvent e) async { - if (e.params != null && e.params!['broadcast'] == false) return; + if (e.params['broadcast'] == false) return; var event = await transformEvent(e); event.eventName = '$path::${event.eventName}'; @@ -160,8 +160,8 @@ class AngelWebSocket { dynamic _filter(WebSocketContext socket) { if (e.service.configuration.containsKey('ws:filter')) { return e.service.configuration['ws:filter'](e, socket); - } else if (e.params != null && e.params!.containsKey('ws:filter')) { - return e.params?['ws:filter'](e, socket); + } else if (e.params.containsKey('ws:filter')) { + return e.params['ws:filter'](e, socket); } else { return true; } @@ -212,11 +212,11 @@ class AngelWebSocket { var actionName = split[1]; - if (action.params is! Map) action.params = {}; + //if (action.params is! Map) action.params = {}; if (allowClientParams != true) { - if (action.params!['query'] is Map) { - action.params = {'query': action.params!['query']}; + if (action.params['query'] is Map) { + action.params = {'query': action.params['query']}; } else { action.params = {}; } @@ -272,11 +272,11 @@ class AngelWebSocket { Future handleAuth(WebSocketAction action, WebSocketContext socket) async { if (allowAuth != false && action.eventName == authenticateAction && - action.params?['query'] is Map && - action.params?['query']['jwt'] is String) { + action.params['query'] is Map && + action.params['query']['jwt'] is String) { try { var auth = socket.request.container!.make(); - var jwt = action.params!['query']['jwt'] as String; + var jwt = action.params['query']['jwt'] as String; AuthToken token; token = AuthToken.validate(jwt, auth.hmac); @@ -330,7 +330,7 @@ class AngelWebSocket { throw AngelHttpException.badRequest(); } - if (fromJson is Map && fromJson.containsKey('eventName')) { + if (fromJson.containsKey('eventName')) { socket._onAction.add(WebSocketAction.fromJson(fromJson)); socket.on ._getStreamForEvent(fromJson['eventName'].toString())! @@ -361,16 +361,16 @@ class AngelWebSocket { // Send an error if (e is AngelHttpException) { socket.sendError(e); - app.logger?.severe(e.message, e.error ?? e, e.stackTrace); + app.logger.severe(e.message, e.error ?? e, e.stackTrace); } else if (sendErrors) { - var err = AngelHttpException(e, + var err = AngelHttpException( message: e.toString(), stackTrace: st, errors: [st.toString()]); socket.sendError(err); - app.logger?.severe(err.message, e, st); + app.logger.severe(err.message, e, st); } else { - var err = AngelHttpException(e); + var err = AngelHttpException(); socket.sendError(err); - app.logger?.severe(e.toString(), e, st); + app.logger.severe(e.toString(), e, st); } } @@ -391,10 +391,10 @@ class AngelWebSocket { /// Configures an [Angel] instance to listen for WebSocket connections. Future configureServer(Angel app) async { - app.container?.registerSingleton(this); + app.container.registerSingleton(this); if (runtimeType != AngelWebSocket) { - app.container?.registerSingleton(this); + app.container.registerSingleton(this); } // Set up services diff --git a/packages/websocket/lib/websocket_context.dart b/packages/websocket/lib/websocket_context.dart index e3681a91..08f9d96d 100644 --- a/packages/websocket/lib/websocket_context.dart +++ b/packages/websocket/lib/websocket_context.dart @@ -20,7 +20,7 @@ class WebSocketContext { final StreamController _onAuthenticated = StreamController(); - final StreamController _onClose = StreamController(); + final StreamController _onClose = StreamController(); final StreamController _onData = StreamController(); @@ -31,7 +31,7 @@ class WebSocketContext { Stream get onAuthenticated => _onAuthenticated.stream; /// Fired once the underlying [WebSocket] closes. - Stream get onClose => _onClose.stream; + Stream get onClose => _onClose.stream; /// Fired when any data is sent through [channel]. Stream get onData => _onData.stream; @@ -45,7 +45,7 @@ class WebSocketContext { await _onAction.close(); await _onAuthenticated.close(); await _onData.close(); - _onClose.add(null); + //_onClose.add(null); await _onClose.close(); }); } diff --git a/packages/websocket/lib/websocket_controller.dart b/packages/websocket/lib/websocket_controller.dart index 03e23b8b..7c683299 100644 --- a/packages/websocket/lib/websocket_controller.dart +++ b/packages/websocket/lib/websocket_controller.dart @@ -38,7 +38,7 @@ class WebSocketController extends Controller { @override Future configureServer(Angel app) async { - if (findExpose(app.container!.reflector) != null) { + if (findExpose(app.container.reflector) != null) { await super.configureServer(app); } diff --git a/packages/websocket/pubspec.yaml b/packages/websocket/pubspec.yaml index a81c298a..ef87d2f9 100644 --- a/packages/websocket/pubspec.yaml +++ b/packages/websocket/pubspec.yaml @@ -1,15 +1,15 @@ name: angel3_websocket -version: 4.1.2 +version: 6.0.0 description: This library provides WebSockets support for Angel3 framework. homepage: https://angel3-framework.web.app/ repository: https://github.com/dukefirehawk/angel/tree/master/packages/websocket environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.15.0 <3.0.0' dependencies: - angel3_auth: ^4.1.0 - angel3_client: ^4.1.0 - angel3_framework: ^4.2.0 - angel3_http_exception: ^3.0.0 + angel3_auth: ^6.0.0 + angel3_client: ^6.0.0 + angel3_framework: ^6.0.0 + angel3_http_exception: ^6.0.0 belatuk_merge_map: ^3.0.0 http: ^0.13.1 meta: ^1.3.0 @@ -18,8 +18,24 @@ dependencies: collection: ^1.15.0 logging: ^1.0.1 dev_dependencies: - angel3_container: ^3.1.0 - angel3_model: ^3.1.0 + angel3_container: ^6.0.0 + angel3_model: ^6.0.0 test: ^1.17.5 lints: ^1.0.0 - \ No newline at end of file +dependency_overrides: + angel3_container: + path: ../container/angel_container + angel3_framework: + path: ../framework + angel3_http_exception: + path: ../http_exception + angel3_model: + path: ../model + angel3_route: + path: ../route + angel3_mock_request: + path: ../mock_request + angel3_auth: + path: ../auth + angel3_client: + path: ../client \ No newline at end of file