@virid/express 0.2.0 → 0.2.2
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 +7 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -29
- package/dist/index.js.map +1 -1
- package/package.json +3 -4
package/dist/index.js
CHANGED
|
@@ -1,36 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @virid/express v0.
|
|
2
|
+
* @virid/express v0.2.2
|
|
3
3
|
* Add express functionality to virid
|
|
4
4
|
*/
|
|
5
|
-
var
|
|
5
|
+
var de=Object.defineProperty;var Me=(t,e,s)=>e in t?de(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var o=(t,e)=>de(t,"name",{value:e,configurable:!0});var p=(t,e,s)=>Me(t,typeof e!="symbol"?e+"":e,s);import{MessageWriter as Te}from"@virid/core";import{MessageRegistry as Oe,MessageWriter as Ce}from"@virid/core";import{BaseMessage as we,MessageWriter as T}from"@virid/core";import{MessageWriter as Ee}from"@virid/core";var W=class W{constructor(e,s,r,n,d){p(this,"id");p(this,"req");p(this,"res");p(this,"timestamp");p(this,"route");p(this,"rc",0);p(this,"isClosed",!1);this.id=e,this.req=s,this.res=r,this.timestamp=n,this.route=d}inc(){this.rc++}dec(){this.rc--,this.rc===0&&this.tryFinalize()}tryFinalize(){if(this.res.writableEnded||this.isClosed)return;this.isClosed=!0;let e=`[Virid Express] Request Orphaned: The connection was closed because all systems finished execution without sending a response.
|
|
6
6
|
Route: ${this.route}
|
|
7
|
-
Uptime: ${Date.now()-this.timestamp}ms`;
|
|
8
|
-
|
|
9
|
-
MessageName: ${t.message.constructor.name}
|
|
10
|
-
MessageData: ${JSON.stringify(t.message)}`))}catch(s){m.error(s,`[Virid Dispatcher]: Sync System Error.
|
|
11
|
-
SystemLocation: ${t.hookContext.context.targetClass.name}.${t.hookContext.context.methodName}
|
|
12
|
-
MessageName: ${t.message.constructor.name}
|
|
13
|
-
MessageData: ${JSON.stringify(t.message)}`)}}prepareSnapshot(){this.eventHub.flip();let e=new Set(this.dirtySignalTypes),t=[...this.eventQueue];return this.dirtySignalTypes.clear(),this.eventQueue=[],{signalSnapshot:e,eventSnapshot:t}}clear(e,t){let s=new Set(t);e.forEach(i=>s.add(i.constructor)),this.eventHub.clearSignals(s),this.eventHub.clearEvents()}executeTickHooks(e){let t={tick:this.globalTick,timestamp:Date.now(),payload:this.tickPayload};e.forEach(s=>s(t))}},n(B,"z"),B);c(tt,"Dispatcher");var wt=tt,N,rt=(N=class{constructor(e,t,s,i){l(this,"fn"),l(this,"priority"),l(this,"message"),l(this,"hookContext"),this.fn=e,this.priority=t,this.message=s,this.hookContext=i}triggerHooks(e){let t=Array.isArray(this.message)?this.message[0]:this.message;if(t){for(let s of e)if(t instanceof s.type)try{let i=s.handler(this.message,this.hookContext);i instanceof Promise&&i.catch(o=>{m.error(o,`[Virid Hook] Async Hook Error:
|
|
14
|
-
It is prohibited to use asynchronous hooks within Hook:
|
|
15
|
-
${s.type.name}`)})}catch(i){m.error(i,`[Virid Hook] Hook Execute Failed:
|
|
16
|
-
Triggered by: ${t.constructor.name}
|
|
17
|
-
Registered type: ${s.type.name}`)}}}execute(e,t){this.triggerHooks(e);let s=c(()=>this.triggerHooks(t),"runAfter");try{let i=this.fn(this.message);return i instanceof Promise?i.finally(()=>s()):(s(),i)}catch(i){throw s(),i}}},n(N,"F"),N);c(rt,"ExecutionTask");var We=rt,q,st=(q=class{constructor(){l(this,"signalActive",new Map),l(this,"signalStaging",new Map),l(this,"eventActive",[]),l(this,"eventStaging",[])}push(e){if(e instanceof Ne){let t=e.constructor;this.signalStaging.has(t)||this.signalStaging.set(t,[]),this.signalStaging.get(t).push(e)}else e instanceof W?this.eventStaging.push(e):m.error(new Error(`[Virid Message] Invalid Message:
|
|
18
|
-
${e.constructor.name} must extend SingleMessage or EventMessage`))}flip(){this.signalActive=this.signalStaging,this.signalStaging=new Map,this.eventActive=this.eventStaging,this.eventStaging=[]}peekSignal(e){return this.signalActive.get(e)||[]}getEventStream(){return this.eventActive}peekEventAt(e){return this.eventActive[e]}clearSignals(e){e.forEach(t=>this.signalActive.delete(t))}clearEvents(){this.eventActive=[]}reset(){this.signalActive.clear(),this.signalStaging.clear(),this.eventActive=[],this.eventStaging=[]}},n(q,"U"),q);c(st,"EventHub");var vt=st,_,nt=(_=class{constructor(){l(this,"systemTaskMap",new Map)}register(e,t,s=0){let i=this.systemTaskMap.get(e)||[];if(i.findIndex(o=>o.fn===t)===-1)i.push({fn:t,priority:s}),i.sort((o,a)=>a.priority-o.priority),this.systemTaskMap.set(e,i);else{let o=t.name||"Anonymous";return m.error(new Error(`[Virid Error] System Already Registered:
|
|
19
|
-
Class ${e.name}
|
|
20
|
-
Function ${o}`)),()=>{}}return()=>{let o=this.systemTaskMap.get(e);if(o){let a=o.findIndex(d=>d.fn===t);a!==-1&&(o.splice(a,1),o.length===0&&this.systemTaskMap.delete(e))}}}},n(_,"J"),_);c(nt,"MessageRegistry");var St=nt,j,it=(j=class{constructor(){l(this,"eventHub",new vt),l(this,"dispatcher",new wt(this.eventHub)),l(this,"registry",new St),l(this,"middlewares",[]),Ze(this)}useMiddleware(e,t){this.middlewares.push(e)}onBeforeExecute(e,t,s){this.dispatcher.addBeforeExecute(e,t,s)}onAfterExecute(e,t,s){this.dispatcher.addAfterExecute(e,t,s)}onBeforeTick(e,t){this.dispatcher.addBeforeTick(e,t)}onAfterTick(e,t){this.dispatcher.addAfterTick(e,t)}dispatch(e){if(!(e instanceof se)){m.error(new Error(`[Virid Dispatch] Type Error: Message must be an instance of BaseMessage,message:${e}`));return}this.pipeline(e,()=>{if(!this.registry.systemTaskMap.has(e.constructor)){m.error(new Error(`[Virid Dispatch] No handler for message: ${e.constructor.name}`));return}this.eventHub.push(e),this.dispatcher.markDirty(e),this.dispatcher.tick(this.registry.systemTaskMap)})}pipeline(e,t){let s=0,i=c(()=>{s<this.middlewares.length?this.middlewares[s++](e,i):t()},"next");i()}register(e,t,s=0){return this.registry.register(e,t,s)}},n(j,"Y"),j);c(it,"MessageInternal");var At=it,Q,at=(Q=class{constructor(){l(this,"bindings",new Map),l(this,"singletonInstances",new Map)}bind(e){let t={type:"transient",ctor:e};return this.bindings.set(e,t),{toSelf:c(()=>({inSingletonScope:c(()=>(t.type="singleton",{onActivation:c(s=>{},"onActivation")}),"inSingletonScope")}),"toSelf")}}get(e,t){let s=this.bindings.get(e);if(!s)throw new Error(`[Virid Container] Unbound Constructor: No binding found for ${e.name}`);let i=s.ctor;if(s.type==="singleton"){if(!this.singletonInstances.has(e)){let a=new i,d=t(a);this.singletonInstances.set(e,d)}return this.singletonInstances.get(e)}let o=new i;return t(o)}},n(Q,"q"),Q);c(at,"ViridContainer");var bt=at,p={reset:"\x1B[0m",red:"\x1B[31m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",gray:"\x1B[90m",bold:"\x1B[1m",green:"\x1B[32m"};function Z(r,e,t){let s={params:r,targetClass:Object,methodName:t,originalMethod:e};return e.ccsContext=s,e}n(Z,"K");c(Z,"withContext");var Rt=c(r=>{let e=`${p.green}${p.bold} \u2714 [Virid Info] ${p.reset}`,t=`${p.magenta}${r.context}${p.reset}`;console.log(`${e}${p.gray}Global Info Caught:${p.reset}
|
|
21
|
-
${p.green}Details:${p.reset}`,r.context||"unknown Info")},"globalInfoHandler"),kt=c(r=>{let e=`${p.red}${p.bold} \u2716 [Virid Error] ${p.reset}`,t=`${p.magenta}${r.context}${p.reset}`;console.error(`${e}${p.gray}Global Error Caught:${p.reset}
|
|
22
|
-
${p.red}Context:${p.reset} ${t}
|
|
23
|
-
${p.red}Details:${p.reset}`,r.error||r||"unknown Error")},"globalErrorHandler"),$t=c(r=>{let e=`${p.yellow}${p.bold} \u26A0 [Virid Warn] ${p.reset}`,t=`${p.cyan}${r.context}${p.reset}`;console.warn(`${e}${p.gray}Global Warn Caught:${p.reset}
|
|
24
|
-
${p.yellow}Context:${p.reset} ${t}`)},"globalWarnHandler");function ot(r){r.register(De,Z(De,$t,"GlobalWarnHandler"),-999),r.register(Ie,Z(Ie,kt,"GlobalErrorHandler"),-999),r.register(Be,Z(Be,Rt,"GlobalInfoHandler"),-999),ee=r}n(ot,"se");c(ot,"initializeGlobalSystems");var ee=null,pr=new Proxy({},{get(r,e){return(...t)=>{if(!ee){console.warn(`[Virid Vue] App method "${String(e)}" called before initialization.`);return}let s=ee[e];if(typeof s=="function")return s.apply(ee,t)}}}),Fe=new Set,U,ct=(U=class{constructor(){l(this,"container",new bt),l(this,"messageInternal",new At),l(this,"activationHooks",[])}addActivationHook(e){this.activationHooks.push(e)}get(e){return e.length>0&&m.error(new Error(`[Virid Container] Violation: Component "${e.name}" should not have constructor arguments. Dependency Injection is only allowed in Systems.`)),this.container.get(e,t=>this.handleActivation(t))}handleActivation(e){return e&&this.activationHooks.reduce((t,s)=>{try{let i=s(t);return i===void 0&&m.warn(`[Virid Container] Hook Does Bot Return A Value: Hook "${s.name}" should return a instance to continue.`),i!==void 0?i:t}catch(i){return m.error(i,"[Virid Container] Activation Hook Failed"),t}},e)}bindController(e){return this.container.bind(e).toSelf(),{inSingletonScope:c(()=>({onActivation:c(()=>{},"onActivation")}),"inSingletonScope")}}bindComponent(e){return this.container.bind(e).toSelf().inSingletonScope(),{onActivation:c(()=>{},"onActivation")}}useMiddleware(e,t=!1){this.messageInternal.useMiddleware(e,t)}onBeforeExecute(e,t,s=!1){this.messageInternal.onBeforeExecute(e,t,s)}onAfterExecute(e,t,s=!1){this.messageInternal.onAfterExecute(e,t,s)}onBeforeTick(e,t=!1){this.messageInternal.onBeforeTick(e,t)}onAfterTick(e,t=!1){this.messageInternal.onAfterTick(e,t)}register(e,t,s=0){return this.messageInternal.register(e,t,s)}use(e,t){if(Fe.has(e.name))return m.warn(`[Virid Plugin] Duplicate Installation: Plugin ${e.name} has already been installed.`),this;try{e.install(this,t),Fe.add(e.name)}catch(s){m.error(s,`[Virid Plugin]: Install Failed: ${e.name}`)}return this}},n(U,"Z"),U);c(ct,"ViridApp");var Tt=ct,G=new Tt;G.addActivationHook(re);ot(G);var A={SYSTEM:"virid:core:system",MESSAGE:"virid:core:message",CONTROLLER:"virid:core:controller",COMPONENT:"virid:core:component",SAFE:"virid:core:safe",OBSERVER:"virid:core:observer"},te=c(r=>{r&&(Array.isArray(r)?r:[r]).forEach(e=>{e instanceof se?m.write(e):m.warn("[Virid HandleResult] Invalid Return Type: Must return Message or Message[].")})},"handleResult");function Ct(r={priority:0,messageClass:null}){return(e,t,s)=>{let i=s.value,o=Reflect.getMetadata("design:paramtypes",e,t),a=Reflect.getMetadata(A.MESSAGE,e,t)||null;if(!o){let f=new Error(`[Virid System] System Parameter Loss:
|
|
25
|
-
Unable to recognize system parameters, please confirm if import "reflection-metadata" was introduced at the beginning!`);m.error(f);return}if(o.some(f=>f===void 0)){let f=new Error(`[Virid System] Parameter Metadata Loss in "${t}":
|
|
7
|
+
Uptime: ${Date.now()-this.timestamp}ms`;Ee.error(new Error(e)),this.res.headersSent?this.res.end():this.res.status(500).json({error:"Internal Logic Error",message:"Request processed but no response was returned by any system."})}};o(W,"HttpContext");var P=W,_=class _{constructor(e,s=null,r={}){p(this,"status");p(this,"data");p(this,"headers");this.status=e,this.data=s,this.headers=r}};o(_,"HttpResponse");var u=_,F=class F extends u{constructor(e,s={}){super(200,e,s)}};o(F,"OkResponse");var $=F,X=class X extends u{constructor(e,s={}){super(201,e,s)}};o(X,"CreatedResponse");var V=X,z=class z extends u{constructor(){super(204,null)}};o(z,"NoContentResponse");var b=z,K=class K extends u{constructor(e="Bad Request"){super(400,{error:e})}};o(K,"BadRequestResponse");var N=K,L=class L extends u{constructor(e="Unauthorized"){super(401,{error:e})}};o(L,"UnauthorizedResponse");var D=L,G=class G extends u{constructor(e="Forbidden"){super(403,{error:e})}};o(G,"ForbiddenResponse");var B=G,J=class J extends u{constructor(e="Not Found"){super(404,{error:e})}};o(J,"NotFoundResponse");var Q=J,Z=class Z extends u{constructor(e="Conflict"){super(409,{error:e})}};o(Z,"ConflictResponse");var ce=Z,k=class k extends u{constructor(e){super(422,{errors:e})}};o(k,"UnprocessableEntityResponse");var pe=k,ee=class ee extends u{constructor(e="Internal Server Error"){super(500,{error:e})}};o(ee,"InternalServerErrorResponse");var U=ee,te=class te extends u{constructor(e,s,r={}){super(e,s,r)}};o(te,"CustomResponseResponse");var Y=te,re=class re extends u{constructor(s,r={dotfiles:"allow"}){super(206,r);p(this,"filePath");p(this,"options");this.filePath=s,this.options=r}};o(re,"StreamFileResponse");var A=re,se=class se extends u{constructor(s,r={}){super(r.status||206,{},r.headers);p(this,"stream");p(this,"options");this.stream=s,this.options=r}};o(se,"StreamResponse");var O=se,Ve=o((t,e={})=>new $(t,e),"Ok"),be=o((t,e={})=>new V(t,e),"Created"),Ne=o(()=>new b,"NoContent"),De=o((t="Bad Request")=>new N(t),"BadRequest"),Be=o((t="Unauthorized")=>new D(t),"Unauthorized"),Qe=o((t="Forbidden")=>new B(t),"Forbidden"),Ue=o((t="Not Found")=>new Q(t),"NotFound"),j=o((t="Internal Server Error")=>new U(t),"InternalServerError"),Ye=o((t,e,s={})=>new Y(t,e,s),"CustomResponse"),je=o((t,e)=>new A(t,e),"StreamFile"),We=o((t,e)=>new O(t,e),"Stream"),oe=class oe extends Error{constructor(s,r){super(r);p(this,"status");p(this,"message");this.status=s,this.message=r}};o(oe,"HttpError");var w=oe;var m=new Map;function S(t,e){if(!t){e.dec();return}(Array.isArray(t)?t:[t]).forEach(r=>{r instanceof u?ge(r,e):r instanceof w?(e.res.status(r.status).json(r.message),m.delete(e.id)):r instanceof we?T.write(r):T.warn(`[Virid Express] Invalid Return Type: ${typeof r}. Expected HttpResponse or Message.`)}),e.dec()}o(S,"handleResult");function ge(t,e){let{res:s}=e;if(t.headers&&Object.entries(t.headers).forEach(([r,n])=>s.setHeader(r,n)),t.status&&s.status(t.status),t instanceof A){e.inc(),s.sendFile(t.filePath,t.options,r=>{s.headersSent||T.error(r,`[Virid Express] SteamFile Error: Path: ${t.filePath}`),e.res.end(),m.delete(e.id),e.isClosed=!0,e.dec()});return}if(t instanceof O){let{stream:r}=t;e.inc(),r.pipe(s);let n=o(()=>{m.has(e.id)&&(e.res.end(),m.delete(e.id),e.isClosed=!0,e.dec())},"cleanup");r.on("end",n),r.on("error",d=>{s.headersSent||T.error(d,"[Virid Express] Stream Error"),n()}),r.on("close",n);return}s.status(t.status).json(t.data),m.delete(e.id)}o(ge,"handleHttpResponse");import{MessageWriter as Se}from"@virid/core";function Re(t){let e=parseInt(t,10);if(isNaN(e))throw new w(400,`Validation failed: "${t}" is not a number.`);return e}o(Re,"ParseIntPipe");function ye(t){return t==="true"||t==="1"?!0:t==="false"||t==="0"?!1:!!t}o(ye,"ParseBoolPipe");var C=new Map;C.set(Number,Re);C.set(Boolean,ye);function Ze(t,e){if(C.has(t)){Se.error(new Error(`[Virid Express Pipe] Repeated Pipe: Auto pipe for ${t} has already been registered.`));return}C.set(t,e)}o(Ze,"addAutoPipe");function ne(t){return C.get(t)}o(ne,"getAutoPipe");function ue(t){let e={};if(!t)return e;let s=t.split(";");for(let r of s){let n=r.indexOf("=");if(n===-1)continue;let d=r.substring(0,n).trim();if(!d)continue;let a=r.substring(n+1).trim();a[0]==='"'&&a[a.length-1]==='"'&&(a=a.slice(1,-1));try{e[d]=a.includes("%")?decodeURIComponent(a):a}catch{e[d]=a}}return e}o(ue,"parseRawCookie");import{EventMessage as Ae}from"@virid/core";var ae=class ae extends Ae{constructor(s){super();p(this,"__virid_express_id");this.__virid_express_id=s,m.get(this.__virid_express_id).inc()}get requestId(){return this.__virid_express_id}};o(ae,"HttpRequestMessage");var v=ae;var H=new Oe,I=new Map,Pe=0;function le(t){for(let[e,s]of H.systemTaskMap.entries())for(let r of s)t.register(e,r.fn,r.priority);H.systemTaskMap.clear()}o(le,"registerHttpSystem");function fe(t){for(let[e,s]of I.entries()){let{method:r,path:n,httpMessage:d}=s,a=r.toLowerCase();t[a](n,(h,f)=>{let c=Pe++>>>0;m.set(c,new P(c,h,f,Date.now(),n));let R=new d(c);f.once("finish",()=>m.delete(c)),f.once("close",()=>m.delete(c)),Ce.write(R)})}}o(fe,"registerHttpRoute");var q=null;function me(t,e){q=t,le(t),fe(e.server)}o(me,"activateApp");var he=new Proxy({},{get(t,e){return(...s)=>{if(!q)return Te.warn(`[Virid Vue] App method "${String(e)}" called before initialization.`),null;let r=q[e];if(typeof r=="function")return Reflect.apply(r,q,s)}}});import{MessageWriter as M}from"@virid/core";import{VIRID_METADATA as ve}from"@virid/core";var i={...ve,HTTPROUTE:"virid:express:route",HTTPSYSTEM:"virid:express:system",BODY:"virid:express:body",QUERY:"virid:express:query",HEADERS:"virid:express:header",REQUEST:"virid:express:request",RESPONSE:"virid:express:response",CONTEXT:"virid:express:context",PARAMS:"virid:express:params",COOKIES:"virid:express:cookie"};function Pt(t){return e=>{let s=`${t.method}:${t.path}`;I.has(s)&&M.error(new Error(`[Virid Http] Routing Conflict: The request method ${t.method} for path ${t.path} has already been registered by ${e.name}`));let r=[];t.path.split("/").forEach(a=>{a.startsWith(":")&&r.push(a.substring(1))});let d={...t,httpMessage:e,params:r};I.set(s,d)}}o(Pt,"HttpRoute");function Tt(t={priority:0,messageClass:null}){return(e,s,r)=>{let n=r.value,d=Reflect.getMetadata("design:paramtypes",e,s),a=Reflect.getMetadata(i.MESSAGE,e,s)||null,h=He(e,s,d);if(!d){let x=new Error(`[Virid HttpSystem] System Parameter Loss:
|
|
8
|
+
Unable to recognize system parameters, please confirm if import "reflection-metadata" was introduced at the beginning!`);M.error(x);return}if(d.some(x=>x===void 0)){let x=new Error(`[Virid HttpSystem] Parameter Metadata Loss in "${s}":
|
|
26
9
|
One or more parameters have 'undefined' types.
|
|
27
10
|
This usually happens when you forget to add a type annotation to a decorated parameter.
|
|
28
|
-
Check parameter at index: ${
|
|
29
|
-
Please declare the message type using the Message decorator`));return}let
|
|
30
|
-
|
|
31
|
-
One or more parameters have 'undefined' types.
|
|
32
|
-
This usually happens when you forget to add a type annotation to a decorated parameter.
|
|
33
|
-
Check parameter at index: ${o.indexOf(void 0)}`);S.error(M);return}if(r.messageClass&&a){S.error(new Error(`[Virid HttpSystem] Multiple Messages Are Not Allowed: Cannot use @ message() and SystemParams simultaneously in ${t}`));return}if(!r.messageClass&&!a){S.error(new Error(`[Virid HttpSystem] System Parameter Loss:
|
|
34
|
-
Please declare the message type using the Message decorator`));return}let h=r.messageClass??a.messageClass;if(!ne.isPrototypeOf(h)){S.error(new Error(`[Virid HttpSystem] Wrong Message Type: ${h.name} is not a derived subclass of HttpRequestMessage!`));return}let u=n(M=>{let w=v.get(M.requestId);if(!w)throw new Error(`[Virid Express HttpSystem] Invalid Request Context: The request context for message ${M.requestId} is missing.`);try{let x=o.map((R,$)=>{if(a&&a.index==$){if(!(M instanceof h)){let ce=M.constructor.name;throw new Error(`[Virid Express HttpSystem] Type Mismatch: Expected ${h.name}, but received ${ce}`)}return M}else return Gt(R,$,w,d)}),b=i.apply(e,x);return b instanceof Promise?b.then(R=>{T(R,w)}).catch(R=>{throw T(xe(),w),R}):T(b,w)}catch(x){throw x instanceof k?T(x,w):T(xe(),w),x}},"wrappedSystem"),f={params:o,targetClass:e,methodName:t,originalMethod:i};u.systemContext=f,s.value=u,ie.register(h,u,r.priority)}}n(Gr,"HttpSystem");function zr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(g.BODY,r,e)){S.error(new Error(`[Virid Express Body] Multiple Body Are Not Allowed: ${e} has multiple @Body() decorators!`));return}let s={index:t};Reflect.defineMetadata(g.BODY,s,r,e)}}n(zr,"Body");function Yr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(g.HEADERS,r,e)){S.error(new Error(`[Virid Express Headers] Multiple Header Are Not Allowed: ${e} has multiple @Headers() decorators!`));return}let s={index:t};Reflect.defineMetadata(g.HEADERS,s,r,e)}}n(Yr,"Headers");function Kr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(g.COOKIES,r,e)){S.error(new Error(`[Virid Express Cookies] Multiple Header Are Not Allowed: ${e} has multiple @Cookies() decorators!`));return}let s={index:t};Reflect.defineMetadata(g.COOKIES,s,r,e)}}n(Kr,"Cookies");function Xr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(g.REQUEST,r,e)){S.error(new Error(`[Virid Express Req] Multiple Request Objects Are Not Allowed: ${e} has multiple @Req() decorators!`));return}let s={index:t};Reflect.defineMetadata(g.REQUEST,s,r,e)}}n(Xr,"Req");function Jr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(g.RESPONSE,r,e)){S.error(new Error(`[Virid Express Res] Multiple Response Objects Are Not Allowed: ${e} has multiple @Res() decorators!`));return}let s={index:t};Reflect.defineMetadata(g.RESPONSE,s,r,e)}}n(Jr,"Res");function Zr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(g.CONTEXT,r,e)){S.error(new Error(`[Virid Express Ctx] Multiple Context Objects Are Not Allowed: ${e} has multiple @Ctx() decorators!`));return}let s={index:t};Reflect.defineMetadata(g.CONTEXT,s,r,e)}}n(Zr,"Ctx");function es(r,e){return(t,s,i)=>{let a=[...Reflect.getOwnMetadata(g.QUERY,t,s)||[],{index:i,query:r,pipe:e}];Reflect.defineMetadata(g.QUERY,a,t,s)}}n(es,"Query");function ts(r,e){return(t,s,i)=>{let a=[...Reflect.getOwnMetadata(g.PARAMS,t,s)||[],{index:i,key:r,pipe:e}];Reflect.defineMetadata(g.PARAMS,a,t,s)}}n(ts,"Params");function Lt(r,e,t){let s=Reflect.getOwnMetadata(g.BODY,r,e),i=Reflect.getOwnMetadata(g.HEADERS,r,e),o=Reflect.getOwnMetadata(g.COOKIES,r,e),a=Reflect.getOwnMetadata(g.RESPONSE,r,e),d=Reflect.getOwnMetadata(g.REQUEST,r,e),h=Reflect.getOwnMetadata(g.CONTEXT,r,e),f=(Reflect.getOwnMetadata(g.QUERY,r,e)||[]).map(x=>{if(!x.pipe){let b=t[x.index];x.pipe=qe(b)}return x}),w=(Reflect.getOwnMetadata(g.PARAMS,r,e)||[]).map(x=>{if(!x.pipe){let b=t[x.index];x.pipe=qe(b)}return x});return{bodyMeta:s,headerMeta:i,queryMeta:f,cookiesMeta:o,reqMeta:d,resMeta:a,ctxMeta:h,paramMeta:w}}n(Lt,"getHttpMetadata");function Gt(r,e,t,s){let{req:i,res:o}=t;if(s.ctxMeta?.index===e)return t;let a=s.paramMeta?.find(u=>u.index===e);if(a){let u=a.key?i.params[a.key]:i.params;return a.pipe&&u!==void 0&&(u=a.pipe(u)),u}if(s.bodyMeta?.index===e)return i.body;if(s.headerMeta?.index===e)return i.headers;if(s.cookiesMeta?.index===e)return lt(i.headers.cookie);if(s.reqMeta?.index===e)return i;if(s.resMeta?.index===e)return o;let d=s.queryMeta?.find(u=>u.index===e);if(d){let u=i.query[d.query];if(u===void 0)throw new Error(`[Virid Express] Missing Query: "${d.query}"`);return d.pipe&&(u=d.pipe(u)),u}let h=ht.get(r);if(!h)throw new Error(`[Virid System] Unknown Inject Type: ${r?.name||"Anonymous Class"} at index ${e}.
|
|
35
|
-
Ensure it is registered in the IOC container or has a proper Http Decorator!`);return h}n(Gt,"getHttpSystemArgs");var os={name:"@virid/express",install(r,e){pt(r,e)}};export{Zt as BadRequest,pe as BadRequestResponse,zr as Body,Qe as ConflictResponse,Kr as Cookies,Xt as Created,de as CreatedResponse,Zr as Ctx,sr as CustomResponse,ye as CustomResponseResponse,os as ExpressPlugin,tr as Forbidden,fe as ForbiddenResponse,Yr as Headers,K as HttpContext,k as HttpError,ne as HttpRequestMessage,E as HttpResponse,Lr as HttpRoute,Gr as HttpSystem,xe as InternalServerError,me as InternalServerErrorResponse,Jt as NoContent,ue as NoContentResponse,rr as NotFound,ge as NotFoundResponse,Kt as Ok,le as OkResponse,ts as Params,qt as ParseBoolPipe,Nt as ParseIntPipe,es as Query,Xr as Req,Jr as Res,ir as Stream,nr as StreamFile,F as StreamFileResponse,L as StreamResponse,er as Unauthorized,he as UnauthorizedResponse,Ue as UnprocessableEntityResponse,yr as addAutoPipe,qe as getAutoPipe,lt as parseRawCookie};
|
|
11
|
+
Check parameter at index: ${d.indexOf(void 0)}`);M.error(x);return}if(t.messageClass&&a){M.error(new Error(`[Virid HttpSystem] Multiple Messages Are Not Allowed: Cannot use @ message() and SystemParams simultaneously in ${s}`));return}if(!t.messageClass&&!a){M.error(new Error(`[Virid HttpSystem] System Parameter Loss:
|
|
12
|
+
Please declare the message type using the Message decorator`));return}let f=t.messageClass??a.messageClass;if(!(f.prototype instanceof v)){M.error(new Error(`[Virid HttpSystem] Wrong Message Type: ${f.name} is not a derived subclass of HttpRequestMessage!`));return}let c=o(x=>{let E=m.get(x.requestId);if(!E)throw new Error(`[Virid Express HttpSystem] Invalid Request Context: The request context for message ${x.requestId} is missing.`);try{let l=d.map((y,ie)=>{if(a&&a.index==ie){if(!(x instanceof f)){let xe=x.constructor.name;throw new Error(`[Virid Express HttpSystem] Type Mismatch: Expected ${f.name}, but received ${xe}`)}return x}else return Ie(y,ie,E,h)}),g=n.apply(e,l);return g instanceof Promise?g.then(y=>{S(y,E)}).catch(y=>{throw S(j(),E),y}):S(g,E)}catch(l){throw l instanceof w?S(l,E):S(j(),E),l}},"wrappedSystem"),R={params:d,targetClass:e,methodName:s,originalMethod:n};c.systemContext=R,r.value=c,H.register(f,c,t.priority)}}o(Tt,"HttpSystem");function vt(){return(t,e,s)=>{if(Reflect.hasOwnMetadata(i.BODY,t,e)){M.error(new Error(`[Virid Express Body] Multiple Body Are Not Allowed: ${e} has multiple @Body() decorators!`));return}let r={index:s};Reflect.defineMetadata(i.BODY,r,t,e)}}o(vt,"Body");function Ht(){return(t,e,s)=>{if(Reflect.hasOwnMetadata(i.HEADERS,t,e)){M.error(new Error(`[Virid Express Headers] Multiple Header Are Not Allowed: ${e} has multiple @Headers() decorators!`));return}let r={index:s};Reflect.defineMetadata(i.HEADERS,r,t,e)}}o(Ht,"Headers");function It(){return(t,e,s)=>{if(Reflect.hasOwnMetadata(i.COOKIES,t,e)){M.error(new Error(`[Virid Express Cookies] Multiple Header Are Not Allowed: ${e} has multiple @Cookies() decorators!`));return}let r={index:s};Reflect.defineMetadata(i.COOKIES,r,t,e)}}o(It,"Cookies");function qt(){return(t,e,s)=>{if(Reflect.hasOwnMetadata(i.REQUEST,t,e)){M.error(new Error(`[Virid Express Req] Multiple Request Objects Are Not Allowed: ${e} has multiple @Req() decorators!`));return}let r={index:s};Reflect.defineMetadata(i.REQUEST,r,t,e)}}o(qt,"Req");function $t(){return(t,e,s)=>{if(Reflect.hasOwnMetadata(i.RESPONSE,t,e)){M.error(new Error(`[Virid Express Res] Multiple Response Objects Are Not Allowed: ${e} has multiple @Res() decorators!`));return}let r={index:s};Reflect.defineMetadata(i.RESPONSE,r,t,e)}}o($t,"Res");function Vt(){return(t,e,s)=>{if(Reflect.hasOwnMetadata(i.CONTEXT,t,e)){M.error(new Error(`[Virid Express Ctx] Multiple Context Objects Are Not Allowed: ${e} has multiple @Ctx() decorators!`));return}let r={index:s};Reflect.defineMetadata(i.CONTEXT,r,t,e)}}o(Vt,"Ctx");function bt(t,e){return(s,r,n)=>{let a=[...Reflect.getOwnMetadata(i.QUERY,s,r)||[],{index:n,query:t,pipe:e}];Reflect.defineMetadata(i.QUERY,a,s,r)}}o(bt,"Query");function Nt(t,e){return(s,r,n)=>{let a=[...Reflect.getOwnMetadata(i.PARAMS,s,r)||[],{index:n,key:t,pipe:e}];Reflect.defineMetadata(i.PARAMS,a,s,r)}}o(Nt,"Params");function He(t,e,s){let r=Reflect.getOwnMetadata(i.BODY,t,e),n=Reflect.getOwnMetadata(i.HEADERS,t,e),d=Reflect.getOwnMetadata(i.COOKIES,t,e),a=Reflect.getOwnMetadata(i.RESPONSE,t,e),h=Reflect.getOwnMetadata(i.REQUEST,t,e),f=Reflect.getOwnMetadata(i.CONTEXT,t,e),R=(Reflect.getOwnMetadata(i.QUERY,t,e)||[]).map(l=>{if(!l.pipe){let g=s[l.index];l.pipe=ne(g)}return l}),E=(Reflect.getOwnMetadata(i.PARAMS,t,e)||[]).map(l=>{if(!l.pipe){let g=s[l.index];l.pipe=ne(g)}return l});return{bodyMeta:r,headerMeta:n,queryMeta:R,cookiesMeta:d,reqMeta:h,resMeta:a,ctxMeta:f,paramMeta:E}}o(He,"getHttpMetadata");function Ie(t,e,s,r){let{req:n,res:d}=s;if(r.ctxMeta?.index===e)return s;let a=r.paramMeta?.find(c=>c.index===e);if(a){let c=a.key?n.params[a.key]:n.params;return a.pipe&&c!==void 0&&(c=a.pipe(c)),c}if(r.bodyMeta?.index===e)return n.body;if(r.headerMeta?.index===e)return n.headers;if(r.cookiesMeta?.index===e)return ue(n.headers.cookie);if(r.reqMeta?.index===e)return n;if(r.resMeta?.index===e)return d;let h=r.queryMeta?.find(c=>c.index===e);if(h){let c=n.query[h.query];if(c===void 0)throw new Error(`[Virid Express] Missing Query: "${h.query}"`);return h.pipe&&(c=h.pipe(c)),c}let f=he.get(t);if(!f)throw new Error(`[Virid System] Unknown Inject Type: ${t?.name||"Anonymous Class"} at index ${e}.
|
|
13
|
+
Ensure it is registered in the IOC container or has a proper Http Decorator!`);return f}o(Ie,"getHttpSystemArgs");var jt={name:"@virid/express",install(t,e){me(t,e)}};export{De as BadRequest,N as BadRequestResponse,vt as Body,ce as ConflictResponse,It as Cookies,be as Created,V as CreatedResponse,Vt as Ctx,Ye as CustomResponse,Y as CustomResponseResponse,jt as ExpressPlugin,Qe as Forbidden,B as ForbiddenResponse,Ht as Headers,P as HttpContext,w as HttpError,v as HttpRequestMessage,u as HttpResponse,Pt as HttpRoute,Tt as HttpSystem,j as InternalServerError,U as InternalServerErrorResponse,Ne as NoContent,b as NoContentResponse,Ue as NotFound,Q as NotFoundResponse,Ve as Ok,$ as OkResponse,Nt as Params,ye as ParseBoolPipe,Re as ParseIntPipe,bt as Query,qt as Req,$t as Res,We as Stream,je as StreamFile,A as StreamFileResponse,O as StreamResponse,Be as Unauthorized,D as UnauthorizedResponse,pe as UnprocessableEntityResponse,Ze as addAutoPipe,ne as getAutoPipe,ue as parseRawCookie};
|
|
36
14
|
//# sourceMappingURL=index.js.map
|