More DDC fixes

This commit is contained in:
Tobe O 2018-06-22 20:18:38 -04:00
parent 75dda051b4
commit e34d712109
10 changed files with 76 additions and 50 deletions

View file

@ -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 # 1.2.0+1
* Removed a type annotation in `authenticateViaPopup` to prevent breaking with DDC. * Removed a type annotation in `authenticateViaPopup` to prevent breaking with DDC.

14
build.yaml Normal file
View file

@ -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

View file

@ -2,8 +2,8 @@
library angel_client; library angel_client;
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'package:dart2_constant/convert.dart';
import 'package:http/src/response.dart' as http; import 'package:http/src/response.dart' as http;
export 'package:angel_http_exception/angel_http_exception.dart'; export 'package:angel_http_exception/angel_http_exception.dart';
@ -82,8 +82,8 @@ class AngelAuthResult {
return result; return result;
} }
factory AngelAuthResult.fromJson(String json) => factory AngelAuthResult.fromJson(String s) =>
new AngelAuthResult.fromMap(JSON.decode(json)); new AngelAuthResult.fromMap(json.decode(s));
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
return {'token': token, 'data': data}; return {'token': token, 'data': data};

View file

@ -1 +1,5 @@
const String LOCAL = 'local'; const String local = 'local';
/// Use [local] instead.
@deprecated
const String LOCAL = local;

View file

