2.0.0-alpha

This commit is contained in:
Tobe O 2018-08-26 18:41:01 -04:00
parent 4a36313c2e
commit ddd5271d1f
15 changed files with 58 additions and 41 deletions

2
.gitignore vendored
View file

@ -77,3 +77,5 @@ jspm_packages
# Yarn Integrity file
.yarn-integrity
.dart_tool

View file

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

View file

@ -1,4 +1,5 @@
analyzer:
strong-mode: true
strong-mode:
implicit-casts: false
exclude:
- test/io_test.dart

View file

@ -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<String, dynamic>) ?? {});
return result;
}
factory AngelAuthResult.fromJson(String s) =>
new AngelAuthResult.fromMap(json.decode(s));
new AngelAuthResult.fromMap(json.decode(s) as Map);
Map<String, dynamic> 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);
}));

View file

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

View file

@ -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<http.Response> sendUnstreamed(
String method, url, Map<String, String> 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);

View file

@ -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();

View file

@ -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<String> 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.');
}
}

View file

@ -12,20 +12,20 @@ export 'angel_client.dart';
class Rest extends BaseAngelClient {
final List<Service> _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<String> 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

View file

@ -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 <thosakwe@gmail.com>
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

View file

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

View file

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

View file

@ -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);
});
}
}

View file

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

View file

@ -5,4 +5,4 @@ import 'package:angel_client/browser.dart';
main() {
var app = new Rest(window.location.origin);
window.alert(app.basePath);
}
}