-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththeon.min.js
4 lines (4 loc) · 35 KB
/
theon.min.js
1
2
3
4
/*! theon v - MIT license - https://github.com/h2non/theon */
(function(t){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=t()}else if(typeof define==="function"&&define.amd){define([],t)}else{var e;if(typeof window!=="undefined"){e=window}else if(typeof global!=="undefined"){e=global}else if(typeof self!=="undefined"){e=self}else{e=this}e.theon=t()}})(function(){var t,e,r;return function t(e,r,n){function o(s,u){if(!r[s]){if(!e[s]){var a=typeof require=="function"&&require;if(!u&&a)return a(s,!0);if(i)return i(s,!0);var p=new Error("Cannot find module '"+s+"'");throw p.code="MODULE_NOT_FOUND",p}var c=r[s]={exports:{}};e[s][0].call(c.exports,function(t){var r=e[s][1][t];return o(r?r:t)},c,c.exports,t,e,r,n)}return r[s].exports}var i=typeof require=="function"&&require;for(var s=0;s<n.length;s++)o(n[s]);return o}({1:[function(t,e,r){e.exports={embed:t("./lil")}},{"./lil":2}],2:[function(t,e,r){e.exports=function(e,r,o){var i=t("lil-http");var s={url:e.url,method:e.method,auth:e.opts.auth,params:e.query,headers:e.headers,timeout:+e.opts.timeout||+e.agentOpts.timeout,withCredentials:e.agentOpts.withCredentials,data:e.body};return i(s,function(t,e){o(t,n(r,t||e))})};function n(t,e){t.setOriginalResponse(e);t.setStatus(e.status);t.setStatusText(e.statusText);t.setHeaders(e.headers);if(e.data)t.setBody(e.data);return t}},{"lil-http":37}],3:[function(t,e,r){var n=typeof window!=="undefined";var o=r.agents=n?t("./browser"):t("./node");r.get=function(t){return t?o[t]:o.embed};r.defaults=function(){return r.get()};r.set=function(t){r.add("embed",t)};r.add=function(t,e){if(typeof t!=="string"){throw new TypeError("first argument must be a string")}if(typeof e!=="function"){throw new TypeError("agent must be a function")}o[t]=e};r.remove=function(t){delete o[t]}},{"./browser":1,"./node":4}],4:[function(t,e,r){e.exports={embed:t("./request")}},{"./request":5}],5:[function(t,e,r){var n=t("request");var o=t("../../utils");e.exports=function(t,e,r){var s={url:t.url,qs:t.query,headers:t.headers,method:t.method,useQuerystring:true};if(t.body)s.body=t.body;s.json=t.opts.format==="json";if(t.opts.auth){s.auth=t.opts.auth}o.extend(s,t.agentOpts);return t.stream?t.stream.pipe(n(s,u)):n(s,u);function u(t,n,o){r(t,i(e,n,o))}};function i(t,e,r){if(!e)return t;t.setOriginalResponse(e);t.setStatus(e.statusCode);t.setStatusText(e.statusText);t.setHeaders(e.headers);if(r)t.setBody(r);return t}},{"../../utils":30,request:36}],6:[function(t,e,r){var n=t("./utils");var o=t("./agents");var i=t("./context");var s=t("./http/response");var u=t("./dispatcher");var a=t("./middleware");e.exports=p;function p(t){this.parent=null;this.publicClient=null;this.plugins=[];this.ctx=new i(t);p.defineAccessors(this)}p.prototype.useParent=function(t){if(!(t instanceof p)){throw new TypeError("Parent context is invalid")}this.parent=t;this.ctx.useParent(t.ctx);return this};p.prototype.options=function(t){n.extend(this.ctx.opts,t);return this};p.prototype.persistOptions=function(t){this.ctx.persistent.opts=t;return this};p.prototype.use=p.prototype.useRequest=function(t){this.ctx.middleware.use("middleware request",t);return this};p.prototype.useEntity=p.prototype.useEntityRequest=function(t){var e="middleware request "+this.entityHierarchy;this.ctx.middleware.use(e,t);return this};p.prototype.useResponse=function(t){this.ctx.middleware.use("middleware response",t);return this};p.prototype.useEntityResponse=function(t){var e="middleware response "+this.entityHierarchy;this.ctx.middleware.use(e,t);return this};p.prototype.handle=p.prototype.response=function(t){this.useResponse(function(e,r,n){t(r,e);n()});return this};p.prototype.before=function(t){this.ctx.middleware.use("before",t);return this};p.prototype.after=function(t){this.ctx.middleware.use("after",t);return this};p.prototype.validator=p.prototype.requestValidator=function(t){this.ctx.middleware.use("validator request",t);return this};p.prototype.entityValidator=p.prototype.entityRequestValidator=function(t){var e="validator request "+this.entityHierarchy;this.ctx.middleware.use(e,t);return this};p.prototype.responseValidator=function(t){this.ctx.middleware.use("validator response",t);return this};p.prototype.entityResponseValidator=function(t){var e="validator response "+this.entityHierarchy;this.ctx.middleware.use(e,t);return this};p.prototype.interceptor=function(t){this.ctx.middleware.use("before dial",t);return this};p.prototype.entityInterceptor=function(t){this.ctx.middleware.use("before dial "+this.entityHierarchy,t);return this};p.prototype.evaluator=function(t){this.ctx.middleware.use("before response",t);return this};p.prototype.entityEvaluator=function(t){this.ctx.middleware.use("before response"+this.entityHierarchy,t);return this};p.prototype.validate=function(t){var e=this.raw();var r=new s(this.req);var n=new u(this);n.runStack("validator","request",e,r,t);return this};p.prototype.observe=function(t,e){this.ctx.middleware.use(t,e);return this};p.prototype.observeEntity=function(t,e){this.ctx.middleware.use(t+" "+this.entityHierarchy,e);return this};p.prototype.plugin=p.prototype.usePlugin=function(t){if(typeof t!=="function"){throw new TypeError("plugin must be a function")}var e=t(this);this.plugins.push({fn:t,instance:e});return this};p.prototype.getPlugin=function(t){return this.plugins.reduce(function(r,n){if(r)return r;if(e(n,t))return n.instance||n;return null},null);function e(t,e){return e===t.fn||e===t.instance||e===t.fn.$name||e===t.fn.name}};p.prototype.model=function(t){this.useResponse(a.model(t));return this};p.prototype.map=p.prototype.bodyMap=function(t){this.useResponse(a.map(t));return this};p.prototype.agent=p.prototype.useAgent=function(t){if(typeof t==="string"){t=o.get(t)}if(typeof t!=="function"){throw new TypeError("unsupported or invalid agent")}this.ctx.agent=t;return this};p.prototype.agentOpts=function(t){n.extend(this.ctx.agentOpts,t);return this};p.prototype.setAgentOpts=function(t){this.ctx.agentOpts=t;return this};p.prototype.persistAgentOpts=function(t){this.ctx.persistent.agentOpts=t;return this};p.prototype.getStore=function(){return this.ctx.store};p.prototype.getRoot=function(){return this.parent?this.parent.root:this};p.prototype.getApi=function(){return this.parent?this.parent.api:this.publicClient};p.prototype.getEntityHierarchy=function(){var t="";if(this.parent){var e=this.parent.entityHierarchy;t=e?e+" ":t}if(this.entity){t+=this.entity+" "+(this.name||"*")}return t};p.accessors=["api","root","store","entityHierarchy"];p.defineAccessors=function(t,e){p.accessors.forEach(function(r){var o="get"+n.capitalize(r);Object.defineProperty(e||t,r,{enumerable:true,configurable:false,get:function(){return t[o]()},set:function(){throw new Error("Cannot overwrite protected property")}})})}},{"./agents":3,"./context":7,"./dispatcher":8,"./http/response":19,"./middleware":20,"./utils":30}],7:[function(t,e,r){var n=t("midware-pool");var o=t("./agents");var i=t("./store");var s=t("./utils");e.exports=u;function u(t){this.body=this.stream=this.method=this.parent=null;this.opts={};this.query={};this.params={};this.headers={};this.cookies={};this.persistent={};this.agentOpts={};this.agent=o.defaults();this.store=new i;this.middleware=new n;if(t)this.useParent(t)}u.fields=["opts","headers","query","params","cookies","agentOpts"];u.prototype.useParent=function(t){this.parent=t;["middleware","store"].forEach(function(e){this[e].useParent(t[e])},this);return this};u.prototype.raw=function(){var t=this.merge();t.agent=this.agent;t.ctx=this;t.store=this.store;if(!t.method)t.method="GET";return t};u.prototype.merge=function(){var t={};var e=this.parent?this.parent.raw():{};["method","body","stream"].forEach(function(r){t[r]=this[r]||e[r]||null},this);u.fields.forEach(function(r){var n=r==="headers"?a:s.merge;t[r]=n(e[r],this[r],this.persistent[r])},this);var r=this.opts.rootUrl;if(r)t.opts.rootUrl=r;return t};u.prototype.renderParams=function(t){var e=t.params=t.params||{};var r=this;Object.keys(e).forEach(function(n){if(typeof e[n]==="function"){e[n]=e[n](r,t)}});return e};u.prototype.clone=function(){var t=new u;return t.useParent(this)};u.prototype.buildPath=function(){return u.buildPath(this)};u.buildPath=function t(e){var r="";if(e.parent){r+=t(e.parent)}var n=e.opts;var o=n.basePath||"";var i=n.path||"";return r+o+i};function a(){return s.normalize(s.merge.apply(null,arguments))}},{"./agents":3,"./store":23,"./utils":30,"midware-pool":38}],8:[function(t,e,r){var n=t("path-params");var o=t("./utils");var i=t("./http/response");e.exports=s;function s(t){this.req=t}s.prototype.run=function(t){t=t||a;var e=this.req.ctx;var r=this.req.raw();var n=new i(r);function s(n,o,i){o=o||r;var s=this.req;if(n==="intercept")n=null;if(i&&!i.req)i.req=o;if(!n)return t(null,i,s);o.error=n;e.middleware.run("error",o,i,function(e,r){t(e||n,r||i,s)})}o.series([function t(e){this.before(r,n,e)},function t(e,r,n){this.dial(e,r,n)},function t(e,r,n){this.after(e,r,n)}],s,this);return this.req};s.prototype.before=function(t,e,r){o.series([function r(n){this.runHook("before",t,e,n)},function t(e,r,n){this.runPhase("request",e,r,n)}],r,this)};s.prototype.after=function(t,e,r){o.series([function r(n){this.runPhase("response",t,e,n)},function t(e,r,n){this.runHook("after",e,r,n)}],r,this)};s.prototype.dial=function(t,e,r){var i=t.opts.rootUrl||"";var s=t.ctx.buildPath();var u=t.ctx.renderParams(t);var a=n(s,u);if(a instanceof Error)return r(a);t.url=i+a;o.series([function r(n){this.runMiddleware("before dial",t,e,n)},function(t,e,r){this.doDial(t,e,r)},function t(e,r,n){this.runMiddleware("after dial",e,r,n)}],r,this)};s.prototype.doDial=function(t,e,r){var n=o.once(u(t,e,r));e.orig=t.ctx.agent(t,e,n);if(e.orig&&e.orig.pipe){(t.pipes||this.req.pipes||[]).forEach(e.orig.pipe,e.orig)}this.runMiddleware("dialing",t,e,i);function i(t){if(t&&e.orig&&typeof e.orig.abort==="function"){n(new Error("Request aborted: "+(t.message||t)));try{e.orig.abort()}catch(t){}}}};s.prototype.runHook=function(t,e,r,n){o.series([function n(o){this.runMiddleware(t,e,r,o)},function e(r,n,o){this.runEntity(t,r,n,o)}],n,this)};s.prototype.runPhase=function(t,e,r,n){o.series([function n(o){this.runHook("before "+t,e,r,o)},function e(r,n,o){this.runStack("middleware",t,r,n,o)},function e(r,n,o){this.runStack("validator",t,r,n,o)},function e(r,n,o){this.runHook("after "+t,r,n,o)}],n,this)};s.prototype.runStack=function(t,e,r,n,i){var s=t+" "+e;o.series([function t(e){this.runHook("before "+s,r,n,e)},function t(e,r,n){this.runMiddleware(s,e,r,n)},function t(e,r,n){this.runEntity(s,e,r,n)},function t(e,r,n){this.runHook("after "+s,e,r,n)}],i,this)};s.prototype.runEntity=function(t,e,r,n){if(!e.client)return n(null,e,r);var o=e.client.entityHierarchy;if(!o)return n(null,e,r);var i=t+" "+o;this.runMiddleware(i,e,r,n)};s.prototype.runMiddleware=function(t,e,r,n){e.ctx.middleware.run(t,e,r,u(e,r,n))};function u(t,e,r){return function(n,o){r(n,t,o||e)}}function a(){}},{"./http/response":19,"./utils":30,"path-params":41}],9:[function(t,e,r){var n=t("../base");var o=t("../http/request");var i=t("../http/response");e.exports=s;function s(t){this._client=t;this._client.publicClient=this;n.defineAccessors(this._client,this)}Object.keys(n.prototype).forEach(function(t){s.prototype[t]=function(){var e=this._client[t].apply(this._client,arguments);return e===this._client?this:e}});s.prototype.doRequest=function(t,e){t=t||{};var r=new i(t);return this._client.ctx.agent(t,r,e)};s.prototype.newRequest=function(t){var e=new o;e.useParent(t||this._client);return e};var u=["GET","POST","PUT","PATCH","DELETE","HEAD","TRACE","OPTIONS"];u.forEach(function(t){s.prototype[t]=function(e,r){e.method=t;return this.doRequest(e,r)}})},{"../base":6,"../http/request":18,"../http/response":19}],10:[function(t,e,r){var n=t("./client");var o=t("../utils").has;e.exports=i;function i(t){this.src=t;this.target=null}i.prototype.bind=function(t){this.target=t;return this};i.prototype.render=function(){var t=this.src;this.target=this.target?this.target:new n(t);if(!this.target._client)this.target._client=t;this.src.entities.forEach(this.renderEntity,this);if(t.proto)this.renderProto();return this.target};i.prototype.renderEntity=function(t){var e=t.name;if(!e)throw new TypeError("Render error: missing entity name");var r=t.renderEntity();var n=this.decorate(t,r);var o=[e].concat(t.aliases);o.forEach(function(t){this.define(t,n)},this)};i.prototype.decorate=function(t,e){var r=s(t,e);if(r===e)return e;if(typeof r!=="function")return r;var n=u(r);Object.keys(e).filter(function(t){return o(n,t)===false}).forEach(function(t){n[t]=e[t]});return n};function s(t,e){return t.decorators.reduce(function(e,r){return r.call(t,e)||e},e)}function u(t){return function e(){return t.apply(t,arguments)}}i.prototype.renderProto=function(){Object.keys(this.src.proto).forEach(function(t){this.define(t,this.src.proto[t])},this)};i.prototype.define=function(t,e){if(o(this.target,t))throw a(t);Object.defineProperty(this.target,t,{enumerable:true,configurable:false,get:function(){return e},set:function(){throw new Error("Cannot overwrite property: "+t)}})};function a(t){return new Error('Name conflict: "'+t+'" property is already defined')}},{"../utils":30,"./client":9}],11:[function(t,e,r){e.exports={Client:t("./client"),Generator:t("./generator")}},{"./client":9,"./generator":10}],12:[function(t,e,r){var n=t("./entity");e.exports=o;function o(t){n.call(this);if(t)this.url(t)}o.prototype=Object.create(n.prototype);o.prototype.constructor=o;o.prototype.entity="client"},{"./entity":14}],13:[function(t,e,r){var n=t("./entity");var o=t("../engine").Generator;e.exports=n.Collection=i;function i(t){n.call(this,t)}i.prototype=Object.create(n.prototype);i.prototype.constructor=i;i.prototype.entity="collection";i.prototype.useConstructor=function(t){if(typeof t==="function")this.constructorFn=t;return this};i.prototype.renderEntity=function(t){var e=t||this;return n(r,e);function r(t){var r={};var o=e.clone();if(o.constructorFn){return o.constructorFn.apply(o,arguments)||n(r,o)}if(t===Object(t))o.options(t);return n(r,o)}function n(t,e){return new o(e).bind(t).render()}}},{"../engine":11,"./entity":14}],14:[function(t,e,r){var n=t("../base");var o=t("../engine");var i=t("../http/request");var s=t("../utils").extend;e.exports=u;function u(t){i.call(this);this.name=t;this.aliases=[];this.entities=[];this.decorators=[];this.proto=Object.create(null)}u.prototype=Object.create(i.prototype);u.accessors=n.accessors.concat("parent");u.prototype.constructor=u;u.prototype.alias=function(t){var e=this.aliases;e.push.apply(e,arguments);return this};u.prototype.collection=function(t){if(!(t instanceof u.Collection)){t=new u.Collection(t)}return this.addEntity(t)};u.prototype.action=u.prototype.resource=function(t){if(!(t instanceof u.Resource)){t=new u.Resource(t)}return this.addEntity(t)};u.prototype.mixin=u.prototype.helper=function(t,e){if(!(t instanceof u.Mixin)){e=new u.Mixin(t,e)}return this.addEntity(e)};u.prototype.addEntity=function(t){if(a(t)){throw new TypeError("entity must implement render() method")}if(t.useParent){t.useParent(this)}var e=this.getEntity(t.name,t.entity);if(e)return e;this.entities.push(t);return t};u.prototype.getCollection=u.prototype.findCollection=function(t){return this.getEntity(t,"collection")};u.prototype.getAction=u.prototype.getResource=u.prototype.findResource=function(t){return this.getEntity(t,"resource")};u.prototype.getMixin=u.prototype.findMixin=function(t){return this.getEntity(t,"mixin")};u.prototype.getClient=u.prototype.findClient=function(t){return this.getEntity(t,"client")};u.prototype.getEntity=u.prototype.findEntity=function(t,e){return this.entities.reduce(function(r,n){if(r)return r;if(n.name===t&&(!e||n.entity===e)){return n}return null},null)};u.prototype.useConstructor=function(){throw new Error("Method only implemented for resource and collection entities")};u.prototype.decorate=u.prototype.decorator=function(t){if(typeof t==="function"){this.decorators.push(t)}return this};u.prototype.meta=function(t){var e=this.ctx.store;var r=e.get("meta");if(r){t=s(r,t)}e.set("meta",t);return this};u.prototype.extend=function(t,e){if(typeof t==="string")this.proto[t]=e;else if(t===Object(t))s(this.proto,t);return this};u.prototype.render=function(t){if(this.parent){return this.parent.render(t)}return this.renderEntity(t)};u.prototype.renderEntity=function(t){return new o.Generator(t||this).render()};u.prototype.clone=function(){var t=new this.constructor(this.name);t.useParent(this.parent);Object.keys(this).filter(function(t){return!~u.accessors.indexOf(t)}).forEach(function(e){t[e]=this[e]},this);t.ctx=this.ctx.clone();return t};function a(t){return!t||typeof t.renderEntity!=="function"}},{"../base":6,"../engine":11,"../http/request":18,"../utils":30}],15:[function(t,e,r){e.exports={Mixin:t("./mixin"),Entity:t("./entity"),Client:t("./client"),Resource:t("./resource"),Collection:t("./collection")}},{"./client":12,"./collection":13,"./entity":14,"./mixin":16,"./resource":17}],16:[function(t,e,r){var n=t("./entity");e.exports=n.Mixin=o;function o(t,e){if(typeof e!=="function"){throw new TypeError("mixin argument must be a function")}n.call(this,t);this.fn=e}o.prototype=Object.create(n.prototype);o.prototype.constructor=o;o.prototype.entity="mixin";o.prototype.renderEntity=function(){var t=this;return function(){return t.fn.apply(t,arguments)}};o.prototype.mixin=o.prototype.helper=o.prototype.action=o.prototype.resource=o.prototype.collection=o.prototype.getMixin=o.prototype.getClient=o.prototype.getEntity=o.prototype.getResource=o.prototype.getCollection=function(){throw new Error("not implemented for mixin entity")}},{"./entity":14}],17:[function(t,e,r){var n=t("./entity");var o=t("../http/request");var i=t("../engine").Generator;e.exports=n.Resource=s;function s(t){n.call(this,t)}s.prototype=Object.create(n.prototype);s.prototype.constructor=s;s.prototype.entity="resource";s.prototype.useConstructor=function(t){if(typeof t==="function")this.constructorFn=t;return this};s.prototype.renderEntity=function(t){var e=t||this;return new i(this).bind(r).render();function r(t,r){var n=new o;n.useParent(e);if(e.constructorFn){return e.constructorFn.apply(n,arguments)||n}if(t===Object(t))n.options(t);if(typeof t==="function")r=t;return typeof r==="function"?n.end(r):n}}},{"../engine":11,"../http/request":18,"./entity":14}],18:[function(t,e,r){var n=t("../base");var o=t("../types");var i=t("../utils");var s=t("../dispatcher");var u=typeof Promise==="function";e.exports=a;function a(t){n.call(this,t);this.pipes=[];this.dispatcher=null}a.prototype=Object.create(n.prototype);a.prototype.url=function(t){this.ctx.opts.rootUrl=t;return this};a.prototype.path=function(t){this.ctx.opts.path=t;return this};a.prototype.basePath=function(t){this.ctx.opts.basePath=t;return this};a.prototype.method=function(t){this.ctx.method=t;return this};a.prototype.param=function(t,e){this.ctx.params[t]=e;return this};a.prototype.params=function(t,e){if(t&&e)return this.param(t,e);i.extend(this.ctx.params,t);return this};a.prototype.persistField=function(t,e,r){var n=this.ctx.persistent;var o=n[t]||{};o[e]=r;n[t]=o;return this};a.prototype.persistParam=function(t,e){return this.persistField("params",t,e)};a.prototype.persistParams=function(t,e){if(t&&e)return this.persistParam(t,e);i.extend(this.ctx.persistent.params,t);return this};a.prototype.unsetParam=function(t){delete this.ctx.params[t];return this};a.prototype.setParams=function(t){this.ctx.params=t;return this};a.prototype.query=function(t,e){if(t&&e)return this.queryParam(t,e);i.extend(this.ctx.query,t);return this};a.prototype.queryParam=function(t,e){this.ctx.query[t]=e;return this};a.prototype.unsetQuery=function(t){delete this.ctx.query[t];return this};a.prototype.persistQueryParam=function(t,e){return this.persistField("query",t,e)};a.prototype.persistQuery=a.prototype.persistQueryParams=function(t,e){if(t&&e)return this.persistentQueryParam(t,e);i.extend(this.ctx.persistent.query,t);return this};a.prototype.setQuery=function(t){this.ctx.query=t;return this};a.prototype.set=a.prototype.header=function(t,e){this.ctx.headers[i.lower(t)]=e;return this};a.prototype.unset=a.prototype.removeHeader=function(t){delete this.ctx.headers[i.lower(t)];return this};a.prototype.headers=function(t,e){if(t&&e)return this.set(t,e);i.extend(this.ctx.persistent.headers,i.normalize(t));return this};a.prototype.setHeaders=function(t){this.ctx.headers=i.normalize(t);return this};a.prototype.persistHeader=function(t,e){var r=this.ctx.persistent.headers||{};r[i.lower(t)]=e;this.ctx.persistent.headers=r;return this};a.prototype.persistHeaders=function(t,e){if(t&&e)return this.persistHeader(t,e);i.extend(this.ctx.persistent.headers,t);return this};a.prototype.format=function(t){this.ctx.opts.format=t;return this};a.prototype.type=a.prototype.mimeType=function(t,e){var r=this.ctx;var n=o[t]||t;if(~n.indexOf("json")){r.agentOpts.json=true}r.headers[e||"content-type"]=n;return this};a.prototype.accept=function(t){return this.type(t,"accept")};a.prototype.send=a.prototype.body=function(t){this.ctx.body=t;return this};a.prototype.cookie=function(t,e){this.ctx.cookies[t]=e;return this};a.prototype.unsetCookie=function(t){delete this.ctx.cookies[t];return this};a.prototype.auth=function(t,e){this.ctx.opts.auth={user:t,password:e};return this};a.prototype.dispatch=function(t){if(this.dispatcher){t(new Error("Request already dispatched"));return this}var e=this.dispatcher=new s(this);setTimeout(function(){e.run(t)},0);return this};a.prototype.end=a.prototype.done=function(t){return this.dispatch(t)};a.prototype.then=function(t,e){if(!u)return p();if(this.promise)return this.promise.then(t,e);var r=this;this.promise=new Promise(function(t,e){r.end(function(r,n){if(r||n.error)e(r||n);else t(n)})});return this.promise.then(t,e)};a.prototype.catch=function(t){if(!u)return p();if(this.promise)return this.promise.catch(t);return this.then(c,t)};a.prototype.pipe=function(t){this.pipes.push(t);return this};a.prototype.stream=a.prototype.bodyStream=function(t){if(!t||typeof t.pipe!=="function"){throw new TypeError("Invalid stream interface")}this.ctx.stream=t;return this};a.prototype.raw=function(){var t=this.ctx.raw();t.client=this;t.root=this.root;return t};a.prototype.clone=function(){var t=this.ctx.clone();var e=new a(t);e.parent=this.parent;return e};a.prototype.newRequest=function(t){var e=new a;e.useParent(t||this);return e};function p(){throw new Error("Native promises are not supported. Use callback instead via: .end(cb)")}function c(){}},{"../base":6,"../dispatcher":8,"../types":25,"../utils":30}],19:[function(t,e,r){e.exports=n;function n(t){this.req=t;this.store=t?t.store:null;this.client=t?t.client:null;this.orig=this.type=this.error=null;this.headers={};this.typeParams={};this.status=this.statusType=this.statusCode=0;this.type=this.statusText="";this.text=this.body=this.json=null}n.prototype.setOriginalResponse=function(t){this.orig=t};n.prototype.setBody=function(t){this.body=t;if(typeof t==="string"){this.text=t}if(t&&s(this.type,this.headers)){this.json=this.body=u(t)}};n.prototype.get=function(t){return this.headers[t.toLowerCase()]};n.prototype.setHeaders=function(t){Object.keys(t).forEach(function(e){this.headers[e.toLowerCase()]=t[e]},this);var e=this.headers["content-type"];if(e)this.setType(e)};n.prototype.setType=function(t){var e=t||"";this.type=i(e);var r=o(e);for(var n in r)this.typeParams[n]=r[n]};n.prototype.setStatus=function(t){if(t===1223)t=204;var e=t/100|0;this.statusType=e;this.status=this.statusCode=t;this.info=e===1;this.ok=e===2;this.clientError=e===4;this.serverError=e===5;this.error=e===4||e===5?this.toError():false;this.accepted=t===202;this.noContent=t===204;this.badRequest=t===400;this.unauthorized=t===401;this.notAcceptable=t===406;this.notFound=t===404;this.forbidden=t===403};n.prototype.setStatusText=function(t){this.statusText=t};n.prototype.toError=function(){var t=this.req;var e=t.url;var r=t.method;var n=this.status||this.statusCode;var o="cannot "+r+" "+e+" ("+n+")";var i=new Error(o);i.status=n;i.method=r;i.url=e;return i};function o(t){return t.split(/ *; */).reduce(function(t,e){var r=e.split(/ *= */);var n=r.shift();var o=r.shift();if(n&&o)t[n]=o;return t},{})}function i(t){return t.split(/ *; */).shift()}function s(t,e){return~t.indexOf("json")||~"".indexOf.call(e["content-type"]||"","json")}function u(t){try{return JSON.parse(t)}catch(e){return t}}},{}],20:[function(t,e,r){e.exports={map:t("./map"),model:t("./model")}},{"./map":21,"./model":22}],21:[function(t,e,r){e.exports=function t(e){return function(t,r,n){var o=r.body;if(!o)return n();e(o,function(t,e){if(t)return n(t);r.body=e;n()})}}},{}],22:[function(t,e,r){e.exports=function t(e){if(typeof e!=="function"){throw new TypeError("model must be a function")}return function(t,r,n){var o=r.body;if(o)r.model=e(o,t,r);n()}}},{}],23:[function(t,e,r){e.exports=n;function n(t){this.parent=t;this.map=Object.create(null)}n.prototype.getParent=function(t){if(this.parent)return this.parent.get(t)};n.prototype.get=function(t){var e=this.map[t];if(e!==undefined)return e;return this.getParent(t)};n.prototype.set=function(t,e){if(t)this.map[t]=e};n.prototype.setParent=function(t,e){if(this.parent)this.parent.set(t,e)};n.prototype.useParent=function(t){this.parent=t};n.prototype.remove=function(t){this.map[t]=undefined};n.prototype.has=function(t){return this.get(t)!==undefined}},{}],24:[function(t,e,r){e.exports=n;function n(t){return new n.entities.Client(t)}n.Request=t("./http/request");n.Response=t("./http/response");n.Context=t("./context");n.Store=t("./store");n.Base=t("./base");n.Dispatcher=t("./dispatcher");n.agents=t("./agents");n.engine=t("./engine");n.entities=t("./entities");Object.keys(n.entities).forEach(function(t){n[t.toLowerCase()]=function(e,r){return new n.entities[t](e,r)}});n.VERSION="0.2.0";Error.stackTraceLimit=10},{"./agents":3,"./base":6,"./context":7,"./dispatcher":8,"./engine":11,"./entities":15,"./http/request":18,"./http/response":19,"./store":23}],25:[function(t,e,r){e.exports={html:"text/html",json:"application/json",xml:"application/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"}},{}],26:[function(t,e,r){e.exports=function t(e){return e.slice(0,1).toUpperCase()+e.slice(1)}},{}],27:[function(t,e,r){e.exports=function t(e){var r={};if(Object(e)!==e)return r;for(var n in e)r[n]=e[n];return r}},{}],28:[function(t,e,r){e.exports=function t(e,r){e=e||{};if(Object(r)!==r)return e;for(var n in r)e[n]=r[n];return e}},{}],29:[function(t,e,r){e.exports=function t(e,r){return!!e&&Object.prototype.hasOwnProperty.call(e,r)}},{}],30:[function(t,e,r){e.exports={has:t("./has"),once:t("./once"),lower:t("./lower"),merge:t("./merge"),clone:t("./clone"),series:t("./series"),extend:t("./extend"),normalize:t("./normalize"),capitalize:t("./capitalize")}},{"./capitalize":26,"./clone":27,"./extend":28,"./has":29,"./lower":31,"./merge":32,"./normalize":33,"./once":34,"./series":35}],31:[function(t,e,r){e.exports=function t(e){return typeof e==="string"?e.toLowerCase():""}},{}],32:[function(t,e,r){var n=t("./clone");var o=t("./extend");var i=Array.prototype.slice;e.exports=function t(e,r){var s=i.call(arguments,1);e=n(e);s.forEach(function(t){o(e,t)});return e}},{"./clone":27,"./extend":28}],33:[function(t,e,r){e.exports=function t(e){var r={};Object.keys(e||{}).forEach(function(t){r[t.toLowerCase()]=e[t]});return r}},{}],34:[function(t,e,r){e.exports=function t(e){var r=false;return function(){if(r)return;r=true;e.apply(null,arguments)}}},{}],35:[function(t,e,r){var n=t("./once");var o=Array.prototype.slice;e.exports=function t(e,r,i){var s=e.slice();r=r||function(){};function u(t){if(t)return r.apply(i,arguments);var e=s.shift();if(!e)return r.apply(i,arguments);var a=o.call(arguments,1);e.apply(i,a.concat(n(u)))}u()}},{"./once":34}],36:[function(t,e,r){},{}],37:[function(e,r,n){(function(e,o){if(typeof t==="function"&&t.amd){t(["exports"],o)}else if(typeof n==="object"){o(n);if(typeof r==="object"&&r!==null){r.exports=n=n.http}}else{o(e.lil=e.lil||{})}})(this,function(t){"use strict";var e="0.1.17";var r=Object.prototype.toString;var n=Array.prototype.slice;var o=Object.prototype.hasOwnProperty;var i=typeof Function.prototype.bind==="function";var s=location.origin;var u=/^(http[s]?:\/\/[a-z0-9\-\.\:]+)[\/]?/i;var a=/application\/json/;var p=typeof XDomainRequest!=="undefined";var c=function(){};var f={method:"GET",timeout:30*1e3,auth:null,data:null,headers:null,withCredentials:false,responseType:"text"};function h(t){return t&&r.call(t)==="[object Object]"||false}function l(t){var e,r,i,s,u=n.call(arguments).slice(1);for(e=0,r=u.length;e<r;e+=1){s=u[e];for(i in s)if(o.call(s,i))t[i]=s[i]}return t}function y(t){var e=false;return function(){if(e===false){e=true;t.apply(null,arguments)}}}function d(t,e){if(!h(e))return;e["Content-Type"]=e["Content-Type"]||e["content-type"]||F.defaultContent;var r=Object.keys(e).reduce(function(t,r){var n=r.toLowerCase();if(n!==r){if(o.call(e,n)){delete e[n];delete t[n]}}t[r]=e[r];return t},{});Object.keys(r).forEach(function(e){t.setRequestHeader(e,r[e])})}function v(t){var e={},r=t.getAllResponseHeaders().trim().split("\n");r.forEach(function(t){var r=t.trim().split(":");var n=r.shift().trim();var o=r.join(":").trim();e[n]=o});return e}function m(t){return a.test(t.getResponseHeader("Content-Type"))}function x(t){return Object.getOwnPropertyNames(t).filter(function(e){return t[e]!==undefined}).map(function(e){var r=t[e]===null?"":t[e];return encodeURIComponent(e)+(r?"="+encodeURIComponent(r):"")}).join("&").replace(/%20/g,"+")}function w(t){var e=null;if(t.responseType==="text"){e=t.responseText;if(m(t)&&e)e=JSON.parse(e)}else{e=t.response}return e}function g(t){return t===1223?204:t}function b(t){var e={xhr:t,status:g(t.status),statusText:t.statusText,data:null,headers:{}};if(t.readyState===4){e.data=w(t);e.headers=v(t)}return e}function E(t,e){var r=b(t);r.error=e;if(e.stack)r.stack=e.stack;return r}function O(t){t.onreadystatechange=t.onerror=t.ontimeout=null}function P(t){var e=g(t.status);return e>=200&&e<300||e===304}function q(t,e){return y(function(r){e(E(t,r),null)})}function T(t,e,r){return function(t){if(e.readyState===4){O(e);if(P(e)){r(null,b(e))}else{q(e,r)(t)}}}}function C(t){var e=t.match(u);return e&&e[1]===s}function j(t){var e=t.url;if(h(t.params)){e+=(e.indexOf("?")===-1?"?":"&")+x(t.params)}return e}function R(t){if(p&&C(t)){return new XDomainRequest}else{return new XMLHttpRequest}}function k(t){var e=(t.method||"GET").toUpperCase();var r=t.auth;var n=j(t);if(!n||typeof n!=="string"){throw new TypeError("Missing required request URL")}var o=R(n);if(r){o.open(e,n,true,r.user,r.password)}else{o.open(e,n)}o.withCredentials=t.withCredentials;o.responseType=t.responseType;o.timeout=t.timeout;d(o,t.headers);return o}function H(t,e){return function(t){if(t.lengthComputable){e(t,t.loaded/t.total)}else{e(t)}}}function S(t){return t&&h(t.headers)&&(t.headers["content-type"]||t.headers["Content-Type"])||false}function A(t,e){var r=e.data;if(h(e.data)||Array.isArray(e.data)){if(S(e)===false){t.setRequestHeader("Content-Type","application/json")}r=JSON.stringify(e.data)}return r}function M(t,e){return function(){clearTimeout(e);t.apply(null,arguments)}}function U(t,e,r){var n=k(t);var o=A(n,t);var s=q(n,e);if(i){n.ontimeout=s}else{var u=setTimeout(function t(){if(n.readyState!==4){n.abort()}},t.timeout);e=M(e,u);s=q(n,e)}n.onreadystatechange=T(t,n,e);n.onerror=s;if(typeof r==="function"){n.onprogress=H(n,r)}try{n.send(o||null)}catch(t){s(t)}return{xhr:n,config:t}}function z(t){return function(e,r,o,i){var s,u,a=null;var p=l({},f,{method:t});var y=n.call(arguments);for(s=0,u=y.length;s<u;s+=1){a=y[s];if(typeof a==="function"){if(y.length===s+1&&typeof y[s-1]==="function"){i=a}else{o=a}}else if(h(a)){l(p,a)}else if(typeof a==="string"&&!p.url){
p.url=a}}return U(p,o||c,i)}}function F(t,e,r,n){return z("GET").apply(null,arguments)}F.VERSION=e;F.defaults=f;F.defaultContent="text/plain";F.get=z("GET");F.post=z("POST");F.put=z("PUT");F.patch=z("PATCH");F.head=z("HEAD");F.delete=F.del=z("DELETE");return t.http=F})},{}],38:[function(t,e,r){var n=t("midware");var o=t("./pool");e.exports=i;function i(t){return new o(t)}i.Pool=i.MiddlewarePool=o;i.midware=n},{"./pool":39,midware:40}],39:[function(t,e,r){var n=t("midware");e.exports=o;function o(t){this.ctx=null;this.pool=Object.create(null);if(t)this.useParent(t)}o.prototype.registered=function(t){return typeof this.pool[t]==="function"};o.prototype.flush=function(t){if(this.registered(t)){this.pool[t].stack.splice(0)}};o.prototype.flushAll=function(){this.pool=Object.create(null)};o.prototype.remove=function(t,e){if(this.registered(t)){this.pool[t].remove(e)}};o.prototype.stack=function(t){if(this.registered(t)){return this.pool[t].stack}};o.prototype.useCtx=function(t){this.ctx=t};o.prototype.useParent=function(t){if(!(t instanceof o))throw new TypeError("Invalid parent middleware");this.parent=t};o.prototype.use=function(t,e){var r=this.pool[t];var o=i(arguments,1);if(!r){r=this.pool[t]=n(this.ctx)}if(Array.isArray(e)){o=e}r.apply(null,o)};o.prototype.runParent=function(t,e){if(!this.parent)return e();this.parent.run.apply(this.parent,t.concat(e))};o.prototype.run=function(t){var e=this.pool;var r=i(arguments);var n=r.pop();this.runParent(r,o);function o(o,i){if(o||i)return n(o,i);var s=e[t];if(!s)return n();s.run.apply(null,r.slice(1).concat(n))}};function i(t,e){return[].slice.call(t,e||0)}},{midware:40}],40:[function(e,r,n){(function(e,o){if(typeof t==="function"&&t.amd){t(["exports"],o)}else if(typeof n==="object"){o(n);if(typeof r==="object"&&r!==null){r.exports=n=n.midware}}else{o(e)}})(this,function(t){"use strict";function e(t){var e=n.stack=[];t=t||null;function n(){r(arguments).filter(function(t){return typeof t==="function"}).forEach(function(t){e.push(t)});return t}n.run=function n(){var o,i=r(arguments);if(typeof i[i.length-1]==="function"){o=i.pop()}if(!e.length){if(o)o.call(t);return}var s=e.slice();i.push(a);function u(){var e=s.shift();e.apply(t,i)}function a(e,r){if(e||r||!s.length){s=null;if(o)o.call(t,e,r)}else{u()}}u()};n.remove=function(t){for(var r=0,n=e.length;r<n;r+=1){var o=e[r];if(o===t||o.name===t){e.splice(r,1);break}}};n.flush=function(){e.splice(0)};return n}function r(t){var e=new Array(t.length);for(var r=0,n=e.length;r<n;r+=1){e[r]=t[r]}return e}e.VERSION="0.1.7";t.midware=e})},{}],41:[function(e,r,n){(function(e,o){if(typeof t==="function"&&t.amd){t(["exports"],o)}else if(typeof n==="object"){o(n);if(typeof r==="object"&&r!==null){r.exports=n=n.pathParams}}else{o(e)}})(this,function(t){"use strict";var e=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^()])+)\\))?|\\(((?:\\\\.|[^()])+)\\))([+*?])?|(\\*))"].join("|"),"g");function r(t,e){return n(t).reduce(function(t,r){if(t instanceof Error)return t;if(typeof r==="string")return t;var n=e[r.name];if(n==null){return new Error("Missing path param: "+r.name)}var o=typeof n;if(o!=="string"&&o!=="number"){return new Error("Invalid type for path param: "+r.name+" = "+o)}var i=new RegExp(":"+r.name,"g");return t.replace(i,n)},t)}function n(t){var r=[];var n=0;var o=0;var i="";var s;while((s=e.exec(t))!=null){var u=s[0];var a=s[1];var p=s.index;i+=t.slice(o,p);o=p+u.length;if(a){i+=a[1];continue}if(i){r.push(i);i=""}var c=s[2];var f=s[3];var h=s[6];var l=h==="+"||h==="*";var y=h==="?"||h==="*";var d=c||"/";r.push({name:f||n++,prefix:c||"",delimiter:d,optional:y,repeat:l})}if(o<t.length){i+=t.substr(o)}if(i){r.push(i)}return r}t.pathParams=r})},{}]},{},[24])(24)});
//# sourceMappingURL=http://cdn.rawgit.com/h2non/theon.js//theon.min.js.map