@andrewcaires/express 1.0.4 → 1.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @andrewcaires/express v1.0.4
2
+ * @andrewcaires/express v1.0.6
3
3
  * Decorators for express
4
4
  * (c) 2023 Andrew Caires
5
5
  * @license: MIT
6
6
  */
7
- "use strict";require("reflect-metadata");var e=require("@andrewcaires/utils.js"),t=require("cors"),s=require("express"),r=require("fs"),o=require("http"),n=require("https"),a=require("net"),i=require("path");function E(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 p,_=E(o),h=E(n);function T(e,t,s,r){return new(s||(s=Promise))((function(o,n){function a(e){try{E(r.next(e))}catch(e){n(e)}}function i(e){try{E(r.throw(e))}catch(e){n(e)}}function E(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(a,i)}E((r=r.apply(e,t||[])).next())}))}exports.MetadataKeys=void 0,(p=exports.MetadataKeys||(exports.MetadataKeys={})).MIDDLEWARE="@express_middleware",p.PATH="@express_path",p.ROUTERS="@express_routers",p.PARAMETERS="@express_parameters";const d=(e,t,s)=>Reflect.hasMetadata(e,t)?Reflect.getMetadata(e,t):s;class u{}u.CONTINUE=100,u.SWITCHING_PROTOCOLS=101,u.PROCESSING=102,u.OK=200,u.CREATED=201,u.ACCEPTED=202,u.NON_AUTHORITATIVE_INFORMATION=203,u.NO_CONTENT=204,u.RESET_CONTENT=205,u.PARTIAL_CONTENT=206,u.MULTI_STATUS=207,u.ALREADY_REPORTED=208,u.IM_USED=226,u.MULTIPLE_CHOICES=300,u.MOVED_PERMANENTLY=301,u.FOUND=302,u.SEE_OTHER=303,u.NOT_MODIFIED=304,u.USE_PROXY=305,u.TEMPORARY_REDIRECT=307,u.PERMANENT_REDIRECT=308,u.BAD_REQUEST=400,u.UNAUTHORIZED=401,u.PAYMENT_REQUIRED=402,u.FORBIDDEN=403,u.NOT_FOUND=404,u.METHOD_NOT_ALLOWED=405,u.NOT_ACCEPTABLE=406,u.PROXY_AUTHENTICATION_REQUIRED=407,u.REQUEST_TIMEOUT=408,u.CONFLICT=409,u.GONE=410,u.LENGTH_REQUIRED=411,u.PRECONDITION_FAILED=412,u.PAYLOAD_TOO_LARGE=413,u.REQUEST_URI_TOO_LONG=414,u.UNSUPPORTED_MEDIA_TYPE=415,u.REQUESTED_RANGE_NOT_SATISFIABLE=416,u.EXPECTATION_FAILED=417,u.IM_A_TEAPOT=418,u.MISDIRECTED_REQUEST=421,u.UNPROCESSABLE_ENTITY=422,u.LOCKED=423,u.FAILED_DEPENDENCY=424,u.UPGRADE_REQUIRED=426,u.PRECONDITION_REQUIRED=428,u.TOO_MANY_REQUESTS=429,u.REQUEST_HEADER_FIELDS_TOO_LARGE=431,u.CONNECTION_CLOSED_WITHOUT_RESPONSE=444,u.UNAVAILABLE_FOR_LEGAL_REASONS=451,u.CLIENT_CLOSED_REQUEST=499,u.INTERNAL_SERVER_ERROR=500,u.NOT_IMPLEMENTED=501,u.BAD_GATEWAY=502,u.SERVICE_UNAVAILABLE=503,u.GATEWAY_TIMEOUT=504,u.HTTP_VERSION_NOT_SUPPORTED=505,u.VARIANT_ALSO_NEGOCIATES=506,u.INSUFFICIENT_STORAGE=507,u.LOOP_DETECTED=508,u.NOT_EXTENDED=510,u.NETWORK_AUTHENTICATION_REQUIRED=511,u.NETWORK_CONNECTION_TIMEOUT_ERROR=599;class c{static success(e,t){return e.status(u.OK).json({message:t})}static data(e,t){return e.status(u.OK).json(Object.assign({},t))}static error(e,t){return e.status(u.INTERNAL_SERVER_ERROR).json({message:t})}static list(e,t){return e.status(u.OK).json([...t])}static notfound(e,t){return e.status(u.NOT_FOUND).json({message:t})}static validation(e,t){return e.status(u.BAD_REQUEST).json({message:t})}static unauthorized(e,t){return e.status(u.UNAUTHORIZED).json({message:t})}}class R extends e.EventEmitter{get instance(){return this._app}get router(){return this._router}get server(){return this._server}constructor(o,n){var a;super(),this._app=s(),this._options={},this._default={cross:!1,hybrid:!1,path:"/",port:3e3},this._router=s.Router(),this._controlles=s.Router(),this._options=Object.assign(Object.assign({},this._default),n),this._app.use(s.json()),this._app.disable("x-powered-by"),this._app.use(s.urlencoded({extended:!0})),this._options.cross&&this._app.use(t()),this._app.use(this._router);const E=(null===(a=this._options.path)||void 0===a?void 0:a.length)?this._options.path:"/";if(this._app.use(E,this._controlles),this._app.all(E+"/*",((e,t)=>c.notfound(t,"Invalid API"))),this._options.public){const e=i.resolve(this._options.public);r.existsSync(e)&&this._app.use(s.static(e)),this._app.get("*",((t,s)=>{if(!r.existsSync(e))return c.notfound(s,'File "index.html" not found');s.sendFile(e+"/index.html")}))}o.forEach((t=>{const r=t.constructor,o=this._path(r),n=this._routers(r),a=this._middlewares(r),i=this._parameters(r),E=s.Router();n.forEach((s=>{const o=s.name.toString();if(e.isFunction(t[o])){if(!e.isFunction(E[s.method]))return this.error(new Error('Method "'+s.method+'" Not Found.'),"express");const r=this._handles(t,o,a,i),n=this._indexes(o,i);E[s.method](s.path,...r,((e,s,r)=>t[o](...this._args(e,s,r,n))))}else this.error(new Error('Router "'+r.name+"."+o+'" Not Found.'),"express")})),this._controlles.use(o,E)}))}error(t,s){e.isUndefined(s)?console.error(t):console.error(s+":",t)}log(t,s){e.isUndefined(s)?console.error(t):console.error(s+":",t)}_args(e,t,s,r,o){const n=[],a={req:e,res:t,next:s,key:"",app:this,argument:o};return r.forEach((e=>{n[e.index]=e.callback(Object.assign(Object.assign({},a),{key:e.key}))})),n}_handles(t,s,r,o){return r.filter((e=>e.name==s)).map((s=>{if(e.isFunction(t[s.method])){const e=this._indexes(s.method,o);return(r,o,n)=>t[s.method](...this._args(r,o,n,e,s.argument))}this.error(new Error('Middleware "'+s.method+'" Not Found.'),"express")})).filter(e.isFunction)}_indexes(e,t){const s=[];return t.forEach((t=>t.name==e&&s.push(t))),s}_middlewares(e){return[...d(exports.MetadataKeys.MIDDLEWARE,e,[])].reverse()}_parameters(e){return d(exports.MetadataKeys.PARAMETERS,e,[])}_path(e){return d(exports.MetadataKeys.PATH,e,"/")}_routers(e){return d(exports.MetadataKeys.ROUTERS,e,[])}listen(){return T(this,void 0,void 0,(function*(){if(this._options.cert&&this._options.key||(this._server=_.createServer(this._app),this._server.listen(this._options.port,(()=>this.log("Server started on port "+this._options.port+".","express")))),!this._server){const e=_.createServer(((e,t)=>{const s=80==this._options.port?":80":"";t.writeHead(301,{Location:"https://"+e.headers.host+s+e.url}),t.end()})),t=h.createServer({key:this._options.key,cert:this._options.cert},this._app);if(this._options.hybrid){new a.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("Server started on port "+this._options.port+".","express"))),this._server=t}this._server||(443==this._options.port&&e.listen(80,(()=>this.log("Server started on port 80","express"))),t.listen(this._options.port,(()=>this.log("Server started on port "+this._options.port+".","express"))),this._server=t)}}))}}var O;exports.Methods=void 0,(O=exports.Methods||(exports.Methods={})).GET="get",O.POST="post",O.PUT="put",O.HEAD="head",O.DELETE="delete",O.OPTIONS="options",O.PATCH="patch";const l=e=>t=>(s,r)=>{const o=s.constructor,n=d(exports.MetadataKeys.ROUTERS,o,[]);n.push({path:(null==t?void 0:t.length)?t:"/",method:e,name:r}),Reflect.defineMetadata(exports.MetadataKeys.ROUTERS,n,o)},A=l(exports.Methods.GET),N=l(exports.Methods.POST),x=l(exports.Methods.PUT),I=l(exports.Methods.DELETE),D=l(exports.Methods.PATCH),S=l(exports.Methods.HEAD),M=l(exports.Methods.OPTIONS),P=e=>t=>(s,r,o)=>{const n=s.constructor,a=d(exports.MetadataKeys.PARAMETERS,n,[]);a.push({callback:e,index:o,key:(null==t?void 0:t.length)?t:"",name:r}),Reflect.defineMetadata(exports.MetadataKeys.PARAMETERS,a,n)},U=(t,s)=>e.isUndefined(s)?t:t[s],f=P((({app:e})=>e)),m=P((({argument:e})=>e)),L=P((({req:e,key:t})=>U(e.body,t))),y=P((({req:e,key:t})=>U(e.cookies,t))),C=P((({req:e,key:t})=>U(e.headers,t))),v=P((({next:e})=>e)),g=P((({req:e,key:t})=>U(e.params,t))),F=P((({req:e,key:t})=>U(e.query,t))),H=P((({req:e})=>e)),K=H,b=P((({res:e})=>e)),j=b;exports.App=f,exports.Application=R,exports.Argument=m,exports.Body=L,exports.Controller=e=>t=>Reflect.defineMetadata(exports.MetadataKeys.PATH,(null==e?void 0:e.length)?e:"/",t),exports.Cookies=y,exports.Delete=I,exports.Get=A,exports.Head=S,exports.Headers=C,exports.Metadata=d,exports.Middleware=(e,t)=>(s,r)=>{const o=s.constructor,n=d(exports.MetadataKeys.MIDDLEWARE,o,[]);n.push({name:r,method:e,argument:t}),Reflect.defineMetadata(exports.MetadataKeys.MIDDLEWARE,n,o)},exports.Next=v,exports.Options=M,exports.Params=g,exports.Patch=D,exports.Post=N,exports.Put=x,exports.Query=F,exports.Req=K,exports.Request=H,exports.Res=j,exports.Response=b,exports.Responses=c,exports.Status=u,exports.methodFactory=l,exports.parameterFactory=P;
7
+ "use strict";var e=require("@andrewcaires/utils.js"),t=require("cors"),s=require("express"),r=require("fs"),o=require("http"),n=require("https"),i=require("net"),a=require("path");function p(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 E=p(o),_=p(n);function h(e,t,s,r){return new(s||(s=Promise))((function(o,n){function i(e){try{p(r.next(e))}catch(e){n(e)}}function a(e){try{p(r.throw(e))}catch(e){n(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(i,a)}p((r=r.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const u=e.cache(),d=(t,s,r)=>{e.isObject(s)&&(s=s.constructor);const o=u(s);return o[t]||(o[t]=r),o[t]};class T{}T.CONTINUE=100,T.SWITCHING_PROTOCOLS=101,T.PROCESSING=102,T.OK=200,T.CREATED=201,T.ACCEPTED=202,T.NON_AUTHORITATIVE_INFORMATION=203,T.NO_CONTENT=204,T.RESET_CONTENT=205,T.PARTIAL_CONTENT=206,T.MULTI_STATUS=207,T.ALREADY_REPORTED=208,T.IM_USED=226,T.MULTIPLE_CHOICES=300,T.MOVED_PERMANENTLY=301,T.FOUND=302,T.SEE_OTHER=303,T.NOT_MODIFIED=304,T.USE_PROXY=305,T.TEMPORARY_REDIRECT=307,T.PERMANENT_REDIRECT=308,T.BAD_REQUEST=400,T.UNAUTHORIZED=401,T.PAYMENT_REQUIRED=402,T.FORBIDDEN=403,T.NOT_FOUND=404,T.METHOD_NOT_ALLOWED=405,T.NOT_ACCEPTABLE=406,T.PROXY_AUTHENTICATION_REQUIRED=407,T.REQUEST_TIMEOUT=408,T.CONFLICT=409,T.GONE=410,T.LENGTH_REQUIRED=411,T.PRECONDITION_FAILED=412,T.PAYLOAD_TOO_LARGE=413,T.REQUEST_URI_TOO_LONG=414,T.UNSUPPORTED_MEDIA_TYPE=415,T.REQUESTED_RANGE_NOT_SATISFIABLE=416,T.EXPECTATION_FAILED=417,T.IM_A_TEAPOT=418,T.MISDIRECTED_REQUEST=421,T.UNPROCESSABLE_ENTITY=422,T.LOCKED=423,T.FAILED_DEPENDENCY=424,T.UPGRADE_REQUIRED=426,T.PRECONDITION_REQUIRED=428,T.TOO_MANY_REQUESTS=429,T.REQUEST_HEADER_FIELDS_TOO_LARGE=431,T.CONNECTION_CLOSED_WITHOUT_RESPONSE=444,T.UNAVAILABLE_FOR_LEGAL_REASONS=451,T.CLIENT_CLOSED_REQUEST=499,T.INTERNAL_SERVER_ERROR=500,T.NOT_IMPLEMENTED=501,T.BAD_GATEWAY=502,T.SERVICE_UNAVAILABLE=503,T.GATEWAY_TIMEOUT=504,T.HTTP_VERSION_NOT_SUPPORTED=505,T.VARIANT_ALSO_NEGOCIATES=506,T.INSUFFICIENT_STORAGE=507,T.LOOP_DETECTED=508,T.NOT_EXTENDED=510,T.NETWORK_AUTHENTICATION_REQUIRED=511,T.NETWORK_CONNECTION_TIMEOUT_ERROR=599;class c{static success(e,t){return e.status(T.OK).json({message:t})}static data(e,t){return e.status(T.OK).json(Object.assign({},t))}static error(e,t){return e.status(T.INTERNAL_SERVER_ERROR).json({message:t})}static list(e,t){return e.status(T.OK).json([...t])}static notfound(e,t){return e.status(T.NOT_FOUND).json({message:t})}static validation(e,t){return e.status(T.BAD_REQUEST).json({message:t})}static unauthorized(e,t){return e.status(T.UNAUTHORIZED).json({message:t})}}var O,R;exports.MetadataKeys=void 0,(O=exports.MetadataKeys||(exports.MetadataKeys={})).EXTENDS="__extends__",O.MIDDLEWARE="__middleware__",O.PARAMETERS="__parameters__",O.PATH="__path__",O.ROUTERS="__routers__",exports.Methods=void 0,(R=exports.Methods||(exports.Methods={})).ALL="all",R.GET="get",R.POST="post",R.PUT="put",R.HEAD="head",R.DELETE="delete",R.OPTIONS="options",R.PATCH="patch";class N extends e.EventEmitter{get instance(){return this._app}get router(){return this._router}get server(){return this._server}constructor(o,n){var i;super(),this._app=s(),this._options={},this._default={cross:!1,hybrid:!1,path:"/",port:3e3},this._router=s.Router(),this._controllers=s.Router(),this._options=Object.assign(Object.assign({},this._default),n),this._app.use(s.json()),this._app.disable("x-powered-by"),this._app.use(s.urlencoded({extended:!0})),this._options.cross&&this._app.use(t()),this._app.use(this._router);const p=(null===(i=this._options.path)||void 0===i?void 0:i.length)?this._options.path:"/";if(this._app.use(p,this._controllers),this._app.all(p+"/*",((e,t)=>c.notfound(t,"Invalid API"))),this._options.public){const e=a.resolve(this._options.public);r.existsSync(e)&&this._app.use(s.static(e)),this._app.get("*",((t,s)=>{if(!r.existsSync(e))return c.notfound(s,'File "index.html" not found');s.sendFile(e+"/index.html")}))}o.forEach((t=>{const r=s.Router(),o=this._middlewares(t),n=this._parameters(t);this._extends(t).forEach((e=>{o.push(...this._middlewares(e)),n.push(...this._parameters(e))})),this._routers(t).forEach((s=>{const i=s.propertyKey.toString();if(e.isFunction(t[i])){if(!e.isFunction(r[s.method]))return this.error(new Error('Method "'+s.method+'" Not Found.'),"express");const a=this._handles(t,i,o,n);return r[s.method](s.path,...a,((e,s,r)=>t[i](...this._args(e,s,r,this._indexes(i,n)))))}return this.error(new Error('Router "'+t.name+"."+i+'" Not Found.'),"express")})),this._extends(t).forEach((s=>{this._routers(s).forEach((s=>{const i=s.propertyKey.toString();if(e.isFunction(t[i])){if(!e.isFunction(r[s.method]))return this.error(new Error('Method "'+s.method+'" Not Found.'),"express");const a=this._handles(t,i,o,n);return r[s.method](s.path,...a,((e,s,r)=>t[i](...this._args(e,s,r,this._indexes(i,n)))))}return this.error(new Error('Router "'+t.constructor.name+"."+i+'" Not Found.'),"express")}))})),this._controllers.use(this._path(t),r)}))}error(t,s){e.isUndefined(s)?console.error(t):console.error(s+":",t)}log(t,s){e.isUndefined(s)?console.error(t):console.error(s+":",t)}_args(e,t,s,r,o){const n=[],i={req:e,res:t,next:s,key:"",app:this,argument:o};return r.forEach((e=>{n[e.parameterIndex]=e.callback(Object.assign(Object.assign({},i),{key:e.key}))})),n}_handles(t,s,r,o){return r.filter((e=>e.propertyKey==s)).map((s=>{if(e.isFunction(t[s.method])){const e=this._indexes(s.method,o);return(r,o,n)=>t[s.method](...this._args(r,o,n,e,s.argument))}this.error(new Error('Middleware "'+s.method+'" Not Found.'),"express")})).filter(e.isFunction)}_extends(e){return d(exports.MetadataKeys.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[...d(exports.MetadataKeys.MIDDLEWARE,e,[])].reverse()}_parameters(e){return d(exports.MetadataKeys.PARAMETERS,e,[])}_path(e){return d(exports.MetadataKeys.PATH,e,"/")}_routers(e){return d(exports.MetadataKeys.ROUTERS,e,[])}listen(){return h(this,void 0,void 0,(function*(){if(this._options.cert&&this._options.key||(this._server=E.createServer(this._app),this._server.listen(this._options.port,(()=>this.log("Server started on port "+this._options.port+".","express")))),!this._server){const e=E.createServer(((e,t)=>{const s=80==this._options.port?":80":"";t.writeHead(301,{Location:"https://"+e.headers.host+s+e.url}),t.end()})),t=_.createServer({key:this._options.key,cert:this._options.cert},this._app);if(this._options.hybrid){new i.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("Server started on port "+this._options.port+".","express"))),this._server=t}this._server||(443==this._options.port&&e.listen(80,(()=>this.log("Server started on port 80.","express"))),t.listen(this._options.port,(()=>this.log("Server started on port "+this._options.port+".","express"))),this._server=t)}}))}}const x=e=>t=>(s,r)=>{d(exports.MetadataKeys.ROUTERS,s,[]).push({method:e,path:(null==t?void 0:t.length)?t:"/",propertyKey:r})},A=x(exports.Methods.ALL),l=x(exports.Methods.GET),I=x(exports.Methods.POST),S=x(exports.Methods.PUT),D=x(exports.Methods.DELETE),y=x(exports.Methods.PATCH),M=x(exports.Methods.HEAD),P=x(exports.Methods.OPTIONS),U=e=>t=>(s,r,o)=>{d(exports.MetadataKeys.PARAMETERS,s,[]).push({callback:e,key:t,propertyKey:r,parameterIndex:o})},f=(t,s)=>e.isUndefined(s)?t:t[s],L=U((({app:e})=>e)),m=U((({argument:e})=>e)),C=U((({req:e,key:t})=>f(e.body,t))),v=U((({req:e,key:t})=>f(e.cookies,t))),g=U((({req:e,key:t})=>f(e.headers,t))),F=U((({next:e})=>e)),K=U((({req:e,key:t})=>f(e.params,t))),H=U((({req:e,key:t})=>f(e.query,t))),b=U((({req:e,key:t})=>f(e,t))),j=b,k=U((({res:e})=>e)),w=k;exports.All=A,exports.App=L,exports.Application=N,exports.Argument=m,exports.Body=C,exports.Controller=e=>t=>{d(exports.MetadataKeys.PATH,t,(null==e?void 0:e.length)?e:"/")},exports.Cookies=v,exports.Delete=D,exports.Extends=e=>t=>{d(exports.MetadataKeys.EXTENDS,t,[]).push(e)},exports.Get=l,exports.Head=M,exports.Headers=g,exports.Metadata=d,exports.Middleware=(e,t)=>(s,r)=>{d(exports.MetadataKeys.MIDDLEWARE,s,[]).push({method:e,argument:t,propertyKey:r})},exports.Next=F,exports.Options=P,exports.Params=K,exports.Patch=y,exports.Post=I,exports.Put=S,exports.Query=H,exports.Req=j,exports.Request=b,exports.Res=w,exports.Response=k,exports.Responses=c,exports.Status=T,exports.methodFactory=x,exports.parameterFactory=U;
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  /*!
2
- * @andrewcaires/express v1.0.4
2
+ * @andrewcaires/express v1.0.6
3
3
  * Decorators for express
4
4
  * (c) 2023 Andrew Caires
5
5
  * @license: MIT
6
6
  */
7
- import { EventEmitter, TypeCallbackFunction } from '@andrewcaires/utils.js';
7
+ import { TypeCallbackFunction, EventEmitter } from '@andrewcaires/utils.js';
8
8
  import { Request as Request$1, Response as Response$1, NextFunction, Express, Router } from 'express';
9
9
  import * as http from 'http';
10
10
  import * as https from 'https';
@@ -17,6 +17,13 @@ interface IArgs {
17
17
  app: Application;
18
18
  argument: any;
19
19
  }
20
+
21
+ interface IMiddlewares {
22
+ method: string;
23
+ argument: any;
24
+ propertyKey: string | symbol;
25
+ }
26
+
20
27
  interface IOptions {
21
28
  cert?: Buffer;
22
29
  cross?: boolean;
@@ -26,21 +33,55 @@ interface IOptions {
26
33
  port?: number;
27
34
  public?: string;
28
35
  }
36
+
37
+ interface IParameter {
38
+ callback: TypeCallbackFunction;
39
+ key?: string;
40
+ propertyKey: string | symbol | undefined;
41
+ parameterIndex: number;
42
+ }
43
+
44
+ declare enum Methods {
45
+ ALL = "all",
46
+ GET = "get",
47
+ POST = "post",
48
+ PUT = "put",
49
+ HEAD = "head",
50
+ DELETE = "delete",
51
+ OPTIONS = "options",
52
+ PATCH = "patch"
53
+ }
54
+
55
+ interface IRouter {
56
+ method: Methods;
57
+ path: string;
58
+ propertyKey: string | symbol;
59
+ }
60
+
61
+ declare enum MetadataKeys {
62
+ EXTENDS = "__extends__",
63
+ MIDDLEWARE = "__middleware__",
64
+ PARAMETERS = "__parameters__",
65
+ PATH = "__path__",
66
+ ROUTERS = "__routers__"
67
+ }
68
+
29
69
  declare class Application extends EventEmitter {
30
70
  private readonly _app;
31
71
  private _server?;
32
72
  private _options;
33
73
  private _default;
34
74
  private readonly _router;
35
- private readonly _controlles;
75
+ private readonly _controllers;
36
76
  get instance(): Express;
37
77
  get router(): Router;
38
78
  get server(): http.Server | https.Server | undefined;
39
- constructor(controlles: Array<object>, options?: IOptions);
79
+ constructor(controllers: Array<object>, options?: IOptions);
40
80
  error(error: any, source?: string): void;
41
81
  log(message: string, source?: string): void;
42
82
  private _args;
43
83
  private _handles;
84
+ private _extends;
44
85
  private _indexes;
45
86
  private _middlewares;
46
87
  private _parameters;
@@ -51,29 +92,10 @@ declare class Application extends EventEmitter {
51
92
 
52
93
  declare const Controller: (path?: string) => ClassDecorator;
53
94
 
54
- declare enum MetadataKeys {
55
- MIDDLEWARE = "@express_middleware",
56
- PATH = "@express_path",
57
- ROUTERS = "@express_routers",
58
- PARAMETERS = "@express_parameters"
59
- }
60
- declare const Metadata: (metadataKey: MetadataKeys, target: any, test: any) => any;
95
+ declare const Extends: (type: any) => ClassDecorator;
61
96
 
62
- interface IRouter {
63
- path: string;
64
- method: Methods;
65
- name: string | symbol;
66
- }
67
- declare enum Methods {
68
- GET = "get",
69
- POST = "post",
70
- PUT = "put",
71
- HEAD = "head",
72
- DELETE = "delete",
73
- OPTIONS = "options",
74
- PATCH = "patch"
75
- }
76
97
  declare const methodFactory: (method: Methods) => (path?: string) => MethodDecorator;
98
+ declare const All: (path?: string) => MethodDecorator;
77
99
  declare const Get: (path?: string) => MethodDecorator;
78
100
  declare const Post: (path?: string) => MethodDecorator;
79
101
  declare const Put: (path?: string) => MethodDecorator;
@@ -82,19 +104,8 @@ declare const Patch: (path?: string) => MethodDecorator;
82
104
  declare const Head: (path?: string) => MethodDecorator;
83
105
  declare const Options: (path?: string) => MethodDecorator;
84
106
 
85
- interface IMiddlewares {
86
- name: string | symbol;
87
- method: string;
88
- argument: any;
89
- }
90
107
  declare const Middleware: (method: string, argument?: any) => MethodDecorator;
91
108
 
92
- interface IParameter {
93
- callback: TypeCallbackFunction;
94
- index: number;
95
- key: string;
96
- name: string | symbol;
97
- }
98
109
  declare const parameterFactory: (callback: TypeCallbackFunction) => (key?: string) => ParameterDecorator;
99
110
  declare const App: (key?: string) => ParameterDecorator;
100
111
  declare const Argument: (key?: string) => ParameterDecorator;
@@ -109,6 +120,8 @@ declare const Req: (key?: string) => ParameterDecorator;
109
120
  declare const Response: (key?: string) => ParameterDecorator;
110
121
  declare const Res: (key?: string) => ParameterDecorator;
111
122
 
123
+ declare const Metadata: <T = any>(metadataKey: MetadataKeys, target: any, metadataValue: T) => T;
124
+
112
125
  type ResponseJson = Response$1<any, Record<string, any>>;
113
126
  declare class Responses {
114
127
  static success(res: Response$1, message: string): ResponseJson;
@@ -186,4 +199,4 @@ declare class Status {
186
199
  static readonly NETWORK_CONNECTION_TIMEOUT_ERROR = 599;
187
200
  }
188
201
 
189
- export { App, Application, Argument, Body, Controller, Cookies, Delete, Get, Head, Headers, IArgs, IMiddlewares, IOptions, IParameter, IRouter, Metadata, MetadataKeys, Methods, Middleware, Next, Options, Params, Patch, Post, Put, Query, Req, Request, Res, Response, ResponseJson, Responses, Status, methodFactory, parameterFactory };
202
+ export { All, App, Application, Argument, Body, Controller, Cookies, Delete, Extends, Get, Head, Headers, type IArgs, type IMiddlewares, type IOptions, type IParameter, type IRouter, Metadata, MetadataKeys, Methods, Middleware, Next, Options, Params, Patch, Post, Put, Query, Req, Request, Res, Response, type ResponseJson, Responses, Status, methodFactory, parameterFactory };
package/dist/index.esm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @andrewcaires/express v1.0.4
2
+ * @andrewcaires/express v1.0.6
3
3
  * Decorators for express
4
4
  * (c) 2023 Andrew Caires
5
5
  * @license: MIT
6
6
  */
7
- import"reflect-metadata";import{EventEmitter as t,isFunction as e,isUndefined as s}from"@andrewcaires/utils.js";import r from"cors";import o,{Router as n,json as E,urlencoded as i}from"express";import{existsSync as a}from"fs";import*as _ from"http";import*as T from"https";import{Server as h}from"net";import{resolve as p}from"path";function R(t,e,s,r){return new(s||(s=Promise))((function(o,n){function E(t){try{a(r.next(t))}catch(t){n(t)}}function i(t){try{a(r.throw(t))}catch(t){n(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(E,i)}a((r=r.apply(t,e||[])).next())}))}var O;!function(t){t.MIDDLEWARE="@express_middleware",t.PATH="@express_path",t.ROUTERS="@express_routers",t.PARAMETERS="@express_parameters"}(O||(O={}));const c=(t,e,s)=>Reflect.hasMetadata(t,e)?Reflect.getMetadata(t,e):s;class u{}u.CONTINUE=100,u.SWITCHING_PROTOCOLS=101,u.PROCESSING=102,u.OK=200,u.CREATED=201,u.ACCEPTED=202,u.NON_AUTHORITATIVE_INFORMATION=203,u.NO_CONTENT=204,u.RESET_CONTENT=205,u.PARTIAL_CONTENT=206,u.MULTI_STATUS=207,u.ALREADY_REPORTED=208,u.IM_USED=226,u.MULTIPLE_CHOICES=300,u.MOVED_PERMANENTLY=301,u.FOUND=302,u.SEE_OTHER=303,u.NOT_MODIFIED=304,u.USE_PROXY=305,u.TEMPORARY_REDIRECT=307,u.PERMANENT_REDIRECT=308,u.BAD_REQUEST=400,u.UNAUTHORIZED=401,u.PAYMENT_REQUIRED=402,u.FORBIDDEN=403,u.NOT_FOUND=404,u.METHOD_NOT_ALLOWED=405,u.NOT_ACCEPTABLE=406,u.PROXY_AUTHENTICATION_REQUIRED=407,u.REQUEST_TIMEOUT=408,u.CONFLICT=409,u.GONE=410,u.LENGTH_REQUIRED=411,u.PRECONDITION_FAILED=412,u.PAYLOAD_TOO_LARGE=413,u.REQUEST_URI_TOO_LONG=414,u.UNSUPPORTED_MEDIA_TYPE=415,u.REQUESTED_RANGE_NOT_SATISFIABLE=416,u.EXPECTATION_FAILED=417,u.IM_A_TEAPOT=418,u.MISDIRECTED_REQUEST=421,u.UNPROCESSABLE_ENTITY=422,u.LOCKED=423,u.FAILED_DEPENDENCY=424,u.UPGRADE_REQUIRED=426,u.PRECONDITION_REQUIRED=428,u.TOO_MANY_REQUESTS=429,u.REQUEST_HEADER_FIELDS_TOO_LARGE=431,u.CONNECTION_CLOSED_WITHOUT_RESPONSE=444,u.UNAVAILABLE_FOR_LEGAL_REASONS=451,u.CLIENT_CLOSED_REQUEST=499,u.INTERNAL_SERVER_ERROR=500,u.NOT_IMPLEMENTED=501,u.BAD_GATEWAY=502,u.SERVICE_UNAVAILABLE=503,u.GATEWAY_TIMEOUT=504,u.HTTP_VERSION_NOT_SUPPORTED=505,u.VARIANT_ALSO_NEGOCIATES=506,u.INSUFFICIENT_STORAGE=507,u.LOOP_DETECTED=508,u.NOT_EXTENDED=510,u.NETWORK_AUTHENTICATION_REQUIRED=511,u.NETWORK_CONNECTION_TIMEOUT_ERROR=599;class N{static success(t,e){return t.status(u.OK).json({message:e})}static data(t,e){return t.status(u.OK).json(Object.assign({},e))}static error(t,e){return t.status(u.INTERNAL_SERVER_ERROR).json({message:e})}static list(t,e){return t.status(u.OK).json([...e])}static notfound(t,e){return t.status(u.NOT_FOUND).json({message:e})}static validation(t,e){return t.status(u.BAD_REQUEST).json({message:e})}static unauthorized(t,e){return t.status(u.UNAUTHORIZED).json({message:e})}}class A extends t{get instance(){return this._app}get router(){return this._router}get server(){return this._server}constructor(t,s){var _;super(),this._app=o(),this._options={},this._default={cross:!1,hybrid:!1,path:"/",port:3e3},this._router=n(),this._controlles=n(),this._options=Object.assign(Object.assign({},this._default),s),this._app.use(E()),this._app.disable("x-powered-by"),this._app.use(i({extended:!0})),this._options.cross&&this._app.use(r()),this._app.use(this._router);const T=(null===(_=this._options.path)||void 0===_?void 0:_.length)?this._options.path:"/";if(this._app.use(T,this._controlles),this._app.all(T+"/*",((t,e)=>N.notfound(e,"Invalid API"))),this._options.public){const t=p(this._options.public);a(t)&&this._app.use(o.static(t)),this._app.get("*",((e,s)=>{if(!a(t))return N.notfound(s,'File "index.html" not found');s.sendFile(t+"/index.html")}))}t.forEach((t=>{const s=t.constructor,r=this._path(s),o=this._routers(s),E=this._middlewares(s),i=this._parameters(s),a=n();o.forEach((r=>{const o=r.name.toString();if(e(t[o])){if(!e(a[r.method]))return this.error(new Error('Method "'+r.method+'" Not Found.'),"express");const s=this._handles(t,o,E,i),n=this._indexes(o,i);a[r.method](r.path,...s,((e,s,r)=>t[o](...this._args(e,s,r,n))))}else this.error(new Error('Router "'+s.name+"."+o+'" Not Found.'),"express")})),this._controlles.use(r,a)}))}error(t,e){s(e)?console.error(t):console.error(e+":",t)}log(t,e){s(e)?console.error(t):console.error(e+":",t)}_args(t,e,s,r,o){const n=[],E={req:t,res:e,next:s,key:"",app:this,argument:o};return r.forEach((t=>{n[t.index]=t.callback(Object.assign(Object.assign({},E),{key:t.key}))})),n}_handles(t,s,r,o){return r.filter((t=>t.name==s)).map((s=>{if(e(t[s.method])){const e=this._indexes(s.method,o);return(r,o,n)=>t[s.method](...this._args(r,o,n,e,s.argument))}this.error(new Error('Middleware "'+s.method+'" Not Found.'),"express")})).filter(e)}_indexes(t,e){const s=[];return e.forEach((e=>e.name==t&&s.push(e))),s}_middlewares(t){return[...c(O.MIDDLEWARE,t,[])].reverse()}_parameters(t){return c(O.PARAMETERS,t,[])}_path(t){return c(O.PATH,t,"/")}_routers(t){return c(O.ROUTERS,t,[])}listen(){return R(this,void 0,void 0,(function*(){if(this._options.cert&&this._options.key||(this._server=_.createServer(this._app),this._server.listen(this._options.port,(()=>this.log("Server started on port "+this._options.port+".","express")))),!this._server){const t=_.createServer(((t,e)=>{const s=80==this._options.port?":80":"";e.writeHead(301,{Location:"https://"+t.headers.host+s+t.url}),e.end()})),e=T.createServer({key:this._options.key,cert:this._options.cert},this._app);if(this._options.hybrid){new h((s=>{s.once("data",(r=>{s.pause(),s.unshift(r),(22===r[0]?e:t).emit("connection",s),process.nextTick((()=>s.resume()))}))})).listen(this._options.port,(()=>this.log("Server started on port "+this._options.port+".","express"))),this._server=e}this._server||(443==this._options.port&&t.listen(80,(()=>this.log("Server started on port 80","express"))),e.listen(this._options.port,(()=>this.log("Server started on port "+this._options.port+".","express"))),this._server=e)}}))}}const d=t=>e=>Reflect.defineMetadata(O.PATH,(null==t?void 0:t.length)?t:"/",e);var l;!function(t){t.GET="get",t.POST="post",t.PUT="put",t.HEAD="head",t.DELETE="delete",t.OPTIONS="options",t.PATCH="patch"}(l||(l={}));const I=t=>e=>(s,r)=>{const o=s.constructor,n=c(O.ROUTERS,o,[]);n.push({path:(null==e?void 0:e.length)?e:"/",method:t,name:r}),Reflect.defineMetadata(O.ROUTERS,n,o)},D=I(l.GET),S=I(l.POST),m=I(l.PUT),f=I(l.DELETE),U=I(l.PATCH),P=I(l.HEAD),L=I(l.OPTIONS),C=(t,e)=>(s,r)=>{const o=s.constructor,n=c(O.MIDDLEWARE,o,[]);n.push({name:r,method:t,argument:e}),Reflect.defineMetadata(O.MIDDLEWARE,n,o)},M=t=>e=>(s,r,o)=>{const n=s.constructor,E=c(O.PARAMETERS,n,[]);E.push({callback:t,index:o,key:(null==e?void 0:e.length)?e:"",name:r}),Reflect.defineMetadata(O.PARAMETERS,E,n)},g=(t,e)=>s(e)?t:t[e],v=M((({app:t})=>t)),x=M((({argument:t})=>t)),H=M((({req:t,key:e})=>g(t.body,e))),y=M((({req:t,key:e})=>g(t.cookies,e))),F=M((({req:t,key:e})=>g(t.headers,e))),k=M((({next:t})=>t)),G=M((({req:t,key:e})=>g(t.params,e))),Q=M((({req:t,key:e})=>g(t.query,e))),b=M((({req:t})=>t)),w=b,j=M((({res:t})=>t)),Y=j;export{v as App,A as Application,x as Argument,H as Body,d as Controller,y as Cookies,f as Delete,D as Get,P as Head,F as Headers,c as Metadata,O as MetadataKeys,l as Methods,C as Middleware,k as Next,L as Options,G as Params,U as Patch,S as Post,m as Put,Q as Query,w as Req,b as Request,Y as Res,j as Response,N as Responses,u as Status,I as methodFactory,M as parameterFactory};
7
+ import{cache as t,isObject as e,EventEmitter as r,isFunction as s,isUndefined as o}from"@andrewcaires/utils.js";import n from"cors";import E,{Router as i,json as _,urlencoded as p}from"express";import{existsSync as h}from"fs";import*as a from"http";import*as T from"https";import{Server as u}from"net";import{resolve as O}from"path";function R(t,e,r,s){return new(r||(r=Promise))((function(o,n){function E(t){try{_(s.next(t))}catch(t){n(t)}}function i(t){try{_(s.throw(t))}catch(t){n(t)}}function _(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(E,i)}_((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const c=t(),N=(t,r,s)=>{e(r)&&(r=r.constructor);const o=c(r);return o[t]||(o[t]=s),o[t]};class d{}d.CONTINUE=100,d.SWITCHING_PROTOCOLS=101,d.PROCESSING=102,d.OK=200,d.CREATED=201,d.ACCEPTED=202,d.NON_AUTHORITATIVE_INFORMATION=203,d.NO_CONTENT=204,d.RESET_CONTENT=205,d.PARTIAL_CONTENT=206,d.MULTI_STATUS=207,d.ALREADY_REPORTED=208,d.IM_USED=226,d.MULTIPLE_CHOICES=300,d.MOVED_PERMANENTLY=301,d.FOUND=302,d.SEE_OTHER=303,d.NOT_MODIFIED=304,d.USE_PROXY=305,d.TEMPORARY_REDIRECT=307,d.PERMANENT_REDIRECT=308,d.BAD_REQUEST=400,d.UNAUTHORIZED=401,d.PAYMENT_REQUIRED=402,d.FORBIDDEN=403,d.NOT_FOUND=404,d.METHOD_NOT_ALLOWED=405,d.NOT_ACCEPTABLE=406,d.PROXY_AUTHENTICATION_REQUIRED=407,d.REQUEST_TIMEOUT=408,d.CONFLICT=409,d.GONE=410,d.LENGTH_REQUIRED=411,d.PRECONDITION_FAILED=412,d.PAYLOAD_TOO_LARGE=413,d.REQUEST_URI_TOO_LONG=414,d.UNSUPPORTED_MEDIA_TYPE=415,d.REQUESTED_RANGE_NOT_SATISFIABLE=416,d.EXPECTATION_FAILED=417,d.IM_A_TEAPOT=418,d.MISDIRECTED_REQUEST=421,d.UNPROCESSABLE_ENTITY=422,d.LOCKED=423,d.FAILED_DEPENDENCY=424,d.UPGRADE_REQUIRED=426,d.PRECONDITION_REQUIRED=428,d.TOO_MANY_REQUESTS=429,d.REQUEST_HEADER_FIELDS_TOO_LARGE=431,d.CONNECTION_CLOSED_WITHOUT_RESPONSE=444,d.UNAVAILABLE_FOR_LEGAL_REASONS=451,d.CLIENT_CLOSED_REQUEST=499,d.INTERNAL_SERVER_ERROR=500,d.NOT_IMPLEMENTED=501,d.BAD_GATEWAY=502,d.SERVICE_UNAVAILABLE=503,d.GATEWAY_TIMEOUT=504,d.HTTP_VERSION_NOT_SUPPORTED=505,d.VARIANT_ALSO_NEGOCIATES=506,d.INSUFFICIENT_STORAGE=507,d.LOOP_DETECTED=508,d.NOT_EXTENDED=510,d.NETWORK_AUTHENTICATION_REQUIRED=511,d.NETWORK_CONNECTION_TIMEOUT_ERROR=599;class A{static success(t,e){return t.status(d.OK).json({message:e})}static data(t,e){return t.status(d.OK).json(Object.assign({},e))}static error(t,e){return t.status(d.INTERNAL_SERVER_ERROR).json({message:e})}static list(t,e){return t.status(d.OK).json([...e])}static notfound(t,e){return t.status(d.NOT_FOUND).json({message:e})}static validation(t,e){return t.status(d.BAD_REQUEST).json({message:e})}static unauthorized(t,e){return t.status(d.UNAUTHORIZED).json({message:e})}}var I,l;!function(t){t.EXTENDS="__extends__",t.MIDDLEWARE="__middleware__",t.PARAMETERS="__parameters__",t.PATH="__path__",t.ROUTERS="__routers__"}(I||(I={})),function(t){t.ALL="all",t.GET="get",t.POST="post",t.PUT="put",t.HEAD="head",t.DELETE="delete",t.OPTIONS="options",t.PATCH="patch"}(l||(l={}));class S extends r{get instance(){return this._app}get router(){return this._router}get server(){return this._server}constructor(t,e){var r;super(),this._app=E(),this._options={},this._default={cross:!1,hybrid:!1,path:"/",port:3e3},this._router=i(),this._controllers=i(),this._options=Object.assign(Object.assign({},this._default),e),this._app.use(_()),this._app.disable("x-powered-by"),this._app.use(p({extended:!0})),this._options.cross&&this._app.use(n()),this._app.use(this._router);const o=(null===(r=this._options.path)||void 0===r?void 0:r.length)?this._options.path:"/";if(this._app.use(o,this._controllers),this._app.all(o+"/*",((t,e)=>A.notfound(e,"Invalid API"))),this._options.public){const t=O(this._options.public);h(t)&&this._app.use(E.static(t)),this._app.get("*",((e,r)=>{if(!h(t))return A.notfound(r,'File "index.html" not found');r.sendFile(t+"/index.html")}))}t.forEach((t=>{const e=i(),r=this._middlewares(t),o=this._parameters(t);this._extends(t).forEach((t=>{r.push(...this._middlewares(t)),o.push(...this._parameters(t))})),this._routers(t).forEach((n=>{const E=n.propertyKey.toString();if(s(t[E])){if(!s(e[n.method]))return this.error(new Error('Method "'+n.method+'" Not Found.'),"express");const i=this._handles(t,E,r,o);return e[n.method](n.path,...i,((e,r,s)=>t[E](...this._args(e,r,s,this._indexes(E,o)))))}return this.error(new Error('Router "'+t.name+"."+E+'" Not Found.'),"express")})),this._extends(t).forEach((n=>{this._routers(n).forEach((n=>{const E=n.propertyKey.toString();if(s(t[E])){if(!s(e[n.method]))return this.error(new Error('Method "'+n.method+'" Not Found.'),"express");const i=this._handles(t,E,r,o);return e[n.method](n.path,...i,((e,r,s)=>t[E](...this._args(e,r,s,this._indexes(E,o)))))}return this.error(new Error('Router "'+t.constructor.name+"."+E+'" Not Found.'),"express")}))})),this._controllers.use(this._path(t),e)}))}error(t,e){o(e)?console.error(t):console.error(e+":",t)}log(t,e){o(e)?console.error(t):console.error(e+":",t)}_args(t,e,r,s,o){const n=[],E={req:t,res:e,next:r,key:"",app:this,argument:o};return s.forEach((t=>{n[t.parameterIndex]=t.callback(Object.assign(Object.assign({},E),{key:t.key}))})),n}_handles(t,e,r,o){return r.filter((t=>t.propertyKey==e)).map((e=>{if(s(t[e.method])){const r=this._indexes(e.method,o);return(s,o,n)=>t[e.method](...this._args(s,o,n,r,e.argument))}this.error(new Error('Middleware "'+e.method+'" Not Found.'),"express")})).filter(s)}_extends(t){return N(I.EXTENDS,t,[]).reduce(((t,e)=>(t.push(e,...this._extends(e)),t)),[]).filter(((t,e,r)=>r.indexOf(t)===e))}_indexes(t,e){return e.filter((e=>e.propertyKey==t))}_middlewares(t){return[...N(I.MIDDLEWARE,t,[])].reverse()}_parameters(t){return N(I.PARAMETERS,t,[])}_path(t){return N(I.PATH,t,"/")}_routers(t){return N(I.ROUTERS,t,[])}listen(){return R(this,void 0,void 0,(function*(){if(this._options.cert&&this._options.key||(this._server=a.createServer(this._app),this._server.listen(this._options.port,(()=>this.log("Server started on port "+this._options.port+".","express")))),!this._server){const t=a.createServer(((t,e)=>{const r=80==this._options.port?":80":"";e.writeHead(301,{Location:"https://"+t.headers.host+r+t.url}),e.end()})),e=T.createServer({key:this._options.key,cert:this._options.cert},this._app);if(this._options.hybrid){new u((r=>{r.once("data",(s=>{r.pause(),r.unshift(s),(22===s[0]?e:t).emit("connection",r),process.nextTick((()=>r.resume()))}))})).listen(this._options.port,(()=>this.log("Server started on port "+this._options.port+".","express"))),this._server=e}this._server||(443==this._options.port&&t.listen(80,(()=>this.log("Server started on port 80.","express"))),e.listen(this._options.port,(()=>this.log("Server started on port "+this._options.port+".","express"))),this._server=e)}}))}}const D=t=>e=>{N(I.PATH,e,(null==t?void 0:t.length)?t:"/")},m=t=>e=>{N(I.EXTENDS,e,[]).push(t)},U=t=>e=>(r,s)=>{N(I.ROUTERS,r,[]).push({method:t,path:(null==e?void 0:e.length)?e:"/",propertyKey:s})},f=U(l.ALL),L=U(l.GET),P=U(l.POST),C=U(l.PUT),y=U(l.DELETE),g=U(l.PATCH),x=U(l.HEAD),v=U(l.OPTIONS),M=(t,e)=>(r,s)=>{N(I.MIDDLEWARE,r,[]).push({method:t,argument:e,propertyKey:s})},F=t=>e=>(r,s,o)=>{N(I.PARAMETERS,r,[]).push({callback:t,key:e,propertyKey:s,parameterIndex:o})},H=(t,e)=>o(e)?t:t[e],k=F((({app:t})=>t)),w=F((({argument:t})=>t)),G=F((({req:t,key:e})=>H(t.body,e))),Q=F((({req:t,key:e})=>H(t.cookies,e))),b=F((({req:t,key:e})=>H(t.headers,e))),K=F((({next:t})=>t)),j=F((({req:t,key:e})=>H(t.params,e))),Y=F((({req:t,key:e})=>H(t.query,e))),W=F((({req:t,key:e})=>H(t,e))),B=W,V=F((({res:t})=>t)),q=V;export{f as All,k as App,S as Application,w as Argument,G as Body,D as Controller,Q as Cookies,y as Delete,m as Extends,L as Get,x as Head,b as Headers,N as Metadata,I as MetadataKeys,l as Methods,M as Middleware,K as Next,v as Options,j as Params,g as Patch,P as Post,C as Put,Y as Query,B as Req,W as Request,q as Res,V as Response,A as Responses,d as Status,U as methodFactory,F as parameterFactory};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andrewcaires/express",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Decorators for express",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "types": "./dist/index.d.ts",
@@ -35,27 +35,26 @@
35
35
  },
36
36
  "homepage": "https://github.com/andrewcaires/npm/tree/main/api#readme",
37
37
  "dependencies": {
38
- "@andrewcaires/utils.js": "^0.2.10",
38
+ "@andrewcaires/utils.js": "^0.2.20",
39
39
  "cors": "^2.8.5",
40
40
  "express": "^4.18.2",
41
- "multer": "^1.4.5-lts.1",
42
- "reflect-metadata": "^0.1.13"
41
+ "multer": "^1.4.5-lts.1"
43
42
  },
44
43
  "devDependencies": {
45
- "@rollup/plugin-commonjs": "^24.0.1",
46
- "@rollup/plugin-terser": "^0.4.0",
47
- "@rollup/plugin-typescript": "^11.0.0",
44
+ "@rollup/plugin-commonjs": "^25.0.4",
45
+ "@rollup/plugin-terser": "^0.4.3",
46
+ "@rollup/plugin-typescript": "^11.1.2",
48
47
  "@types/cors": "^2.8.13",
49
48
  "@types/express": "^4.17.17",
50
49
  "@types/mime-types": "^2.1.1",
51
50
  "@types/multer": "^1.4.7",
52
- "@types/node": "^18.14.6",
53
- "@typescript-eslint/eslint-plugin": "^5.54.1",
54
- "@typescript-eslint/parser": "^5.54.1",
55
- "eslint": "^8.35.0",
56
- "rollup-plugin-dts": "^5.2.0",
51
+ "@types/node": "^20.5.3",
52
+ "@typescript-eslint/eslint-plugin": "^6.4.1",
53
+ "@typescript-eslint/parser": "^6.4.1",
54
+ "eslint": "^8.47.0",
55
+ "rollup-plugin-dts": "^6.0.0",
57
56
  "ts-node": "^10.9.1",
58
57
  "ts-node-dev": "^2.0.0",
59
- "tslib": "^2.5.0"
58
+ "tslib": "^2.6.2"
60
59
  }
61
- }
60
+ }