truxie 0.1.0-test.4 → 0.1.0-test.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -524,6 +524,27 @@ declare class ZodParamPipe<T> implements ParamPipe {
524
524
  */
525
525
  declare function DefaultValuePipe(defaultValue: unknown): ParamPipe;
526
526
 
527
+ /**
528
+ * Factory that creates a typed `@Body()` parameter decorator which
529
+ * validates the request body against a Zod schema.
530
+ *
531
+ * @example
532
+ * ```ts
533
+ * const createUserSchema = z.object({
534
+ * email: z.string().email(),
535
+ * name: z.string().min(1),
536
+ * })
537
+ *
538
+ * const CreateUserDTO = ZodValidatedBody(createUserSchema)
539
+ *
540
+ * @Post('/')
541
+ * async create(@CreateUserDTO() body) {
542
+ * // body is parsed & validated — z.infer<typeof createUserSchema>
543
+ * }
544
+ * ```
545
+ */
546
+ declare function ZodValidatedBody<T extends ZodSchema>(schema: T): () => ParameterDecorator;
547
+
527
548
  declare function UseFilters(...filters: FilterRef[]): ClassDecorator & MethodDecorator;
528
549
  declare function Catch(...exceptions: Type<Error>[]): ClassDecorator;
529
550
 
@@ -907,6 +928,35 @@ declare function createParamDecorator<T = unknown>(extractor: (ctx: ExecutionCon
907
928
  declare function getRouteParams(controllerClass: Function, methodName: string): RouteParamMetadata[] | null;
908
929
  declare function resolveParamArgs(meta: RouteParamMetadata[], ctx: ExecutionContext): Promise<unknown[]>;
909
930
 
931
+ /** Sentinel brand for redirect detection by framework adapters. */
932
+ declare const REDIRECT_BRAND: "__redirect";
933
+ interface RedirectResult {
934
+ [REDIRECT_BRAND]: true;
935
+ url: string;
936
+ statusCode: number;
937
+ }
938
+ /**
939
+ * Return this from a controller method to trigger an HTTP redirect.
940
+ * The framework adapter (e.g. Nitro) detects the branded object and
941
+ * performs the actual redirect.
942
+ *
943
+ * @example
944
+ * ```ts
945
+ * @Get('/old-path')
946
+ * async legacy() {
947
+ * return redirect('/new-path')
948
+ * }
949
+ *
950
+ * @Get('/external')
951
+ * async external() {
952
+ * return redirect('https://example.com', 301)
953
+ * }
954
+ * ```
955
+ */
956
+ declare function redirect(url: string, statusCode?: number): RedirectResult;
957
+ /** Type guard to check if a controller return value is a redirect. */
958
+ declare function isRedirect(value: unknown): value is RedirectResult;
959
+
910
960
  /**
911
961
  * Provides runtime access to registered providers and the DI container.
912
962
  *
@@ -986,4 +1036,4 @@ declare class BackendApplication {
986
1036
  private ensureInitialized;
987
1037
  }
988
1038
 
989
- export { AppError, type ApplicationOptions, Auth, type AuthExtractorFn, BackendApplication, BaseExecutionContext, Body, Catch, type CompiledRoute, ConfigurableModuleBuilder, type ConfigurableModuleBuilderResult, type ConfigurableModuleClass, ConflictError, Container, Controller, ControllerRouter, Cookie, type CreatePipelineOptions, DefaultValuePipe, Delete, DiscoveryService, DomainEvent, DynamicModule, EventBus, type EventBusOptions, type EventHandler, type ExceptionFilter, type ExecutionContext, type ExtraOptions, type FeatureConfig, type FilterRef, ForbiddenError, FormData, type FormDataPart, ForwardRef, Get, Global, type GuardClass, type GuardInstance, type GuardRef, type HandlerFn, Headers, type HttpMethod, type ICanActivateGuard, type IUseCase, Inject, Injectable, InjectableOptions, type Interceptor, type InterceptorRef, Ip, type Middleware, type MiddlewareRef, Module, ModuleAsyncOptions, ModuleMetadata, ModuleRegistry, NoGuard, NotFoundError, type OnApplicationBootstrap, type OnApplicationShutdown, OnEvent, type OnModuleDestroy, type OnModuleInit, Optional, Param, type ParamPipe, type ParamPipeRef, ParseIdPipe, ParseIntPipe, Patch, type PipeRef, type PipeTransform, type PipelineOptions, Post, Provider, Put, Query, RawBody, RequestAbortedError, RouteGuards, type RouteMatch, type RouteMetadata, type RouteParamMetadata, type RouteParamType, Token, Type, UOW_INSTANCE_KEY, UOW_SESSION_KEY, UnauthorizedError, type UnitOfWork, type UnitOfWorkFactory, UnitOfWorkInterceptor, UseFilters, UseInterceptors, UseMiddleware, UsePipes, UserAgent, ValidationError, ZodParamPipe, ZodValidationPipe, createParamDecorator, createPipeline, defineAuth, forwardRef, getControllerGuards, getControllerPath, getEffectiveInterceptors, getEffectiveMiddlewares, getInterceptorsMetadata, getMethodGuards, getMethodInterceptors, getMethodMiddlewares, getMiddlewaresMetadata, getModuleMetadata, getRouteMetadata, getRouteParams, isGlobalModule, resolveForwardRef, resolveParamArgs };
1039
+ export { AppError, type ApplicationOptions, Auth, type AuthExtractorFn, BackendApplication, BaseExecutionContext, Body, Catch, type CompiledRoute, ConfigurableModuleBuilder, type ConfigurableModuleBuilderResult, type ConfigurableModuleClass, ConflictError, Container, Controller, ControllerRouter, Cookie, type CreatePipelineOptions, DefaultValuePipe, Delete, DiscoveryService, DomainEvent, DynamicModule, EventBus, type EventBusOptions, type EventHandler, type ExceptionFilter, type ExecutionContext, type ExtraOptions, type FeatureConfig, type FilterRef, ForbiddenError, FormData, type FormDataPart, ForwardRef, Get, Global, type GuardClass, type GuardInstance, type GuardRef, type HandlerFn, Headers, type HttpMethod, type ICanActivateGuard, type IUseCase, Inject, Injectable, InjectableOptions, type Interceptor, type InterceptorRef, Ip, type Middleware, type MiddlewareRef, Module, ModuleAsyncOptions, ModuleMetadata, ModuleRegistry, NoGuard, NotFoundError, type OnApplicationBootstrap, type OnApplicationShutdown, OnEvent, type OnModuleDestroy, type OnModuleInit, Optional, Param, type ParamPipe, type ParamPipeRef, ParseIdPipe, ParseIntPipe, Patch, type PipeRef, type PipeTransform, type PipelineOptions, Post, Provider, Put, Query, REDIRECT_BRAND, RawBody, type RedirectResult, RequestAbortedError, RouteGuards, type RouteMatch, type RouteMetadata, type RouteParamMetadata, type RouteParamType, Token, Type, UOW_INSTANCE_KEY, UOW_SESSION_KEY, UnauthorizedError, type UnitOfWork, type UnitOfWorkFactory, UnitOfWorkInterceptor, UseFilters, UseInterceptors, UseMiddleware, UsePipes, UserAgent, ValidationError, ZodParamPipe, ZodValidatedBody, ZodValidationPipe, createParamDecorator, createPipeline, defineAuth, forwardRef, getControllerGuards, getControllerPath, getEffectiveInterceptors, getEffectiveMiddlewares, getInterceptorsMetadata, getMethodGuards, getMethodInterceptors, getMethodMiddlewares, getMiddlewaresMetadata, getModuleMetadata, getRouteMetadata, getRouteParams, isGlobalModule, isRedirect, redirect, resolveForwardRef, resolveParamArgs };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import {c as c$2,e as e$1,g as g$1}from'./chunk-XVPJFMLQ.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-XVPJFMLQ.js';import {c as c$1,d,e}from'./chunk-F5KXBDV2.js';export{e as DiscoveryService,b as Global,a as Module,c as getModuleMetadata,d as isGlobalModule}from'./chunk-F5KXBDV2.js';import {a,g,b as b$1,h as h$1,i,j as j$1,c,d as d$1}from'./chunk-RMR6UXWO.js';export{e as Inject,d as Injectable,f as Optional,b as Scope}from'./chunk-RMR6UXWO.js';import'reflect-metadata';function Ne(o){return {forwardRef:o}}a(Ne,"forwardRef");function U(o){return typeof o=="object"&&"forwardRef"in o?o.forwardRef():o}a(U,"resolveForwardRef");var E=class o{static{a(this,"Container");}registrations=new Map;resolving=new Set;parent=null;children=[];register(...e){for(let t of e)this.registerOne(t);}registerOne(e){if(typeof e=="function"){let s=g(e)?.scope??b$1.SINGLETON;this.registrations.set(e,{provider:e,scope:s});return}let t=e.provide,r=b$1.SINGLETON;if("useClass"in e){let n=g(e.useClass);r=e.scope??n?.scope??b$1.SINGLETON;}else "useFactory"in e&&(r=e.scope??b$1.SINGLETON);this.registrations.set(t,{provider:e,scope:r});}async resolve(e){let t=U(e),r=t!==e?t:e,n=this.registrations.get(r)??this.parent?.findRegistration(r);if(!n)throw new Error(`No provider found for ${ee(r)}`);if(n.scope===b$1.SINGLETON&&n.instance!==void 0||n.scope===b$1.REQUEST&&this.parent!==null&&n.instance!==void 0)return n.instance;if(this.resolving.has(r))throw new Error(`Circular dependency detected for ${ee(r)}`);this.resolving.add(r);try{let s=await this.createInstance(n);return (n.scope===b$1.SINGLETON||n.scope===b$1.REQUEST&&this.parent!==null)&&(n.instance=s),s}finally{this.resolving.delete(r);}}has(e){return this.registrations.has(e)||(this.parent?.has(e)??false)}findRegistration(e){return this.registrations.get(e)??this.parent?.findRegistration(e)}createChild(){let e=new o;e.parent=this;for(let[t,r]of this.registrations)r.scope===b$1.REQUEST&&e.registrations.set(t,{provider:r.provider,scope:b$1.REQUEST,instance:void 0});return this.children.push(e),e}async dispose(){for(let e of this.children)await e.dispose();this.children=[];for(let[,e]of this.registrations)if(e.instance&&typeof e.instance=="object"&&e.instance!==null){let t=e.instance;typeof t.onModuleDestroy=="function"&&await t.onModuleDestroy();}this.registrations.clear(),this.resolving.clear();}async createInstance(e){let{provider:t}=e;if(typeof t=="function")return this.instantiateClass(t);if("useValue"in t)return t.useValue;if("useClass"in t)return this.instantiateClass(t.useClass);if("useFactory"in t){let r=t,n=[];if(r.inject)for(let s of r.inject)n.push(await this.resolve(s));return r.useFactory(...n)}if("useExisting"in t)return this.resolve(t.useExisting);throw new Error("Unknown provider type")}async instantiateClass(e){let t=Reflect.getMetadata("design:paramtypes",e)??[],r=h$1(e),n=i(e),s=j$1(e),a=n.size>0?Math.max(...n.keys())+1:0,c=Math.max(t.length,a,r.length),f=[];for(let d=0;d<c;d++){let u=n.get(d)??r[d]??t[d],l=s.has(d);try{f.push(await this.resolve(u));}catch{if(l)f.push(void 0);else throw new Error(`Cannot resolve parameter at index ${d} (${ee(u)}) of ${e.name}`)}}return new e(...f)}};function ee(o){return typeof o=="string"?o:typeof o=="symbol"||o instanceof c?o.toString():typeof o=="function"?o.name:String(o)}a(ee,"tokenToString");var De=Symbol("controller:path"),te=Symbol("controller:guards"),re=Symbol("route:metadata"),oe=Symbol("method:route"),S=Symbol("method:guards"),ne=Symbol("method:noguard");function Fe(o){return e=>{Reflect.defineMetadata(De,o,e);}}a(Fe,"Controller");function I(o){return (e="")=>(t,r,n)=>{let s=n!==void 0,a=String(s?r:r?.name??r),c=s?n?.value:t;if(typeof c=="function"&&(c[oe]={method:o,path:e,methodName:a}),s){let f=Reflect.getOwnMetadata(re,t.constructor)??[];return f.push({method:o,path:e,methodName:a}),Reflect.defineMetadata(re,f,t.constructor),n}return t}}a(I,"createMethodDecorator");var Oe=I("GET"),_e=I("POST"),ke=I("PUT"),Ue=I("DELETE"),$e=I("PATCH");function Ge(...o){return (e,t,r)=>{if(t==null){Reflect.defineMetadata(te,o,e);return}if(r!==void 0){if(r?.value){let n=r.value[S]??[];r.value[S]=[...n,...o];}return r}if(typeof e=="function"){let n=e[S]??[];e[S]=[...n,...o];}return typeof e=="function"&&t?.kind==="class"&&Reflect.defineMetadata(te,o,e),e}}a(Ge,"RouteGuards");function Be(){return (o,e,t)=>t!==void 0?(t?.value&&(t.value[ne]=true),t):(typeof o=="function"&&(o[ne]=true),o)}a(Be,"NoGuard");function M(o){return Reflect.getOwnMetadata(De,o)}a(M,"getControllerPath");function se(o){return Reflect.getOwnMetadata(te,o)??[]}a(se,"getControllerGuards");function $(o){let e=[],t=o.prototype;if(t){let r=Object.getOwnPropertyNames(t);for(let n of r){if(n==="constructor")continue;let s=t[n];typeof s=="function"&&s[oe]&&e.push(s[oe]);}}return e.length>0?e:Reflect.getOwnMetadata(re,o)??[]}a($,"getRouteMetadata");function G(o,e){let r=o.prototype?.[e],n=typeof r=="function"&&r[ne]===true,s=typeof r=="function"&&r[S]||[];return n?s:[...se(o),...s]}a(G,"getMethodGuards");var b=class{static{a(this,"ModuleRegistry");}resolved=new Map;sortedModules=[];scan(e){this.resolveModule(e),this.sortedModules=this.topologicalSort(),this.validateExports();}registerAll(e){let t=new Set;for(let r of this.sortedModules)if(r.global)for(let n of r.providers)t.add(n);t.size>0&&e.register(...t);for(let r of this.sortedModules){e.register(...r.providers);for(let n of r.metadata.imports??[]){let s=this.getModuleType(n),a=this.resolved.get(s);if(a)for(let c of a.exports){let f=this.findProvider(a,c)??this.findReExportedProvider(a,c);f&&e.register(f);}}}}getAllProviders(){let e=[];for(let t of this.sortedModules)e.push(...t.providers);return e}getAllControllers(){let e=new Set,t=[];for(let r of this.sortedModules){for(let n of r.controllers)e.has(n)||(e.add(n),t.push(n));for(let n of r.metadata.providers??[])typeof n=="function"&&M(n)!==void 0&&!e.has(n)&&(e.add(n),t.push(n));}return t}async callLifecycleHooks(e,t,r){for(let n of this.sortedModules)for(let s of n.providers){let a=typeof s=="function"?s:s.provide;if(e.has(a))try{let c=await e.resolve(a);c&&typeof c=="object"&&typeof c[t]=="function"&&await c[t](r);}catch{}}}resolveModule(e){let t=typeof e=="object"&&"module"in e,r=t?e.module:e;if(this.resolved.has(r))return this.resolved.get(r);let n=c$1(r)??{},s=t?e:{},a=[...n.controllers??[],...s.controllers??[]],c={imports:[...n.imports??[],...s.imports??[]],controllers:a,providers:[...n.providers??[],...s.providers??[]],exports:[...n.exports??[],...s.exports??[]]},f={type:r,metadata:c,controllers:a,providers:[...a,...c.providers??[]],exports:new Set(c.exports??[]),global:t?e.global??d(r):d(r)};this.resolved.set(r,f);for(let d of c.imports??[])this.resolveModule(d);return f}getVisibleTokens(e){let t=new Set;for(let r of e.providers)t.add(this.getProviderToken(r));for(let r of e.metadata.imports??[]){let n=this.getModuleType(r),s=this.resolved.get(n);if(s)for(let a of s.exports)t.add(a);}for(let r of this.sortedModules)if(r.global)for(let n of r.providers)t.add(this.getProviderToken(n));return t}validateExports(){for(let e of this.sortedModules){let t=new Set(e.providers.map(n=>this.getProviderToken(n))),r=this.collectImportedExports(e);for(let n of e.exports)if(!t.has(n)&&!r.has(n)){let s=typeof n=="function"?n.name:String(n);throw new Error(`${e.type.name} exports ${s} but it is not in its providers and is not re-exported from an imported module`)}}}validateVisibility(){for(let e of this.sortedModules){let t=this.getVisibleTokens(e);for(let r of e.providers){if(typeof r!="function")continue;let n=h$1(r);for(let s of n)if(!t.has(s)){let a=typeof s=="function"?s.name:String(s);throw new Error(`${e.type.name}: ${r.name} depends on ${a}, but it is not provided in this module and not exported by any imported module`)}}}}getProviderToken(e){return typeof e=="function"?e:e.provide}collectImportedExports(e){let t=new Set;for(let r of e.metadata.imports??[]){let n=this.getModuleType(r),s=this.resolved.get(n);if(s)for(let a of s.exports)t.add(a);}return t}findProvider(e,t){return e.providers.find(r=>typeof r=="function"?r===t:r.provide===t)}findReExportedProvider(e,t){for(let r of e.metadata.imports??[]){let n=this.getModuleType(r),s=this.resolved.get(n);if(!s||!s.exports.has(t))continue;let a=this.findProvider(s,t);if(a)return a;let c=this.findReExportedProvider(s,t);if(c)return c}}getModuleType(e){return typeof e=="object"&&"module"in e?e.module:e}topologicalSort(){let e=new Set,t=new Set,r=[],n=a(s=>{if(e.has(s))return;if(t.has(s))throw new Error(`Circular module dependency detected: ${s.name}`);t.add(s);let a=this.resolved.get(s);if(a){for(let c of a.metadata.imports??[])n(this.getModuleType(c));t.delete(s),e.add(s),r.push(a);}},"visit");for(let[s]of this.resolved)n(s);return r}};function ht(o,e){if("useFactory"in e&&e.useFactory){let t=e.useFactory;return [{provide:o,useFactory:t,inject:e.inject??[]}]}if("useClass"in e&&e.useClass){let t=e.useClass;return [{provide:o,useFactory:a(async r=>r.createModuleOptions(),"useFactory"),inject:[t]},t]}if("useExisting"in e&&e.useExisting){let t=e.useExisting;return [{provide:o,useFactory:a(async r=>r.createModuleOptions(),"useFactory"),inject:[t]}]}throw new Error("ModuleAsyncOptions must specify one of: useFactory, useClass, or useExisting")}a(ht,"createAsyncProviders");var B=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 c(this.description),t=new c(this.featureDescription),r=this.onForRoot,n=this.onForFeature;return {ConfigurableModuleClass:class{static{a(this,"ConfigurableModuleClassImpl");}static forRoot(c,f={}){let d={module:this,global:f.global??false,providers:[{provide:e,useValue:c}],exports:[e]};return r&&(d=r(d,c)),d}static forRootAsync(c){let f=ht(e,c);return {module:this,imports:c.imports??[],providers:f,exports:[e]}}static forFeature(c,f={}){let d={module:this,global:f.global??false,providers:[{provide:t,useValue:c}],exports:[t]};return n&&(d=n(d,c)),d}},MODULE_OPTIONS_TOKEN:e,MODULE_FEATURE_TOKEN:t}}};var j=class{static{a(this,"BaseExecutionContext");}nativeRequest;handler;container;query;params;body;rawBody;formData;auth;data=new Map;metadata=new Map;abortController;constructor(e,t,r,n={},s={},a){this.nativeRequest=e,this.handler=t,this.container=r,this.query=n,this.params=s,this.abortController=a??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,t){this.metadata.set(e,t);}getData(e){return this.data.get(e)}setData(e,t){this.data.set(e,t);}getContainer(){return this.container}getSignal(){return this.abortController.signal}abort(e){this.abortController.abort(e);}};var je=Symbol("filters"),He=Symbol("catch");function Le(...o){return (e,t,r)=>{let n=t?e.constructor:e,s=Reflect.getOwnMetadata(je,n)??[];Reflect.defineMetadata(je,[...s,...o],n);}}a(Le,"UseFilters");function qe(...o){return e=>{Reflect.defineMetadata(He,o,e);}}a(qe,"Catch");function ie(o){return Reflect.getOwnMetadata(He,o)??[]}a(ie,"getCatchMetadata");function H(o,e,t){return async r=>{let n=[...e.middlewares??[],...t.middlewares??[]],s=[...e.guards??[],...t.guards??[]],a$1=[...e.interceptors??[],...t.interceptors??[]],c=[...e.pipes??[],...t.pipes??[]],f=[...e.filters??[],...t.filters??[]],d=await N(o,f);try{w(r);let u=await N(o,n);return await mt(r,u,async()=>{w(r);let l=await N(o,s);for(let R of l)if(w(r),!await R.canActivate(r))throw new e$1("Access denied by guard");w(r);let v=await N(o,c);for(let R of v)w(r),await R.transform(r);w(r);let g=await N(o,a$1),ve=a(async()=>(w(r),t.handler(r)),"handlerCall");return g.length===0?ve():g.reduceRight((R,xe)=>async()=>(w(r),xe.intercept(r,R)),ve)()})}catch(u){return gt(u,r,d)}}}a(H,"createPipeline");async function mt(o,e,t){return e.length===0?t():e.reduceRight((n,s)=>()=>s.use(o,n),t)()}a(mt,"runMiddlewareChain");function w(o){if(o.getSignal().aborted)throw new g$1}a(w,"checkAborted");async function gt(o,e,t){for(let r of t){let n=ie(r.constructor);if(n.length===0||o instanceof Error&&n.some(a=>o instanceof a))return r.catch(o,e)}throw o}a(gt,"handleError");async function N(o,e){let t=[];for(let r of e)typeof r=="function"?t.push(await o.resolve(r)):t.push(r);return t}a(N,"resolveRefs");var ae=Symbol("interceptors"),ce=Symbol("method:interceptors");function Ve(...o){return (e,t,r)=>{if(t!==void 0){let s=r?.value??e,a=s[ce]??[];return s[ce]=[...a,...o],r}let n=Reflect.getOwnMetadata(ae,e)??[];Reflect.defineMetadata(ae,[...n,...o],e);}}a(Ve,"UseInterceptors");function de(o){return Reflect.getOwnMetadata(ae,o)??[]}a(de,"getInterceptorsMetadata");function fe(o,e){let r=o.prototype?.[e];return typeof r=="function"&&r[ce]||[]}a(fe,"getMethodInterceptors");function L(o,e){return [...de(o),...fe(o,e)]}a(L,"getEffectiveInterceptors");var ue="uow:session",le="uow:instance",q=class{static{a(this,"UnitOfWorkInterceptor");}factory;constructor(e){this.factory=e;}async intercept(e,t){let r=this.factory();await r.start(),e.setData(ue,r.getContext()),e.setData(le,r);try{let n=await t();return await r.commit(),n}catch(n){throw await r.rollback(),n}}};var pe=Symbol("middlewares"),he=Symbol("method:middlewares");function ze(...o){return (e,t,r)=>{if(t!==void 0){let s=r?.value??e,a=s[he]??[];return s[he]=[...a,...o],r}let n=Reflect.getOwnMetadata(pe,e)??[];Reflect.defineMetadata(pe,[...n,...o],e);}}a(ze,"UseMiddleware");function me(o){return Reflect.getOwnMetadata(pe,o)??[]}a(me,"getMiddlewaresMetadata");function ge(o,e){let r=o.prototype?.[e];return typeof r=="function"&&r[he]||[]}a(ge,"getMethodMiddlewares");function V(o,e){return [...me(o),...ge(o,e)]}a(V,"getEffectiveMiddlewares");var We=Symbol("pipes");function Qe(...o){return (e,t,r)=>{let n=t?e.constructor:e,s=Reflect.getOwnMetadata(We,n)??[];Reflect.defineMetadata(We,[...s,...o],n);}}a(Qe,"UsePipes");var z=class{static{a(this,"ZodValidationPipe");}schema;constructor(e){this.schema=e;}transform(e){let t=e.getBody(),r=this.schema.safeParse(t);if(!r.success){let n={};for(let s of r.error.issues){let a=s.path.join(".")||"_root";n[a]||(n[a]=[]),n[a].push(s.message);}throw new c$2("Validation failed",n)}e.setBody(r.data);}};var yt=/^[0-9a-fA-F]{24}$/,W=class{static{a(this,"ParseIdPipe");}paramName;constructor(e="id"){this.paramName=e;}transform(e){let r=e.getParams()[this.paramName];if(!r||!yt.test(r))throw new c$2(`Invalid ${this.paramName}: must be a valid ObjectId`)}};var Q=class{static{a(this,"ParseIntPipe");}transform(e){let t=Number(e);if(!Number.isInteger(t)||e===""||e===null||e===void 0)throw new c$2(`Expected an integer, received: ${JSON.stringify(e)}`);return t}};var Y=class{static{a(this,"ZodParamPipe");}schema;constructor(e){this.schema=e;}transform(e){let t=this.schema.safeParse(e);if(!t.success){let r=t.error.errors.map(n=>`${n.path.join(".")}: ${n.message}`).join(", ");throw new c$2(r)}return t.data}};function Ye(o){return {transform(e){return e??o}}}a(Ye,"DefaultValuePipe");var Z=class{static{a(this,"DomainEvent");}payload;timestamp;constructor(e){this.payload=e,this.timestamp=Date.now();}};function wt(o,e,t,r){var n=arguments.length,s=n<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(o,e,t,r);else for(var c=o.length-1;c>=0;c--)(a=o[c])&&(s=(n<3?a(s):n>3?a(e,t,s):a(e,t))||s);return n>3&&s&&Object.defineProperty(e,t,s),s}a(wt,"_ts_decorate");function Ze(o,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,e)}a(Ze,"_ts_metadata");var h=class{static{a(this,"EventBus");}handlers=new Map;onError;constructor(){this.onError=vt;}setOptions(e){e.onError&&(this.onError=e.onError);}subscribe(e,t,r){let n=this.handlers.get(e)??[];n.push({instance:r?.instance??{},methodName:r?.methodName??"anonymous",handler:t}),this.handlers.set(e,n);}registerHandler(e,t,r){let n=t[r].bind(t);this.subscribe(e,n,{instance:t,methodName:r});}async emit(e){let t=this.handlers.get(e.type);if(!t||t.length===0)return;let r=await Promise.allSettled(t.map(n=>n.handler(e)));for(let n=0;n<r.length;n++){let s=r[n];if(s.status==="rejected"){let a=t[n],c=`${a.instance.constructor?.name??"Unknown"}.${a.methodName}`;this.onError(s.reason,e.type,c);}}}emitAsync(e){this.emit(e).catch(()=>{});}hasHandlers(e){let t=this.handlers.get(e);return t!==void 0&&t.length>0}handlerCount(e){return this.handlers.get(e)?.length??0}clear(){this.handlers.clear();}};h=wt([d$1(),Ze("design:type",Function),Ze("design:paramtypes",[])],h);function vt(o,e,t){console.error(`[EventBus] Handler "${t}" failed for event "${e}":`,o);}a(vt,"defaultErrorHandler");var ye=Symbol("on-event");function Je(o){return (e,t,r)=>{let n=Reflect.getOwnMetadata(ye,e.constructor)??[];n.push({eventType:o,methodName:String(t)}),Reflect.defineMetadata(ye,n,e.constructor);}}a(Je,"OnEvent");function Ke(o){return Reflect.getOwnMetadata(ye,o)??[]}a(Ke,"getOnEventMetadata");var J=class{static{a(this,"ControllerRouter");}routes=[];globalPrefix;constructor(e=""){this.globalPrefix=e;}register(...e){for(let t of e){let r=M(t)??"",n=$(t);for(let s of n){let a=xt(`${this.globalPrefix}/${r}/${s.path}`);bt(a,t.name,s.methodName),this.checkDuplicate(a,s.method,t.name,s.methodName);let{pattern:c,paramNames:f}=Et(a),d=G(t,s.methodName),u=L(t,s.methodName),l=V(t,s.methodName);this.routes.push({method:s.method,pattern:c,paramNames:f,controllerClass:t,methodName:s.methodName,guardClasses:d,interceptorRefs:u,middlewareRefs:l,rawPath:a});}}this.routes.sort((t,r)=>Xe(t.rawPath)-Xe(r.rawPath));}checkDuplicate(e,t,r,n){let s=this.routes.find(a=>a.method===t&&a.rawPath===e);if(s)throw new Error(`Duplicate route: ${t} ${e}
1
+ import {c as c$2,e as e$1,g as g$1}from'./chunk-XVPJFMLQ.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-XVPJFMLQ.js';import {c as c$1,d,e}from'./chunk-F5KXBDV2.js';export{e as DiscoveryService,b as Global,a as Module,c as getModuleMetadata,d as isGlobalModule}from'./chunk-F5KXBDV2.js';import {a,g,b,h,i,j as j$1,c,d as d$1}from'./chunk-RMR6UXWO.js';export{e as Inject,d as Injectable,f as Optional,b as Scope}from'./chunk-RMR6UXWO.js';import'reflect-metadata';function De(o){return {forwardRef:o}}a(De,"forwardRef");function k(o){return typeof o=="object"&&"forwardRef"in o?o.forwardRef():o}a(k,"resolveForwardRef");var x=class o{static{a(this,"Container");}registrations=new Map;resolving=new Set;parent=null;children=[];register(...e){for(let t of e)this.registerOne(t);}registerOne(e){if(typeof e=="function"){let s=g(e)?.scope??b.SINGLETON;this.registrations.set(e,{provider:e,scope:s});return}let t=e.provide,r=b.SINGLETON;if("useClass"in e){let n=g(e.useClass);r=e.scope??n?.scope??b.SINGLETON;}else "useFactory"in e&&(r=e.scope??b.SINGLETON);this.registrations.set(t,{provider:e,scope:r});}async resolve(e){let t=k(e),r=t!==e?t:e,n=this.registrations.get(r)??this.parent?.findRegistration(r);if(!n)throw new Error(`No provider found for ${te(r)}`);if(n.scope===b.SINGLETON&&n.instance!==void 0||n.scope===b.REQUEST&&this.parent!==null&&n.instance!==void 0)return n.instance;if(this.resolving.has(r))throw new Error(`Circular dependency detected for ${te(r)}`);this.resolving.add(r);try{let s=await this.createInstance(n);return (n.scope===b.SINGLETON||n.scope===b.REQUEST&&this.parent!==null)&&(n.instance=s),s}finally{this.resolving.delete(r);}}has(e){return this.registrations.has(e)||(this.parent?.has(e)??false)}findRegistration(e){return this.registrations.get(e)??this.parent?.findRegistration(e)}createChild(){let e=new o;e.parent=this;for(let[t,r]of this.registrations)r.scope===b.REQUEST&&e.registrations.set(t,{provider:r.provider,scope:b.REQUEST,instance:void 0});return this.children.push(e),e}async dispose(){for(let e of this.children)await e.dispose();this.children=[];for(let[,e]of this.registrations)if(e.instance&&typeof e.instance=="object"&&e.instance!==null){let t=e.instance;typeof t.onModuleDestroy=="function"&&await t.onModuleDestroy();}this.registrations.clear(),this.resolving.clear();}async createInstance(e){let{provider:t}=e;if(typeof t=="function")return this.instantiateClass(t);if("useValue"in t)return t.useValue;if("useClass"in t)return this.instantiateClass(t.useClass);if("useFactory"in t){let r=t,n=[];if(r.inject)for(let s of r.inject)n.push(await this.resolve(s));return r.useFactory(...n)}if("useExisting"in t)return this.resolve(t.useExisting);throw new Error("Unknown provider type")}async instantiateClass(e){let t=Reflect.getMetadata("design:paramtypes",e)??[],r=h(e),n=i(e),s=j$1(e),a=n.size>0?Math.max(...n.keys())+1:0,c=Math.max(t.length,a,r.length),f=[];for(let d=0;d<c;d++){let u=n.get(d)??r[d]??t[d],l=s.has(d);try{f.push(await this.resolve(u));}catch{if(l)f.push(void 0);else throw new Error(`Cannot resolve parameter at index ${d} (${te(u)}) of ${e.name}`)}}return new e(...f)}};function te(o){return typeof o=="string"?o:typeof o=="symbol"||o instanceof c?o.toString():typeof o=="function"?o.name:String(o)}a(te,"tokenToString");var _e=Symbol("controller:path"),re=Symbol("controller:guards"),oe=Symbol("route:metadata"),ne=Symbol("method:route"),S=Symbol("method:guards"),se=Symbol("method:noguard");function Fe(o){return e=>{Reflect.defineMetadata(_e,o,e);}}a(Fe,"Controller");function I(o){return (e="")=>(t,r,n)=>{let s=n!==void 0,a=String(s?r:r?.name??r),c=s?n?.value:t;if(typeof c=="function"&&(c[ne]={method:o,path:e,methodName:a}),s){let f=Reflect.getOwnMetadata(oe,t.constructor)??[];return f.push({method:o,path:e,methodName:a}),Reflect.defineMetadata(oe,f,t.constructor),n}return t}}a(I,"createMethodDecorator");var Oe=I("GET"),Be=I("POST"),ke=I("PUT"),Ue=I("DELETE"),$e=I("PATCH");function Ge(...o){return (e,t,r)=>{if(t==null){Reflect.defineMetadata(re,o,e);return}if(r!==void 0){if(r?.value){let n=r.value[S]??[];r.value[S]=[...n,...o];}return r}if(typeof e=="function"){let n=e[S]??[];e[S]=[...n,...o];}return typeof e=="function"&&t?.kind==="class"&&Reflect.defineMetadata(re,o,e),e}}a(Ge,"RouteGuards");function je(){return (o,e,t)=>t!==void 0?(t?.value&&(t.value[se]=true),t):(typeof o=="function"&&(o[se]=true),o)}a(je,"NoGuard");function M(o){return Reflect.getOwnMetadata(_e,o)}a(M,"getControllerPath");function ie(o){return Reflect.getOwnMetadata(re,o)??[]}a(ie,"getControllerGuards");function U(o){let e=[],t=o.prototype;if(t){let r=Object.getOwnPropertyNames(t);for(let n of r){if(n==="constructor")continue;let s=t[n];typeof s=="function"&&s[ne]&&e.push(s[ne]);}}return e.length>0?e:Reflect.getOwnMetadata(oe,o)??[]}a(U,"getRouteMetadata");function $(o,e){let r=o.prototype?.[e],n=typeof r=="function"&&r[se]===true,s=typeof r=="function"&&r[S]||[];return n?s:[...ie(o),...s]}a($,"getMethodGuards");var R=class{static{a(this,"ModuleRegistry");}resolved=new Map;sortedModules=[];scan(e){this.resolveModule(e),this.sortedModules=this.topologicalSort(),this.validateExports();}registerAll(e){let t=new Set;for(let r of this.sortedModules)if(r.global)for(let n of r.providers)t.add(n);t.size>0&&e.register(...t);for(let r of this.sortedModules){e.register(...r.providers);for(let n of r.metadata.imports??[]){let s=this.getModuleType(n),a=this.resolved.get(s);if(a)for(let c of a.exports){let f=this.findProvider(a,c)??this.findReExportedProvider(a,c);f&&e.register(f);}}}}getAllProviders(){let e=[];for(let t of this.sortedModules)e.push(...t.providers);return e}getAllControllers(){let e=new Set,t=[];for(let r of this.sortedModules){for(let n of r.controllers)e.has(n)||(e.add(n),t.push(n));for(let n of r.metadata.providers??[])typeof n=="function"&&M(n)!==void 0&&!e.has(n)&&(e.add(n),t.push(n));}return t}async callLifecycleHooks(e,t,r){for(let n of this.sortedModules)for(let s of n.providers){let a=typeof s=="function"?s:s.provide;if(e.has(a))try{let c=await e.resolve(a);c&&typeof c=="object"&&typeof c[t]=="function"&&await c[t](r);}catch{}}}resolveModule(e){let t=typeof e=="object"&&"module"in e,r=t?e.module:e;if(this.resolved.has(r))return this.resolved.get(r);let n=c$1(r)??{},s=t?e:{},a=[...n.controllers??[],...s.controllers??[]],c={imports:[...n.imports??[],...s.imports??[]],controllers:a,providers:[...n.providers??[],...s.providers??[]],exports:[...n.exports??[],...s.exports??[]]},f={type:r,metadata:c,controllers:a,providers:[...a,...c.providers??[]],exports:new Set(c.exports??[]),global:t?e.global??d(r):d(r)};this.resolved.set(r,f);for(let d of c.imports??[])this.resolveModule(d);return f}getVisibleTokens(e){let t=new Set;for(let r of e.providers)t.add(this.getProviderToken(r));for(let r of e.metadata.imports??[]){let n=this.getModuleType(r),s=this.resolved.get(n);if(s)for(let a of s.exports)t.add(a);}for(let r of this.sortedModules)if(r.global)for(let n of r.providers)t.add(this.getProviderToken(n));return t}validateExports(){for(let e of this.sortedModules){let t=new Set(e.providers.map(n=>this.getProviderToken(n))),r=this.collectImportedExports(e);for(let n of e.exports)if(!t.has(n)&&!r.has(n)){let s=typeof n=="function"?n.name:String(n);throw new Error(`${e.type.name} exports ${s} but it is not in its providers and is not re-exported from an imported module`)}}}validateVisibility(){for(let e of this.sortedModules){let t=this.getVisibleTokens(e);for(let r of e.providers){if(typeof r!="function")continue;let n=h(r);for(let s of n)if(!t.has(s)){let a=typeof s=="function"?s.name:String(s);throw new Error(`${e.type.name}: ${r.name} depends on ${a}, but it is not provided in this module and not exported by any imported module`)}}}}getProviderToken(e){return typeof e=="function"?e:e.provide}collectImportedExports(e){let t=new Set;for(let r of e.metadata.imports??[]){let n=this.getModuleType(r),s=this.resolved.get(n);if(s)for(let a of s.exports)t.add(a);}return t}findProvider(e,t){return e.providers.find(r=>typeof r=="function"?r===t:r.provide===t)}findReExportedProvider(e,t){for(let r of e.metadata.imports??[]){let n=this.getModuleType(r),s=this.resolved.get(n);if(!s||!s.exports.has(t))continue;let a=this.findProvider(s,t);if(a)return a;let c=this.findReExportedProvider(s,t);if(c)return c}}getModuleType(e){return typeof e=="object"&&"module"in e?e.module:e}topologicalSort(){let e=new Set,t=new Set,r=[],n=a(s=>{if(e.has(s))return;if(t.has(s))throw new Error(`Circular module dependency detected: ${s.name}`);t.add(s);let a=this.resolved.get(s);if(a){for(let c of a.metadata.imports??[])n(this.getModuleType(c));t.delete(s),e.add(s),r.push(a);}},"visit");for(let[s]of this.resolved)n(s);return r}};function wt(o,e){if("useFactory"in e&&e.useFactory){let t=e.useFactory;return [{provide:o,useFactory:t,inject:e.inject??[]}]}if("useClass"in e&&e.useClass){let t=e.useClass;return [{provide:o,useFactory:a(async r=>r.createModuleOptions(),"useFactory"),inject:[t]},t]}if("useExisting"in e&&e.useExisting){let t=e.useExisting;return [{provide:o,useFactory:a(async r=>r.createModuleOptions(),"useFactory"),inject:[t]}]}throw new Error("ModuleAsyncOptions must specify one of: useFactory, useClass, or useExisting")}a(wt,"createAsyncProviders");var G=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 c(this.description),t=new c(this.featureDescription),r=this.onForRoot,n=this.onForFeature;return {ConfigurableModuleClass:class{static{a(this,"ConfigurableModuleClassImpl");}static forRoot(c,f={}){let d={module:this,global:f.global??false,providers:[{provide:e,useValue:c}],exports:[e]};return r&&(d=r(d,c)),d}static forRootAsync(c){let f=wt(e,c);return {module:this,imports:c.imports??[],providers:f,exports:[e]}}static forFeature(c,f={}){let d={module:this,global:f.global??false,providers:[{provide:t,useValue:c}],exports:[t]};return n&&(d=n(d,c)),d}},MODULE_OPTIONS_TOKEN:e,MODULE_FEATURE_TOKEN:t}}};var j=class{static{a(this,"BaseExecutionContext");}nativeRequest;handler;container;query;params;body;rawBody;formData;auth;data=new Map;metadata=new Map;abortController;constructor(e,t,r,n={},s={},a){this.nativeRequest=e,this.handler=t,this.container=r,this.query=n,this.params=s,this.abortController=a??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,t){this.metadata.set(e,t);}getData(e){return this.data.get(e)}setData(e,t){this.data.set(e,t);}getContainer(){return this.container}getSignal(){return this.abortController.signal}abort(e){this.abortController.abort(e);}};var He=Symbol("filters"),Ve=Symbol("catch");function Le(...o){return (e,t,r)=>{let n=t?e.constructor:e,s=Reflect.getOwnMetadata(He,n)??[];Reflect.defineMetadata(He,[...s,...o],n);}}a(Le,"UseFilters");function qe(...o){return e=>{Reflect.defineMetadata(Ve,o,e);}}a(qe,"Catch");function ae(o){return Reflect.getOwnMetadata(Ve,o)??[]}a(ae,"getCatchMetadata");function H(o,e,t){return async r=>{let n=[...e.middlewares??[],...t.middlewares??[]],s=[...e.guards??[],...t.guards??[]],a$1=[...e.interceptors??[],...t.interceptors??[]],c=[...e.pipes??[],...t.pipes??[]],f=[...e.filters??[],...t.filters??[]],d=await N(o,f);try{w(r);let u=await N(o,n);return await vt(r,u,async()=>{w(r);let l=await N(o,s);for(let b of l)if(w(r),!await b.canActivate(r))throw new e$1("Access denied by guard");w(r);let v=await N(o,c);for(let b of v)w(r),await b.transform(r);w(r);let g=await N(o,a$1),Ee=a(async()=>(w(r),t.handler(r)),"handlerCall");return g.length===0?Ee():g.reduceRight((b,xe)=>async()=>(w(r),xe.intercept(r,b)),Ee)()})}catch(u){return Et(u,r,d)}}}a(H,"createPipeline");async function vt(o,e,t){return e.length===0?t():e.reduceRight((n,s)=>()=>s.use(o,n),t)()}a(vt,"runMiddlewareChain");function w(o){if(o.getSignal().aborted)throw new g$1}a(w,"checkAborted");async function Et(o,e,t){for(let r of t){let n=ae(r.constructor);if(n.length===0||o instanceof Error&&n.some(a=>o instanceof a))return r.catch(o,e)}throw o}a(Et,"handleError");async function N(o,e){let t=[];for(let r of e)typeof r=="function"?t.push(await o.resolve(r)):t.push(r);return t}a(N,"resolveRefs");var ce=Symbol("interceptors"),de=Symbol("method:interceptors");function ze(...o){return (e,t,r)=>{if(t!==void 0){let s=r?.value??e,a=s[de]??[];return s[de]=[...a,...o],r}let n=Reflect.getOwnMetadata(ce,e)??[];Reflect.defineMetadata(ce,[...n,...o],e);}}a(ze,"UseInterceptors");function fe(o){return Reflect.getOwnMetadata(ce,o)??[]}a(fe,"getInterceptorsMetadata");function ue(o,e){let r=o.prototype?.[e];return typeof r=="function"&&r[de]||[]}a(ue,"getMethodInterceptors");function V(o,e){return [...fe(o),...ue(o,e)]}a(V,"getEffectiveInterceptors");var le="uow:session",pe="uow:instance",L=class{static{a(this,"UnitOfWorkInterceptor");}factory;constructor(e){this.factory=e;}async intercept(e,t){let r=this.factory();await r.start(),e.setData(le,r.getContext()),e.setData(pe,r);try{let n=await t();return await r.commit(),n}catch(n){throw await r.rollback(),n}}};var he=Symbol("middlewares"),me=Symbol("method:middlewares");function We(...o){return (e,t,r)=>{if(t!==void 0){let s=r?.value??e,a=s[me]??[];return s[me]=[...a,...o],r}let n=Reflect.getOwnMetadata(he,e)??[];Reflect.defineMetadata(he,[...n,...o],e);}}a(We,"UseMiddleware");function ge(o){return Reflect.getOwnMetadata(he,o)??[]}a(ge,"getMiddlewaresMetadata");function ye(o,e){let r=o.prototype?.[e];return typeof r=="function"&&r[me]||[]}a(ye,"getMethodMiddlewares");function q(o,e){return [...ge(o),...ye(o,e)]}a(q,"getEffectiveMiddlewares");var Qe=Symbol("pipes");function Ze(...o){return (e,t,r)=>{let n=t?e.constructor:e,s=Reflect.getOwnMetadata(Qe,n)??[];Reflect.defineMetadata(Qe,[...s,...o],n);}}a(Ze,"UsePipes");var z=class{static{a(this,"ZodValidationPipe");}schema;constructor(e){this.schema=e;}transform(e){let t=e.getBody(),r=this.schema.safeParse(t);if(!r.success){let n={};for(let s of r.error.issues){let a=s.path.join(".")||"_root";n[a]||(n[a]=[]),n[a].push(s.message);}throw new c$2("Validation failed",n)}e.setBody(r.data);}};var xt=/^[0-9a-fA-F]{24}$/,W=class{static{a(this,"ParseIdPipe");}paramName;constructor(e="id"){this.paramName=e;}transform(e){let r=e.getParams()[this.paramName];if(!r||!xt.test(r))throw new c$2(`Invalid ${this.paramName}: must be a valid ObjectId`)}};var Q=class{static{a(this,"ParseIntPipe");}transform(e){let t=Number(e);if(!Number.isInteger(t)||e===""||e===null||e===void 0)throw new c$2(`Expected an integer, received: ${JSON.stringify(e)}`);return t}};var Z=class{static{a(this,"ZodParamPipe");}schema;constructor(e){this.schema=e;}transform(e){let t=this.schema.safeParse(e);if(!t.success){let r=t.error.errors.map(n=>`${n.path.join(".")}: ${n.message}`).join(", ");throw new c$2(r)}return t.data}};function Ye(o){return {transform(e){return e??o}}}a(Ye,"DefaultValuePipe");var E=Symbol("route:params");function Mt(o){return o==null?false:typeof o=="function"||typeof o=="object"&&typeof o.transform=="function"}a(Mt,"isParamPipeRef");function Y(o,e){return Mt(o)?{key:void 0,pipes:[o,...e??[]]}:{key:o,pipes:e??[]}}a(Y,"resolveArgs");function y(o,e,t=[]){return (r,n,s)=>{if(n===void 0)return;let a=r[n];if(typeof a!="function")return;let c=a[E]??[];a[E]=[...c,{index:s,type:o,key:e,pipes:t.length>0?t:void 0}];}}a(y,"buildBuiltinDecorator");function Rt(o){return typeof o=="function"?new o:o}a(Rt,"resolveParamPipe");function Je(o,...e){let{key:t,pipes:r}=Y(o,e);return y("query",t,r)}a(Je,"Query");function Ke(o,...e){let{key:t,pipes:r}=Y(o,e);return y("param",t,r)}a(Ke,"Param");function Xe(o,...e){let{key:t,pipes:r}=Y(o,e);return y("body",t,r)}a(Xe,"Body");var et=a(()=>y("rawBody"),"RawBody"),tt=a(()=>y("formData"),"FormData"),rt=a(()=>y("ip"),"Ip"),ot=a(()=>y("userAgent"),"UserAgent"),nt=a(o=>y("cookie",o),"Cookie");function st(o,...e){let{key:t,pipes:r}=Y(o,e);return y("headers",t,r)}a(st,"Headers");function we(o){return ()=>(e,t,r)=>{if(t===void 0)return;let n=e[t];if(typeof n!="function")return;let s=n[E]??[];n[E]=[...s,{index:r,type:"auth",extractor:o}];}}a(we,"defineAuth");var it=we();function J(o){return ()=>(e,t,r)=>{if(t===void 0)return;let n=e[t];if(typeof n!="function")return;let s=n[E]??[];n[E]=[...s,{index:r,type:"custom",extractor:o}];}}a(J,"createParamDecorator");function at(o,e){let t=o.prototype[e];if(typeof t!="function")return null;let r=t[E];return r&&r.length>0?r:null}a(at,"getRouteParams");async function ct(o,e){let t=Math.max(...o.map(n=>n.index)),r=new Array(t+1).fill(void 0);for(let{index:n,type:s,key:a,pipes:c,extractor:f}of o){let d;switch(s){case "query":{let u=e.getQuery();d=a!==void 0?u[a]:u;break}case "param":{let u=e.getParams();d=a!==void 0?u[a]:u;break}case "body":{let u=e.getBody()??{};d=a!==void 0?u[a]:u;break}case "rawBody":{d=e.getRawBody();break}case "formData":{d=e.getFormData();break}case "headers":{let u=e.getNativeRequest(),l=u?.node?.req?.headers??u?.headers??{};d=a!==void 0?l[a.toLowerCase()]:l;break}case "cookie":{let u=e.getNativeRequest(),l=u?.node?.req?.headers?.cookie??u?.headers?.cookie??"";if(a&&l){let v=l.split(";").map(g=>g.trim()).find(g=>g.startsWith(a+"="));d=v?decodeURIComponent(v.slice(a.length+1)):void 0;}else d=void 0;break}case "ip":{let u=e.getNativeRequest(),l=u?.node?.req?.headers??{},v=l["cf-connecting-ip"];if(v){d=v.trim();break}let g=l["x-forwarded-for"];if(g){d=(String(g).split(",")[0]??"").trim();break}d=u?.node?.req?.socket?.remoteAddress??"";break}case "userAgent":{d=(e.getNativeRequest()?.node?.req?.headers??{})["user-agent"]??"";break}case "auth":{d=f?await f(e):e.getAuth();break}case "custom":{d=f?await f(e):void 0;break}}if(c&&c.length>0)for(let u of c)d=Rt(u).transform(d);r[n]=d;}return r}a(ct,"resolveParamArgs");function dt(o){return J(e=>{let t=e.getBody(),r=o.safeParse(t);if(!r.success){let n={};for(let s of r.error.issues){let a=s.path.join(".")||"_root";(n[a]??=[]).push(s.message);}throw new c$2("Validation failed",n)}return r.data})}a(dt,"ZodValidatedBody");var K=class{static{a(this,"DomainEvent");}payload;timestamp;constructor(e){this.payload=e,this.timestamp=Date.now();}};function bt(o,e,t,r){var n=arguments.length,s=n<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(o,e,t,r);else for(var c=o.length-1;c>=0;c--)(a=o[c])&&(s=(n<3?a(s):n>3?a(e,t,s):a(e,t))||s);return n>3&&s&&Object.defineProperty(e,t,s),s}a(bt,"_ts_decorate");function ft(o,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,e)}a(ft,"_ts_metadata");var m=class{static{a(this,"EventBus");}handlers=new Map;onError;constructor(){this.onError=Pt;}setOptions(e){e.onError&&(this.onError=e.onError);}subscribe(e,t,r){let n=this.handlers.get(e)??[];n.push({instance:r?.instance??{},methodName:r?.methodName??"anonymous",handler:t}),this.handlers.set(e,n);}registerHandler(e,t,r){let n=t[r].bind(t);this.subscribe(e,n,{instance:t,methodName:r});}async emit(e){let t=this.handlers.get(e.type);if(!t||t.length===0)return;let r=await Promise.allSettled(t.map(n=>n.handler(e)));for(let n=0;n<r.length;n++){let s=r[n];if(s.status==="rejected"){let a=t[n],c=`${a.instance.constructor?.name??"Unknown"}.${a.methodName}`;this.onError(s.reason,e.type,c);}}}emitAsync(e){this.emit(e).catch(()=>{});}hasHandlers(e){let t=this.handlers.get(e);return t!==void 0&&t.length>0}handlerCount(e){return this.handlers.get(e)?.length??0}clear(){this.handlers.clear();}};m=bt([d$1(),ft("design:type",Function),ft("design:paramtypes",[])],m);function Pt(o,e,t){console.error(`[EventBus] Handler "${t}" failed for event "${e}":`,o);}a(Pt,"defaultErrorHandler");var ve=Symbol("on-event");function ut(o){return (e,t,r)=>{let n=Reflect.getOwnMetadata(ve,e.constructor)??[];n.push({eventType:o,methodName:String(t)}),Reflect.defineMetadata(ve,n,e.constructor);}}a(ut,"OnEvent");function lt(o){return Reflect.getOwnMetadata(ve,o)??[]}a(lt,"getOnEventMetadata");var X=class{static{a(this,"ControllerRouter");}routes=[];globalPrefix;constructor(e=""){this.globalPrefix=e;}register(...e){for(let t of e){let r=M(t)??"",n=U(t);for(let s of n){let a=Ct(`${this.globalPrefix}/${r}/${s.path}`);St(a,t.name,s.methodName),this.checkDuplicate(a,s.method,t.name,s.methodName);let{pattern:c,paramNames:f}=Tt(a),d=$(t,s.methodName),u=V(t,s.methodName),l=q(t,s.methodName);this.routes.push({method:s.method,pattern:c,paramNames:f,controllerClass:t,methodName:s.methodName,guardClasses:d,interceptorRefs:u,middlewareRefs:l,rawPath:a});}}this.routes.sort((t,r)=>pt(t.rawPath)-pt(r.rawPath));}checkDuplicate(e,t,r,n){let s=this.routes.find(a=>a.method===t&&a.rawPath===e);if(s)throw new Error(`Duplicate route: ${t} ${e}
2
2
  Already registered by: ${s.controllerClass.name}.${s.methodName}
3
- Conflicting with: ${r}.${n}`)}match(e,t){let r=e.toUpperCase();for(let n of this.routes){if(n.method!==r)continue;let s=n.pattern.exec(t);if(!s)continue;let a={};for(let c=0;c<n.paramNames.length;c++)a[n.paramNames[c]]=s[c+1]??"";return {route:n,params:a}}return null}getRoutes(){return this.routes}};function xt(o){return "/"+o.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}a(xt,"normalizePath");function Et(o){let e=[],t=o.split("/").map(r=>r.startsWith(":")?(e.push(r.slice(1)),"([^/]+)"):Mt(r)).join("/");return {pattern:new RegExp(`^${t}$`),paramNames:e}}a(Et,"compilePath");function Mt(o){return o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}a(Mt,"escapeRegex");function Xe(o){return o.split("/").filter(Boolean).reduce((e,t)=>e+(t.startsWith(":")?1:0),0)}a(Xe,"routePriority");function bt(o,e,t){let r=`Invalid path "${o}" on ${e}.${t}:`;if(!o.startsWith("/"))throw new Error(`${r} must start with /`);let n=o.split("/").filter((a,c)=>c>0),s=new Set;for(let a of n){if(a==="")throw new Error(`${r} contains empty segment (double slash)`);if(a.startsWith(":")){let c=a.slice(1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c))throw new Error(`${r} invalid param name ":${c}" \u2014 must be a valid identifier`);if(s.has(c))throw new Error(`${r} duplicate param name ":${c}"`);s.add(c);}}}a(bt,"validatePath");var x=Symbol("route:params");function Rt(o){return o==null?false:typeof o=="function"||typeof o=="object"&&typeof o.transform=="function"}a(Rt,"isParamPipeRef");function K(o,e){return Rt(o)?{key:void 0,pipes:[o,...e??[]]}:{key:o,pipes:e??[]}}a(K,"resolveArgs");function y(o,e,t=[]){return (r,n,s)=>{if(n===void 0)return;let a=r[n];if(typeof a!="function")return;let c=a[x]??[];a[x]=[...c,{index:s,type:o,key:e,pipes:t.length>0?t:void 0}];}}a(y,"buildBuiltinDecorator");function Pt(o){return typeof o=="function"?new o:o}a(Pt,"resolveParamPipe");function et(o,...e){let{key:t,pipes:r}=K(o,e);return y("query",t,r)}a(et,"Query");function tt(o,...e){let{key:t,pipes:r}=K(o,e);return y("param",t,r)}a(tt,"Param");function rt(o,...e){let{key:t,pipes:r}=K(o,e);return y("body",t,r)}a(rt,"Body");var ot=a(()=>y("rawBody"),"RawBody"),nt=a(()=>y("formData"),"FormData"),st=a(()=>y("ip"),"Ip"),it=a(()=>y("userAgent"),"UserAgent"),at=a(o=>y("cookie",o),"Cookie");function ct(o,...e){let{key:t,pipes:r}=K(o,e);return y("headers",t,r)}a(ct,"Headers");function we(o){return ()=>(e,t,r)=>{if(t===void 0)return;let n=e[t];if(typeof n!="function")return;let s=n[x]??[];n[x]=[...s,{index:r,type:"auth",extractor:o}];}}a(we,"defineAuth");var dt=we();function ft(o){return ()=>(e,t,r)=>{if(t===void 0)return;let n=e[t];if(typeof n!="function")return;let s=n[x]??[];n[x]=[...s,{index:r,type:"custom",extractor:o}];}}a(ft,"createParamDecorator");function ut(o,e){let t=o.prototype[e];if(typeof t!="function")return null;let r=t[x];return r&&r.length>0?r:null}a(ut,"getRouteParams");async function lt(o,e){let t=Math.max(...o.map(n=>n.index)),r=new Array(t+1).fill(void 0);for(let{index:n,type:s,key:a,pipes:c,extractor:f}of o){let d;switch(s){case "query":{let u=e.getQuery();d=a!==void 0?u[a]:u;break}case "param":{let u=e.getParams();d=a!==void 0?u[a]:u;break}case "body":{let u=e.getBody()??{};d=a!==void 0?u[a]:u;break}case "rawBody":{d=e.getRawBody();break}case "formData":{d=e.getFormData();break}case "headers":{let u=e.getNativeRequest(),l=u?.node?.req?.headers??u?.headers??{};d=a!==void 0?l[a.toLowerCase()]:l;break}case "cookie":{let u=e.getNativeRequest(),l=u?.node?.req?.headers?.cookie??u?.headers?.cookie??"";if(a&&l){let v=l.split(";").map(g=>g.trim()).find(g=>g.startsWith(a+"="));d=v?decodeURIComponent(v.slice(a.length+1)):void 0;}else d=void 0;break}case "ip":{let u=e.getNativeRequest(),l=u?.node?.req?.headers??{},v=l["cf-connecting-ip"];if(v){d=v.trim();break}let g=l["x-forwarded-for"];if(g){d=(String(g).split(",")[0]??"").trim();break}d=u?.node?.req?.socket?.remoteAddress??"";break}case "userAgent":{d=(e.getNativeRequest()?.node?.req?.headers??{})["user-agent"]??"";break}case "auth":{d=f?await f(e):e.getAuth();break}case "custom":{d=f?await f(e):void 0;break}}if(c&&c.length>0)for(let u of c)d=Pt(u).transform(d);r[n]=d;}return r}a(lt,"resolveParamArgs");async function pt(o,e){let t=await o.resolve(h);for(let r of e){let n=Ct(r);if(!n)continue;let s=Ke(n);if(s.length===0)continue;let a=typeof r=="function"?r:r.provide,c;try{c=await o.resolve(a);}catch{continue}for(let f of s)typeof c[f.methodName]=="function"&&t.registerHandler(f.eventType,c,f.methodName);}}a(pt,"scanEventHandlers");function Ct(o){return typeof o=="function"?g(o)?o:null:"useClass"in o?o.useClass:null}a(Ct,"getProviderClass");var X=class{static{a(this,"BackendApplication");}container;registry;initialized=false;options;eventBus;prefix="";constructor(e){this.options=e,this.container=new E,this.registry=new b;}async init(){if(this.initialized)return;this.eventBus=new h,this.options.eventBus&&this.eventBus.setOptions(this.options.eventBus),this.container.register({provide:h,useValue:this.eventBus});let e$1=new e;this.container.register({provide:e,useValue:e$1}),this.registry.scan(this.options.rootModule),this.registry.registerAll(this.container);let t=this.registry.getAllProviders();e$1._init(this.container,t),await this.registry.callLifecycleHooks(this.container,"onModuleInit"),await pt(this.container,t),await this.registry.callLifecycleHooks(this.container,"onApplicationBootstrap"),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}getControllers(){return this.ensureInitialized(),this.registry.getAllControllers()}getProviders(){return this.ensureInitialized(),this.registry.getAllProviders()}getEventBus(){return this.ensureInitialized(),this.eventBus}createHandler(e){return this.ensureInitialized(),H(this.container,this.getGlobalOptions(),e)}async shutdown(){this.initialized&&(await this.registry.callLifecycleHooks(this.container,"onModuleDestroy"),await this.registry.callLifecycleHooks(this.container,"onApplicationShutdown"),this.eventBus.clear(),await this.container.dispose(),this.initialized=false);}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("BackendApplication not initialized. Call init() first.")}};export{dt as Auth,X as BackendApplication,j as BaseExecutionContext,rt as Body,qe as Catch,B as ConfigurableModuleBuilder,E as Container,Fe as Controller,J as ControllerRouter,at as Cookie,Ye as DefaultValuePipe,Ue as Delete,Z as DomainEvent,h as EventBus,nt as FormData,Oe as Get,ct as Headers,st as Ip,b as ModuleRegistry,Be as NoGuard,Je as OnEvent,tt as Param,W as ParseIdPipe,Q as ParseIntPipe,$e as Patch,_e as Post,ke as Put,et as Query,ot as RawBody,Ge as RouteGuards,le as UOW_INSTANCE_KEY,ue as UOW_SESSION_KEY,q as UnitOfWorkInterceptor,Le as UseFilters,Ve as UseInterceptors,ze as UseMiddleware,Qe as UsePipes,it as UserAgent,Y as ZodParamPipe,z as ZodValidationPipe,ft as createParamDecorator,H as createPipeline,we as defineAuth,Ne as forwardRef,se as getControllerGuards,M as getControllerPath,L as getEffectiveInterceptors,V as getEffectiveMiddlewares,de as getInterceptorsMetadata,G as getMethodGuards,fe as getMethodInterceptors,ge as getMethodMiddlewares,me as getMiddlewaresMetadata,$ as getRouteMetadata,ut as getRouteParams,U as resolveForwardRef,lt as resolveParamArgs};
3
+ Conflicting with: ${r}.${n}`)}match(e,t){let r=e.toUpperCase();for(let n of this.routes){if(n.method!==r)continue;let s=n.pattern.exec(t);if(!s)continue;let a={};for(let c=0;c<n.paramNames.length;c++)a[n.paramNames[c]]=s[c+1]??"";return {route:n,params:a}}return null}getRoutes(){return this.routes}};function Ct(o){return "/"+o.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}a(Ct,"normalizePath");function Tt(o){let e=[],t=o.split("/").map(r=>r.startsWith(":")?(e.push(r.slice(1)),"([^/]+)"):At(r)).join("/");return {pattern:new RegExp(`^${t}$`),paramNames:e}}a(Tt,"compilePath");function At(o){return o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}a(At,"escapeRegex");function pt(o){return o.split("/").filter(Boolean).reduce((e,t)=>e+(t.startsWith(":")?1:0),0)}a(pt,"routePriority");function St(o,e,t){let r=`Invalid path "${o}" on ${e}.${t}:`;if(!o.startsWith("/"))throw new Error(`${r} must start with /`);let n=o.split("/").filter((a,c)=>c>0),s=new Set;for(let a of n){if(a==="")throw new Error(`${r} contains empty segment (double slash)`);if(a.startsWith(":")){let c=a.slice(1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c))throw new Error(`${r} invalid param name ":${c}" \u2014 must be a valid identifier`);if(s.has(c))throw new Error(`${r} duplicate param name ":${c}"`);s.add(c);}}}a(St,"validatePath");var ht="__redirect";function mt(o,e=302){return {__redirect:true,url:o,statusCode:e}}a(mt,"redirect");function gt(o){return o!==null&&typeof o=="object"&&o.__redirect===true}a(gt,"isRedirect");async function yt(o,e){let t=await o.resolve(m);for(let r of e){let n=It(r);if(!n)continue;let s=lt(n);if(s.length===0)continue;let a=typeof r=="function"?r:r.provide,c;try{c=await o.resolve(a);}catch{continue}for(let f of s)typeof c[f.methodName]=="function"&&t.registerHandler(f.eventType,c,f.methodName);}}a(yt,"scanEventHandlers");function It(o){return typeof o=="function"?g(o)?o:null:"useClass"in o?o.useClass:null}a(It,"getProviderClass");var ee=class{static{a(this,"BackendApplication");}container;registry;initialized=false;options;eventBus;prefix="";constructor(e){this.options=e,this.container=new x,this.registry=new R;}async init(){if(this.initialized)return;this.eventBus=new m,this.options.eventBus&&this.eventBus.setOptions(this.options.eventBus),this.container.register({provide:m,useValue:this.eventBus});let e$1=new e;this.container.register({provide:e,useValue:e$1}),this.registry.scan(this.options.rootModule),this.registry.registerAll(this.container);let t=this.registry.getAllProviders();e$1._init(this.container,t),await this.registry.callLifecycleHooks(this.container,"onModuleInit"),await yt(this.container,t),await this.registry.callLifecycleHooks(this.container,"onApplicationBootstrap"),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}getControllers(){return this.ensureInitialized(),this.registry.getAllControllers()}getProviders(){return this.ensureInitialized(),this.registry.getAllProviders()}getEventBus(){return this.ensureInitialized(),this.eventBus}createHandler(e){return this.ensureInitialized(),H(this.container,this.getGlobalOptions(),e)}async shutdown(){this.initialized&&(await this.registry.callLifecycleHooks(this.container,"onModuleDestroy"),await this.registry.callLifecycleHooks(this.container,"onApplicationShutdown"),this.eventBus.clear(),await this.container.dispose(),this.initialized=false);}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("BackendApplication not initialized. Call init() first.")}};export{it as Auth,ee as BackendApplication,j as BaseExecutionContext,Xe as Body,qe as Catch,G as ConfigurableModuleBuilder,x as Container,Fe as Controller,X as ControllerRouter,nt as Cookie,Ye as DefaultValuePipe,Ue as Delete,K as DomainEvent,m as EventBus,tt as FormData,Oe as Get,st as Headers,rt as Ip,R as ModuleRegistry,je as NoGuard,ut as OnEvent,Ke as Param,W as ParseIdPipe,Q as ParseIntPipe,$e as Patch,Be as Post,ke as Put,Je as Query,ht as REDIRECT_BRAND,et as RawBody,Ge as RouteGuards,pe as UOW_INSTANCE_KEY,le as UOW_SESSION_KEY,L as UnitOfWorkInterceptor,Le as UseFilters,ze as UseInterceptors,We as UseMiddleware,Ze as UsePipes,ot as UserAgent,Z as ZodParamPipe,dt as ZodValidatedBody,z as ZodValidationPipe,J as createParamDecorator,H as createPipeline,we as defineAuth,De as forwardRef,ie as getControllerGuards,M as getControllerPath,V as getEffectiveInterceptors,q as getEffectiveMiddlewares,fe as getInterceptorsMetadata,$ as getMethodGuards,ue as getMethodInterceptors,ye as getMethodMiddlewares,ge as getMiddlewaresMetadata,U as getRouteMetadata,at as getRouteParams,gt as isRedirect,mt as redirect,k as resolveForwardRef,ct as resolveParamArgs};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "truxie",
3
- "version": "0.1.0-test.4",
3
+ "version": "0.1.0-test.5",
4
4
  "description": "NestJS-like structural backend library with DI, modules, guards, interceptors, pipes, and exception filters",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",