@ -1,7 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert' show Encoding;
import 'package:angel_http_exception/angel_http_exception.dart'; 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_client.dart' as http;
import 'package:http/src/base_request.dart' as http; import 'package:http/src/base_request.dart' as http;
import 'package:http/src/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}) { AngelHttpException failure(http.Response response, {error, StackTrace stack}) {
try { try {
final json = JSON.decode(response.body); final v = json.decode(response.body);
if (json is Map && json['isError'] == true) { if (v is Map && v['isError'] == true) {
return new AngelHttpException.fromMap(json); return new AngelHttpException.fromMap(v);
} else { } else {
return new AngelHttpException(error, return new AngelHttpException(error,
message: 'Unhandled exception while connecting to Angel backend.', message: 'Unhandled exception while connecting to Angel backend.',
@ -95,17 +95,17 @@ abstract class BaseAngelClient extends Angel {
} }
try { try {
final json = JSON.decode(response.body); final v = json.decode(response.body);
if (json is! Map || if (v is! Map ||
!json.containsKey('data') || !v.containsKey('data') ||
!json.containsKey('token')) { !v.containsKey('token')) {
throw new AngelHttpException.notAuthenticated( throw new AngelHttpException.notAuthenticated(
message: message:
"Auth endpoint '$url' did not return a proper response."); "Auth endpoint '$url' did not return a proper response.");
} }
var r = new AngelAuthResult.fromMap(json); var r = new AngelAuthResult.fromMap(v);
_onAuthenticated.add(r); _onAuthenticated.add(r);
return r; return r;
} on AngelHttpException { } on AngelHttpException {
@ -119,7 +119,7 @@ abstract class BaseAngelClient extends Angel {
if (credentials != null) { if (credentials != null) {
response = await client.post(url, response = await client.post(url,
body: JSON.encode(credentials), headers: _writeHeaders); body: json.encode(credentials), headers: _writeHeaders);
} else { } else {
response = await client.post(url, headers: _writeHeaders); response = await client.post(url, headers: _writeHeaders);
} }
@ -129,17 +129,17 @@ abstract class BaseAngelClient extends Angel {
} }
try { try {
final json = JSON.decode(response.body); final v = json.decode(response.body);
if (json is! Map || if (v is! Map ||
!json.containsKey('data') || !v.containsKey('data') ||
!json.containsKey('token')) { !v.containsKey('token')) {
throw new AngelHttpException.notAuthenticated( throw new AngelHttpException.notAuthenticated(
message: message:
"Auth endpoint '$url' did not return a proper response."); "Auth endpoint '$url' did not return a proper response.");
} }
var r = new AngelAuthResult.fromMap(json); var r = new AngelAuthResult.fromMap(v);
_onAuthenticated.add(r); _onAuthenticated.add(r);
return r; return r;
} on AngelHttpException { } on AngelHttpException {
@ -179,9 +179,9 @@ abstract class BaseAngelClient extends Angel {
if (body is String) { if (body is String) {
request.body = body; request.body = body;
} else if (body is List) { } else if (body is List) {
request.bodyBytes = DelegatingList.typed(body); request.bodyBytes = new List.from(body);
} else if (body is Map) { } else if (body is Map) {
request.bodyFields = DelegatingMap.typed(body); request.bodyFields = new Map.from(body);
} else { } else {
throw new ArgumentError('Invalid request body "$body".'); throw new ArgumentError('Invalid request body "$body".');
} }
@ -289,7 +289,7 @@ class BaseAngelService extends Service {
} }
makeBody(x) { makeBody(x) {
return JSON.encode(x); return json.encode(x);
} }
Future<http.StreamedResponse> send(http.BaseRequest request) { Future<http.StreamedResponse> send(http.BaseRequest request) {
@ -313,14 +313,14 @@ class BaseAngelService extends Service {
throw failure(response); throw failure(response);
} }
final json = JSON.decode(response.body); final v = json.decode(response.body);
if (json is! List) { if (v is! List) {
_onIndexed.add(json); _onIndexed.add(v);
return json; return v;
} }
var r = json.map(deserialize).toList(); var r = v.map(deserialize).toList();
_onIndexed.add(r); _onIndexed.add(r);
return r; return r;
} catch (e, st) { } catch (e, st) {
@ -344,7 +344,7 @@ class BaseAngelService extends Service {
throw failure(response); throw failure(response);
} }
var r = deserialize(JSON.decode(response.body)); var r = deserialize(json.decode(response.body));
_onRead.add(r); _onRead.add(r);
return r; return r;
} catch (e, st) { } catch (e, st) {
@ -368,7 +368,7 @@ class BaseAngelService extends Service {
throw failure(response); throw failure(response);
} }
var r = deserialize(JSON.decode(response.body)); var r = deserialize(json.decode(response.body));
_onCreated.add(r); _onCreated.add(r);
return r; return r;
} catch (e, st) { } catch (e, st) {
@ -392,7 +392,7 @@ class BaseAngelService extends Service {
throw failure(response); throw failure(response);
} }
var r = deserialize(JSON.decode(response.body)); var r = deserialize(json.decode(response.body));
_onModified.add(r); _onModified.add(r);
return r; return r;
} catch (e, st) { } catch (e, st) {
@ -416,7 +416,7 @@ class BaseAngelService extends Service {
throw failure(response); throw failure(response);
} }
var r = deserialize(JSON.decode(response.body)); var r = deserialize(json.decode(response.body));
_onUpdated.add(r); _onUpdated.add(r);
return r; return r;
} catch (e, st) { } catch (e, st) {
@ -440,7 +440,7 @@ class BaseAngelService extends Service {
throw failure(response); throw failure(response);
} }
var r = deserialize(JSON.decode(response.body)); var r = deserialize(json.decode(response.body));
_onRemoved.add(r); _onRemoved.add(r);
return r; return r;
} catch (e, st) { } catch (e, st) {

View file

@ -2,8 +2,8 @@
library angel_client.browser; library angel_client.browser;
import 'dart:async' show Future, Stream, StreamController, StreamSubscription, Timer; import 'dart:async' show Future, Stream, StreamController, StreamSubscription, Timer;
import 'dart:convert' show JSON;
import 'dart:html' show CustomEvent, Event, window; import 'dart:html' show CustomEvent, Event, window;
import 'package:dart2_constant/convert.dart';
import 'package:http/browser_client.dart' as http; import 'package:http/browser_client.dart' as http;
import 'angel_client.dart'; import 'angel_client.dart';
// import 'auth_types.dart' as auth_types; // import 'auth_types.dart' as auth_types;
@ -29,10 +29,10 @@ class Rest extends BaseAngelClient {
try { try {
final result = await super.authenticate( final result = await super.authenticate(
type: null, type: null,
credentials: {'token': JSON.decode(window.localStorage['token'])}, credentials: {'token': json.decode(window.localStorage['token'])},
reviveEndpoint: reviveEndpoint); reviveEndpoint: reviveEndpoint);
window.localStorage['token'] = JSON.encode(authToken = result.token); window.localStorage['token'] = json.encode(authToken = result.token);
window.localStorage['user'] = JSON.encode(result.data); window.localStorage['user'] = json.encode(result.data);
return result; return result;
} catch (e, st) { } catch (e, st) {
throw new AngelHttpException(e, throw new AngelHttpException(e,
@ -41,8 +41,8 @@ class Rest extends BaseAngelClient {
} else { } else {
final result = await super.authenticate( final result = await super.authenticate(
type: type, credentials: credentials, authEndpoint: authEndpoint); type: type, credentials: credentials, authEndpoint: authEndpoint);
window.localStorage['token'] = JSON.encode(authToken = result.token); window.localStorage['token'] = json.encode(authToken = result.token);
window.localStorage['user'] = JSON.encode(result.data); window.localStorage['user'] = json.encode(result.data);
return result; return result;
} }
} }

View file

@ -1,18 +1,21 @@
name: angel_client name: angel_client
version: 1.2.0+1 version: 1.2.0+2
description: Client library for the Angel framework. description: Client library for the Angel framework.
author: Tobe O <thosakwe@gmail.com> author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/angel_client homepage: https://github.com/angel-dart/angel_client
environment: environment:
sdk: ">=1.21.0" sdk: ">=1.8.0 <3.0.0"
dependencies: dependencies:
angel_http_exception: ^1.0.0 angel_http_exception: ^1.0.0
collection: ^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" json_god: ">=2.0.0-beta <3.0.0"
merge_map: ">=1.0.0 <2.0.0" merge_map: ^1.0.0
dev_dependencies: dev_dependencies:
angel_framework: ^1.1.0-alpha angel_framework: ^1.1.0-alpha
angel_model: ^1.0.0 angel_model: ^1.0.0
build_runner: ^0.9.0
build_web_compilers: ^0.4.0
mock_request: ^1.0.0 mock_request: ^1.0.0
test: ">= 0.12.13 < 0.13.0" test: ^0.12.0

View file

@ -1,5 +1,5 @@
import 'dart:convert';
import 'package:angel_client/angel_client.dart'; import 'package:angel_client/angel_client.dart';
import 'package:dart2_constant/convert.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import 'common.dart'; import 'common.dart';
@ -87,7 +87,7 @@ main() {
.authenticate(type: 'local', credentials: {'username': 'password'}); .authenticate(type: 'local', credentials: {'username': 'password'});
expect( expect(
await read(app.client.spec.request.finalize()), await read(app.client.spec.request.finalize()),
JSON.encode({'username': 'password'}), json.encode({'username': 'password'}),
); );
}); });
}); });

