truxie 0.1.0-test.13 → 0.1.0-test.14
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.js +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {l,n,o,c as c$1,p,q as q$1,s}from'./chunk-IEQXYYZJ.js';export{c as Container,d as Controller,h as Delete,q as EventEmitter2,e as Get,p as ModuleRegistry,k as NoGuard,r as OnEvent,i as Patch,f as Post,g as Put,j as RouteGuards,a as forwardRef,m as getControllerGuards,l as getControllerPath,o as getMethodGuards,n as getRouteMetadata,b as resolveForwardRef}from'./chunk-IEQXYYZJ.js';import {a as a$1}from'./chunk-2ACNLLXS.js';export{a as DiscoveryService}from'./chunk-2ACNLLXS.js';import {c,e,g as g$1}from'./chunk-PT5RXFB5.js';export{a as AppError,f as ConflictError,e as ForbiddenError,b as NotFoundError,g as RequestAbortedError,d as UnauthorizedError,c as ValidationError}from'./chunk-PT5RXFB5.js';import {b}from'./chunk-MF2CCNPQ.js';export{k as Global,d as Inject,c as Injectable,j as Module,e as Optional,a as Scope,l as getModuleMetadata,m as isGlobalModule}from'./chunk-MF2CCNPQ.js';import {n as n$1,i,j,k as k$1,m as m$1}from'./chunk-RLQ7JJW6.js';import {a}from'./chunk-EI7MMDWY.js';import'reflect-metadata';function it(o,e){if("useFactory"in e&&e.useFactory){let r=e.useFactory;return [{provide:o,useFactory:r,inject:e.inject??[]}]}if("useClass"in e&&e.useClass){let r=e.useClass;return [{provide:o,useFactory:a(async t=>t.createModuleOptions(),"useFactory"),inject:[r]},r]}if("useExisting"in e&&e.useExisting){let r=e.useExisting;return [{provide:o,useFactory:a(async t=>t.createModuleOptions(),"useFactory"),inject:[r]}]}throw new Error("ModuleAsyncOptions must specify one of: useFactory, useClass, or useExisting")}a(it,"createAsyncProviders");var F=class{static{a(this,"ConfigurableModuleBuilder");}description;featureDescription;onForRoot;onForFeature;constructor(e="MODULE_OPTIONS"){this.description=e,this.featureDescription=e+"_FEATURE";}setTokenDescription(e){return this.description=e,this}transformDynamicModule(e){return this.onForRoot=e,this}transformFeatureModule(e){return this.onForFeature=e,this}build(){let e=new b(this.description),r=new b(this.featureDescription),t=this.onForRoot,s=this.onForFeature;return {ConfigurableModuleClass:class{static{a(this,"ConfigurableModuleClassImpl");}static forRoot(
|
|
1
|
+
import {l,n,o,c as c$1,p,q as q$1,s}from'./chunk-IEQXYYZJ.js';export{c as Container,d as Controller,h as Delete,q as EventEmitter2,e as Get,p as ModuleRegistry,k as NoGuard,r as OnEvent,i as Patch,f as Post,g as Put,j as RouteGuards,a as forwardRef,m as getControllerGuards,l as getControllerPath,o as getMethodGuards,n as getRouteMetadata,b as resolveForwardRef}from'./chunk-IEQXYYZJ.js';import {a as a$1}from'./chunk-2ACNLLXS.js';export{a as DiscoveryService}from'./chunk-2ACNLLXS.js';import {c,e,g as g$1}from'./chunk-PT5RXFB5.js';export{a as AppError,f as ConflictError,e as ForbiddenError,b as NotFoundError,g as RequestAbortedError,d as UnauthorizedError,c as ValidationError}from'./chunk-PT5RXFB5.js';import {b}from'./chunk-MF2CCNPQ.js';export{k as Global,d as Inject,c as Injectable,j as Module,e as Optional,a as Scope,l as getModuleMetadata,m as isGlobalModule}from'./chunk-MF2CCNPQ.js';import {n as n$1,i,j,k as k$1,m as m$1}from'./chunk-RLQ7JJW6.js';import {a}from'./chunk-EI7MMDWY.js';import'reflect-metadata';function it(o,e){if("useFactory"in e&&e.useFactory){let r=e.useFactory;return [{provide:o,useFactory:r,inject:e.inject??[]}]}if("useClass"in e&&e.useClass){let r=e.useClass;return [{provide:o,useFactory:a(async t=>t.createModuleOptions(),"useFactory"),inject:[r]},r]}if("useExisting"in e&&e.useExisting){let r=e.useExisting;return [{provide:o,useFactory:a(async t=>t.createModuleOptions(),"useFactory"),inject:[r]}]}throw new Error("ModuleAsyncOptions must specify one of: useFactory, useClass, or useExisting")}a(it,"createAsyncProviders");var F=class{static{a(this,"ConfigurableModuleBuilder");}description;featureDescription;onForRoot;onForFeature;constructor(e="MODULE_OPTIONS"){this.description=e,this.featureDescription=e+"_FEATURE";}setTokenDescription(e){return this.description=e,this}transformDynamicModule(e){return this.onForRoot=e,this}transformFeatureModule(e){return this.onForFeature=e,this}build(){let e=new b(this.description),r=new b(this.featureDescription),t=this.onForRoot,s=this.onForFeature;return {ConfigurableModuleClass:class{static{a(this,"ConfigurableModuleClassImpl");}static forRoot(l,d={}){let c={module:this,global:d.global??false,providers:[{provide:e,useValue:l}],exports:[e]};return t&&(c=t(c,l)),c}static forRootAsync(l){let d=it(e,l);return {module:this,imports:l.imports??[],providers:d,exports:[e]}}static forFeature(l,d={}){let c={module:this,global:d.global??false,providers:[{provide:r,useValue:l}],exports:[r]};return s&&(c=s(c,l)),c}},MODULE_OPTIONS_TOKEN:e,MODULE_FEATURE_TOKEN:r}}};var _=class{static{a(this,"BaseExecutionContext");}nativeRequest;handler;container;query;params;body;rawBody;formData;auth;data=new Map;metadata=new Map;abortController;constructor(e,r,t,s={},a={},i){this.nativeRequest=e,this.handler=r,this.container=t,this.query=s,this.params=a,this.abortController=i??new AbortController;}getNativeRequest(){return this.nativeRequest}getHandler(){return this.handler}getBody(){return this.body}setBody(e){this.body=e;}getRawBody(){return this.rawBody}setRawBody(e){this.rawBody=e;}getFormData(){return this.formData}setFormData(e){this.formData=e;}getQuery(){return this.query}getParams(){return this.params}getAuth(){return this.auth}setAuth(e){this.auth=e;}getMetadata(e){return this.metadata.get(e)}setMetadata(e,r){this.metadata.set(e,r);}getData(e){return this.data.get(e)}setData(e,r){this.data.set(e,r);}getContainer(){return this.container}getSignal(){return this.abortController.signal}abort(e){this.abortController.abort(e);}};var Ge=Symbol("filters"),$e=Symbol("catch");function Be(...o){return (e,r,t)=>{let s=r?e.constructor:e,a=Reflect.getOwnMetadata(Ge,s)??[];Reflect.defineMetadata(Ge,[...a,...o],s);}}a(Be,"UseFilters");function Oe(...o){return e=>{Reflect.defineMetadata($e,o,e);}}a(Oe,"Catch");function V(o){return Reflect.getOwnMetadata($e,o)??[]}a(V,"getCatchMetadata");function T(o,e$1,r){return async t=>{let s=[...e$1.middlewares??[],...r.middlewares??[]],a$1=[...e$1.guards??[],...r.guards??[]],i=[...e$1.interceptors??[],...r.interceptors??[]],l=[...e$1.pipes??[],...r.pipes??[]],d=[...e$1.filters??[],...r.filters??[]],c=await C(o,d);try{g(t);let u=await C(o,s);return await ct(t,u,async()=>{g(t);let f=await C(o,a$1);for(let M of f)if(g(t),!await M.canActivate(t))throw new e("Access denied by guard");g(t);let h=await C(o,l);for(let M of h)g(t),await M.transform(t);g(t);let p=await C(o,i),se=a(async()=>(g(t),r.handler(t)),"handlerCall");return p.length===0?se():p.reduceRight((M,ae)=>async()=>(g(t),ae.intercept(t,M)),se)()})}catch(u){return lt(u,t,c)}}}a(T,"createPipeline");async function ct(o,e,r){return e.length===0?r():e.reduceRight((s,a)=>()=>a.use(o,s),r)()}a(ct,"runMiddlewareChain");function g(o){if(o.getSignal().aborted)throw new g$1}a(g,"checkAborted");async function lt(o,e,r){for(let t of r){let s=V(t.constructor);if(s.length===0||o instanceof Error&&s.some(i=>o instanceof i))return t.catch(o,e)}throw o}a(lt,"handleError");async function C(o,e){let r=[];for(let t of e)typeof t=="function"?r.push(await o.resolve(t)):r.push(t);return r}a(C,"resolveRefs");var K=Symbol("interceptors"),Y=Symbol("method:interceptors");function ze(...o){return (e,r,t)=>{if(r!==void 0){let a=t?.value??e,i=a[Y]??[];return a[Y]=[...i,...o],t}let s=Reflect.getOwnMetadata(K,e)??[];Reflect.defineMetadata(K,[...s,...o],e);}}a(ze,"UseInterceptors");function Q(o){return Reflect.getOwnMetadata(K,o)??[]}a(Q,"getInterceptorsMetadata");function J(o,e){let t=o.prototype?.[e];return typeof t=="function"&&t[Y]||[]}a(J,"getMethodInterceptors");function k(o,e){return [...Q(o),...J(o,e)]}a(k,"getEffectiveInterceptors");var Z="uow:session",X="uow:instance",U=class{static{a(this,"UnitOfWorkInterceptor");}factory;constructor(e){this.factory=e;}async intercept(e,r){let t=this.factory();await t.start(),e.setData(Z,t.getContext()),e.setData(X,t);try{let s=await r();return await t.commit(),s}catch(s){throw await t.rollback(),s}}};var ee=Symbol("middlewares"),te=Symbol("method:middlewares");function qe(...o){return (e,r,t)=>{if(r!==void 0){let a=t?.value??e,i=a[te]??[];return a[te]=[...i,...o],t}let s=Reflect.getOwnMetadata(ee,e)??[];Reflect.defineMetadata(ee,[...s,...o],e);}}a(qe,"UseMiddleware");function re(o){return Reflect.getOwnMetadata(ee,o)??[]}a(re,"getMiddlewaresMetadata");function oe(o,e){let t=o.prototype?.[e];return typeof t=="function"&&t[te]||[]}a(oe,"getMethodMiddlewares");function G(o,e){return [...re(o),...oe(o,e)]}a(G,"getEffectiveMiddlewares");var We=Symbol("pipes");function He(...o){return (e,r,t)=>{let s=r?e.constructor:e,a=Reflect.getOwnMetadata(We,s)??[];Reflect.defineMetadata(We,[...a,...o],s);}}a(He,"UsePipes");var ut=/^[0-9a-fA-F]{24}$/,$=class{static{a(this,"ParseIdPipe");}paramName;constructor(e="id"){this.paramName=e;}transform(e){let t=e.getParams()[this.paramName];if(!t||!ut.test(t))throw new c(`Invalid ${this.paramName}: must be a valid ObjectId`)}};var B=class{static{a(this,"ParseIntPipe");}transform(e){let r=Number(e);if(!Number.isInteger(r)||e===""||e===null||e===void 0)throw new c(`Expected an integer, received: ${JSON.stringify(e)}`);return r}};function Le(o){return {transform(e){return e??o}}}a(Le,"DefaultValuePipe");var O=class{static{a(this,"DomainEvent");}payload;timestamp;constructor(e){this.payload=e,this.timestamp=Date.now();}};var w=class{static{a(this,"ControllerRouter");}routes=[];globalPrefix;constructor(e=""){this.globalPrefix=e;}register(...e){for(let r of e){let t=l(r)??"",s=n(r);for(let a of s){let i=dt(`${this.globalPrefix}/${t}/${a.path}`);ht(i,r.name,a.methodName),this.checkDuplicate(i,a.method,r.name,a.methodName);let{pattern:l,paramNames:d}=ft(i),c=o(r,a.methodName),u=k(r,a.methodName),f=G(r,a.methodName);this.routes.push({method:a.method,pattern:l,paramNames:d,controllerClass:r,methodName:a.methodName,guardClasses:c,interceptorRefs:u,middlewareRefs:f,rawPath:i});}}this.routes.sort((r,t)=>je(r.rawPath)-je(t.rawPath));}checkDuplicate(e,r,t,s){let a=this.routes.find(i=>i.method===r&&i.rawPath===e);if(a)throw new Error(`Duplicate route: ${r} ${e}
|
|
2
2
|
Already registered by: ${a.controllerClass.name}.${a.methodName}
|
|
3
|
-
Conflicting with: ${t}.${s}`)}match(e,r){let t=e.toUpperCase();for(let s of this.routes){if(s.method!==t)continue;let a=s.pattern.exec(r);if(!a)continue;let i={};for(let u=0;u<s.paramNames.length;u++)i[s.paramNames[u]]=a[u+1]??"";return {route:s,params:i}}return null}getRoutes(){return this.routes}};function dt(o){return "/"+o.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}a(dt,"normalizePath");function ft(o){let e=[],r=o.split("/").map(t=>t.startsWith(":")?(e.push(t.slice(1)),"([^/]+)"):pt(t)).join("/");return {pattern:new RegExp(`^${r}$`),paramNames:e}}a(ft,"compilePath");function pt(o){return o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}a(pt,"escapeRegex");function je(o){return o.split("/").filter(Boolean).reduce((e,r)=>e+(r.startsWith(":")?1:0),0)}a(je,"routePriority");function ht(o,e,r){let t=`Invalid path "${o}" on ${e}.${r}:`;if(!o.startsWith("/"))throw new Error(`${t} must start with /`);let s=o.split("/").filter((i,u)=>u>0),a=new Set;for(let i of s){if(i==="")throw new Error(`${t} contains empty segment (double slash)`);if(i.startsWith(":")){let u=i.slice(1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u))throw new Error(`${t} invalid param name ":${u}" \u2014 must be a valid identifier`);if(a.has(u))throw new Error(`${t} duplicate param name ":${u}"`);a.add(u);}}}a(ht,"validatePath");var w=Symbol("route:params");function mt(o){return o==null?false:typeof o=="function"||typeof o=="object"&&typeof o.transform=="function"}a(mt,"isParamPipeRef");function z(o,e){return mt(o)?{key:void 0,pipes:[o,...e??[]]}:{key:o,pipes:e??[]}}a(z,"resolveArgs");function m(o,e,r=[]){return (t,s,a)=>{if(s===void 0)return;let i=t[s];if(typeof i!="function")return;let u=i[w]??[];i[w]=[...u,{index:a,type:o,key:e,pipes:r.length>0?r:void 0}];}}a(m,"buildBuiltinDecorator");function gt(o){return typeof o=="function"?new o:o}a(gt,"resolveParamPipe");function Ve(o,...e){let{key:r,pipes:t}=z(o,e);return m("query",r,t)}a(Ve,"Query");function Ke(o,...e){let{key:r,pipes:t}=z(o,e);return m("param",r,t)}a(Ke,"Param");function Ye(o,...e){let{key:r,pipes:t}=z(o,e);return m("body",r,t)}a(Ye,"Body");var Qe=a(()=>m("rawBody"),"RawBody"),Je=a(()=>m("formData"),"FormData"),Ze=a(()=>m("ip"),"Ip"),Xe=a(()=>m("userAgent"),"UserAgent"),et=a(o=>m("cookie",o),"Cookie");function tt(o,...e){let{key:r,pipes:t}=z(o,e);return m("headers",r,t)}a(tt,"Headers");function ne(o){return ()=>(e,r,t)=>{if(r===void 0)return;let s=e[r];if(typeof s!="function")return;let a=s[w]??[];s[w]=[...a,{index:t,type:"auth",extractor:o}];}}a(ne,"defineAuth");var rt=ne();function ot(o){return ()=>(e,r,t)=>{if(r===void 0)return;let s=e[r];if(typeof s!="function")return;let a=s[w]??[];s[w]=[...a,{index:t,type:"custom",extractor:o}];}}a(ot,"createParamDecorator");function q(o,e){let r=o.prototype[e];if(typeof r!="function")return null;let t=r[w];return t&&t.length>0?t:null}a(q,"getRouteParams");async function W(o,e){let r=Math.max(...o.map(s=>s.index)),t=new Array(r+1).fill(void 0);for(let{index:s,type:a,key:i,pipes:u,extractor:d}of o){let c;switch(a){case "query":{let l=e.getQuery();c=i!==void 0?l[i]:l;break}case "param":{let l=e.getParams();c=i!==void 0?l[i]:l;break}case "body":{let l=e.getBody()??{};c=i!==void 0?l[i]:l;break}case "rawBody":{c=e.getRawBody();break}case "formData":{c=e.getFormData();break}case "headers":{let l=e.getNativeRequest(),f=l?.node?.req?.headers??l?.headers??{};c=i!==void 0?f[i.toLowerCase()]:f;break}case "cookie":{let l=e.getNativeRequest(),f=l?.node?.req?.headers?.cookie??l?.headers?.cookie??"";if(i&&f){let h=f.split(";").map(p=>p.trim()).find(p=>p.startsWith(i+"="));c=h?decodeURIComponent(h.slice(i.length+1)):void 0;}else c=void 0;break}case "ip":{let l=e.getNativeRequest(),f=l?.node?.req?.headers??{},h=f["cf-connecting-ip"];if(h){c=h.trim();break}let p=f["x-forwarded-for"];if(p){c=(String(p).split(",")[0]??"").trim();break}c=l?.node?.req?.socket?.remoteAddress??"";break}case "userAgent":{c=(e.getNativeRequest()?.node?.req?.headers??{})["user-agent"]??"";break}case "auth":{c=d?await d(e):e.getAuth();break}case "custom":{c=d?await d(e):void 0;break}}if(u&&u.length>0)for(let l of u)c=gt(l).transform(c);t[s]=c;}return t}a(W,"resolveParamArgs");var nt="__redirect";function st(o,e=302){return {__redirect:true,url:o,statusCode:e}}a(st,"redirect");function H(o){return o!==null&&typeof o=="object"&&o.__redirect===true}a(H,"isRedirect");function at(){return !!(process.env.VERCEL||process.env.AWS_LAMBDA_FUNCTION_NAME||process.env.LAMBDA_TASK_ROOT||process.env.FUNCTIONS_WORKER_RUNTIME||process.env.K_SERVICE||process.env.NETLIFY)}a(at,"isServerless");var A=class{static{a(this,"TruxieApplication");}container;registry;initialized=false;rootModule;options;eventEmitter;prefix="";router;filters=[];gateways=new Map;wsInitialized=false;constructor(e,r={}){this.rootModule=e,this.options=r,this.container=new c$1,this.registry=new p;}async init(){if(this.initialized)return;this.eventEmitter=new q$1,this.options.eventBus&&this.eventEmitter.setOptions(this.options.eventBus),this.container.register({provide:q$1,useValue:this.eventEmitter});let e=new a$1;this.container.register({provide:a$1,useValue:e}),this.registry.scan(this.rootModule),this.registry.registerAll(this.container);let r=this.registry.getAllProviders();e._init(this.container,r),await this.registry.callLifecycleHooks(this.container,"onModuleInit"),await s(this.container,r),await this.registry.callLifecycleHooks(this.container,"onApplicationBootstrap"),this.router=new E(this.prefix),this.router.register(...this.registry.getAllControllers()),this.filters=this.options.globalFilters??[],this.initialized=true;}setGlobalPrefix(e){return this.prefix=e,this}getGlobalPrefix(){return this.prefix}async resolve(e){return this.ensureInitialized(),this.container.resolve(e)}has(e){return this.container.has(e)}getContainer(){return this.container}matchRoute(e,r){return this.ensureInitialized(),this.router.match(e,r)??null}async handleRequest(e$1,r){this.ensureInitialized();let{container:t,dispose:s}=this.createRequestContext();try{let a=await t.resolve(e$1.controllerClass),i=a[e$1.methodName].bind(a),u=q(e$1.controllerClass,e$1.methodName);try{for(let c of e$1.guardClasses)if(!await(t.has(c)?await t.resolve(c):new c).canActivate(r))throw new e("Access denied by guard");let d=u?await i(...await W(u,r)):await i(r);if(H(d)){let c=d;return {value:d,isRedirect:!0,redirectUrl:c.url,redirectStatus:c.statusCode}}return {value:d,isRedirect:!1}}catch(d){for(let c of this.filters)try{return {value:await c.catch(d,r),isRedirect:!1}}catch{continue}throw d}}finally{await s();}}hasGateways(){return this.ensureInitialized(),this.registry.getAllGateways().length>0}async createWebSocketHooks(e){this.ensureInitialized(),await this.initGateways();let r=this;return {async open(t){let a="/"+(e.getUrl(t).split("?")[0]??"/").replace(/^\/+|\/+$/g,""),i=r.matchGatewayPath(a);if(!i)return;let u=t.context;u&&(u._gatewayPath=i);let d=r.gateways.get(i),c=e.adaptPeer(t);for(let l of d.serverProps)d.instance[l]={peers:e.getPeers(t)??new Set};if(d.hasConnection)try{await d.instance.handleConnection(c);}catch(l){console.error(`[WS] ${d.className}.handleConnection error:`,l);}},async message(t,s){let i=t.context?._gatewayPath;if(!i)return;let u=r.gateways.get(i);if(!u)return;let d=e.adaptPeer(t),c=e.adaptMessage(s),l;try{l=c.json();}catch{return}if(!l.event||typeof l.event!="string")return;let f=u.messageHandlers.get(l.event);if(f)try{let h=n$1(f.paramMeta,d,c,l.data),p=await f.method(...h);p!=null&&d.send(p);}catch(h){console.error(`[WS] ${u.className}.${l.event} error:`,h);}},async close(t,s){let i=t.context?._gatewayPath;if(!i)return;let u=r.gateways.get(i);if(!u?.hasDisconnect)return;let d=e.adaptPeer(t);try{await u.instance.handleDisconnect(d,s);}catch(c){console.error(`[WS] ${u.className}.handleDisconnect error:`,c);}},async error(t,s){let a=t?.id??"unknown";console.error(`[WS] Peer ${String(a)} error:`,s);}}}getControllers(){return this.ensureInitialized(),this.registry.getAllControllers()}getGateways(){return this.ensureInitialized(),this.registry.getAllGateways()}getProviders(){return this.ensureInitialized(),this.registry.getAllProviders()}getEventEmitter(){return this.ensureInitialized(),this.eventEmitter}getRouter(){return this.ensureInitialized(),this.router}createHandler(e){return this.ensureInitialized(),T(this.container,this.getGlobalOptions(),e)}async shutdown(){this.initialized&&(await this.registry.callLifecycleHooks(this.container,"onModuleDestroy"),await this.registry.callLifecycleHooks(this.container,"onApplicationShutdown"),this.eventEmitter.clear(),await this.container.dispose(),this.initialized=false);}createRequestContext(){if(!this.container.hasRequestScoped())return {container:this.container,dispose:a(async()=>{},"dispose")};let e=this.container.createChild();return {container:e,dispose:a(()=>e.dispose(),"dispose")}}matchGatewayPath(e){if(this.gateways.has(e))return e;for(let r of this.gateways.keys())if(e.endsWith(r))return r;if(this.gateways.has("/"))return "/"}async initGateways(){if(!this.wsInitialized){for(let e of this.registry.getAllGateways()){let r=i(e);if(!r)continue;let t=await this.container.resolve(e),s=new Map;for(let a of j(e)){let i=t[a.methodName];typeof i=="function"&&s.set(a.event,{method:i.bind(t),paramMeta:k$1(e.prototype[a.methodName])});}if(this.gateways.set(r.path,{instance:t,className:e.name,messageHandlers:s,hasConnection:typeof t.handleConnection=="function",hasDisconnect:typeof t.handleDisconnect=="function",serverProps:m$1(e)}),typeof t.afterInit=="function")try{await t.afterInit();}catch{}}this.wsInitialized=true;}}getGlobalOptions(){return {guards:this.options.globalGuards,interceptors:this.options.globalInterceptors,pipes:this.options.globalPipes,filters:this.options.globalFilters}}ensureInitialized(){if(!this.initialized)throw new Error("TruxieApplication not initialized. Call TruxieFactory.create() or app.init().")}},L=class{static{a(this,"TruxieFactory");}static async create(e,r){let t=new A(e,r);return await t.init(),t}};export{rt as Auth,_ as BaseExecutionContext,Ye as Body,Oe as Catch,F as ConfigurableModuleBuilder,E as ControllerRouter,et as Cookie,Le as DefaultValuePipe,O as DomainEvent,Je as FormData,tt as Headers,Ze as Ip,Ke as Param,$ as ParseIdPipe,B as ParseIntPipe,Ve as Query,nt as REDIRECT_BRAND,Qe as RawBody,A as TruxieApplication,L as TruxieFactory,X as UOW_INSTANCE_KEY,Z as UOW_SESSION_KEY,U as UnitOfWorkInterceptor,Be as UseFilters,ze as UseInterceptors,qe as UseMiddleware,He as UsePipes,Xe as UserAgent,ot as createParamDecorator,T as createPipeline,ne as defineAuth,k as getEffectiveInterceptors,G as getEffectiveMiddlewares,Q as getInterceptorsMetadata,J as getMethodInterceptors,oe as getMethodMiddlewares,re as getMiddlewaresMetadata,q as getRouteParams,H as isRedirect,at as isServerless,st as redirect,W as resolveParamArgs};
|
|
3
|
+
Conflicting with: ${t}.${s}`)}match(e,r){let t=e.toUpperCase();for(let s of this.routes){if(s.method!==t)continue;let a=s.pattern.exec(r);if(!a)continue;let i={};for(let l=0;l<s.paramNames.length;l++)i[s.paramNames[l]]=a[l+1]??"";return {route:s,params:i}}return null}getRoutes(){return this.routes}};function dt(o){return "/"+o.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}a(dt,"normalizePath");function ft(o){let e=[],r=o.split("/").map(t=>t.startsWith(":")?(e.push(t.slice(1)),"([^/]+)"):pt(t)).join("/");return {pattern:new RegExp(`^${r}$`),paramNames:e}}a(ft,"compilePath");function pt(o){return o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}a(pt,"escapeRegex");function je(o){return o.split("/").filter(Boolean).reduce((e,r)=>e+(r.startsWith(":")?1:0),0)}a(je,"routePriority");function ht(o,e,r){let t=`Invalid path "${o}" on ${e}.${r}:`;if(!o.startsWith("/"))throw new Error(`${t} must start with /`);let s=o.split("/").filter((i,l)=>l>0),a=new Set;for(let i of s){if(i==="")throw new Error(`${t} contains empty segment (double slash)`);if(i.startsWith(":")){let l=i.slice(1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l))throw new Error(`${t} invalid param name ":${l}" \u2014 must be a valid identifier`);if(a.has(l))throw new Error(`${t} duplicate param name ":${l}"`);a.add(l);}}}a(ht,"validatePath");var y=Symbol("route:params");function mt(o){return o==null?false:typeof o=="function"||typeof o=="object"&&typeof o.transform=="function"}a(mt,"isParamPipeRef");function z(o,e){return mt(o)?{key:void 0,pipes:[o,...e??[]]}:{key:o,pipes:e??[]}}a(z,"resolveArgs");function m(o,e,r=[]){return (t,s,a)=>{if(s===void 0)return;let i=t[s];if(typeof i!="function")return;let l=i[y]??[];i[y]=[...l,{index:a,type:o,key:e,pipes:r.length>0?r:void 0}];}}a(m,"buildBuiltinDecorator");function gt(o){return typeof o=="function"?new o:o}a(gt,"resolveParamPipe");function Ve(o,...e){let{key:r,pipes:t}=z(o,e);return m("query",r,t)}a(Ve,"Query");function Ke(o,...e){let{key:r,pipes:t}=z(o,e);return m("param",r,t)}a(Ke,"Param");function Ye(o,...e){let{key:r,pipes:t}=z(o,e);return m("body",r,t)}a(Ye,"Body");var Qe=a(()=>m("rawBody"),"RawBody"),Je=a(()=>m("formData"),"FormData"),Ze=a(()=>m("ip"),"Ip"),Xe=a(()=>m("userAgent"),"UserAgent"),et=a(o=>m("cookie",o),"Cookie");function tt(o,...e){let{key:r,pipes:t}=z(o,e);return m("headers",r,t)}a(tt,"Headers");function ne(o){return ()=>(e,r,t)=>{if(r===void 0)return;let s=e[r];if(typeof s!="function")return;let a=s[y]??[];s[y]=[...a,{index:t,type:"auth",extractor:o}];}}a(ne,"defineAuth");var rt=ne();function ot(o){return ()=>(e,r,t)=>{if(r===void 0)return;let s=e[r];if(typeof s!="function")return;let a=s[y]??[];s[y]=[...a,{index:t,type:"custom",extractor:o}];}}a(ot,"createParamDecorator");function q(o,e){let r=o.prototype[e];if(typeof r!="function")return null;let t=r[y];return t&&t.length>0?t:null}a(q,"getRouteParams");async function W(o,e){let r=Math.max(...o.map(s=>s.index)),t=new Array(r+1).fill(void 0);for(let{index:s,type:a,key:i,pipes:l,extractor:d}of o){let c;switch(a){case "query":{let u=e.getQuery();c=i!==void 0?u[i]:u;break}case "param":{let u=e.getParams();c=i!==void 0?u[i]:u;break}case "body":{let u=e.getBody()??{};c=i!==void 0?u[i]:u;break}case "rawBody":{c=e.getRawBody();break}case "formData":{c=e.getFormData();break}case "headers":{let u=e.getNativeRequest(),f=u?.node?.req?.headers??u?.headers??{};c=i!==void 0?f[i.toLowerCase()]:f;break}case "cookie":{let u=e.getNativeRequest(),f=u?.node?.req?.headers?.cookie??u?.headers?.cookie??"";if(i&&f){let h=f.split(";").map(p=>p.trim()).find(p=>p.startsWith(i+"="));c=h?decodeURIComponent(h.slice(i.length+1)):void 0;}else c=void 0;break}case "ip":{let u=e.getNativeRequest(),f=u?.node?.req?.headers??{},h=f["cf-connecting-ip"];if(h){c=h.trim();break}let p=f["x-forwarded-for"];if(p){c=(String(p).split(",")[0]??"").trim();break}c=u?.node?.req?.socket?.remoteAddress??"";break}case "userAgent":{c=(e.getNativeRequest()?.node?.req?.headers??{})["user-agent"]??"";break}case "auth":{c=d?await d(e):e.getAuth();break}case "custom":{c=d?await d(e):void 0;break}}if(l&&l.length>0)for(let u of l)c=gt(u).transform(c);t[s]=c;}return t}a(W,"resolveParamArgs");var nt="__redirect";function st(o,e=302){return {__redirect:true,url:o,statusCode:e}}a(st,"redirect");function H(o){return o!==null&&typeof o=="object"&&o.__redirect===true}a(H,"isRedirect");function at(){return !!(process.env.VERCEL||process.env.AWS_LAMBDA_FUNCTION_NAME||process.env.LAMBDA_TASK_ROOT||process.env.FUNCTIONS_WORKER_RUNTIME||process.env.K_SERVICE||process.env.NETLIFY)}a(at,"isServerless");var A=class{static{a(this,"TruxieApplication");}container;registry;initialized=false;rootModule;options;eventEmitter;prefix="";router;filters=[];gateways=new Map;wsInitialized=false;constructor(e,r={}){this.rootModule=e,this.options=r,this.container=new c$1,this.registry=new p;}async init(){if(this.initialized)return;this.eventEmitter=new q$1,this.options.eventBus&&this.eventEmitter.setOptions(this.options.eventBus),this.container.register({provide:q$1,useValue:this.eventEmitter});let e=new a$1;this.container.register({provide:a$1,useValue:e}),this.registry.scan(this.rootModule),this.registry.registerAll(this.container);let r=this.registry.getAllProviders();e._init(this.container,r),await this.registry.callLifecycleHooks(this.container,"onModuleInit"),await s(this.container,r),await this.registry.callLifecycleHooks(this.container,"onApplicationBootstrap"),this.router=new w(this.prefix),this.router.register(...this.registry.getAllControllers()),this.filters=this.options.globalFilters??[],this.initialized=true;}setGlobalPrefix(e){return this.prefix=e,this.initialized&&(this.router=new w(this.prefix),this.router.register(...this.registry.getAllControllers())),this}getGlobalPrefix(){return this.prefix}async resolve(e){return this.ensureInitialized(),this.container.resolve(e)}has(e){return this.container.has(e)}getContainer(){return this.container}matchRoute(e,r){return this.ensureInitialized(),this.router.match(e,r)??null}async handleRequest(e$1,r){this.ensureInitialized();let{container:t,dispose:s}=this.createRequestContext();try{let a=await t.resolve(e$1.controllerClass),i=a[e$1.methodName].bind(a),l=q(e$1.controllerClass,e$1.methodName);try{for(let c of e$1.guardClasses)if(!await(t.has(c)?await t.resolve(c):new c).canActivate(r))throw new e("Access denied by guard");let d=l?await i(...await W(l,r)):await i(r);if(H(d)){let c=d;return {value:d,isRedirect:!0,redirectUrl:c.url,redirectStatus:c.statusCode}}return {value:d,isRedirect:!1}}catch(d){for(let c of this.filters)try{return {value:await c.catch(d,r),isRedirect:!1}}catch{continue}throw d}}finally{await s();}}hasGateways(){return this.ensureInitialized(),this.registry.getAllGateways().length>0}async createWebSocketHooks(e){this.ensureInitialized(),await this.initGateways();let r=this;return {async open(t){let a="/"+(e.getUrl(t).split("?")[0]??"/").replace(/^\/+|\/+$/g,""),i=r.matchGatewayPath(a);if(!i)return;let l=t.context;l&&(l._gatewayPath=i);let d=r.gateways.get(i),c=e.adaptPeer(t);for(let u of d.serverProps)d.instance[u]={peers:e.getPeers(t)??new Set};if(d.hasConnection)try{await d.instance.handleConnection(c);}catch(u){console.error(`[WS] ${d.className}.handleConnection error:`,u);}},async message(t,s){let i=t.context?._gatewayPath;if(!i)return;let l=r.gateways.get(i);if(!l)return;let d=e.adaptPeer(t),c=e.adaptMessage(s),u;try{u=c.json();}catch{return}if(!u.event||typeof u.event!="string")return;let f=l.messageHandlers.get(u.event);if(f)try{let h=n$1(f.paramMeta,d,c,u.data),p=await f.method(...h);p!=null&&d.send(p);}catch(h){console.error(`[WS] ${l.className}.${u.event} error:`,h);}},async close(t,s){let i=t.context?._gatewayPath;if(!i)return;let l=r.gateways.get(i);if(!l?.hasDisconnect)return;let d=e.adaptPeer(t);try{await l.instance.handleDisconnect(d,s);}catch(c){console.error(`[WS] ${l.className}.handleDisconnect error:`,c);}},async error(t,s){let a=t?.id??"unknown";console.error(`[WS] Peer ${String(a)} error:`,s);}}}getControllers(){return this.ensureInitialized(),this.registry.getAllControllers()}getGateways(){return this.ensureInitialized(),this.registry.getAllGateways()}getProviders(){return this.ensureInitialized(),this.registry.getAllProviders()}getEventEmitter(){return this.ensureInitialized(),this.eventEmitter}getRouter(){return this.ensureInitialized(),this.router}createHandler(e){return this.ensureInitialized(),T(this.container,this.getGlobalOptions(),e)}async shutdown(){this.initialized&&(await this.registry.callLifecycleHooks(this.container,"onModuleDestroy"),await this.registry.callLifecycleHooks(this.container,"onApplicationShutdown"),this.eventEmitter.clear(),await this.container.dispose(),this.initialized=false);}createRequestContext(){if(!this.container.hasRequestScoped())return {container:this.container,dispose:a(async()=>{},"dispose")};let e=this.container.createChild();return {container:e,dispose:a(()=>e.dispose(),"dispose")}}matchGatewayPath(e){if(this.gateways.has(e))return e;for(let r of this.gateways.keys())if(e.endsWith(r))return r;if(this.gateways.has("/"))return "/"}async initGateways(){if(!this.wsInitialized){for(let e of this.registry.getAllGateways()){let r=i(e);if(!r)continue;let t=await this.container.resolve(e),s=new Map;for(let a of j(e)){let i=t[a.methodName];typeof i=="function"&&s.set(a.event,{method:i.bind(t),paramMeta:k$1(e.prototype[a.methodName])});}if(this.gateways.set(r.path,{instance:t,className:e.name,messageHandlers:s,hasConnection:typeof t.handleConnection=="function",hasDisconnect:typeof t.handleDisconnect=="function",serverProps:m$1(e)}),typeof t.afterInit=="function")try{await t.afterInit();}catch{}}this.wsInitialized=true;}}getGlobalOptions(){return {guards:this.options.globalGuards,interceptors:this.options.globalInterceptors,pipes:this.options.globalPipes,filters:this.options.globalFilters}}ensureInitialized(){if(!this.initialized)throw new Error("TruxieApplication not initialized. Call TruxieFactory.create() or app.init().")}},L=class{static{a(this,"TruxieFactory");}static async create(e,r){let t=new A(e,r);return await t.init(),t}};export{rt as Auth,_ as BaseExecutionContext,Ye as Body,Oe as Catch,F as ConfigurableModuleBuilder,w as ControllerRouter,et as Cookie,Le as DefaultValuePipe,O as DomainEvent,Je as FormData,tt as Headers,Ze as Ip,Ke as Param,$ as ParseIdPipe,B as ParseIntPipe,Ve as Query,nt as REDIRECT_BRAND,Qe as RawBody,A as TruxieApplication,L as TruxieFactory,X as UOW_INSTANCE_KEY,Z as UOW_SESSION_KEY,U as UnitOfWorkInterceptor,Be as UseFilters,ze as UseInterceptors,qe as UseMiddleware,He as UsePipes,Xe as UserAgent,ot as createParamDecorator,T as createPipeline,ne as defineAuth,k as getEffectiveInterceptors,G as getEffectiveMiddlewares,Q as getInterceptorsMetadata,J as getMethodInterceptors,oe as getMethodMiddlewares,re as getMiddlewaresMetadata,q as getRouteParams,H as isRedirect,at as isServerless,st as redirect,W as resolveParamArgs};
|
package/package.json
CHANGED