More
This commit is contained in:
parent
ec67091b10
commit
c700a399e4
10 changed files with 100 additions and 96 deletions
4
.babelrc
4
.babelrc
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"presets": ["es2015"],
|
||||||
|
"plugins": ["add-module-exports"]
|
||||||
|
}
|
50
.gitignore
vendored
50
.gitignore
vendored
|
@ -28,4 +28,52 @@ pubspec.lock
|
||||||
.idea
|
.idea
|
||||||
|
|
||||||
lib/angel_client.js
|
lib/angel_client.js
|
||||||
*.sum
|
*.sum
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules
|
||||||
|
jspm_packages
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
89
.npmignore
89
.npmignore
|
@ -1,79 +1,10 @@
|
||||||
# Created by .ignore support plugin (hsz.mobi)
|
.babelrc
|
||||||
### JetBrains template
|
.istanbul.yml
|
||||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
.travis.yml
|
||||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
.editorconfig
|
||||||
|
.idea/
|
||||||
# User-specific stuff:
|
src/
|
||||||
.idea/workspace.xml
|
test/
|
||||||
.idea/tasks.xml
|
!lib/
|
||||||
|
.github/
|
||||||
# Sensitive or high-churn files:
|
coverage
|
||||||
.idea/dataSources/
|
|
||||||
.idea/dataSources.ids
|
|
||||||
.idea/dataSources.xml
|
|
||||||
.idea/dataSources.local.xml
|
|
||||||
.idea/sqlDataSources.xml
|
|
||||||
.idea/dynamic.xml
|
|
||||||
.idea/uiDesigner.xml
|
|
||||||
|
|
||||||
# Gradle:
|
|
||||||
.idea/gradle.xml
|
|
||||||
.idea/libraries
|
|
||||||
|
|
||||||
# Mongo Explorer plugin:
|
|
||||||
.idea/mongoSettings.xml
|
|
||||||
|
|
||||||
## File-based project format:
|
|
||||||
*.iws
|
|
||||||
|
|
||||||
## Plugin-specific files:
|
|
||||||
|
|
||||||
# IntelliJ
|
|
||||||
/out/
|
|
||||||
|
|
||||||
# mpeltonen/sbt-idea plugin
|
|
||||||
.idea_modules/
|
|
||||||
|
|
||||||
# JIRA plugin
|
|
||||||
atlassian-ide-plugin.xml
|
|
||||||
|
|
||||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
|
||||||
com_crashlytics_export_strings.xml
|
|
||||||
crashlytics.properties
|
|
||||||
crashlytics-build.properties
|
|
||||||
fabric.properties
|
|
||||||
### Dart template
|
|
||||||
# See https://www.dartlang.org/tools/private-files.html
|
|
||||||
|
|
||||||
# Files and directories created by pub
|
|
||||||
|
|
||||||
# SDK 1.20 and later (no longer creates packages directories)
|
|
||||||
.packages
|
|
||||||
.pub/
|
|
||||||
build/
|
|
||||||
|
|
||||||
# Older SDK versions
|
|
||||||
# (Include if the minimum SDK version specified in pubsepc.yaml is earlier than 1.20)
|
|
||||||
.project
|
|
||||||
.buildlog
|
|
||||||
**/packages/
|
|
||||||
|
|
||||||
|
|
||||||
# Files created by dart2js
|
|
||||||
# (Most Dart developers will use pub build to compile Dart, use/modify these
|
|
||||||
# rules if you intend to use dart2js directly
|
|
||||||
# Convention is to use extension '.dart.js' for Dart compiled to Javascript to
|
|
||||||
# differentiate from explicit Javascript files)
|
|
||||||
*.dart.js
|
|
||||||
*.part.js
|
|
||||||
*.js.deps
|
|
||||||
*.js.map
|
|
||||||
*.info.json
|
|
||||||
|
|
||||||
# Directory created by dartdoc
|
|
||||||
doc/api/
|
|
||||||
|
|
||||||
# Don't commit pubspec lock file
|
|
||||||
# (Library packages only! Remove pattern if developing an application package)
|
|
||||||
pubspec.lock
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# angel_client
|
# angel_client
|
||||||
|
|
||||||
[![pub 1.0.0-dev+20](https://img.shields.io/badge/pub-1.0.0--dev+20-red.svg)](https://pub.dartlang.org/packages/angel_client)
|
[![pub 1.0.0-dev+21](https://img.shields.io/badge/pub-1.0.0--dev+21-red.svg)](https://pub.dartlang.org/packages/angel_client)
|
||||||
![build status](https://travis-ci.org/angel-dart/client.svg)
|
![build status](https://travis-ci.org/angel-dart/client.svg)
|
||||||
|
|
||||||
Client library for the Angel framework.
|
Client library for the Angel framework.
|
||||||
|
|
|
@ -9,6 +9,12 @@ export 'package:angel_framework/src/http/angel_http_exception.dart';
|
||||||
/// A function that configures an [Angel] client in some way.
|
/// A function that configures an [Angel] client in some way.
|
||||||
typedef Future AngelConfigurer(Angel app);
|
typedef Future AngelConfigurer(Angel app);
|
||||||
|
|
||||||
|
/// A function that deserializes data received from the server.
|
||||||
|
///
|
||||||
|
/// This is only really necessary in the browser, where `json_god`
|
||||||
|
/// doesn't work.
|
||||||
|
typedef AngelDeserializer(x);
|
||||||
|
|
||||||
/// Represents an Angel server that we are querying.
|
/// Represents an Angel server that we are querying.
|
||||||
abstract class Angel {
|
abstract class Angel {
|
||||||
String get authToken;
|
String get authToken;
|
||||||
|
@ -29,7 +35,7 @@ abstract class Angel {
|
||||||
await configurer(this);
|
await configurer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Service service<T>(String path, {Type type});
|
Service service<T>(String path, {Type type, AngelDeserializer deserializer});
|
||||||
|
|
||||||
Future<http.Response> delete(String url,
|
Future<http.Response> delete(String url,
|
||||||
{Map<String, String> headers});
|
{Map<String, String> headers});
|
||||||
|
|
|
@ -128,9 +128,10 @@ abstract class BaseAngelClient extends Angel {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Service service<T>(String path, {Type type}) {
|
Service service<T>(String path, {Type type, AngelDeserializer deserializer}) {
|
||||||
String uri = path.toString().replaceAll(straySlashes, "");
|
String uri = path.toString().replaceAll(straySlashes, "");
|
||||||
return new BaseAngelService(client, this, '$basePath/$uri');
|
return new BaseAngelService(client, this, '$basePath/$uri',
|
||||||
|
deserializer: deserializer);
|
||||||
}
|
}
|
||||||
|
|
||||||
String _join(url) {
|
String _join(url) {
|
||||||
|
@ -179,8 +180,13 @@ class BaseAngelService extends Service {
|
||||||
final Angel app;
|
final Angel app;
|
||||||
final String basePath;
|
final String basePath;
|
||||||
final http.BaseClient client;
|
final http.BaseClient client;
|
||||||
|
final AngelDeserializer deserializer;
|
||||||
|
|
||||||
BaseAngelService(this.client, this.app, this.basePath);
|
BaseAngelService(this.client, this.app, this.basePath, {this.deserializer});
|
||||||
|
|
||||||
|
deserialize(x) {
|
||||||
|
return deserializer != null ? deserializer(x) : x;
|
||||||
|
}
|
||||||
|
|
||||||
makeBody(x) {
|
makeBody(x) {
|
||||||
return JSON.encode(x);
|
return JSON.encode(x);
|
||||||
|
@ -234,7 +240,7 @@ class BaseAngelService extends Service {
|
||||||
throw failure(response);
|
throw failure(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
return json;
|
return json.map(deserialize).toList();
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
throw failure(response, error: e, stack: st);
|
throw failure(response, error: e, stack: st);
|
||||||
}
|
}
|
||||||
|
@ -250,7 +256,7 @@ class BaseAngelService extends Service {
|
||||||
throw failure(response);
|
throw failure(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSON.decode(response.body);
|
return deserialize(JSON.decode(response.body));
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
throw failure(response, error: e, stack: st);
|
throw failure(response, error: e, stack: st);
|
||||||
}
|
}
|
||||||
|
@ -266,7 +272,7 @@ class BaseAngelService extends Service {
|
||||||
throw failure(response);
|
throw failure(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSON.decode(response.body);
|
return deserialize(JSON.decode(response.body));
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
throw failure(response, error: e, stack: st);
|
throw failure(response, error: e, stack: st);
|
||||||
}
|
}
|
||||||
|
@ -282,7 +288,7 @@ class BaseAngelService extends Service {
|
||||||
throw failure(response);
|
throw failure(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSON.decode(response.body);
|
return deserialize(JSON.decode(response.body));
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
throw failure(response, error: e, stack: st);
|
throw failure(response, error: e, stack: st);
|
||||||
}
|
}
|
||||||
|
@ -298,7 +304,7 @@ class BaseAngelService extends Service {
|
||||||
throw failure(response);
|
throw failure(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSON.decode(response.body);
|
return deserialize(JSON.decode(response.body));
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
throw failure(response, error: e, stack: st);
|
throw failure(response, error: e, stack: st);
|
||||||
}
|
}
|
||||||
|
@ -314,7 +320,7 @@ class BaseAngelService extends Service {
|
||||||
throw failure(response);
|
throw failure(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSON.decode(response.body);
|
return deserialize(JSON.decode(response.body));
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
throw failure(response, error: e, stack: st);
|
throw failure(response, error: e, stack: st);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ class Rest extends BaseAngelClient {
|
||||||
Rest(String path) : super(new http.Client(), path);
|
Rest(String path) : super(new http.Client(), path);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Service service<T>(String path, {Type type}) {
|
Service service<T>(String path, {Type type, AngelDeserializer deserializer}) {
|
||||||
String uri = path.replaceAll(straySlashes, "");
|
String uri = path.replaceAll(straySlashes, "");
|
||||||
return new RestService(
|
return new RestService(
|
||||||
client, this, "$basePath/$uri", T != dynamic ? T : type);
|
client, this, "$basePath/$uri", T != dynamic ? T : type);
|
||||||
|
|
13
package.json
13
package.json
|
@ -2,11 +2,15 @@
|
||||||
"name": "angel_client",
|
"name": "angel_client",
|
||||||
"version": "1.0.0-dev",
|
"version": "1.0.0-dev",
|
||||||
"description": "Client library for the Angel framework.",
|
"description": "Client library for the Angel framework.",
|
||||||
"main": "lib/angel_client.js",
|
"main": "build/angel_client.js",
|
||||||
|
"jsnext:main": "lib/angel_client.js",
|
||||||
"directories": {
|
"directories": {
|
||||||
"test": "test"
|
"test": "test"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"compile": "npm run dartdevc && babel -o build/angel_client.js lib/angel_client.js",
|
||||||
|
"dartdevc": "dartdevc --modules node -o lib/angel_client.js lib/angel_client.dart",
|
||||||
|
"prepublish": "npm run compile",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -22,5 +26,10 @@
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/angel-dart/angel_client/issues"
|
"url": "https://github.com/angel-dart/angel_client/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/angel-dart/angel_client#readme"
|
"homepage": "https://github.com/angel-dart/angel_client#readme",
|
||||||
|
"devDependencies": {
|
||||||
|
"babel-cli": "^6.18.0",
|
||||||
|
"babel-plugin-add-module-exports": "^0.2.1",
|
||||||
|
"babel-preset-es2015": "^6.18.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: angel_client
|
name: angel_client
|
||||||
version: 1.0.0-dev+20
|
version: 1.0.0-dev+21
|
||||||
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
|
||||||
|
|
|
@ -23,7 +23,7 @@ main() {
|
||||||
|
|
||||||
clientApp = new client.Rest(url);
|
clientApp = new client.Rest(url);
|
||||||
clientPostcards = clientApp.service("postcards");
|
clientPostcards = clientApp.service("postcards");
|
||||||
clientTypedPostcards = clientApp.service<Postcard>("postcards", type: Postcard);
|
clientTypedPostcards = clientApp.service("postcards", type: Postcard);
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
|
|
Loading…
Reference in a new issue