2.0.0-alpha
This commit is contained in:
parent
4a36313c2e
commit
ddd5271d1f
15 changed files with 58 additions and 41 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -77,3 +77,5 @@ jspm_packages
|
||||||
|
|
||||||
# Yarn Integrity file
|
# Yarn Integrity file
|
||||||
.yarn-integrity
|
.yarn-integrity
|
||||||
|
|
||||||
|
.dart_tool
|
|
@ -1,3 +1,8 @@
|
||||||
|
# 2.0.0-alpha
|
||||||
|
* Depend on Dart 2.
|
||||||
|
* Depend on Angel 2.
|
||||||
|
* Remove `dart2_constant`.
|
||||||
|
|
||||||
# 1.2.0+2
|
# 1.2.0+2
|
||||||
* Code cleanup + housekeeping, update to `dart2_constant`, and
|
* Code cleanup + housekeeping, update to `dart2_constant`, and
|
||||||
ensured build works with `2.0.0-dev.64.1`.
|
ensured build works with `2.0.0-dev.64.1`.
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
analyzer:
|
analyzer:
|
||||||
strong-mode: true
|
strong-mode:
|
||||||
|
implicit-casts: false
|
||||||
exclude:
|
exclude:
|
||||||
- test/io_test.dart
|
- test/io_test.dart
|
|
@ -3,7 +3,7 @@ library angel_client;
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:dart2_constant/convert.dart';
|
import 'dart:convert';
|
||||||
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';
|
||||||
|
|
||||||
|
@ -75,15 +75,16 @@ class AngelAuthResult {
|
||||||
final result = new AngelAuthResult();
|
final result = new AngelAuthResult();
|
||||||
|
|
||||||
if (data is Map && data.containsKey('token') && data['token'] is String)
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
factory AngelAuthResult.fromJson(String s) =>
|
factory AngelAuthResult.fromJson(String s) =>
|
||||||
new AngelAuthResult.fromMap(json.decode(s));
|
new AngelAuthResult.fromMap(json.decode(s) as Map);
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
return {'token': token, 'data': data};
|
return {'token': token, 'data': data};
|
||||||
|
@ -163,7 +164,7 @@ class ServiceList extends DelegatingList {
|
||||||
var items = asPaginated == true ? data['data'] : data;
|
var items = asPaginated == true ? data['data'] : data;
|
||||||
this
|
this
|
||||||
..clear()
|
..clear()
|
||||||
..addAll(items);
|
..addAll(items as Iterable);
|
||||||
_onChange.add(this);
|
_onChange.add(this);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
@ -2,4 +2,4 @@ const String local = 'local';
|
||||||
|
|
||||||
/// Use [local] instead.
|
/// Use [local] instead.
|
||||||
@deprecated
|
@deprecated
|
||||||
const String LOCAL = local;
|
const String LOCAL = local;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert' show Encoding;
|
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:dart2_constant/convert.dart';
|
import 'dart:convert';
|
||||||
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;
|
||||||
|
@ -77,7 +77,7 @@ abstract class BaseAngelClient extends Angel {
|
||||||
if (credentials is String)
|
if (credentials is String)
|
||||||
token = credentials;
|
token = credentials;
|
||||||
else if (credentials is Map && credentials.containsKey('token'))
|
else if (credentials is Map && credentials.containsKey('token'))
|
||||||
token = credentials['token'];
|
token = credentials['token'].toString();
|
||||||
|
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
throw new ArgumentError(
|
throw new ArgumentError(
|
||||||
|
@ -98,14 +98,14 @@ abstract class BaseAngelClient extends Angel {
|
||||||
final v = json.decode(response.body);
|
final v = json.decode(response.body);
|
||||||
|
|
||||||
if (v is! Map ||
|
if (v is! Map ||
|
||||||
!v.containsKey('data') ||
|
!(v as Map).containsKey('data') ||
|
||||||
!v.containsKey('token')) {
|
!(v as Map).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(v);
|
var r = new AngelAuthResult.fromMap(v as Map);
|
||||||
_onAuthenticated.add(r);
|
_onAuthenticated.add(r);
|
||||||
return r;
|
return r;
|
||||||
} on AngelHttpException {
|
} on AngelHttpException {
|
||||||
|
@ -132,14 +132,14 @@ abstract class BaseAngelClient extends Angel {
|
||||||
final v = json.decode(response.body);
|
final v = json.decode(response.body);
|
||||||
|
|
||||||
if (v is! Map ||
|
if (v is! Map ||
|
||||||
!v.containsKey('data') ||
|
!(v as Map).containsKey('data') ||
|
||||||
!v.containsKey('token')) {
|
!(v as Map).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(v);
|
var r = new AngelAuthResult.fromMap(v as Map);
|
||||||
_onAuthenticated.add(r);
|
_onAuthenticated.add(r);
|
||||||
return r;
|
return r;
|
||||||
} on AngelHttpException {
|
} on AngelHttpException {
|
||||||
|
@ -166,8 +166,8 @@ abstract class BaseAngelClient extends Angel {
|
||||||
Future<http.Response> sendUnstreamed(
|
Future<http.Response> sendUnstreamed(
|
||||||
String method, url, Map<String, String> headers,
|
String method, url, Map<String, String> headers,
|
||||||
[body, Encoding encoding]) async {
|
[body, Encoding encoding]) async {
|
||||||
if (url is String) url = Uri.parse(url);
|
var request =
|
||||||
var request = new http.Request(method, url);
|
new http.Request(method, url is Uri ? url : Uri.parse(url.toString()));
|
||||||
|
|
||||||
if (headers != null) request.headers.addAll(headers);
|
if (headers != null) request.headers.addAll(headers);
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
/// Browser client library for the Angel framework.
|
/// Browser client library for the Angel framework.
|
||||||
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:html' show CustomEvent, Event, window;
|
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 '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;
|
||||||
|
@ -72,7 +73,7 @@ class Rest extends BaseAngelClient {
|
||||||
sub = window.on[eventName ?? 'token'].listen((Event ev) {
|
sub = window.on[eventName ?? 'token'].listen((Event ev) {
|
||||||
var e = ev as CustomEvent;
|
var e = ev as CustomEvent;
|
||||||
if (!ctrl.isClosed) {
|
if (!ctrl.isClosed) {
|
||||||
ctrl.add(e.detail);
|
ctrl.add(e.detail.toString());
|
||||||
t.cancel();
|
t.cancel();
|
||||||
ctrl.close();
|
ctrl.close();
|
||||||
sub.cancel();
|
sub.cancel();
|
||||||
|
|
|
@ -8,10 +8,11 @@ export 'angel_client.dart';
|
||||||
|
|
||||||
/// Queries an Angel server via REST.
|
/// Queries an Angel server via REST.
|
||||||
class Rest extends BaseAngelClient {
|
class Rest extends BaseAngelClient {
|
||||||
Rest(String basePath) : super(new http.Client(), basePath);
|
Rest(String basePath) : super(new http.Client() as http.BaseClient, basePath);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Stream<String> authenticateViaPopup(String url, {String eventName: 'token'}) {
|
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.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
11
lib/io.dart
11
lib/io.dart
|
@ -12,20 +12,20 @@ export 'angel_client.dart';
|
||||||
class Rest extends BaseAngelClient {
|
class Rest extends BaseAngelClient {
|
||||||
final List<Service> _services = [];
|
final List<Service> _services = [];
|
||||||
|
|
||||||
Rest(String path) : super(new http.Client(), path);
|
Rest(String path) : super(new http.Client() as http.BaseClient, path);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Service service(String path, {Type type, AngelDeserializer deserializer}) {
|
Service service(String path, {Type type, AngelDeserializer deserializer}) {
|
||||||
String uri = path.replaceAll(straySlashes, "");
|
String uri = path.replaceAll(straySlashes, "");
|
||||||
var s = new RestService(
|
var s = new RestService(client, this, "$basePath/$uri", type);
|
||||||
client, this, "$basePath/$uri", type);
|
|
||||||
_services.add(s);
|
_services.add(s);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Stream<String> authenticateViaPopup(String url, {String eventName: 'token'}) {
|
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 {
|
Future close() async {
|
||||||
|
@ -40,7 +40,8 @@ class Rest extends BaseAngelClient {
|
||||||
class RestService extends BaseAngelService {
|
class RestService extends BaseAngelService {
|
||||||
final Type type;
|
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);
|
: super(client, app, url);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
13
pubspec.yaml
13
pubspec.yaml
|
@ -1,21 +1,20 @@
|
||||||
name: angel_client
|
name: angel_client
|
||||||
version: 1.2.0+2
|
version: 2.0.0-alpha
|
||||||
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.8.0 <3.0.0"
|
sdk: ">=2.0.0-dev <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
|
||||||
dart2_constant: ^1.0.0
|
|
||||||
http: ^0.11.3
|
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
|
merge_map: ^1.0.0
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
angel_framework: ^1.1.0-alpha
|
angel_framework: ^2.0.0-alpha
|
||||||
angel_model: ^1.0.0
|
angel_model: ^1.0.0
|
||||||
build_runner: ">=0.6.0 <0.10.0"
|
build_runner: ^0.10.0
|
||||||
build_web_compilers: ">=0.2.0 <0.5.0"
|
build_web_compilers: ^0.4.0
|
||||||
mock_request: ^1.0.0
|
mock_request: ^1.0.0
|
||||||
test: ^0.12.0
|
test: ^1.0.0
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import 'package:angel_client/angel_client.dart';
|
import 'package:angel_client/angel_client.dart';
|
||||||
import 'package:dart2_constant/convert.dart';
|
import 'dart:convert';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'common.dart';
|
import 'common.dart';
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:angel_client/base_angel_client.dart';
|
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_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;
|
||||||
|
|
|
@ -32,7 +32,9 @@ main() {
|
||||||
test('listens on create', () async {
|
test('listens on create', () async {
|
||||||
list.service.create({'foo': 'bar'});
|
list.service.create({'foo': 'bar'});
|
||||||
await list.onChange.first;
|
await list.onChange.first;
|
||||||
expect(list, [{'foo': 'bar'}]);
|
expect(list, [
|
||||||
|
{'foo': 'bar'}
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('listens on modify', () async {
|
test('listens on modify', () async {
|
||||||
|
@ -41,7 +43,9 @@ main() {
|
||||||
|
|
||||||
await list.service.update(1, {'id': 1, 'bar': 'baz'});
|
await list.service.update(1, {'id': 1, 'bar': 'baz'});
|
||||||
await queue.next;
|
await queue.next;
|
||||||
expect(list, [{'id': 1, 'bar': 'baz'}]);
|
expect(list, [
|
||||||
|
{'id': 1, 'bar': 'baz'}
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('listens on remove', () async {
|
test('listens on remove', () async {
|
||||||
|
@ -52,4 +56,4 @@ main() {
|
||||||
await queue.next;
|
await queue.next;
|
||||||
expect(list, isEmpty);
|
expect(list, isEmpty);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,9 @@ class Postcard extends Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
factory Postcard.fromJson(Map data) => new Postcard(
|
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
|
@override
|
||||||
bool operator ==(other) {
|
bool operator ==(other) {
|
||||||
|
|
|
@ -5,4 +5,4 @@ import 'package:angel_client/browser.dart';
|
||||||
main() {
|
main() {
|
||||||
var app = new Rest(window.location.origin);
|
var app = new Rest(window.location.origin);
|
||||||
window.alert(app.basePath);
|
window.alert(app.basePath);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue