Skip to content

Commit 2a34117

Browse files
committed
Stable Version 1.0.0-beta.2.
1 parent 1cf187e commit 2a34117

11 files changed

+89
-33
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
##### 1.0.0-beta.2 - 10 January 2014
2+
3+
Fixed some tests.
4+
15
##### 1.0.0-beta.1 - 10 January 2014
26

37
Now in beta

dist/js-data-http.js

+67-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @author Jason Dobry <[email protected]>
33
* @file js-data-http.js
4-
* @version 1.0.0-beta.1 - Homepage <http://www.js-data.io/docs/dshttpadapter>
4+
* @version 1.0.0-beta.2 - Homepage <http://www.js-data.io/docs/dshttpadapter>
55
* @copyright (c) 2014 Jason Dobry
66
* @license MIT <https://github.com/js-data/js-data-http/blob/master/LICENSE>
77
*
@@ -33,9 +33,13 @@ module.exports = function xhrAdapter(resolve, reject, config) {
3333
config.headers || {}
3434
);
3535

36+
if (utils.isFormData(data)) {
37+
delete headers['Content-Type']; // Let the browser set it
38+
}
39+
3640
// Create the request
3741
var request = new(XMLHttpRequest || ActiveXObject)('Microsoft.XMLHTTP');
38-
request.open(config.method, buildUrl(config.url, config.params), true);
42+
request.open(config.method.toUpperCase(), buildUrl(config.url, config.params), true);
3943

