@virid/express 0.1.1 → 0.1.3
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 +21 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -21
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @virid/express v0.
|
|
2
|
+
* @virid/express v0.1.3
|
|
3
3
|
* Add express functionality to virid
|
|
4
4
|
*/
|
|
5
|
-
var
|
|
5
|
+
var K=Object.defineProperty;var Rt=Object.getOwnPropertyDescriptor;var $t=Object.getOwnPropertyNames;var Tt=Object.prototype.hasOwnProperty;var Ht=(r,e,t)=>e in r?K(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var i=(r,e)=>K(r,"name",{value:e,configurable:!0});var Ot=(r,e)=>{for(var t in e)K(r,t,{get:e[t],enumerable:!0})},Vt=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of $t(e))!Tt.call(r,n)&&n!==t&&K(r,n,{get:()=>e[n],enumerable:!(s=Rt(e,n))||s.enumerable});return r};var Pt=r=>Vt(K({},"__esModule",{value:!0}),r);var y=(r,e,t)=>Ht(r,typeof e!="symbol"?e+"":e,t);var Rr={};Ot(Rr,{BadRequest:()=>Nt,BadRequestResponse:()=>oe,Body:()=>yr,ConflictResponse:()=>Ae,Cookies:()=>Mr,Created:()=>Dt,CreatedResponse:()=>ie,Ctx:()=>vr,CustomResponse:()=>_t,CustomResponseResponse:()=>he,ExpressPlugin:()=>Cr,Forbidden:()=>jt,ForbiddenResponse:()=>le,Headers:()=>xr,HttpContext:()=>X,HttpError:()=>k,HttpRequestMessage:()=>re,HttpResponse:()=>M,HttpRoute:()=>gr,HttpSystem:()=>mr,InternalServerError:()=>pe,InternalServerErrorResponse:()=>ue,NoContent:()=>Bt,NoContentResponse:()=>ae,NotFound:()=>Qt,NotFoundResponse:()=>de,Ok:()=>It,OkResponse:()=>ne,Params:()=>br,ParseBoolPipe:()=>Mt,ParseIntPipe:()=>xt,Query:()=>Sr,Req:()=>Er,Res:()=>wr,Stream:()=>Wt,StreamFile:()=>Ft,StreamFileResponse:()=>H,StreamResponse:()=>O,Unauthorized:()=>qt,UnauthorizedResponse:()=>ce,UnprocessableEntityResponse:()=>ke,addAutoPipe:()=>pr,getAutoPipe:()=>Me,parseRawCookie:()=>ze});module.exports=Pt(Rr);var St=require("@virid/core");var we=require("@virid/core");var R=require("@virid/core");var Ke=require("@virid/core");var Ce=class Ce{constructor(e,t,s,n,o){y(this,"id");y(this,"req");y(this,"res");y(this,"timestamp");y(this,"route");y(this,"rc",0);y(this,"isClosed",!1);this.id=e,this.req=t,this.res=s,this.timestamp=n,this.route=o}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`;
|
|
7
|
+
Uptime: ${Date.now()-this.timestamp}ms`;Ke.MessageWriter.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."})}};i(Ce,"HttpContext");var X=Ce,Re=class Re{constructor(e,t=null,s={}){y(this,"status");y(this,"data");y(this,"headers");this.status=e,this.data=t,this.headers=s}};i(Re,"HttpResponse");var M=Re,$e=class $e extends M{constructor(e,t={}){super(200,e,t)}};i($e,"OkResponse");var ne=$e,Te=class Te extends M{constructor(e,t={}){super(201,e,t)}};i(Te,"CreatedResponse");var ie=Te,He=class He extends M{constructor(){super(204,null)}};i(He,"NoContentResponse");var ae=He,Oe=class Oe extends M{constructor(e="Bad Request"){super(400,{error:e})}};i(Oe,"BadRequestResponse");var oe=Oe,Ve=class Ve extends M{constructor(e="Unauthorized"){super(401,{error:e})}};i(Ve,"UnauthorizedResponse");var ce=Ve,Pe=class Pe extends M{constructor(e="Forbidden"){super(403,{error:e})}};i(Pe,"ForbiddenResponse");var le=Pe,Ie=class Ie extends M{constructor(e="Not Found"){super(404,{error:e})}};i(Ie,"NotFoundResponse");var de=Ie,De=class De extends M{constructor(e="Conflict"){super(409,{error:e})}};i(De,"ConflictResponse");var Ae=De,Be=class Be extends M{constructor(e){super(422,{errors:e})}};i(Be,"UnprocessableEntityResponse");var ke=Be,Ne=class Ne extends M{constructor(e="Internal Server Error"){super(500,{error:e})}};i(Ne,"InternalServerErrorResponse");var ue=Ne,qe=class qe extends M{constructor(e,t,s={}){super(e,t,s)}};i(qe,"CustomResponseResponse");var he=qe,je=class je extends M{constructor(t,s={dotfiles:"allow"}){super(206,s);y(this,"filePath");y(this,"options");this.filePath=t,this.options=s}};i(je,"StreamFileResponse");var H=je,Qe=class Qe extends M{constructor(t,s={}){super(s.status,{},s.headers);y(this,"stream");y(this,"options");this.stream=t,this.options=s}};i(Qe,"StreamResponse");var O=Qe,It=i((r,e={})=>new ne(r,e),"Ok"),Dt=i((r,e={})=>new ie(r,e),"Created"),Bt=i(()=>new ae,"NoContent"),Nt=i((r="Bad Request")=>new oe(r),"BadRequest"),qt=i((r="Unauthorized")=>new ce(r),"Unauthorized"),jt=i((r="Forbidden")=>new le(r),"Forbidden"),Qt=i((r="Not Found")=>new de(r),"NotFound"),pe=i((r="Internal Server Error")=>new ue(r),"InternalServerError"),_t=i((r,e,t={})=>new he(r,e,t),"CustomResponse"),Ft=i((r,e)=>new H(r,e),"StreamFile"),Wt=i((r,e)=>new O(r,e),"Stream"),_e=class _e extends Error{constructor(t,s){super(s);y(this,"status");y(this,"message");this.status=t,this.message=s}};i(_e,"HttpError");var k=_e;var v=new Map;function V(r,e){if(!r){e.dec();return}(Array.isArray(r)?r:[r]).forEach(s=>{s instanceof M?Ut(s,e):s instanceof k?(e.res.status(s.status).json(s.message),v.delete(e.id)):s instanceof R.BaseMessage?R.MessageWriter.write(s):R.MessageWriter.warn(`[Virid Express] Invalid Return Type: ${typeof s}. Expected HttpResponse or Message.`)}),e.dec()}i(V,"handleResult");function Ut(r,e){let{res:t}=e;if(r.headers&&Object.entries(r.headers).forEach(([s,n])=>t.setHeader(s,n)),r.status&&t.status(r.status),r instanceof H){e.inc(),t.sendFile(r.filePath,r.options,s=>{t.headersSent||R.MessageWriter.error(s,`[Virid Express] SteamFile Error: Path: ${r.filePath}`),e.res.end(),v.delete(e.id),e.isClosed=!0,e.dec()});return}if(r instanceof O){let{stream:s}=r;e.inc(),s.pipe(t);let n=i(()=>{v.has(e.id)&&(e.res.end(),v.delete(e.id),e.isClosed=!0,e.dec())},"cleanup");s.on("end",n),s.on("error",o=>{t.headersSent||R.MessageWriter.error(o,"[Virid Express] Stream Error"),n()}),s.on("close",n);return}t.status(r.status).json(r.data),v.delete(e.id)}i(Ut,"handleHttpResponse");var et=Object.defineProperty,Lt=i((r,e,t)=>e in r?et(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,"pe"),c=i((r,e)=>et(r,"name",{value:e,configurable:!0}),"o"),l=i((r,e,t)=>Lt(r,typeof e!="symbol"?e+"":e,t),"i"),P,tt=(P=class{static send(...e){p.write(this,...e)}},i(P,"L"),P);c(tt,"BaseMessage");var ye=tt,I,rt=(I=class extends ye{constructor(){super(),l(this,"__kind","SingleMessage")}},i(I,"W"),I);c(rt,"SingleMessage");var xe=rt,D,st=(D=class extends ye{constructor(){super(),l(this,"__kind","EventMessage")}},i(D,"F"),D);c(st,"EventMessage");var $=st,B,nt=(B=class extends ${constructor(e,t){super(),l(this,"error"),l(this,"context"),this.error=e,this.context=t}},i(B,"Q"),B);c(nt,"ErrorMessage");var Ue=nt,N,it=(N=class extends ${constructor(e){super(),l(this,"context"),this.context=e}},i(N,"z"),N);c(it,"WarnMessage");var Le=it,q,at=(q=class extends ${constructor(e){super(),l(this,"context"),this.context=e}},i(q,"U"),q);c(at,"InfoMessage");var Ge=at,j,ot=(j=class extends ${constructor(e,t,s){super(),l(this,"ComponentClass"),l(this,"recipe"),l(this,"label"),this.ComponentClass=e,this.recipe=t,this.label=s}},i(j,"J"),j);c(ot,"AtomicModifyMessage");var Xe=ot,Fe=new Map,We=new Map,Q,Gt=(Q=class extends xe{constructor(){super()}static send(...e){let t=new this(...e),s=t.debounceTime,n=Fe.get(this);if(n){t.debounceCallback(n);let a=We.get(this);a&&clearTimeout(a)}Fe.set(this,t);let o=setTimeout(()=>{Fe.delete(this),We.delete(this)},s);We.set(this,o),p.write(t)}debounceCallback(e){}},i(Q,"Y"),Q);c(Gt,"DebounceMessage");var fe=null;function ct(r){fe=r}i(ct,"ce");c(ct,"activateInstance");var zt=new Proxy({},{get(r,e){return e==="dispatch"?t=>{if(!fe){console.error(`[Virid] Message dispatched before system init: ${t.constructor.name}`);return}return fe.dispatch(t)}:Reflect.get(fe||{},e)}}),_,lt=(_=class{static write(e,...t){let s=typeof e=="function"?new e(...t):e;zt.dispatch(s)}static error(e,t=""){this.write(new Ue(e,t))}static warn(e){this.write(new Le(e))}static info(e){this.write(new Ge(e))}},i(_,"q"),_);c(lt,"MessageWriter");var p=lt,F,dt=(F=class{constructor(e){l(this,"dirtySignalTypes",new Set),l(this,"eventQueue",[]),l(this,"isRunning",!1),l(this,"globalTick",0),l(this,"internalDepth",0),l(this,"eventHub"),l(this,"tickPayload",{}),l(this,"beforeExecuteHooks",[]),l(this,"afterExecuteHooks",[]),l(this,"beforeTickHooks",[]),l(this,"afterTickHooks",[]),this.eventHub=e}addBeforeExecute(e,t,s){s?this.beforeExecuteHooks.unshift({type:e,handler:t}):this.beforeExecuteHooks.push({type:e,handler:t})}addAfterExecute(e,t,s){s?this.afterExecuteHooks.unshift({type:e,handler:t}):this.afterExecuteHooks.push({type:e,handler:t})}addBeforeTick(e,t){t?this.beforeTickHooks.unshift(e):this.beforeTickHooks.push(e)}addAfterTick(e,t){t?this.afterTickHooks.unshift(e):this.afterTickHooks.push(e)}markDirty(e){e instanceof $?this.eventQueue.push(e):e instanceof xe&&this.dirtySignalTypes.add(e.constructor)}tick(e){if(!(this.isRunning||this.dirtySignalTypes.size===0&&this.eventQueue.length===0)){if(this.internalDepth>100){this.internalDepth=0,this.dirtySignalTypes.clear(),this.eventQueue=[],this.eventHub.reset(),p.error(new Error("[Virid Dispatcher] Deadlock: Recursive loop detected \u{1F4A5}."));return}this.isRunning=!0,this.internalDepth++,queueMicrotask(()=>{let t,s;try{this.internalDepth==0&&(this.tickPayload={},this.executeTickHooks(this.beforeTickHooks));let n=this.prepareSnapshot();t=n.signalSnapshot,s=n.eventSnapshot;let o=this.collectTasks(s,t,e);this.executeTasks(o)}catch(n){p.error(n,"[Virid Dispatcher] Unhandled Error")}finally{t&&s&&this.clear(s,t),this.isRunning=!1,this.dirtySignalTypes.size>0||this.eventQueue.length>0?this.tick(e):(this.executeTickHooks(this.afterTickHooks),this.globalTick++,this.internalDepth=0)}})}}collectTasks(e,t,s){let n=[];for(let a of e)(s.get(a.constructor)||[]).forEach(d=>{n.push(new Je(d.fn,d.priority,a,{context:d.fn.systemContext,tick:this.globalTick,payload:{}}))});let o=new Set;for(let a of t)(s.get(a)||[]).forEach(d=>{o.has(d.fn)||(n.push(new Je(d.fn,d.priority,this.eventHub.peekSignal(a),{context:d.fn.systemContext,tick:this.globalTick,payload:{}})),o.add(d.fn))});return n}executeTasks(e){e.sort((t,s)=>s.priority-t.priority);for(let t of e)try{let s=t.execute(this.beforeExecuteHooks,this.afterExecuteHooks);s instanceof Promise&&s.catch(n=>p.error(n,`[Virid Dispatcher]: Async System Error.
|
|
8
8
|
SystemLocation: ${t.hookContext.context.targetClass.name}.${t.hookContext.context.methodName}
|
|
9
9
|
MessageName: ${t.message.constructor.name}
|
|
10
|
-
MessageData: ${JSON.stringify(t.message)}`))}catch(s){
|
|
10
|
+
MessageData: ${JSON.stringify(t.message)}`))}catch(s){p.error(s,`[Virid Dispatcher]: Sync System Error.
|
|
11
11
|
SystemLocation: ${t.hookContext.context.targetClass.name}.${t.hookContext.context.methodName}
|
|
12
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(n=>s.add(n.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))}},i(
|
|
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(n=>s.add(n.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))}},i(F,"K"),F);c(dt,"Dispatcher");var Yt=dt,W,ut=(W=class{constructor(e,t,s,n){l(this,"fn"),l(this,"priority"),l(this,"message"),l(this,"hookContext"),this.fn=e,this.priority=t,this.message=s,this.hookContext=n}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 n=s.handler(this.message,this.hookContext);n instanceof Promise&&n.catch(o=>{p.error(o,`[Virid Hook] Async Hook Error:
|
|
14
14
|
It is prohibited to use asynchronous hooks within Hook:
|
|
15
|
-
${s.type.name}`)})}catch(n){
|
|
15
|
+
${s.type.name}`)})}catch(n){p.error(n,`[Virid Hook] Hook Execute Failed:
|
|
16
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 n=this.fn(this.message);return n instanceof Promise?n.finally(()=>s()):(s(),n)}catch(n){throw s(),n}}},i(
|
|
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=[]}},i(
|
|
17
|
+
Registered type: ${s.type.name}`)}}}execute(e,t){this.triggerHooks(e);let s=c(()=>this.triggerHooks(t),"runAfter");try{let n=this.fn(this.message);return n instanceof Promise?n.finally(()=>s()):(s(),n)}catch(n){throw s(),n}}},i(W,"X"),W);c(ut,"ExecutionTask");var Je=ut,U,ht=(U=class{constructor(){l(this,"signalActive",new Map),l(this,"signalStaging",new Map),l(this,"eventActive",[]),l(this,"eventStaging",[])}push(e){if(e instanceof xe){let t=e.constructor;this.signalStaging.has(t)||this.signalStaging.set(t,[]),this.signalStaging.get(t).push(e)}else e instanceof $?this.eventStaging.push(e):p.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=[]}},i(U,"Z"),U);c(ht,"EventHub");var Kt=ht,L,pt=(L=class{constructor(){l(this,"systemTaskMap",new Map)}register(e,t,s=0){let n=this.systemTaskMap.get(e)||[];if(n.findIndex(o=>o.fn===t)===-1)n.push({fn:t,priority:s}),n.sort((o,a)=>a.priority-o.priority),this.systemTaskMap.set(e,n);else{let o=t.name||"Anonymous";return p.error(new Error(`[Virid Error] System Already Registered:
|
|
19
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))}}}},i(
|
|
21
|
-
${
|
|
22
|
-
${
|
|
23
|
-
${
|
|
24
|
-
${
|
|
25
|
-
Component ${r.ComponentClass.name} not found in Registry.`);return}try{r.recipe(e),
|
|
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))}}}},i(L,"ee"),L);c(pt,"MessageRegistry");var Xt=pt,G,ft=(G=class{constructor(){l(this,"eventHub",new Kt),l(this,"dispatcher",new Yt(this.eventHub)),l(this,"registry",new Xt),l(this,"middlewares",[]),ct(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 ye)){p.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)){p.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,n=c(()=>{s<this.middlewares.length?this.middlewares[s++](e,n):t()},"next");n()}register(e,t,s=0){return this.registry.register(e,t,s)}},i(G,"te"),G);c(ft,"MessageInternal");var Jt=ft,z,gt=(z=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 n=s.ctor;if(s.type==="singleton"){if(!this.singletonInstances.has(e)){let a=new n,d=t(a);this.singletonInstances.set(e,d)}return this.singletonInstances.get(e)}let o=new n;return t(o)}},i(z,"re"),z);c(gt,"ViridContainer");var Zt=gt,h={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 J(r,e,t){let s={params:r,targetClass:Object,methodName:t,originalMethod:e};return e.ccsContext=s,e}i(J,"N");c(J,"withContext");var er=c(r=>{let e=`${h.green}${h.bold} \u2714 [Virid Info] ${h.reset}`,t=`${h.magenta}${r.context}${h.reset}`;console.log(`${e}${h.gray}Global Info Caught:${h.reset}
|
|
21
|
+
${h.green}Details:${h.reset}`,r.context||"unknown Info")},"globalInfoHandler"),tr=c(r=>{let e=`${h.red}${h.bold} \u2716 [Virid Error] ${h.reset}`,t=`${h.magenta}${r.context}${h.reset}`;console.error(`${e}${h.gray}Global Error Caught:${h.reset}
|
|
22
|
+
${h.red}Context:${h.reset} ${t}
|
|
23
|
+
${h.red}Details:${h.reset}`,r.error||r||"unknown Error")},"globalErrorHandler"),rr=c(r=>{let e=`${h.yellow}${h.bold} \u26A0 [Virid Warn] ${h.reset}`,t=`${h.cyan}${r.context}${h.reset}`;console.warn(`${e}${h.gray}Global Warn Caught:${h.reset}
|
|
24
|
+
${h.yellow}Context:${h.reset} ${t}`)},"globalWarnHandler"),sr=c(r=>{let e=Z.get(r.ComponentClass);if(!e){console.error(`[Virid Modify] Component Not Found:
|
|
25
|
+
Component ${r.ComponentClass.name} not found in Registry.`);return}try{r.recipe(e),p.warn(`[Virid Modify] Successfully:
|
|
26
26
|
Modify on ${r.ComponentClass.name}
|
|
27
|
-
label: ${r.label}`)}catch(t){
|
|
28
|
-
${r.label}`)}},"atomicModifyHandler");function
|
|
29
|
-
Unable to recognize system parameters, please confirm if import "reflection-metadata" was introduced at the beginning!`);
|
|
27
|
+
label: ${r.label}`)}catch(t){p.error(t,`[Virid Error] Modify Failed:
|
|
28
|
+
${r.label}`)}},"atomicModifyHandler");function mt(r){r.register(Xe,J(Xe,sr,"GlobalAtomicModifier"),1e3),r.register(Le,J(Le,rr,"GlobalWarnHandler"),-999),r.register(Ue,J(Ue,tr,"GlobalErrorHandler"),-999),r.register(Ge,J(Ge,er,"GlobalInfoHandler"),-999),Z=r}i(mt,"le");c(mt,"initializeGlobalSystems");var Z=null,Ir=new Proxy({},{get(r,e){return(...t)=>{if(!Z){console.warn(`[Virid Vue] App method "${String(e)}" called before initialization.`);return}let s=Z[e];if(typeof s=="function")return s.apply(Z,t)}}}),Ze=new Set,Y,yt=(Y=class{constructor(){l(this,"container",new Zt),l(this,"messageInternal",new Jt),l(this,"activationHooks",[])}addActivationHook(e){this.activationHooks.push(e)}get(e){return e.length>0&&p.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 n=s(t);return n===void 0&&p.warn(`[Virid Container] Hook Does Bot Return A Value: Hook "${s.name}" should return a instance to continue.`),n!==void 0?n:t}catch(n){return p.error(n,"[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(Ze.has(e.name))return p.warn(`[Virid Plugin] Duplicate Installation: Plugin ${e.name} has already been installed.`),this;try{e.install(this,t),Ze.add(e.name)}catch(s){p.error(s,`[Virid Plugin]: Install Failed: ${e.name}`)}return this}},i(Y,"ne"),Y);c(yt,"ViridApp");var nr=yt,ee=new nr;ee.addActivationHook(me);mt(ee);var b={SYSTEM:"virid:core:system",MESSAGE:"virid:core:message",CONTROLLER:"virid:core:controller",COMPONENT:"virid:core:component",SAFE:"virid:core:safe",OBSERVER:"virid:core:observer"},ge=c(r=>{r&&(Array.isArray(r)?r:[r]).forEach(e=>{e instanceof ye?p.write(e):p.warn("[Virid HandleResult] Invalid Return Type: Must return Message or Message[].")})},"handleResult");function ir(r={priority:0,messageClass:null}){return(e,t,s)=>{let n=s.value,o=Reflect.getMetadata("design:paramtypes",e,t),a=Reflect.getMetadata(b.MESSAGE,e,t)||null;if(!o){let g=new Error(`[Virid System] System Parameter Loss:
|
|
29
|
+
Unable to recognize system parameters, please confirm if import "reflection-metadata" was introduced at the beginning!`);p.error(g);return}if(o.some(g=>g===void 0)){let g=new Error(`[Virid System] Parameter Metadata Loss in "${t}":
|
|
30
30
|
One or more parameters have 'undefined' types.
|
|
31
31
|
This usually happens when you forget to add a type annotation to a decorated parameter.
|
|
32
|
-
Check parameter at index: ${o.indexOf(void 0)}`);
|
|
33
|
-
Please declare the message type using the Message decorator`));return}let d=c(
|
|
32
|
+
Check parameter at index: ${o.indexOf(void 0)}`);p.error(g);return}if(r.messageClass&&a){p.error(new Error(`[Virid System] Multiple Messages Are Not Allowed: Cannot use @ message() and SystemParams simultaneously in ${t}`));return}if(!r.messageClass&&!a){p.error(new Error(`[Virid System] System Parameter Loss:
|
|
33
|
+
Please declare the message type using the Message decorator`));return}let d=c(g=>{let E=o.map((x,A)=>{if(a&&a.index==A){let{messageClass:T,single:be}=a,se=Array.isArray(g)?g[0]:g;if(!(se instanceof T)){let Ct=se.constructor.name;throw new Error(`[Virid System] Type Mismatch: Expected ${T.name}, but received ${Ct}`)}if(se instanceof xe)return be?Array.isArray(g)?g[g.length-1]:g:Array.isArray(g)?g:[g];if(se instanceof $)return g;throw new Error(`[Virid System] unknown Message Types: Message ${T.name} is not a subclass of SingleMessage or EventMessage!`)}let C=ee.get(x);if(!C)throw new Error(`[Virid System] unknown Inject Data Types: ${x.name} is not registered in the container!`);return C}),w=n.apply(e,E);return w instanceof Promise?w.then(ge):ge(w)},"wrappedSystem"),f={params:o,targetClass:e,methodName:t,originalMethod:n};d.systemContext=f,s.value=d;let u=r.messageClass||a.messageClass;ee.register(u,d,r.priority)}}i(ir,"ft");c(ir,"System");function ar(r,e=!0){return(t,s,n)=>{if(Reflect.hasOwnMetadata(b.MESSAGE,t,s)){p.error(new Error(`[Virid Message] Multiple Messages Are Not Allowed: ${s} has multiple @Message() decorators!`));return}let o={index:n,messageClass:r,single:e};Reflect.defineMetadata(b.MESSAGE,o,t,s)}}i(ar,"pt");c(ar,"Message");function or(){return(r,e,t)=>{let s=Reflect.getMetadata(b.SAFE,r)||new Set;s.add(e),Reflect.defineMetadata(b.SAFE,s,r)}}i(or,"gt");c(or,"Safe");function cr(r,[]){return(e,t)=>{let s=Reflect.getMetadata(b.OBSERVER,e)||[];s.push({key:t,callback:r}),Reflect.defineMetadata(b.OBSERVER,s,e)}}i(cr,"mt");c(cr,"Observer");function lr(){return r=>{Reflect.defineMetadata(b.CONTROLLER,!0,r)}}i(lr,"yt");c(lr,"Controller");function dr(){return r=>{Reflect.defineMetadata(b.COMPONENT,!0,r)}}i(dr,"xt");c(dr,"Component");var ur=["push","pop","shift","unshift","splice","sort","reverse"];function me(r){return!r||typeof r!="object"||Object.prototype.hasOwnProperty.call(r,"__virid_observer_processed__")||(Object.defineProperty(r,"__virid_observer_processed__",{value:!0,enumerable:!1,configurable:!0}),(Reflect.getMetadata(b.OBSERVER,r.constructor)||[]).forEach(({propertyKey:e,callback:t})=>{let s={value:r[e]},n=new Proxy(s,{get(a,d){let f=a.value;return Array.isArray(f)&&ur.includes(d)?(...u)=>{let g=[...f],E=f[d].apply(f,u),w=t.call(r,g,f);return ge(w),E}:f},set(a,d,f){let u=a.value;if(f===u)return!0;a.value=f;let g=t.call(r,u,f);return ge(g),!0}}),o=c(()=>n.value,"getter");o.__virid_box__=s,Object.defineProperty(r,e,{get:o,set:c(a=>{n.value=a},"set"),enumerable:!0,configurable:!0}),s.value&&typeof s.value=="object"&&me(s.value)}),Reflect.ownKeys(r).forEach(e=>{if(e==="__virid_observer_processed__")return;let t=Object.getOwnPropertyDescriptor(r,e);if(t&&t.get)return;let s=r[e];s&&typeof s=="object"&&me(s)})),r}i(me,"_");c(me,"bindObservers");function hr(){return ee}i(hr,"It");c(hr,"createVirid");function xt(r){let e=parseInt(r,10);if(isNaN(e))throw new k(400,`Validation failed: "${r}" is not a number.`);return e}i(xt,"ParseIntPipe");function Mt(r){return r==="true"||r==="1"?!0:r==="false"||r==="0"?!1:!!r}i(Mt,"ParseBoolPipe");var te=new Map;te.set(Number,xt);te.set(Boolean,Mt);function pr(r,e){if(te.has(r)){p.error(new Error(`[Virid Express Pipe] Repeated Pipe: Auto pipe for ${r} has already been registered.`));return}te.set(r,e)}i(pr,"addAutoPipe");function Me(r){return te.get(r)}i(Me,"getAutoPipe");function ze(r){let e={};if(!r)return e;let t=r.split(";");for(let s of t){let n=s.indexOf("=");if(n===-1)continue;let o=s.substring(0,n).trim();if(!o)continue;let a=s.substring(n+1).trim();a[0]==='"'&&a[a.length-1]==='"'&&(a=a.slice(1,-1));try{e[o]=a.includes("%")?decodeURIComponent(a):a}catch{e[o]=a}}return e}i(ze,"parseRawCookie");var Et=require("@virid/core");var Ye=class Ye extends Et.EventMessage{constructor(t){super();y(this,"__virid_express_id");this.__virid_express_id=t,v.get(this.__virid_express_id).inc()}get requestId(){return this.__virid_express_id}};i(Ye,"HttpRequestMessage");var re=Ye;var Ee=new we.MessageRegistry,ve=new Map,fr=0;function wt(r){for(let[e,t]of Ee.systemTaskMap.entries())for(let s of t)r.register(e,s.fn,s.priority);Ee.systemTaskMap.clear()}i(wt,"registerHttpSystem");function vt(r){for(let[e,t]of ve.entries()){let{method:s,path:n,httpMessage:o}=t,a=s.toLowerCase();r[a](n,(d,f)=>{let u=fr++>>>0;v.set(u,new X(u,d,f,Date.now(),n));let g=new o(u);f.once("finish",()=>v.delete(u)),f.once("close",()=>v.delete(u)),we.MessageWriter.write(g)})}}i(vt,"registerHttpRoute");var Se=null;function bt(r,e){Se=r,wt(r),vt(e.server)}i(bt,"activateApp");var At=new Proxy({},{get(r,e){return(...t)=>{if(!Se)return St.MessageWriter.warn(`[Virid Vue] App method "${String(e)}" called before initialization.`),null;let s=Se[e];if(typeof s=="function")return s.apply(Se,t)}}});var S=require("@virid/core");var kt=require("@virid/core"),m={...kt.VIRID_METADATA,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 gr(r){return e=>{let t=`${r.method}:${r.path}`;ve.has(t)&&S.MessageWriter.error(new Error(`[Virid Http] Routing Conflict: The request method ${r.method} for path ${r.path} has already been registered by ${e.name}`));let s=[];r.path.split("/").forEach(a=>{a.startsWith(":")&&s.push(a.substring(1))});let o={...r,httpMessage:e,params:s};ve.set(t,o)}}i(gr,"HttpRoute");function mr(r={priority:0,messageClass:null}){return(e,t,s)=>{let n=s.value,o=Reflect.getMetadata("design:paramtypes",e,t),a=Reflect.getMetadata(m.MESSAGE,e,t)||null,d=Ar(e,t,o);if(!o){let E=new Error(`[Virid HttpSystem] System Parameter Loss:
|
|
34
34
|
Unable to recognize system parameters, please confirm if import "reflection-metadata" was introduced at the beginning!`);S.MessageWriter.error(E);return}if(o.some(E=>E===void 0)){let E=new Error(`[Virid HttpSystem] Parameter Metadata Loss in "${t}":
|
|
35
35
|
One or more parameters have 'undefined' types.
|
|
36
36
|
This usually happens when you forget to add a type annotation to a decorated parameter.
|
|
37
37
|
Check parameter at index: ${o.indexOf(void 0)}`);S.MessageWriter.error(E);return}if(r.messageClass&&a){S.MessageWriter.error(new Error(`[Virid HttpSystem] Multiple Messages Are Not Allowed: Cannot use @ message() and SystemParams simultaneously in ${t}`));return}if(!r.messageClass&&!a){S.MessageWriter.error(new Error(`[Virid HttpSystem] System Parameter Loss:
|
|
38
|
-
Please declare the message type using the Message decorator`));return}let
|
|
39
|
-
Ensure it is registered in the IOC container or has a proper Http Decorator!`);return
|
|
38
|
+
Please declare the message type using the Message decorator`));return}let f=r.messageClass??a.messageClass;if(!re.isPrototypeOf(f)){S.MessageWriter.error(new Error(`[Virid HttpSystem] Wrong Message Type: ${f.name} is not a derived subclass of HttpRequestMessage!`));return}let u=i(E=>{let w=v.get(E.requestId);if(!w)throw new Error(`[Virid Express HttpSystem] Invalid Request Context: The request context for message ${E.requestId} is missing.`);try{let x=o.map((C,T)=>{if(a&&a.index==T){if(!(E instanceof f)){let be=E.constructor.name;throw new Error(`[Virid Express HttpSystem] Type Mismatch: Expected ${f.name}, but received ${be}`)}return E}else return kr(C,T,w,d)}),A=n.apply(e,x);return A instanceof Promise?A.then(C=>{V(C,w)}).catch(C=>{throw V(pe(),w),C}):V(A,w)}catch(x){throw x instanceof k?V(x,w):V(pe(),w),x}},"wrappedSystem"),g={params:o,targetClass:e,methodName:t,originalMethod:n};u.systemContext=g,s.value=u,Ee.register(f,u,r.priority)}}i(mr,"HttpSystem");function yr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(m.BODY,r,e)){S.MessageWriter.error(new Error(`[Virid Express Body] Multiple Body Are Not Allowed: ${e} has multiple @Body() decorators!`));return}let s={index:t};Reflect.defineMetadata(m.BODY,s,r,e)}}i(yr,"Body");function xr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(m.HEADERS,r,e)){S.MessageWriter.error(new Error(`[Virid Express Headers] Multiple Header Are Not Allowed: ${e} has multiple @Headers() decorators!`));return}let s={index:t};Reflect.defineMetadata(m.HEADERS,s,r,e)}}i(xr,"Headers");function Mr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(m.COOKIES,r,e)){S.MessageWriter.error(new Error(`[Virid Express Cookies] Multiple Header Are Not Allowed: ${e} has multiple @Cookies() decorators!`));return}let s={index:t};Reflect.defineMetadata(m.COOKIES,s,r,e)}}i(Mr,"Cookies");function Er(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(m.REQUEST,r,e)){S.MessageWriter.error(new Error(`[Virid Express Req] Multiple Request Objects Are Not Allowed: ${e} has multiple @Req() decorators!`));return}let s={index:t};Reflect.defineMetadata(m.REQUEST,s,r,e)}}i(Er,"Req");function wr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(m.RESPONSE,r,e)){S.MessageWriter.error(new Error(`[Virid Express Res] Multiple Response Objects Are Not Allowed: ${e} has multiple @Res() decorators!`));return}let s={index:t};Reflect.defineMetadata(m.RESPONSE,s,r,e)}}i(wr,"Res");function vr(){return(r,e,t)=>{if(Reflect.hasOwnMetadata(m.CONTEXT,r,e)){S.MessageWriter.error(new Error(`[Virid Express Ctx] Multiple Context Objects Are Not Allowed: ${e} has multiple @Ctx() decorators!`));return}let s={index:t};Reflect.defineMetadata(m.CONTEXT,s,r,e)}}i(vr,"Ctx");function Sr(r,e){return(t,s,n)=>{let a=[...Reflect.getOwnMetadata(m.QUERY,t,s)||[],{index:n,query:r,pipe:e}];Reflect.defineMetadata(m.QUERY,a,t,s)}}i(Sr,"Query");function br(r,e){return(t,s,n)=>{let a=[...Reflect.getOwnMetadata(m.PARAMS,t,s)||[],{index:n,key:r,pipe:e}];Reflect.defineMetadata(m.PARAMS,a,t,s)}}i(br,"Params");function Ar(r,e,t){let s=Reflect.getOwnMetadata(m.BODY,r,e),n=Reflect.getOwnMetadata(m.HEADERS,r,e),o=Reflect.getOwnMetadata(m.COOKIES,r,e),a=Reflect.getOwnMetadata(m.RESPONSE,r,e),d=Reflect.getOwnMetadata(m.REQUEST,r,e),f=Reflect.getOwnMetadata(m.CONTEXT,r,e),g=(Reflect.getOwnMetadata(m.QUERY,r,e)||[]).map(x=>{if(!x.pipe){let A=t[x.index];x.pipe=Me(A)}return x}),w=(Reflect.getOwnMetadata(m.PARAMS,r,e)||[]).map(x=>{if(!x.pipe){let A=t[x.index];x.pipe=Me(A)}return x});return{bodyMeta:s,headerMeta:n,queryMeta:g,cookiesMeta:o,reqMeta:d,resMeta:a,ctxMeta:f,paramMeta:w}}i(Ar,"getHttpMetadata");function kr(r,e,t,s){let{req:n,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?n.params[a.key]:n.params;return a.pipe&&u!==void 0&&(u=a.pipe(u)),u}if(s.bodyMeta?.index===e)return n.body;if(s.headerMeta?.index===e)return n.headers;if(s.cookiesMeta?.index===e)return ze(n.headers.cookie);if(s.reqMeta?.index===e)return n;if(s.resMeta?.index===e)return o;let d=s.queryMeta?.find(u=>u.index===e);if(d){let u=n.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 f=At.get(r);if(!f)throw new Error(`[Virid System] Unknown Inject Type: ${r?.name||"Anonymous Class"} at index ${e}.
|
|
39
|
+
Ensure it is registered in the IOC container or has a proper Http Decorator!`);return f}i(kr,"getHttpSystemArgs");var Cr={name:"@virid/express",install(r,e){bt(r,e)}};0&&(module.exports={BadRequest,BadRequestResponse,Body,ConflictResponse,Cookies,Created,CreatedResponse,Ctx,CustomResponse,CustomResponseResponse,ExpressPlugin,Forbidden,ForbiddenResponse,Headers,HttpContext,HttpError,HttpRequestMessage,HttpResponse,HttpRoute,HttpSystem,InternalServerError,InternalServerErrorResponse,NoContent,NoContentResponse,NotFound,NotFoundResponse,Ok,OkResponse,Params,ParseBoolPipe,ParseIntPipe,Query,Req,Res,Stream,StreamFile,StreamFileResponse,StreamResponse,Unauthorized,UnauthorizedResponse,UnprocessableEntityResponse,addAutoPipe,getAutoPipe,parseRawCookie});
|
|
40
40
|
//# sourceMappingURL=index.cjs.map
|