diff --git a/CHANGELOG.md b/CHANGELOG.md index df9b6c8..23e456e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,16 @@ -# Changelog + +## v0.4.0 (2014-01-13) + + +#### Bug Fixes + +* **loader:** extending headers by itself ([8c7739a7](http://github.com/weluse/hyperagent/commit/8c7739a7962efd29f24012af8bffdbbe9fb48702)) + + +#### Features + +* **build:** changelog is now automatically generated ([68fec099](http://github.com/weluse/hyperagent/commit/68fec0997be743a76861e7b98e7f58cb41d120fc)) +* **deps:** update Q and URIjs deps ([8d3e098c](http://github.com/weluse/hyperagent/commit/8d3e098c7438cb98d78d342c7a8fad59638c01c1)) ## v0.3.0 (2013-08-07) diff --git a/dist/amd/hyperagent/loader.js b/dist/amd/hyperagent/loader.js index 9945d47..b320f22 100644 --- a/dist/amd/hyperagent/loader.js +++ b/dist/amd/hyperagent/loader.js @@ -6,11 +6,13 @@ define("/hyperagent/loader", function loadAjax(options) { var deferred = config.defer(); - config.ajax(config._.extend({ - headers: { + if (options.headers) { + config._.extend(options.headers, { 'Accept': 'application/hal+json, application/json, */*; q=0.01', 'X-Requested-With': 'XMLHttpRequest' - }, + }); + } + config.ajax(config._.extend({ success: deferred.resolve, error: deferred.reject, dataType: 'html' // We don't want auto-converting diff --git a/dist/commonjs/hyperagent/loader.js b/dist/commonjs/hyperagent/loader.js index 05c5743..ac6a02d 100644 --- a/dist/commonjs/hyperagent/loader.js +++ b/dist/commonjs/hyperagent/loader.js @@ -3,11 +3,13 @@ var config = require("hyperagent/config").config; function loadAjax(options) { var deferred = config.defer(); - config.ajax(config._.extend({ - headers: { + if (options.headers) { + config._.extend(options.headers, { 'Accept': 'application/hal+json, application/json, */*; q=0.01', 'X-Requested-With': 'XMLHttpRequest' - }, + }); + } + config.ajax(config._.extend({ success: deferred.resolve, error: deferred.reject, dataType: 'html' // We don't want auto-converting diff --git a/dist/hyperagent.js b/dist/hyperagent.js index fa3d716..4f22ae6 100644 --- a/dist/hyperagent.js +++ b/dist/hyperagent.js @@ -153,11 +153,13 @@ define("hyperagent/loader", function loadAjax(options) { var deferred = config.defer(); - config.ajax(config._.extend({ - headers: { + if (options.headers) { + config._.extend(options.headers, { 'Accept': 'application/hal+json, application/json, */*; q=0.01', 'X-Requested-With': 'XMLHttpRequest' - }, + }); + } + config.ajax(config._.extend({ success: deferred.resolve, error: deferred.reject, dataType: 'html' // We don't want auto-converting diff --git a/dist/hyperagent.min.js b/dist/hyperagent.min.js index 700ce4a..ef88cf6 100644 --- a/dist/hyperagent.min.js +++ b/dist/hyperagent.min.js @@ -1 +1 @@ -!function(){var a,b;!function(){"use strict";var c={},d={};a=function(a,b,d){c[a]={deps:b,callback:d}},b=function(a){if(d[a])return d[a];d[a]={};for(var e,f=c[a],g=f.deps,h=f.callback,i=[],j=0,k=g.length;k>j;j++)"exports"===g[j]?i.push(e={}):i.push(b(g[j]));var l=h.apply(this,i);return d[a]=e||l}}(),a("hyperagent",["hyperagent/resource","hyperagent/properties","hyperagent/curie","hyperagent/config","exports"],function(a,b,c,d,e){"use strict";function f(a,b){l[a]=b}var g=a.Resource,h=a.LazyResource,i=a.LinkResource,j=b.Properties,k=c.CurieStore,l=d.config;e.Resource=g,e.Properties=j,e.LazyResource=h,e.LinkResource=i,e.CurieStore=k,e.configure=f,e._config=l}),a("hyperagent/config",["hyperagent/miniscore","exports"],function(a,b){"use strict";var c=a._,d={};"undefined"!=typeof window&&(d.ajax=window.$&&window.$.ajax.bind(window.$),d.defer=window.Q&&window.Q.defer,d._=c,d.loadHooks=[]),b.config=d}),a("hyperagent/curie",["exports"],function(a){"use strict";function b(){this._store={}}b.prototype.register=function(a,b){this._store[a]=URITemplate(b)},b._split=function(a){var b=a.indexOf(":"),c=a.substring(0,b),d=a.substring(b+1);return-1===a||a===a.length-1?null:[c,d]},b.prototype.empty=function(){return 0===Object.keys(this._store).length},b.prototype.expand=function(a){var c,d=b._split(a);return d?(c=this._store[d[0]],void 0===c?a:c.expand({rel:d[1]})):a},b.prototype.canExpand=function(a){var c=b._split(a);return c?void 0!==this._store[c[0]]:!1},a.CurieStore=b}),a("hyperagent/loader",["hyperagent/config","exports"],function(a,b){"use strict";function c(a){var b=d.defer();return d.ajax(d._.extend({headers:{Accept:"application/hal+json, application/json, */*; q=0.01","X-Requested-With":"XMLHttpRequest"},success:b.resolve,error:b.reject,dataType:"html"},a)),b.promise}var d=a.config;b.loadAjax=c}),a("hyperagent/miniscore",["exports"],function(a){"use strict";var b={},c={};b.each=b.forEach=function(a,b,d){if(null!==a&&void 0!==a)if(a.forEach===Array.prototype.forEach)a.forEach(b,d);else if(a.length===+a.length){for(var e=0,f=a.length;f>e;e++)if(b.call(d,a[e],e,a)===c)return}else for(var g in a)if(a.hasOwnProperty(g)&&b.call(d,a[g],g,a)===c)return},b.contains=function(a,c){return null===a||void 0===a?!1:a.indexOf===Array.prototype.indexOf?-1!==a.indexOf(c):b.any(a,function(a){return a===c})},b.pick=function(a){var c={},d=Array.prototype.concat.apply(Array.prototype,Array.prototype.slice.call(arguments,1));return b.each(d,function(b){b in a&&(c[b]=a[b])}),c},b.extend=function(a){return b.each(Array.prototype.slice.call(arguments,1),function(b){if(b)for(var c in b)a[c]=b[c]}),a},b.defaults=function(a){return b.each(Array.prototype.slice.call(arguments,1),function(b){if(b)for(var c in b)(null===a[c]||void 0===a[c])&&(a[c]=b[c])}),a},b.clone=function(a){return a!==Object(a)?a:Array.isArray(a)?a.slice():b.extend({},a)},a._=b}),a("hyperagent/properties",["hyperagent/config","exports"],function(a,b){"use strict";function c(a,b){if(b=b||{},Object(a)!==a)throw new Error("The Properties argument must be an object.");d._.defaults(a,b.original||{});var c=["_links","_embedded"];Object.keys(a).forEach(function(b){d._.contains(c,b)||(this[b]=a[b])}.bind(this));var e=b.curies;e&&Object.keys(this).forEach(function(a){e.canExpand(a)&&Object.defineProperty(this,e.expand(a),{enumerable:!0,value:this[a]})}.bind(this))}var d=a.config;b.Properties=c}),a("hyperagent/resource",["hyperagent/config","hyperagent/loader","hyperagent/properties","hyperagent/curie","exports"],function(a,b,c,d,e){"use strict";function f(a){this._options=Object(a)===a?a:{url:a},this.props=new l({}),this.embedded={},this.links={},this.curies=new m,this._loadHooks=[this._loadLinks,this._loadEmbedded,this._loadProperties].concat(j.loadHooks),this.loaded=!1}function g(a,b,c){this._parent=a,this._options=n.defaults(c||{},{factory:function(a,b){var c=new f(b);return c._load(a),c}}),Object.defineProperties(this,{_parent:{enumerable:!1},_options:{enumerable:!1}}),n.each(b,function(a,b){Array.isArray(a)?this._setLazyArray(b,a,!0):this._setLazyObject(b,a,!0)}.bind(this));var d=this._options.curies;d&&!d.empty()&&n.each(b,function(a,b){if(d.canExpand(b)){var c=d.expand(b);Array.isArray(a)?this._setLazyArray(c,a,!1):this._setLazyObject(c,a,!1)}}.bind(this))}function h(a,b){f.call(this,b),this._load(a),this.loaded=!0}function i(a,b){f.call(this,b),this.href=a.href,this.templated=a.templated,this.href?this.templated||this._navigateUrl(this.href):console.warn("Link object did not provide an `href`: ",a),this._load(a)}var j=a.config,k=b.loadAjax,l=c.Properties,m=d.CurieStore,n=j._;f.factory=function(a){return function(b,c){return new a(b,c)}},f.prototype.fetch=function(a){if(a=n.defaults(a||{},{force:!1}),this.loaded&&!a.force){var b=j.defer();return b.resolve(this),b.promise}var c=n.pick(this._options,"headers","username","password","url");return this._options.ajax&&n.extend(c,this._options.ajax),a.ajax&&n.extend(c,a.ajax),k(c).then(function(a){return this._parse(a),this.loaded=!0,this}.bind(this))},f.prototype.url=function(){return this._options.url},f.prototype.link=function(a,b){var c=this.links[a];return b&&c.expand(b),c},f.prototype._parse=function(a){var b=JSON.parse(a);this._load(b)},f.prototype._loadLinks=function(a){a._links&&(a._links.curies&&(this._loadCuries(a._links.curies),delete a._links.curies),a._links.self&&this._navigateUrl(a._links.self.href),this.links=new g(this,a._links,{factory:f.factory(i),curies:this.curies}))},f.prototype._loadEmbedded=function(a){a._embedded&&(this.embedded=new g(this,a._embedded,{factory:f.factory(h),curies:this.curies}))},f.prototype._loadProperties=function(a){this.props=new l(a,{curies:this.curies,original:this.props})},f.prototype._load=function(a){this._loadHooks.forEach(function(b){b.bind(this)(a)}.bind(this))},f.prototype._loadCuries=function(a){return Array.isArray(a)?(a.forEach(function(a){a.templated||console.warn("CURIE links should always be marked as templated: ",a),this.curies.register(a.name,a.href)}.bind(this)),void 0):(console.warn("Expected `curies` to be an array, got instead: ",a),void 0)},f.resolveUrl=function(a,b){if(!b)throw new Error("Expected absolute or relative URL, but got: "+b);var c=new URI(b);return c.is("absolute")?c.normalize().toString():"/"===b[0]?new URI(a).resource(b).normalize().toString():new URI([a,b].join("/")).normalize().toString()},f.prototype._navigateUrl=function(a){var b=f.resolveUrl(this._options.url,a);return b!==this._options.url?(this._options.url=b,!0):!1},g.prototype._setLazyObject=function(a,b,c){Object.defineProperty(this,a,{enumerable:c,get:this._makeGetter(b)})},g.prototype._setLazyArray=function(a,b,c){Object.defineProperty(this,a,{enumerable:c,get:function(){return b.map(function(a){return this._makeGetter(a)()}.bind(this))}})},g.prototype._makeGetter=function(a){var b,c=this._parent,d=this._options;return function(){return void 0===b&&(b=new d.factory(a,n.clone(c._options))),b}},n.extend(h.prototype,f.prototype),n.extend(i.prototype,f.prototype),i.prototype.expand=function(a){this.templated||console.log("Trying to expand non-templated LinkResource: ",this);var b=new URI.expand(this.href,a).toString();this._navigateUrl(b)&&(this.loaded=!1)},i.prototype.toString=function(){return'LinkResource(url="'+this.url()+'")'},e.Resource=f,e.LazyResource=g,e.LinkResource=i}),window.Hyperagent=b("hyperagent")}(); \ No newline at end of file +!function(){var a,b;!function(){"use strict";var c={},d={};a=function(a,b,d){c[a]={deps:b,callback:d}},b=function(a){if(d[a])return d[a];d[a]={};for(var e,f=c[a],g=f.deps,h=f.callback,i=[],j=0,k=g.length;k>j;j++)"exports"===g[j]?i.push(e={}):i.push(b(g[j]));var l=h.apply(this,i);return d[a]=e||l}}(),a("hyperagent",["hyperagent/resource","hyperagent/properties","hyperagent/curie","hyperagent/config","exports"],function(a,b,c,d,e){"use strict";function f(a,b){l[a]=b}var g=a.Resource,h=a.LazyResource,i=a.LinkResource,j=b.Properties,k=c.CurieStore,l=d.config;e.Resource=g,e.Properties=j,e.LazyResource=h,e.LinkResource=i,e.CurieStore=k,e.configure=f,e._config=l}),a("hyperagent/config",["hyperagent/miniscore","exports"],function(a,b){"use strict";var c=a._,d={};"undefined"!=typeof window&&(d.ajax=window.$&&window.$.ajax.bind(window.$),d.defer=window.Q&&window.Q.defer,d._=c,d.loadHooks=[]),b.config=d}),a("hyperagent/curie",["exports"],function(a){"use strict";function b(){this._store={}}b.prototype.register=function(a,b){this._store[a]=URITemplate(b)},b._split=function(a){var b=a.indexOf(":"),c=a.substring(0,b),d=a.substring(b+1);return-1===a||a===a.length-1?null:[c,d]},b.prototype.empty=function(){return 0===Object.keys(this._store).length},b.prototype.expand=function(a){var c,d=b._split(a);return d?(c=this._store[d[0]],void 0===c?a:c.expand({rel:d[1]})):a},b.prototype.canExpand=function(a){var c=b._split(a);return c?void 0!==this._store[c[0]]:!1},a.CurieStore=b}),a("hyperagent/loader",["hyperagent/config","exports"],function(a,b){"use strict";function c(a){var b=d.defer();return a.headers&&d._.extend(a.headers,{Accept:"application/hal+json, application/json, */*; q=0.01","X-Requested-With":"XMLHttpRequest"}),d.ajax(d._.extend({success:b.resolve,error:b.reject,dataType:"html"},a)),b.promise}var d=a.config;b.loadAjax=c}),a("hyperagent/miniscore",["exports"],function(a){"use strict";var b={},c={};b.each=b.forEach=function(a,b,d){if(null!==a&&void 0!==a)if(a.forEach===Array.prototype.forEach)a.forEach(b,d);else if(a.length===+a.length){for(var e=0,f=a.length;f>e;e++)if(b.call(d,a[e],e,a)===c)return}else for(var g in a)if(a.hasOwnProperty(g)&&b.call(d,a[g],g,a)===c)return},b.contains=function(a,c){return null===a||void 0===a?!1:a.indexOf===Array.prototype.indexOf?-1!==a.indexOf(c):b.any(a,function(a){return a===c})},b.pick=function(a){var c={},d=Array.prototype.concat.apply(Array.prototype,Array.prototype.slice.call(arguments,1));return b.each(d,function(b){b in a&&(c[b]=a[b])}),c},b.extend=function(a){return b.each(Array.prototype.slice.call(arguments,1),function(b){if(b)for(var c in b)a[c]=b[c]}),a},b.defaults=function(a){return b.each(Array.prototype.slice.call(arguments,1),function(b){if(b)for(var c in b)(null===a[c]||void 0===a[c])&&(a[c]=b[c])}),a},b.clone=function(a){return a!==Object(a)?a:Array.isArray(a)?a.slice():b.extend({},a)},a._=b}),a("hyperagent/properties",["hyperagent/config","exports"],function(a,b){"use strict";function c(a,b){if(b=b||{},Object(a)!==a)throw new Error("The Properties argument must be an object.");d._.defaults(a,b.original||{});var c=["_links","_embedded"];Object.keys(a).forEach(function(b){d._.contains(c,b)||(this[b]=a[b])}.bind(this));var e=b.curies;e&&Object.keys(this).forEach(function(a){e.canExpand(a)&&Object.defineProperty(this,e.expand(a),{enumerable:!0,value:this[a]})}.bind(this))}var d=a.config;b.Properties=c}),a("hyperagent/resource",["hyperagent/config","hyperagent/loader","hyperagent/properties","hyperagent/curie","exports"],function(a,b,c,d,e){"use strict";function f(a){this._options=Object(a)===a?a:{url:a},this.props=new l({}),this.embedded={},this.links={},this.curies=new m,this._loadHooks=[this._loadLinks,this._loadEmbedded,this._loadProperties].concat(j.loadHooks),this.loaded=!1}function g(a,b,c){this._parent=a,this._options=n.defaults(c||{},{factory:function(a,b){var c=new f(b);return c._load(a),c}}),Object.defineProperties(this,{_parent:{enumerable:!1},_options:{enumerable:!1}}),n.each(b,function(a,b){Array.isArray(a)?this._setLazyArray(b,a,!0):this._setLazyObject(b,a,!0)}.bind(this));var d=this._options.curies;d&&!d.empty()&&n.each(b,function(a,b){if(d.canExpand(b)){var c=d.expand(b);Array.isArray(a)?this._setLazyArray(c,a,!1):this._setLazyObject(c,a,!1)}}.bind(this))}function h(a,b){f.call(this,b),this._load(a),this.loaded=!0}function i(a,b){f.call(this,b),this.href=a.href,this.templated=a.templated,this.href?this.templated||this._navigateUrl(this.href):console.warn("Link object did not provide an `href`: ",a),this._load(a)}var j=a.config,k=b.loadAjax,l=c.Properties,m=d.CurieStore,n=j._;f.factory=function(a){return function(b,c){return new a(b,c)}},f.prototype.fetch=function(a){if(a=n.defaults(a||{},{force:!1}),this.loaded&&!a.force){var b=j.defer();return b.resolve(this),b.promise}var c=n.pick(this._options,"headers","username","password","url");return this._options.ajax&&n.extend(c,this._options.ajax),a.ajax&&n.extend(c,a.ajax),k(c).then(function(a){return this._parse(a),this.loaded=!0,this}.bind(this))},f.prototype.url=function(){return this._options.url},f.prototype.link=function(a,b){var c=this.links[a];return b&&c.expand(b),c},f.prototype._parse=function(a){var b=JSON.parse(a);this._load(b)},f.prototype._loadLinks=function(a){a._links&&(a._links.curies&&(this._loadCuries(a._links.curies),delete a._links.curies),a._links.self&&this._navigateUrl(a._links.self.href),this.links=new g(this,a._links,{factory:f.factory(i),curies:this.curies}))},f.prototype._loadEmbedded=function(a){a._embedded&&(this.embedded=new g(this,a._embedded,{factory:f.factory(h),curies:this.curies}))},f.prototype._loadProperties=function(a){this.props=new l(a,{curies:this.curies,original:this.props})},f.prototype._load=function(a){this._loadHooks.forEach(function(b){b.bind(this)(a)}.bind(this))},f.prototype._loadCuries=function(a){return Array.isArray(a)?(a.forEach(function(a){a.templated||console.warn("CURIE links should always be marked as templated: ",a),this.curies.register(a.name,a.href)}.bind(this)),void 0):(console.warn("Expected `curies` to be an array, got instead: ",a),void 0)},f.resolveUrl=function(a,b){if(!b)throw new Error("Expected absolute or relative URL, but got: "+b);var c=new URI(b);return c.is("absolute")?c.normalize().toString():"/"===b[0]?new URI(a).resource(b).normalize().toString():new URI([a,b].join("/")).normalize().toString()},f.prototype._navigateUrl=function(a){var b=f.resolveUrl(this._options.url,a);return b!==this._options.url?(this._options.url=b,!0):!1},g.prototype._setLazyObject=function(a,b,c){Object.defineProperty(this,a,{enumerable:c,get:this._makeGetter(b)})},g.prototype._setLazyArray=function(a,b,c){Object.defineProperty(this,a,{enumerable:c,get:function(){return b.map(function(a){return this._makeGetter(a)()}.bind(this))}})},g.prototype._makeGetter=function(a){var b,c=this._parent,d=this._options;return function(){return void 0===b&&(b=new d.factory(a,n.clone(c._options))),b}},n.extend(h.prototype,f.prototype),n.extend(i.prototype,f.prototype),i.prototype.expand=function(a){this.templated||console.log("Trying to expand non-templated LinkResource: ",this);var b=new URI.expand(this.href,a).toString();this._navigateUrl(b)&&(this.loaded=!1)},i.prototype.toString=function(){return'LinkResource(url="'+this.url()+'")'},e.Resource=f,e.LazyResource=g,e.LinkResource=i}),window.Hyperagent=b("hyperagent")}(); \ No newline at end of file