truxie 0.1.0-test.9 → 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 vannguyen799
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # truxie
2
+
3
+ A NestJS-shaped backend core — modules, DI, controllers, guards, interceptors, pipes, filters — that runs **inside whatever HTTP framework you already have**. There is no `truxie.listen()`: an adapter hands the framework's request to the application, and the application answers it.
4
+
5
+ ```
6
+ npm install truxie reflect-metadata
7
+ ```
8
+
9
+ Node 20 or newer — the SDK builds on `globalThis.crypto`, `File` and
10
+ `Headers.getSetCookie()`, none of which exist on Node 18.
11
+
12
+ ```ts
13
+ import 'reflect-metadata'
14
+ import {Module, Controller, Get, Param, Injectable, Inject, TruxieFactory} from 'truxie'
15
+
16
+ @Injectable()
17
+ class UserService {
18
+ find(id: string) { return {id} }
19
+ }
20
+
21
+ @Controller('users')
22
+ @Inject(UserService) // constructor deps, in order
23
+ class UserController {
24
+ constructor(private readonly users: UserService) {}
25
+
26
+ @Get('/:id')
27
+ one(@Param('id') id: string) { return this.users.find(id) }
28
+ }
29
+
30
+ @Module({controllers: [UserController], providers: [UserService]})
31
+ class AppModule {}
32
+
33
+ export const app = await TruxieFactory.create(AppModule)
34
+ ```
35
+
36
+ Then mount it — `@truxie/express`, `@truxie/next`, `@truxie/nitro`, `@truxie/sveltekit` — or drive it yourself with `matchRoute` + `handleRequest`.
37
+
38
+ ## `@Inject` on the class, not just the parameter
39
+
40
+ `design:paramtypes` is emitted by `tsc` and dropped by esbuild/swc, which is what most projects actually build with. So the dependency list is declared explicitly:
41
+
42
+ ```ts
43
+ @Injectable()
44
+ @Inject(UserService, LOGGER_TOKEN) // class form: full list, constructor order
45
+ class Thing {
46
+ constructor(private users: UserService, @Inject(OTHER) private other: Other) {}
47
+ }
48
+ ```
49
+
50
+ Both forms work, and the parameter form wins for the parameter it names.
51
+
52
+ ## The request pipeline
53
+
54
+ One pipeline, in this order, for every adapter:
55
+
56
+ ```
57
+ middlewares → guards → pipes → interceptors → handler → filters
58
+ ```
59
+
60
+ Each layer can be declared globally (on `TruxieFactory.create`) and per route (`@UseMiddleware`, `@RouteGuards`, `@UsePipes`, `@UseInterceptors`, `@UseFilters`). Both sets run: global first, then the route's.
61
+
62
+ ```ts
63
+ const app = await TruxieFactory.create(AppModule, {
64
+ globalGuards: [AuthGuard],
65
+ globalInterceptors: [TimingInterceptor],
66
+ globalFilters: [new HttpErrorFilter()],
67
+ trustProxy: false,
68
+ })
69
+ ```
70
+
71
+ Throwing is how a handler fails: `NotFoundError`, `ValidationError`, `UnauthorizedError`, `ForbiddenError`, `ConflictError`, or any `AppError` with a status. A filter decorated `@Catch(SomeError)` sees only what it declared; an undecorated filter sees everything.
72
+
73
+ ## Application options
74
+
75
+ | Option | Default | What it does |
76
+ |---|---|---|
77
+ | `globalGuards` / `globalInterceptors` / `globalMiddlewares` / `globalPipes` / `globalFilters` | none | Run for every controller route. |
78
+ | `trustProxy` | `isServerless()` | Whether `X-Forwarded-For` / `X-Real-IP` / `CF-Connecting-IP` are believed. Off, the address comes from the connection. Turn it on only behind a proxy that overwrites those headers — otherwise anything keyed on the client address is chosen by the client. |
79
+ | `strictModuleBoundaries` | `false` | Fail at boot when a provider depends on something its module neither provides nor imports. |
80
+ | `eventBus` | — | `onError` for `@OnEvent` handlers. |
81
+
82
+ ## Scopes
83
+
84
+ `Scope.SINGLETON` (default), `Scope.REQUEST` — one instance per request, built in a child container the application disposes when the response is done — and `Scope.TRANSIENT`. A singleton is always built on the container it was registered on, so it can never capture a request-scoped dependency and keep it forever.
85
+
86
+ ## Modules
87
+
88
+ ```ts
89
+ @Global() // exports visible everywhere
90
+ @Module({imports: [], controllers: [], providers: [], exports: []})
91
+ class CoreModule {}
92
+ ```
93
+
94
+ Dynamic modules (`forRoot` / `forRootAsync` / `forFeature`) come from `ConfigurableModuleBuilder`, or write them by hand and use `createAsyncOptionsProviders` for the `useFactory` / `useClass` / `useExisting` triad. `forwardRef(() => X)` closes a genuine circular import.
95
+
96
+ ## Everything else in the box
97
+
98
+ - **Events** — `EventEmitter2` and `@OnEvent('user.created')`, fan-out, error-isolated.
99
+ - **CQRS** (`truxie/cqrs`) — `CommandBus`, `QueryBus`, `EventBus`, `AggregateRoot`, `@CommandHandler`, `@QueryHandler`, `@EventsHandler`.
100
+ - **WebSockets** (`truxie/ws`) — `@WebSocketGateway`, `@SubscribeMessage`, adapter-agnostic peers.
101
+ - **Testing** (`truxie/testing`) — `Test.createTestingModule(...)` with `overrideProvider`, running the same lifecycle the application runs.
102
+ - **Introspection** — `app.getRoutes()`, `@ApiDoc`, `describeRouteInput`, consumed by `@truxie/openapi` and `@truxie/mcp`.
103
+
104
+ ```ts
105
+ const testingModule = await Test.createTestingModule(UserModule)
106
+ .overrideProvider(UserRepository)
107
+ .useValue(mockRepository)
108
+ .compile()
109
+ ```
110
+
111
+ ## Lifecycle
112
+
113
+ `onModuleInit` → `onApplicationBootstrap` → … → `onModuleDestroy` → `onApplicationShutdown`. Each hook runs once per instance, whether the application or the container gets there first.
114
+
115
+ ## The rest of the family
116
+
117
+ `@truxie/express` · `@truxie/next` · `@truxie/nitro` · `@truxie/sveltekit` — HTTP adapters.
118
+ `@truxie/zod` · `@truxie/openapi` · `@truxie/mcp` — validation, documentation, agents.
119
+ `@truxie/jwt` · `@truxie/rbac` · `@truxie/throttle` — authentication, authorization, rate limiting.
120
+ `@truxie/cache` · `@truxie/schedule` · `@truxie/bullmq` · `@truxie/nats` · `@truxie/health` · `@truxie/logger` — the usual infrastructure.
121
+
122
+ MIT.
@@ -0,0 +1 @@
1
+ import {a}from'./chunk-EI7MMDWY.js';import'reflect-metadata';var S=Symbol.for("truxie:ws:gateway"),f=Symbol.for("truxie:ws:message"),d=Symbol.for("truxie:ws:params"),l=Symbol.for("truxie:ws:guards"),x=Symbol.for("truxie:ws:server");function p(e){return n=>{let r=typeof e=="string"?{path:e}:e??{},a={path:r.path??"/",namespace:r.namespace??"/",target:n};Reflect.defineMetadata(S,a,n);}}a(p,"WebSocketGateway");function w(e){return (n,r,a)=>{let s=n.constructor,o=Reflect.getOwnMetadata(f,s)??[];Reflect.defineMetadata(f,[...o,{event:e,methodName:String(r)}],s);}}a(w,"SubscribeMessage");function b(){return (e,n)=>{let r=e.constructor,a=Reflect.getOwnMetadata(x,r)??[];Reflect.defineMetadata(x,[...a,String(n)],r);}}a(b,"WebSocketServer");function i(e,n){return (r,a,s)=>{if(a===void 0)return;let o=r[a];if(typeof o!="function")return;let c=o[d]??[];o[d]=[...c,{type:e,index:s,extractor:n}];}}a(i,"buildWsParamDecorator");var M=a(()=>i("message-body"),"MessageBody"),W=a(()=>i("connected-socket"),"ConnectedSocket"),R=a(()=>i("ws-auth"),"WsAuth");function y(e){return ()=>i("custom",e)}a(y,"createWsParamDecorator");function A(...e){return n=>{Reflect.defineMetadata(l,e,n);}}a(A,"WsGuards");function h(e){return Reflect.getOwnMetadata(S,e)}a(h,"getGatewayMetadata");function k(e){return Reflect.getOwnMetadata(f,e)??[]}a(k,"getMessageHandlers");function _(e){return e[d]??[]}a(_,"getWsParams");function E(e){return Reflect.getOwnMetadata(l,e)??[]}a(E,"getWsGuards");function G(e){return Reflect.getOwnMetadata(x,e)??[]}a(G,"getWsServerProperties");function D(e,n,r,a){if(e.length===0)return [];let s=Math.max(...e.map(c=>c.index)),o=new Array(s+1).fill(void 0);for(let{type:c,index:u,extractor:g}of e)switch(c){case "message-body":o[u]=a;break;case "connected-socket":o[u]=n;break;case "ws-auth":o[u]=n.context.auth;break;case "custom":o[u]=g?g(n,r):void 0;break}return o}a(D,"resolveWsArgs");export{p as a,w as b,b as c,M as d,W as e,R as f,y as g,A as h,h as i,k as j,_ as k,E as l,G as m,D as n};
@@ -0,0 +1 @@
1
+ import {i as i$1}from'./chunk-42ZAPMNO.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 M(i){return $.has(i)?false:($.add(i),true)}a(M,"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,W)}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 ${S(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 ${S(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"&&M(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 x=g instanceof Error?g.message:String(g);throw new Error(`Cannot resolve parameter at index ${d} (${S(h)}) of ${e.name}: ${x}`,{cause:g})}}return new e(...m)}},W=new Set;function S(i){return typeof i=="string"?i:typeof i=="symbol"||i instanceof b?i.toString():typeof i=="function"?i.name:String(i)}a(S,"tokenToString");var L=Symbol.for("truxie:controller:path"),T=Symbol.for("truxie:controller:guards"),O=Symbol.for("truxie:route:metadata"),U=Symbol.for("truxie:method:route"),w=Symbol.for("truxie:method:guards"),P=Symbol.for("truxie:method:noguard");function de(i){return e=>{Reflect.defineMetadata(L,i,e);}}a(de,"Controller");function E(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[U]={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(E,"createMethodDecorator");var le=E("GET"),ue=E("POST"),pe=E("PUT"),he=E("DELETE"),me=E("PATCH");function ge(...i){return (e,t,r)=>{if(t==null){Reflect.defineMetadata(T,i,e);return}if(r!==void 0){if(r?.value){let o=r.value[w]??[];r.value[w]=[...o,...i];}return r}if(typeof e=="function"){let o=e[w]??[];e[w]=[...o,...i];}return typeof e=="function"&&t?.kind==="class"&&Reflect.defineMetadata(T,i,e),e}}a(ge,"RouteGuards");function ve(){return (i,e,t)=>t!==void 0?(t?.value&&(t.value[P]=true),t):(typeof i=="function"&&(i[P]=true),i)}a(ve,"NoGuard");function k(i){return Reflect.getOwnMetadata(L,i)}a(k,"getControllerPath");function ye(i){return Reflect.getOwnMetadata(T,i)??[]}a(ye,"getControllerGuards");function V(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(V,"methodsOf");function Y(i,e){return V(i).get(e)}a(Y,"methodOf");function we(i){let e=[],t=new Set;for(let[r,o]of V(i)){let n=o[U];!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(we,"getRouteMetadata");function Ee(i,e){let t=Y(i,e),r=t!==void 0&&t[P]===true,o=t!==void 0&&t[w]||[];return r?o:[...B(i),...o]}a(Ee,"getMethodGuards");function B(i){for(let e=i;e&&e!==Function.prototype;e=Object.getPrototypeOf(e)){let t=Reflect.getOwnMetadata(T,e);if(t)return t}return []}a(B,"controllerGuardsOf");var Q=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"&&k(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"&&!M(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),x={imports:[...s.imports??[],...a.imports??[]],controllers:f,providers:h,exports:g},N={type:o$1,metadata:x,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 x.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 J(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(J,"_ts_decorate");function z(i,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(i,e)}a(z,"_ts_metadata");var v=class{static{a(this,"EventEmitter2");}handlers=new Map;pending=new Map;onError;constructor(){this.onError=X;}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}})}};v=J([e(),z("design:type",Function),z("design:paramtypes",[])],v);function X(i,e,t){console.error(`[EventEmitter2] Handler "${t}" failed for event "${e}":`,i);}a(X,"defaultErrorHandler");var j=Symbol.for("truxie:on-event");function Ae(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(Ae,"OnEvent");function q(i){return Reflect.getOwnMetadata(j,i)??[]}a(q,"getOnEventMetadata");async function Ue(i,e){let t=await i.resolve(v);for(let r of e){let o=Z(r);if(!o)continue;let n=q(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(Ue,"scanEventHandlers");function Z(i){return typeof i=="function"?h(i)?i:null:"useClass"in i?i.useClass:null}a(Z,"getProviderClass");export{M as a,_ as b,de as c,le as d,ue as e,pe as f,he as g,me as h,ge as i,ve as j,k,ye as l,we as m,Ee as n,Q as o,v as p,Ae as q,Ue as r};
@@ -0,0 +1 @@
1
+ import {a}from'./chunk-EI7MMDWY.js';import'reflect-metadata';var M=(function(e){return e.SINGLETON="singleton",e.REQUEST="request",e.TRANSIENT="transient",e})({}),d=class{static{a(this,"InjectionToken");}description;constructor(t){this.description=t;}toString(){return `InjectionToken(${this.description})`}};function E(e){return {forwardRef:e}}a(E,"forwardRef");function l(e){return typeof e=="object"&&"forwardRef"in e?e.forwardRef():e}a(l,"resolveForwardRef");var R=Symbol.for("truxie:injectable"),s=Symbol.for("truxie:inject:param"),A=Symbol.for("truxie:inject:deps"),p=Symbol.for("truxie:optional");function w(e){return t=>{Reflect.defineMetadata(R,{scope:e?.scope??M.SINGLETON},t);}}a(w,"Injectable");function I(...e){return (t,r,o)=>{if(typeof o=="number"){let a=Reflect.getOwnMetadata(s,t)??new Map;a.set(o,e[0]),Reflect.defineMetadata(s,a,t);}else Reflect.defineMetadata(A,e,t);}}a(I,"Inject");function N(){return (e,t,r)=>{let o=Reflect.getOwnMetadata(p,e)??new Set;o.add(r),Reflect.defineMetadata(p,o,e);}}a(N,"Optional");function D(e){return Reflect.getOwnMetadata(R,e)}a(D,"getInjectableMetadata");function h(e){return (Reflect.getOwnMetadata(A,e)??[]).map(r=>l(r))}a(h,"getClassDeps");function v(e){let t=Reflect.getOwnMetadata(s,e)??new Map,r=new Map;for(let[o,a]of t)r.set(o,l(a));return r}a(v,"getInjectTokens");function P(e){return Reflect.getOwnMetadata(p,e)??new Set}a(P,"getOptionalParams");var x=Symbol.for("truxie:module"),T=Symbol.for("truxie:module:global");function J(e){return t=>{Reflect.defineMetadata(x,e,t);}}a(J,"Module");function B(){return e=>{Reflect.defineMetadata(T,true,e);}}a(B,"Global");function F(e){return Reflect.getOwnMetadata(x,e)}a(F,"getModuleMetadata");function K(e){return Reflect.getOwnMetadata(T,e)===true}a(K,"isGlobalModule");function m(e,t,r,o){var a=arguments.length,i=a<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,r):o,f;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(e,t,r,o);else for(var u=e.length-1;u>=0;u--)(f=e[u])&&(i=(a<3?f(i):a>3?f(t,r,i):f(t,r))||i);return a>3&&i&&Object.defineProperty(t,r,i),i}a(m,"_ts_decorate");var c=class{static{a(this,"DiscoveryService");}container;providers=[];_init(t,r){this.container=t,this.providers=r;}getProviders(){return this.providers}async resolve(t){return this.container.resolve(t)}getProviderClass(t){return typeof t=="function"?t:"useClass"in t?t.useClass:null}};c=m([w()],c);export{M as a,d as b,E as c,l as d,w as e,I as f,N as g,D as h,h as i,v as j,P as k,J as l,B as m,F as n,K as o,c as p};
package/dist/cqrs.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { D as DynamicModule, a as Type } from './types-D-An5cXP.js';
1
+ import { D as DynamicModule, a as Type } from './types-BonRQLDb.js';
2
2
 