View file

@ -1,12 +1,12 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'package:angel_client/base_angel_client.dart'; 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_client.dart' as http;
import 'package:http/src/base_request.dart' as http; import 'package:http/src/base_request.dart' as http;
import 'package:http/src/streamed_response.dart' as http; 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 BaseAngelClient {
@override @override
@ -38,7 +38,7 @@ class SpecClient extends http.BaseClient {
}; };
return new Future<http.StreamedResponse>.value(new http.StreamedResponse( return new Future<http.StreamedResponse>.value(new http.StreamedResponse(
new Stream<List<int>>.fromIterable([UTF8.encode(JSON.encode(data))]), new Stream<List<int>>.fromIterable([utf8.encode(json.encode(data))]),
200, 200,
headers: { headers: {
'content-type': 'application/json', 'content-type': 'application/json',

View file

@ -12,9 +12,10 @@ main() {
setUp(() async { setUp(() async {
var serverApp = new s.Angel(); var serverApp = new s.Angel();
var http = new s.AngelHttp(serverApp);
serverApp.use('/api/todos', new s.MapService(autoIdAndDateFields: false)); 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}'; var uri = 'http://${server.address.address}:${server.port}';
app = new c.Rest(uri); app = new c.Rest(uri);
list = new c.ServiceList(app.service('api/todos')); list = new c.ServiceList(app.service('api/todos'));