From ddd5271d1f0c06f1abc8d8a68f68f453e07d260c Mon Sep 17 00:00:00 2001 From: Tobe O Date: Sun, 26 Aug 2018 18:41:01 -0400 Subject: [PATCH] 2.0.0-alpha --- .gitignore | 2 ++ CHANGELOG.md | 5 +++++ analysis_options.yaml | 3 ++- lib/angel_client.dart | 11 ++++++----- lib/auth_types.dart | 2 +- lib/base_angel_client.dart | 20 ++++++++++---------- lib/browser.dart | 7 ++++--- lib/flutter.dart | 5 +++-- lib/io.dart | 11 ++++++----- pubspec.yaml | 13 ++++++------- test/all_test.dart | 2 +- test/common.dart | 2 +- test/list_test.dart | 10 +++++++--- test/shared.dart | 4 +++- web/main.dart | 2 +- 15 files changed, 58 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index a84c50a4..7752ec67 100644 --- a/.gitignore +++ b/.gitignore @@ -77,3 +77,5 @@ jspm_packages # Yarn Integrity file .yarn-integrity + +.dart_tool \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index a303c0c6..866e5ba8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 2.0.0-alpha +* Depend on Dart 2. +* Depend on Angel 2. +* Remove `dart2_constant`. + # 1.2.0+2 * Code cleanup + housekeeping, update to `dart2_constant`, and ensured build works with `2.0.0-dev.64.1`. diff --git a/analysis_options.yaml b/analysis_options.yaml index 1325f758..3e203853 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,4 +1,5 @@ analyzer: - strong-mode: true + strong-mode: + implicit-casts: false exclude: - test/io_test.dart \ No newline at end of file diff --git a/lib/angel_client.dart b/lib/angel_client.dart index 2d75d071..2f89bd8f 100644 --- a/lib/angel_client.dart +++ b/lib/angel_client.dart @@ -3,7 +3,7 @@ library angel_client; import 'dart:async'; import 'package:collection/collection.dart'; -import 'package:dart2_constant/convert.dart'; +import 'dart:convert'; import 'package:http/src/response.dart' as http; export 'package:angel_http_exception/angel_http_exception.dart'; @@ -75,15 +75,16 @@ class AngelAuthResult { final result = new AngelAuthResult(); if (data is Map && data.containsKey('token') && data['token'] is String) - result._token = data['token']; + result._token = data['token'].toString(); - if (data is Map) result.data.addAll(data['data'] ?? {}); + if (data is Map) + result.data.addAll((data['data'] as Map) ?? {}); return result; } factory AngelAuthResult.fromJson(String s) => - new AngelAuthResult.fromMap(json.decode(s)); + new AngelAuthResult.fromMap(json.decode(s) as Map); Map toJson() { return {'token': token, 'data': data}; @@ -163,7 +164,7 @@ class ServiceList extends DelegatingList { var items = asPaginated == true ? data['data'] : data; this ..clear() - ..addAll(items); + ..addAll(items as Iterable); _onChange.add(this); })); diff --git a/lib/auth_types.dart b/lib/auth_types.dart index f51ca7d6..f28a06af 100644 --- a/lib/auth_types.dart +++ b/lib/auth_types.dart @@ -2,4 +2,4 @@ const String local = 'local'; /// Use [local] instead. @deprecated -const String LOCAL = local; \ No newline at end of file +const String LOCAL = local; diff --git a/lib/base_angel_client.dart b/lib/base_angel_client.dart index 67508b11..96fb0308 100644 --- a/lib/base_angel_client.dart +++ b/lib/base_angel_client.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'dart:convert' show Encoding; import 'package:angel_http_exception/angel_http_exception.dart'; -import 'package:dart2_constant/convert.dart'; +import 'dart:convert'; import 'package:http/src/base_client.dart' as http; import 'package:http/src/base_request.dart' as http; import 'package:http/src/request.dart' as http; @@ -77,7 +77,7 @@ abstract class BaseAngelClient extends Angel { if (credentials is String) token = credentials; else if (credentials is Map && credentials.containsKey('token')) - token = credentials['token']; + token = credentials['token'].toString(); if (token == null) { throw new ArgumentError( @@ -98,14 +98,14 @@ abstract class BaseAngelClient extends Angel { final v = json.decode(response.body); if (v is! Map || - !v.containsKey('data') || - !v.containsKey('token')) { + !(v as Map).containsKey('data') || + !(v as Map).containsKey('token')) { throw new AngelHttpException.notAuthenticated( message: "Auth endpoint '$url' did not return a proper response."); } - var r = new AngelAuthResult.fromMap(v); + var r = new AngelAuthResult.fromMap(v as Map); _onAuthenticated.add(r); return r; } on AngelHttpException { @@ -132,14 +132,14 @@ abstract class BaseAngelClient extends Angel { final v = json.decode(response.body); if (v is! Map || - !v.containsKey('data') || - !v.containsKey('token')) { + !(v as Map).containsKey('data') || + !(v as Map).containsKey('token')) { throw new AngelHttpException.notAuthenticated( message: "Auth endpoint '$url' did not return a proper response."); } - var r = new AngelAuthResult.fromMap(v); + var r = new AngelAuthResult.fromMap(v as Map); _onAuthenticated.add(r); return r; } on AngelHttpException { @@ -166,8 +166,8 @@ abstract class BaseAngelClient extends Angel { Future sendUnstreamed( String method, url, Map headers, [body, Encoding encoding]) async { - if (url is String) url = Uri.parse(url); - var request = new http.Request(method, url); + var request = + new http.Request(method, url is Uri ? url : Uri.parse(url.toString())); if (headers != null) request.headers.addAll(headers); diff --git a/lib/browser.dart b/lib/browser.dart index a8cb3b0f..54b67a80 100644 --- a/lib/browser.dart +++ b/lib/browser.dart @@ -1,9 +1,10 @@ /// Browser client library for the Angel framework. library angel_client.browser; -import 'dart:async' show Future, Stream, StreamController, StreamSubscription, Timer; +import 'dart:async' + show Future, Stream, StreamController, StreamSubscription, Timer; import 'dart:html' show CustomEvent, Event, window; -import 'package:dart2_constant/convert.dart'; +import 'dart:convert'; import 'package:http/browser_client.dart' as http; import 'angel_client.dart'; // import 'auth_types.dart' as auth_types; @@ -72,7 +73,7 @@ class Rest extends BaseAngelClient { sub = window.on[eventName ?? 'token'].listen((Event ev) { var e = ev as CustomEvent; if (!ctrl.isClosed) { - ctrl.add(e.detail); + ctrl.add(e.detail.toString()); t.cancel(); ctrl.close(); sub.cancel(); diff --git a/lib/flutter.dart b/lib/flutter.dart index 3b407932..83bfec5e 100644 --- a/lib/flutter.dart +++ b/lib/flutter.dart @@ -8,10 +8,11 @@ export 'angel_client.dart'; /// Queries an Angel server via REST. class Rest extends BaseAngelClient { - Rest(String basePath) : super(new http.Client(), basePath); + Rest(String basePath) : super(new http.Client() as http.BaseClient, basePath); @override Stream authenticateViaPopup(String url, {String eventName: 'token'}) { - throw new UnimplementedError('Opening popup windows is not supported in the `dart:io` client.'); + throw new UnimplementedError( + 'Opening popup windows is not supported in the `dart:io` client.'); } } diff --git a/lib/io.dart b/lib/io.dart index e1a34cf7..538d9fe6 100644 --- a/lib/io.dart +++ b/lib/io.dart @@ -12,20 +12,20 @@ export 'angel_client.dart'; class Rest extends BaseAngelClient { final List _services = []; - Rest(String path) : super(new http.Client(), path); + Rest(String path) : super(new http.Client() as http.BaseClient, path); @override Service service(String path, {Type type, AngelDeserializer deserializer}) { String uri = path.replaceAll(straySlashes, ""); - var s = new RestService( - client, this, "$basePath/$uri", type); + var s = new RestService(client, this, "$basePath/$uri", type); _services.add(s); return s; } @override Stream authenticateViaPopup(String url, {String eventName: 'token'}) { - throw new UnimplementedError('Opening popup windows is not supported in the `dart:io` client.'); + throw new UnimplementedError( + 'Opening popup windows is not supported in the `dart:io` client.'); } Future close() async { @@ -40,7 +40,8 @@ class Rest extends BaseAngelClient { class RestService extends BaseAngelService { final Type type; - RestService(http.BaseClient client, Angel app, String url, this.type) + RestService( + http.BaseClient client, BaseAngelClient app, String url, this.type) : super(client, app, url); @override diff --git a/pubspec.yaml b/pubspec.yaml index 159deac7..2870cf10 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,21 +1,20 @@ name: angel_client -version: 1.2.0+2 +version: 2.0.0-alpha description: Client library for the Angel framework. author: Tobe O homepage: https://github.com/angel-dart/angel_client environment: - sdk: ">=1.8.0 <3.0.0" + sdk: ">=2.0.0-dev <3.0.0" dependencies: angel_http_exception: ^1.0.0 collection: ^1.0.0 - dart2_constant: ^1.0.0 http: ^0.11.3 json_god: ">=2.0.0-beta <3.0.0" merge_map: ^1.0.0 dev_dependencies: - angel_framework: ^1.1.0-alpha + angel_framework: ^2.0.0-alpha angel_model: ^1.0.0 - build_runner: ">=0.6.0 <0.10.0" - build_web_compilers: ">=0.2.0 <0.5.0" + build_runner: ^0.10.0 + build_web_compilers: ^0.4.0 mock_request: ^1.0.0 - test: ^0.12.0 + test: ^1.0.0 diff --git a/test/all_test.dart b/test/all_test.dart index 5a1fded1..4816d38e 100644 --- a/test/all_test.dart +++ b/test/all_test.dart @@ -1,5 +1,5 @@ import 'package:angel_client/angel_client.dart'; -import 'package:dart2_constant/convert.dart'; +import 'dart:convert'; import 'package:test/test.dart'; import 'common.dart'; diff --git a/test/common.dart b/test/common.dart index 2814f788..3a7921d5 100644 --- a/test/common.dart +++ b/test/common.dart @@ -1,6 +1,6 @@ import 'dart:async'; import 'package:angel_client/base_angel_client.dart'; -import 'package:dart2_constant/convert.dart'; +import 'dart:convert'; import 'package:http/src/base_client.dart' as http; import 'package:http/src/base_request.dart' as http; import 'package:http/src/streamed_response.dart' as http; diff --git a/test/list_test.dart b/test/list_test.dart index 3198c989..26c934c5 100644 --- a/test/list_test.dart +++ b/test/list_test.dart @@ -32,7 +32,9 @@ main() { test('listens on create', () async { list.service.create({'foo': 'bar'}); await list.onChange.first; - expect(list, [{'foo': 'bar'}]); + expect(list, [ + {'foo': 'bar'} + ]); }); test('listens on modify', () async { @@ -41,7 +43,9 @@ main() { await list.service.update(1, {'id': 1, 'bar': 'baz'}); await queue.next; - expect(list, [{'id': 1, 'bar': 'baz'}]); + expect(list, [ + {'id': 1, 'bar': 'baz'} + ]); }); test('listens on remove', () async { @@ -52,4 +56,4 @@ main() { await queue.next; expect(list, isEmpty); }); -} \ No newline at end of file +} diff --git a/test/shared.dart b/test/shared.dart index 7b8af9f6..11b6c660 100644 --- a/test/shared.dart +++ b/test/shared.dart @@ -9,7 +9,9 @@ class Postcard extends Model { } factory Postcard.fromJson(Map data) => new Postcard( - id: data['id'], location: data['location'], message: data['message']); + id: data['id'].toString(), + location: data['location'].toString(), + message: data['message'].toString()); @override bool operator ==(other) { diff --git a/web/main.dart b/web/main.dart index 4bfc44f4..4cd7910d 100644 --- a/web/main.dart +++ b/web/main.dart @@ -5,4 +5,4 @@ import 'package:angel_client/browser.dart'; main() { var app = new Rest(window.location.origin); window.alert(app.basePath); -} \ No newline at end of file +}