-
Notifications
You must be signed in to change notification settings - Fork 2
/
rapport.router.min.js
1 lines (1 loc) · 11.9 KB
/
rapport.router.min.js
1
!function e(t,r,n){function o(a,s){if(!r[a]){if(!t[a]){var u="function"==typeof require&&require;if(!s&&u)return u(a,!0);if(i)return i(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var f=r[a]={exports:{}};t[a][0].call(f.exports,function(e){var r=t[a][1][e];return o(r||e)},f,f.exports,e,t,r,n)}return r[a].exports}for(var i="function"==typeof require&&require,a=0;a<n.length;a++)o(n[a]);return o}({1:[function(e,t,r){"use strict";var n=e("./router.js"),o=e("./websocket.js"),i=e("./util.js"),a={extendWebsocket:function(e,t,r,n){if(n&&n.router&&!i.isObject(n.router)&&!i.isFunction(n.router.handle))throw new TypeError("options.router must be a Rapport router");o(e,t,r,n)},extendRapportConstructor:function(e){e.Router=n},extendRapportInstance:function(e){e.Router=n}};"undefined"!=typeof window&&(window.RapportRouter=a),void 0!==t&&(t.exports=a)},{"./router.js":3,"./util.js":4,"./websocket.js":5}],2:[function(e,t,r){"use strict";function n(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}var o=e("./util.js"),i={create:function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),a=1;a<t;a++)r[a-1]=arguments[a];var s=[];if(!r||0===r.length)throw new TypeError("At least one handler function must be supplied");for(var u=0;u<r.length;u++){var c={method:e};if(o.isFunction(r[u]))c.handle=r[u],s.push(c);else{if(!o.isArray(r[u]))throw new TypeError("Handlers must be functions");i.append(s,i.create.apply(i,[e].concat(n(r[u]))))}}return s},handledMethods:function(e){for(var t={},r=0;r<e.length;r++)t[e[r].method]=!0;return t},traverse:function(e,t,r,n,i){!function a(){if(r.length>0){var s=r.shift();if("all"===s.method||s.method===e.method)try{var u=void 0;u=i?s.handle(i,e,t,a):s.handle(e,t,a),u&&o.isFunction(u.then)&&u.then(a,n)}catch(e){n(e)}else a()}}()},append:function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),o=1;o<t;o++)r[o-1]=arguments[o];for(var i=0;i<r.length;i++)r[i]&&0!==r[i].length&&e.push.apply(e,n(r[i]));return e}};t.exports=i},{"./util.js":4}],3:[function(e,t,r){"use strict";var n=e("path-to-regexp"),o=e("./route.chain.js"),i=e("./util.js"),a=function(e){var t=[];return n(e,t),0!==t.length},s=function(){var e={},t=[],r=[],s=[],u=function s(u,c){if(i.isArray(u))for(var f=0;f<u.length;f++)s(u[f],c);else{if(!i.isString(u))throw new TypeError("Routes must be strings");var l=i.trimSlashes(u);if(a(l)){for(var p=0;p<t.length;p++)if(t[p].route===l)return o.append(t[p].chain,c),void(t[p].handledMethods=o.handledMethods(t[p].chain));var h=[],d=n(l,h),g=o.append([],r,c),v=o.handledMethods(g);t.push({keys:h,regex:d,handledMethods:v,route:l,chain:g})}else e[l]||(e[l]={chain:o.append([],r)}),o.append(e[l].chain,c),e[l].handledMethods=o.handledMethods(e[l].chain)}},c=function(e){o.append(s,e)},f=function(n){o.append(r,n),i.forEach(e,function(e,t){o.append(t.chain,n),t.handledMethods=o.handledMethods(t.chain)});for(var a=0;a<t.length;a++)o.append(t[a].chain,n),t[a].handledMethods=o.handledMethods(t[a].chain)},l=function e(t,r){if(i.isArray(t))for(var n=0;n<t.length;n++)e(t[n],r);else if(i.isArray(r))for(var o=0;o<r.length;o++)e(t,r[o]);else{if(!i.isString(t))throw new TypeError("Routes must be strings");if(!(i.isObject(r)&&i.isFunction(r.getRoutes)&&i.isFunction(r.getRegexRoutes)&&i.isFunction(r.getErrorHandlers)))throw new TypeError("Router must be a Rapport router");i.forEach(r.getRoutes(),function(e,r){u(i.combineUrls(t,e),r.chain)});for(var a=r.getRegexRoutes(),s=0;s<a.length;s++)u(i.combineUrls(t,a[s].route),a[s].chain);c(r.getErrorHandlers())}},p={getRoutes:function(){return e},getRegexRoutes:function(){return t},getErrorHandlers:function(){return s},use:function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];if(i.isString(e)||i.isArray(e)){if(!r||0===r.length)throw new TypeError("At least one Rapport router must be supplied");l(e,r)}else if(i.isObject(e))l("",[e].concat(r));else{if(!i.isFunction(e))throw new TypeError("First parameter must be a string, Rapport router, or function");f(o.create.apply(o,["all"].concat([e].concat(r))))}},all:function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];u(e,o.create.apply(o,["all"].concat(r)))},put:function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];u(e,o.create.apply(o,["put"].concat(r)))},post:function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];u(e,o.create.apply(o,["post"].concat(r)))},patch:function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];u(e,o.create.apply(o,["patch"].concat(r)))},get:function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];u(e,o.create.apply(o,["get"].concat(r)))},delete:function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];u(e,o.create.apply(o,["delete"].concat(r)))},error:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];c(o.create.apply(o,["all"].concat(t)))},handle:function(e,t){var r=i.trimSlashes(e.url),n=function(r){var n=o.append([],p.getErrorHandlers()),a=function(e){var r=500;i.isObject(e)&&e.status&&(r=e.status,delete e.status);try{t.status(r).send(e)}catch(e){console.error("Failed to send error response. Set an error handler that explicitly catches errors to suppress this log:",e)}};if(0===n.length)return void a(r);o.traverse(e,t,n,a,r)},a=function(){for(var i=p.getRegexRoutes(),a=[],s=0;s<i.length;s++){var u=i[s],c=r.match(u.regex);if(null!==c&&(c.shift(),u.handledMethods.all||u.handledMethods[e.method])){e.params={};for(var f=0;f<u.keys.length;f++)e.params[u.keys[f].name]=c[f];o.append(a,u.chain);break}}if(0===a.length){var l=new Error("Not Found");return l.status=404,void n(l)}o.traverse(e,t,a,n)};!function(){var i=p.getRoutes()[r],s=i?o.append([],i.chain):[];if(0===s.length||!i.handledMethods.all&&!i.handledMethods[e.method])return void a();o.traverse(e,t,s,n)}()}};return p};t.exports=s},{"./route.chain.js":2,"./util.js":4,"path-to-regexp":7}],4:[function(e,t,r){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o={trimSlashes:function(e){var t=e;return o.endsWith(t,"/")&&(t=t.substring(0,t.length-1)),o.startsWith(t,"/")&&(t=t.substring(1,t.length)),t},combineUrls:function(e,t){var r=o.trimSlashes(e),n=o.trimSlashes(t);return 0!==r.length&&0!==n.length?r+"/"+n:0===r.length?n:r},endsWith:function(e,t){return-1!==e.indexOf(t,e.length-t.length)},startsWith:function(e,t){return 0===e.lastIndexOf(t,0)},isFunction:function(e){return"function"==typeof e},isString:function(e){return"string"==typeof e},isArray:function(e){return Array.isArray(e)},isObject:function(e){return"object"===(void 0===e?"undefined":n(e))},forEach:function(e,t){for(var r in e)e.hasOwnProperty(r)&&t(r,e[r])},isUndefined:function(e){return void 0===e}};t.exports=o},{}],5:[function(e,t,r){"use strict";var n=e("./util.js"),o=function(e,t){return!!(e&&e.router&&n.isObject(t)&&t._m&&t._u)},i=function(e,t){var r=e._u.indexOf("?")>=0,o=r?e._u.substr(0,e._u.indexOf("?")):e._u,i=r?e._u.substr(e._u.indexOf("?")+1).split("&"):[],a={};if(i&&i.length>0)for(var s=0;s<i.length;s++){var u=decodeURIComponent(i[s].substr(0,i[s].indexOf("="))),c=decodeURIComponent(i[s].substr(i[s].indexOf("=")+1));n.isUndefined(a[u])?a[u]=c:(n.isArray(a[u])||(a[u]=[a[u]]),a[u].push(c))}return{id:t,responseExpected:!!t,method:e._m.toLowerCase(),body:e._b,url:o,query:a}},a=function(e,t){var r=void 0;return r=t?{_status:200,_body:void 0,sent:!1,status:function(e){return r._status=e,r},respond:function(n){r.sent=!0,e.respond(t,n)},respondWithError:function(n){r.sent=!0,e.respondWithError(t,n)},send:function(e){r._body=e;var t={_s:r._status,_b:r._body};r._status>=200&&r._status<300?r.respond(t):r.respondWithError(t)}}:{_status:void 0,_body:void 0,sent:void 0,status:function(){return r},respond:function(){return r},respondWithError:function(){return r},send:function(){return r}}},s=function(e,t,r,n){t.handle(e._functions.onMessage.createRouterRequestObject(n,r),e._functions.onMessage.createRouterResponderObject(e,r))},u=function(e,t,r){t.handle(e._functions.onMessage.createRouterRequestObject(r),e._functions.onMessage.createRouterResponderObject())};t.exports=function(e){var t=e._functions.onMessage.handleRequest,r=e._functions.onMessage.handleMessage;e._functions.onMessage.createRouterResponderObject=a,e._functions.onMessage.createRouterRequestObject=i,e._functions.onMessage.handleRequest=function(e,r,n,i,a,u,c){o(i,u)?s(r,i.router,a,u):t(e,r,n,i,a,u,c)},e._functions.onMessage.handleMessage=function(e,t,n,i,a,s){o(i,a)?u(t,i.router,a):r(e,t,n,i,a,s)}}},{"./util.js":4}],6:[function(e,t,r){t.exports=Array.isArray||function(e){return"[object Array]"==Object.prototype.toString.call(e)}},{}],7:[function(e,t,r){function n(e,t){for(var r,n=[],o=0,i=0,a="",s=t&&t.delimiter||"/";null!=(r=m.exec(e));){var f=r[0],l=r[1],p=r.index;if(a+=e.slice(i,p),i=p+f.length,l)a+=l[1];else{var h=e[i],d=r[2],g=r[3],v=r[4],y=r[5],b=r[6],x=r[7];a&&(n.push(a),a="");var R=null!=d&&null!=h&&h!==d,w="+"===b||"*"===b,E="?"===b||"*"===b,_=r[2]||s,j=v||y;n.push({name:g||o++,prefix:d||"",delimiter:_,optional:E,repeat:w,partial:R,asterisk:!!x,pattern:j?c(j):x?".*":"[^"+u(_)+"]+?"})}}return i<e.length&&(a+=e.substr(i)),a&&n.push(a),n}function o(e,t){return s(n(e,t))}function i(e){return encodeURI(e).replace(/[\/?#]/g,function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()})}function a(e){return encodeURI(e).replace(/[?#]/g,function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()})}function s(e){for(var t=new Array(e.length),r=0;r<e.length;r++)"object"==typeof e[r]&&(t[r]=new RegExp("^(?:"+e[r].pattern+")$"));return function(r,n){for(var o="",s=r||{},u=n||{},c=u.pretty?i:encodeURIComponent,f=0;f<e.length;f++){var l=e[f];if("string"!=typeof l){var p,h=s[l.name];if(null==h){if(l.optional){l.partial&&(o+=l.prefix);continue}throw new TypeError('Expected "'+l.name+'" to be defined')}if(y(h)){if(!l.repeat)throw new TypeError('Expected "'+l.name+'" to not repeat, but received `'+JSON.stringify(h)+"`");if(0===h.length){if(l.optional)continue;throw new TypeError('Expected "'+l.name+'" to not be empty')}for(var d=0;d<h.length;d++){if(p=c(h[d]),!t[f].test(p))throw new TypeError('Expected all "'+l.name+'" to match "'+l.pattern+'", but received `'+JSON.stringify(p)+"`");o+=(0===d?l.prefix:l.delimiter)+p}}else{if(p=l.asterisk?a(h):c(h),!t[f].test(p))throw new TypeError('Expected "'+l.name+'" to match "'+l.pattern+'", but received "'+p+'"');o+=l.prefix+p}}else o+=l}return o}}function u(e){return e.replace(/([.+*?=^!:${}()[\]|\/\\])/g,"\\$1")}function c(e){return e.replace(/([=!:$\/()])/g,"\\$1")}function f(e,t){return e.keys=t,e}function l(e){return e.sensitive?"":"i"}function p(e,t){var r=e.source.match(/\((?!\?)/g);if(r)for(var n=0;n<r.length;n++)t.push({name:n,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,asterisk:!1,pattern:null});return f(e,t)}function h(e,t,r){for(var n=[],o=0;o<e.length;o++)n.push(v(e[o],t,r).source);return f(new RegExp("(?:"+n.join("|")+")",l(r)),t)}function d(e,t,r){return g(n(e,r),t,r)}function g(e,t,r){y(t)||(r=t||r,t=[]),r=r||{};for(var n=r.strict,o=!1!==r.end,i="",a=0;a<e.length;a++){var s=e[a];if("string"==typeof s)i+=u(s);else{var c=u(s.prefix),p="(?:"+s.pattern+")";t.push(s),s.repeat&&(p+="(?:"+c+p+")*"),p=s.optional?s.partial?c+"("+p+")?":"(?:"+c+"("+p+"))?":c+"("+p+")",i+=p}}var h=u(r.delimiter||"/"),d=i.slice(-h.length)===h;return n||(i=(d?i.slice(0,-h.length):i)+"(?:"+h+"(?=$))?"),i+=o?"$":n&&d?"":"(?="+h+"|$)",f(new RegExp("^"+i,l(r)),t)}function v(e,t,r){return y(t)||(r=t||r,t=[]),r=r||{},e instanceof RegExp?p(e,t):y(e)?h(e,t,r):d(e,t,r)}var y=e("isarray");t.exports=v,t.exports.parse=n,t.exports.compile=o,t.exports.tokensToFunction=s,t.exports.tokensToRegExp=g;var m=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g")},{isarray:6}]},{},[1]);