4044
// Listen for ready state
4145
request.onreadystatechange = function () {
@@ -123,20 +127,22 @@ var axios = module.exports = function axios(config) {
123127
// Don't allow overriding defaults.withCredentials
124128
config.withCredentials = config.withCredentials || defaults.withCredentials;
125129

126-
var promise = new Promise(function (resolve, reject) {
127-
try {
128-
// For browsers use XHR adapter
129-
if (typeof window !== 'undefined') {
130-
require('./adapters/xhr')(resolve, reject, config);
131-
}
132-
// For node use HTTP adapter
133-
else if (typeof process !== 'undefined') {
134-
require('./adapters/http')(resolve, reject, config);
130+
var serverRequest = function (config) {
131+
return new Promise(function (resolve, reject) {
132+
try {
133+
// For browsers use XHR adapter
134+
if (typeof window !== 'undefined') {
135+
require('./adapters/xhr')(resolve, reject, config);
136+
}
137+
// For node use HTTP adapter
138+
else if (typeof process !== 'undefined') {
139+
require('./adapters/http')(resolve, reject, config);
140+
}
141+
} catch (e) {
142+
reject(e);
135143
}
136-
} catch (e) {
137-
reject(e);
138-
}
139-
});
144+
});
145+
};
140146

141147
function deprecatedMethod(method, instead, docs) {
142148
try {
@@ -151,6 +157,24 @@ var axios = module.exports = function axios(config) {
151157
} catch (e) {}
152158
}
153159

160+
var chain = [serverRequest, undefined];
161+
var promise = Promise.resolve(config);
162+
163+
utils.forEach(axios.interceptors.request.handlers, function (interceptor) {
164+
chain.unshift(interceptor.request, interceptor.requestError);
165+
});
166+
167+
utils.forEach(axios.interceptors.response.handlers, function (interceptor) {
168+
chain.push(interceptor.response, interceptor.responseError);
169+
});
170+
171+
while (chain.length) {
172+
var thenFn = chain.shift();
173+
var rejectFn = chain.shift();
174+
175+
promise = promise.then(thenFn, rejectFn);
176+
}
177+
154178
// Provide alias for success
155179
promise.success = function success(fn) {
156180
deprecatedMethod('success', 'then', 'https://github.com/mzabriskie/axios/blob/master/README.md#response-api');
@@ -183,6 +207,22 @@ axios.all = function (promises) {
183207
};
184208
axios.spread = require('./helpers/spread');
185209

210+
// interceptors
211+
axios.interceptors = {
212+
request: {
213+
handlers: [],
214+
use: function (thenFn, rejectFn) {
215+
axios.interceptors.request.handlers.push({ request: thenFn, requestError: rejectFn });
216+
}
217+
},
218+
response: {
219+
handlers: [],
220+
use: function (thenFn, rejectFn) {
221+
axios.interceptors.response.handlers.push({ response: thenFn, responseError: rejectFn });
222+
}
223+
}
224+
};
225+
186226
// Provide aliases for supported request methods
187227
createShortMethods('delete', 'get', 'head');
188228
createShortMethodsWithData('post', 'put', 'patch');
@@ -209,6 +249,7 @@ function createShortMethodsWithData() {
209249
};
210250
});
211251
}
252+
212253
}).call(this,require('_process'))
213254
},{"./adapters/http":2,"./adapters/xhr":2,"./defaults":4,"./helpers/spread":8,"./utils":11,"_process":22,"es6-promise":12}],4:[function(require,module,exports){
214255
'use strict';
@@ -503,6 +544,16 @@ function isArrayBuffer(val) {
503544
return toString.call(val) === '[object ArrayBuffer]';
504545
}
505546

547+
/**
548+
* Determine if a value is a FormData
549+
*
550+
* @param {Object} val The value to test
551+
* @returns {boolean} True if value is an FormData, otherwise false
552+
*/
553+
function isFormData(val) {
554+
return toString.call(val) === '[object FormData]';
555+
}
556+
506557
/**
507558
* Determine if a value is a view on an ArrayBuffer
508559
*
@@ -669,6 +720,7 @@ function merge(obj1/*, obj2, obj3, ...*/) {
669720
module.exports = {
670721
isArray: isArray,
671722
isArrayBuffer: isArrayBuffer,
723+
isFormData: isFormData,
672724
isArrayBufferView: isArrayBufferView,
673725
isString: isString,
674726
isNumber: isNumber,

dist/js-data-http.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "js-data-http",
33
"description": "http adapter for js-data.",
4-
"version": "1.0.0-beta.1",
4+
"version": "1.0.0-beta.2",
55
"homepage": "http://www.js-data.io/docs/dshttpadapter",
66
"repository": {
77
"type": "git",

test/create.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('DSHttpAdapter.create(resourceConfig, attrs, options)', function () {
3131
setTimeout(function () {
3232
assert.equal(1, _this.requests.length);
3333
assert.equal(_this.requests[0].url, 'api/posts');
34-
assert.equal(_this.requests[0].method, 'post');
34+
assert.equal(_this.requests[0].method, 'POST');
3535
assert.equal(_this.requests[0].requestBody, DSUtils.toJson({ author: 'John', age: 30 }));
3636
_this.requests[0].respond(200, {'Content-Type': 'application/json'}, DSUtils.toJson(p1));
3737
}, 10);

test/destroy.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('DSHttpAdapter.destroy(resourceConfig, id, options)', function () {
1818
setTimeout(function () {
1919
assert.equal(2, _this.requests.length);
2020
assert.equal(_this.requests[1].url, 'api2/posts/1');
21-
assert.equal(_this.requests[1].method, 'delete');
21+
assert.equal(_this.requests[1].method, 'DELETE');
2222
_this.requests[1].respond(200, {'Content-Type': 'text/plain'}, '1');
2323
}, 10);
2424

@@ -30,7 +30,7 @@ describe('DSHttpAdapter.destroy(resourceConfig, id, options)', function () {
3030
setTimeout(function () {
3131
assert.equal(1, _this.requests.length);
3232
assert.equal(_this.requests[0].url, 'api/posts/1');
33-
assert.equal(_this.requests[0].method, 'delete');
33+
assert.equal(_this.requests[0].method, 'DELETE');
3434
_this.requests[0].respond(200, {'Content-Type': 'text/plain'}, '1');
3535
}, 10);
3636
});

test/destroyAll.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('DSHttpAdapter.destroyAll(resourceConfig, params, options)', function (
2424
setTimeout(function () {
2525
assert.equal(2, _this.requests.length);
2626
assert.equal(_this.requests[1].url, 'api2/posts?where=%7B%22author%22:%7B%22%3D%3D%22:%22John%22%7D%7D');
27-
assert.equal(_this.requests[1].method, 'delete');
27+
assert.equal(_this.requests[1].method, 'DELETE');
2828
_this.requests[1].respond(204);
2929
}, 10);
3030
}).catch(function (err) {
@@ -35,7 +35,7 @@ describe('DSHttpAdapter.destroyAll(resourceConfig, params, options)', function (
3535
setTimeout(function () {
3636
assert.equal(1, _this.requests.length);
3737
assert.equal(_this.requests[0].url, 'api/posts');
38-
assert.equal(_this.requests[0].method, 'delete');
38+
assert.equal(_this.requests[0].method, 'DELETE');
3939
_this.requests[0].respond(204);
4040
}, 10);
4141
});

test/find.spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('DSHttpAdapter.find(resourceConfig, id, options)', function () {
1818
setTimeout(function () {
1919
assert.equal(2, _this.requests.length);
2020
assert.equal(_this.requests[1].url, 'api2/posts/1');
21-
assert.equal(_this.requests[1].method, 'get');
21+
assert.equal(_this.requests[1].method, 'GET');
2222
_this.requests[1].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify(p1));
2323
}, 10);
2424
}).catch(function (err) {
@@ -29,7 +29,7 @@ describe('DSHttpAdapter.find(resourceConfig, id, options)', function () {
2929
setTimeout(function () {
3030
assert.equal(1, _this.requests.length);
3131
assert.equal(_this.requests[0].url, 'api/posts/1');
32-
assert.equal(_this.requests[0].method, 'get');
32+
assert.equal(_this.requests[0].method, 'GET');
3333
_this.requests[0].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify(p1));
3434
}, 10);
3535
});
@@ -54,7 +54,7 @@ describe('DSHttpAdapter.find(resourceConfig, id, options)', function () {
5454
setTimeout(function () {
5555
assert.equal(1, _this.requests.length);
5656
assert.equal(_this.requests[0].url, 'api/posts/1?test=test');
57-
assert.equal(_this.requests[0].method, 'get');
57+
assert.equal(_this.requests[0].method, 'GET');
5858
assert.deepEqual({
5959
Authorization: 'test',
6060
Accept: 'application/json, text/plain, */*'
@@ -83,7 +83,7 @@ describe('DSHttpAdapter.find(resourceConfig, id, options)', function () {
8383
try {
8484
assert.equal(1, _this.requests.length);
8585
assert.equal(_this.requests[0].url, 'api/posts/1');
86-
assert.equal(_this.requests[0].method, 'get');
86+
assert.equal(_this.requests[0].method, 'GET');
8787
} catch (err) {
8888
done(err);
8989
}

test/findAll.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('dsHttpAdapter.findAll(resourceConfig, params, options)', function () {
2424
setTimeout(function () {
2525
assert.equal(2, _this.requests.length);
2626
assert.equal(_this.requests[1].url, 'api2/posts?where=%7B%22author%22:%7B%22%3D%3D%22:%22John%22%7D%7D');
27-
assert.equal(_this.requests[1].method, 'get');
27+
assert.equal(_this.requests[1].method, 'GET');
2828
_this.requests[1].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify([p1]));
2929
}, 10);
3030
}).catch(function (err) {
@@ -35,7 +35,7 @@ describe('dsHttpAdapter.findAll(resourceConfig, params, options)', function () {
3535
setTimeout(function () {
3636
assert.equal(1, _this.requests.length);
3737
assert.equal(_this.requests[0].url, 'api/posts');
38-
assert.equal(_this.requests[0].method, 'get');
38+
assert.equal(_this.requests[0].method, 'GET');
3939
_this.requests[0].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify([p1]));
4040
}, 10);
4141
});

test/update.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('DSHttpAdapter.update(resourceConfig, id, attrs, options)', function ()
1818
setTimeout(function () {
1919
assert.equal(2, _this.requests.length);
2020
assert.equal(_this.requests[1].url, 'api2/posts/1');
21-
assert.equal(_this.requests[1].method, 'put');
21+
assert.equal(_this.requests[1].method, 'PUT');
2222
assert.equal(_this.requests[1].requestBody, JSON.stringify({ author: 'John', age: 30 }));
2323
_this.requests[1].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify(p1));
2424
}, 10);
@@ -30,7 +30,7 @@ describe('DSHttpAdapter.update(resourceConfig, id, attrs, options)', function ()
3030
setTimeout(function () {
3131
assert.equal(1, _this.requests.length);
3232
assert.equal(_this.requests[0].url, 'api/posts/1');
33-
assert.equal(_this.requests[0].method, 'put');
33+
assert.equal(_this.requests[0].method, 'PUT');
3434
assert.equal(_this.requests[0].requestBody, JSON.stringify({ author: 'John', age: 30 }));
3535
_this.requests[0].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify(p1));
3636
}, 10);

test/updateAll.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('DSHttpAdapter.updateAll(resourceConfig, attrs, params, options)', func
2424
setTimeout(function () {
2525
assert.equal(2, _this.requests.length);
2626
assert.equal(_this.requests[1].url, 'api2/posts?where=%7B%22author%22:%7B%22%3D%3D%22:%22John%22%7D%7D');
27-
assert.equal(_this.requests[1].method, 'put');
27+
assert.equal(_this.requests[1].method, 'PUT');
2828
_this.requests[1].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify([p1]));
2929
}, 10);
3030
}).catch(function (err) {
@@ -35,7 +35,7 @@ describe('DSHttpAdapter.updateAll(resourceConfig, attrs, params, options)', func
3535
setTimeout(function () {
3636
assert.equal(1, _this.requests.length);
3737
assert.equal(_this.requests[0].url, 'api/posts');
38-
assert.equal(_this.requests[0].method, 'put');
38+
assert.equal(_this.requests[0].method, 'PUT');
3939
_this.requests[0].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify([p1]));
4040
}, 10);
4141
});

0 commit comments

Comments
 (0)