@andrewcaires/express 1.0.3 → 1.0.5
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 +16 -10
- package/dist/index.esm.js +2 -2
- package/package.json +5 -6
package/dist/index.cjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @andrewcaires/express v1.0.
|
|
2
|
+
* @andrewcaires/express v1.0.5
|
|
3
3
|
* Decorators for express
|
|
4
4
|
* (c) 2023 Andrew Caires
|
|
5
5
|
* @license: MIT
|
|
6
6
|
*/
|
|
7
|
-
"use strict";
|
|
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 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 u(e,t,s,r){return new(s||(s=Promise))((function(o,n){function i(e){try{E(r.next(e))}catch(e){n(e)}}function a(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(i,a)}E((r=r.apply(e,t||[])).next())}))}exports.MetadataKeys=void 0,(_=exports.MetadataKeys||(exports.MetadataKeys={})).EXTENDS="__express_extends__",_.MIDDLEWARE="__express_middleware__",_.PATH="__express_path__",_.ROUTERS="__express_routers__",_.PARAMETERS="__express_parameters__";const d=e.cache(),T=(t,s,r)=>{e.isObject(s)&&(s=s.constructor);const o=d(s);return o[t]||(o[t]=r),o[t]};class c{}c.CONTINUE=100,c.SWITCHING_PROTOCOLS=101,c.PROCESSING=102,c.OK=200,c.CREATED=201,c.ACCEPTED=202,c.NON_AUTHORITATIVE_INFORMATION=203,c.NO_CONTENT=204,c.RESET_CONTENT=205,c.PARTIAL_CONTENT=206,c.MULTI_STATUS=207,c.ALREADY_REPORTED=208,c.IM_USED=226,c.MULTIPLE_CHOICES=300,c.MOVED_PERMANENTLY=301,c.FOUND=302,c.SEE_OTHER=303,c.NOT_MODIFIED=304,c.USE_PROXY=305,c.TEMPORARY_REDIRECT=307,c.PERMANENT_REDIRECT=308,c.BAD_REQUEST=400,c.UNAUTHORIZED=401,c.PAYMENT_REQUIRED=402,c.FORBIDDEN=403,c.NOT_FOUND=404,c.METHOD_NOT_ALLOWED=405,c.NOT_ACCEPTABLE=406,c.PROXY_AUTHENTICATION_REQUIRED=407,c.REQUEST_TIMEOUT=408,c.CONFLICT=409,c.GONE=410,c.LENGTH_REQUIRED=411,c.PRECONDITION_FAILED=412,c.PAYLOAD_TOO_LARGE=413,c.REQUEST_URI_TOO_LONG=414,c.UNSUPPORTED_MEDIA_TYPE=415,c.REQUESTED_RANGE_NOT_SATISFIABLE=416,c.EXPECTATION_FAILED=417,c.IM_A_TEAPOT=418,c.MISDIRECTED_REQUEST=421,c.UNPROCESSABLE_ENTITY=422,c.LOCKED=423,c.FAILED_DEPENDENCY=424,c.UPGRADE_REQUIRED=426,c.PRECONDITION_REQUIRED=428,c.TOO_MANY_REQUESTS=429,c.REQUEST_HEADER_FIELDS_TOO_LARGE=431,c.CONNECTION_CLOSED_WITHOUT_RESPONSE=444,c.UNAVAILABLE_FOR_LEGAL_REASONS=451,c.CLIENT_CLOSED_REQUEST=499,c.INTERNAL_SERVER_ERROR=500,c.NOT_IMPLEMENTED=501,c.BAD_GATEWAY=502,c.SERVICE_UNAVAILABLE=503,c.GATEWAY_TIMEOUT=504,c.HTTP_VERSION_NOT_SUPPORTED=505,c.VARIANT_ALSO_NEGOCIATES=506,c.INSUFFICIENT_STORAGE=507,c.LOOP_DETECTED=508,c.NOT_EXTENDED=510,c.NETWORK_AUTHENTICATION_REQUIRED=511,c.NETWORK_CONNECTION_TIMEOUT_ERROR=599;class O{static success(e,t){return e.status(c.OK).json({message:t})}static data(e,t){return e.status(c.OK).json(Object.assign({},t))}static error(e,t){return e.status(c.INTERNAL_SERVER_ERROR).json({message:t})}static list(e,t){return e.status(c.OK).json([...t])}static notfound(e,t){return e.status(c.NOT_FOUND).json({message:t})}static validation(e,t){return e.status(c.BAD_REQUEST).json({message:t})}static unauthorized(e,t){return e.status(c.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 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 E=(null===(i=this._options.path)||void 0===i?void 0:i.length)?this._options.path:"/";if(this._app.use(E,this._controllers),this._app.all(E+"/*",((e,t)=>O.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 O.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.name.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.name.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.index]=e.callback(Object.assign(Object.assign({},i),{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)}_extends(e){return T(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.name==e))}_middlewares(e){return[...T(exports.MetadataKeys.MIDDLEWARE,e,[])].reverse()}_parameters(e){return T(exports.MetadataKeys.PARAMETERS,e,[])}_path(e){return T(exports.MetadataKeys.PATH,e,"/")}_routers(e){return T(exports.MetadataKeys.ROUTERS,e,[])}listen(){return u(this,void 0,void 0,(function*(){if(this._options.cert&&this._options.key||(this._server=p.createServer(this._app),this._server.listen(this._options.port,(()=>this.log("Server started on port "+this._options.port+".","express")))),!this._server){const e=p.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 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)}}))}}var x;exports.Methods=void 0,(x=exports.Methods||(exports.Methods={})).ALL="all",x.GET="get",x.POST="post",x.PUT="put",x.HEAD="head",x.DELETE="delete",x.OPTIONS="options",x.PATCH="patch";const N=e=>t=>(s,r)=>{T(exports.MetadataKeys.ROUTERS,s,[]).push({path:(null==t?void 0:t.length)?t:"/",method:e,name:r})},A=N(exports.Methods.ALL),l=N(exports.Methods.GET),I=N(exports.Methods.POST),S=N(exports.Methods.PUT),D=N(exports.Methods.DELETE),M=N(exports.Methods.PATCH),P=N(exports.Methods.HEAD),U=N(exports.Methods.OPTIONS),m=e=>t=>(s,r,o)=>{T(exports.MetadataKeys.PARAMETERS,s,[]).push({callback:e,index:o,key:t,name:r})},f=(t,s)=>e.isUndefined(s)?t:t[s],L=m((({app:e})=>e)),y=m((({argument:e})=>e)),C=m((({req:e,key:t})=>f(e.body,t))),v=m((({req:e,key:t})=>f(e.cookies,t))),g=m((({req:e,key:t})=>f(e.headers,t))),F=m((({next:e})=>e)),H=m((({req:e,key:t})=>f(e.params,t))),b=m((({req:e,key:t})=>f(e.query,t))),j=m((({req:e,key:t})=>f(e,t))),K=j,k=m((({res:e})=>e)),w=k;exports.All=A,exports.App=L,exports.Application=R,exports.Argument=y,exports.Body=C,exports.Controller=e=>t=>{T(exports.MetadataKeys.PATH,t,(null==e?void 0:e.length)?e:"/")},exports.Cookies=v,exports.Delete=D,exports.Extends=e=>t=>{T(exports.MetadataKeys.EXTENDS,t,[]).push(e)},exports.Get=l,exports.Head=P,exports.Headers=g,exports.Metadata=T,exports.Middleware=(e,t)=>(s,r)=>{T(exports.MetadataKeys.MIDDLEWARE,s,[]).push({name:r,method:e,argument:t})},exports.Next=F,exports.Options=U,exports.Params=H,exports.Patch=M,exports.Post=I,exports.Put=S,exports.Query=b,exports.Req=K,exports.Request=j,exports.Res=w,exports.Response=k,exports.Responses=O,exports.Status=c,exports.methodFactory=N,exports.parameterFactory=m;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @andrewcaires/express v1.0.
|
|
2
|
+
* @andrewcaires/express v1.0.5
|
|
3
3
|
* Decorators for express
|
|
4
4
|
* (c) 2023 Andrew Caires
|
|
5
5
|
* @license: MIT
|
|
@@ -32,15 +32,16 @@ declare class Application extends EventEmitter {
|
|
|
32
32
|
private _options;
|
|
33
33
|
private _default;
|
|
34
34
|
private readonly _router;
|
|
35
|
-
private readonly
|
|
35
|
+
private readonly _controllers;
|
|
36
36
|
get instance(): Express;
|
|
37
37
|
get router(): Router;
|
|
38
38
|
get server(): http.Server | https.Server | undefined;
|
|
39
|
-
constructor(
|
|
39
|
+
constructor(controllers: Array<object>, options?: IOptions);
|
|
40
40
|
error(error: any, source?: string): void;
|
|
41
41
|
log(message: string, source?: string): void;
|
|
42
42
|
private _args;
|
|
43
43
|
private _handles;
|
|
44
|
+
private _extends;
|
|
44
45
|
private _indexes;
|
|
45
46
|
private _middlewares;
|
|
46
47
|
private _parameters;
|
|
@@ -51,13 +52,16 @@ declare class Application extends EventEmitter {
|
|
|
51
52
|
|
|
52
53
|
declare const Controller: (path?: string) => ClassDecorator;
|
|
53
54
|
|
|
55
|
+
declare const Extends: (type: any) => ClassDecorator;
|
|
56
|
+
|
|
54
57
|
declare enum MetadataKeys {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
EXTENDS = "__express_extends__",
|
|
59
|
+
MIDDLEWARE = "__express_middleware__",
|
|
60
|
+
PATH = "__express_path__",
|
|
61
|
+
ROUTERS = "__express_routers__",
|
|
62
|
+
PARAMETERS = "__express_parameters__"
|
|
59
63
|
}
|
|
60
|
-
declare const Metadata: (metadataKey: MetadataKeys, target: any,
|
|
64
|
+
declare const Metadata: <T = any>(metadataKey: MetadataKeys, target: any, metadataValue: T) => T;
|
|
61
65
|
|
|
62
66
|
interface IRouter {
|
|
63
67
|
path: string;
|
|
@@ -65,6 +69,7 @@ interface IRouter {
|
|
|
65
69
|
name: string | symbol;
|
|
66
70
|
}
|
|
67
71
|
declare enum Methods {
|
|
72
|
+
ALL = "all",
|
|
68
73
|
GET = "get",
|
|
69
74
|
POST = "post",
|
|
70
75
|
PUT = "put",
|
|
@@ -74,6 +79,7 @@ declare enum Methods {
|
|
|
74
79
|
PATCH = "patch"
|
|
75
80
|
}
|
|
76
81
|
declare const methodFactory: (method: Methods) => (path?: string) => MethodDecorator;
|
|
82
|
+
declare const All: (path?: string) => MethodDecorator;
|
|
77
83
|
declare const Get: (path?: string) => MethodDecorator;
|
|
78
84
|
declare const Post: (path?: string) => MethodDecorator;
|
|
79
85
|
declare const Put: (path?: string) => MethodDecorator;
|
|
@@ -92,7 +98,7 @@ declare const Middleware: (method: string, argument?: any) => MethodDecorator;
|
|
|
92
98
|
interface IParameter {
|
|
93
99
|
callback: TypeCallbackFunction;
|
|
94
100
|
index: number;
|
|
95
|
-
key
|
|
101
|
+
key?: string;
|
|
96
102
|
name: string | symbol;
|
|
97
103
|
}
|
|
98
104
|
declare const parameterFactory: (callback: TypeCallbackFunction) => (key?: string) => ParameterDecorator;
|
|
@@ -186,4 +192,4 @@ declare class Status {
|
|
|
186
192
|
static readonly NETWORK_CONNECTION_TIMEOUT_ERROR = 599;
|
|
187
193
|
}
|
|
188
194
|
|
|
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 };
|
|
195
|
+
export { All, App, Application, Argument, Body, Controller, Cookies, Delete, Extends, 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 };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @andrewcaires/express v1.0.
|
|
2
|
+
* @andrewcaires/express v1.0.5
|
|
3
3
|
* Decorators for express
|
|
4
4
|
* (c) 2023 Andrew Caires
|
|
5
5
|
* @license: MIT
|
|
6
6
|
*/
|
|
7
|
-
import
|
|
7
|
+
import{cache as t,isObject as e,EventEmitter as s,isFunction as r,isUndefined as o}from"@andrewcaires/utils.js";import n from"cors";import i,{Router as E,json as _,urlencoded as a}from"express";import{existsSync as h}from"fs";import*as T from"http";import*as p from"https";import{Server as u}from"net";import{resolve as O}from"path";function R(t,e,s,r){return new(s||(s=Promise))((function(o,n){function i(t){try{_(r.next(t))}catch(t){n(t)}}function E(t){try{_(r.throw(t))}catch(t){n(t)}}function _(t){var e;t.done?o(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(i,E)}_((r=r.apply(t,e||[])).next())}))}var c;!function(t){t.EXTENDS="__express_extends__",t.MIDDLEWARE="__express_middleware__",t.PATH="__express_path__",t.ROUTERS="__express_routers__",t.PARAMETERS="__express_parameters__"}(c||(c={}));const N=t(),d=(t,s,r)=>{e(s)&&(s=s.constructor);const o=N(s);return o[t]||(o[t]=r),o[t]};class A{}A.CONTINUE=100,A.SWITCHING_PROTOCOLS=101,A.PROCESSING=102,A.OK=200,A.CREATED=201,A.ACCEPTED=202,A.NON_AUTHORITATIVE_INFORMATION=203,A.NO_CONTENT=204,A.RESET_CONTENT=205,A.PARTIAL_CONTENT=206,A.MULTI_STATUS=207,A.ALREADY_REPORTED=208,A.IM_USED=226,A.MULTIPLE_CHOICES=300,A.MOVED_PERMANENTLY=301,A.FOUND=302,A.SEE_OTHER=303,A.NOT_MODIFIED=304,A.USE_PROXY=305,A.TEMPORARY_REDIRECT=307,A.PERMANENT_REDIRECT=308,A.BAD_REQUEST=400,A.UNAUTHORIZED=401,A.PAYMENT_REQUIRED=402,A.FORBIDDEN=403,A.NOT_FOUND=404,A.METHOD_NOT_ALLOWED=405,A.NOT_ACCEPTABLE=406,A.PROXY_AUTHENTICATION_REQUIRED=407,A.REQUEST_TIMEOUT=408,A.CONFLICT=409,A.GONE=410,A.LENGTH_REQUIRED=411,A.PRECONDITION_FAILED=412,A.PAYLOAD_TOO_LARGE=413,A.REQUEST_URI_TOO_LONG=414,A.UNSUPPORTED_MEDIA_TYPE=415,A.REQUESTED_RANGE_NOT_SATISFIABLE=416,A.EXPECTATION_FAILED=417,A.IM_A_TEAPOT=418,A.MISDIRECTED_REQUEST=421,A.UNPROCESSABLE_ENTITY=422,A.LOCKED=423,A.FAILED_DEPENDENCY=424,A.UPGRADE_REQUIRED=426,A.PRECONDITION_REQUIRED=428,A.TOO_MANY_REQUESTS=429,A.REQUEST_HEADER_FIELDS_TOO_LARGE=431,A.CONNECTION_CLOSED_WITHOUT_RESPONSE=444,A.UNAVAILABLE_FOR_LEGAL_REASONS=451,A.CLIENT_CLOSED_REQUEST=499,A.INTERNAL_SERVER_ERROR=500,A.NOT_IMPLEMENTED=501,A.BAD_GATEWAY=502,A.SERVICE_UNAVAILABLE=503,A.GATEWAY_TIMEOUT=504,A.HTTP_VERSION_NOT_SUPPORTED=505,A.VARIANT_ALSO_NEGOCIATES=506,A.INSUFFICIENT_STORAGE=507,A.LOOP_DETECTED=508,A.NOT_EXTENDED=510,A.NETWORK_AUTHENTICATION_REQUIRED=511,A.NETWORK_CONNECTION_TIMEOUT_ERROR=599;class I{static success(t,e){return t.status(A.OK).json({message:e})}static data(t,e){return t.status(A.OK).json(Object.assign({},e))}static error(t,e){return t.status(A.INTERNAL_SERVER_ERROR).json({message:e})}static list(t,e){return t.status(A.OK).json([...e])}static notfound(t,e){return t.status(A.NOT_FOUND).json({message:e})}static validation(t,e){return t.status(A.BAD_REQUEST).json({message:e})}static unauthorized(t,e){return t.status(A.UNAUTHORIZED).json({message:e})}}class l extends s{get instance(){return this._app}get router(){return this._router}get server(){return this._server}constructor(t,e){var s;super(),this._app=i(),this._options={},this._default={cross:!1,hybrid:!1,path:"/",port:3e3},this._router=E(),this._controllers=E(),this._options=Object.assign(Object.assign({},this._default),e),this._app.use(_()),this._app.disable("x-powered-by"),this._app.use(a({extended:!0})),this._options.cross&&this._app.use(n()),this._app.use(this._router);const o=(null===(s=this._options.path)||void 0===s?void 0:s.length)?this._options.path:"/";if(this._app.use(o,this._controllers),this._app.all(o+"/*",((t,e)=>I.notfound(e,"Invalid API"))),this._options.public){const t=O(this._options.public);h(t)&&this._app.use(i.static(t)),this._app.get("*",((e,s)=>{if(!h(t))return I.notfound(s,'File "index.html" not found');s.sendFile(t+"/index.html")}))}t.forEach((t=>{const e=E(),s=this._middlewares(t),o=this._parameters(t);this._extends(t).forEach((t=>{s.push(...this._middlewares(t)),o.push(...this._parameters(t))})),this._routers(t).forEach((n=>{const i=n.name.toString();if(r(t[i])){if(!r(e[n.method]))return this.error(new Error('Method "'+n.method+'" Not Found.'),"express");const E=this._handles(t,i,s,o);return e[n.method](n.path,...E,((e,s,r)=>t[i](...this._args(e,s,r,this._indexes(i,o)))))}return this.error(new Error('Router "'+t.name+"."+i+'" Not Found.'),"express")})),this._extends(t).forEach((n=>{this._routers(n).forEach((n=>{const i=n.name.toString();if(r(t[i])){if(!r(e[n.method]))return this.error(new Error('Method "'+n.method+'" Not Found.'),"express");const E=this._handles(t,i,s,o);return e[n.method](n.path,...E,((e,s,r)=>t[i](...this._args(e,s,r,this._indexes(i,o)))))}return this.error(new Error('Router "'+t.constructor.name+"."+i+'" 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,s,r,o){const n=[],i={req:t,res:e,next:s,key:"",app:this,argument:o};return r.forEach((t=>{n[t.index]=t.callback(Object.assign(Object.assign({},i),{key:t.key}))})),n}_handles(t,e,s,o){return s.filter((t=>t.name==e)).map((e=>{if(r(t[e.method])){const s=this._indexes(e.method,o);return(r,o,n)=>t[e.method](...this._args(r,o,n,s,e.argument))}this.error(new Error('Middleware "'+e.method+'" Not Found.'),"express")})).filter(r)}_extends(t){return d(c.EXTENDS,t,[]).reduce(((t,e)=>(t.push(e,...this._extends(e)),t)),[]).filter(((t,e,s)=>s.indexOf(t)===e))}_indexes(t,e){return e.filter((e=>e.name==t))}_middlewares(t){return[...d(c.MIDDLEWARE,t,[])].reverse()}_parameters(t){return d(c.PARAMETERS,t,[])}_path(t){return d(c.PATH,t,"/")}_routers(t){return d(c.ROUTERS,t,[])}listen(){return R(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("Server started on port "+this._options.port+".","express")))),!this._server){const t=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=p.createServer({key:this._options.key,cert:this._options.cert},this._app);if(this._options.hybrid){new u((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=>{d(c.PATH,e,(null==t?void 0:t.length)?t:"/")},S=t=>e=>{d(c.EXTENDS,e,[]).push(t)};var m;!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"}(m||(m={}));const U=t=>e=>(s,r)=>{d(c.ROUTERS,s,[]).push({path:(null==e?void 0:e.length)?e:"/",method:t,name:r})},L=U(m.ALL),f=U(m.GET),P=U(m.POST),C=U(m.PUT),x=U(m.DELETE),g=U(m.PATCH),v=U(m.HEAD),M=U(m.OPTIONS),F=(t,e)=>(s,r)=>{d(c.MIDDLEWARE,s,[]).push({name:r,method:t,argument:e})},y=t=>e=>(s,r,o)=>{d(c.PARAMETERS,s,[]).push({callback:t,index:o,key:e,name:r})},H=(t,e)=>o(e)?t:t[e],k=y((({app:t})=>t)),w=y((({argument:t})=>t)),G=y((({req:t,key:e})=>H(t.body,e))),Q=y((({req:t,key:e})=>H(t.cookies,e))),b=y((({req:t,key:e})=>H(t.headers,e))),j=y((({next:t})=>t)),Y=y((({req:t,key:e})=>H(t.params,e))),W=y((({req:t,key:e})=>H(t.query,e))),B=y((({req:t,key:e})=>H(t,e))),V=B,q=y((({res:t})=>t)),K=q;export{L as All,k as App,l as Application,w as Argument,G as Body,D as Controller,Q as Cookies,x as Delete,S as Extends,f as Get,v as Head,b as Headers,d as Metadata,c as MetadataKeys,m as Methods,F as Middleware,j as Next,M as Options,Y as Params,g as Patch,P as Post,C as Put,W as Query,V as Req,B as Request,K as Res,q as Response,I as Responses,A as Status,U as methodFactory,y as parameterFactory};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andrewcaires/express",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Decorators for express",
|
|
5
5
|
"main": "./dist/index.cjs.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -35,11 +35,10 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://github.com/andrewcaires/npm/tree/main/api#readme",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@andrewcaires/utils.js": "^0.2.
|
|
38
|
+
"@andrewcaires/utils.js": "^0.2.11",
|
|
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
44
|
"@rollup/plugin-commonjs": "^24.0.1",
|
|
@@ -49,10 +48,10 @@
|
|
|
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.
|
|
51
|
+
"@types/node": "^18.15.0",
|
|
53
52
|
"@typescript-eslint/eslint-plugin": "^5.54.1",
|
|
54
53
|
"@typescript-eslint/parser": "^5.54.1",
|
|
55
|
-
"eslint": "^8.
|
|
54
|
+
"eslint": "^8.36.0",
|
|
56
55
|
"rollup-plugin-dts": "^5.2.0",
|
|
57
56
|
"ts-node": "^10.9.1",
|
|
58
57
|
"ts-node-dev": "^2.0.0",
|