3
3
  /**
4
4
  * Enables CQRS with CommandBus, QueryBus, EventBus, and auto-discovered handlers.
package/dist/cqrs.js CHANGED
@@ -1 +1 @@
1
- import {a as a$1}from'./chunk-NXAGO5NO.js';import {b,a as a$2}from'./chunk-XZNMJJJU.js';import {c,d}from'./chunk-N277L4OB.js';import {a}from'./chunk-EI7MMDWY.js';import'reflect-metadata';function A(o,e,t,n){var s=arguments.length,r=s<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(o,e,t,n);else for(var i=o.length-1;i>=0;i--)(c=o[i])&&(r=(s<3?c(r):s>3?c(e,t,r):c(e,t))||r);return s>3&&r&&Object.defineProperty(e,t,r),r}a(A,"_ts_decorate");var f=class{static{a(this,"CommandBus");}handlers=new Map;register(e,t){if(this.handlers.has(e))throw new Error(`Duplicate command handler for ${e.name}. Each command must have exactly one handler.`);this.handlers.set(e,t);}async execute(e){let t=e.constructor,n=this.handlers.get(t);if(!n)throw new Error(`No handler registered for command ${t.name}`);return n.execute(e)}};f=A([c()],f);function H(o,e,t,n){var s=arguments.length,r=s<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(o,e,t,n);else for(var i=o.length-1;i>=0;i--)(c=o[i])&&(r=(s<3?c(r):s>3?c(e,t,r):c(e,t))||r);return s>3&&r&&Object.defineProperty(e,t,r),r}a(H,"_ts_decorate");var l=class{static{a(this,"QueryBus");}handlers=new Map;register(e,t){if(this.handlers.has(e))throw new Error(`Duplicate query handler for ${e.name}. Each query must have exactly one handler.`);this.handlers.set(e,t);}async execute(e){let t=e.constructor,n=this.handlers.get(t);if(!n)throw new Error(`No handler registered for query ${t.name}`);return n.execute(e)}};l=H([c()],l);function D(o,e,t,n){var s=arguments.length,r=s<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(o,e,t,n);else for(var i=o.length-1;i>=0;i--)(c=o[i])&&(r=(s<3?c(r):s>3?c(e,t,r):c(e,t))||r);return s>3&&r&&Object.defineProperty(e,t,r),r}a(D,"_ts_decorate");var u=class{static{a(this,"EventBus");}handlers=new Map;register(e,t){let n=this.handlers.get(e)??[];n.push(t),this.handlers.set(e,n);}async publish(e){let t=e.constructor,n=this.handlers.get(t);if(!n||n.length===0)return;let s=await Promise.allSettled(n.map(r=>r.handle(e)));for(let r of s)r.status==="rejected"&&console.error(`[CQRS EventBus] Handler failed for ${t.name}:`,r.reason);}async publishAll(e){for(let t of e)await this.publish(t);}};u=D([c()],u);var j=Symbol("cqrs:command-handler"),x=Symbol("cqrs:query-handler"),g=Symbol("cqrs:events-handler");function P(o){return e=>{Reflect.defineMetadata(j,o,e);}}a(P,"CommandHandler");function T(o){return e=>{Reflect.defineMetadata(x,o,e);}}a(T,"QueryHandler");function q(...o){return e=>{Reflect.defineMetadata(g,o,e);}}a(q,"EventsHandler");function w(o){return Reflect.getOwnMetadata(j,o)}a(w,"getCommandHandlerMetadata");function O(o){return Reflect.getOwnMetadata(x,o)}a(O,"getQueryHandlerMetadata");function M(o){return Reflect.getOwnMetadata(g,o)}a(M,"getEventsHandlerMetadata");function Q(o,e,t,n){var s=arguments.length,r=s<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(o,e,t,n);else for(var i=o.length-1;i>=0;i--)(c=o[i])&&(r=(s<3?c(r):s>3?c(e,t,r):c(e,t))||r);return s>3&&r&&Object.defineProperty(e,t,r),r}a(Q,"_ts_decorate");function B(o,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,e)}a(B,"_ts_metadata");var m=class{static{a(this,"CqrsExplorer");}discovery;commandBus;queryBus;eventBus;constructor(e,t,n,s){this.discovery=e,this.commandBus=t,this.queryBus=n,this.eventBus=s;}async onApplicationBootstrap(){let e=this.discovery.getProviders();for(let t of e){let n=this.discovery.getProviderClass(t);if(!n)continue;let s=w(n),r=O(n),c=M(n);if(!s&&!r&&!c)continue;let i=typeof t=="function"?t:t.provide,h;try{h=await this.discovery.resolve(i);}catch{continue}if(s&&this.commandBus.register(s,h),r&&this.queryBus.register(r,h),c)for(let _ of c)this.eventBus.register(_,h);}}};m=Q([c(),d(a$1,f,l,u),B("design:type",Function),B("design:paramtypes",[typeof a$1>"u"?Object:a$1,typeof f>"u"?Object:f,typeof l>"u"?Object:l,typeof u>"u"?Object:u])],m);function C(o,e,t,n){var s=arguments.length,r=s<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(o,e,t,n);else for(var i=o.length-1;i>=0;i--)(c=o[i])&&(r=(s<3?c(r):s>3?c(e,t,r):c(e,t))||r);return s>3&&r&&Object.defineProperty(e,t,r),r}a(C,"_ts_decorate");var p=class o{static{a(this,"CqrsModule");}static forRoot(){return {module:o,global:true,providers:[f,l,u,m],exports:[f,l,u]}}};p=C([b(),a$2({})],p);var y=class{static{a(this,"AggregateRoot");}uncommittedEvents=[];apply(e){this.uncommittedEvents.push(e);}getUncommittedEvents(){return [...this.uncommittedEvents]}async commit(e){let t=this.uncommittedEvents;this.uncommittedEvents=[],await e.publishAll(t);}clearEvents(){this.uncommittedEvents=[];}};export{y as AggregateRoot,f as CommandBus,P as CommandHandler,p as CqrsModule,u as EventBus,q as EventsHandler,l as QueryBus,T as QueryHandler};
1
+ import {e,f as f$1,p as p$1,m as m$1,l as l$1}from'./chunk-TSJZVSHP.js';import {a}from'./chunk-EI7MMDWY.js';import'reflect-metadata';function A(o,e,t,n){var s=arguments.length,r=s<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(o,e,t,n);else for(var i=o.length-1;i>=0;i--)(c=o[i])&&(r=(s<3?c(r):s>3?c(e,t,r):c(e,t))||r);return s>3&&r&&Object.defineProperty(e,t,r),r}a(A,"_ts_decorate");var f=class{static{a(this,"CommandBus");}handlers=new Map;register(e,t){if(this.handlers.has(e))throw new Error(`Duplicate command handler for ${e.name}. Each command must have exactly one handler.`);this.handlers.set(e,t);}async execute(e){let t=e.constructor,n=this.handlers.get(t);if(!n)throw new Error(`No handler registered for command ${t.name}`);return n.execute(e)}};f=A([e()],f);function H(o,e,t,n){var s=arguments.length,r=s<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(o,e,t,n);else for(var i=o.length-1;i>=0;i--)(c=o[i])&&(r=(s<3?c(r):s>3?c(e,t,r):c(e,t))||r);return s>3&&r&&Object.defineProperty(e,t,r),r}a(H,"_ts_decorate");var l=class{static{a(this,"QueryBus");}handlers=new Map;register(e,t){if(this.handlers.has(e))throw new Error(`Duplicate query handler for ${e.name}. Each query must have exactly one handler.`);this.handlers.set(e,t);}async execute(e){let t=e.constructor,n=this.handlers.get(t);if(!n)throw new Error(`No handler registered for query ${t.name}`);return n.execute(e)}};l=H([e()],l);function D(o,e,t,n){var s=arguments.length,r=s<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(o,e,t,n);else for(var i=o.length-1;i>=0;i--)(c=o[i])&&(r=(s<3?c(r):s>3?c(e,t,r):c(e,t))||r);return s>3&&r&&Object.defineProperty(e,t,r),r}a(D,"_ts_decorate");var u=class{static{a(this,"EventBus");}handlers=new Map;register(e,t){let n=this.handlers.get(e)??[];n.push(t),this.handlers.set(e,n);}async publish(e){let t=e.constructor,n=this.handlers.get(t);if(!n||n.length===0)return;let s=await Promise.allSettled(n.map(r=>r.handle(e)));for(let r of s)r.status==="rejected"&&console.error(`[CQRS EventBus] Handler failed for ${t.name}:`,r.reason);}async publishAll(e){for(let t of e)await this.publish(t);}};u=D([e()],u);var x=Symbol.for("truxie:cqrs:command-handler"),j=Symbol.for("truxie:cqrs:query-handler"),g=Symbol.for("truxie:cqrs:events-handler");function P(o){return e=>{Reflect.defineMetadata(x,o,e);}}a(P,"CommandHandler");function T(o){return e=>{Reflect.defineMetadata(j,o,e);}}a(T,"QueryHandler");function q(...o){return e=>{Reflect.defineMetadata(g,o,e);}}a(q,"EventsHandler");function w(o){return Reflect.getOwnMetadata(x,o)}a(w,"getCommandHandlerMetadata");function O(o){return Reflect.getOwnMetadata(j,o)}a(O,"getQueryHandlerMetadata");function M(o){return Reflect.getOwnMetadata(g,o)}a(M,"getEventsHandlerMetadata");function Q(o,e,t,n){var s=arguments.length,r=s<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(o,e,t,n);else for(var i=o.length-1;i>=0;i--)(c=o[i])&&(r=(s<3?c(r):s>3?c(e,t,r):c(e,t))||r);return s>3&&r&&Object.defineProperty(e,t,r),r}a(Q,"_ts_decorate");function B(o,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,e)}a(B,"_ts_metadata");var m=class{static{a(this,"CqrsExplorer");}discovery;commandBus;queryBus;eventBus;constructor(e,t,n,s){this.discovery=e,this.commandBus=t,this.queryBus=n,this.eventBus=s;}async onApplicationBootstrap(){let e=this.discovery.getProviders();for(let t of e){let n=this.discovery.getProviderClass(t);if(!n)continue;let s=w(n),r=O(n),c=M(n);if(!s&&!r&&!c)continue;let i=typeof t=="function"?t:t.provide,h;try{h=await this.discovery.resolve(i);}catch{continue}if(s&&this.commandBus.register(s,h),r&&this.queryBus.register(r,h),c)for(let _ of c)this.eventBus.register(_,h);}}};m=Q([e(),f$1(p$1,f,l,u),B("design:type",Function),B("design:paramtypes",[typeof p$1>"u"?Object:p$1,typeof f>"u"?Object:f,typeof l>"u"?Object:l,typeof u>"u"?Object:u])],m);function C(o,e,t,n){var s=arguments.length,r=s<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(o,e,t,n);else for(var i=o.length-1;i>=0;i--)(c=o[i])&&(r=(s<3?c(r):s>3?c(e,t,r):c(e,t))||r);return s>3&&r&&Object.defineProperty(e,t,r),r}a(C,"_ts_decorate");var p=class o{static{a(this,"CqrsModule");}static forRoot(){return {module:o,global:true,providers:[f,l,u,m],exports:[f,l,u]}}};p=C([m$1(),l$1({})],p);var y=class{static{a(this,"AggregateRoot");}uncommittedEvents=[];apply(e){this.uncommittedEvents.push(e);}getUncommittedEvents(){return [...this.uncommittedEvents]}async commit(e){let t=this.uncommittedEvents;this.uncommittedEvents=[],await e.publishAll(t);}clearEvents(){this.uncommittedEvents=[];}};export{y as AggregateRoot,f as CommandBus,P as CommandHandler,p as CqrsModule,u as EventBus,q as EventsHandler,l as QueryBus,T as QueryHandler};
@@ -0,0 +1,178 @@
1
+ import { P as Provider, T as Token } from './types-BonRQLDb.js';
2
+
3
+ declare class Container {
4
+ private registrations;
5
+ private parent;
6
+ private children;
7
+ register(...providers: Provider[]): void;
8
+ private registerOne;
9
+ resolve<T>(token: Token<T>): Promise<T>;
10
+ /**
11
+ * @param path the tokens already being built ABOVE this one, in this
12
+ * resolution chain. Cycles are detected against it rather than against a
13
+ * per-container flag: a shared flag cannot tell "A needs A" from "two
14
+ * requests happened to need A at the same moment", and reported the second
15
+ * as a circular dependency that was never there.
16
+ */
17
+ private resolveInternal;
18
+ has(token: Token): boolean;
19
+ /** Returns true if any registered provider uses Scope.REQUEST. */
20
+ hasRequestScoped(): boolean;
21
+ /** The container that actually holds the registration, or null. */
22
+ private findOwner;
23
+ createChild(): Container;
24
+ dispose(): Promise<void>;
25
+ private createInstance;
26
+ private instantiateClass;
27
+ }
28
+
29
+ /**
30
+ * Base class for all domain events.
31
+ *
32
+ * Events carry an immutable `type` string and a `payload`.
33
+ * The `type` is used for routing to @OnEvent() handlers.
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * class ProjectCreatedEvent extends DomainEvent<{
38
+ * userId: string
39
+ * projectId: string
40
+ * }> {
41
+ * readonly type = 'project.created'
42
+ * }
43
+ *
44
+ * const event = new ProjectCreatedEvent({
45
+ * userId: '123',
46
+ * projectId: '456',
47
+ * })
48
+ * ```
49
+ */
50
+ declare abstract class DomainEvent<TPayload = unknown> {
51
+ readonly payload: TPayload;
52
+ abstract readonly type: string;
53
+ readonly timestamp: number;
54
+ constructor(payload: TPayload);
55
+ }
56
+ interface EventHandler {
57
+ (event: DomainEvent): unknown | Promise<unknown>;
58
+ }
59
+ interface EventBusOptions {
60
+ /** Called when an event handler throws. Defaults to console.error. */
61
+ onError?: (error: unknown, eventType: string, handlerName: string) => void;
62
+ }
63
+ /**
64
+ * Per-handler outcome returned by `emitAsync()` — mirrors NestJS / eventemitter2
65
+ * convention where `emitAsync` resolves to the array of handler return values.
66
+ *
67
+ * Each row identifies the handler (`{ClassName}.{methodName}`) and reports
68
+ * either the resolved value or the error message for grep-by-listener log
69
+ * search downstream.
70
+ */
71
+ interface HandlerOutcome {
72
+ /** `${ClassName}.${methodName}` — same shape used by `onError`. */
73
+ name: string;
74
+ status: 'success' | 'failed';
75
+ /** Handler return value (when fulfilled). */
76
+ value?: unknown;
77
+ /** Error message when rejected. */
78
+ error?: string;
79
+ /** Wall-clock duration of the handler in milliseconds. */
80
+ durationMs: number;
81
+ }
82
+
83
+ /**
84
+ * In-process async EventEmitter2.
85
+ *
86
+ * - Handlers are fire-and-forget: errors are caught and reported, never propagated
87
+ * - Multiple handlers can subscribe to the same event type (fan-out)
88
+ * - Handlers run concurrently via Promise.allSettled
89
+ * - Replaces manual `.catch(() => {})` patterns
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * // Emit from a UseCase
94
+ * this.eventBus.emit(new ProjectCreatedEvent({ userId, projectId }))
95
+ *
96
+ * // Subscribe programmatically (auto-done by @OnEvent scanner)
97
+ * eventBus.subscribe('project.created', async (event) => {
98
+ * await logService.create({ ... })
99
+ * })
100
+ * ```
101
+ */
102
+ declare class EventEmitter2 {
103
+ private handlers;
104
+ private pending;
105
+ private onError;
106
+ constructor();
107
+ setOptions(options: EventBusOptions): void;
108
+ /**
109
+ * Register an event handler for a specific event type.
110
+ */
111
+ subscribe(eventType: string, handler: EventHandler, meta?: {
112
+ instance?: object;
113
+ methodName?: string;
114
+ }): void;
115
+ /**
116
+ * Register an instance method as a handler (used by module scanner).
117
+ */
118
+ registerHandler(eventType: string, instance: object, methodName: string): void;
119
+ /**
120
+ * Emit a domain event and await all handlers.
121
+ *
122
+ * All subscribed handlers execute concurrently. Errors are caught per-handler
123
+ * and reported via the `onError` callback. The emit call itself never throws.
124
+ *
125
+ * Returns `void` — when you need the handler return values, use
126
+ * {@link emitAsync} instead (mirrors NestJS / eventemitter2 convention).
127
+ */
128
+ emit(event: DomainEvent): Promise<void>;
129
+ /**
130
+ * Emit a domain event and resolve to an array of per-handler outcomes —
131
+ * matches the NestJS / eventemitter2 `emitAsync` convention.
132
+ *
133
+ * If the caller does not `await` the returned promise the call is still
134
+ * fire-and-forget: handlers run, the tracked promise is kept in the internal
135
+ * `pending` set, and `waitForAllDone()` can still synchronize on it.
136
+ *
137
+ * Errors thrown by individual handlers are surfaced on the result row
138
+ * (`status: 'failed'`) and additionally reported via the `onError` callback —
139
+ * the returned promise itself never rejects.
140
+ */
141
+ emitAsync(event: DomainEvent): Promise<HandlerOutcome[]>;
142
+ /**
143
+ * Wait for in-flight emissions to complete.
144
+ *
145
+ * @param eventTypes — if provided, only wait for emissions matching these event types.
146
+ * Otherwise, wait for all pending emissions.
147
+ *
148
+ * Handles re-entrant emissions: if a handler emits another event during execution,
149
+ * this method loops until the matching pending set is fully drained.
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * // Wait for everything:
154
+ * await eventEmitter.waitForAllDone()
155
+ *
156
+ * // Wait for specific event types:
157
+ * await eventEmitter.waitForAllDone('order.completed')
158
+ * await eventEmitter.waitForAllDone('order.completed', 'email.sent')
159
+ * ```
160
+ */
161
+ waitForAllDone(...eventTypes: string[]): Promise<void>;
162
+ private getPending;
163
+ /**
164
+ * Check if any handlers are registered for an event type.
165
+ */
166
+ hasHandlers(eventType: string): boolean;
167
+ /**
168
+ * Get count of registered handlers for an event type.
169
+ */
170
+ handlerCount(eventType: string): number;
171
+ /**
172
+ * Remove all handlers (used during shutdown).
173
+ */
174
+ clear(): void;
175
+ private executeHandlers;
176
+ }
177
+
178
+ export { Container as C, DomainEvent as D, type EventBusOptions as E, EventEmitter2 as a, type EventHandler as b };