truxie 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-CD6QSDG5.js +2 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.js +2 -2
- package/dist/testing.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-6JQLGFPZ.js +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {i as i$1}from'./chunk-RDP32XIU.js';import {d,h,a as a$1,i,j as j$1,k as k$1,b,n,o,e}from'./chunk-TSJZVSHP.js';import {a}from'./chunk-EI7MMDWY.js';import'reflect-metadata';var $=new WeakSet;function S(i){return $.has(i)?false:($.add(i),true)}a(S,"claimDestroy");var k=class extends Error{static{a(this,"MissingProviderError");}},F=class i$1{static{a(this,"Container");}registrations=new Map;parent=null;children=[];register(...e){for(let t of e)this.registerOne(t);}registerOne(e){let t=e&&typeof e=="object"&&"forwardRef"in e?d(e):e;if(typeof t=="function"){let a=h(t)?.scope??a$1.SINGLETON;this.registrations.set(t,{provider:t,scope:a,resolved:false});return}let n=t.provide,o=a$1.SINGLETON,s=t;if("useClass"in t){let r=t.useClass,a=r&&typeof r=="object"&&"forwardRef"in r?d(r):r,f=h(a);o=t.scope??f?.scope??a$1.SINGLETON,s={...t,useClass:a};}else if("useExisting"in t){let r=t.useExisting,a=r&&typeof r=="object"&&"forwardRef"in r?d(r):r;s={...t,useExisting:a};}else "useFactory"in t&&(o=t.scope??a$1.SINGLETON);this.registrations.set(n,{provider:s,scope:o,resolved:false});}async resolve(e){return this.resolveInternal(e,J)}async resolveInternal(e,t){let n=d(e),o=n!==e?n:e,s=this.findOwner(o);if(!s)throw new k(`No provider found for ${P(o)}`);let r=s.registrations.get(o),a=r.scope===a$1.SINGLETON?s:this,f=r.scope===a$1.SINGLETON||r.scope===a$1.REQUEST&&a.parent!==null;if(f&&r.resolved)return r.instance;if(t.has(o))throw new Error(`Circular dependency detected for ${P(o)}`);if(f&&r.inFlight)return r.inFlight;let m=new Set(t).add(o),l=a.createInstance(r,m).then(h=>(f&&(r.instance=h,r.resolved=true),r.inFlight=void 0,h),h=>{throw r.inFlight=void 0,h});return f&&(r.inFlight=l),l}has(e){return this.registrations.has(e)||(this.parent?.has(e)??false)}hasRequestScoped(){for(let[,e]of this.registrations)if(e.scope===a$1.REQUEST)return true;return this.parent?.hasRequestScoped()??false}findOwner(e){return this.registrations.has(e)?this:this.parent?.findOwner(e)??null}createChild(){let e=new i$1;e.parent=this;for(let[t,n]of this.registrations)n.scope===a$1.REQUEST&&e.registrations.set(t,{provider:n.provider,scope:a$1.REQUEST,instance:void 0,resolved:false});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.resolved)continue;let t=e.instance;if(!t||typeof t!="object")continue;let n=t;typeof n.onModuleDestroy=="function"&&S(t)&&await n.onModuleDestroy();}if(this.registrations.clear(),this.parent){let e=this.parent.children.indexOf(this);e!==-1&&this.parent.children.splice(e,1),this.parent=null;}}async createInstance(e,t){let{provider:n}=e;if(typeof n=="function")return this.instantiateClass(n,t);if("useValue"in n)return n.useValue;if("useClass"in n)return this.instantiateClass(n.useClass,t);if("useFactory"in n){let o=n,s=[];if(o.inject)for(let r of o.inject)s.push(await this.resolveInternal(r,t));return o.useFactory(...s)}if("useExisting"in n)return this.resolveInternal(n.useExisting,t);throw new Error("Unknown provider type")}async instantiateClass(e,t){let n=Reflect.getMetadata("design:paramtypes",e)??[],o=i(e),s=j$1(e),r=k$1(e),a=s.size>0?Math.max(...s.keys())+1:0,f=Math.max(n.length,a,o.length),m=[];for(let l=0;l<f;l++){let h=s.get(l)??o[l]??n[l];try{m.push(await this.resolveInternal(h,t));}catch(g){if(g instanceof k&&r.has(l)){m.push(void 0);continue}let M=g instanceof Error?g.message:String(g);throw new Error(`Cannot resolve parameter at index ${l} (${P(h)}) of ${e.name}: ${M}`,{cause:g})}}return new e(...m)}},J=new Set;function P(i){return typeof i=="string"?i:typeof i=="symbol"||i instanceof b?i.toString():typeof i=="function"?i.name:String(i)}a(P,"tokenToString");function _(i,e){let t=[];for(let s=e;typeof s=="function"&&s!==Function.prototype;s=Object.getPrototypeOf(s)){let r=Reflect.getOwnMetadata(i,s);r!==void 0&&r.length>0&&t.push(r);}let n=new Set,o=[];for(let s of t.reverse())for(let r of s)n.has(r)||(n.add(r),o.push(r));return o}a(_,"inheritedClassMetadata");var L=Symbol.for("truxie:controller:path"),v=Symbol.for("truxie:controller:guards"),j=Symbol.for("truxie:route:metadata"),U=Symbol.for("truxie:method:route"),E=Symbol.for("truxie:method:guards"),N=Symbol.for("truxie:method:noguard");function ye(i){return e=>{Reflect.defineMetadata(L,i,e);}}a(ye,"Controller");function x(i){return (e="")=>(t,n,o)=>{let s=o!==void 0,r=String(s?n:n?.name??n),a=s?o?.value:t;if(typeof a=="function"&&(a[U]={method:i,path:e,methodName:r}),s){let f=Reflect.getOwnMetadata(j,t.constructor)??[];return f.push({method:i,path:e,methodName:r}),Reflect.defineMetadata(j,f,t.constructor),o}return t}}a(x,"createMethodDecorator");var we=x("GET"),Ee=x("POST"),xe=x("PUT"),Me=x("DELETE"),be=x("PATCH");function Te(...i){return (e,t,n)=>{if(t==null){let o=Reflect.getOwnMetadata(v,e)??[];Reflect.defineMetadata(v,[...o,...i],e);return}if(n!==void 0){if(n?.value){let o=n.value[E]??[];n.value[E]=[...o,...i];}return n}if(typeof e=="function"){let o=e[E]??[];e[E]=[...o,...i];}if(typeof e=="function"&&t?.kind==="class"){let o=Reflect.getOwnMetadata(v,e)??[];Reflect.defineMetadata(v,[...o,...i],e);}return e}}a(Te,"RouteGuards");function Re(){return (i,e,t)=>t!==void 0?(t?.value&&(t.value[N]=true),t):(typeof i=="function"&&(i[N]=true),i)}a(Re,"NoGuard");function V(i){return Reflect.getOwnMetadata(L,i)}a(V,"getControllerPath");function Se(i){return Reflect.getOwnMetadata(v,i)??[]}a(Se,"getControllerGuards");function Q(i){let e=new Map,t=i.prototype;for(;t&&t!==Object.prototype;){for(let n of Object.getOwnPropertyNames(t)){if(n==="constructor"||e.has(n))continue;let o=Object.getOwnPropertyDescriptor(t,n);!o||typeof o.value!="function"||e.set(n,o.value);}t=Object.getPrototypeOf(t);}return e}a(Q,"methodsOf");function X(i,e){return Q(i).get(e)}a(X,"methodOf");function Oe(i){let e=[],t=new Set;for(let[n,o]of Q(i)){let s=o[U];!s||t.has(n)||(t.add(n),e.push(s));}if(e.length>0)return e;for(let n=i;n&&n!==Function.prototype;n=Object.getPrototypeOf(n)){let o=Reflect.getOwnMetadata(j,n)??[];for(let s of o)t.has(s.methodName)||(t.add(s.methodName),e.push(s));}return e}a(Oe,"getRouteMetadata");function Pe(i,e){let t=X(i,e),n=t!==void 0&&t[N]===true,o=t!==void 0&&t[E]||[];return n?o:[...Z(i),...o]}a(Pe,"getMethodGuards");function Z(i){return _(v,i)}a(Z,"controllerGuardsOf");var z=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 n of this.sortedModules)if(n.global)for(let o of n.providers)t.add(o);t.size>0&&e.register(...t);for(let n of this.sortedModules){e.register(...n.providers);for(let o of n.metadata.imports??[]){let s=this.getModuleType(o),r=this.resolved.get(s);if(r)for(let a of r.exports){let f=this.findProvider(r,a)??this.findReExportedProvider(r,a);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 n of this.sortedModules){for(let o of n.controllers)e.has(o)||(e.add(o),t.push(o));for(let o of n.metadata.providers??[])typeof o=="function"&&V(o)!==void 0&&!e.has(o)&&(e.add(o),t.push(o));}return t}getAllGateways(){let e=new Set,t=[];for(let n of this.sortedModules)for(let o of n.providers)typeof o=="function"&&i$1(o)!==void 0&&!e.has(o)&&(e.add(o),t.push(o));return t}async callLifecycleHooks(e,t,n){for(let o of this.sortedModules)for(let s of o.providers){let r=typeof s=="function"?s:s.provide;if(e.has(r))try{let a=await e.resolve(r);if(a&&typeof a=="object"&&typeof a[t]=="function"){if(t==="onModuleDestroy"&&!S(a))continue;await a[t](n);}}catch{}}}resolveModule(e){let t=d(e),n$1=typeof t=="object"&&"module"in t,o$1=n$1?t.module:t,s=this.resolved.get(o$1);if(s)return n$1&&this.mergeDynamicModule(s,e),s;let r=n(o$1)??{},a=n$1?e:{},f=[...r.controllers??[],...a.controllers??[]],m=[...r.providers??[],...a.providers??[]],l=[...r.exports??[],...a.exports??[]],h=m.map(u=>u&&typeof u=="object"&&"forwardRef"in u?d(u):u),g=l.map(u=>u&&typeof u=="object"&&"forwardRef"in u?d(u):u),M={imports:[...r.imports??[],...a.imports??[]],controllers:f,providers:h,exports:g},D={type:o$1,metadata:M,controllers:f,providers:[...f,...h],exports:new Set(g),global:n$1?e.global??o(o$1):o(o$1)};this.resolved.set(o$1,D);for(let u of M.imports??[])this.resolveModule(u);return D}mergeDynamicModule(e,t){if(t.controllers&&t.controllers.length>0&&(e.controllers.push(...t.controllers),e.providers.push(...t.controllers),e.metadata.controllers=[...e.metadata.controllers??[],...t.controllers]),t.providers&&t.providers.length>0){let n=t.providers.map(o=>o&&typeof o=="object"&&"forwardRef"in o?d(o):o);e.providers.push(...n),e.metadata.providers=[...e.metadata.providers??[],...n];}if(t.exports&&t.exports.length>0){let n=t.exports.map(o=>o&&typeof o=="object"&&"forwardRef"in o?d(o):o);for(let o of n)e.exports.add(o);e.metadata.exports=[...e.metadata.exports??[],...n];}if(t.imports&&t.imports.length>0){e.metadata.imports=[...e.metadata.imports??[],...t.imports];for(let n of t.imports)this.resolveModule(n);}t.global===true&&(e.global=true);}getVisibleTokens(e){let t=new Set;for(let n of e.providers)t.add(this.getProviderToken(n));for(let n of e.metadata.imports??[]){let o=this.getModuleType(n),s=this.resolved.get(o);if(s)for(let r of s.exports)t.add(r);}for(let n of this.sortedModules)if(n.global)for(let o of n.providers)t.add(this.getProviderToken(o));return t}validateExports(){for(let e of this.sortedModules){let t=new Set(e.providers.map(o=>this.getProviderToken(o))),n=this.collectImportedExports(e);for(let o of e.exports)if(!t.has(o)&&!n.has(o)){let s=typeof o=="function"?o.name:String(o);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(e=[]){let t=new Set(e),n=[];for(let o of this.sortedModules){let s=this.getVisibleTokens(o);for(let r of o.providers){let a=typeof r=="function"?r.name:q(r.provide);for(let f of K(r))!s.has(f)&&!t.has(f)&&n.push(`${o.type.name}: ${a} depends on ${q(f)}, but it is not provided in this module and not exported by any imported module`);}}if(n.length>0)throw new Error(n.join(`
|
|
2
|
+
`))}getProviderToken(e){return typeof e=="function"?e:e.provide}collectImportedExports(e){let t=new Set;for(let n of e.metadata.imports??[]){let o=this.getModuleType(n),s=this.resolved.get(o);if(s)for(let r of s.exports)t.add(r);}return t}findProvider(e,t){return e.providers.find(n=>typeof n=="function"?n===t:n.provide===t)}findReExportedProvider(e,t){for(let n of e.metadata.imports??[]){let o=this.getModuleType(n),s=this.resolved.get(o);if(!s||!s.exports.has(t))continue;let r=this.findProvider(s,t);if(r)return r;let a=this.findReExportedProvider(s,t);if(a)return a}}getModuleType(e){let t=d(e);return typeof t=="object"&&"module"in t?t.module:t}topologicalSort(){let e=new Set,t=new Set,n=[],o=a(s=>{if(e.has(s))return;if(t.has(s))throw new Error(`Circular module dependency detected: ${s.name}`);t.add(s);let r=this.resolved.get(s);if(r){for(let a of r.metadata.imports??[])o(this.getModuleType(a));t.delete(s),e.add(s),n.push(r);}},"visit");for(let[s]of this.resolved)o(s);return n}};function q(i){return typeof i=="function"?i.name:String(i)}a(q,"tokenName");function W(i$1){let e=i(i$1),t=j$1(i$1),n=k$1(i$1),o=Math.max(e.length,...[...t.keys()].map(r=>r+1),0),s=[];for(let r=0;r<o;r++){if(n.has(r))continue;let a=t.get(r)??e[r];a!==void 0&&s.push(a);}return s}a(W,"classDependencies");function K(i){return typeof i=="function"?W(i):"useClass"in i?W(d(i.useClass)):"useFactory"in i?(i.inject??[]).map(e=>d(e)):"useExisting"in i?[d(i.useExisting)]:[]}a(K,"providerDependencies");function ee(i,e,t,n){var o=arguments.length,s=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(i,e,t,n);else for(var a=i.length-1;a>=0;a--)(r=i[a])&&(s=(o<3?r(s):o>3?r(e,t,s):r(e,t))||s);return o>3&&s&&Object.defineProperty(e,t,s),s}a(ee,"_ts_decorate");function Y(i,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(i,e)}a(Y,"_ts_metadata");var y=class{static{a(this,"EventEmitter2");}handlers=new Map;pending=new Map;onError;constructor(){this.onError=te;}setOptions(e){e.onError&&(this.onError=e.onError);}subscribe(e,t,n){let o=this.handlers.get(e)??[];o.push({instance:n?.instance??{},methodName:n?.methodName??"anonymous",handler:t}),this.handlers.set(e,o);}registerHandler(e,t,n){let o=t[n].bind(t);this.subscribe(e,o,{instance:t,methodName:n});}async emit(e){let t=this.handlers.get(e.type);if(!t||t.length===0)return;let n=this.executeHandlers(t,e);this.pending.set(n,e.type);try{await n;}finally{this.pending.delete(n);}}emitAsync(e){let t=this.handlers.get(e.type);if(!t||t.length===0)return Promise.resolve([]);let n=this.executeHandlers(t,e).then(o=>(this.pending.delete(n),o),()=>(this.pending.delete(n),[]));return this.pending.set(n,e.type),n}async waitForAllDone(...e){for(;;){let t=this.getPending(e);if(t.length===0)break;await Promise.allSettled(t);}}getPending(e){if(e.length===0)return [...this.pending.keys()];let t=[];for(let[n,o]of this.pending)e.includes(o)&&t.push(n);return t}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();}async executeHandlers(e,t){return (await Promise.allSettled(e.map(async o=>{let s=Date.now();try{return {value:await o.handler(t),durationMs:Date.now()-s}}catch(r){return {err:r,durationMs:Date.now()-s,threw:true}}}))).map((o,s)=>{let r=e[s],a=`${r.instance.constructor?.name??"Unknown"}.${r.methodName}`;if(o.status==="fulfilled"&&!("threw"in o.value))return {name:a,status:"success",value:o.value.value,durationMs:o.value.durationMs};let f=o.status==="fulfilled"?o.value.err:o.reason,m=f instanceof Error?f.message:typeof f=="string"?f:String(f),l=o.status==="fulfilled"?o.value.durationMs:0;return this.onError(f,t.type,a),{name:a,status:"failed",error:m,durationMs:l}})}};y=ee([e(),Y("design:type",Function),Y("design:paramtypes",[])],y);function te(i,e,t){console.error(`[EventEmitter2] Handler "${t}" failed for event "${e}":`,i);}a(te,"defaultErrorHandler");var C=Symbol.for("truxie:on-event");function Ve(i){return (e,t,n)=>{let o=Reflect.getOwnMetadata(C,e.constructor)??[];o.push({eventType:i,methodName:String(t)}),Reflect.defineMetadata(C,o,e.constructor);}}a(Ve,"OnEvent");function B(i){return Reflect.getOwnMetadata(C,i)??[]}a(B,"getOnEventMetadata");async function Be(i,e){let t=await i.resolve(y);for(let n of e){let o=oe(n);if(!o)continue;let s=B(o);if(s.length===0)continue;let r=typeof n=="function"?n:n.provide,a;try{a=await i.resolve(r);}catch{continue}for(let f of s)typeof a[f.methodName]=="function"&&t.registerHandler(f.eventType,a,f.methodName);}}a(Be,"scanEventHandlers");function oe(i){return typeof i=="function"?h(i)?i:null:"useClass"in i?i.useClass:null}a(oe,"getProviderClass");export{S as a,F as b,_ as c,ye as d,we as e,Ee as f,xe as g,Me as h,be as i,Te as j,Re as k,V as l,Se as m,Oe as n,Pe as o,z as p,y as q,Ve as r,Be as s};
|
package/dist/index.d.ts
CHANGED
|
@@ -92,11 +92,14 @@ declare class ModuleRegistry {
|
|
|
92
92
|
*/
|
|
93
93
|
private validateExports;
|
|
94
94
|
/**
|
|
95
|
-
* Validate that
|
|
96
|
-
*
|
|
95
|
+
* Validate that every dependency of every provider (class `@Inject(...)`, parameter `@Inject(token)`,
|
|
96
|
+
* `useClass`, `useFactory.inject`, `useExisting`) is visible to the module that declares it: its own
|
|
97
|
+
* providers, the exports of the modules it imports, a global module, or `alwaysVisible` — tokens the
|
|
98
|
+
* application registers itself outside every module (EventEmitter2, DiscoveryService).
|
|
99
|
+
* `@Optional()` parameters are skipped. Throws once, listing every violation.
|
|
97
100
|
* Call after scan() for strict visibility enforcement.
|
|
98
101
|
*/
|
|
99
|
-
validateVisibility(): void;
|
|
102
|
+
validateVisibility(alwaysVisible?: Iterable<Token>): void;
|
|
100
103
|
private getProviderToken;
|
|
101
104
|
private collectImportedExports;
|
|
102
105
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {l,n,o,b as b$2,p,q,s,c}from'./chunk-6JQLGFPZ.js';export{b 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,m as getControllerGuards,l as getControllerPath,o as getMethodGuards,n as getRouteMetadata}from'./chunk-6JQLGFPZ.js';import {n as n$1,i,j as j$1,k,l as l$1,m as m$1}from'./chunk-RDP32XIU.js';import {b as b$1,p as p$1,i as i$1,j as j$2}from'./chunk-TSJZVSHP.js';export{p as DiscoveryService,m as Global,f as Inject,e as Injectable,b as InjectionToken,l as Module,g as Optional,a as Scope,c as forwardRef,n as getModuleMetadata,o as isGlobalModule,d as resolveForwardRef}from'./chunk-TSJZVSHP.js';import {a}from'./chunk-EI7MMDWY.js';import'reflect-metadata';function se(t,e){if("useFactory"in e&&e.useFactory){let r=e.useFactory;return [{provide:t,useFactory:r,inject:e.inject??[]}]}if("useClass"in e&&e.useClass){let r=e.useClass;return [{provide:t,useFactory:a(async o=>o.createModuleOptions(),"useFactory"),inject:[r]},r]}if("useExisting"in e&&e.useExisting){let r=e.useExisting;return [{provide:t,useFactory:a(async o=>o.createModuleOptions(),"useFactory"),inject:[r]}]}throw new Error("ModuleAsyncOptions must specify one of: useFactory, useClass, or useExisting")}a(se,"createAsyncOptionsProviders");var j=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$1(this.description),r=new b$1(this.featureDescription),o=this.onForRoot,s=this.onForFeature;return {ConfigurableModuleClass:class{static{a(this,"ConfigurableModuleClassImpl");}static forRoot(c,d={}){let u={module:this,global:d.global??false,providers:[{provide:e,useValue:c}],exports:[e]};return o&&(u=o(u,c)),u}static forRootAsync(c){let d=se(e,c),u={module:this,imports:c.imports??[],providers:d,exports:[e]};return o&&(u=o(u)),u}static forFeature(c,d={}){let u={module:this,global:d.global??false,providers:[{provide:r,useValue:c}],exports:[r]};return s&&(u=s(u,c)),u}},MODULE_OPTIONS_TOKEN:e,MODULE_FEATURE_TOKEN:r}}};var U=class{static{a(this,"BaseExecutionContext");}nativeRequest;handler;container;query;params;body;bodyParseError;rawBody;formData;auth;data=new Map;metadata=new Map;abortController;constructor(e,r,o,s={},i={},a){this.nativeRequest=e,this.handler=r,this.container=o,this.query=s,this.params=i,this.abortController=a??new AbortController;}getNativeRequest(){return this.nativeRequest}getHandler(){return this.handler}setHandler(e){this.handler=e;}getBody(){return this.body}setBody(e){this.body=e;}getRawBody(){return this.rawBody}setRawBody(e){this.rawBody=e;}getBodyParseError(){return this.bodyParseError}setBodyParseError(e){this.bodyParseError=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}setContainer(e){this.container=e;}getSignal(){return this.abortController.signal}abort(e){this.abortController.abort(e);}};function nt(t,e,r=""){if(e!=="")try{t.setBody(JSON.parse(e));}catch(o){$t(e,r)&&t.setBodyParseError(o instanceof Error?o:new Error(String(o)));}}a(nt,"applyJsonBody");function $t(t,e){if(e.toLowerCase().includes("json"))return true;let r=t.trimStart().charAt(0);return r==="{"||r==="["}a($t,"looksLikeJson");var ie=Symbol.for("truxie:filters"),st=Symbol.for("truxie:catch");function it(...t){return (e,r,o)=>{let s=r?e.constructor:e,i=Reflect.getOwnMetadata(ie,s)??[];Reflect.defineMetadata(ie,[...i,...t],s);}}a(it,"UseFilters");function at(...t){return e=>{Reflect.defineMetadata(st,t,e);}}a(at,"Catch");function ae(t){return c(ie,t)}a(ae,"getFiltersMetadata");function ce(t){return Reflect.getOwnMetadata(st,t)??[]}a(ce,"getCatchMetadata");var m=class extends Error{static{a(this,"AppError");}statusCode;status;isOperational;constructor(e,r){super(e),this.statusCode=r,this.status=r>=400&&r<500?"fail":"error",this.isOperational=true,Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace(this,this.constructor);}},G=class extends m{static{a(this,"NotFoundError");}constructor(e="Resource not found"){super(e,404);}},y=class extends m{static{a(this,"ValidationError");}errors;constructor(e="Validation failed",r){super(e,400),this.errors=r;}},z=class extends m{static{a(this,"UnauthorizedError");}constructor(e="Not authorized"){super(e,401);}},A=class extends m{static{a(this,"ForbiddenError");}constructor(e="Access forbidden"){super(e,403);}},W=class extends m{static{a(this,"ConflictError");}constructor(e="Resource conflict"){super(e,409);}},P=class extends m{static{a(this,"RequestAbortedError");}constructor(e="Request aborted by client"){super(e,499);}};function _(t,e,r){return async o=>{let s=[...e.middlewares??[],...r.middlewares??[]],i=[...e.guards??[],...r.guards??[]],a$1=[...e.interceptors??[],...r.interceptors??[]],c=[...e.pipes??[],...r.pipes??[]],d=[...e.filters??[],...r.filters??[]],u=await E(t,d);try{x(o);let f=await E(t,s);return await Bt(o,f,async()=>{x(o);let l=await E(t,i);for(let v of l)if(x(o),!await v.canActivate(o))throw new A("Access denied by guard");x(o);let p=await E(t,c);for(let v of p)x(o),await v.transform(o);x(o);let h=await E(t,a$1),ve=a(async()=>(x(o),r.handler(o)),"handlerCall");return h.length===0?ve():h.reduceRight((v,De)=>async()=>(x(o),De.intercept(o,v)),ve)()})}catch(f){return jt(f,o,u)}}}a(_,"createPipeline");async function Bt(t,e,r){return e.length===0?r():e.reduceRight((s,i)=>()=>i.use(t,s),r)()}a(Bt,"runMiddlewareChain");function x(t){if(t.getSignal().aborted)throw new P}a(x,"checkAborted");async function jt(t,e,r){for(let o of r){let s=ce(o.constructor);if(s.length===0||t instanceof Error&&s.some(a=>t instanceof a))return o.catch(t,e)}throw t}a(jt,"handleError");async function E(t,e){let r=[];for(let o of e){if(typeof o!="function"){r.push(o);continue}let s=o;if(t.has(s)){r.push(await t.resolve(s));continue}if(Ut(s))throw new Error(`${s.name} declares constructor dependencies but is not registered as a provider, so they cannot be injected. Add it to a module's \`providers\`, or read what it needs off the ExecutionContext instead (\`ctx.getContainer().resolve(...)\`).`);r.push(new s);}return r}a(E,"resolveRefs");function Ut(t){return i$1(t).length>0||j$2(t).size>0?true:(Reflect.getMetadata?.("design:paramtypes",t)??[]).length>0}a(Ut,"declaresDependencies");var ue=Symbol.for("truxie:interceptors"),de=Symbol.for("truxie:method:interceptors");function ct(...t){return (e,r,o)=>{if(r!==void 0){let i=o?.value??e,a=i[de]??[];return i[de]=[...a,...t],o}let s=Reflect.getOwnMetadata(ue,e)??[];Reflect.defineMetadata(ue,[...s,...t],e);}}a(ct,"UseInterceptors");function fe(t){return c(ue,t)}a(fe,"getInterceptorsMetadata");function le(t,e){let o=t.prototype?.[e];return typeof o=="function"&&o[de]||[]}a(le,"getMethodInterceptors");function H(t,e){return [...fe(t),...le(t,e)]}a(H,"getEffectiveInterceptors");var pe="uow:session",he="uow:instance",K=class{static{a(this,"UnitOfWorkInterceptor");}factory;constructor(e){this.factory=e;}async intercept(e,r){let o=this.factory();await o.start(),e.setData(pe,o.getContext()),e.setData(he,o);try{let s=await r();return await o.commit(),s}catch(s){throw await o.rollback(),s}}};var me=Symbol.for("truxie:middlewares"),ye=Symbol.for("truxie:method:middlewares");function ut(...t){return (e,r,o)=>{if(r!==void 0){let i=o?.value??e,a=i[ye]??[];return i[ye]=[...a,...t],o}let s=Reflect.getOwnMetadata(me,e)??[];Reflect.defineMetadata(me,[...s,...t],e);}}a(ut,"UseMiddleware");function ge(t){return c(me,t)}a(ge,"getMiddlewaresMetadata");function we(t,e){let o=t.prototype?.[e];return typeof o=="function"&&o[ye]||[]}a(we,"getMethodMiddlewares");function Y(t,e){return [...ge(t),...we(t,e)]}a(Y,"getEffectiveMiddlewares");var xe=Symbol.for("truxie:pipes");function dt(...t){return (e,r,o)=>{let s=r?e.constructor:e,i=Reflect.getOwnMetadata(xe,s)??[];Reflect.defineMetadata(xe,[...i,...t],s);}}a(dt,"UsePipes");function Ee(t){return c(xe,t)}a(Ee,"getPipesMetadata");var Gt=/^[0-9a-fA-F]{24}$/,L=class{static{a(this,"ParseIdPipe");}paramName;constructor(e="id"){this.paramName=e;}transform(e){let o=e.getParams()[this.paramName];if(!o||!Gt.test(o))throw new y(`Invalid ${this.paramName}: must be a valid ObjectId`)}};var V=class{static{a(this,"ParseIntPipe");}transform(e){let r=Number(e);if(!Number.isInteger(r)||e===""||e===null||e===void 0)throw new y(`Expected an integer, received: ${JSON.stringify(e)}`);return r}};function ft(t){return {transform(e){return e??t}}}a(ft,"DefaultValuePipe");var J=class{static{a(this,"DomainEvent");}payload;timestamp;constructor(e){this.payload=e,this.timestamp=Date.now();}};function lt(t){let e=t,r=typeof e?.statusCode=="number"&&e.statusCode>=400&&e.statusCode<=599?e.statusCode:500,s=(e?.isOperational===true||r>=400&&r<500)&&typeof e?.message=="string"&&e.message.length>0?e.message:"Internal server error";return {status:r,message:s}}a(lt,"clientSafeError");var R=class{static{a(this,"ControllerRouter");}routes=[];globalPrefix;constructor(e=""){this.globalPrefix=e;}register(...e){for(let r of e){let o$1=l(r)??"",s=n(r);for(let i of s){let a=pt(`${this.globalPrefix}/${o$1}/${i.path}`);Wt(a,r.name,i.methodName),this.checkDuplicate(a,i.method,r.name,i.methodName);let{pattern:c,paramNames:d}=ht(a),u=o(r,i.methodName),f=H(r,i.methodName),l=Y(r,i.methodName);this.routes.push({method:i.method,pattern:c,paramNames:d,controllerClass:r,methodName:i.methodName,guardClasses:u,interceptorRefs:f,middlewareRefs:l,pipeRefs:Ee(r),filterRefs:ae(r),rawPath:a});}}this.routes.sort((r,o)=>mt(r.rawPath)-mt(o.rawPath));}checkDuplicate(e,r,o,s){let{pattern:i}=ht(e),a=this.routes.find(c=>c.method===r&&c.pattern.source===i.source);if(a){let c=a.rawPath===e?e:`${a.rawPath} / ${e}`;throw new Error(`Duplicate route: ${r} ${c}
|
|
1
|
+
import {l,n,o,b as b$2,p,q,s,c}from'./chunk-CD6QSDG5.js';export{b 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,m as getControllerGuards,l as getControllerPath,o as getMethodGuards,n as getRouteMetadata}from'./chunk-CD6QSDG5.js';import {n as n$1,i,j as j$1,k,l as l$1,m as m$1}from'./chunk-RDP32XIU.js';import {b as b$1,p as p$1,i as i$1,j as j$2}from'./chunk-TSJZVSHP.js';export{p as DiscoveryService,m as Global,f as Inject,e as Injectable,b as InjectionToken,l as Module,g as Optional,a as Scope,c as forwardRef,n as getModuleMetadata,o as isGlobalModule,d as resolveForwardRef}from'./chunk-TSJZVSHP.js';import {a}from'./chunk-EI7MMDWY.js';import'reflect-metadata';function se(t,e){if("useFactory"in e&&e.useFactory){let r=e.useFactory;return [{provide:t,useFactory:r,inject:e.inject??[]}]}if("useClass"in e&&e.useClass){let r=e.useClass;return [{provide:t,useFactory:a(async o=>o.createModuleOptions(),"useFactory"),inject:[r]},r]}if("useExisting"in e&&e.useExisting){let r=e.useExisting;return [{provide:t,useFactory:a(async o=>o.createModuleOptions(),"useFactory"),inject:[r]}]}throw new Error("ModuleAsyncOptions must specify one of: useFactory, useClass, or useExisting")}a(se,"createAsyncOptionsProviders");var j=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$1(this.description),r=new b$1(this.featureDescription),o=this.onForRoot,s=this.onForFeature;return {ConfigurableModuleClass:class{static{a(this,"ConfigurableModuleClassImpl");}static forRoot(c,d={}){let u={module:this,global:d.global??false,providers:[{provide:e,useValue:c}],exports:[e]};return o&&(u=o(u,c)),u}static forRootAsync(c){let d=se(e,c),u={module:this,imports:c.imports??[],providers:d,exports:[e]};return o&&(u=o(u)),u}static forFeature(c,d={}){let u={module:this,global:d.global??false,providers:[{provide:r,useValue:c}],exports:[r]};return s&&(u=s(u,c)),u}},MODULE_OPTIONS_TOKEN:e,MODULE_FEATURE_TOKEN:r}}};var U=class{static{a(this,"BaseExecutionContext");}nativeRequest;handler;container;query;params;body;bodyParseError;rawBody;formData;auth;data=new Map;metadata=new Map;abortController;constructor(e,r,o,s={},i={},a){this.nativeRequest=e,this.handler=r,this.container=o,this.query=s,this.params=i,this.abortController=a??new AbortController;}getNativeRequest(){return this.nativeRequest}getHandler(){return this.handler}setHandler(e){this.handler=e;}getBody(){return this.body}setBody(e){this.body=e;}getRawBody(){return this.rawBody}setRawBody(e){this.rawBody=e;}getBodyParseError(){return this.bodyParseError}setBodyParseError(e){this.bodyParseError=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}setContainer(e){this.container=e;}getSignal(){return this.abortController.signal}abort(e){this.abortController.abort(e);}};function nt(t,e,r=""){if(e!=="")try{t.setBody(JSON.parse(e));}catch(o){$t(e,r)&&t.setBodyParseError(o instanceof Error?o:new Error(String(o)));}}a(nt,"applyJsonBody");function $t(t,e){if(e.toLowerCase().includes("json"))return true;let r=t.trimStart().charAt(0);return r==="{"||r==="["}a($t,"looksLikeJson");var ie=Symbol.for("truxie:filters"),st=Symbol.for("truxie:catch");function it(...t){return (e,r,o)=>{let s=r?e.constructor:e,i=Reflect.getOwnMetadata(ie,s)??[];Reflect.defineMetadata(ie,[...i,...t],s);}}a(it,"UseFilters");function at(...t){return e=>{Reflect.defineMetadata(st,t,e);}}a(at,"Catch");function ae(t){return c(ie,t)}a(ae,"getFiltersMetadata");function ce(t){return Reflect.getOwnMetadata(st,t)??[]}a(ce,"getCatchMetadata");var m=class extends Error{static{a(this,"AppError");}statusCode;status;isOperational;constructor(e,r){super(e),this.statusCode=r,this.status=r>=400&&r<500?"fail":"error",this.isOperational=true,Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace(this,this.constructor);}},G=class extends m{static{a(this,"NotFoundError");}constructor(e="Resource not found"){super(e,404);}},y=class extends m{static{a(this,"ValidationError");}errors;constructor(e="Validation failed",r){super(e,400),this.errors=r;}},z=class extends m{static{a(this,"UnauthorizedError");}constructor(e="Not authorized"){super(e,401);}},C=class extends m{static{a(this,"ForbiddenError");}constructor(e="Access forbidden"){super(e,403);}},W=class extends m{static{a(this,"ConflictError");}constructor(e="Resource conflict"){super(e,409);}},v=class extends m{static{a(this,"RequestAbortedError");}constructor(e="Request aborted by client"){super(e,499);}};function _(t,e,r){return async o=>{let s=[...e.middlewares??[],...r.middlewares??[]],i=[...e.guards??[],...r.guards??[]],a$1=[...e.interceptors??[],...r.interceptors??[]],c=[...e.pipes??[],...r.pipes??[]],d=[...e.filters??[],...r.filters??[]],u=await E(t,d);try{x(o);let f=await E(t,s);return await Bt(o,f,async()=>{x(o);let l=await E(t,i);for(let S of l)if(x(o),!await S.canActivate(o))throw new C("Access denied by guard");x(o);let p=await E(t,c);for(let S of p)x(o),await S.transform(o);x(o);let h=await E(t,a$1),ve=a(async()=>(x(o),r.handler(o)),"handlerCall");return h.length===0?ve():h.reduceRight((S,De)=>async()=>(x(o),De.intercept(o,S)),ve)()})}catch(f){return jt(f,o,u)}}}a(_,"createPipeline");async function Bt(t,e,r){return e.length===0?r():e.reduceRight((s,i)=>()=>i.use(t,s),r)()}a(Bt,"runMiddlewareChain");function x(t){if(t.getSignal().aborted)throw new v}a(x,"checkAborted");async function jt(t,e,r){for(let o of r){let s=ce(o.constructor);if(s.length===0||t instanceof Error&&s.some(a=>t instanceof a))return o.catch(t,e)}throw t}a(jt,"handleError");async function E(t,e){let r=[];for(let o of e){if(typeof o!="function"){r.push(o);continue}let s=o;if(t.has(s)){r.push(await t.resolve(s));continue}if(Ut(s))throw new Error(`${s.name} declares constructor dependencies but is not registered as a provider, so they cannot be injected. Add it to a module's \`providers\`, or read what it needs off the ExecutionContext instead (\`ctx.getContainer().resolve(...)\`).`);r.push(new s);}return r}a(E,"resolveRefs");function Ut(t){return i$1(t).length>0||j$2(t).size>0?true:(Reflect.getMetadata?.("design:paramtypes",t)??[]).length>0}a(Ut,"declaresDependencies");var ue=Symbol.for("truxie:interceptors"),de=Symbol.for("truxie:method:interceptors");function ct(...t){return (e,r,o)=>{if(r!==void 0){let i=o?.value??e,a=i[de]??[];return i[de]=[...a,...t],o}let s=Reflect.getOwnMetadata(ue,e)??[];Reflect.defineMetadata(ue,[...s,...t],e);}}a(ct,"UseInterceptors");function fe(t){return c(ue,t)}a(fe,"getInterceptorsMetadata");function le(t,e){let o=t.prototype?.[e];return typeof o=="function"&&o[de]||[]}a(le,"getMethodInterceptors");function H(t,e){return [...fe(t),...le(t,e)]}a(H,"getEffectiveInterceptors");var pe="uow:session",he="uow:instance",K=class{static{a(this,"UnitOfWorkInterceptor");}factory;constructor(e){this.factory=e;}async intercept(e,r){let o=this.factory();await o.start(),e.setData(pe,o.getContext()),e.setData(he,o);try{let s=await r();return await o.commit(),s}catch(s){throw await o.rollback(),s}}};var me=Symbol.for("truxie:middlewares"),ye=Symbol.for("truxie:method:middlewares");function ut(...t){return (e,r,o)=>{if(r!==void 0){let i=o?.value??e,a=i[ye]??[];return i[ye]=[...a,...t],o}let s=Reflect.getOwnMetadata(me,e)??[];Reflect.defineMetadata(me,[...s,...t],e);}}a(ut,"UseMiddleware");function ge(t){return c(me,t)}a(ge,"getMiddlewaresMetadata");function we(t,e){let o=t.prototype?.[e];return typeof o=="function"&&o[ye]||[]}a(we,"getMethodMiddlewares");function Y(t,e){return [...ge(t),...we(t,e)]}a(Y,"getEffectiveMiddlewares");var xe=Symbol.for("truxie:pipes");function dt(...t){return (e,r,o)=>{let s=r?e.constructor:e,i=Reflect.getOwnMetadata(xe,s)??[];Reflect.defineMetadata(xe,[...i,...t],s);}}a(dt,"UsePipes");function Ee(t){return c(xe,t)}a(Ee,"getPipesMetadata");var Gt=/^[0-9a-fA-F]{24}$/,L=class{static{a(this,"ParseIdPipe");}paramName;constructor(e="id"){this.paramName=e;}transform(e){let o=e.getParams()[this.paramName];if(!o||!Gt.test(o))throw new y(`Invalid ${this.paramName}: must be a valid ObjectId`)}};var V=class{static{a(this,"ParseIntPipe");}transform(e){let r=Number(e);if(!Number.isInteger(r)||e===""||e===null||e===void 0)throw new y(`Expected an integer, received: ${JSON.stringify(e)}`);return r}};function ft(t){return {transform(e){return e??t}}}a(ft,"DefaultValuePipe");var J=class{static{a(this,"DomainEvent");}payload;timestamp;constructor(e){this.payload=e,this.timestamp=Date.now();}};function lt(t){let e=t,r=typeof e?.statusCode=="number"&&e.statusCode>=400&&e.statusCode<=599?e.statusCode:500,s=(e?.isOperational===true||r>=400&&r<500)&&typeof e?.message=="string"&&e.message.length>0?e.message:"Internal server error";return {status:r,message:s}}a(lt,"clientSafeError");var R=class{static{a(this,"ControllerRouter");}routes=[];globalPrefix;constructor(e=""){this.globalPrefix=e;}register(...e){for(let r of e){let o$1=l(r)??"",s=n(r);for(let i of s){let a=pt(`${this.globalPrefix}/${o$1}/${i.path}`);Wt(a,r.name,i.methodName),this.checkDuplicate(a,i.method,r.name,i.methodName);let{pattern:c,paramNames:d}=ht(a),u=o(r,i.methodName),f=H(r,i.methodName),l=Y(r,i.methodName);this.routes.push({method:i.method,pattern:c,paramNames:d,controllerClass:r,methodName:i.methodName,guardClasses:u,interceptorRefs:f,middlewareRefs:l,pipeRefs:Ee(r),filterRefs:ae(r),rawPath:a});}}this.routes.sort((r,o)=>mt(r.rawPath)-mt(o.rawPath));}checkDuplicate(e,r,o,s){let{pattern:i}=ht(e),a=this.routes.find(c=>c.method===r&&c.pattern.source===i.source);if(a){let c=a.rawPath===e?e:`${a.rawPath} / ${e}`;throw new Error(`Duplicate route: ${r} ${c}
|
|
2
2
|
Already registered by: ${a.controllerClass.name}.${a.methodName}
|
|
3
|
-
Conflicting with: ${o}.${s}`)}}match(e,r){let o=e.toUpperCase(),s=pt(r);for(let i of this.routes){if(i.method!==o)continue;let a=i.pattern.exec(s);if(!a)continue;let c={};for(let d=0;d<i.paramNames.length;d++)c[i.paramNames[d]]=a[d+1]??"";return {route:i,params:c}}return null}getRoutes(){return this.routes}};function pt(t){return "/"+t.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}a(pt,"normalizePath");function ht(t){let e=[],r=t.split("/").map(o=>o.startsWith(":")?(e.push(o.slice(1)),"([^/]+)"):zt(o)).join("/");return {pattern:new RegExp(`^${r}$`),paramNames:e}}a(ht,"compilePath");function zt(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}a(zt,"escapeRegex");function mt(t){return t.split("/").filter(Boolean).reduce((e,r)=>e+(r.startsWith(":")?1:0),0)}a(mt,"routePriority");function Wt(t,e,r){let o=`Invalid path "${t}" on ${e}.${r}:`;if(!t.startsWith("/"))throw new Error(`${o} must start with /`);let s=t.split("/").filter((a,c)=>c>0),i=new Set;for(let a of s){if(a==="")throw new Error(`${o} 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(`${o} invalid param name ":${c}" \u2014 must be a valid identifier`);if(i.has(c))throw new Error(`${o} duplicate param name ":${c}"`);i.add(c);}}}a(Wt,"validatePath");var N="__trustProxy",Re="__remoteAddress";function yt(t){return C(t.getNativeRequest())}a(yt,"getRequestHeaders");function C(t){let e=t?.node?.req?.headers;if(e&&typeof e=="object")return e;let r=t?.headers;return r&&typeof r.entries=="function"?Object.fromEntries(r.entries()):r&&typeof r=="object"?r:{}}a(C,"headersOf");function Q(t){let e=Ht(t);if(t.getData(N)!==true)return e;let r=C(t.getNativeRequest()),o=r["cf-connecting-ip"];if(o)return String(o).trim();let s=r["x-forwarded-for"];if(s){let a=String(s).split(",")[0]?.trim();if(a)return a}let i=r["x-real-ip"];return i?String(i).trim():e}a(Q,"clientIp");function Ht(t){let e=t.getData(Re);if(e)return e;let r=t.getNativeRequest();return r?.node?.req?.socket?.remoteAddress??r?.socket?.remoteAddress??""}a(Ht,"directAddress");var b=Symbol.for("truxie:route:params");function Kt(t){return t==null?false:typeof t=="function"||typeof t=="object"&&typeof t.transform=="function"}a(Kt,"isParamPipeRef");function X(t,e){return Kt(t)?{key:void 0,pipes:[t,...e??[]]}:{key:t,pipes:e??[]}}a(X,"resolveArgs");function g(t,e,r=[]){return (o,s,i)=>{if(s===void 0)return;let a=o[s];if(typeof a!="function")return;let c=a[b]??[];a[b]=[...c,{index:i,type:t,key:e,pipes:r.length>0?r:void 0}];}}a(g,"buildBuiltinDecorator");function Yt(t){return typeof t=="function"?new t:t}a(Yt,"resolveParamPipe");function gt(t,...e){let{key:r,pipes:o}=X(t,e);return g("query",r,o)}a(gt,"Query");function wt(t,...e){let{key:r,pipes:o}=X(t,e);return g("param",r,o)}a(wt,"Param");function xt(t,...e){let{key:r,pipes:o}=X(t,e);return g("body",r,o)}a(xt,"Body");var Et=a(()=>g("rawBody"),"RawBody"),Rt=a(()=>g("formData"),"FormData"),bt=a(()=>g("ip"),"Ip"),Mt=a(()=>g("userAgent"),"UserAgent"),At=a(t=>g("cookie",t),"Cookie");function Pt(t,...e){let{key:r,pipes:o}=X(t,e);return g("headers",r,o)}a(Pt,"Headers");function be(t){return ()=>(e,r,o)=>{if(r===void 0)return;let s=e[r];if(typeof s!="function")return;let i=s[b]??[];s[b]=[...i,{index:o,type:"auth",extractor:t}];}}a(be,"defineAuth");var Ct=be();function vt(t,e){return ()=>(r,o,s)=>{if(o===void 0)return;let i=r[o];if(typeof i!="function")return;let a=i[b]??[];i[b]=[...a,{index:s,type:"custom",extractor:t,schema:e?.schema,source:e?.source}];}}a(vt,"createParamDecorator");function M(t,e){let r=t.prototype[e];if(typeof r!="function")return null;let o=r[b];return o&&o.length>0?o:null}a(M,"getRouteParams");async function Z(t,e){let r=Math.max(...t.map(s=>s.index)),o=new Array(r+1).fill(void 0);for(let{index:s,type:i,key:a,pipes:c,extractor:d}of t){let u;switch(i){case "query":{let f=e.getQuery();u=a!==void 0?f[a]:f;break}case "param":{let f=e.getParams();u=a!==void 0?f[a]:f;break}case "body":{let f=e.getBodyParseError();if(f)throw new y(`Malformed JSON body: ${f.message}`);let l=e.getBody()??{};u=a!==void 0?l[a]:l;break}case "rawBody":{u=e.getRawBody();break}case "formData":{u=e.getFormData();break}case "headers":{let f=C(e.getNativeRequest());u=a!==void 0?f[a.toLowerCase()]:f;break}case "cookie":{let l=C(e.getNativeRequest()).cookie??"";if(a&&l){let p=l.split(";").map(h=>h.trim()).find(h=>h.startsWith(a+"="));u=p?decodeURIComponent(p.slice(a.length+1)):void 0;}else u=void 0;break}case "ip":{u=Q(e);break}case "userAgent":{u=C(e.getNativeRequest())["user-agent"]??"";break}case "auth":{u=d?await d(e):e.getAuth();break}case "custom":{u=d?await d(e):void 0;break}}if(c&&c.length>0)for(let f of c)u=await Yt(f).transform(u);o[s]=u;}return o}a(Z,"resolveParamArgs");var ee=Symbol.for("truxie:api:doc");function Dt(t){return (e,r,o)=>o!==void 0?(typeof o.value=="function"&&Ae(o.value,t,"override"),o):(typeof e=="function"&&Ae(e,t,"override"),e)}a(Dt,"ApiDoc");function St(t,e){Ae(t,e,"fill");}a(St,"contributeApiDoc");function Ae(t,e,r){let o=t,s=Lt(o[ee])?o[ee]:{},i=Me(e),a=r==="override"?{...s,...i}:{...i,...s},c=r==="override"?{...s.extensions,...i.extensions}:{...i.extensions,...s.extensions};if(Object.keys(c).length>0&&(a.extensions=c),s.request||i.request){let d=Me(s.request??{}),u=Me(i.request??{});a.request=r==="override"?{...d,...u}:{...u,...d};}o[ee]=a;}a(Ae,"writeApiDoc");function Me(t){return Object.fromEntries(Object.entries(t).filter(([,e])=>e!==void 0))}a(Me,"defined");function Lt(t){return typeof t=="object"&&t!==null}a(Lt,"isRecord");function T(t,e){let r=t.prototype?.[e];if(typeof r!="function")return null;let o=r[ee];return Vt(o)?o:null}a(T,"getApiDoc");function It(t){return t?.returns?(Array.isArray(t.returns)?t.returns:[t.returns]).map(r=>({...r,status:r.status??200})):[]}a(It,"apiResponses");function Vt(t){return typeof t=="object"&&t!==null&&typeof t.summary=="string"}a(Vt,"isApiDoc");function Tt(t,e={}){let r=M(t.controllerClass,t.methodName)??[],o=T(t.controllerClass,t.methodName)?.request,s=e.toJsonSchema,i={},a=Pe(r,"param",s)??te(o?.params,s)??Xt(t.paramNames);a&&(i.params=a);let c=e.querySchema??Pe(r,"query",s)??te(o?.query,s)??_t(r,"query");if(c&&(i.query=c),t.method!=="GET"){let d=e.bodySchema??Pe(r,"body",s)??te(o?.body,s)??_t(r,"body")??Qt(r);d&&Object.assign(i,{body:d},Jt(o));}return i}a(Tt,"describeRouteInput");function Jt(t){let e={},r=t?.contentType===void 0?[]:[t.contentType].flat();return r.length>0&&(e.bodyContentTypes=r),t?.bodyRequired!==void 0&&(e.bodyRequired=t.bodyRequired),e}a(Jt,"bodyMedia");function Pe(t,e,r){if(r)for(let o of t){if(o.schema===void 0||(o.source??o.type)!==e)continue;let s=r(o.schema,{io:"input"});if(s)return s}}a(Pe,"schemaFor");function te(t,e){if(t!==void 0)return Ce(t)?t:e?.(t,{io:"input"})??void 0}a(te,"documentedSchema");function _t(t,e){let r=kt(t,e);if(r.length===0)return;let o={};for(let s of r)o[s]={};return {type:"object",properties:o}}a(_t,"keyedSchema");function Qt(t){return t.some(r=>r.type==="body"||r.source==="body")?{type:"object",description:"Shape not declared by the handler."}:void 0}a(Qt,"looseBody");function Xt(t){if(t.length===0)return;let e={};for(let r of t)e[r]={type:"string"};return {type:"object",properties:e,required:[...t]}}a(Xt,"pathParamsSchema");function Ce(t){if(typeof t!="object"||t===null)return false;let e=t;return typeof e._def=="object"||typeof e._zod=="object"?false:"type"in e||"properties"in e||"$ref"in e||"anyOf"in e||"allOf"in e||"oneOf"in e}a(Ce,"isJsonSchemaObject");function Ot(t,e={}){let r=M(t.controllerClass,t.methodName)??[],o=T(t.controllerClass,t.methodName)?.request;return {query:Nt(r,"query",o?.query,e.toJsonSchema),body:Nt(r,"body",o?.body,e.toJsonSchema)}}a(Ot,"routeInputDrift");function Nt(t,e,r,o){let s={undocumented:[],unread:[]};if(r===void 0||Zt(t,e))return s;let i=er(te(r,o));if(!i)return s;let a=new Set(kt(t,e)),c=new Set(i);return {undocumented:[...a].filter(d=>!c.has(d)),unread:i.filter(d=>!a.has(d))}}a(Nt,"partDrift");function kt(t,e){let r=t.filter(o=>o.type===e&&typeof o.key=="string").map(o=>o.key);return [...new Set(r)]}a(kt,"readKeys");function Zt(t,e){return t.some(r=>r.type===e&&r.key===void 0||r.type==="custom"&&r.source===e?true:e==="body"&&(r.type==="rawBody"||r.type==="formData"))}a(Zt,"readsWholeObject");function er(t){let r=tr(t)?.properties;return typeof r!="object"||r===null?null:Object.keys(r)}a(er,"propertyNames");function tr(t){let e=t?.$ref;if(typeof e!="string")return t;let r=/^#\/(\$defs|definitions)\/([^/]+)$/.exec(e);return r?t?.[r[1]]?.[rr(r[2])]??t:t}a(tr,"resolveRootRef");function rr(t){return t.replace(/~1/g,"/").replace(/~0/g,"~")}a(rr,"decodePointer");var Ft="__redirect";function qt(t,e=302){return {__redirect:true,url:t,statusCode:e}}a(qt,"redirect");function re(t){return t!==null&&typeof t=="object"&&t.__redirect===true}a(re,"isRedirect");function oe(){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(oe,"isServerless");var O=class{static{a(this,"TruxieApplication");}container;registry;initialized=false;rootModule;options;eventEmitter;prefix="";trustProxy;router;gateways=new Map;wsInitialized=false;constructor(e,r={}){this.rootModule=e,this.options=r,this.trustProxy=r.trustProxy??oe(),this.container=new b$2,this.registry=new p;}async init(){if(this.initialized)return;this.eventEmitter=new q,this.options.eventBus&&this.eventEmitter.setOptions(this.options.eventBus),this.container.register({provide:q,useValue:this.eventEmitter});let e=new p$1;this.container.register({provide:p$1,useValue:e}),this.registry.scan(this.rootModule),this.options.strictModuleBoundaries&&this.registry.validateVisibility(),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 R(this.prefix),this.router.register(...this.registry.getAllControllers()),this.initialized=true;}setGlobalPrefix(e){return this.prefix=e,this.initialized&&(this.router=new R(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}getRoutes(){return this.ensureInitialized(),this.router.getRoutes()}async handleRequest(e,r){this.ensureInitialized();let{container:o,dispose:s}=this.createRequestContext();try{let i=await o.resolve(e.controllerClass),a$1=i[e.methodName];if(typeof a$1!="function")throw new Error(`${e.controllerClass.name}.${e.methodName} is not a method on the resolved controller.`);let c=a$1.bind(i),d=M(e.controllerClass,e.methodName);r.setData("__controllerClass",e.controllerClass),r.setData("__methodName",e.methodName),r.setData(N,this.trustProxy),r.setHandler?.(a$1),r.setContainer?.(o);let f=await _(o,this.getGlobalOptions(),{middlewares:e.middlewareRefs,guards:e.guardClasses,interceptors:e.interceptorRefs,pipes:e.pipeRefs,filters:e.filterRefs,handler:a(async l=>d?c(...await Z(d,l)):c(l),"handler")})(r);if(re(f)){let l=f;return {value:f,isRedirect:!0,redirectUrl:l.url,redirectStatus:l.statusCode}}return {value:f,isRedirect:!1}}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(o){let i="/"+(e.getUrl(o).split("?")[0]??"/").replace(/^\/+|\/+$/g,""),a=r.matchGatewayPath(i);if(!a)return;let c=r.gateways.get(a),d=e.adaptPeer(o);for(let f of c.guards){let l=false;try{l=await f.canActivate(d);}catch(p){console.error(`[WS] ${c.className} guard error:`,p);}if(!l){d.close(1008,"Unauthorized");return}}let u=o.context;u&&(u._gatewayPath=a);for(let f of c.serverProps)c.instance[f]={peers:e.getPeers(o)??new Set};if(c.hasConnection)try{await c.instance.handleConnection(d);}catch(f){console.error(`[WS] ${c.className}.handleConnection error:`,f);}},async message(o,s){let a=o.context?._gatewayPath;if(!a)return;let c=r.gateways.get(a);if(!c)return;let d=e.adaptPeer(o),u=e.adaptMessage(s),f;try{f=u.json();}catch{return}if(!f.event||typeof f.event!="string")return;let l=c.messageHandlers.get(f.event);if(l)try{let p=n$1(l.paramMeta,d,u,f.data),h=await l.method(...p);h!=null&&d.send(h);}catch(p){console.error(`[WS] ${c.className}.${f.event} error:`,p);}},async close(o,s){let a=o.context?._gatewayPath;if(!a)return;let c=r.gateways.get(a);if(!c?.hasDisconnect)return;let d=e.adaptPeer(o);try{await c.instance.handleDisconnect(d,s);}catch(u){console.error(`[WS] ${c.className}.handleDisconnect error:`,u);}},async error(o,s){let i=o?.id??"unknown";console.error(`[WS] Peer ${String(i)} 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(),_(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;if(this.prefix){let r="/"+this.prefix.replace(/^\/+|\/+$/g,"");if(r!=="/"&&e.startsWith(r+"/")){let o=e.slice(r.length);if(this.gateways.has(o))return o}}}async initGateways(){if(!this.wsInitialized){for(let e of this.registry.getAllGateways()){let r=i(e);if(!r)continue;let o=await this.container.resolve(e),s=new Map;for(let a of j$1(e)){let c=o[a.methodName];typeof c=="function"&&s.set(a.event,{method:c.bind(o),paramMeta:k(e.prototype[a.methodName])});}let i$1=await E(this.container,l$1(e));if(this.gateways.set(r.path,{instance:o,className:e.name,messageHandlers:s,hasConnection:typeof o.handleConnection=="function",hasDisconnect:typeof o.handleDisconnect=="function",serverProps:m$1(e),guards:i$1}),typeof o.afterInit=="function")try{await o.afterInit();}catch{}}this.wsInitialized=true;}}getGlobalOptions(){return {middlewares:this.options.globalMiddlewares,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().")}},ne=class{static{a(this,"TruxieFactory");}static async create(e,r){let o=new O(e,r);return await o.init(),o}};export{Dt as ApiDoc,m as AppError,Ct as Auth,U as BaseExecutionContext,xt as Body,at as Catch,j as ConfigurableModuleBuilder,W as ConflictError,R as ControllerRouter,At as Cookie,ft as DefaultValuePipe,J as DomainEvent,A as ForbiddenError,Rt as FormData,Pt as Headers,bt as Ip,G as NotFoundError,wt as Param,L as ParseIdPipe,V as ParseIntPipe,gt as Query,Ft as REDIRECT_BRAND,Re as REMOTE_ADDRESS_KEY,Et as RawBody,P as RequestAbortedError,N as TRUST_PROXY_KEY,O as TruxieApplication,ne as TruxieFactory,he as UOW_INSTANCE_KEY,pe as UOW_SESSION_KEY,z as UnauthorizedError,K as UnitOfWorkInterceptor,it as UseFilters,ct as UseInterceptors,ut as UseMiddleware,dt as UsePipes,Mt as UserAgent,y as ValidationError,It as apiResponses,nt as applyJsonBody,Q as clientIp,lt as clientSafeError,St as contributeApiDoc,se as createAsyncOptionsProviders,vt as createParamDecorator,_ as createPipeline,be as defineAuth,Tt as describeRouteInput,T as getApiDoc,H as getEffectiveInterceptors,Y as getEffectiveMiddlewares,fe as getInterceptorsMetadata,le as getMethodInterceptors,we as getMethodMiddlewares,ge as getMiddlewaresMetadata,yt as getRequestHeaders,M as getRouteParams,Ce as isJsonSchemaObject,re as isRedirect,oe as isServerless,qt as redirect,Z as resolveParamArgs,Ot as routeInputDrift};
|
|
3
|
+
Conflicting with: ${o}.${s}`)}}match(e,r){let o=e.toUpperCase(),s=pt(r);for(let i of this.routes){if(i.method!==o)continue;let a=i.pattern.exec(s);if(!a)continue;let c={};for(let d=0;d<i.paramNames.length;d++)c[i.paramNames[d]]=a[d+1]??"";return {route:i,params:c}}return null}getRoutes(){return this.routes}};function pt(t){return "/"+t.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}a(pt,"normalizePath");function ht(t){let e=[],r=t.split("/").map(o=>o.startsWith(":")?(e.push(o.slice(1)),"([^/]+)"):zt(o)).join("/");return {pattern:new RegExp(`^${r}$`),paramNames:e}}a(ht,"compilePath");function zt(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}a(zt,"escapeRegex");function mt(t){return t.split("/").filter(Boolean).reduce((e,r)=>e+(r.startsWith(":")?1:0),0)}a(mt,"routePriority");function Wt(t,e,r){let o=`Invalid path "${t}" on ${e}.${r}:`;if(!t.startsWith("/"))throw new Error(`${o} must start with /`);let s=t.split("/").filter((a,c)=>c>0),i=new Set;for(let a of s){if(a==="")throw new Error(`${o} 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(`${o} invalid param name ":${c}" \u2014 must be a valid identifier`);if(i.has(c))throw new Error(`${o} duplicate param name ":${c}"`);i.add(c);}}}a(Wt,"validatePath");var N="__trustProxy",Re="__remoteAddress";function yt(t){return D(t.getNativeRequest())}a(yt,"getRequestHeaders");function D(t){let e=t?.node?.req?.headers;if(e&&typeof e=="object")return e;let r=t?.headers;return r&&typeof r.entries=="function"?Object.fromEntries(r.entries()):r&&typeof r=="object"?r:{}}a(D,"headersOf");function Q(t){let e=Ht(t);if(t.getData(N)!==true)return e;let r=D(t.getNativeRequest()),o=r["cf-connecting-ip"];if(o)return String(o).trim();let s=r["x-forwarded-for"];if(s){let a=String(s).split(",")[0]?.trim();if(a)return a}let i=r["x-real-ip"];return i?String(i).trim():e}a(Q,"clientIp");function Ht(t){let e=t.getData(Re);if(e)return e;let r=t.getNativeRequest();return r?.node?.req?.socket?.remoteAddress??r?.socket?.remoteAddress??""}a(Ht,"directAddress");var b=Symbol.for("truxie:route:params");function Kt(t){return t==null?false:typeof t=="function"||typeof t=="object"&&typeof t.transform=="function"}a(Kt,"isParamPipeRef");function X(t,e){return Kt(t)?{key:void 0,pipes:[t,...e??[]]}:{key:t,pipes:e??[]}}a(X,"resolveArgs");function g(t,e,r=[]){return (o,s,i)=>{if(s===void 0)return;let a=o[s];if(typeof a!="function")return;let c=a[b]??[];a[b]=[...c,{index:i,type:t,key:e,pipes:r.length>0?r:void 0}];}}a(g,"buildBuiltinDecorator");function Yt(t){return typeof t=="function"?new t:t}a(Yt,"resolveParamPipe");function gt(t,...e){let{key:r,pipes:o}=X(t,e);return g("query",r,o)}a(gt,"Query");function wt(t,...e){let{key:r,pipes:o}=X(t,e);return g("param",r,o)}a(wt,"Param");function xt(t,...e){let{key:r,pipes:o}=X(t,e);return g("body",r,o)}a(xt,"Body");var Et=a(()=>g("rawBody"),"RawBody"),Rt=a(()=>g("formData"),"FormData"),bt=a(()=>g("ip"),"Ip"),Mt=a(()=>g("userAgent"),"UserAgent"),At=a(t=>g("cookie",t),"Cookie");function Pt(t,...e){let{key:r,pipes:o}=X(t,e);return g("headers",r,o)}a(Pt,"Headers");function be(t){return ()=>(e,r,o)=>{if(r===void 0)return;let s=e[r];if(typeof s!="function")return;let i=s[b]??[];s[b]=[...i,{index:o,type:"auth",extractor:t}];}}a(be,"defineAuth");var Ct=be();function vt(t,e){return ()=>(r,o,s)=>{if(o===void 0)return;let i=r[o];if(typeof i!="function")return;let a=i[b]??[];i[b]=[...a,{index:s,type:"custom",extractor:t,schema:e?.schema,source:e?.source}];}}a(vt,"createParamDecorator");function M(t,e){let r=t.prototype[e];if(typeof r!="function")return null;let o=r[b];return o&&o.length>0?o:null}a(M,"getRouteParams");async function Z(t,e){let r=Math.max(...t.map(s=>s.index)),o=new Array(r+1).fill(void 0);for(let{index:s,type:i,key:a,pipes:c,extractor:d}of t){let u;switch(i){case "query":{let f=e.getQuery();u=a!==void 0?f[a]:f;break}case "param":{let f=e.getParams();u=a!==void 0?f[a]:f;break}case "body":{let f=e.getBodyParseError();if(f)throw new y(`Malformed JSON body: ${f.message}`);let l=e.getBody()??{};u=a!==void 0?l[a]:l;break}case "rawBody":{u=e.getRawBody();break}case "formData":{u=e.getFormData();break}case "headers":{let f=D(e.getNativeRequest());u=a!==void 0?f[a.toLowerCase()]:f;break}case "cookie":{let l=D(e.getNativeRequest()).cookie??"";if(a&&l){let p=l.split(";").map(h=>h.trim()).find(h=>h.startsWith(a+"="));u=p?decodeURIComponent(p.slice(a.length+1)):void 0;}else u=void 0;break}case "ip":{u=Q(e);break}case "userAgent":{u=D(e.getNativeRequest())["user-agent"]??"";break}case "auth":{u=d?await d(e):e.getAuth();break}case "custom":{u=d?await d(e):void 0;break}}if(c&&c.length>0)for(let f of c)u=await Yt(f).transform(u);o[s]=u;}return o}a(Z,"resolveParamArgs");var ee=Symbol.for("truxie:api:doc");function Dt(t){return (e,r,o)=>o!==void 0?(typeof o.value=="function"&&Ae(o.value,t,"override"),o):(typeof e=="function"&&Ae(e,t,"override"),e)}a(Dt,"ApiDoc");function St(t,e){Ae(t,e,"fill");}a(St,"contributeApiDoc");function Ae(t,e,r){let o=t,s=Lt(o[ee])?o[ee]:{},i=Me(e),a=r==="override"?{...s,...i}:{...i,...s},c=r==="override"?{...s.extensions,...i.extensions}:{...i.extensions,...s.extensions};if(Object.keys(c).length>0&&(a.extensions=c),s.request||i.request){let d=Me(s.request??{}),u=Me(i.request??{});a.request=r==="override"?{...d,...u}:{...u,...d};}o[ee]=a;}a(Ae,"writeApiDoc");function Me(t){return Object.fromEntries(Object.entries(t).filter(([,e])=>e!==void 0))}a(Me,"defined");function Lt(t){return typeof t=="object"&&t!==null}a(Lt,"isRecord");function T(t,e){let r=t.prototype?.[e];if(typeof r!="function")return null;let o=r[ee];return Vt(o)?o:null}a(T,"getApiDoc");function It(t){return t?.returns?(Array.isArray(t.returns)?t.returns:[t.returns]).map(r=>({...r,status:r.status??200})):[]}a(It,"apiResponses");function Vt(t){return typeof t=="object"&&t!==null&&typeof t.summary=="string"}a(Vt,"isApiDoc");function Tt(t,e={}){let r=M(t.controllerClass,t.methodName)??[],o=T(t.controllerClass,t.methodName)?.request,s=e.toJsonSchema,i={},a=Pe(r,"param",s)??te(o?.params,s)??Xt(t.paramNames);a&&(i.params=a);let c=e.querySchema??Pe(r,"query",s)??te(o?.query,s)??_t(r,"query");if(c&&(i.query=c),t.method!=="GET"){let d=e.bodySchema??Pe(r,"body",s)??te(o?.body,s)??_t(r,"body")??Qt(r);d&&Object.assign(i,{body:d},Jt(o));}return i}a(Tt,"describeRouteInput");function Jt(t){let e={},r=t?.contentType===void 0?[]:[t.contentType].flat();return r.length>0&&(e.bodyContentTypes=r),t?.bodyRequired!==void 0&&(e.bodyRequired=t.bodyRequired),e}a(Jt,"bodyMedia");function Pe(t,e,r){if(r)for(let o of t){if(o.schema===void 0||(o.source??o.type)!==e)continue;let s=r(o.schema,{io:"input"});if(s)return s}}a(Pe,"schemaFor");function te(t,e){if(t!==void 0)return Ce(t)?t:e?.(t,{io:"input"})??void 0}a(te,"documentedSchema");function _t(t,e){let r=kt(t,e);if(r.length===0)return;let o={};for(let s of r)o[s]={};return {type:"object",properties:o}}a(_t,"keyedSchema");function Qt(t){return t.some(r=>r.type==="body"||r.source==="body")?{type:"object",description:"Shape not declared by the handler."}:void 0}a(Qt,"looseBody");function Xt(t){if(t.length===0)return;let e={};for(let r of t)e[r]={type:"string"};return {type:"object",properties:e,required:[...t]}}a(Xt,"pathParamsSchema");function Ce(t){if(typeof t!="object"||t===null)return false;let e=t;return typeof e._def=="object"||typeof e._zod=="object"?false:"type"in e||"properties"in e||"$ref"in e||"anyOf"in e||"allOf"in e||"oneOf"in e}a(Ce,"isJsonSchemaObject");function Ot(t,e={}){let r=M(t.controllerClass,t.methodName)??[],o=T(t.controllerClass,t.methodName)?.request;return {query:Nt(r,"query",o?.query,e.toJsonSchema),body:Nt(r,"body",o?.body,e.toJsonSchema)}}a(Ot,"routeInputDrift");function Nt(t,e,r,o){let s={undocumented:[],unread:[]};if(r===void 0||Zt(t,e))return s;let i=er(te(r,o));if(!i)return s;let a=new Set(kt(t,e)),c=new Set(i);return {undocumented:[...a].filter(d=>!c.has(d)),unread:i.filter(d=>!a.has(d))}}a(Nt,"partDrift");function kt(t,e){let r=t.filter(o=>o.type===e&&typeof o.key=="string").map(o=>o.key);return [...new Set(r)]}a(kt,"readKeys");function Zt(t,e){return t.some(r=>r.type===e&&r.key===void 0||r.type==="custom"&&r.source===e?true:e==="body"&&(r.type==="rawBody"||r.type==="formData"))}a(Zt,"readsWholeObject");function er(t){let r=tr(t)?.properties;return typeof r!="object"||r===null?null:Object.keys(r)}a(er,"propertyNames");function tr(t){let e=t?.$ref;if(typeof e!="string")return t;let r=/^#\/(\$defs|definitions)\/([^/]+)$/.exec(e);return r?t?.[r[1]]?.[rr(r[2])]??t:t}a(tr,"resolveRootRef");function rr(t){return t.replace(/~1/g,"/").replace(/~0/g,"~")}a(rr,"decodePointer");var Ft="__redirect";function qt(t,e=302){return {__redirect:true,url:t,statusCode:e}}a(qt,"redirect");function re(t){return t!==null&&typeof t=="object"&&t.__redirect===true}a(re,"isRedirect");function oe(){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(oe,"isServerless");var O=class{static{a(this,"TruxieApplication");}container;registry;initialized=false;rootModule;options;eventEmitter;prefix="";trustProxy;router;gateways=new Map;wsInitialized=false;constructor(e,r={}){this.rootModule=e,this.options=r,this.trustProxy=r.trustProxy??oe(),this.container=new b$2,this.registry=new p;}async init(){if(this.initialized)return;this.eventEmitter=new q,this.options.eventBus&&this.eventEmitter.setOptions(this.options.eventBus),this.container.register({provide:q,useValue:this.eventEmitter});let e=new p$1;this.container.register({provide:p$1,useValue:e}),this.registry.scan(this.rootModule),this.options.strictModuleBoundaries&&this.registry.validateVisibility([q,p$1]),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 R(this.prefix),this.router.register(...this.registry.getAllControllers()),this.initialized=true;}setGlobalPrefix(e){return this.prefix=e,this.initialized&&(this.router=new R(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}getRoutes(){return this.ensureInitialized(),this.router.getRoutes()}async handleRequest(e,r){this.ensureInitialized();let{container:o,dispose:s}=this.createRequestContext();try{let i=await o.resolve(e.controllerClass),a$1=i[e.methodName];if(typeof a$1!="function")throw new Error(`${e.controllerClass.name}.${e.methodName} is not a method on the resolved controller.`);let c=a$1.bind(i),d=M(e.controllerClass,e.methodName);r.setData("__controllerClass",e.controllerClass),r.setData("__methodName",e.methodName),r.setData(N,this.trustProxy),r.setHandler?.(a$1),r.setContainer?.(o);let f=await _(o,this.getGlobalOptions(),{middlewares:e.middlewareRefs,guards:e.guardClasses,interceptors:e.interceptorRefs,pipes:e.pipeRefs,filters:e.filterRefs,handler:a(async l=>d?c(...await Z(d,l)):c(l),"handler")})(r);if(re(f)){let l=f;return {value:f,isRedirect:!0,redirectUrl:l.url,redirectStatus:l.statusCode}}return {value:f,isRedirect:!1}}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(o){let i="/"+(e.getUrl(o).split("?")[0]??"/").replace(/^\/+|\/+$/g,""),a=r.matchGatewayPath(i);if(!a)return;let c=r.gateways.get(a),d=e.adaptPeer(o);for(let f of c.guards){let l=false;try{l=await f.canActivate(d);}catch(p){console.error(`[WS] ${c.className} guard error:`,p);}if(!l){d.close(1008,"Unauthorized");return}}let u=o.context;u&&(u._gatewayPath=a);for(let f of c.serverProps)c.instance[f]={peers:e.getPeers(o)??new Set};if(c.hasConnection)try{await c.instance.handleConnection(d);}catch(f){console.error(`[WS] ${c.className}.handleConnection error:`,f);}},async message(o,s){let a=o.context?._gatewayPath;if(!a)return;let c=r.gateways.get(a);if(!c)return;let d=e.adaptPeer(o),u=e.adaptMessage(s),f;try{f=u.json();}catch{return}if(!f.event||typeof f.event!="string")return;let l=c.messageHandlers.get(f.event);if(l)try{let p=n$1(l.paramMeta,d,u,f.data),h=await l.method(...p);h!=null&&d.send(h);}catch(p){console.error(`[WS] ${c.className}.${f.event} error:`,p);}},async close(o,s){let a=o.context?._gatewayPath;if(!a)return;let c=r.gateways.get(a);if(!c?.hasDisconnect)return;let d=e.adaptPeer(o);try{await c.instance.handleDisconnect(d,s);}catch(u){console.error(`[WS] ${c.className}.handleDisconnect error:`,u);}},async error(o,s){let i=o?.id??"unknown";console.error(`[WS] Peer ${String(i)} 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(),_(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;if(this.prefix){let r="/"+this.prefix.replace(/^\/+|\/+$/g,"");if(r!=="/"&&e.startsWith(r+"/")){let o=e.slice(r.length);if(this.gateways.has(o))return o}}}async initGateways(){if(!this.wsInitialized){for(let e of this.registry.getAllGateways()){let r=i(e);if(!r)continue;let o=await this.container.resolve(e),s=new Map;for(let a of j$1(e)){let c=o[a.methodName];typeof c=="function"&&s.set(a.event,{method:c.bind(o),paramMeta:k(e.prototype[a.methodName])});}let i$1=await E(this.container,l$1(e));if(this.gateways.set(r.path,{instance:o,className:e.name,messageHandlers:s,hasConnection:typeof o.handleConnection=="function",hasDisconnect:typeof o.handleDisconnect=="function",serverProps:m$1(e),guards:i$1}),typeof o.afterInit=="function")try{await o.afterInit();}catch{}}this.wsInitialized=true;}}getGlobalOptions(){return {middlewares:this.options.globalMiddlewares,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().")}},ne=class{static{a(this,"TruxieFactory");}static async create(e,r){let o=new O(e,r);return await o.init(),o}};export{Dt as ApiDoc,m as AppError,Ct as Auth,U as BaseExecutionContext,xt as Body,at as Catch,j as ConfigurableModuleBuilder,W as ConflictError,R as ControllerRouter,At as Cookie,ft as DefaultValuePipe,J as DomainEvent,C as ForbiddenError,Rt as FormData,Pt as Headers,bt as Ip,G as NotFoundError,wt as Param,L as ParseIdPipe,V as ParseIntPipe,gt as Query,Ft as REDIRECT_BRAND,Re as REMOTE_ADDRESS_KEY,Et as RawBody,v as RequestAbortedError,N as TRUST_PROXY_KEY,O as TruxieApplication,ne as TruxieFactory,he as UOW_INSTANCE_KEY,pe as UOW_SESSION_KEY,z as UnauthorizedError,K as UnitOfWorkInterceptor,it as UseFilters,ct as UseInterceptors,ut as UseMiddleware,dt as UsePipes,Mt as UserAgent,y as ValidationError,It as apiResponses,nt as applyJsonBody,Q as clientIp,lt as clientSafeError,St as contributeApiDoc,se as createAsyncOptionsProviders,vt as createParamDecorator,_ as createPipeline,be as defineAuth,Tt as describeRouteInput,T as getApiDoc,H as getEffectiveInterceptors,Y as getEffectiveMiddlewares,fe as getInterceptorsMetadata,le as getMethodInterceptors,we as getMethodMiddlewares,ge as getMiddlewaresMetadata,yt as getRequestHeaders,M as getRouteParams,Ce as isJsonSchemaObject,re as isRedirect,oe as isServerless,qt as redirect,Z as resolveParamArgs,Ot as routeInputDrift};
|
package/dist/testing.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {b,q,p as p$2,s,a as a$1}from'./chunk-
|
|
1
|
+
import {b,q,p as p$2,s,a as a$1}from'./chunk-CD6QSDG5.js';import'./chunk-RDP32XIU.js';import {p as p$1,d}from'./chunk-TSJZVSHP.js';import {a}from'./chunk-EI7MMDWY.js';var h=class{static{a(this,"TestBuilder");}metadata;overrides=new Map;constructor(e){this.metadata=e;}overrideProvider(e){return {useValue:a(s=>(this.overrides.set(e,{provide:e,useValue:s}),this),"useValue"),useClass:a(s=>(this.overrides.set(e,{provide:e,useClass:s}),this),"useClass"),useFactory:a((s,n)=>(this.overrides.set(e,{provide:e,useFactory:s,inject:n??[]}),this),"useFactory")}}async compile(){let e=new b,s$1=new q;e.register({provide:q,useValue:s$1});let n=new p$1;e.register({provide:p$1,useValue:n});let i=this.metadata,o=[];if(g(i)){let t=(i.providers??[]).map(a=>a&&typeof a=="object"&&"forwardRef"in a?d(a):a);if(e.register(...t),o=t,i.imports&&i.imports.length>0){let a$1=new p$2,w={module:class{static{a(this,"TempTestModule");}},imports:i.imports,providers:t,exports:i.exports??[]};a$1.scan(w),a$1.registerAll(e),o=a$1.getAllProviders();}}else {let t=new p$2;t.scan(i),t.registerAll(e),o=t.getAllProviders();}for(let[,t]of this.overrides)e.register(t);return n._init(e,o),await this.callHook(e,o,"onModuleInit"),await s(e,o),await this.callHook(e,o,"onApplicationBootstrap"),{resolve:a(t=>e.resolve(t),"resolve"),has:a(t=>e.has(t),"has"),getContainer:a(()=>e,"getContainer"),getEventEmitter:a(()=>s$1,"getEventEmitter"),shutdown:a(async()=>{await this.callHook(e,o,"onModuleDestroy"),await this.callHook(e,o,"onApplicationShutdown"),s$1.clear(),await e.dispose();},"shutdown")}}async callHook(e,s,n){for(let i of s){let o=typeof i=="function"?i:i.provide;if(e.has(o))try{let t=await e.resolve(o);if(t&&typeof t=="object"&&typeof t[n]=="function"){if(n==="onModuleDestroy"&&!a$1(t))continue;await t[n]();}}catch{}}}};function g(l){return !(typeof l=="function"||l&&typeof l=="object"&&"module"in l)}a(g,"isModuleMetadata");var p=class{static{a(this,"Test");}static createTestingModule(e){return new h(e)}};export{p as Test};
|
package/package.json
CHANGED
package/dist/chunk-6JQLGFPZ.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import {i as i$1}from'./chunk-RDP32XIU.js';import {d,h,a as a$1,i,j as j$1,k as k$1,b,n,o,e}from'./chunk-TSJZVSHP.js';import {a}from'./chunk-EI7MMDWY.js';import'reflect-metadata';var $=new WeakSet;function R(i){return $.has(i)?false:($.add(i),true)}a(R,"claimDestroy");var F=class extends Error{static{a(this,"MissingProviderError");}},_=class i$1{static{a(this,"Container");}registrations=new Map;parent=null;children=[];register(...e){for(let t of e)this.registerOne(t);}registerOne(e){let t=e&&typeof e=="object"&&"forwardRef"in e?d(e):e;if(typeof t=="function"){let a=h(t)?.scope??a$1.SINGLETON;this.registrations.set(t,{provider:t,scope:a,resolved:false});return}let r=t.provide,o=a$1.SINGLETON,n=t;if("useClass"in t){let s=t.useClass,a=s&&typeof s=="object"&&"forwardRef"in s?d(s):s,f=h(a);o=t.scope??f?.scope??a$1.SINGLETON,n={...t,useClass:a};}else if("useExisting"in t){let s=t.useExisting,a=s&&typeof s=="object"&&"forwardRef"in s?d(s):s;n={...t,useExisting:a};}else "useFactory"in t&&(o=t.scope??a$1.SINGLETON);this.registrations.set(r,{provider:n,scope:o,resolved:false});}async resolve(e){return this.resolveInternal(e,Y)}async resolveInternal(e,t){let r=d(e),o=r!==e?r:e,n=this.findOwner(o);if(!n)throw new F(`No provider found for ${T(o)}`);let s=n.registrations.get(o),a=s.scope===a$1.SINGLETON?n:this,f=s.scope===a$1.SINGLETON||s.scope===a$1.REQUEST&&a.parent!==null;if(f&&s.resolved)return s.instance;if(t.has(o))throw new Error(`Circular dependency detected for ${T(o)}`);if(f&&s.inFlight)return s.inFlight;let m=new Set(t).add(o),d$1=a.createInstance(s,m).then(h=>(f&&(s.instance=h,s.resolved=true),s.inFlight=void 0,h),h=>{throw s.inFlight=void 0,h});return f&&(s.inFlight=d$1),d$1}has(e){return this.registrations.has(e)||(this.parent?.has(e)??false)}hasRequestScoped(){for(let[,e]of this.registrations)if(e.scope===a$1.REQUEST)return true;return this.parent?.hasRequestScoped()??false}findOwner(e){return this.registrations.has(e)?this:this.parent?.findOwner(e)??null}createChild(){let e=new i$1;e.parent=this;for(let[t,r]of this.registrations)r.scope===a$1.REQUEST&&e.registrations.set(t,{provider:r.provider,scope:a$1.REQUEST,instance:void 0,resolved:false});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.resolved)continue;let t=e.instance;if(!t||typeof t!="object")continue;let r=t;typeof r.onModuleDestroy=="function"&&R(t)&&await r.onModuleDestroy();}if(this.registrations.clear(),this.parent){let e=this.parent.children.indexOf(this);e!==-1&&this.parent.children.splice(e,1),this.parent=null;}}async createInstance(e,t){let{provider:r}=e;if(typeof r=="function")return this.instantiateClass(r,t);if("useValue"in r)return r.useValue;if("useClass"in r)return this.instantiateClass(r.useClass,t);if("useFactory"in r){let o=r,n=[];if(o.inject)for(let s of o.inject)n.push(await this.resolveInternal(s,t));return o.useFactory(...n)}if("useExisting"in r)return this.resolveInternal(r.useExisting,t);throw new Error("Unknown provider type")}async instantiateClass(e,t){let r=Reflect.getMetadata("design:paramtypes",e)??[],o=i(e),n=j$1(e),s=k$1(e),a=n.size>0?Math.max(...n.keys())+1:0,f=Math.max(r.length,a,o.length),m=[];for(let d=0;d<f;d++){let h=n.get(d)??o[d]??r[d];try{m.push(await this.resolveInternal(h,t));}catch(g){if(g instanceof F&&s.has(d)){m.push(void 0);continue}let M=g instanceof Error?g.message:String(g);throw new Error(`Cannot resolve parameter at index ${d} (${T(h)}) of ${e.name}: ${M}`,{cause:g})}}return new e(...m)}},Y=new Set;function T(i){return typeof i=="string"?i:typeof i=="symbol"||i instanceof b?i.toString():typeof i=="function"?i.name:String(i)}a(T,"tokenToString");function L(i,e){let t=[];for(let n=e;typeof n=="function"&&n!==Function.prototype;n=Object.getPrototypeOf(n)){let s=Reflect.getOwnMetadata(i,n);s!==void 0&&s.length>0&&t.push(s);}let r=new Set,o=[];for(let n of t.reverse())for(let s of n)r.has(s)||(r.add(s),o.push(s));return o}a(L,"inheritedClassMetadata");var U=Symbol.for("truxie:controller:path"),v=Symbol.for("truxie:controller:guards"),O=Symbol.for("truxie:route:metadata"),k=Symbol.for("truxie:method:route"),E=Symbol.for("truxie:method:guards"),P=Symbol.for("truxie:method:noguard");function me(i){return e=>{Reflect.defineMetadata(U,i,e);}}a(me,"Controller");function x(i){return (e="")=>(t,r,o)=>{let n=o!==void 0,s=String(n?r:r?.name??r),a=n?o?.value:t;if(typeof a=="function"&&(a[k]={method:i,path:e,methodName:s}),n){let f=Reflect.getOwnMetadata(O,t.constructor)??[];return f.push({method:i,path:e,methodName:s}),Reflect.defineMetadata(O,f,t.constructor),o}return t}}a(x,"createMethodDecorator");var ge=x("GET"),ve=x("POST"),ye=x("PUT"),we=x("DELETE"),Ee=x("PATCH");function xe(...i){return (e,t,r)=>{if(t==null){let o=Reflect.getOwnMetadata(v,e)??[];Reflect.defineMetadata(v,[...o,...i],e);return}if(r!==void 0){if(r?.value){let o=r.value[E]??[];r.value[E]=[...o,...i];}return r}if(typeof e=="function"){let o=e[E]??[];e[E]=[...o,...i];}if(typeof e=="function"&&t?.kind==="class"){let o=Reflect.getOwnMetadata(v,e)??[];Reflect.defineMetadata(v,[...o,...i],e);}return e}}a(xe,"RouteGuards");function Me(){return (i,e,t)=>t!==void 0?(t?.value&&(t.value[P]=true),t):(typeof i=="function"&&(i[P]=true),i)}a(Me,"NoGuard");function V(i){return Reflect.getOwnMetadata(U,i)}a(V,"getControllerPath");function be(i){return Reflect.getOwnMetadata(v,i)??[]}a(be,"getControllerGuards");function Q(i){let e=new Map,t=i.prototype;for(;t&&t!==Object.prototype;){for(let r of Object.getOwnPropertyNames(t)){if(r==="constructor"||e.has(r))continue;let o=Object.getOwnPropertyDescriptor(t,r);!o||typeof o.value!="function"||e.set(r,o.value);}t=Object.getPrototypeOf(t);}return e}a(Q,"methodsOf");function B(i,e){return Q(i).get(e)}a(B,"methodOf");function Re(i){let e=[],t=new Set;for(let[r,o]of Q(i)){let n=o[k];!n||t.has(r)||(t.add(r),e.push(n));}if(e.length>0)return e;for(let r=i;r&&r!==Function.prototype;r=Object.getPrototypeOf(r)){let o=Reflect.getOwnMetadata(O,r)??[];for(let n of o)t.has(n.methodName)||(t.add(n.methodName),e.push(n));}return e}a(Re,"getRouteMetadata");function Se(i,e){let t=B(i,e),r=t!==void 0&&t[P]===true,o=t!==void 0&&t[E]||[];return r?o:[...J(i),...o]}a(Se,"getMethodGuards");function J(i){return L(v,i)}a(J,"controllerGuardsOf");var z=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 o of r.providers)t.add(o);t.size>0&&e.register(...t);for(let r of this.sortedModules){e.register(...r.providers);for(let o of r.metadata.imports??[]){let n=this.getModuleType(o),s=this.resolved.get(n);if(s)for(let a of s.exports){let f=this.findProvider(s,a)??this.findReExportedProvider(s,a);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 o of r.controllers)e.has(o)||(e.add(o),t.push(o));for(let o of r.metadata.providers??[])typeof o=="function"&&V(o)!==void 0&&!e.has(o)&&(e.add(o),t.push(o));}return t}getAllGateways(){let e=new Set,t=[];for(let r of this.sortedModules)for(let o of r.providers)typeof o=="function"&&i$1(o)!==void 0&&!e.has(o)&&(e.add(o),t.push(o));return t}async callLifecycleHooks(e,t,r){for(let o of this.sortedModules)for(let n of o.providers){let s=typeof n=="function"?n:n.provide;if(e.has(s))try{let a=await e.resolve(s);if(a&&typeof a=="object"&&typeof a[t]=="function"){if(t==="onModuleDestroy"&&!R(a))continue;await a[t](r);}}catch{}}}resolveModule(e){let t=d(e),r=typeof t=="object"&&"module"in t,o$1=r?t.module:t,n$1=this.resolved.get(o$1);if(n$1)return r&&this.mergeDynamicModule(n$1,e),n$1;let s=n(o$1)??{},a=r?e:{},f=[...s.controllers??[],...a.controllers??[]],m=[...s.providers??[],...a.providers??[]],d$1=[...s.exports??[],...a.exports??[]],h=m.map(l=>l&&typeof l=="object"&&"forwardRef"in l?d(l):l),g=d$1.map(l=>l&&typeof l=="object"&&"forwardRef"in l?d(l):l),M={imports:[...s.imports??[],...a.imports??[]],controllers:f,providers:h,exports:g},N={type:o$1,metadata:M,controllers:f,providers:[...f,...h],exports:new Set(g),global:r?e.global??o(o$1):o(o$1)};this.resolved.set(o$1,N);for(let l of M.imports??[])this.resolveModule(l);return N}mergeDynamicModule(e,t){if(t.controllers&&t.controllers.length>0&&(e.controllers.push(...t.controllers),e.providers.push(...t.controllers),e.metadata.controllers=[...e.metadata.controllers??[],...t.controllers]),t.providers&&t.providers.length>0){let r=t.providers.map(o=>o&&typeof o=="object"&&"forwardRef"in o?d(o):o);e.providers.push(...r),e.metadata.providers=[...e.metadata.providers??[],...r];}if(t.exports&&t.exports.length>0){let r=t.exports.map(o=>o&&typeof o=="object"&&"forwardRef"in o?d(o):o);for(let o of r)e.exports.add(o);e.metadata.exports=[...e.metadata.exports??[],...r];}if(t.imports&&t.imports.length>0){e.metadata.imports=[...e.metadata.imports??[],...t.imports];for(let r of t.imports)this.resolveModule(r);}t.global===true&&(e.global=true);}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 o=this.getModuleType(r),n=this.resolved.get(o);if(n)for(let s of n.exports)t.add(s);}for(let r of this.sortedModules)if(r.global)for(let o of r.providers)t.add(this.getProviderToken(o));return t}validateExports(){for(let e of this.sortedModules){let t=new Set(e.providers.map(o=>this.getProviderToken(o))),r=this.collectImportedExports(e);for(let o of e.exports)if(!t.has(o)&&!r.has(o)){let n=typeof o=="function"?o.name:String(o);throw new Error(`${e.type.name} exports ${n} 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 o=i(r);for(let n of o)if(!t.has(n)){let s=typeof n=="function"?n.name:String(n);throw new Error(`${e.type.name}: ${r.name} depends on ${s}, 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 o=this.getModuleType(r),n=this.resolved.get(o);if(n)for(let s of n.exports)t.add(s);}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 o=this.getModuleType(r),n=this.resolved.get(o);if(!n||!n.exports.has(t))continue;let s=this.findProvider(n,t);if(s)return s;let a=this.findReExportedProvider(n,t);if(a)return a}}getModuleType(e){let t=d(e);return typeof t=="object"&&"module"in t?t.module:t}topologicalSort(){let e=new Set,t=new Set,r=[],o=a(n=>{if(e.has(n))return;if(t.has(n))throw new Error(`Circular module dependency detected: ${n.name}`);t.add(n);let s=this.resolved.get(n);if(s){for(let a of s.metadata.imports??[])o(this.getModuleType(a));t.delete(n),e.add(n),r.push(s);}},"visit");for(let[n]of this.resolved)o(n);return r}};function X(i,e,t,r){var o=arguments.length,n=o<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(i,e,t,r);else for(var a=i.length-1;a>=0;a--)(s=i[a])&&(n=(o<3?s(n):o>3?s(e,t,n):s(e,t))||n);return o>3&&n&&Object.defineProperty(e,t,n),n}a(X,"_ts_decorate");function q(i,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(i,e)}a(q,"_ts_metadata");var y=class{static{a(this,"EventEmitter2");}handlers=new Map;pending=new Map;onError;constructor(){this.onError=Z;}setOptions(e){e.onError&&(this.onError=e.onError);}subscribe(e,t,r){let o=this.handlers.get(e)??[];o.push({instance:r?.instance??{},methodName:r?.methodName??"anonymous",handler:t}),this.handlers.set(e,o);}registerHandler(e,t,r){let o=t[r].bind(t);this.subscribe(e,o,{instance:t,methodName:r});}async emit(e){let t=this.handlers.get(e.type);if(!t||t.length===0)return;let r=this.executeHandlers(t,e);this.pending.set(r,e.type);try{await r;}finally{this.pending.delete(r);}}emitAsync(e){let t=this.handlers.get(e.type);if(!t||t.length===0)return Promise.resolve([]);let r=this.executeHandlers(t,e).then(o=>(this.pending.delete(r),o),()=>(this.pending.delete(r),[]));return this.pending.set(r,e.type),r}async waitForAllDone(...e){for(;;){let t=this.getPending(e);if(t.length===0)break;await Promise.allSettled(t);}}getPending(e){if(e.length===0)return [...this.pending.keys()];let t=[];for(let[r,o]of this.pending)e.includes(o)&&t.push(r);return t}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();}async executeHandlers(e,t){return (await Promise.allSettled(e.map(async o=>{let n=Date.now();try{return {value:await o.handler(t),durationMs:Date.now()-n}}catch(s){return {err:s,durationMs:Date.now()-n,threw:true}}}))).map((o,n)=>{let s=e[n],a=`${s.instance.constructor?.name??"Unknown"}.${s.methodName}`;if(o.status==="fulfilled"&&!("threw"in o.value))return {name:a,status:"success",value:o.value.value,durationMs:o.value.durationMs};let f=o.status==="fulfilled"?o.value.err:o.reason,m=f instanceof Error?f.message:typeof f=="string"?f:String(f),d=o.status==="fulfilled"?o.value.durationMs:0;return this.onError(f,t.type,a),{name:a,status:"failed",error:m,durationMs:d}})}};y=X([e(),q("design:type",Function),q("design:paramtypes",[])],y);function Z(i,e,t){console.error(`[EventEmitter2] Handler "${t}" failed for event "${e}":`,i);}a(Z,"defaultErrorHandler");var j=Symbol.for("truxie:on-event");function Le(i){return (e,t,r)=>{let o=Reflect.getOwnMetadata(j,e.constructor)??[];o.push({eventType:i,methodName:String(t)}),Reflect.defineMetadata(j,o,e.constructor);}}a(Le,"OnEvent");function W(i){return Reflect.getOwnMetadata(j,i)??[]}a(W,"getOnEventMetadata");async function qe(i,e){let t=await i.resolve(y);for(let r of e){let o=K(r);if(!o)continue;let n=W(o);if(n.length===0)continue;let s=typeof r=="function"?r:r.provide,a;try{a=await i.resolve(s);}catch{continue}for(let f of n)typeof a[f.methodName]=="function"&&t.registerHandler(f.eventType,a,f.methodName);}}a(qe,"scanEventHandlers");function K(i){return typeof i=="function"?h(i)?i:null:"useClass"in i?i.useClass:null}a(K,"getProviderClass");export{R as a,_ as b,L as c,me as d,ge as e,ve as f,ye as g,we as h,Ee as i,xe as j,Me as k,V as l,be as m,Re as n,Se as o,z as p,y as q,Le as r,qe as s};
|