@andrewcaires/express 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +2 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.esm.js +2 -2
- package/package.json +3 -3
package/dist/index.cjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @andrewcaires/express v2.0.
|
|
2
|
+
* @andrewcaires/express v2.0.1
|
|
3
3
|
* Decorators for express
|
|
4
4
|
* (c) 2026 Andrew Caires
|
|
5
5
|
* @license: MIT
|
|
6
6
|
*/
|
|
7
|
-
"use strict";var e=require("@andrewcaires/decorator"),t=require("@andrewcaires/node"),s=require("@andrewcaires/utils.js"),r=require("compression"),o=require("cookie-parser"),i=require("cors"),n=require("express"),a=require("express-session"),p=require("fs"),u=require("http"),h=require("https"),l=require("net"),d=require("path"),E=require("request-ip"),c=require("multer");function _(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(s){if("default"!==s){var r=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,r.get?r:{enumerable:!0,get:function(){return e[s]}})}}),t.default=e,Object.freeze(t)}var T=_(u),O=_(h);function v(e,t,s,r){return new(s||(s=Promise))(function(o,i){function n(e){try{p(r.next(e))}catch(e){i(e)}}function a(e){try{p(r.throw(e))}catch(e){i(e)}}function p(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s(function(e){e(t)})).then(n,a)}p((r=r.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class R{}R.CONTINUE=100,R.SWITCHING_PROTOCOLS=101,R.PROCESSING=102,R.OK=200,R.CREATED=201,R.ACCEPTED=202,R.NON_AUTHORITATIVE_INFORMATION=203,R.NO_CONTENT=204,R.RESET_CONTENT=205,R.PARTIAL_CONTENT=206,R.MULTI_STATUS=207,R.ALREADY_REPORTED=208,R.IM_USED=226,R.MULTIPLE_CHOICES=300,R.MOVED_PERMANENTLY=301,R.FOUND=302,R.SEE_OTHER=303,R.NOT_MODIFIED=304,R.USE_PROXY=305,R.TEMPORARY_REDIRECT=307,R.PERMANENT_REDIRECT=308,R.BAD_REQUEST=400,R.UNAUTHORIZED=401,R.PAYMENT_REQUIRED=402,R.FORBIDDEN=403,R.NOT_FOUND=404,R.METHOD_NOT_ALLOWED=405,R.NOT_ACCEPTABLE=406,R.PROXY_AUTHENTICATION_REQUIRED=407,R.REQUEST_TIMEOUT=408,R.CONFLICT=409,R.GONE=410,R.LENGTH_REQUIRED=411,R.PRECONDITION_FAILED=412,R.PAYLOAD_TOO_LARGE=413,R.REQUEST_URI_TOO_LONG=414,R.UNSUPPORTED_MEDIA_TYPE=415,R.REQUESTED_RANGE_NOT_SATISFIABLE=416,R.EXPECTATION_FAILED=417,R.IM_A_TEAPOT=418,R.MISDIRECTED_REQUEST=421,R.UNPROCESSABLE_ENTITY=422,R.LOCKED=423,R.FAILED_DEPENDENCY=424,R.UPGRADE_REQUIRED=426,R.PRECONDITION_REQUIRED=428,R.TOO_MANY_REQUESTS=429,R.REQUEST_HEADER_FIELDS_TOO_LARGE=431,R.CONNECTION_CLOSED_WITHOUT_RESPONSE=444,R.UNAVAILABLE_FOR_LEGAL_REASONS=451,R.CLIENT_CLOSED_REQUEST=499,R.INTERNAL_SERVER_ERROR=500,R.NOT_IMPLEMENTED=501,R.BAD_GATEWAY=502,R.SERVICE_UNAVAILABLE=503,R.GATEWAY_TIMEOUT=504,R.HTTP_VERSION_NOT_SUPPORTED=505,R.VARIANT_ALSO_NEGOCIATES=506,R.INSUFFICIENT_STORAGE=507,R.LOOP_DETECTED=508,R.NOT_EXTENDED=510,R.NETWORK_AUTHENTICATION_REQUIRED=511,R.NETWORK_CONNECTION_TIMEOUT_ERROR=599;class x extends Error{constructor(e,t=R.INTERNAL_SERVER_ERROR){super(e),this.status=t}}class N extends x{constructor(e){super(e,R.UNPROCESSABLE_ENTITY)}}class A{constructor(e,t,s,r,o){this.req=e,this.res=t,this.next=s,this.app=r,this.controller=o}cache(e){const t=[];e.private?t.push("private"):e.public&&t.push("public"),e.noStore&&(e.noCache=!0,t.push("no-store")),e.noCache&&(e.maxAge=0,delete e.sMaxAge,t.push("no-cache")),e.noTransform&&t.push("no-transform"),e.proxyRevalidate&&t.push("proxy-revalidate"),e.mustRevalidate?t.push("must-revalidate"):e.noCache||(s.isNumber(e.staleIfError)&&t.push(`stale-if-error=${e.staleIfError}`),s.isNumber(e.staleWhileRevalidate)&&t.push(`stale-while-revalidate=${e.staleWhileRevalidate}`)),s.isNumber(e.maxAge)&&t.push(`max-age=${e.maxAge}`),s.isNumber(e.sMaxAge)&&t.push(`s-maxage=${e.sMaxAge}`),t.length&&(this.res.setHeader("Cache-Control",t.join(",")),e.noCache&&s.forEachKey({"Surrogate-Control":"no-store",Pragma:"no-cache",ETag:"false",Expires:"0"},(e,t)=>this.res.setHeader(t,e)))}close(e){this.res.headersSent||this.res.json(e||this.storage)}cookie(e,t,r){s.isUndefined(t)?this.res.clearCookie(e):this.res.cookie(e,t,null!=r?r:{})}destroy(e){var t;e&&this.error(e),null===(t=this.res.socket)||void 0===t||t.destroy(e)}error(e){var t;let s=null!==(t=e.toString())&&void 0!==t?t:"",r=R.INTERNAL_SERVER_ERROR;e instanceof Error&&(s=e.message,e instanceof x&&(r=e.status)),this.send(r,{error:s})}file(e){this.res.headersSent||(this.status(R.OK),this.res.sendFile(d.resolve(e)))}getIp(){return E.getClientIp(this.req)||"0.0.0.0"}getUrl(){return`${this.req.protocol}://${this.req.get("host")}${this.req.originalUrl}`}json(e){this.send(R.OK,e)}prepare(e,t){this.res.headersSent||(this.status(e),this.storage=t)}send(e,t){this.res.headersSent||(this.status(e),this.res.json(t))}status(e){return e&&this.res.status(e),this.res.statusCode}success(e){this.send(R.OK,{message:e})}}class m{static extends(t){return e.metadata(m.EXTENDS,t,[])}static middleware(t){return e.metadata(m.MIDDLEWARE,t,[])}static parameters(t){return e.metadata(m.PARAMETERS,t,[])}static path(t,s){return e.metadata(m.PATH,t,s)}static routers(t){return e.metadata(m.ROUTERS,t,[])}}m.EXTENDS=Symbol("EXTENDS"),m.MIDDLEWARE=Symbol("MIDDLEWARE"),m.PARAMETERS=Symbol("PARAMETERS"),m.PATH=Symbol("PATH"),m.ROUTERS=Symbol("ROUTERS");class I extends s.EventEmitter{get controllers(){return this._controllers}get instance(){return this._app}get router(){return this._router}get server(){return this._server}constructor(t,u){var h,l;super(),this._app=n(),this._options={},this._base=n.Router(),this._router=n.Router(),this._controllers=[],this._controllers.push(...t.map(t=>s.isConstructor(t)?new t(...e.getInjectionArgs(t)):t)),this._options=s.merge({},{cross:!1,hybrid:!1,path:"/",port:3e3,session:{secret:"yoursecret",resave:!0,saveUninitialized:!1,cookie:{maxAge:864e5}}},null!=u?u:{}),this._app.use(n.json(this._options.json)),this._app.disable("x-powered-by"),this._app.use(n.urlencoded({extended:!0})),this._options.cross&&this._app.use(i(s.isObject(this._options.cross)?this._options.cross:{})),this._app.use(r(this._options.compression)),this._app.use(o(null===(h=this._options.cookie)||void 0===h?void 0:h.secret,this._options.cookie)),this._app.use(a(this._options.session)),this.init(),this._app.use(this._router);const E=(null===(l=this._options.path)||void 0===l?void 0:l.length)?this._options.path:"/";if(this._app.use(E,this._base),this._app.all(E+"/*path",(e,t)=>{this._options.redirect?t.redirect(this._options.redirect):(t.status(R.NOT_FOUND),t.json({message:"INVALID API"}))}),this._options.public){const e=d.resolve(this._options.public);p.existsSync(e)&&this._app.use(n.static(e)),this._app.get("*path",(t,s)=>{p.existsSync(e)?s.sendFile(e+"/index.html"):this._options.notfound?s.redirect(this._options.notfound):(s.status(R.NOT_FOUND),s.json({message:'FILE "index.html" NOT FOUND'}))})}else this._app.all("*path",(e,t)=>{this._options.redirect?t.redirect(this._options.redirect):(t.status(R.NOT_FOUND),t.json({message:"INVALID API"}))});this._controllers.forEach(e=>{const t=n.Router(),r=this._middlewares(e),o=m.parameters(e);this._extends(e).forEach(e=>{r.push(...this._middlewares(e)),o.push(...m.parameters(e))}),m.routers(e).forEach(i=>{const n=i.propertyKey.toString();if(s.isFunction(e[n])){if(!s.isFunction(t[i.method]))return this._notFound(i.method);const a=this._handles(e,n,r,o);return t[i.method](i.path,...a,(t,r,i)=>v(this,void 0,void 0,function*(){const a=new A(t,r,i,this,e),p=this._args(a,this._indexes(n,o)),u=yield e[n](...p);a.close(s.isArray(u)||s.isObject(u)?u:void 0)}))}this._notFound(`${e.name}.${n}`)}),this._extends(e).forEach(i=>{m.routers(i).forEach(i=>{const n=i.propertyKey.toString();if(s.isFunction(e[n])){if(!s.isFunction(t[i.method]))return this._notFound(i.method);const a=this._handles(e,n,r,o);return t[i.method](i.path,...a,(t,r,i)=>v(this,void 0,void 0,function*(){const a=new A(t,r,i,this,e),p=this._args(a,this._indexes(n,o)),u=yield e[n](...p);a.close(s.isArray(u)||s.isObject(u)?u:void 0)}))}this._notFound(`${e.constructor.name}.${n}`)})}),this._base.use(m.path(e,"/"),t)})}init(){}error(e,s){t.Log.error(e)}log(e,s){t.Log.info(e)}_args(e,t,s){const r=[],o={ctx:e,key:"",app:this,argument:s};return t.forEach(e=>{r[e.parameterIndex]=e.callback(Object.assign(Object.assign({},o),{key:e.key}))}),r}_handles(e,t,r,o){return r.filter(e=>e.propertyKey==t).map(t=>{if(t.callback!=s.noop){const r=this._indexes(t.method,o);return(o,i,n)=>v(this,void 0,void 0,function*(){const a=new A(o,i,n,this,e),p=s.isFunction(t.argument)?t.argument(a):t.argument,u=yield t.callback.call(e,...this._args(a,r,p));(s.isArray(u)||s.isObject(u))&&a.close(u)})}this._notFound(t.method)}).filter(s.isFunction)}_extends(e){return m.extends(e).reduce((e,t)=>(e.push(t,...this._extends(t)),e),[]).filter((e,t,s)=>s.indexOf(e)===t)}_indexes(e,t){return t.filter(t=>t.propertyKey==e)}_middlewares(e){return[...m.middleware(e)].reverse()}_notFound(e){this.error(new Error(`Router "${e}" not found`),"express")}_port(e){return`Server listening on port ${e}`}listen(){return v(this,void 0,void 0,function*(){if(this._options.cert&&this._options.key||(this._server=T.createServer(this._app),this._server.listen(this._options.port,()=>this.log(this._port(this._options.port),"express"))),!this._server){const e=T.createServer((e,t)=>{const s=80==this._options.port?":80":"";t.writeHead(R.MOVED_PERMANENTLY,{Location:`https://${e.headers.host}${s}${e.url}`}),t.end()}),t=O.createServer({key:this._options.key,cert:this._options.cert},this._app);if(this._options.hybrid){new l.Server(s=>{s.once("data",r=>{s.pause(),s.unshift(r),(22===r[0]?t:e).emit("connection",s),process.nextTick(()=>s.resume())})}).listen(this._options.port,()=>this.log(this._port(this._options.port),"express")),this._server=t}this._server||(443==this._options.port&&e.listen(80,()=>this.log(this._port(80),"express")),t.listen(this._options.port,()=>this.log(this._port(this._options.port),"express")),this._server=t)}})}}var S;exports.Methods=void 0,(S=exports.Methods||(exports.Methods={})).ALL="all",S.GET="get",S.POST="post",S.PUT="put",S.HEAD="head",S.DELETE="delete",S.OPTIONS="options",S.PATCH="patch";const D=e=>t=>(s,r)=>{m.routers(s).push({method:e,path:(null==t?void 0:t.length)?t:"/",propertyKey:r})},g=D(exports.Methods.ALL),f=D(exports.Methods.DELETE),y=D(exports.Methods.GET),L=D(exports.Methods.HEAD),U=D(exports.Methods.OPTIONS),C=D(exports.Methods.PATCH),P=D(exports.Methods.POST),F=D(exports.Methods.PUT),M=e=>t=>(s,r,o)=>{m.parameters(s).push({callback:e,key:t,propertyKey:r,parameterIndex:o})},b=M(({app:e})=>e),k=M(({argument:e})=>e),q=(e,t)=>s.isUndefined(t)?e:e[t],w=M(({ctx:e,key:t})=>{var s,r;return q(null!==(r=null===(s=e.req)||void 0===s?void 0:s.body)&&void 0!==r?r:{},t)}),j=M(({ctx:e,key:t})=>{var s,r;return q(null!==(r=null===(s=e.req)||void 0===s?void 0:s.cookies)&&void 0!==r?r:{},t)}),H=M(({ctx:e})=>e),$=M(({ctx:e})=>{var t,s;return null!==(s=null===(t=e.req)||void 0===t?void 0:t.files)&&void 0!==s?s:{}}),G=M(({ctx:e,key:t})=>{var s,r;return q(null!==(r=null===(s=e.req)||void 0===s?void 0:s.headers)&&void 0!==r?r:{},t)}),K=M(({ctx:e,key:t})=>{var s,r;return q(null!==(r=null===(s=e.req)||void 0===s?void 0:s.params)&&void 0!==r?r:{},t)}),V=M(({ctx:e,key:t})=>{var s,r,o;return String(null!==(o=q(null!==(r=null===(s=e.req)||void 0===s?void 0:s.query)&&void 0!==r?r:{},t))&&void 0!==o?o:"")}),Y=M(({ctx:e})=>{var t;return null===(t=e.req)||void 0===t?void 0:t.session}),Q=(e,t)=>(r,o)=>{const i=s.uuidv7();H()(r,i,0),m.middleware(r).push({method:i,argument:t,propertyKey:o,callback:e})},W=e=>{var t;return(null===(t=e.split(".").pop())||void 0===t?void 0:t.toLowerCase())||"bin"},B=(e,t)=>{var s;return null!==(s=e[t])&&void 0!==s?s:null},X=(e,t)=>{const r=s.uuidv7()+"."+t;return p.existsSync(d.join(e,r))?X(e,t):r};exports.All=g,exports.App=b,exports.Application=I,exports.Argument=k,exports.Body=w,exports.Cache=e=>(t,s,r)=>{Q(t=>{t.cache(Object.assign({},e)),t.next()})(t,s,r)},exports.Context=A,exports.Controller=e=>t=>{m.path(t,(null==e?void 0:e.length)?e:"/")},exports.Cookies=j,exports.Ctx=H,exports.Delete=f,exports.Extends=e=>t=>{m.extends(t).push(e)},exports.Files=$,exports.Get=y,exports.Head=L,exports.Headers=G,exports.Metadata=m,exports.Middleware=(e,t)=>(r,o)=>{let i=s.noop;if(s.isString(o)){const t=r;s.isFunction(t[e])&&(i=t[e])}m.middleware(r).push({method:e,argument:t,propertyKey:o,callback:i})},exports.NotFoundError=class extends x{constructor(e="Record not found"){super(e,R.NOT_FOUND)}},exports.Options=U,exports.Params=K,exports.Parse=e=>{const t=s.Validation.object(s.isFunction(e)?e(s.Validation):e).parse();return(e,s,r)=>{Q(e=>v(void 0,void 0,void 0,function*(){const{error:s,message:r,value:o}=yield t.validateAsync(e.req.body);if(s)return e.error(new N(null!=r?r:s));e.req.body=o,e.next()}))(e,s,r)}},exports.Patch=C,exports.Post=P,exports.Put=F,exports.Query=V,exports.ResponseError=x,exports.Session=Y,exports.Status=R,exports.UnauthorizedError=class extends x{constructor(e="Unauthorized"){super(e,R.UNAUTHORIZED)}},exports.Upload=e=>{const t=s.merge({},e),r=c.diskStorage({destination(e,s,r){var o;const i=B(t,s.fieldname);r(null,null!==(o=null==i?void 0:i.path)&&void 0!==o?o:"./")},filename(e,s,r){var o;const i=B(t,s.fieldname);r(null,X(null!==(o=null==i?void 0:i.path)&&void 0!==o?o:"./",W(s.originalname)))}}),o=Math.max(...Object.values(t).map(e=>{var t;return null!==(t=e.size)&&void 0!==t?t:0})),i=c({storage:r,fileFilter(e,s,r){var o;const i=B(t,s.fieldname);return i?((e,t)=>!t.length||t.includes(W(e.originalname))||t.includes(e.mimetype.toLowerCase()))(s,null!==(o=null==i?void 0:i.types)&&void 0!==o?o:[])?void r(null,!0):r(new Error(`FILE TYPE NOT ALLOWED FOR "${s.fieldname}"`)):r(new Error(`UPLOAD FIELD "${s.fieldname}" IS NOT CONFIGURED`))},limits:{fileSize:1024*o*1024}}).fields(Object.keys(t).map(e=>{var s,r;return{name:e,maxCount:null!==(r=null===(s=t[e])||void 0===s?void 0:s.count)&&void 0!==r?r:1}}));return(e,t,s)=>{Q(e=>{i(e.req,e.res,t=>{if(t)return"LIMIT_UNEXPECTED_FILE"==t.code&&(t.message=`FIELD "${t.field}" EXCEEDS MAX SIZE`),e.destroy(t);e.next()})})(e,t,s)}},exports.Use=Q,exports.ValidationError=N,exports.methodFactory=D,exports.parameterFactory=M;
|
|
7
|
+
"use strict";var e=require("@andrewcaires/decorator"),t=require("@andrewcaires/node"),s=require("@andrewcaires/utils.js"),r=require("compression"),o=require("cookie-parser"),i=require("cors"),n=require("express"),a=require("express-session"),p=require("fs"),u=require("http"),l=require("https"),h=require("net"),d=require("path"),E=require("request-ip"),c=require("multer");function _(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(s){if("default"!==s){var r=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,r.get?r:{enumerable:!0,get:function(){return e[s]}})}}),t.default=e,Object.freeze(t)}var T=_(u),O=_(l);function v(e,t,s,r){return new(s||(s=Promise))(function(o,i){function n(e){try{p(r.next(e))}catch(e){i(e)}}function a(e){try{p(r.throw(e))}catch(e){i(e)}}function p(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s(function(e){e(t)})).then(n,a)}p((r=r.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class R{}R.CONTINUE=100,R.SWITCHING_PROTOCOLS=101,R.PROCESSING=102,R.OK=200,R.CREATED=201,R.ACCEPTED=202,R.NON_AUTHORITATIVE_INFORMATION=203,R.NO_CONTENT=204,R.RESET_CONTENT=205,R.PARTIAL_CONTENT=206,R.MULTI_STATUS=207,R.ALREADY_REPORTED=208,R.IM_USED=226,R.MULTIPLE_CHOICES=300,R.MOVED_PERMANENTLY=301,R.FOUND=302,R.SEE_OTHER=303,R.NOT_MODIFIED=304,R.USE_PROXY=305,R.TEMPORARY_REDIRECT=307,R.PERMANENT_REDIRECT=308,R.BAD_REQUEST=400,R.UNAUTHORIZED=401,R.PAYMENT_REQUIRED=402,R.FORBIDDEN=403,R.NOT_FOUND=404,R.METHOD_NOT_ALLOWED=405,R.NOT_ACCEPTABLE=406,R.PROXY_AUTHENTICATION_REQUIRED=407,R.REQUEST_TIMEOUT=408,R.CONFLICT=409,R.GONE=410,R.LENGTH_REQUIRED=411,R.PRECONDITION_FAILED=412,R.PAYLOAD_TOO_LARGE=413,R.REQUEST_URI_TOO_LONG=414,R.UNSUPPORTED_MEDIA_TYPE=415,R.REQUESTED_RANGE_NOT_SATISFIABLE=416,R.EXPECTATION_FAILED=417,R.IM_A_TEAPOT=418,R.MISDIRECTED_REQUEST=421,R.UNPROCESSABLE_ENTITY=422,R.LOCKED=423,R.FAILED_DEPENDENCY=424,R.UPGRADE_REQUIRED=426,R.PRECONDITION_REQUIRED=428,R.TOO_MANY_REQUESTS=429,R.REQUEST_HEADER_FIELDS_TOO_LARGE=431,R.CONNECTION_CLOSED_WITHOUT_RESPONSE=444,R.UNAVAILABLE_FOR_LEGAL_REASONS=451,R.CLIENT_CLOSED_REQUEST=499,R.INTERNAL_SERVER_ERROR=500,R.NOT_IMPLEMENTED=501,R.BAD_GATEWAY=502,R.SERVICE_UNAVAILABLE=503,R.GATEWAY_TIMEOUT=504,R.HTTP_VERSION_NOT_SUPPORTED=505,R.VARIANT_ALSO_NEGOCIATES=506,R.INSUFFICIENT_STORAGE=507,R.LOOP_DETECTED=508,R.NOT_EXTENDED=510,R.NETWORK_AUTHENTICATION_REQUIRED=511,R.NETWORK_CONNECTION_TIMEOUT_ERROR=599;class x extends Error{constructor(e,t=R.INTERNAL_SERVER_ERROR){super(e),this.status=t}}class N extends x{constructor(e){super(e,R.UNPROCESSABLE_ENTITY)}}class A{constructor(e,t,s,r,o){this.req=e,this.res=t,this.next=s,this.app=r,this.controller=o}cache(e){const t=[];e.private?t.push("private"):e.public&&t.push("public"),e.noStore&&(e.noCache=!0,t.push("no-store")),e.noCache&&(e.maxAge=0,delete e.sMaxAge,t.push("no-cache")),e.noTransform&&t.push("no-transform"),e.proxyRevalidate&&t.push("proxy-revalidate"),e.mustRevalidate?t.push("must-revalidate"):e.noCache||(s.isNumber(e.staleIfError)&&t.push(`stale-if-error=${e.staleIfError}`),s.isNumber(e.staleWhileRevalidate)&&t.push(`stale-while-revalidate=${e.staleWhileRevalidate}`)),s.isNumber(e.maxAge)&&t.push(`max-age=${e.maxAge}`),s.isNumber(e.sMaxAge)&&t.push(`s-maxage=${e.sMaxAge}`),t.length&&(this.res.setHeader("Cache-Control",t.join(",")),e.noCache&&s.forEachKey({"Surrogate-Control":"no-store",Pragma:"no-cache",ETag:"false",Expires:"0"},(e,t)=>this.res.setHeader(t,e)))}close(e){this.res.headersSent||this.res.json(e||this.storage)}cookie(e,t,r){s.isUndefined(t)?this.res.clearCookie(e):this.res.cookie(e,t,null!=r?r:{})}destroy(e){var t;e&&this.error(e),null===(t=this.res.socket)||void 0===t||t.destroy(e)}error(e){var t;let s=null!==(t=e.toString())&&void 0!==t?t:"",r=R.INTERNAL_SERVER_ERROR;e instanceof Error&&(s=e.message,e instanceof x&&(r=e.status)),this.send(r,{error:s})}file(e){this.res.headersSent||(this.status(R.OK),this.res.sendFile(d.resolve(e)))}getIp(){return E.getClientIp(this.req)||"0.0.0.0"}getUrl(){return`${this.req.protocol}://${this.req.get("host")}${this.req.originalUrl}`}json(e){this.send(R.OK,e)}prepare(e,t){this.res.headersSent||(this.status(e),this.storage=t)}send(e,t){this.res.headersSent||(this.status(e),this.res.json(t))}status(e){return e&&this.res.status(e),this.res.statusCode}success(e){this.send(R.OK,{message:e})}}class m{static extends(t){return e.metadata(m.EXTENDS,t,[])}static middleware(t){return e.metadata(m.MIDDLEWARE,t,[])}static parameters(t){return e.metadata(m.PARAMETERS,t,[])}static path(t,s){return e.metadata(m.PATH,t,s)}static routers(t){return e.metadata(m.ROUTERS,t,[])}}m.EXTENDS=Symbol("EXTENDS"),m.MIDDLEWARE=Symbol("MIDDLEWARE"),m.PARAMETERS=Symbol("PARAMETERS"),m.PATH=Symbol("PATH"),m.ROUTERS=Symbol("ROUTERS");class I extends s.EventEmitter{get controllers(){return this._controllers}get instance(){return this._app}get router(){return this._router}get server(){return this._server}constructor(t,u){var l,h;super(),this._app=n(),this._options={},this._base=n.Router(),this._router=n.Router(),this._controllers=[],this._controllers.push(...t.map(t=>s.isConstructor(t)?new t(...e.getInjectionArgs(t)):t)),this._options=s.merge({},{cross:!1,hybrid:!1,path:"/",port:3e3,session:{secret:"yoursecret",resave:!0,saveUninitialized:!1,cookie:{maxAge:864e5}}},null!=u?u:{}),this._app.use(n.json(this._options.json)),this._app.disable("x-powered-by"),this._app.use(n.urlencoded({extended:!0})),this._options.cross&&this._app.use(i(s.isObject(this._options.cross)?this._options.cross:{})),this._app.use(r(this._options.compression)),this._app.use(o(null===(l=this._options.cookie)||void 0===l?void 0:l.secret,this._options.cookie)),this._app.use(a(this._options.session)),this.init(),this._app.use(this._router);const E=(null===(h=this._options.path)||void 0===h?void 0:h.length)?this._options.path:"/";if(this._app.use(E,this._base),this._app.all(E+"/*path",(e,t)=>{this._options.redirect?t.redirect(this._options.redirect):(t.status(R.NOT_FOUND),t.json({message:"INVALID API"}))}),this._options.public){const e=d.resolve(this._options.public);p.existsSync(e)&&this._app.use(n.static(e)),this._app.get("*path",(t,s)=>{p.existsSync(e)?s.sendFile(e+"/index.html"):this._options.notfound?s.redirect(this._options.notfound):(s.status(R.NOT_FOUND),s.json({message:'FILE "index.html" NOT FOUND'}))})}else this._app.all("*path",(e,t)=>{this._options.redirect?t.redirect(this._options.redirect):(t.status(R.NOT_FOUND),t.json({message:"INVALID API"}))});this._controllers.forEach(e=>{const t=n.Router(),r=this._middlewares(e),o=m.parameters(e);this._extends(e).forEach(e=>{r.push(...this._middlewares(e)),o.push(...m.parameters(e))}),m.routers(e).forEach(i=>{const n=i.propertyKey.toString();if(s.isFunction(e[n])){if(!s.isFunction(t[i.method]))return this._notFound(i.method);const a=this._handles(e,n,r,o);return t[i.method](i.path,...a,(t,r,i)=>v(this,void 0,void 0,function*(){const a=new A(t,r,i,this,e),p=this._args(a,this._indexes(n,o)),u=yield e[n](...p);a.close(s.isArray(u)||s.isObject(u)?u:void 0)}))}this._notFound(`${e.name}.${n}`)}),this._extends(e).forEach(i=>{m.routers(i).forEach(i=>{const n=i.propertyKey.toString();if(s.isFunction(e[n])){if(!s.isFunction(t[i.method]))return this._notFound(i.method);const a=this._handles(e,n,r,o);return t[i.method](i.path,...a,(t,r,i)=>v(this,void 0,void 0,function*(){const a=new A(t,r,i,this,e),p=this._args(a,this._indexes(n,o)),u=yield e[n](...p);a.close(s.isArray(u)||s.isObject(u)?u:void 0)}))}this._notFound(`${e.constructor.name}.${n}`)})}),this._base.use(m.path(e,"/"),t)})}init(){}error(e,s){t.Log.error(e)}log(e,s){t.Log.info(e)}_args(e,t,s){const r=[],o={ctx:e,key:"",app:this,argument:s};return t.forEach(e=>{r[e.parameterIndex]=e.callback(Object.assign(Object.assign({},o),{key:e.key}))}),r}_handles(e,t,r,o){return r.filter(e=>e.propertyKey==t).map(t=>{if(t.callback!=s.noop){const r=this._indexes(t.method,o);return(o,i,n)=>v(this,void 0,void 0,function*(){const a=new A(o,i,n,this,e),p=s.isFunction(t.argument)?t.argument(a):t.argument,u=yield t.callback.call(e,...this._args(a,r,p));(s.isArray(u)||s.isObject(u))&&a.close(u)})}this._notFound(t.method)}).filter(s.isFunction)}_extends(e){return m.extends(e).reduce((e,t)=>(e.push(t,...this._extends(t)),e),[]).filter((e,t,s)=>s.indexOf(e)===t)}_indexes(e,t){return t.filter(t=>t.propertyKey==e)}_middlewares(e){return[...m.middleware(e)].reverse()}_notFound(e){this.error(new Error(`Router "${e}" not found`),"express")}_port(e){return`Server listening on port ${e}`}listen(){return v(this,void 0,void 0,function*(){if(this._options.cert&&this._options.key||(this._server=T.createServer(this._app),this._server.listen(this._options.port,()=>this.log(this._port(this._options.port),"express"))),!this._server){const e=T.createServer((e,t)=>{const s=80==this._options.port?":80":"";t.writeHead(R.MOVED_PERMANENTLY,{Location:`https://${e.headers.host}${s}${e.url}`}),t.end()}),t=O.createServer({key:this._options.key,cert:this._options.cert},this._app);if(this._options.hybrid){new h.Server(s=>{s.once("data",r=>{s.pause(),s.unshift(r),(22===r[0]?t:e).emit("connection",s),process.nextTick(()=>s.resume())})}).listen(this._options.port,()=>this.log(this._port(this._options.port),"express")),this._server=t}this._server||(443==this._options.port&&e.listen(80,()=>this.log(this._port(80),"express")),t.listen(this._options.port,()=>this.log(this._port(this._options.port),"express")),this._server=t)}})}}var S;exports.Methods=void 0,(S=exports.Methods||(exports.Methods={})).ALL="all",S.GET="get",S.POST="post",S.PUT="put",S.HEAD="head",S.DELETE="delete",S.OPTIONS="options",S.PATCH="patch";const D=e=>t=>(s,r)=>{m.routers(s).push({method:e,path:(null==t?void 0:t.length)?t:"/",propertyKey:r})},g=D(exports.Methods.ALL),f=D(exports.Methods.DELETE),y=D(exports.Methods.GET),L=D(exports.Methods.HEAD),U=D(exports.Methods.OPTIONS),C=D(exports.Methods.PATCH),P=D(exports.Methods.POST),F=D(exports.Methods.PUT),M=e=>t=>(s,r,o)=>{m.parameters(s).push({callback:e,key:t,propertyKey:r,parameterIndex:o})},b=M(({app:e})=>e),k=M(({argument:e})=>e),q=(e,t)=>s.isUndefined(t)?e:e[t],w=M(({ctx:e,key:t})=>{var s,r;return q(null!==(r=null===(s=e.req)||void 0===s?void 0:s.body)&&void 0!==r?r:{},t)}),j=M(({ctx:e,key:t})=>{var s,r;return q(null!==(r=null===(s=e.req)||void 0===s?void 0:s.cookies)&&void 0!==r?r:{},t)}),H=M(({ctx:e})=>e),$=M(({ctx:e})=>{var t,s;return null!==(s=null===(t=e.req)||void 0===t?void 0:t.files)&&void 0!==s?s:{}}),G=M(({ctx:e,key:t})=>{var s,r;return q(null!==(r=null===(s=e.req)||void 0===s?void 0:s.headers)&&void 0!==r?r:{},t)}),V=M(({ctx:e,key:t})=>{var s,r;return q(null!==(r=null===(s=e.req)||void 0===s?void 0:s.params)&&void 0!==r?r:{},t)}),K=M(({ctx:e,key:t})=>{var s,r,o;return String(null!==(o=q(null!==(r=null===(s=e.req)||void 0===s?void 0:s.query)&&void 0!==r?r:{},t))&&void 0!==o?o:"")}),Y=M(({ctx:e})=>{var t;return null===(t=e.req)||void 0===t?void 0:t.session}),Q=(e,t)=>(r,o)=>{const i=s.uuidv7();H()(r,i,0),m.middleware(r).push({method:i,argument:t,propertyKey:o,callback:e})},W=e=>{var t;return(null===(t=e.split(".").pop())||void 0===t?void 0:t.toLowerCase())||"bin"},B=(e,t)=>{var s;return null!==(s=e[t])&&void 0!==s?s:null},X=(e,t)=>{const r=s.uuidv7()+"."+t;return p.existsSync(d.join(e,r))?X(e,t):r};exports.All=g,exports.App=b,exports.Application=I,exports.Argument=k,exports.Body=w,exports.Cache=e=>(t,s,r)=>{Q(t=>{t.cache(Object.assign({},e)),t.next()})(t,s,r)},exports.Context=A,exports.Controller=e=>t=>{m.path(t,(null==e?void 0:e.length)?e:"/")},exports.Cookies=j,exports.Ctx=H,exports.Delete=f,exports.Extends=e=>t=>{m.extends(t).push(e)},exports.Files=$,exports.Get=y,exports.Head=L,exports.Headers=G,exports.InternalServerError=class extends x{constructor(e="Internal server error"){super(e,R.INTERNAL_SERVER_ERROR)}},exports.Metadata=m,exports.Middleware=(e,t)=>(r,o)=>{let i=s.noop;if(s.isString(o)){const t=r;s.isFunction(t[e])&&(i=t[e])}m.middleware(r).push({method:e,argument:t,propertyKey:o,callback:i})},exports.NotFoundError=class extends x{constructor(e="Record not found"){super(e,R.NOT_FOUND)}},exports.Options=U,exports.Params=V,exports.Parse=e=>{const t=s.Validation.object(s.isFunction(e)?e(s.Validation):e).parse();return(e,s,r)=>{Q(e=>v(void 0,void 0,void 0,function*(){var s,r;const{error:o,message:i,value:n}=yield t.validateAsync(null!==(r=null===(s=e.req)||void 0===s?void 0:s.body)&&void 0!==r?r:{});if(o)return e.error(new N(null!=i?i:o));e.req.body=n,e.next()}))(e,s,r)}},exports.Patch=C,exports.Post=P,exports.Put=F,exports.Query=K,exports.ResponseError=x,exports.Session=Y,exports.Status=R,exports.UnauthorizedError=class extends x{constructor(e="Unauthorized"){super(e,R.UNAUTHORIZED)}},exports.Upload=e=>{const t=s.merge({},e),r=c.diskStorage({destination(e,s,r){var o;const i=B(t,s.fieldname);r(null,null!==(o=null==i?void 0:i.path)&&void 0!==o?o:"./")},filename(e,s,r){var o;const i=B(t,s.fieldname);r(null,X(null!==(o=null==i?void 0:i.path)&&void 0!==o?o:"./",W(s.originalname)))}}),o=Math.max(...Object.values(t).map(e=>{var t;return null!==(t=e.size)&&void 0!==t?t:0})),i=c({storage:r,fileFilter(e,s,r){var o;const i=B(t,s.fieldname);return i?((e,t)=>!t.length||t.includes(W(e.originalname))||t.includes(e.mimetype.toLowerCase()))(s,null!==(o=null==i?void 0:i.types)&&void 0!==o?o:[])?void r(null,!0):r(new Error(`FILE TYPE NOT ALLOWED FOR "${s.fieldname}"`)):r(new Error(`UPLOAD FIELD "${s.fieldname}" IS NOT CONFIGURED`))},limits:{fileSize:1024*o*1024}}).fields(Object.keys(t).map(e=>{var s,r;return{name:e,maxCount:null!==(r=null===(s=t[e])||void 0===s?void 0:s.count)&&void 0!==r?r:1}}));return(e,t,s)=>{Q(e=>{i(e.req,e.res,t=>{if(t)return"LIMIT_UNEXPECTED_FILE"==t.code&&(t.message=`FIELD "${t.field}" EXCEEDS MAX SIZE`),e.destroy(t);e.next()})})(e,t,s)}},exports.Use=Q,exports.ValidationError=N,exports.methodFactory=D,exports.parameterFactory=M;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @andrewcaires/express v2.0.
|
|
2
|
+
* @andrewcaires/express v2.0.1
|
|
3
3
|
* Decorators for express
|
|
4
4
|
* (c) 2026 Andrew Caires
|
|
5
5
|
* @license: MIT
|
|
@@ -475,6 +475,10 @@ declare class ResponseError extends Error {
|
|
|
475
475
|
constructor(message: string, status?: number);
|
|
476
476
|
}
|
|
477
477
|
|
|
478
|
+
declare class InternalServerError extends ResponseError {
|
|
479
|
+
constructor(message?: string);
|
|
480
|
+
}
|
|
481
|
+
|
|
478
482
|
declare class NotFoundError extends ResponseError {
|
|
479
483
|
constructor(message?: string);
|
|
480
484
|
}
|
|
@@ -566,5 +570,5 @@ declare class Status {
|
|
|
566
570
|
static readonly NETWORK_CONNECTION_TIMEOUT_ERROR = 599;
|
|
567
571
|
}
|
|
568
572
|
|
|
569
|
-
export { All, App, Application, Argument, Body, Cache, Context, Controller, Cookies, Ctx, Delete, Extends, Files, Get, Head, Headers, Metadata, Methods, Middleware, NotFoundError, Options, Params, Parse, Patch, Post, Put, Query, ResponseError, Session, Status, UnauthorizedError, Upload, Use, ValidationError, methodFactory, parameterFactory };
|
|
573
|
+
export { All, App, Application, Argument, Body, Cache, Context, Controller, Cookies, Ctx, Delete, Extends, Files, Get, Head, Headers, InternalServerError, Metadata, Methods, Middleware, NotFoundError, Options, Params, Parse, Patch, Post, Put, Query, ResponseError, Session, Status, UnauthorizedError, Upload, Use, ValidationError, methodFactory, parameterFactory };
|
|
570
574
|
export type { CallbackObject, ComponentsObject, ContactObject, EncodingObject, ExampleObject, ExternalDocumentationObject, HeaderObject, IArgs, ICache, ICookie, IFile, IHandler, IMiddlewares, IOptions, IParameter, IRouter, IStore, IUpload, IUse, InfoObject, LicenseObject, LinkObject, MediaTypeObject, OAuthFlowObject, OAuthFlowsObject, OpenAPIObject, OperationObject, ParameterObject, ParseFunction, PathItemObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SecurityRequirementObject, SecuritySchemeObject, ServerObject, ServerVariableObject, TagObject };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @andrewcaires/express v2.0.
|
|
2
|
+
* @andrewcaires/express v2.0.1
|
|
3
3
|
* Decorators for express
|
|
4
4
|
* (c) 2026 Andrew Caires
|
|
5
5
|
* @license: MIT
|
|
6
6
|
*/
|
|
7
|
-
import{metadata as e,getInjectionArgs as t}from"@andrewcaires/decorator";import{Log as s}from"@andrewcaires/node";import{isNumber as r,forEachKey as o,isUndefined as i,EventEmitter as n,isConstructor as a,merge as h,isObject as l,isFunction as E,noop as p,isArray as u,uuidv7 as d,isString as c,Validation as _}from"@andrewcaires/utils.js";import T from"compression";import O from"cookie-parser";import m from"cors";import R,{Router as v,json as N,urlencoded as A}from"express";import I from"express-session";import{existsSync as S}from"fs";import*as f from"http";import*as D from"https";import{Server as g}from"net";import{resolve as L,join as x}from"path";import{getClientIp as U}from"request-ip";import y,{diskStorage as C}from"multer";function P(e,t,s,r){return new(s||(s=Promise))(function(o,i){function n(e){try{h(r.next(e))}catch(e){i(e)}}function a(e){try{h(r.throw(e))}catch(e){i(e)}}function h(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s(function(e){e(t)})).then(n,a)}h((r=r.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class F{}F.CONTINUE=100,F.SWITCHING_PROTOCOLS=101,F.PROCESSING=102,F.OK=200,F.CREATED=201,F.ACCEPTED=202,F.NON_AUTHORITATIVE_INFORMATION=203,F.NO_CONTENT=204,F.RESET_CONTENT=205,F.PARTIAL_CONTENT=206,F.MULTI_STATUS=207,F.ALREADY_REPORTED=208,F.IM_USED=226,F.MULTIPLE_CHOICES=300,F.MOVED_PERMANENTLY=301,F.FOUND=302,F.SEE_OTHER=303,F.NOT_MODIFIED=304,F.USE_PROXY=305,F.TEMPORARY_REDIRECT=307,F.PERMANENT_REDIRECT=308,F.BAD_REQUEST=400,F.UNAUTHORIZED=401,F.PAYMENT_REQUIRED=402,F.FORBIDDEN=403,F.NOT_FOUND=404,F.METHOD_NOT_ALLOWED=405,F.NOT_ACCEPTABLE=406,F.PROXY_AUTHENTICATION_REQUIRED=407,F.REQUEST_TIMEOUT=408,F.CONFLICT=409,F.GONE=410,F.LENGTH_REQUIRED=411,F.PRECONDITION_FAILED=412,F.PAYLOAD_TOO_LARGE=413,F.REQUEST_URI_TOO_LONG=414,F.UNSUPPORTED_MEDIA_TYPE=415,F.REQUESTED_RANGE_NOT_SATISFIABLE=416,F.EXPECTATION_FAILED=417,F.IM_A_TEAPOT=418,F.MISDIRECTED_REQUEST=421,F.UNPROCESSABLE_ENTITY=422,F.LOCKED=423,F.FAILED_DEPENDENCY=424,F.UPGRADE_REQUIRED=426,F.PRECONDITION_REQUIRED=428,F.TOO_MANY_REQUESTS=429,F.REQUEST_HEADER_FIELDS_TOO_LARGE=431,F.CONNECTION_CLOSED_WITHOUT_RESPONSE=444,F.UNAVAILABLE_FOR_LEGAL_REASONS=451,F.CLIENT_CLOSED_REQUEST=499,F.INTERNAL_SERVER_ERROR=500,F.NOT_IMPLEMENTED=501,F.BAD_GATEWAY=502,F.SERVICE_UNAVAILABLE=503,F.GATEWAY_TIMEOUT=504,F.HTTP_VERSION_NOT_SUPPORTED=505,F.VARIANT_ALSO_NEGOCIATES=506,F.INSUFFICIENT_STORAGE=507,F.LOOP_DETECTED=508,F.NOT_EXTENDED=510,F.NETWORK_AUTHENTICATION_REQUIRED=511,F.NETWORK_CONNECTION_TIMEOUT_ERROR=599;class M extends Error{constructor(e,t=F.INTERNAL_SERVER_ERROR){super(e),this.status=t}}class b extends M{constructor(e="Record not found"){super(e,F.NOT_FOUND)}}class k extends M{constructor(e="Unauthorized"){super(e,F.UNAUTHORIZED)}}class w extends M{constructor(e){super(e,F.UNPROCESSABLE_ENTITY)}}class H{constructor(e,t,s,r,o){this.req=e,this.res=t,this.next=s,this.app=r,this.controller=o}cache(e){const t=[];e.private?t.push("private"):e.public&&t.push("public"),e.noStore&&(e.noCache=!0,t.push("no-store")),e.noCache&&(e.maxAge=0,delete e.sMaxAge,t.push("no-cache")),e.noTransform&&t.push("no-transform"),e.proxyRevalidate&&t.push("proxy-revalidate"),e.mustRevalidate?t.push("must-revalidate"):e.noCache||(r(e.staleIfError)&&t.push(`stale-if-error=${e.staleIfError}`),r(e.staleWhileRevalidate)&&t.push(`stale-while-revalidate=${e.staleWhileRevalidate}`)),r(e.maxAge)&&t.push(`max-age=${e.maxAge}`),r(e.sMaxAge)&&t.push(`s-maxage=${e.sMaxAge}`),t.length&&(this.res.setHeader("Cache-Control",t.join(",")),e.noCache&&o({"Surrogate-Control":"no-store",Pragma:"no-cache",ETag:"false",Expires:"0"},(e,t)=>this.res.setHeader(t,e)))}close(e){this.res.headersSent||this.res.json(e||this.storage)}cookie(e,t,s){i(t)?this.res.clearCookie(e):this.res.cookie(e,t,null!=s?s:{})}destroy(e){var t;e&&this.error(e),null===(t=this.res.socket)||void 0===t||t.destroy(e)}error(e){var t;let s=null!==(t=e.toString())&&void 0!==t?t:"",r=F.INTERNAL_SERVER_ERROR;e instanceof Error&&(s=e.message,e instanceof M&&(r=e.status)),this.send(r,{error:s})}file(e){this.res.headersSent||(this.status(F.OK),this.res.sendFile(L(e)))}getIp(){return U(this.req)||"0.0.0.0"}getUrl(){return`${this.req.protocol}://${this.req.get("host")}${this.req.originalUrl}`}json(e){this.send(F.OK,e)}prepare(e,t){this.res.headersSent||(this.status(e),this.storage=t)}send(e,t){this.res.headersSent||(this.status(e),this.res.json(t))}status(e){return e&&this.res.status(e),this.res.statusCode}success(e){this.send(F.OK,{message:e})}}class ${static extends(t){return e($.EXTENDS,t,[])}static middleware(t){return e($.MIDDLEWARE,t,[])}static parameters(t){return e($.PARAMETERS,t,[])}static path(t,s){return e($.PATH,t,s)}static routers(t){return e($.ROUTERS,t,[])}}$.EXTENDS=Symbol("EXTENDS"),$.MIDDLEWARE=Symbol("MIDDLEWARE"),$.PARAMETERS=Symbol("PARAMETERS"),$.PATH=Symbol("PATH"),$.ROUTERS=Symbol("ROUTERS");class q extends n{get controllers(){return this._controllers}get instance(){return this._app}get router(){return this._router}get server(){return this._server}constructor(e,s){var r,o;super(),this._app=R(),this._options={},this._base=v(),this._router=v(),this._controllers=[],this._controllers.push(...e.map(e=>a(e)?new e(...t(e)):e)),this._options=h({},{cross:!1,hybrid:!1,path:"/",port:3e3,session:{secret:"yoursecret",resave:!0,saveUninitialized:!1,cookie:{maxAge:864e5}}},null!=s?s:{}),this._app.use(N(this._options.json)),this._app.disable("x-powered-by"),this._app.use(A({extended:!0})),this._options.cross&&this._app.use(m(l(this._options.cross)?this._options.cross:{})),this._app.use(T(this._options.compression)),this._app.use(O(null===(r=this._options.cookie)||void 0===r?void 0:r.secret,this._options.cookie)),this._app.use(I(this._options.session)),this.init(),this._app.use(this._router);const i=(null===(o=this._options.path)||void 0===o?void 0:o.length)?this._options.path:"/";if(this._app.use(i,this._base),this._app.all(i+"/*path",(e,t)=>{this._options.redirect?t.redirect(this._options.redirect):(t.status(F.NOT_FOUND),t.json({message:"INVALID API"}))}),this._options.public){const e=L(this._options.public);S(e)&&this._app.use(R.static(e)),this._app.get("*path",(t,s)=>{S(e)?s.sendFile(e+"/index.html"):this._options.notfound?s.redirect(this._options.notfound):(s.status(F.NOT_FOUND),s.json({message:'FILE "index.html" NOT FOUND'}))})}else this._app.all("*path",(e,t)=>{this._options.redirect?t.redirect(this._options.redirect):(t.status(F.NOT_FOUND),t.json({message:"INVALID API"}))});this._controllers.forEach(e=>{const t=v(),s=this._middlewares(e),r=$.parameters(e);this._extends(e).forEach(e=>{s.push(...this._middlewares(e)),r.push(...$.parameters(e))}),$.routers(e).forEach(o=>{const i=o.propertyKey.toString();if(E(e[i])){if(!E(t[o.method]))return this._notFound(o.method);const n=this._handles(e,i,s,r);return t[o.method](o.path,...n,(t,s,o)=>P(this,void 0,void 0,function*(){const n=new H(t,s,o,this,e),a=this._args(n,this._indexes(i,r)),h=yield e[i](...a);n.close(u(h)||l(h)?h:void 0)}))}this._notFound(`${e.name}.${i}`)}),this._extends(e).forEach(o=>{$.routers(o).forEach(o=>{const i=o.propertyKey.toString();if(E(e[i])){if(!E(t[o.method]))return this._notFound(o.method);const n=this._handles(e,i,s,r);return t[o.method](o.path,...n,(t,s,o)=>P(this,void 0,void 0,function*(){const n=new H(t,s,o,this,e),a=this._args(n,this._indexes(i,r)),h=yield e[i](...a);n.close(u(h)||l(h)?h:void 0)}))}this._notFound(`${e.constructor.name}.${i}`)})}),this._base.use($.path(e,"/"),t)})}init(){}error(e,t){s.error(e)}log(e,t){s.info(e)}_args(e,t,s){const r=[],o={ctx:e,key:"",app:this,argument:s};return t.forEach(e=>{r[e.parameterIndex]=e.callback(Object.assign(Object.assign({},o),{key:e.key}))}),r}_handles(e,t,s,r){return s.filter(e=>e.propertyKey==t).map(t=>{if(t.callback!=p){const s=this._indexes(t.method,r);return(r,o,i)=>P(this,void 0,void 0,function*(){const n=new H(r,o,i,this,e),a=E(t.argument)?t.argument(n):t.argument,h=yield t.callback.call(e,...this._args(n,s,a));(u(h)||l(h))&&n.close(h)})}this._notFound(t.method)}).filter(E)}_extends(e){return $.extends(e).reduce((e,t)=>(e.push(t,...this._extends(t)),e),[]).filter((e,t,s)=>s.indexOf(e)===t)}_indexes(e,t){return t.filter(t=>t.propertyKey==e)}_middlewares(e){return[...$.middleware(e)].reverse()}_notFound(e){this.error(new Error(`Router "${e}" not found`),"express")}_port(e){return`Server listening on port ${e}`}listen(){return P(this,void 0,void 0,function*(){if(this._options.cert&&this._options.key||(this._server=f.createServer(this._app),this._server.listen(this._options.port,()=>this.log(this._port(this._options.port),"express"))),!this._server){const e=f.createServer((e,t)=>{const s=80==this._options.port?":80":"";t.writeHead(F.MOVED_PERMANENTLY,{Location:`https://${e.headers.host}${s}${e.url}`}),t.end()}),t=D.createServer({key:this._options.key,cert:this._options.cert},this._app);if(this._options.hybrid){new g(s=>{s.once("data",r=>{s.pause(),s.unshift(r),(22===r[0]?t:e).emit("connection",s),process.nextTick(()=>s.resume())})}).listen(this._options.port,()=>this.log(this._port(this._options.port),"express")),this._server=t}this._server||(443==this._options.port&&e.listen(80,()=>this.log(this._port(80),"express")),t.listen(this._options.port,()=>this.log(this._port(this._options.port),"express")),this._server=t)}})}}const G=e=>t=>{$.path(t,(null==e?void 0:e.length)?e:"/")},Y=e=>t=>{$.extends(t).push(e)};var j;!function(e){e.ALL="all",e.GET="get",e.POST="post",e.PUT="put",e.HEAD="head",e.DELETE="delete",e.OPTIONS="options",e.PATCH="patch"}(j||(j={}));const K=e=>t=>(s,r)=>{$.routers(s).push({method:e,path:(null==t?void 0:t.length)?t:"/",propertyKey:r})},Q=K(j.ALL),V=K(j.DELETE),W=K(j.GET),X=K(j.HEAD),B=K(j.OPTIONS),z=K(j.PATCH),Z=K(j.POST),J=K(j.PUT),ee=e=>t=>(s,r,o)=>{$.parameters(s).push({callback:e,key:t,propertyKey:r,parameterIndex:o})},te=ee(({app:e})=>e),se=ee(({argument:e})=>e),re=(e,t)=>i(t)?e:e[t],oe=ee(({ctx:e,key:t})=>{var s,r;return re(null!==(r=null===(s=e.req)||void 0===s?void 0:s.body)&&void 0!==r?r:{},t)}),ie=ee(({ctx:e,key:t})=>{var s,r;return re(null!==(r=null===(s=e.req)||void 0===s?void 0:s.cookies)&&void 0!==r?r:{},t)}),ne=ee(({ctx:e})=>e),ae=ee(({ctx:e})=>{var t,s;return null!==(s=null===(t=e.req)||void 0===t?void 0:t.files)&&void 0!==s?s:{}}),he=ee(({ctx:e,key:t})=>{var s,r;return re(null!==(r=null===(s=e.req)||void 0===s?void 0:s.headers)&&void 0!==r?r:{},t)}),le=ee(({ctx:e,key:t})=>{var s,r;return re(null!==(r=null===(s=e.req)||void 0===s?void 0:s.params)&&void 0!==r?r:{},t)}),Ee=ee(({ctx:e,key:t})=>{var s,r,o;return String(null!==(o=re(null!==(r=null===(s=e.req)||void 0===s?void 0:s.query)&&void 0!==r?r:{},t))&&void 0!==o?o:"")}),pe=ee(({ctx:e})=>{var t;return null===(t=e.req)||void 0===t?void 0:t.session}),ue=(e,t)=>(s,r)=>{const o=d();ne()(s,o,0),$.middleware(s).push({method:o,argument:t,propertyKey:r,callback:e})},de=e=>{var t;return(null===(t=e.split(".").pop())||void 0===t?void 0:t.toLowerCase())||"bin"},ce=(e,t)=>{var s;return null!==(s=e[t])&&void 0!==s?s:null},_e=(e,t)=>{const s=d()+"."+t;return S(x(e,s))?_e(e,t):s},Te=e=>{const t=h({},e),s=C({destination(e,s,r){var o;const i=ce(t,s.fieldname);r(null,null!==(o=null==i?void 0:i.path)&&void 0!==o?o:"./")},filename(e,s,r){var o;const i=ce(t,s.fieldname);r(null,_e(null!==(o=null==i?void 0:i.path)&&void 0!==o?o:"./",de(s.originalname)))}}),r=Math.max(...Object.values(t).map(e=>{var t;return null!==(t=e.size)&&void 0!==t?t:0})),o=y({storage:s,fileFilter(e,s,r){var o;const i=ce(t,s.fieldname);return i?((e,t)=>!t.length||t.includes(de(e.originalname))||t.includes(e.mimetype.toLowerCase()))(s,null!==(o=null==i?void 0:i.types)&&void 0!==o?o:[])?void r(null,!0):r(new Error(`FILE TYPE NOT ALLOWED FOR "${s.fieldname}"`)):r(new Error(`UPLOAD FIELD "${s.fieldname}" IS NOT CONFIGURED`))},limits:{fileSize:1024*r*1024}}).fields(Object.keys(t).map(e=>{var s,r;return{name:e,maxCount:null!==(r=null===(s=t[e])||void 0===s?void 0:s.count)&&void 0!==r?r:1}}));return(e,t,s)=>{ue(e=>{o(e.req,e.res,t=>{if(t)return"LIMIT_UNEXPECTED_FILE"==t.code&&(t.message=`FIELD "${t.field}" EXCEEDS MAX SIZE`),e.destroy(t);e.next()})})(e,t,s)}},Oe=e=>(t,s,r)=>{ue(t=>{t.cache(Object.assign({},e)),t.next()})(t,s,r)},me=(e,t)=>(s,r)=>{let o=p;if(c(r)){const t=s;E(t[e])&&(o=t[e])}$.middleware(s).push({method:e,argument:t,propertyKey:r,callback:o})},Re=e=>{const t=_.object(E(e)?e(_):e).parse();return(e,s,r)=>{ue(e=>P(void 0,void 0,void 0,function*(){const{error:s,message:r,value:o}=yield t.validateAsync(e.req.body);if(s)return e.error(new w(null!=r?r:s));e.req.body=o,e.next()}))(e,s,r)}};export{Q as All,te as App,q as Application,se as Argument,oe as Body,Oe as Cache,H as Context,G as Controller,ie as Cookies,ne as Ctx,V as Delete,Y as Extends,ae as Files,W as Get,X as Head,he as Headers,$ as Metadata,j as Methods,me as Middleware,b as NotFoundError,B as Options,le as Params,Re as Parse,z as Patch,Z as Post,J as Put,Ee as Query,M as ResponseError,pe as Session,F as Status,k as UnauthorizedError,Te as Upload,ue as Use,w as ValidationError,K as methodFactory,ee as parameterFactory};
|
|
7
|
+
import{metadata as e,getInjectionArgs as t}from"@andrewcaires/decorator";import{Log as s}from"@andrewcaires/node";import{isNumber as r,forEachKey as o,isUndefined as i,EventEmitter as n,isConstructor as a,merge as h,isObject as l,isFunction as E,noop as p,isArray as u,uuidv7 as d,isString as c,Validation as _}from"@andrewcaires/utils.js";import T from"compression";import O from"cookie-parser";import R from"cors";import m,{Router as v,json as N,urlencoded as A}from"express";import I from"express-session";import{existsSync as S}from"fs";import*as f from"http";import*as D from"https";import{Server as L}from"net";import{resolve as g,join as x}from"path";import{getClientIp as U}from"request-ip";import y,{diskStorage as C}from"multer";function P(e,t,s,r){return new(s||(s=Promise))(function(o,i){function n(e){try{h(r.next(e))}catch(e){i(e)}}function a(e){try{h(r.throw(e))}catch(e){i(e)}}function h(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s(function(e){e(t)})).then(n,a)}h((r=r.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class F{}F.CONTINUE=100,F.SWITCHING_PROTOCOLS=101,F.PROCESSING=102,F.OK=200,F.CREATED=201,F.ACCEPTED=202,F.NON_AUTHORITATIVE_INFORMATION=203,F.NO_CONTENT=204,F.RESET_CONTENT=205,F.PARTIAL_CONTENT=206,F.MULTI_STATUS=207,F.ALREADY_REPORTED=208,F.IM_USED=226,F.MULTIPLE_CHOICES=300,F.MOVED_PERMANENTLY=301,F.FOUND=302,F.SEE_OTHER=303,F.NOT_MODIFIED=304,F.USE_PROXY=305,F.TEMPORARY_REDIRECT=307,F.PERMANENT_REDIRECT=308,F.BAD_REQUEST=400,F.UNAUTHORIZED=401,F.PAYMENT_REQUIRED=402,F.FORBIDDEN=403,F.NOT_FOUND=404,F.METHOD_NOT_ALLOWED=405,F.NOT_ACCEPTABLE=406,F.PROXY_AUTHENTICATION_REQUIRED=407,F.REQUEST_TIMEOUT=408,F.CONFLICT=409,F.GONE=410,F.LENGTH_REQUIRED=411,F.PRECONDITION_FAILED=412,F.PAYLOAD_TOO_LARGE=413,F.REQUEST_URI_TOO_LONG=414,F.UNSUPPORTED_MEDIA_TYPE=415,F.REQUESTED_RANGE_NOT_SATISFIABLE=416,F.EXPECTATION_FAILED=417,F.IM_A_TEAPOT=418,F.MISDIRECTED_REQUEST=421,F.UNPROCESSABLE_ENTITY=422,F.LOCKED=423,F.FAILED_DEPENDENCY=424,F.UPGRADE_REQUIRED=426,F.PRECONDITION_REQUIRED=428,F.TOO_MANY_REQUESTS=429,F.REQUEST_HEADER_FIELDS_TOO_LARGE=431,F.CONNECTION_CLOSED_WITHOUT_RESPONSE=444,F.UNAVAILABLE_FOR_LEGAL_REASONS=451,F.CLIENT_CLOSED_REQUEST=499,F.INTERNAL_SERVER_ERROR=500,F.NOT_IMPLEMENTED=501,F.BAD_GATEWAY=502,F.SERVICE_UNAVAILABLE=503,F.GATEWAY_TIMEOUT=504,F.HTTP_VERSION_NOT_SUPPORTED=505,F.VARIANT_ALSO_NEGOCIATES=506,F.INSUFFICIENT_STORAGE=507,F.LOOP_DETECTED=508,F.NOT_EXTENDED=510,F.NETWORK_AUTHENTICATION_REQUIRED=511,F.NETWORK_CONNECTION_TIMEOUT_ERROR=599;class M extends Error{constructor(e,t=F.INTERNAL_SERVER_ERROR){super(e),this.status=t}}class b extends M{constructor(e="Internal server error"){super(e,F.INTERNAL_SERVER_ERROR)}}class k extends M{constructor(e="Record not found"){super(e,F.NOT_FOUND)}}class w extends M{constructor(e="Unauthorized"){super(e,F.UNAUTHORIZED)}}class H extends M{constructor(e){super(e,F.UNPROCESSABLE_ENTITY)}}class ${constructor(e,t,s,r,o){this.req=e,this.res=t,this.next=s,this.app=r,this.controller=o}cache(e){const t=[];e.private?t.push("private"):e.public&&t.push("public"),e.noStore&&(e.noCache=!0,t.push("no-store")),e.noCache&&(e.maxAge=0,delete e.sMaxAge,t.push("no-cache")),e.noTransform&&t.push("no-transform"),e.proxyRevalidate&&t.push("proxy-revalidate"),e.mustRevalidate?t.push("must-revalidate"):e.noCache||(r(e.staleIfError)&&t.push(`stale-if-error=${e.staleIfError}`),r(e.staleWhileRevalidate)&&t.push(`stale-while-revalidate=${e.staleWhileRevalidate}`)),r(e.maxAge)&&t.push(`max-age=${e.maxAge}`),r(e.sMaxAge)&&t.push(`s-maxage=${e.sMaxAge}`),t.length&&(this.res.setHeader("Cache-Control",t.join(",")),e.noCache&&o({"Surrogate-Control":"no-store",Pragma:"no-cache",ETag:"false",Expires:"0"},(e,t)=>this.res.setHeader(t,e)))}close(e){this.res.headersSent||this.res.json(e||this.storage)}cookie(e,t,s){i(t)?this.res.clearCookie(e):this.res.cookie(e,t,null!=s?s:{})}destroy(e){var t;e&&this.error(e),null===(t=this.res.socket)||void 0===t||t.destroy(e)}error(e){var t;let s=null!==(t=e.toString())&&void 0!==t?t:"",r=F.INTERNAL_SERVER_ERROR;e instanceof Error&&(s=e.message,e instanceof M&&(r=e.status)),this.send(r,{error:s})}file(e){this.res.headersSent||(this.status(F.OK),this.res.sendFile(g(e)))}getIp(){return U(this.req)||"0.0.0.0"}getUrl(){return`${this.req.protocol}://${this.req.get("host")}${this.req.originalUrl}`}json(e){this.send(F.OK,e)}prepare(e,t){this.res.headersSent||(this.status(e),this.storage=t)}send(e,t){this.res.headersSent||(this.status(e),this.res.json(t))}status(e){return e&&this.res.status(e),this.res.statusCode}success(e){this.send(F.OK,{message:e})}}class q{static extends(t){return e(q.EXTENDS,t,[])}static middleware(t){return e(q.MIDDLEWARE,t,[])}static parameters(t){return e(q.PARAMETERS,t,[])}static path(t,s){return e(q.PATH,t,s)}static routers(t){return e(q.ROUTERS,t,[])}}q.EXTENDS=Symbol("EXTENDS"),q.MIDDLEWARE=Symbol("MIDDLEWARE"),q.PARAMETERS=Symbol("PARAMETERS"),q.PATH=Symbol("PATH"),q.ROUTERS=Symbol("ROUTERS");class G extends n{get controllers(){return this._controllers}get instance(){return this._app}get router(){return this._router}get server(){return this._server}constructor(e,s){var r,o;super(),this._app=m(),this._options={},this._base=v(),this._router=v(),this._controllers=[],this._controllers.push(...e.map(e=>a(e)?new e(...t(e)):e)),this._options=h({},{cross:!1,hybrid:!1,path:"/",port:3e3,session:{secret:"yoursecret",resave:!0,saveUninitialized:!1,cookie:{maxAge:864e5}}},null!=s?s:{}),this._app.use(N(this._options.json)),this._app.disable("x-powered-by"),this._app.use(A({extended:!0})),this._options.cross&&this._app.use(R(l(this._options.cross)?this._options.cross:{})),this._app.use(T(this._options.compression)),this._app.use(O(null===(r=this._options.cookie)||void 0===r?void 0:r.secret,this._options.cookie)),this._app.use(I(this._options.session)),this.init(),this._app.use(this._router);const i=(null===(o=this._options.path)||void 0===o?void 0:o.length)?this._options.path:"/";if(this._app.use(i,this._base),this._app.all(i+"/*path",(e,t)=>{this._options.redirect?t.redirect(this._options.redirect):(t.status(F.NOT_FOUND),t.json({message:"INVALID API"}))}),this._options.public){const e=g(this._options.public);S(e)&&this._app.use(m.static(e)),this._app.get("*path",(t,s)=>{S(e)?s.sendFile(e+"/index.html"):this._options.notfound?s.redirect(this._options.notfound):(s.status(F.NOT_FOUND),s.json({message:'FILE "index.html" NOT FOUND'}))})}else this._app.all("*path",(e,t)=>{this._options.redirect?t.redirect(this._options.redirect):(t.status(F.NOT_FOUND),t.json({message:"INVALID API"}))});this._controllers.forEach(e=>{const t=v(),s=this._middlewares(e),r=q.parameters(e);this._extends(e).forEach(e=>{s.push(...this._middlewares(e)),r.push(...q.parameters(e))}),q.routers(e).forEach(o=>{const i=o.propertyKey.toString();if(E(e[i])){if(!E(t[o.method]))return this._notFound(o.method);const n=this._handles(e,i,s,r);return t[o.method](o.path,...n,(t,s,o)=>P(this,void 0,void 0,function*(){const n=new $(t,s,o,this,e),a=this._args(n,this._indexes(i,r)),h=yield e[i](...a);n.close(u(h)||l(h)?h:void 0)}))}this._notFound(`${e.name}.${i}`)}),this._extends(e).forEach(o=>{q.routers(o).forEach(o=>{const i=o.propertyKey.toString();if(E(e[i])){if(!E(t[o.method]))return this._notFound(o.method);const n=this._handles(e,i,s,r);return t[o.method](o.path,...n,(t,s,o)=>P(this,void 0,void 0,function*(){const n=new $(t,s,o,this,e),a=this._args(n,this._indexes(i,r)),h=yield e[i](...a);n.close(u(h)||l(h)?h:void 0)}))}this._notFound(`${e.constructor.name}.${i}`)})}),this._base.use(q.path(e,"/"),t)})}init(){}error(e,t){s.error(e)}log(e,t){s.info(e)}_args(e,t,s){const r=[],o={ctx:e,key:"",app:this,argument:s};return t.forEach(e=>{r[e.parameterIndex]=e.callback(Object.assign(Object.assign({},o),{key:e.key}))}),r}_handles(e,t,s,r){return s.filter(e=>e.propertyKey==t).map(t=>{if(t.callback!=p){const s=this._indexes(t.method,r);return(r,o,i)=>P(this,void 0,void 0,function*(){const n=new $(r,o,i,this,e),a=E(t.argument)?t.argument(n):t.argument,h=yield t.callback.call(e,...this._args(n,s,a));(u(h)||l(h))&&n.close(h)})}this._notFound(t.method)}).filter(E)}_extends(e){return q.extends(e).reduce((e,t)=>(e.push(t,...this._extends(t)),e),[]).filter((e,t,s)=>s.indexOf(e)===t)}_indexes(e,t){return t.filter(t=>t.propertyKey==e)}_middlewares(e){return[...q.middleware(e)].reverse()}_notFound(e){this.error(new Error(`Router "${e}" not found`),"express")}_port(e){return`Server listening on port ${e}`}listen(){return P(this,void 0,void 0,function*(){if(this._options.cert&&this._options.key||(this._server=f.createServer(this._app),this._server.listen(this._options.port,()=>this.log(this._port(this._options.port),"express"))),!this._server){const e=f.createServer((e,t)=>{const s=80==this._options.port?":80":"";t.writeHead(F.MOVED_PERMANENTLY,{Location:`https://${e.headers.host}${s}${e.url}`}),t.end()}),t=D.createServer({key:this._options.key,cert:this._options.cert},this._app);if(this._options.hybrid){new L(s=>{s.once("data",r=>{s.pause(),s.unshift(r),(22===r[0]?t:e).emit("connection",s),process.nextTick(()=>s.resume())})}).listen(this._options.port,()=>this.log(this._port(this._options.port),"express")),this._server=t}this._server||(443==this._options.port&&e.listen(80,()=>this.log(this._port(80),"express")),t.listen(this._options.port,()=>this.log(this._port(this._options.port),"express")),this._server=t)}})}}const Y=e=>t=>{q.path(t,(null==e?void 0:e.length)?e:"/")},j=e=>t=>{q.extends(t).push(e)};var K;!function(e){e.ALL="all",e.GET="get",e.POST="post",e.PUT="put",e.HEAD="head",e.DELETE="delete",e.OPTIONS="options",e.PATCH="patch"}(K||(K={}));const Q=e=>t=>(s,r)=>{q.routers(s).push({method:e,path:(null==t?void 0:t.length)?t:"/",propertyKey:r})},V=Q(K.ALL),W=Q(K.DELETE),X=Q(K.GET),B=Q(K.HEAD),z=Q(K.OPTIONS),Z=Q(K.PATCH),J=Q(K.POST),ee=Q(K.PUT),te=e=>t=>(s,r,o)=>{q.parameters(s).push({callback:e,key:t,propertyKey:r,parameterIndex:o})},se=te(({app:e})=>e),re=te(({argument:e})=>e),oe=(e,t)=>i(t)?e:e[t],ie=te(({ctx:e,key:t})=>{var s,r;return oe(null!==(r=null===(s=e.req)||void 0===s?void 0:s.body)&&void 0!==r?r:{},t)}),ne=te(({ctx:e,key:t})=>{var s,r;return oe(null!==(r=null===(s=e.req)||void 0===s?void 0:s.cookies)&&void 0!==r?r:{},t)}),ae=te(({ctx:e})=>e),he=te(({ctx:e})=>{var t,s;return null!==(s=null===(t=e.req)||void 0===t?void 0:t.files)&&void 0!==s?s:{}}),le=te(({ctx:e,key:t})=>{var s,r;return oe(null!==(r=null===(s=e.req)||void 0===s?void 0:s.headers)&&void 0!==r?r:{},t)}),Ee=te(({ctx:e,key:t})=>{var s,r;return oe(null!==(r=null===(s=e.req)||void 0===s?void 0:s.params)&&void 0!==r?r:{},t)}),pe=te(({ctx:e,key:t})=>{var s,r,o;return String(null!==(o=oe(null!==(r=null===(s=e.req)||void 0===s?void 0:s.query)&&void 0!==r?r:{},t))&&void 0!==o?o:"")}),ue=te(({ctx:e})=>{var t;return null===(t=e.req)||void 0===t?void 0:t.session}),de=(e,t)=>(s,r)=>{const o=d();ae()(s,o,0),q.middleware(s).push({method:o,argument:t,propertyKey:r,callback:e})},ce=e=>{var t;return(null===(t=e.split(".").pop())||void 0===t?void 0:t.toLowerCase())||"bin"},_e=(e,t)=>{var s;return null!==(s=e[t])&&void 0!==s?s:null},Te=(e,t)=>{const s=d()+"."+t;return S(x(e,s))?Te(e,t):s},Oe=e=>{const t=h({},e),s=C({destination(e,s,r){var o;const i=_e(t,s.fieldname);r(null,null!==(o=null==i?void 0:i.path)&&void 0!==o?o:"./")},filename(e,s,r){var o;const i=_e(t,s.fieldname);r(null,Te(null!==(o=null==i?void 0:i.path)&&void 0!==o?o:"./",ce(s.originalname)))}}),r=Math.max(...Object.values(t).map(e=>{var t;return null!==(t=e.size)&&void 0!==t?t:0})),o=y({storage:s,fileFilter(e,s,r){var o;const i=_e(t,s.fieldname);return i?((e,t)=>!t.length||t.includes(ce(e.originalname))||t.includes(e.mimetype.toLowerCase()))(s,null!==(o=null==i?void 0:i.types)&&void 0!==o?o:[])?void r(null,!0):r(new Error(`FILE TYPE NOT ALLOWED FOR "${s.fieldname}"`)):r(new Error(`UPLOAD FIELD "${s.fieldname}" IS NOT CONFIGURED`))},limits:{fileSize:1024*r*1024}}).fields(Object.keys(t).map(e=>{var s,r;return{name:e,maxCount:null!==(r=null===(s=t[e])||void 0===s?void 0:s.count)&&void 0!==r?r:1}}));return(e,t,s)=>{de(e=>{o(e.req,e.res,t=>{if(t)return"LIMIT_UNEXPECTED_FILE"==t.code&&(t.message=`FIELD "${t.field}" EXCEEDS MAX SIZE`),e.destroy(t);e.next()})})(e,t,s)}},Re=e=>(t,s,r)=>{de(t=>{t.cache(Object.assign({},e)),t.next()})(t,s,r)},me=(e,t)=>(s,r)=>{let o=p;if(c(r)){const t=s;E(t[e])&&(o=t[e])}q.middleware(s).push({method:e,argument:t,propertyKey:r,callback:o})},ve=e=>{const t=_.object(E(e)?e(_):e).parse();return(e,s,r)=>{de(e=>P(void 0,void 0,void 0,function*(){var s,r;const{error:o,message:i,value:n}=yield t.validateAsync(null!==(r=null===(s=e.req)||void 0===s?void 0:s.body)&&void 0!==r?r:{});if(o)return e.error(new H(null!=i?i:o));e.req.body=n,e.next()}))(e,s,r)}};export{V as All,se as App,G as Application,re as Argument,ie as Body,Re as Cache,$ as Context,Y as Controller,ne as Cookies,ae as Ctx,W as Delete,j as Extends,he as Files,X as Get,B as Head,le as Headers,b as InternalServerError,q as Metadata,K as Methods,me as Middleware,k as NotFoundError,z as Options,Ee as Params,ve as Parse,Z as Patch,J as Post,ee as Put,pe as Query,M as ResponseError,ue as Session,F as Status,w as UnauthorizedError,Oe as Upload,de as Use,H as ValidationError,Q as methodFactory,te as parameterFactory};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andrewcaires/express",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Decorators for express",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@andrewcaires/decorator": "^1.1.1",
|
|
40
40
|
"@andrewcaires/node": "^1.2.10",
|
|
41
|
-
"@andrewcaires/utils.js": "^0.4.
|
|
41
|
+
"@andrewcaires/utils.js": "^0.4.26",
|
|
42
42
|
"compression": "^1.8.1",
|
|
43
43
|
"cookie-parser": "^1.4.7",
|
|
44
44
|
"cors": "^2.8.5",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@rollup/plugin-commonjs": "^29.0.0",
|
|
52
52
|
"@rollup/plugin-terser": "^0.4.4",
|
|
53
53
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
54
|
-
"@rollup/rollup-darwin-arm64": "^4.55.
|
|
54
|
+
"@rollup/rollup-darwin-arm64": "^4.55.3",
|
|
55
55
|
"@types/compression": "^1.8.1",
|
|
56
56
|
"@types/cookie-parser": "^1.4.10",
|
|
57
57
|
"@types/cors": "^2.8.19",
|