From 11b7b6159edfc12340296639b51bb69a79497abe Mon Sep 17 00:00:00 2001 From: Tobe O Date: Tue, 2 Oct 2018 11:32:06 -0400 Subject: [PATCH] 2.0.0-alpha.1 --- CHANGELOG.md | 4 +++ lib/angel_websocket.dart | 8 +++--- lib/base_websocket_client.dart | 45 +++++++++++++++++----------------- lib/browser.dart | 3 ++- lib/flutter.dart | 2 +- lib/io.dart | 3 ++- lib/server.dart | 11 +++++---- pubspec.yaml | 4 ++- test/auth_test.dart | 8 +++--- test/service/browser_test.dart | 2 +- test/service/common.dart | 3 ++- web/main.dart | 2 +- 12 files changed, 53 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4110e2b..dddbe931 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 2.0.0-alpha.1 +* Refactorings for updated Angel 2 versions. +* Remove `package:dart2_constant`. + # 2.0.0-alpha * Depend on Dart 2 and Angel 2. diff --git a/lib/angel_websocket.dart b/lib/angel_websocket.dart index b45078c4..0a3a652b 100644 --- a/lib/angel_websocket.dart +++ b/lib/angel_websocket.dart @@ -45,8 +45,8 @@ class WebSocketEvent { WebSocketEvent({String this.eventName, this.data}); - factory WebSocketEvent.fromJson(Map data) => - new WebSocketEvent(eventName: data['eventName'].toString(), data: data['data']); + factory WebSocketEvent.fromJson(Map data) => new WebSocketEvent( + eventName: data['eventName'].toString(), data: data['data']); Map toJson() { return {'eventName': eventName, 'data': data}; @@ -58,7 +58,7 @@ class WebSocketAction { String id; String eventName; var data; - var params; + Map params; WebSocketAction( {String this.id, String this.eventName, this.data, this.params}); @@ -67,7 +67,7 @@ class WebSocketAction { id: data['id'].toString(), eventName: data['eventName'].toString(), data: data['data'], - params: data['params']); + params: data['params'] as Map); Map toJson() { return {'id': id, 'eventName': eventName, 'data': data, 'params': params}; diff --git a/lib/base_websocket_client.dart b/lib/base_websocket_client.dart index a4870ecb..1f200b31 100644 --- a/lib/base_websocket_client.dart +++ b/lib/base_websocket_client.dart @@ -1,9 +1,9 @@ import 'dart:async'; import 'dart:collection'; +import 'dart:convert'; import 'package:angel_client/angel_client.dart'; import 'package:angel_client/base_angel_client.dart'; import 'package:angel_http_exception/angel_http_exception.dart'; -import 'package:dart2_constant/convert.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; @@ -159,7 +159,8 @@ abstract class BaseWebSocketClient extends BaseAngelClient { } if (event.eventName == EVENT_ERROR) { - var error = new AngelHttpException.fromMap((event.data ?? {}) as Map); + var error = + new AngelHttpException.fromMap((event.data ?? {}) as Map); _onError.add(error); } else if (event.eventName == EVENT_AUTHENTICATED) { var authResult = new AngelAuthResult.fromMap(event.data as Map); @@ -240,18 +241,12 @@ class WebSocketsService extends Service { final StreamController _onAllEvents = new StreamController(); - final StreamController _onIndexed = - new StreamController(); - final StreamController _onRead = - new StreamController(); - final StreamController _onCreated = - new StreamController(); - final StreamController _onModified = - new StreamController(); - final StreamController _onUpdated = - new StreamController(); - final StreamController _onRemoved = - new StreamController(); + final StreamController _onIndexed = new StreamController(); + final StreamController _onRead = new StreamController(); + final StreamController _onCreated = new StreamController(); + final StreamController _onModified = new StreamController(); + final StreamController _onUpdated = new StreamController(); + final StreamController _onRemoved = new StreamController(); /// Fired on all events. Stream get onAllEvents => _onAllEvents.stream; @@ -340,21 +335,23 @@ class WebSocketsService extends Service { } @override - Future index([Map params]) async { + Future index([Map params]) async { app.sendAction(new WebSocketAction( eventName: '$path::${ACTION_INDEX}', params: params ?? {})); return null; } @override - Future read(id, [Map params]) async { + Future read(id, [Map params]) async { app.sendAction(new WebSocketAction( - eventName: '$path::${ACTION_READ}', id: id.toString(), params: params ?? {})); + eventName: '$path::${ACTION_READ}', + id: id.toString(), + params: params ?? {})); return null; } @override - Future create(data, [Map params]) async { + Future create(data, [Map params]) async { app.sendAction(new WebSocketAction( eventName: '$path::${ACTION_CREATE}', data: data, @@ -363,7 +360,7 @@ class WebSocketsService extends Service { } @override - Future modify(id, data, [Map params]) async { + Future modify(id, data, [Map params]) async { app.sendAction(new WebSocketAction( eventName: '$path::${ACTION_MODIFY}', id: id.toString(), @@ -373,7 +370,7 @@ class WebSocketsService extends Service { } @override - Future update(id, data, [Map params]) async { + Future update(id, data, [Map params]) async { app.sendAction(new WebSocketAction( eventName: '$path::${ACTION_UPDATE}', id: id.toString(), @@ -383,9 +380,11 @@ class WebSocketsService extends Service { } @override - Future remove(id, [Map params]) async { + Future remove(id, [Map params]) async { app.sendAction(new WebSocketAction( - eventName: '$path::${ACTION_REMOVE}', id: id.toString(), params: params ?? {})); + eventName: '$path::${ACTION_REMOVE}', + id: id.toString(), + params: params ?? {})); return null; } @@ -411,4 +410,4 @@ class WebSocketExtraneousEventHandler { return _events[index].stream; } -} \ No newline at end of file +} diff --git a/lib/browser.dart b/lib/browser.dart index 2a35596f..3e64fca2 100644 --- a/lib/browser.dart +++ b/lib/browser.dart @@ -75,7 +75,8 @@ class WebSockets extends BaseWebSocketClient { return completer.complete(new HtmlWebSocketChannel(socket)); }) ..onError.listen((e) { - if (!completer.isCompleted) return completer.completeError(e is ErrorEvent ? e.error : e); + if (!completer.isCompleted) + return completer.completeError(e is ErrorEvent ? e.error : e); }); return completer.future; diff --git a/lib/flutter.dart b/lib/flutter.dart index 37d00350..263e50ed 100644 --- a/lib/flutter.dart +++ b/lib/flutter.dart @@ -41,4 +41,4 @@ class WebSockets extends BaseWebSocketClient { : {}); return new IOWebSocketChannel(socket); } -} \ No newline at end of file +} diff --git a/lib/io.dart b/lib/io.dart index d791f588..02baef5d 100644 --- a/lib/io.dart +++ b/lib/io.dart @@ -59,7 +59,8 @@ class WebSockets extends BaseWebSocketClient { class IoWebSocketsService extends WebSocketsService { final Type type; - IoWebSocketsService(WebSocketChannel socket, WebSockets app, String uri, this.type) + IoWebSocketsService( + WebSocketChannel socket, WebSockets app, String uri, this.type) : super(socket, app, uri); @override diff --git a/lib/server.dart b/lib/server.dart index 17b89085..2dbcf198 100644 --- a/lib/server.dart +++ b/lib/server.dart @@ -2,11 +2,11 @@ library angel_websocket.server; import 'dart:async'; +import 'dart:convert'; import 'dart:io'; import 'dart:mirrors'; import 'package:angel_auth/angel_auth.dart'; import 'package:angel_framework/angel_framework.dart'; -import 'package:dart2_constant/convert.dart'; import 'package:json_god/json_god.dart' as god; import 'package:merge_map/merge_map.dart'; import 'package:web_socket_channel/io.dart'; @@ -132,7 +132,7 @@ class AngelWebSocket { return null; } - var service = app.service(split[0]); + var service = app.findService(split[0]); if (service == null) { socket.sendError(new AngelHttpException.notFound( @@ -142,7 +142,7 @@ 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) @@ -151,8 +151,9 @@ class AngelWebSocket { action.params = {}; } - var params = mergeMap([ - ((deserializer ?? (params) => params)(action.params)) as Map, + var params = mergeMap([ + ((deserializer ?? (params) => params)(action.params)) + as Map, { "provider": Providers.websocket, '__requestctx': socket.request, diff --git a/pubspec.yaml b/pubspec.yaml index 5431df6a..1952d638 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: angel_websocket description: WebSocket plugin for Angel. environment: sdk: ">=2.0.0-dev <3.0.0" -version: 2.0.0-alpha +version: 2.0.0-alpha.1 author: Tobe O homepage: https://github.com/angel-dart/angel_websocket dependencies: @@ -16,5 +16,7 @@ dependencies: meta: ^1.0.0 web_socket_channel: ^1.0.0 dev_dependencies: + angel_container: ^1.0.0-alpha + angel_model: ^1.0.0 logging: ^0.11.0 test: ^1.0.0 diff --git a/test/auth_test.dart b/test/auth_test.dart index d4f6ba7d..d7dab90a 100644 --- a/test/auth_test.dart +++ b/test/auth_test.dart @@ -23,9 +23,11 @@ main() { auth.serializer = (_) async => 'baz'; auth.deserializer = (_) async => USER; - auth.strategies.add(new LocalAuthStrategy((username, password) async { - if (username == 'foo' && password == 'bar') return USER; - })); + auth.strategies['local'] = new LocalAuthStrategy( + (username, password) async { + if (username == 'foo' && password == 'bar') return USER; + }, + ); app.post('/auth/local', auth.authenticate('local')); diff --git a/test/service/browser_test.dart b/test/service/browser_test.dart index 2a91c878..b11d0664 100644 --- a/test/service/browser_test.dart +++ b/test/service/browser_test.dart @@ -2,4 +2,4 @@ import 'package:test/test.dart'; main() { group('service.browser', () {}); -} \ No newline at end of file +} diff --git a/test/service/common.dart b/test/service/common.dart index b3aa11e4..daae99d1 100644 --- a/test/service/common.dart +++ b/test/service/common.dart @@ -13,7 +13,8 @@ class Todo extends Model { class TodoService extends MapService { TodoService() : super() { - configuration['ws:filter'] = (HookedServiceEvent e, WebSocketContext socket) { + configuration['ws:filter'] = + (HookedServiceEvent e, WebSocketContext socket) { print('Hello, service filter world!'); return true; }; diff --git a/web/main.dart b/web/main.dart index 8cab522e..48bd1e27 100644 --- a/web/main.dart +++ b/web/main.dart @@ -9,4 +9,4 @@ main() { app.connect().catchError((_) { window.alert('no websocket'); }); -} \ No newline at end of file +}