UNPKG

frexp

Version:
2 lines (1 loc) 2.53 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./_rollupPluginBabelHelpers-aESfU7SF.js");require("reflect-metadata");var e=require("express"),r=Symbol("methodMetadata"),o=Symbol("middlewareMetadata"),n=Symbol("controllerMetadata");function a(t,e,o,n){var a=Reflect.getMetadata(r,t.constructor)||[];a.push({methodName:e,httpMethod:o,path:n}),Reflect.defineMetadata(r,a,t.constructor)}function c(a){for(var c=Reflect.getMetadata(n,a.constructor),u=Reflect.getMetadata(r,a.constructor),l=Reflect.getMetadata(o,a.constructor)||[],s=e.Router(),f=a instanceof Function?new a:a,i=function(){var e=u[p],r=e.methodName,n=e.httpMethod,i=e.path,d=f[r],y=c+i;if("function"==typeof d){var h=Reflect.getMetadata(o,a.constructor.prototype)||{},v=[].concat(t._toConsumableArray(l),t._toConsumableArray(h[r]||[]));s[n.toLowerCase()].apply(s,[y].concat(t._toConsumableArray(v),[function(){var e=t._asyncToGenerator(t._regeneratorRuntime().mark((function e(r,o,n){return t._regeneratorRuntime().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,d.call(f,r,o,n);case 3:t.next=8;break;case 5:t.prev=5,t.t0=t.catch(0),n(t.t0);case 8:case"end":return t.stop()}}),e,null,[[0,5]])})));return function(t,r,o){return e.apply(this,arguments)}}()]))}},p=0;p<u.length;p++)i();return s}exports.Controller=function(t){return function(e){Reflect.defineMetadata(n,t,e)}},exports.Delete=function(t){return function(e,r,o){a(e,r,"DELETE",t)}},exports.Get=function(t){return function(e,r,o){a(e,r,"GET",t)}},exports.Middleware=function(e){return function(r,n,a){var c=Array.isArray(e)?e:[e];if(n){var u,l=Reflect.getMetadata(o,r.constructor.prototype)||{};l[n]=l[n]||[],(u=l[n]).push.apply(u,t._toConsumableArray(c)),Reflect.defineMetadata(o,l,r.constructor.prototype)}else{var s=Reflect.getMetadata(o,r)||[];s.push.apply(s,t._toConsumableArray(c)),Reflect.defineMetadata(o,s,r)}}},exports.Patch=function(t){return function(e,r,o){a(e,r,"PATCH",t)}},exports.Post=function(t){return function(e,r,o){a(e,r,"POST",t)}},exports.Put=function(t){return function(e,r,o){a(e,r,"PUT",t)}},exports.createRouter=c,exports.registerRoutes=function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0,o=e;try{for(var n=Object.keys(o),a=0,u=n;a<u.length;a++){var l=u[a],s=o[l];if(s){var f=new s;t.use(c(f)),console.log("@controller: ".concat(l))}else console.error("Controller class not found: ".concat(l))}r&&t.use(r)}catch(t){console.error("Error loading controllers from ".concat(o,":"),t)}};