From e34d712109d4b83d35df06fbeff71bcc7a062e86 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Fri, 22 Jun 2018 20:18:38 -0400 Subject: [PATCH] More DDC fixes --- CHANGELOG.md | 4 +++ build.yaml | 14 +++++++++ lib/angel_client.dart | 6 ++-- lib/auth_types.dart | 6 +++- lib/base_angel_client.dart | 58 +++++++++++++++++++------------------- lib/browser.dart | 12 ++++---- pubspec.yaml | 13 +++++---- test/all_test.dart | 4 +-- test/common.dart | 6 ++-- test/list_test.dart | 3 +- 10 files changed, 76 insertions(+), 50 deletions(-) create mode 100644 build.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b2dab42..a303c0c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.2.0+2 +* Code cleanup + housekeeping, update to `dart2_constant`, and +ensured build works with `2.0.0-dev.64.1`. + # 1.2.0+1 * Removed a type annotation in `authenticateViaPopup` to prevent breaking with DDC. diff --git a/build.yaml b/build.yaml new file mode 100644 index 00000000..44932516 --- /dev/null +++ b/build.yaml @@ -0,0 +1,14 @@ +targets: + $default: + builders: + build_web_compilers|entrypoint: + generate_for: + - web/**.dart + options: + dart2js_args: + - --dump-info + - --fast-startup + - --minify + - --trust-type-annotations + - --trust-primitives + - --no-source-maps \ No newline at end of file diff --git a/lib/angel_client.dart b/lib/angel_client.dart index dba4f644..2d75d071 100644 --- a/lib/angel_client.dart +++ b/lib/angel_client.dart @@ -2,8 +2,8 @@ library angel_client; import 'dart:async'; -import 'dart:convert'; import 'package:collection/collection.dart'; +import 'package:dart2_constant/convert.dart'; import 'package:http/src/response.dart' as http; export 'package:angel_http_exception/angel_http_exception.dart'; @@ -82,8 +82,8 @@ class AngelAuthResult { return result; } - factory AngelAuthResult.fromJson(String json) => - new AngelAuthResult.fromMap(JSON.decode(json)); + factory AngelAuthResult.fromJson(String s) => + new AngelAuthResult.fromMap(json.decode(s)); Map toJson() { return {'token': token, 'data': data}; diff --git a/lib/auth_types.dart b/lib/auth_types.dart index 6c57d352..f51ca7d6 100644 --- a/lib/auth_types.dart +++ b/lib/auth_types.dart @@ -1 +1,5 @@ -const String LOCAL = 'local'; \ No newline at end of file +const String local = 'local'; + +/// Use [local] instead. +@deprecated +const String LOCAL = local; \ No newline at end of file diff --git a/lib/base_angel_client.dart b/lib/base_angel_client.dart index 527775b3..67508b11 100644 --- a/lib/base_angel_client.dart +++ b/lib/base_angel_client.dart @@ -1,7 +1,7 @@ import 'dart:async'; -import 'dart:convert'; +import 'dart:convert' show Encoding; import 'package:angel_http_exception/angel_http_exception.dart'; -import 'package:collection/collection.dart'; +import 'package:dart2_constant/convert.dart'; 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; @@ -35,10 +35,10 @@ bool _invalid(http.Response response) => AngelHttpException failure(http.Response response, {error, StackTrace stack}) { try { - final json = JSON.decode(response.body); + final v = json.decode(response.body); - if (json is Map && json['isError'] == true) { - return new AngelHttpException.fromMap(json); + if (v is Map && v['isError'] == true) { + return new AngelHttpException.fromMap(v); } else { return new AngelHttpException(error, message: 'Unhandled exception while connecting to Angel backend.', @@ -95,17 +95,17 @@ abstract class BaseAngelClient extends Angel { } try { - final json = JSON.decode(response.body); + final v = json.decode(response.body); - if (json is! Map || - !json.containsKey('data') || - !json.containsKey('token')) { + if (v is! Map || + !v.containsKey('data') || + !v.containsKey('token')) { throw new AngelHttpException.notAuthenticated( message: "Auth endpoint '$url' did not return a proper response."); } - var r = new AngelAuthResult.fromMap(json); + var r = new AngelAuthResult.fromMap(v); _onAuthenticated.add(r); return r; } on AngelHttpException { @@ -119,7 +119,7 @@ abstract class BaseAngelClient extends Angel { if (credentials != null) { response = await client.post(url, - body: JSON.encode(credentials), headers: _writeHeaders); + body: json.encode(credentials), headers: _writeHeaders); } else { response = await client.post(url, headers: _writeHeaders); } @@ -129,17 +129,17 @@ abstract class BaseAngelClient extends Angel { } try { - final json = JSON.decode(response.body); + final v = json.decode(response.body); - if (json is! Map || - !json.containsKey('data') || - !json.containsKey('token')) { + if (v is! Map || + !v.containsKey('data') || + !v.containsKey('token')) { throw new AngelHttpException.notAuthenticated( message: "Auth endpoint '$url' did not return a proper response."); } - var r = new AngelAuthResult.fromMap(json); + var r = new AngelAuthResult.fromMap(v); _onAuthenticated.add(r); return r; } on AngelHttpException { @@ -179,9 +179,9 @@ abstract class BaseAngelClient extends Angel { if (body is String) { request.body = body; } else if (body is List) { - request.bodyBytes = DelegatingList.typed(body); + request.bodyBytes = new List.from(body); } else if (body is Map) { - request.bodyFields = DelegatingMap.typed(body); + request.bodyFields = new Map.from(body); } else { throw new ArgumentError('Invalid request body "$body".'); } @@ -289,7 +289,7 @@ class BaseAngelService extends Service { } makeBody(x) { - return JSON.encode(x); + return json.encode(x); } Future send(http.BaseRequest request) { @@ -313,14 +313,14 @@ class BaseAngelService extends Service { throw failure(response); } - final json = JSON.decode(response.body); + final v = json.decode(response.body); - if (json is! List) { - _onIndexed.add(json); - return json; + if (v is! List) { + _onIndexed.add(v); + return v; } - var r = json.map(deserialize).toList(); + var r = v.map(deserialize).toList(); _onIndexed.add(r); return r; } catch (e, st) { @@ -344,7 +344,7 @@ class BaseAngelService extends Service { throw failure(response); } - var r = deserialize(JSON.decode(response.body)); + var r = deserialize(json.decode(response.body)); _onRead.add(r); return r; } catch (e, st) { @@ -368,7 +368,7 @@ class BaseAngelService extends Service { throw failure(response); } - var r = deserialize(JSON.decode(response.body)); + var r = deserialize(json.decode(response.body)); _onCreated.add(r); return r; } catch (e, st) { @@ -392,7 +392,7 @@ class BaseAngelService extends Service { throw failure(response); } - var r = deserialize(JSON.decode(response.body)); + var r = deserialize(json.decode(response.body)); _onModified.add(r); return r; } catch (e, st) { @@ -416,7 +416,7 @@ class BaseAngelService extends Service { throw failure(response); } - var r = deserialize(JSON.decode(response.body)); + var r = deserialize(json.decode(response.body)); _onUpdated.add(r); return r; } catch (e, st) { @@ -440,7 +440,7 @@ class BaseAngelService extends Service { throw failure(response); } - var r = deserialize(JSON.decode(response.body)); + var r = deserialize(json.decode(response.body)); _onRemoved.add(r); return r; } catch (e, st) { diff --git a/lib/browser.dart b/lib/browser.dart index 19ec2826..a8cb3b0f 100644 --- a/lib/browser.dart +++ b/lib/browser.dart @@ -2,8 +2,8 @@ library angel_client.browser; import 'dart:async' show Future, Stream, StreamController, StreamSubscription, Timer; -import 'dart:convert' show JSON; import 'dart:html' show CustomEvent, Event, window; +import 'package:dart2_constant/convert.dart'; import 'package:http/browser_client.dart' as http; import 'angel_client.dart'; // import 'auth_types.dart' as auth_types; @@ -29,10 +29,10 @@ class Rest extends BaseAngelClient { try { final result = await super.authenticate( type: null, - credentials: {'token': JSON.decode(window.localStorage['token'])}, + credentials: {'token': json.decode(window.localStorage['token'])}, reviveEndpoint: reviveEndpoint); - window.localStorage['token'] = JSON.encode(authToken = result.token); - window.localStorage['user'] = JSON.encode(result.data); + window.localStorage['token'] = json.encode(authToken = result.token); + window.localStorage['user'] = json.encode(result.data); return result; } catch (e, st) { throw new AngelHttpException(e, @@ -41,8 +41,8 @@ class Rest extends BaseAngelClient { } else { final result = await super.authenticate( type: type, credentials: credentials, authEndpoint: authEndpoint); - window.localStorage['token'] = JSON.encode(authToken = result.token); - window.localStorage['user'] = JSON.encode(result.data); + window.localStorage['token'] = json.encode(authToken = result.token); + window.localStorage['user'] = json.encode(result.data); return result; } } diff --git a/pubspec.yaml b/pubspec.yaml index d24af027..fef48fa9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,18 +1,21 @@ name: angel_client -version: 1.2.0+1 +version: 1.2.0+2 description: Client library for the Angel framework. author: Tobe O homepage: https://github.com/angel-dart/angel_client environment: - sdk: ">=1.21.0" + sdk: ">=1.8.0 <3.0.0" dependencies: angel_http_exception: ^1.0.0 collection: ^1.0.0 - http: ">= 0.11.3 < 0.12.0" + dart2_constant: ^1.0.0 + http: ^0.11.3 json_god: ">=2.0.0-beta <3.0.0" - merge_map: ">=1.0.0 <2.0.0" + merge_map: ^1.0.0 dev_dependencies: angel_framework: ^1.1.0-alpha angel_model: ^1.0.0 + build_runner: ^0.9.0 + build_web_compilers: ^0.4.0 mock_request: ^1.0.0 - test: ">= 0.12.13 < 0.13.0" + test: ^0.12.0 diff --git a/test/all_test.dart b/test/all_test.dart index 2bd2d10b..5a1fded1 100644 --- a/test/all_test.dart +++ b/test/all_test.dart @@ -1,5 +1,5 @@ -import 'dart:convert'; import 'package:angel_client/angel_client.dart'; +import 'package:dart2_constant/convert.dart'; import 'package:test/test.dart'; import 'common.dart'; @@ -87,7 +87,7 @@ main() { .authenticate(type: 'local', credentials: {'username': 'password'}); expect( await read(app.client.spec.request.finalize()), - JSON.encode({'username': 'password'}), + json.encode({'username': 'password'}), ); }); }); diff --git a/test/common.dart b/test/common.dart index 536665a2..2814f788 100644 --- a/test/common.dart +++ b/test/common.dart @@ -1,12 +1,12 @@ import 'dart:async'; -import 'dart:convert'; import 'package:angel_client/base_angel_client.dart'; +import 'package:dart2_constant/convert.dart'; 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; Future read(Stream> stream) => - stream.transform(UTF8.decoder).join(); + stream.transform(utf8.decoder).join(); class MockAngel extends BaseAngelClient { @override @@ -38,7 +38,7 @@ class SpecClient extends http.BaseClient { }; return new Future.value(new http.StreamedResponse( - new Stream>.fromIterable([UTF8.encode(JSON.encode(data))]), + new Stream>.fromIterable([utf8.encode(json.encode(data))]), 200, headers: { 'content-type': 'application/json', diff --git a/test/list_test.dart b/test/list_test.dart index 0829a3f5..3198c989 100644 --- a/test/list_test.dart +++ b/test/list_test.dart @@ -12,9 +12,10 @@ main() { setUp(() async { var serverApp = new s.Angel(); + var http = new s.AngelHttp(serverApp); serverApp.use('/api/todos', new s.MapService(autoIdAndDateFields: false)); - server = await serverApp.startServer(); + server = await http.startServer(); var uri = 'http://${server.address.address}:${server.port}'; app = new c.Rest(uri); list = new c.ServiceList(app.service('api/todos'));