truxie 0.1.0-test.16 → 0.1.0-test.18
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {i as i$1}from'./chunk-RLQ7JJW6.js';import {d,h,a as a$1,i,j,k as k$1,b,n,o,e}from'./chunk-ASOZYX5T.js';import {a}from'./chunk-EI7MMDWY.js';import'reflect-metadata';var $=class i$1{static{a(this,"Container");}registrations=new Map;resolving=new Set;parent=null;children=[];register(...t){for(let e of t)this.registerOne(e);}registerOne(t){let e=t&&typeof t=="object"&&"forwardRef"in t?d(t):t;if(typeof e=="function"){let a=h(e)?.scope??a$1.SINGLETON;this.registrations.set(e,{provider:e,scope:a});return}let r=e.provide,o=a$1.SINGLETON,n=e;if("useClass"in e){let s=e.useClass,a=s&&typeof s=="object"&&"forwardRef"in s?d(s):s,c=h(a);o=e.scope??c?.scope??a$1.SINGLETON,n={...e,useClass:a};}else if("useExisting"in e){let s=e.useExisting,a=s&&typeof s=="object"&&"forwardRef"in s?d(s):s;n={...e,useExisting:a};}else "useFactory"in e&&(o=e.scope??a$1.SINGLETON);this.registrations.set(r,{provider:n,scope:o});}async resolve(t){let e=d(t),r=e!==t?e:t,o=this.registrations.get(r)??this.parent?.findRegistration(r);if(!o)throw new Error(`No provider found for ${x(r)}`);if(o.scope===a$1.SINGLETON&&o.instance!==void 0||o.scope===a$1.REQUEST&&this.parent!==null&&o.instance!==void 0)return o.instance;if(this.resolving.has(r))throw new Error(`Circular dependency detected for ${x(r)}`);this.resolving.add(r);try{let n=await this.createInstance(o);return (o.scope===a$1.SINGLETON||o.scope===a$1.REQUEST&&this.parent!==null)&&(o.instance=n),n}finally{this.resolving.delete(r);}}has(t){return this.registrations.has(t)||(this.parent?.has(t)??false)}hasRequestScoped(){for(let[,t]of this.registrations)if(t.scope===a$1.REQUEST)return true;return false}findRegistration(t){return this.registrations.get(t)??this.parent?.findRegistration(t)}createChild(){let t=new i$1;t.parent=this;for(let[e,r]of this.registrations)r.scope===a$1.REQUEST&&t.registrations.set(e,{provider:r.provider,scope:a$1.REQUEST,instance:void 0});return this.children.push(t),t}async dispose(){for(let t of this.children)await t.dispose();this.children=[];for(let[,t]of this.registrations)if(t.instance&&typeof t.instance=="object"&&t.instance!==null){let e=t.instance;typeof e.onModuleDestroy=="function"&&await e.onModuleDestroy();}this.registrations.clear(),this.resolving.clear();}async createInstance(t){let{provider:e}=t;if(typeof e=="function")return this.instantiateClass(e);if("useValue"in e)return e.useValue;if("useClass"in e)return this.instantiateClass(e.useClass);if("useFactory"in e){let r=e,o=[];if(r.inject)for(let n of r.inject)o.push(await this.resolve(n));return r.useFactory(...o)}if("useExisting"in e)return this.resolve(e.useExisting);throw new Error("Unknown provider type")}async instantiateClass(t){let e=Reflect.getMetadata("design:paramtypes",t)??[],r=i(t),o=j(t),n=k$1(t),s=o.size>0?Math.max(...o.keys())+1:0,a=Math.max(e.length,s,r.length),c=[];for(let p=0;p<a;p++){let h=o.get(p)??r[p]??e[p],w=n.has(p);try{c.push(await this.resolve(h));}catch{if(w)c.push(void 0);else throw new Error(`Cannot resolve parameter at index ${p} (${x(h)}) of ${t.name}`)}}return new t(...c)}};function x(i){return typeof i=="string"?i:typeof i=="symbol"||i instanceof b?i.toString():typeof i=="function"?i.name:String(i)}a(x,"tokenToString");var L=Symbol("controller:path"),M=Symbol("controller:guards"),R=Symbol("route:metadata"),T=Symbol("method:route"),v=Symbol("method:guards"),S=Symbol("method:noguard");function tt(i){return t=>{Reflect.defineMetadata(L,i,t);}}a(tt,"Controller");function y(i){return (t="")=>(e,r,o)=>{let n=o!==void 0,s=String(n?r:r?.name??r),a=n?o?.value:e;if(typeof a=="function"&&(a[T]={method:i,path:t,methodName:s}),n){let c=Reflect.getOwnMetadata(R,e.constructor)??[];return c.push({method:i,path:t,methodName:s}),Reflect.defineMetadata(R,c,e.constructor),o}return e}}a(y,"createMethodDecorator");var et=y("GET"),ot=y("POST"),rt=y("PUT"),nt=y("DELETE"),st=y("PATCH");function it(...i){return (t,e,r)=>{if(e==null){Reflect.defineMetadata(M,i,t);return}if(r!==void 0){if(r?.value){let o=r.value[v]??[];r.value[v]=[...o,...i];}return r}if(typeof t=="function"){let o=t[v]??[];t[v]=[...o,...i];}return typeof t=="function"&&e?.kind==="class"&&Reflect.defineMetadata(M,i,t),t}}a(it,"RouteGuards");function at(){return (i,t,e)=>e!==void 0?(e?.value&&(e.value[S]=true),e):(typeof i=="function"&&(i[S]=true),i)}a(at,"NoGuard");function U(i){return Reflect.getOwnMetadata(L,i)}a(U,"getControllerPath");function V(i){return Reflect.getOwnMetadata(M,i)??[]}a(V,"getControllerGuards");function ct(i){let t=[],e=i.prototype;if(e){let r=Object.getOwnPropertyNames(e);for(let o of r){if(o==="constructor")continue;let n=Object.getOwnPropertyDescriptor(e,o);if(!n||typeof n.value!="function")continue;let s=n.value;s[T]&&t.push(s[T]);}}return t.length>0?t:Reflect.getOwnMetadata(R,i)??[]}a(ct,"getRouteMetadata");function ft(i,t){let r=i.prototype?.[t],o=typeof r=="function"&&r[S]===true,n=typeof r=="function"&&r[v]||[];return o?n:[...V(i),...n]}a(ft,"getMethodGuards");var _=class{static{a(this,"ModuleRegistry");}resolved=new Map;sortedModules=[];scan(t){this.resolveModule(t),this.sortedModules=this.topologicalSort(),this.validateExports();}registerAll(t){let e=new Set;for(let r of this.sortedModules)if(r.global)for(let o of r.providers)e.add(o);e.size>0&&t.register(...e);for(let r of this.sortedModules){t.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 c=this.findProvider(s,a)??this.findReExportedProvider(s,a);c&&t.register(c);}}}}getAllProviders(){let t=[];for(let e of this.sortedModules)t.push(...e.providers);return t}getAllControllers(){let t=new Set,e=[];for(let r of this.sortedModules){for(let o of r.controllers)t.has(o)||(t.add(o),e.push(o));for(let o of r.metadata.providers??[])typeof o=="function"&&U(o)!==void 0&&!t.has(o)&&(t.add(o),e.push(o));}return e}getAllGateways(){let t=new Set,e=[];for(let r of this.sortedModules)for(let o of r.providers)typeof o=="function"&&i$1(o)!==void 0&&!t.has(o)&&(t.add(o),e.push(o));return e}async callLifecycleHooks(t,e,r){for(let o of this.sortedModules)for(let n of o.providers){let s=typeof n=="function"?n:n.provide;if(t.has(s))try{let a=await t.resolve(s);a&&typeof a=="object"&&typeof a[e]=="function"&&await a[e](r);}catch{}}}resolveModule(t){let e=d(t),r=typeof e=="object"&&"module"in e,o$1=r?e.module:e,n$1=this.resolved.get(o$1);if(n$1)return r&&this.mergeDynamicModule(n$1,t),n$1;let s=n(o$1)??{},a=r?t:{},c=[...s.controllers??[],...a.controllers??[]],p=[...s.providers??[],...a.providers??[]],h=[...s.exports??[],...a.exports??[]],w=p.map(d$1=>d$1&&typeof d$1=="object"&&"forwardRef"in d$1?d(d$1):d$1),O=h.map(d$1=>d$1&&typeof d$1=="object"&&"forwardRef"in d$1?d(d$1):d$1),N={imports:[...s.imports??[],...a.imports??[]],controllers:c,providers:w,exports:O},j={type:o$1,metadata:N,controllers:c,providers:[...c,...w],exports:new Set(O),global:r?t.global??o(o$1):o(o$1)};this.resolved.set(o$1,j);for(let d of N.imports??[])this.resolveModule(d);return j}mergeDynamicModule(t,e){if(e.controllers&&e.controllers.length>0&&(t.controllers.push(...e.controllers),t.providers.push(...e.controllers),t.metadata.controllers=[...t.metadata.controllers??[],...e.controllers]),e.providers&&e.providers.length>0){let r=e.providers.map(o=>o&&typeof o=="object"&&"forwardRef"in o?d(o):o);t.providers.push(...r),t.metadata.providers=[...t.metadata.providers??[],...r];}if(e.exports&&e.exports.length>0){let r=e.exports.map(o=>o&&typeof o=="object"&&"forwardRef"in o?d(o):o);for(let o of r)t.exports.add(o);t.metadata.exports=[...t.metadata.exports??[],...r];}if(e.imports&&e.imports.length>0){t.metadata.imports=[...t.metadata.imports??[],...e.imports];for(let r of e.imports)this.resolveModule(r);}e.global===true&&(t.global=true);}getVisibleTokens(t){let e=new Set;for(let r of t.providers)e.add(this.getProviderToken(r));for(let r of t.metadata.imports??[]){let o=this.getModuleType(r),n=this.resolved.get(o);if(n)for(let s of n.exports)e.add(s);}for(let r of this.sortedModules)if(r.global)for(let o of r.providers)e.add(this.getProviderToken(o));return e}validateExports(){for(let t of this.sortedModules){let e=new Set(t.providers.map(o=>this.getProviderToken(o))),r=this.collectImportedExports(t);for(let o of t.exports)if(!e.has(o)&&!r.has(o)){let n=typeof o=="function"?o.name:String(o);throw new Error(`${t.type.name} exports ${n} but it is not in its providers and is not re-exported from an imported module`)}}}validateVisibility(){for(let t of this.sortedModules){let e=this.getVisibleTokens(t);for(let r of t.providers){if(typeof r!="function")continue;let o=i(r);for(let n of o)if(!e.has(n)){let s=typeof n=="function"?n.name:String(n);throw new Error(`${t.type.name}: ${r.name} depends on ${s}, but it is not provided in this module and not exported by any imported module`)}}}}getProviderToken(t){return typeof t=="function"?t:t.provide}collectImportedExports(t){let e=new Set;for(let r of t.metadata.imports??[]){let o=this.getModuleType(r),n=this.resolved.get(o);if(n)for(let s of n.exports)e.add(s);}return e}findProvider(t,e){return t.providers.find(r=>typeof r=="function"?r===e:r.provide===e)}findReExportedProvider(t,e){for(let r of t.metadata.imports??[]){let o=this.getModuleType(r),n=this.resolved.get(o);if(!n||!n.exports.has(e))continue;let s=this.findProvider(n,e);if(s)return s;let a=this.findReExportedProvider(n,e);if(a)return a}}getModuleType(t){let e=d(t);return typeof e=="object"&&"module"in e?e.module:e}topologicalSort(){let t=new Set,e=new Set,r=[],o=a(n=>{if(t.has(n))return;if(e.has(n))throw new Error(`Circular module dependency detected: ${n.name}`);e.add(n);let s=this.resolved.get(n);if(s){for(let a of s.metadata.imports??[])o(this.getModuleType(a));e.delete(n),t.add(n),r.push(s);}},"visit");for(let[n]of this.resolved)o(n);return r}};function Q(i,t,e,r){var o=arguments.length,n=o<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,e):r,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(i,t,e,r);else for(var a=i.length-1;a>=0;a--)(s=i[a])&&(n=(o<3?s(n):o>3?s(t,e,n):s(t,e))||n);return o>3&&n&&Object.defineProperty(t,e,n),n}a(Q,"_ts_decorate");function k(i,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(i,t)}a(k,"_ts_metadata");var m=class{static{a(this,"EventEmitter2");}handlers=new Map;pending=new Map;onError;constructor(){this.onError=z;}setOptions(t){t.onError&&(this.onError=t.onError);}subscribe(t,e,r){let o=this.handlers.get(t)??[];o.push({instance:r?.instance??{},methodName:r?.methodName??"anonymous",handler:e}),this.handlers.set(t,o);}registerHandler(t,e,r){let o=e[r].bind(e);this.subscribe(t,o,{instance:e,methodName:r});}async emit(t){let e=this.handlers.get(t.type);if(!e||e.length===0)return;let r=this.executeHandlers(e,t);this.pending.set(r,t.type);try{await r;}finally{this.pending.delete(r);}}emitAsync(t){let e=this.handlers.get(t.type);if(!e||e.length===0)return Promise.resolve([]);let r=this.executeHandlers(e,t).then(o=>(this.pending.delete(r),o),()=>(this.pending.delete(r),[]));return this.pending.set(r,t.type),r}async waitForAllDone(...t){for(;;){let e=this.getPending(t);if(e.length===0)break;await Promise.allSettled(e);}}getPending(t){if(t.length===0)return [...this.pending.keys()];let e=[];for(let[r,o]of this.pending)t.includes(o)&&e.push(r);return e}hasHandlers(t){let e=this.handlers.get(t);return e!==void 0&&e.length>0}handlerCount(t){return this.handlers.get(t)?.length??0}clear(){this.handlers.clear();}async executeHandlers(t,e){return (await Promise.allSettled(t.map(async o=>{let n=Date.now();try{return {value:await o.handler(e),durationMs:Date.now()-n}}catch(s){return {err:s,durationMs:Date.now()-n,threw:true}}}))).map((o,n)=>{let s=t[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 c=o.status==="fulfilled"?o.value.err:o.reason,p=c instanceof Error?c.message:typeof c=="string"?c:String(c),h=o.status==="fulfilled"?o.value.durationMs:0;return this.onError(c,e.type,a),{name:a,status:"failed",error:p,durationMs:h}})}};m=Q([e(),k("design:type",Function),k("design:paramtypes",[])],m);function z(i,t,e){console.error(`[EventEmitter2] Handler "${e}" failed for event "${t}":`,i);}a(z,"defaultErrorHandler");var P=Symbol("on-event");function Mt(i){return (t,e,r)=>{let o=Reflect.getOwnMetadata(P,t.constructor)??[];o.push({eventType:i,methodName:String(e)}),Reflect.defineMetadata(P,o,t.constructor);}}a(Mt,"OnEvent");function F(i){return Reflect.getOwnMetadata(P,i)??[]}a(F,"getOnEventMetadata");async function Nt(i,t){let e=await i.resolve(m);for(let r of t){let o=q(r);if(!o)continue;let n=F(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 c of n)typeof a[c.methodName]=="function"&&e.registerHandler(c.eventType,a,c.methodName);}}a(Nt,"scanEventHandlers");function q(i){return typeof i=="function"?h(i)?i:null:"useClass"in i?i.useClass:null}a(q,"getProviderClass");export{$ as a,tt as b,et as c,ot as d,rt as e,nt as f,st as g,it as h,at as i,U as j,V as k,ct as l,ft as m,_ as n,m as o,Mt as p,Nt as q};
|
|
@@ -26,12 +26,31 @@ declare abstract class DomainEvent<TPayload = unknown> {
|
|
|
26
26
|
constructor(payload: TPayload);
|
|
27
27
|
}
|
|
28
28
|
interface EventHandler {
|
|
29
|
-
(event: DomainEvent):
|
|
29
|
+
(event: DomainEvent): unknown | Promise<unknown>;
|
|
30
30
|
}
|
|
31
31
|
interface EventBusOptions {
|
|
32
32
|
/** Called when an event handler throws. Defaults to console.error. */
|
|
33
33
|
onError?: (error: unknown, eventType: string, handlerName: string) => void;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Per-handler outcome returned by `emitAsync()` — mirrors NestJS / eventemitter2
|
|
37
|
+
* convention where `emitAsync` resolves to the array of handler return values.
|
|
38
|
+
*
|
|
39
|
+
* Each row identifies the handler (`{ClassName}.{methodName}`) and reports
|
|
40
|
+
* either the resolved value or the error message for grep-by-listener log
|
|
41
|
+
* search downstream.
|
|
42
|
+
*/
|
|
43
|
+
interface HandlerOutcome {
|
|
44
|
+
/** `${ClassName}.${methodName}` — same shape used by `onError`. */
|
|
45
|
+
name: string;
|
|
46
|
+
status: 'success' | 'failed';
|
|
47
|
+
/** Handler return value (when fulfilled). */
|
|
48
|
+
value?: unknown;
|
|
49
|
+
/** Error message when rejected. */
|
|
50
|
+
error?: string;
|
|
51
|
+
/** Wall-clock duration of the handler in milliseconds. */
|
|
52
|
+
durationMs: number;
|
|
53
|
+
}
|
|
35
54
|
|
|
36
55
|
/**
|
|
37
56
|
* In-process async EventEmitter2.
|
|
@@ -70,20 +89,28 @@ declare class EventEmitter2 {
|
|
|
70
89
|
*/
|
|
71
90
|
registerHandler(eventType: string, instance: object, methodName: string): void;
|
|
72
91
|
/**
|
|
73
|
-
* Emit a domain event.
|
|
92
|
+
* Emit a domain event and await all handlers.
|
|
93
|
+
*
|
|
94
|
+
* All subscribed handlers execute concurrently. Errors are caught per-handler
|
|
95
|
+
* and reported via the `onError` callback. The emit call itself never throws.
|
|
74
96
|
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* The emit call itself never throws.
|
|
97
|
+
* Returns `void` — when you need the handler return values, use
|
|
98
|
+
* {@link emitAsync} instead (mirrors NestJS / eventemitter2 convention).
|
|
78
99
|
*/
|
|
79
100
|
emit(event: DomainEvent): Promise<void>;
|
|
80
101
|
/**
|
|
81
|
-
* Emit
|
|
102
|
+
* Emit a domain event and resolve to an array of per-handler outcomes —
|
|
103
|
+
* matches the NestJS / eventemitter2 `emitAsync` convention.
|
|
104
|
+
*
|
|
105
|
+
* If the caller does not `await` the returned promise the call is still
|
|
106
|
+
* fire-and-forget: handlers run, the tracked promise is kept in the internal
|
|
107
|
+
* `pending` set, and `waitForAllDone()` can still synchronize on it.
|
|
82
108
|
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
109
|
+
* Errors thrown by individual handlers are surfaced on the result row
|
|
110
|
+
* (`status: 'failed'`) and additionally reported via the `onError` callback —
|
|
111
|
+
* the returned promise itself never rejects.
|
|
85
112
|
*/
|
|
86
|
-
emitAsync(event: DomainEvent):
|
|
113
|
+
emitAsync(event: DomainEvent): Promise<HandlerOutcome[]>;
|
|
87
114
|
/**
|
|
88
115
|
* Wait for in-flight emissions to complete.
|
|
89
116
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { T as Type, F as ForwardRef, M as ModuleMetadata, D as DynamicModule, P
|
|
|
4
4
|
export { C as ClassProvider, E as ExistingProvider, c as FactoryProvider, d as InjectableOptions, e as ModuleOptionsFactory, S as Scope, V as ValueProvider } from './types-CoyG1lE2.js';
|
|
5
5
|
import { E as ExecutionContext, I as ICanActivateGuard } from './interfaces-ivJCgMba.js';
|
|
6
6
|
export { B as BaseExecutionContext, F as FormDataPart } from './interfaces-ivJCgMba.js';
|
|
7
|
-
import { E as EventBusOptions, a as EventEmitter2 } from './event-bus-
|
|
8
|
-
export { D as DomainEvent, b as EventHandler } from './event-bus-
|
|
7
|
+
import { E as EventBusOptions, a as EventEmitter2 } from './event-bus-FfJi7Bg2.js';
|
|
8
|
+
export { D as DomainEvent, b as EventHandler } from './event-bus-FfJi7Bg2.js';
|
|
9
9
|
import { W as WsPeer, a as WsMessage } from './types-G2NQp5Jb.js';
|
|
10
10
|
|
|
11
11
|
declare function forwardRef<T>(fn: () => Type<T>): ForwardRef<T>;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {j as j$1,l,m as m$1,a as a$1,n,o,q as q$1}from'./chunk-
|
|
2
|
-
Already registered by: ${
|
|
3
|
-
Conflicting with: ${r}.${s}`)}match(e,t){let r=e.toUpperCase();for(let s of this.routes){if(s.method!==r)continue;let a=s.pattern.exec(t);if(!a)continue;let i={};for(let u=0;u<s.paramNames.length;u++)i[s.paramNames[u]]=a[u+1]??"";return {route:s,params:i}}return null}getRoutes(){return this.routes}};function ft(o){return "/"+o.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}a(ft,"normalizePath");function pt(o){let e=[],t=o.split("/").map(r=>r.startsWith(":")?(e.push(r.slice(1)),"([^/]+)"):ht(r)).join("/");return {pattern:new RegExp(`^${t}$`),paramNames:e}}a(pt,"compilePath");function ht(o){return o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}a(ht,"escapeRegex");function Ve(o){return o.split("/").filter(Boolean).reduce((e,t)=>e+(t.startsWith(":")?1:0),0)}a(Ve,"routePriority");function mt(o,e,t){let r=`Invalid path "${o}" on ${e}.${t}:`;if(!o.startsWith("/"))throw new Error(`${r} must start with /`);let s=o.split("/").filter((i,u)=>u>0),a=new Set;for(let i of s){if(i==="")throw new Error(`${r} contains empty segment (double slash)`);if(i.startsWith(":")){let u=i.slice(1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u))throw new Error(`${r} invalid param name ":${u}" \u2014 must be a valid identifier`);if(a.has(u))throw new Error(`${r} duplicate param name ":${u}"`);a.add(u);}}}a(mt,"validatePath");var y=Symbol("route:params");function gt(o){return o==null?false:typeof o=="function"||typeof o=="object"&&typeof o.transform=="function"}a(gt,"isParamPipeRef");function W(o,e){return gt(o)?{key:void 0,pipes:[o,...e??[]]}:{key:o,pipes:e??[]}}a(W,"resolveArgs");function m(o,e,t=[]){return (r,s,a)=>{if(s===void 0)return;let i=r[s];if(typeof i!="function")return;let u=i[y]??[];i[y]=[...u,{index:a,type:o,key:e,pipes:t.length>0?t:void 0}];}}a(m,"buildBuiltinDecorator");function wt(o){return typeof o=="function"?new o:o}a(wt,"resolveParamPipe");function Ke(o,...e){let{key:t,pipes:r}=W(o,e);return m("query",t,r)}a(Ke,"Query");function Ye(o,...e){let{key:t,pipes:r}=W(o,e);return m("param",t,r)}a(Ye,"Param");function Qe(o,...e){let{key:t,pipes:r}=W(o,e);return m("body",t,r)}a(Qe,"Body");var Je=a(()=>m("rawBody"),"RawBody"),Ze=a(()=>m("formData"),"FormData"),Xe=a(()=>m("ip"),"Ip"),et=a(()=>m("userAgent"),"UserAgent"),tt=a(o=>m("cookie",o),"Cookie");function rt(o,...e){let{key:t,pipes:r}=W(o,e);return m("headers",t,r)}a(rt,"Headers");function se(o){return ()=>(e,t,r)=>{if(t===void 0)return;let s=e[t];if(typeof s!="function")return;let a=s[y]??[];s[y]=[...a,{index:r,type:"auth",extractor:o}];}}a(se,"defineAuth");var ot=se();function nt(o){return ()=>(e,t,r)=>{if(t===void 0)return;let s=e[t];if(typeof s!="function")return;let a=s[y]??[];s[y]=[...a,{index:r,type:"custom",extractor:o}];}}a(nt,"createParamDecorator");function q(o,e){let t=o.prototype[e];if(typeof t!="function")return null;let r=t[y];return r&&r.length>0?r:null}a(q,"getRouteParams");function z(o){let e=o?.node?.req?.headers;if(e&&typeof e=="object")return e;let t=o?.headers;return t&&typeof t.entries=="function"?Object.fromEntries(t.entries()):t&&typeof t=="object"?t:{}}a(z,"getHeadersAsRecord");async function H(o,e){let t=Math.max(...o.map(s=>s.index)),r=new Array(t+1).fill(void 0);for(let{index:s,type:a,key:i,pipes:u,extractor:d}of o){let c;switch(a){case "query":{let l=e.getQuery();c=i!==void 0?l[i]:l;break}case "param":{let l=e.getParams();c=i!==void 0?l[i]:l;break}case "body":{let l=e.getBody()??{};c=i!==void 0?l[i]:l;break}case "rawBody":{c=e.getRawBody();break}case "formData":{c=e.getFormData();break}case "headers":{let l=z(e.getNativeRequest());c=i!==void 0?l[i.toLowerCase()]:l;break}case "cookie":{let f=z(e.getNativeRequest()).cookie??"";if(i&&f){let h=f.split(";").map(p=>p.trim()).find(p=>p.startsWith(i+"="));c=h?decodeURIComponent(h.slice(i.length+1)):void 0;}else c=void 0;break}case "ip":{let l=e.getNativeRequest(),f=z(l),h=f["cf-connecting-ip"];if(h){c=h.trim();break}let p=f["x-forwarded-for"];if(p){c=(String(p).split(",")[0]??"").trim();break}c=l?.node?.req?.socket?.remoteAddress??"";break}case "userAgent":{c=z(e.getNativeRequest())["user-agent"]??"";break}case "auth":{c=d?await d(e):e.getAuth();break}case "custom":{c=d?await d(e):void 0;break}}if(u&&u.length>0)for(let l of u)c=wt(l).transform(c);r[s]=c;}return r}a(H,"resolveParamArgs");var st="__redirect";function at(o,e=302){return {__redirect:true,url:o,statusCode:e}}a(at,"redirect");function j(o){return o!==null&&typeof o=="object"&&o.__redirect===true}a(j,"isRedirect");function it(){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(it,"isServerless");var C=class{static{a(this,"TruxieApplication");}container;registry;initialized=false;rootModule;options;eventEmitter;prefix="";router;filters=[];gateways=new Map;wsInitialized=false;constructor(e,t={}){this.rootModule=e,this.options=t,this.container=new a$1,this.registry=new n;}async init(){if(this.initialized)return;this.eventEmitter=new o,this.options.eventBus&&this.eventEmitter.setOptions(this.options.eventBus),this.container.register({provide:o,useValue:this.eventEmitter});let e=new a$2;this.container.register({provide:a$2,useValue:e}),this.registry.scan(this.rootModule),this.registry.registerAll(this.container);let t=this.registry.getAllProviders();e._init(this.container,t),await this.registry.callLifecycleHooks(this.container,"onModuleInit"),await q$1(this.container,t),await this.registry.callLifecycleHooks(this.container,"onApplicationBootstrap"),this.router=new w(this.prefix),this.router.register(...this.registry.getAllControllers()),this.filters=this.options.globalFilters??[],this.initialized=true;}setGlobalPrefix(e){return this.prefix=e,this.initialized&&(this.router=new w(this.prefix),this.router.register(...this.registry.getAllControllers())),this}getGlobalPrefix(){return this.prefix}async resolve(e){return this.ensureInitialized(),this.container.resolve(e)}has(e){return this.container.has(e)}getContainer(){return this.container}matchRoute(e,t){return this.ensureInitialized(),this.router.match(e,t)??null}async handleRequest(e$1,t){this.ensureInitialized();let{container:r,dispose:s}=this.createRequestContext();try{let a=await r.resolve(e$1.controllerClass),i=a[e$1.methodName].bind(a),u=q(e$1.controllerClass,e$1.methodName);try{for(let c of e$1.guardClasses)if(!await(r.has(c)?await r.resolve(c):new c).canActivate(t))throw new e("Access denied by guard");let d=u?await i(...await H(u,t)):await i(t);if(j(d)){let c=d;return {value:d,isRedirect:!0,redirectUrl:c.url,redirectStatus:c.statusCode}}return {value:d,isRedirect:!1}}catch(d){for(let c of this.filters)try{return {value:await c.catch(d,t),isRedirect:!1}}catch{continue}throw d}}finally{await s();}}hasGateways(){return this.ensureInitialized(),this.registry.getAllGateways().length>0}async createWebSocketHooks(e){this.ensureInitialized(),await this.initGateways();let t=this;return {async open(r){let a="/"+(e.getUrl(r).split("?")[0]??"/").replace(/^\/+|\/+$/g,""),i=t.matchGatewayPath(a);if(!i)return;let u=r.context;u&&(u._gatewayPath=i);let d=t.gateways.get(i),c=e.adaptPeer(r);for(let l of d.serverProps)d.instance[l]={peers:e.getPeers(r)??new Set};if(d.hasConnection)try{await d.instance.handleConnection(c);}catch(l){console.error(`[WS] ${d.className}.handleConnection error:`,l);}},async message(r,s){let i=r.context?._gatewayPath;if(!i)return;let u=t.gateways.get(i);if(!u)return;let d=e.adaptPeer(r),c=e.adaptMessage(s),l;try{l=c.json();}catch{return}if(!l.event||typeof l.event!="string")return;let f=u.messageHandlers.get(l.event);if(f)try{let h=n$1(f.paramMeta,d,c,l.data),p=await f.method(...h);p!=null&&d.send(p);}catch(h){console.error(`[WS] ${u.className}.${l.event} error:`,h);}},async close(r,s){let i=r.context?._gatewayPath;if(!i)return;let u=t.gateways.get(i);if(!u?.hasDisconnect)return;let d=e.adaptPeer(r);try{await u.instance.handleDisconnect(d,s);}catch(c){console.error(`[WS] ${u.className}.handleDisconnect error:`,c);}},async error(r,s){let a=r?.id??"unknown";console.error(`[WS] Peer ${String(a)} error:`,s);}}}getControllers(){return this.ensureInitialized(),this.registry.getAllControllers()}getGateways(){return this.ensureInitialized(),this.registry.getAllGateways()}getProviders(){return this.ensureInitialized(),this.registry.getAllProviders()}getEventEmitter(){return this.ensureInitialized(),this.eventEmitter}getRouter(){return this.ensureInitialized(),this.router}createHandler(e){return this.ensureInitialized(),T(this.container,this.getGlobalOptions(),e)}async shutdown(){this.initialized&&(await this.registry.callLifecycleHooks(this.container,"onModuleDestroy"),await this.registry.callLifecycleHooks(this.container,"onApplicationShutdown"),this.eventEmitter.clear(),await this.container.dispose(),this.initialized=false);}createRequestContext(){if(!this.container.hasRequestScoped())return {container:this.container,dispose:a(async()=>{},"dispose")};let e=this.container.createChild();return {container:e,dispose:a(()=>e.dispose(),"dispose")}}matchGatewayPath(e){if(this.gateways.has(e))return e;for(let t of this.gateways.keys())if(e.endsWith(t))return t;if(this.gateways.has("/"))return "/"}async initGateways(){if(!this.wsInitialized){for(let e of this.registry.getAllGateways()){let t=i(e);if(!t)continue;let r=await this.container.resolve(e),s=new Map;for(let a of j$2(e)){let i=r[a.methodName];typeof i=="function"&&s.set(a.event,{method:i.bind(r),paramMeta:k$1(e.prototype[a.methodName])});}if(this.gateways.set(t.path,{instance:r,className:e.name,messageHandlers:s,hasConnection:typeof r.handleConnection=="function",hasDisconnect:typeof r.handleDisconnect=="function",serverProps:m$2(e)}),typeof r.afterInit=="function")try{await r.afterInit();}catch{}}this.wsInitialized=true;}}getGlobalOptions(){return {guards:this.options.globalGuards,interceptors:this.options.globalInterceptors,pipes:this.options.globalPipes,filters:this.options.globalFilters}}ensureInitialized(){if(!this.initialized)throw new Error("TruxieApplication not initialized. Call TruxieFactory.create() or app.init().")}},L=class{static{a(this,"TruxieFactory");}static async create(e,t){let r=new C(e,t);return await r.init(),r}};export{ot as Auth,_ as BaseExecutionContext,Qe as Body,ze as Catch,F as ConfigurableModuleBuilder,w as ControllerRouter,tt as Cookie,Le as DefaultValuePipe,B as DomainEvent,Ze as FormData,rt as Headers,Xe as Ip,Ye as Param,$ as ParseIdPipe,O as ParseIntPipe,Ke as Query,st as REDIRECT_BRAND,Je as RawBody,C as TruxieApplication,L as TruxieFactory,ee as UOW_INSTANCE_KEY,X as UOW_SESSION_KEY,U as UnitOfWorkInterceptor,Be as UseFilters,We as UseInterceptors,qe as UseMiddleware,je as UsePipes,et as UserAgent,nt as createParamDecorator,T as createPipeline,se as defineAuth,k as getEffectiveInterceptors,G as getEffectiveMiddlewares,J as getInterceptorsMetadata,Z as getMethodInterceptors,ne as getMethodMiddlewares,oe as getMiddlewaresMetadata,q as getRouteParams,j as isRedirect,it as isServerless,at as redirect,H as resolveParamArgs};
|
|
1
|
+
import {j as j$1,l,m as m$1,a as a$1,n,o,q as q$1}from'./chunk-SWXNQKUR.js';export{a as Container,b as Controller,f as Delete,o as EventEmitter2,c as Get,n as ModuleRegistry,i as NoGuard,p as OnEvent,g as Patch,d as Post,e as Put,h as RouteGuards,k as getControllerGuards,j as getControllerPath,m as getMethodGuards,l as getRouteMetadata}from'./chunk-SWXNQKUR.js';import {n as n$1,i,j as j$2,k as k$1,m as m$2}from'./chunk-RLQ7JJW6.js';import {a as a$2}from'./chunk-F3UTUZEO.js';export{a as DiscoveryService}from'./chunk-F3UTUZEO.js';import {c,e,g as g$1}from'./chunk-PT5RXFB5.js';export{a as AppError,f as ConflictError,e as ForbiddenError,b as NotFoundError,g as RequestAbortedError,d as UnauthorizedError,c as ValidationError}from'./chunk-PT5RXFB5.js';import {b}from'./chunk-ASOZYX5T.js';export{m as Global,f as Inject,e as Injectable,l as Module,g as Optional,a as Scope,c as forwardRef,n as getModuleMetadata,o as isGlobalModule,d as resolveForwardRef}from'./chunk-ASOZYX5T.js';import {a}from'./chunk-EI7MMDWY.js';import'reflect-metadata';function ut(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(ut,"createAsyncProviders");var F=class{static{a(this,"ConfigurableModuleBuilder");}description;featureDescription;onForRoot;onForFeature;constructor(e="MODULE_OPTIONS"){this.description=e,this.featureDescription=e+"_FEATURE";}setTokenDescription(e){return this.description=e,this}transformDynamicModule(e){return this.onForRoot=e,this}transformFeatureModule(e){return this.onForFeature=e,this}build(){let e=new b(this.description),t=new b(this.featureDescription),r=this.onForRoot,a$1=this.onForFeature;return {ConfigurableModuleClass:class{static{a(this,"ConfigurableModuleClassImpl");}static forRoot(u,l={}){let c={module:this,global:l.global??false,providers:[{provide:e,useValue:u}],exports:[e]};return r&&(c=r(c,u)),c}static forRootAsync(u){let l=ut(e,u);return {module:this,imports:u.imports??[],providers:l,exports:[e]}}static forFeature(u,l={}){let c={module:this,global:l.global??false,providers:[{provide:t,useValue:u}],exports:[t]};return a$1&&(c=a$1(c,u)),c}},MODULE_OPTIONS_TOKEN:e,MODULE_FEATURE_TOKEN:t}}};var _=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,a={},s={},i){this.nativeRequest=e,this.handler=t,this.container=r,this.query=a,this.params=s,this.abortController=i??new AbortController;}getNativeRequest(){return this.nativeRequest}getHandler(){return this.handler}getBody(){return this.body}setBody(e){this.body=e;}getRawBody(){return this.rawBody}setRawBody(e){this.rawBody=e;}getFormData(){return this.formData}setFormData(e){this.formData=e;}getQuery(){return this.query}getParams(){return this.params}getAuth(){return this.auth}setAuth(e){this.auth=e;}getMetadata(e){return this.metadata.get(e)}setMetadata(e,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 $e=Symbol("filters"),Oe=Symbol("catch");function Be(...o){return (e,t,r)=>{let a=t?e.constructor:e,s=Reflect.getOwnMetadata($e,a)??[];Reflect.defineMetadata($e,[...s,...o],a);}}a(Be,"UseFilters");function ze(...o){return e=>{Reflect.defineMetadata(Oe,o,e);}}a(ze,"Catch");function K(o){return Reflect.getOwnMetadata(Oe,o)??[]}a(K,"getCatchMetadata");function T(o,e$1,t){return async r=>{let a$1=[...e$1.middlewares??[],...t.middlewares??[]],s=[...e$1.guards??[],...t.guards??[]],i=[...e$1.interceptors??[],...t.interceptors??[]],u=[...e$1.pipes??[],...t.pipes??[]],l=[...e$1.filters??[],...t.filters??[]],c=await A(o,l);try{g(r);let d=await A(o,a$1);return await lt(r,d,async()=>{g(r);let f=await A(o,s);for(let M of f)if(g(r),!await M.canActivate(r))throw new e("Access denied by guard");g(r);let h=await A(o,u);for(let M of h)g(r),await M.transform(r);g(r);let p=await A(o,i),ae=a(async()=>(g(r),t.handler(r)),"handlerCall");return p.length===0?ae():p.reduceRight((M,ie)=>async()=>(g(r),ie.intercept(r,M)),ae)()})}catch(d){return dt(d,r,c)}}}a(T,"createPipeline");async function lt(o,e,t){return e.length===0?t():e.reduceRight((a,s)=>()=>s.use(o,a),t)()}a(lt,"runMiddlewareChain");function g(o){if(o.getSignal().aborted)throw new g$1}a(g,"checkAborted");async function dt(o,e,t){for(let r of t){let a=K(r.constructor);if(a.length===0||o instanceof Error&&a.some(i=>o instanceof i))return r.catch(o,e)}throw o}a(dt,"handleError");async function A(o,e){let t=[];for(let r of e)typeof r=="function"?t.push(await o.resolve(r)):t.push(r);return t}a(A,"resolveRefs");var Y=Symbol("interceptors"),Q=Symbol("method:interceptors");function We(...o){return (e,t,r)=>{if(t!==void 0){let s=r?.value??e,i=s[Q]??[];return s[Q]=[...i,...o],r}let a=Reflect.getOwnMetadata(Y,e)??[];Reflect.defineMetadata(Y,[...a,...o],e);}}a(We,"UseInterceptors");function J(o){return Reflect.getOwnMetadata(Y,o)??[]}a(J,"getInterceptorsMetadata");function Z(o,e){let r=o.prototype?.[e];return typeof r=="function"&&r[Q]||[]}a(Z,"getMethodInterceptors");function k(o,e){return [...J(o),...Z(o,e)]}a(k,"getEffectiveInterceptors");var X="uow:session",ee="uow:instance",U=class{static{a(this,"UnitOfWorkInterceptor");}factory;constructor(e){this.factory=e;}async intercept(e,t){let r=this.factory();await r.start(),e.setData(X,r.getContext()),e.setData(ee,r);try{let a=await t();return await r.commit(),a}catch(a){throw await r.rollback(),a}}};var te=Symbol("middlewares"),re=Symbol("method:middlewares");function qe(...o){return (e,t,r)=>{if(t!==void 0){let s=r?.value??e,i=s[re]??[];return s[re]=[...i,...o],r}let a=Reflect.getOwnMetadata(te,e)??[];Reflect.defineMetadata(te,[...a,...o],e);}}a(qe,"UseMiddleware");function oe(o){return Reflect.getOwnMetadata(te,o)??[]}a(oe,"getMiddlewaresMetadata");function ne(o,e){let r=o.prototype?.[e];return typeof r=="function"&&r[re]||[]}a(ne,"getMethodMiddlewares");function G(o,e){return [...oe(o),...ne(o,e)]}a(G,"getEffectiveMiddlewares");var He=Symbol("pipes");function je(...o){return (e,t,r)=>{let a=t?e.constructor:e,s=Reflect.getOwnMetadata(He,a)??[];Reflect.defineMetadata(He,[...s,...o],a);}}a(je,"UsePipes");var ft=/^[0-9a-fA-F]{24}$/,$=class{static{a(this,"ParseIdPipe");}paramName;constructor(e="id"){this.paramName=e;}transform(e){let r=e.getParams()[this.paramName];if(!r||!ft.test(r))throw new c(`Invalid ${this.paramName}: must be a valid ObjectId`)}};var O=class{static{a(this,"ParseIntPipe");}transform(e){let t=Number(e);if(!Number.isInteger(t)||e===""||e===null||e===void 0)throw new c(`Expected an integer, received: ${JSON.stringify(e)}`);return t}};function Le(o){return {transform(e){return e??o}}}a(Le,"DefaultValuePipe");var B=class{static{a(this,"DomainEvent");}payload;timestamp;constructor(e){this.payload=e,this.timestamp=Date.now();}};var w=class{static{a(this,"ControllerRouter");}routes=[];globalPrefix;constructor(e=""){this.globalPrefix=e;}register(...e){for(let t of e){let r=j$1(t)??"",a=l(t);for(let s of a){let i=Ve(`${this.globalPrefix}/${r}/${s.path}`);mt(i,t.name,s.methodName),this.checkDuplicate(i,s.method,t.name,s.methodName);let{pattern:u,paramNames:l}=pt(i),c=m$1(t,s.methodName),d=k(t,s.methodName),f=G(t,s.methodName);this.routes.push({method:s.method,pattern:u,paramNames:l,controllerClass:t,methodName:s.methodName,guardClasses:c,interceptorRefs:d,middlewareRefs:f,rawPath:i});}}this.routes.sort((t,r)=>Ke(t.rawPath)-Ke(r.rawPath));}checkDuplicate(e,t,r,a){let s=this.routes.find(i=>i.method===t&&i.rawPath===e);if(s)throw new Error(`Duplicate route: ${t} ${e}
|
|
2
|
+
Already registered by: ${s.controllerClass.name}.${s.methodName}
|
|
3
|
+
Conflicting with: ${r}.${a}`)}match(e,t){let r=e.toUpperCase(),a=Ve(t);for(let s of this.routes){if(s.method!==r)continue;let i=s.pattern.exec(a);if(!i)continue;let u={};for(let l=0;l<s.paramNames.length;l++)u[s.paramNames[l]]=i[l+1]??"";return {route:s,params:u}}return null}getRoutes(){return this.routes}};function Ve(o){return "/"+o.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}a(Ve,"normalizePath");function pt(o){let e=[],t=o.split("/").map(r=>r.startsWith(":")?(e.push(r.slice(1)),"([^/]+)"):ht(r)).join("/");return {pattern:new RegExp(`^${t}$`),paramNames:e}}a(pt,"compilePath");function ht(o){return o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}a(ht,"escapeRegex");function Ke(o){return o.split("/").filter(Boolean).reduce((e,t)=>e+(t.startsWith(":")?1:0),0)}a(Ke,"routePriority");function mt(o,e,t){let r=`Invalid path "${o}" on ${e}.${t}:`;if(!o.startsWith("/"))throw new Error(`${r} must start with /`);let a=o.split("/").filter((i,u)=>u>0),s=new Set;for(let i of a){if(i==="")throw new Error(`${r} contains empty segment (double slash)`);if(i.startsWith(":")){let u=i.slice(1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u))throw new Error(`${r} invalid param name ":${u}" \u2014 must be a valid identifier`);if(s.has(u))throw new Error(`${r} duplicate param name ":${u}"`);s.add(u);}}}a(mt,"validatePath");var y=Symbol.for("truxie:route:params");function gt(o){return o==null?false:typeof o=="function"||typeof o=="object"&&typeof o.transform=="function"}a(gt,"isParamPipeRef");function W(o,e){return gt(o)?{key:void 0,pipes:[o,...e??[]]}:{key:o,pipes:e??[]}}a(W,"resolveArgs");function m(o,e,t=[]){return (r,a,s)=>{if(a===void 0)return;let i=r[a];if(typeof i!="function")return;let u=i[y]??[];i[y]=[...u,{index:s,type:o,key:e,pipes:t.length>0?t:void 0}];}}a(m,"buildBuiltinDecorator");function wt(o){return typeof o=="function"?new o:o}a(wt,"resolveParamPipe");function Ye(o,...e){let{key:t,pipes:r}=W(o,e);return m("query",t,r)}a(Ye,"Query");function Qe(o,...e){let{key:t,pipes:r}=W(o,e);return m("param",t,r)}a(Qe,"Param");function Je(o,...e){let{key:t,pipes:r}=W(o,e);return m("body",t,r)}a(Je,"Body");var Ze=a(()=>m("rawBody"),"RawBody"),Xe=a(()=>m("formData"),"FormData"),et=a(()=>m("ip"),"Ip"),tt=a(()=>m("userAgent"),"UserAgent"),rt=a(o=>m("cookie",o),"Cookie");function ot(o,...e){let{key:t,pipes:r}=W(o,e);return m("headers",t,r)}a(ot,"Headers");function se(o){return ()=>(e,t,r)=>{if(t===void 0)return;let a=e[t];if(typeof a!="function")return;let s=a[y]??[];a[y]=[...s,{index:r,type:"auth",extractor:o}];}}a(se,"defineAuth");var nt=se();function st(o){return ()=>(e,t,r)=>{if(t===void 0)return;let a=e[t];if(typeof a!="function")return;let s=a[y]??[];a[y]=[...s,{index:r,type:"custom",extractor:o}];}}a(st,"createParamDecorator");function q(o,e){let t=o.prototype[e];if(typeof t!="function")return null;let r=t[y];return r&&r.length>0?r:null}a(q,"getRouteParams");function z(o){let e=o?.node?.req?.headers;if(e&&typeof e=="object")return e;let t=o?.headers;return t&&typeof t.entries=="function"?Object.fromEntries(t.entries()):t&&typeof t=="object"?t:{}}a(z,"getHeadersAsRecord");async function H(o,e){let t=Math.max(...o.map(a=>a.index)),r=new Array(t+1).fill(void 0);for(let{index:a,type:s,key:i,pipes:u,extractor:l}of o){let c;switch(s){case "query":{let d=e.getQuery();c=i!==void 0?d[i]:d;break}case "param":{let d=e.getParams();c=i!==void 0?d[i]:d;break}case "body":{let d=e.getBody()??{};c=i!==void 0?d[i]:d;break}case "rawBody":{c=e.getRawBody();break}case "formData":{c=e.getFormData();break}case "headers":{let d=z(e.getNativeRequest());c=i!==void 0?d[i.toLowerCase()]:d;break}case "cookie":{let f=z(e.getNativeRequest()).cookie??"";if(i&&f){let h=f.split(";").map(p=>p.trim()).find(p=>p.startsWith(i+"="));c=h?decodeURIComponent(h.slice(i.length+1)):void 0;}else c=void 0;break}case "ip":{let d=e.getNativeRequest(),f=z(d),h=f["cf-connecting-ip"];if(h){c=h.trim();break}let p=f["x-forwarded-for"];if(p){c=(String(p).split(",")[0]??"").trim();break}c=d?.node?.req?.socket?.remoteAddress??"";break}case "userAgent":{c=z(e.getNativeRequest())["user-agent"]??"";break}case "auth":{c=l?await l(e):e.getAuth();break}case "custom":{c=l?await l(e):void 0;break}}if(u&&u.length>0)for(let d of u)c=wt(d).transform(c);r[a]=c;}return r}a(H,"resolveParamArgs");var at="__redirect";function it(o,e=302){return {__redirect:true,url:o,statusCode:e}}a(it,"redirect");function j(o){return o!==null&&typeof o=="object"&&o.__redirect===true}a(j,"isRedirect");function ct(){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(ct,"isServerless");var C=class{static{a(this,"TruxieApplication");}container;registry;initialized=false;rootModule;options;eventEmitter;prefix="";router;filters=[];gateways=new Map;wsInitialized=false;constructor(e,t={}){this.rootModule=e,this.options=t,this.container=new a$1,this.registry=new n;}async init(){if(this.initialized)return;this.eventEmitter=new o,this.options.eventBus&&this.eventEmitter.setOptions(this.options.eventBus),this.container.register({provide:o,useValue:this.eventEmitter});let e=new a$2;this.container.register({provide:a$2,useValue:e}),this.registry.scan(this.rootModule),this.registry.registerAll(this.container);let t=this.registry.getAllProviders();e._init(this.container,t),await this.registry.callLifecycleHooks(this.container,"onModuleInit"),await q$1(this.container,t),await this.registry.callLifecycleHooks(this.container,"onApplicationBootstrap"),this.router=new w(this.prefix),this.router.register(...this.registry.getAllControllers()),this.filters=this.options.globalFilters??[],this.initialized=true;}setGlobalPrefix(e){return this.prefix=e,this.initialized&&(this.router=new w(this.prefix),this.router.register(...this.registry.getAllControllers())),this}getGlobalPrefix(){return this.prefix}async resolve(e){return this.ensureInitialized(),this.container.resolve(e)}has(e){return this.container.has(e)}getContainer(){return this.container}matchRoute(e,t){return this.ensureInitialized(),this.router.match(e,t)??null}async handleRequest(e$1,t){this.ensureInitialized();let{container:r,dispose:a}=this.createRequestContext();try{let s=await r.resolve(e$1.controllerClass),i=s[e$1.methodName].bind(s),u=q(e$1.controllerClass,e$1.methodName);try{for(let c of e$1.guardClasses)if(!await(r.has(c)?await r.resolve(c):new c).canActivate(t))throw new e("Access denied by guard");let l=u?await i(...await H(u,t)):await i(t);if(j(l)){let c=l;return {value:l,isRedirect:!0,redirectUrl:c.url,redirectStatus:c.statusCode}}return {value:l,isRedirect:!1}}catch(l){for(let c of this.filters)try{return {value:await c.catch(l,t),isRedirect:!1}}catch{continue}throw l}}finally{await a();}}hasGateways(){return this.ensureInitialized(),this.registry.getAllGateways().length>0}async createWebSocketHooks(e){this.ensureInitialized(),await this.initGateways();let t=this;return {async open(r){let s="/"+(e.getUrl(r).split("?")[0]??"/").replace(/^\/+|\/+$/g,""),i=t.matchGatewayPath(s);if(!i)return;let u=r.context;u&&(u._gatewayPath=i);let l=t.gateways.get(i),c=e.adaptPeer(r);for(let d of l.serverProps)l.instance[d]={peers:e.getPeers(r)??new Set};if(l.hasConnection)try{await l.instance.handleConnection(c);}catch(d){console.error(`[WS] ${l.className}.handleConnection error:`,d);}},async message(r,a){let i=r.context?._gatewayPath;if(!i)return;let u=t.gateways.get(i);if(!u)return;let l=e.adaptPeer(r),c=e.adaptMessage(a),d;try{d=c.json();}catch{return}if(!d.event||typeof d.event!="string")return;let f=u.messageHandlers.get(d.event);if(f)try{let h=n$1(f.paramMeta,l,c,d.data),p=await f.method(...h);p!=null&&l.send(p);}catch(h){console.error(`[WS] ${u.className}.${d.event} error:`,h);}},async close(r,a){let i=r.context?._gatewayPath;if(!i)return;let u=t.gateways.get(i);if(!u?.hasDisconnect)return;let l=e.adaptPeer(r);try{await u.instance.handleDisconnect(l,a);}catch(c){console.error(`[WS] ${u.className}.handleDisconnect error:`,c);}},async error(r,a){let s=r?.id??"unknown";console.error(`[WS] Peer ${String(s)} error:`,a);}}}getControllers(){return this.ensureInitialized(),this.registry.getAllControllers()}getGateways(){return this.ensureInitialized(),this.registry.getAllGateways()}getProviders(){return this.ensureInitialized(),this.registry.getAllProviders()}getEventEmitter(){return this.ensureInitialized(),this.eventEmitter}getRouter(){return this.ensureInitialized(),this.router}createHandler(e){return this.ensureInitialized(),T(this.container,this.getGlobalOptions(),e)}async shutdown(){this.initialized&&(await this.registry.callLifecycleHooks(this.container,"onModuleDestroy"),await this.registry.callLifecycleHooks(this.container,"onApplicationShutdown"),this.eventEmitter.clear(),await this.container.dispose(),this.initialized=false);}createRequestContext(){if(!this.container.hasRequestScoped())return {container:this.container,dispose:a(async()=>{},"dispose")};let e=this.container.createChild();return {container:e,dispose:a(()=>e.dispose(),"dispose")}}matchGatewayPath(e){if(this.gateways.has(e))return e;for(let t of this.gateways.keys())if(e.endsWith(t))return t;if(this.gateways.has("/"))return "/"}async initGateways(){if(!this.wsInitialized){for(let e of this.registry.getAllGateways()){let t=i(e);if(!t)continue;let r=await this.container.resolve(e),a=new Map;for(let s of j$2(e)){let i=r[s.methodName];typeof i=="function"&&a.set(s.event,{method:i.bind(r),paramMeta:k$1(e.prototype[s.methodName])});}if(this.gateways.set(t.path,{instance:r,className:e.name,messageHandlers:a,hasConnection:typeof r.handleConnection=="function",hasDisconnect:typeof r.handleDisconnect=="function",serverProps:m$2(e)}),typeof r.afterInit=="function")try{await r.afterInit();}catch{}}this.wsInitialized=true;}}getGlobalOptions(){return {guards:this.options.globalGuards,interceptors:this.options.globalInterceptors,pipes:this.options.globalPipes,filters:this.options.globalFilters}}ensureInitialized(){if(!this.initialized)throw new Error("TruxieApplication not initialized. Call TruxieFactory.create() or app.init().")}},L=class{static{a(this,"TruxieFactory");}static async create(e,t){let r=new C(e,t);return await r.init(),r}};export{nt as Auth,_ as BaseExecutionContext,Je as Body,ze as Catch,F as ConfigurableModuleBuilder,w as ControllerRouter,rt as Cookie,Le as DefaultValuePipe,B as DomainEvent,Xe as FormData,ot as Headers,et as Ip,Qe as Param,$ as ParseIdPipe,O as ParseIntPipe,Ye as Query,at as REDIRECT_BRAND,Ze as RawBody,C as TruxieApplication,L as TruxieFactory,ee as UOW_INSTANCE_KEY,X as UOW_SESSION_KEY,U as UnitOfWorkInterceptor,Be as UseFilters,We as UseInterceptors,qe as UseMiddleware,je as UsePipes,tt as UserAgent,st as createParamDecorator,T as createPipeline,se as defineAuth,k as getEffectiveInterceptors,G as getEffectiveMiddlewares,J as getInterceptorsMetadata,Z as getMethodInterceptors,ne as getMethodMiddlewares,oe as getMiddlewaresMetadata,q as getRouteParams,j as isRedirect,ct as isServerless,it as redirect,H as resolveParamArgs};
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { C as Container } from './container-4Q8Oq_GB.js';
|
|
2
2
|
import { M as ModuleMetadata, T as Type, D as DynamicModule, a as Token } from './types-CoyG1lE2.js';
|
|
3
|
-
import { a as EventEmitter2 } from './event-bus-
|
|
3
|
+
import { a as EventEmitter2 } from './event-bus-FfJi7Bg2.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Chain API for overriding a single provider in a testing module.
|
package/dist/testing.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a as a$1,o,n,q}from'./chunk-
|
|
1
|
+
import {a as a$1,o,n,q}from'./chunk-SWXNQKUR.js';import'./chunk-RLQ7JJW6.js';import {a as a$2}from'./chunk-F3UTUZEO.js';import {d}from'./chunk-ASOZYX5T.js';import {a}from'./chunk-EI7MMDWY.js';var y=class{static{a(this,"TestBuilder");}metadata;overrides=new Map;constructor(e){this.metadata=e;}overrideProvider(e){return {useValue:a(t=>(this.overrides.set(e,{provide:e,useValue:t}),this),"useValue"),useClass:a(t=>(this.overrides.set(e,{provide:e,useClass:t}),this),"useClass"),useFactory:a((t,n)=>(this.overrides.set(e,{provide:e,useFactory:t,inject:n??[]}),this),"useFactory")}}async compile(){let e=new a$1,t=new o;e.register({provide:o,useValue:t});let n$1=new a$2;e.register({provide:a$2,useValue:n$1});let s=this.metadata;if(h(s)){let r=(s.providers??[]).map(a=>a&&typeof a=="object"&&"forwardRef"in a?d(a):a);if(e.register(...r),s.imports&&s.imports.length>0){let a$1=new n,w={module:class{static{a(this,"TempTestModule");}},imports:s.imports,providers:r,exports:s.exports??[]};a$1.scan(w),a$1.registerAll(e);}}else {let r=new n;r.scan(s),r.registerAll(e);}for(let[,r]of this.overrides)e.register(r);let i=this.collectProviders(s);return n$1._init(e,i),await this.callHook(e,i,"onModuleInit"),await q(e,i),await this.callHook(e,i,"onApplicationBootstrap"),{resolve:a(r=>e.resolve(r),"resolve"),has:a(r=>e.has(r),"has"),getContainer:a(()=>e,"getContainer"),getEventEmitter:a(()=>t,"getEventEmitter"),shutdown:a(async()=>{await this.callHook(e,i,"onModuleDestroy"),await this.callHook(e,i,"onApplicationShutdown"),t.clear(),await e.dispose();},"shutdown")}}collectProviders(e){return h(e)?(e.providers??[]).map(t=>t&&typeof t=="object"&&"forwardRef"in t?d(t):t):[]}async callHook(e,t,n){for(let s of t){let i=typeof s=="function"?s:s.provide;if(e.has(i))try{let r=await e.resolve(i);r&&typeof r=="object"&&typeof r[n]=="function"&&await r[n]();}catch{}}}};function h(c){return !(typeof c=="function"||c&&typeof c=="object"&&"module"in c)}a(h,"isModuleMetadata");var p=class{static{a(this,"Test");}static createTestingModule(e){return new y(e)}};export{p as Test};
|
package/package.json
CHANGED
package/dist/chunk-QS3YFPBL.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import {i as i$1}from'./chunk-RLQ7JJW6.js';import {d,h as h$1,a as a$1,i,j,k as k$1,b,n,o,e}from'./chunk-ASOZYX5T.js';import {a}from'./chunk-EI7MMDWY.js';import'reflect-metadata';var $=class s{static{a(this,"Container");}registrations=new Map;resolving=new Set;parent=null;children=[];register(...t){for(let e of t)this.registerOne(e);}registerOne(t){let e=t&&typeof t=="object"&&"forwardRef"in t?d(t):t;if(typeof e=="function"){let a=h$1(e)?.scope??a$1.SINGLETON;this.registrations.set(e,{provider:e,scope:a});return}let r=e.provide,o=a$1.SINGLETON,n=e;if("useClass"in e){let i=e.useClass,a=i&&typeof i=="object"&&"forwardRef"in i?d(i):i,f=h$1(a);o=e.scope??f?.scope??a$1.SINGLETON,n={...e,useClass:a};}else if("useExisting"in e){let i=e.useExisting,a=i&&typeof i=="object"&&"forwardRef"in i?d(i):i;n={...e,useExisting:a};}else "useFactory"in e&&(o=e.scope??a$1.SINGLETON);this.registrations.set(r,{provider:n,scope:o});}async resolve(t){let e=d(t),r=e!==t?e:t,o=this.registrations.get(r)??this.parent?.findRegistration(r);if(!o)throw new Error(`No provider found for ${x(r)}`);if(o.scope===a$1.SINGLETON&&o.instance!==void 0||o.scope===a$1.REQUEST&&this.parent!==null&&o.instance!==void 0)return o.instance;if(this.resolving.has(r))throw new Error(`Circular dependency detected for ${x(r)}`);this.resolving.add(r);try{let n=await this.createInstance(o);return (o.scope===a$1.SINGLETON||o.scope===a$1.REQUEST&&this.parent!==null)&&(o.instance=n),n}finally{this.resolving.delete(r);}}has(t){return this.registrations.has(t)||(this.parent?.has(t)??false)}hasRequestScoped(){for(let[,t]of this.registrations)if(t.scope===a$1.REQUEST)return true;return false}findRegistration(t){return this.registrations.get(t)??this.parent?.findRegistration(t)}createChild(){let t=new s;t.parent=this;for(let[e,r]of this.registrations)r.scope===a$1.REQUEST&&t.registrations.set(e,{provider:r.provider,scope:a$1.REQUEST,instance:void 0});return this.children.push(t),t}async dispose(){for(let t of this.children)await t.dispose();this.children=[];for(let[,t]of this.registrations)if(t.instance&&typeof t.instance=="object"&&t.instance!==null){let e=t.instance;typeof e.onModuleDestroy=="function"&&await e.onModuleDestroy();}this.registrations.clear(),this.resolving.clear();}async createInstance(t){let{provider:e}=t;if(typeof e=="function")return this.instantiateClass(e);if("useValue"in e)return e.useValue;if("useClass"in e)return this.instantiateClass(e.useClass);if("useFactory"in e){let r=e,o=[];if(r.inject)for(let n of r.inject)o.push(await this.resolve(n));return r.useFactory(...o)}if("useExisting"in e)return this.resolve(e.useExisting);throw new Error("Unknown provider type")}async instantiateClass(t){let e=Reflect.getMetadata("design:paramtypes",t)??[],r=i(t),o=j(t),n=k$1(t),i$1=o.size>0?Math.max(...o.keys())+1:0,a=Math.max(e.length,i$1,r.length),f=[];for(let p=0;p<a;p++){let y=o.get(p)??r[p]??e[p],w=n.has(p);try{f.push(await this.resolve(y));}catch{if(w)f.push(void 0);else throw new Error(`Cannot resolve parameter at index ${p} (${x(y)}) of ${t.name}`)}}return new t(...f)}};function x(s){return typeof s=="string"?s:typeof s=="symbol"||s instanceof b?s.toString():typeof s=="function"?s.name:String(s)}a(x,"tokenToString");var L=Symbol("controller:path"),R=Symbol("controller:guards"),T=Symbol("route:metadata"),M=Symbol("method:route"),g=Symbol("method:guards"),S=Symbol("method:noguard");function tt(s){return t=>{Reflect.defineMetadata(L,s,t);}}a(tt,"Controller");function v(s){return (t="")=>(e,r,o)=>{let n=o!==void 0,i=String(n?r:r?.name??r),a=n?o?.value:e;if(typeof a=="function"&&(a[M]={method:s,path:t,methodName:i}),n){let f=Reflect.getOwnMetadata(T,e.constructor)??[];return f.push({method:s,path:t,methodName:i}),Reflect.defineMetadata(T,f,e.constructor),o}return e}}a(v,"createMethodDecorator");var et=v("GET"),ot=v("POST"),rt=v("PUT"),nt=v("DELETE"),st=v("PATCH");function it(...s){return (t,e,r)=>{if(e==null){Reflect.defineMetadata(R,s,t);return}if(r!==void 0){if(r?.value){let o=r.value[g]??[];r.value[g]=[...o,...s];}return r}if(typeof t=="function"){let o=t[g]??[];t[g]=[...o,...s];}return typeof t=="function"&&e?.kind==="class"&&Reflect.defineMetadata(R,s,t),t}}a(it,"RouteGuards");function at(){return (s,t,e)=>e!==void 0?(e?.value&&(e.value[S]=true),e):(typeof s=="function"&&(s[S]=true),s)}a(at,"NoGuard");function U(s){return Reflect.getOwnMetadata(L,s)}a(U,"getControllerPath");function V(s){return Reflect.getOwnMetadata(R,s)??[]}a(V,"getControllerGuards");function ct(s){let t=[],e=s.prototype;if(e){let r=Object.getOwnPropertyNames(e);for(let o of r){if(o==="constructor")continue;let n=Object.getOwnPropertyDescriptor(e,o);if(!n||typeof n.value!="function")continue;let i=n.value;i[M]&&t.push(i[M]);}}return t.length>0?t:Reflect.getOwnMetadata(T,s)??[]}a(ct,"getRouteMetadata");function ft(s,t){let r=s.prototype?.[t],o=typeof r=="function"&&r[S]===true,n=typeof r=="function"&&r[g]||[];return o?n:[...V(s),...n]}a(ft,"getMethodGuards");var _=class{static{a(this,"ModuleRegistry");}resolved=new Map;sortedModules=[];scan(t){this.resolveModule(t),this.sortedModules=this.topologicalSort(),this.validateExports();}registerAll(t){let e=new Set;for(let r of this.sortedModules)if(r.global)for(let o of r.providers)e.add(o);e.size>0&&t.register(...e);for(let r of this.sortedModules){t.register(...r.providers);for(let o of r.metadata.imports??[]){let n=this.getModuleType(o),i=this.resolved.get(n);if(i)for(let a of i.exports){let f=this.findProvider(i,a)??this.findReExportedProvider(i,a);f&&t.register(f);}}}}getAllProviders(){let t=[];for(let e of this.sortedModules)t.push(...e.providers);return t}getAllControllers(){let t=new Set,e=[];for(let r of this.sortedModules){for(let o of r.controllers)t.has(o)||(t.add(o),e.push(o));for(let o of r.metadata.providers??[])typeof o=="function"&&U(o)!==void 0&&!t.has(o)&&(t.add(o),e.push(o));}return e}getAllGateways(){let t=new Set,e=[];for(let r of this.sortedModules)for(let o of r.providers)typeof o=="function"&&i$1(o)!==void 0&&!t.has(o)&&(t.add(o),e.push(o));return e}async callLifecycleHooks(t,e,r){for(let o of this.sortedModules)for(let n of o.providers){let i=typeof n=="function"?n:n.provide;if(t.has(i))try{let a=await t.resolve(i);a&&typeof a=="object"&&typeof a[e]=="function"&&await a[e](r);}catch{}}}resolveModule(t){let e=d(t),r=typeof e=="object"&&"module"in e,o$1=r?e.module:e,n$1=this.resolved.get(o$1);if(n$1)return r&&this.mergeDynamicModule(n$1,t),n$1;let i=n(o$1)??{},a=r?t:{},f=[...i.controllers??[],...a.controllers??[]],p=[...i.providers??[],...a.providers??[]],y=[...i.exports??[],...a.exports??[]],w=p.map(d$1=>d$1&&typeof d$1=="object"&&"forwardRef"in d$1?d(d$1):d$1),O=y.map(d$1=>d$1&&typeof d$1=="object"&&"forwardRef"in d$1?d(d$1):d$1),N={imports:[...i.imports??[],...a.imports??[]],controllers:f,providers:w,exports:O},j={type:o$1,metadata:N,controllers:f,providers:[...f,...w],exports:new Set(O),global:r?t.global??o(o$1):o(o$1)};this.resolved.set(o$1,j);for(let d of N.imports??[])this.resolveModule(d);return j}mergeDynamicModule(t,e){if(e.controllers&&e.controllers.length>0&&(t.controllers.push(...e.controllers),t.providers.push(...e.controllers),t.metadata.controllers=[...t.metadata.controllers??[],...e.controllers]),e.providers&&e.providers.length>0){let r=e.providers.map(o=>o&&typeof o=="object"&&"forwardRef"in o?d(o):o);t.providers.push(...r),t.metadata.providers=[...t.metadata.providers??[],...r];}if(e.exports&&e.exports.length>0){let r=e.exports.map(o=>o&&typeof o=="object"&&"forwardRef"in o?d(o):o);for(let o of r)t.exports.add(o);t.metadata.exports=[...t.metadata.exports??[],...r];}if(e.imports&&e.imports.length>0){t.metadata.imports=[...t.metadata.imports??[],...e.imports];for(let r of e.imports)this.resolveModule(r);}e.global===true&&(t.global=true);}getVisibleTokens(t){let e=new Set;for(let r of t.providers)e.add(this.getProviderToken(r));for(let r of t.metadata.imports??[]){let o=this.getModuleType(r),n=this.resolved.get(o);if(n)for(let i of n.exports)e.add(i);}for(let r of this.sortedModules)if(r.global)for(let o of r.providers)e.add(this.getProviderToken(o));return e}validateExports(){for(let t of this.sortedModules){let e=new Set(t.providers.map(o=>this.getProviderToken(o))),r=this.collectImportedExports(t);for(let o of t.exports)if(!e.has(o)&&!r.has(o)){let n=typeof o=="function"?o.name:String(o);throw new Error(`${t.type.name} exports ${n} but it is not in its providers and is not re-exported from an imported module`)}}}validateVisibility(){for(let t of this.sortedModules){let e=this.getVisibleTokens(t);for(let r of t.providers){if(typeof r!="function")continue;let o=i(r);for(let n of o)if(!e.has(n)){let i=typeof n=="function"?n.name:String(n);throw new Error(`${t.type.name}: ${r.name} depends on ${i}, but it is not provided in this module and not exported by any imported module`)}}}}getProviderToken(t){return typeof t=="function"?t:t.provide}collectImportedExports(t){let e=new Set;for(let r of t.metadata.imports??[]){let o=this.getModuleType(r),n=this.resolved.get(o);if(n)for(let i of n.exports)e.add(i);}return e}findProvider(t,e){return t.providers.find(r=>typeof r=="function"?r===e:r.provide===e)}findReExportedProvider(t,e){for(let r of t.metadata.imports??[]){let o=this.getModuleType(r),n=this.resolved.get(o);if(!n||!n.exports.has(e))continue;let i=this.findProvider(n,e);if(i)return i;let a=this.findReExportedProvider(n,e);if(a)return a}}getModuleType(t){let e=d(t);return typeof e=="object"&&"module"in e?e.module:e}topologicalSort(){let t=new Set,e=new Set,r=[],o=a(n=>{if(t.has(n))return;if(e.has(n))throw new Error(`Circular module dependency detected: ${n.name}`);e.add(n);let i=this.resolved.get(n);if(i){for(let a of i.metadata.imports??[])o(this.getModuleType(a));e.delete(n),t.add(n),r.push(i);}},"visit");for(let[n]of this.resolved)o(n);return r}};function Q(s,t,e,r){var o=arguments.length,n=o<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,e):r,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(s,t,e,r);else for(var a=s.length-1;a>=0;a--)(i=s[a])&&(n=(o<3?i(n):o>3?i(t,e,n):i(t,e))||n);return o>3&&n&&Object.defineProperty(t,e,n),n}a(Q,"_ts_decorate");function k(s,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(s,t)}a(k,"_ts_metadata");var h=class{static{a(this,"EventEmitter2");}handlers=new Map;pending=new Map;onError;constructor(){this.onError=z;}setOptions(t){t.onError&&(this.onError=t.onError);}subscribe(t,e,r){let o=this.handlers.get(t)??[];o.push({instance:r?.instance??{},methodName:r?.methodName??"anonymous",handler:e}),this.handlers.set(t,o);}registerHandler(t,e,r){let o=e[r].bind(e);this.subscribe(t,o,{instance:e,methodName:r});}async emit(t){let e=this.handlers.get(t.type);if(!e||e.length===0)return;let r=this.executeHandlers(e,t);this.pending.set(r,t.type);try{await r;}finally{this.pending.delete(r);}}emitAsync(t){let e=this.handlers.get(t.type);if(!e||e.length===0)return;let r=this.executeHandlers(e,t).then(()=>{this.pending.delete(r);},()=>{this.pending.delete(r);});this.pending.set(r,t.type);}async waitForAllDone(...t){for(;;){let e=this.getPending(t);if(e.length===0)break;await Promise.allSettled(e);}}getPending(t){if(t.length===0)return [...this.pending.keys()];let e=[];for(let[r,o]of this.pending)t.includes(o)&&e.push(r);return e}hasHandlers(t){let e=this.handlers.get(t);return e!==void 0&&e.length>0}handlerCount(t){return this.handlers.get(t)?.length??0}clear(){this.handlers.clear();}async executeHandlers(t,e){let r=await Promise.allSettled(t.map(o=>o.handler(e)));for(let o=0;o<r.length;o++){let n=r[o];if(n.status==="rejected"){let i=t[o],a=`${i.instance.constructor?.name??"Unknown"}.${i.methodName}`;this.onError(n.reason,e.type,a);}}}};h=Q([e(),k("design:type",Function),k("design:paramtypes",[])],h);function z(s,t,e){console.error(`[EventEmitter2] Handler "${e}" failed for event "${t}":`,s);}a(z,"defaultErrorHandler");var P=Symbol("on-event");function Rt(s){return (t,e,r)=>{let o=Reflect.getOwnMetadata(P,t.constructor)??[];o.push({eventType:s,methodName:String(e)}),Reflect.defineMetadata(P,o,t.constructor);}}a(Rt,"OnEvent");function F(s){return Reflect.getOwnMetadata(P,s)??[]}a(F,"getOnEventMetadata");async function Nt(s,t){let e=await s.resolve(h);for(let r of t){let o=q(r);if(!o)continue;let n=F(o);if(n.length===0)continue;let i=typeof r=="function"?r:r.provide,a;try{a=await s.resolve(i);}catch{continue}for(let f of n)typeof a[f.methodName]=="function"&&e.registerHandler(f.eventType,a,f.methodName);}}a(Nt,"scanEventHandlers");function q(s){return typeof s=="function"?h$1(s)?s:null:"useClass"in s?s.useClass:null}a(q,"getProviderClass");export{$ as a,tt as b,et as c,ot as d,rt as e,nt as f,st as g,it as h,at as i,U as j,V as k,ct as l,ft as m,_ as n,h as o,Rt as p,Nt as q};
|