Skip to content

Commit

Permalink
chore(all): prepare release 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
EisenbergEffect committed Nov 10, 2015
1 parent 78859ed commit 4fcc56b
Show file tree
Hide file tree
Showing 14 changed files with 399 additions and 109 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aurelia-fetch-client",
"version": "0.3.0",
"version": "0.4.0",
"description": "A simple client based on the Fetch standard.",
"keywords": [
"aurelia",
Expand Down
47 changes: 39 additions & 8 deletions dist/amd/aurelia-fetch-client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@ declare module 'aurelia-fetch-client' {
import 'core-js';

/* eslint-disable */
/**
* Interceptors can process requests before they are sent, and responses
* before they are returned to callers.
*/
export interface Interceptor {
request(request: Request): Request | Response | Promise<Request | Response>;
requestError(error: any): Request | Response | Promise<Request | Response>;
response(response: Response): Response | Promise<Response>;
responseError(error: any): Response | Promise<Response>;
}

/**
* The init object used to initialize a fetch Request.
* See https://developer.mozilla.org/en-US/docs/Web/API/Request/Request
*/
export interface RequestInit {
method?: string;
headers?: Headers | Object;
Expand All @@ -27,8 +36,6 @@ declare module 'aurelia-fetch-client' {

/**
* A class for configuring HttpClients.
*
* @constructor
*/
export class HttpClientConfiguration {

Expand Down Expand Up @@ -101,25 +108,49 @@ declare module 'aurelia-fetch-client' {

/**
* An HTTP client based on the Fetch API.
*
* @constructor
*/
export class HttpClient {

/**
* The current number of active requests.
* Requests being processed by interceptors are considered active.
*/
activeRequestCount: number;

/**
* Indicates whether or not the client is currently making one or more requests.
*/
isRequesting: boolean;
interceptors: Interceptor[];

/**
* Indicates whether or not the client has been configured.
*/
isConfigured: boolean;

/**
* The base URL set by the config.
*/
baseUrl: string;

/**
* The default request init to merge with values specified at request time.
*/
defaults: RequestInit;

/**
* The interceptors to be run during requests.
*/
interceptors: Interceptor[];

/**
* Configure this client with default settings to be used by all requests.
*
* @param config - A function that takes a config argument,
* or a config object, or a string to use as the client's baseUrl.
* @param config - A configuration object, or a function that takes a config
* object and configures it.
*
* @chainable
*/
configure(config: string | RequestInit | ((config: HttpClientConfiguration) => void)): HttpClient;
configure(config: RequestInit | ((config: HttpClientConfiguration) => void | HttpClientConfiguration)): HttpClient;

/**
* Starts the process of fetching a resource. Default configuration parameters
Expand Down
11 changes: 6 additions & 5 deletions dist/amd/aurelia-fetch-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,25 @@ define(['exports', 'core-js'], function (exports, _coreJs) {

this.activeRequestCount = 0;
this.isRequesting = false;
this.interceptors = [];
this.isConfigured = false;
this.baseUrl = '';
this.defaults = null;
this.interceptors = [];
}

HttpClient.prototype.configure = function configure(config) {
var _interceptors;

var normalizedConfig = undefined;

if (typeof config === 'string') {
normalizedConfig = { baseUrl: config };
} else if (typeof config === 'object') {
if (typeof config === 'object') {
normalizedConfig = { defaults: config };
} else if (typeof config === 'function') {
normalizedConfig = new HttpClientConfiguration();
config(normalizedConfig);
var c = config(normalizedConfig);
if (typeof c === HttpClientConfiguration) {
normalizedConfig = c;
}
} else {
throw new Error('invalid config');
}
Expand Down
47 changes: 39 additions & 8 deletions dist/aurelia-fetch-client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@ declare module 'aurelia-fetch-client' {
import 'core-js';

/* eslint-disable */
/**
* Interceptors can process requests before they are sent, and responses
* before they are returned to callers.
*/
export interface Interceptor {
request(request: Request): Request | Response | Promise<Request | Response>;
requestError(error: any): Request | Response | Promise<Request | Response>;
response(response: Response): Response | Promise<Response>;
responseError(error: any): Response | Promise<Response>;
}

/**
* The init object used to initialize a fetch Request.
* See https://developer.mozilla.org/en-US/docs/Web/API/Request/Request
*/
export interface RequestInit {
method?: string;
headers?: Headers | Object;
Expand All @@ -27,8 +36,6 @@ declare module 'aurelia-fetch-client' {

/**
* A class for configuring HttpClients.
*
* @constructor
*/
export class HttpClientConfiguration {

Expand Down Expand Up @@ -101,25 +108,49 @@ declare module 'aurelia-fetch-client' {

/**
* An HTTP client based on the Fetch API.
*
* @constructor
*/
export class HttpClient {

/**
* The current number of active requests.
* Requests being processed by interceptors are considered active.
*/
activeRequestCount: number;

/**
* Indicates whether or not the client is currently making one or more requests.
*/
isRequesting: boolean;
interceptors: Interceptor[];

/**
* Indicates whether or not the client has been configured.
*/
isConfigured: boolean;

/**
* The base URL set by the config.
*/
baseUrl: string;

/**
* The default request init to merge with values specified at request time.
*/
defaults: RequestInit;

/**
* The interceptors to be run during requests.
*/
interceptors: Interceptor[];

/**
* Configure this client with default settings to be used by all requests.
*
* @param config - A function that takes a config argument,
* or a config object, or a string to use as the client's baseUrl.
* @param config - A configuration object, or a function that takes a config
* object and configures it.
*
* @chainable
*/
configure(config: string | RequestInit | ((config: HttpClientConfiguration) => void)): HttpClient;
configure(config: RequestInit | ((config: HttpClientConfiguration) => void | HttpClientConfiguration)): HttpClient;

/**
* Starts the process of fetching a resource. Default configuration parameters
Expand Down
79 changes: 66 additions & 13 deletions dist/aurelia-fetch-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,52 @@ export function json(body: any): Blob {

/* eslint-disable */

/**
* Interceptors can process requests before they are sent, and responses
* before they are returned to callers.
*/
interface Interceptor {
/**
* Called with the request before it is sent. Request interceptors can modify and
* return the request, or return a new one to be sent. If desired, the interceptor
* may return a Response in order to short-circuit the HTTP request itself.
*
* @param request - The request to be sent.
*/
request?: (request: Request) => Request|Response|Promise<Request|Response>;

/**
* Handles errors generated by previous request interceptors. This function acts
* as a Promise rejection handler. It may rethrow the error to propagate the
* failure, or return a new Request or Response to recover.
*
* @param error - The rejection value from the previous interceptor.
*/
requestError?: (error: any) => Request|Response|Promise<Request|Response>;

/**
* Called with the response after it is received. Response interceptors can modify
* and return the Response, or create a new one to be returned to the caller.
*
* @param response - The response.
*/
response?: (response: Response) => Response|Promise<Response>;

/**
* Handles fetch errors and errors generated by previous interceptors. This
* function acts as a Promise rejection handler. It may rethrow the error
* to propagate the failure, or return a new Response to recover.
*
* @param error - The rejection value from the fetch request or from a
* previous interceptor.
*/
responseError?: (error: any) => Response|Promise<Response>;
}

/**
* The init object used to initialize a fetch Request.
* See https://developer.mozilla.org/en-US/docs/Web/API/Request/Request
*/
interface RequestInit {
method?: string;

Expand All @@ -38,8 +74,6 @@ interface RequestInit {

/**
* A class for configuring HttpClients.
*
* @constructor
*/
export class HttpClientConfiguration {
/**
Expand Down Expand Up @@ -134,39 +168,58 @@ function rejectOnError(response) {

/**
* An HTTP client based on the Fetch API.
*
* @constructor
*/
export class HttpClient {
/**
* The current number of active requests.
* Requests being processed by interceptors are considered active.
*/
activeRequestCount: number = 0;

/**
* Indicates whether or not the client is currently making one or more requests.
*/
isRequesting: boolean = false;

interceptors: Interceptor[] = [];

/**
* Indicates whether or not the client has been configured.
*/
isConfigured: boolean = false;

/**
* The base URL set by the config.
*/
baseUrl: string = '';

/**
* The default request init to merge with values specified at request time.
*/
defaults: RequestInit = null;

/**
* The interceptors to be run during requests.
*/
interceptors: Interceptor[] = [];

/**
* Configure this client with default settings to be used by all requests.
*
* @param config - A function that takes a config argument,
* or a config object, or a string to use as the client's baseUrl.
* @param config - A configuration object, or a function that takes a config
* object and configures it.
*
* @chainable
*/
configure(config: string|RequestInit|(config: HttpClientConfiguration) => void): HttpClient {
configure(config: RequestInit|(config: HttpClientConfiguration) => void|HttpClientConfiguration): HttpClient {
let normalizedConfig;

if (typeof config === 'string') {
normalizedConfig = { baseUrl: config };
} else if (typeof config === 'object') {
if (typeof config === 'object') {
normalizedConfig = { defaults: config };
} else if (typeof config === 'function') {
normalizedConfig = new HttpClientConfiguration();
config(normalizedConfig);
let c = config(normalizedConfig);
if (typeof c === HttpClientConfiguration) {
normalizedConfig = c;
}
} else {
throw new Error('invalid config');
}
Expand Down
Loading

0 comments on commit 4fcc56b

Please sign in to comment.