truxie 0.1.0-test.8 → 0.1.0-test.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-MXBVL723.js +1 -0
- package/dist/cqrs.d.ts +5 -5
- package/dist/cqrs.js +1 -1
- package/dist/{event-bus-BQ4piYUx.d.ts → event-bus-C58NcKP1.d.ts} +3 -3
- package/dist/index.d.ts +5 -5
- package/dist/index.js +2 -2
- package/dist/testing.d.ts +3 -3
- package/dist/testing.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-LUBJE4B3.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {i as i$1}from'./chunk-RLQ7JJW6.js';import {c,d}from'./chunk-XZNMJJJU.js';import {f,a as a$1,g,h as h$1,i,b,c as c$1}from'./chunk-N277L4OB.js';import {a}from'./chunk-EI7MMDWY.js';import'reflect-metadata';function V(s){return {forwardRef:s}}a(V,"forwardRef");function G(s){return typeof s=="object"&&"forwardRef"in s?s.forwardRef():s}a(G,"resolveForwardRef");var j=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){if(typeof t=="function"){let r=f(t)?.scope??a$1.SINGLETON;this.registrations.set(t,{provider:t,scope:r});return}let e=t.provide,n=a$1.SINGLETON;if("useClass"in t){let o=f(t.useClass);n=t.scope??o?.scope??a$1.SINGLETON;}else "useFactory"in t&&(n=t.scope??a$1.SINGLETON);this.registrations.set(e,{provider:t,scope:n});}async resolve(t){let e=G(t),n=e!==t?e:t,o=this.registrations.get(n)??this.parent?.findRegistration(n);if(!o)throw new Error(`No provider found for ${y(n)}`);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(n))throw new Error(`Circular dependency detected for ${y(n)}`);this.resolving.add(n);try{let r=await this.createInstance(o);return (o.scope===a$1.SINGLETON||o.scope===a$1.REQUEST&&this.parent!==null)&&(o.instance=r),r}finally{this.resolving.delete(n);}}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,n]of this.registrations)n.scope===a$1.REQUEST&&t.registrations.set(e,{provider:n.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 n=e,o=[];if(n.inject)for(let r of n.inject)o.push(await this.resolve(r));return n.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)??[],n=g(t),o=h$1(t),r=i(t),i$1=o.size>0?Math.max(...o.keys())+1:0,a=Math.max(e.length,i$1,n.length),f=[];for(let l=0;l<a;l++){let R=o.get(l)??n[l]??e[l],_=r.has(l);try{f.push(await this.resolve(R));}catch{if(_)f.push(void 0);else throw new Error(`Cannot resolve parameter at index ${l} (${y(R)}) of ${t.name}`)}}return new t(...f)}};function y(s){return typeof s=="string"?s:typeof s=="symbol"||s instanceof b?s.toString():typeof s=="function"?s.name:String(s)}a(y,"tokenToString");var I=Symbol("controller:path"),E=Symbol("controller:guards"),w=Symbol("route:metadata"),M=Symbol("method:route"),h=Symbol("method:guards"),x=Symbol("method:noguard");function K(s){return t=>{Reflect.defineMetadata(I,s,t);}}a(K,"Controller");function m(s){return (t="")=>(e,n,o)=>{let r=o!==void 0,i=String(r?n:n?.name??n),a=r?o?.value:e;if(typeof a=="function"&&(a[M]={method:s,path:t,methodName:i}),r){let f=Reflect.getOwnMetadata(w,e.constructor)??[];return f.push({method:s,path:t,methodName:i}),Reflect.defineMetadata(w,f,e.constructor),o}return e}}a(m,"createMethodDecorator");var tt=m("GET"),et=m("POST"),ot=m("PUT"),nt=m("DELETE"),rt=m("PATCH");function st(...s){return (t,e,n)=>{if(e==null){Reflect.defineMetadata(E,s,t);return}if(n!==void 0){if(n?.value){let o=n.value[h]??[];n.value[h]=[...o,...s];}return n}if(typeof t=="function"){let o=t[h]??[];t[h]=[...o,...s];}return typeof t=="function"&&e?.kind==="class"&&Reflect.defineMetadata(E,s,t),t}}a(st,"RouteGuards");function it(){return (s,t,e)=>e!==void 0?(e?.value&&(e.value[x]=true),e):(typeof s=="function"&&(s[x]=true),s)}a(it,"NoGuard");function A(s){return Reflect.getOwnMetadata(I,s)}a(A,"getControllerPath");function H(s){return Reflect.getOwnMetadata(E,s)??[]}a(H,"getControllerGuards");function at(s){let t=[],e=s.prototype;if(e){let n=Object.getOwnPropertyNames(e);for(let o of n){if(o==="constructor")continue;let r=e[o];typeof r=="function"&&r[M]&&t.push(r[M]);}}return t.length>0?t:Reflect.getOwnMetadata(w,s)??[]}a(at,"getRouteMetadata");function ct(s,t){let n=s.prototype?.[t],o=typeof n=="function"&&n[x]===true,r=typeof n=="function"&&n[h]||[];return o?r:[...H(s),...r]}a(ct,"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 n of this.sortedModules)if(n.global)for(let o of n.providers)e.add(o);e.size>0&&t.register(...e);for(let n of this.sortedModules){t.register(...n.providers);for(let o of n.metadata.imports??[]){let r=this.getModuleType(o),i=this.resolved.get(r);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 n of this.sortedModules){for(let o of n.controllers)t.has(o)||(t.add(o),e.push(o));for(let o of n.metadata.providers??[])typeof o=="function"&&A(o)!==void 0&&!t.has(o)&&(t.add(o),e.push(o));}return e}getAllGateways(){let t=new Set,e=[];for(let n of this.sortedModules)for(let o of n.providers)typeof o=="function"&&i$1(o)!==void 0&&!t.has(o)&&(t.add(o),e.push(o));return e}async callLifecycleHooks(t,e,n){for(let o of this.sortedModules)for(let r of o.providers){let i=typeof r=="function"?r:r.provide;if(t.has(i))try{let a=await t.resolve(i);a&&typeof a=="object"&&typeof a[e]=="function"&&await a[e](n);}catch{}}}resolveModule(t){let e=typeof t=="object"&&"module"in t,n=e?t.module:t;if(this.resolved.has(n))return this.resolved.get(n);let o=c(n)??{},r=e?t:{},i=[...o.controllers??[],...r.controllers??[]],a={imports:[...o.imports??[],...r.imports??[]],controllers:i,providers:[...o.providers??[],...r.providers??[]],exports:[...o.exports??[],...r.exports??[]]},f={type:n,metadata:a,controllers:i,providers:[...i,...a.providers??[]],exports:new Set(a.exports??[]),global:e?t.global??d(n):d(n)};this.resolved.set(n,f);for(let l of a.imports??[])this.resolveModule(l);return f}getVisibleTokens(t){let e=new Set;for(let n of t.providers)e.add(this.getProviderToken(n));for(let n of t.metadata.imports??[]){let o=this.getModuleType(n),r=this.resolved.get(o);if(r)for(let i of r.exports)e.add(i);}for(let n of this.sortedModules)if(n.global)for(let o of n.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))),n=this.collectImportedExports(t);for(let o of t.exports)if(!e.has(o)&&!n.has(o)){let r=typeof o=="function"?o.name:String(o);throw new Error(`${t.type.name} exports ${r} 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 n of t.providers){if(typeof n!="function")continue;let o=g(n);for(let r of o)if(!e.has(r)){let i=typeof r=="function"?r.name:String(r);throw new Error(`${t.type.name}: ${n.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 n of t.metadata.imports??[]){let o=this.getModuleType(n),r=this.resolved.get(o);if(r)for(let i of r.exports)e.add(i);}return e}findProvider(t,e){return t.providers.find(n=>typeof n=="function"?n===e:n.provide===e)}findReExportedProvider(t,e){for(let n of t.metadata.imports??[]){let o=this.getModuleType(n),r=this.resolved.get(o);if(!r||!r.exports.has(e))continue;let i=this.findProvider(r,e);if(i)return i;let a=this.findReExportedProvider(r,e);if(a)return a}}getModuleType(t){return typeof t=="object"&&"module"in t?t.module:t}topologicalSort(){let t=new Set,e=new Set,n=[],o=a(r=>{if(t.has(r))return;if(e.has(r))throw new Error(`Circular module dependency detected: ${r.name}`);e.add(r);let i=this.resolved.get(r);if(i){for(let a of i.metadata.imports??[])o(this.getModuleType(a));e.delete(r),t.add(r),n.push(i);}},"visit");for(let[r]of this.resolved)o(r);return n}};function D(s,t,e,n){var o=arguments.length,r=o<3?t:n===null?n=Object.getOwnPropertyDescriptor(t,e):n,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,t,e,n);else for(var a=s.length-1;a>=0;a--)(i=s[a])&&(r=(o<3?i(r):o>3?i(t,e,r):i(t,e))||r);return o>3&&r&&Object.defineProperty(t,e,r),r}a(D,"_ts_decorate");function L(s,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(s,t)}a(L,"_ts_metadata");var u=class{static{a(this,"EventEmitter2");}handlers=new Map;onError;constructor(){this.onError=k;}setOptions(t){t.onError&&(this.onError=t.onError);}subscribe(t,e,n){let o=this.handlers.get(t)??[];o.push({instance:n?.instance??{},methodName:n?.methodName??"anonymous",handler:e}),this.handlers.set(t,o);}registerHandler(t,e,n){let o=e[n].bind(e);this.subscribe(t,o,{instance:e,methodName:n});}async emit(t){let e=this.handlers.get(t.type);if(!e||e.length===0)return;let n=await Promise.allSettled(e.map(o=>o.handler(t)));for(let o=0;o<n.length;o++){let r=n[o];if(r.status==="rejected"){let i=e[o],a=`${i.instance.constructor?.name??"Unknown"}.${i.methodName}`;this.onError(r.reason,t.type,a);}}}emitAsync(t){this.emit(t).catch(()=>{});}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();}};u=D([c$1(),L("design:type",Function),L("design:paramtypes",[])],u);function k(s,t,e){console.error(`[EventEmitter2] Handler "${e}" failed for event "${t}":`,s);}a(k,"defaultErrorHandler");var T=Symbol("on-event");function Mt(s){return (t,e,n)=>{let o=Reflect.getOwnMetadata(T,t.constructor)??[];o.push({eventType:s,methodName:String(e)}),Reflect.defineMetadata(T,o,t.constructor);}}a(Mt,"OnEvent");function U(s){return Reflect.getOwnMetadata(T,s)??[]}a(U,"getOnEventMetadata");async function Nt(s,t){let e=await s.resolve(u);for(let n of t){let o=F(n);if(!o)continue;let r=U(o);if(r.length===0)continue;let i=typeof n=="function"?n:n.provide,a;try{a=await s.resolve(i);}catch{continue}for(let f of r)typeof a[f.methodName]=="function"&&e.registerHandler(f.eventType,a,f.methodName);}}a(Nt,"scanEventHandlers");function F(s){return typeof s=="function"?f(s)?s:null:"useClass"in s?s.useClass:null}a(F,"getProviderClass");export{V as a,G as b,j as c,K as d,tt as e,et as f,ot as g,nt as h,rt as i,st as j,it as k,A as l,H as m,at as n,ct as o,$ as p,u as q,Mt as r,Nt as s};
|
package/dist/cqrs.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { D as DynamicModule, a as Type } from './types-D-An5cXP.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Enables CQRS with CommandBus, QueryBus,
|
|
4
|
+
* Enables CQRS with CommandBus, QueryBus, EventBus, and auto-discovered handlers.
|
|
5
5
|
*
|
|
6
6
|
* Import with `CqrsModule.forRoot()` in your root module.
|
|
7
7
|
*
|
|
8
8
|
* **Three buses, three purposes:**
|
|
9
9
|
* - `CommandBus` — dispatches commands to `@CommandHandler` (1:1 mapping)
|
|
10
10
|
* - `QueryBus` — dispatches queries to `@QueryHandler` (1:1 mapping)
|
|
11
|
-
* - `
|
|
11
|
+
* - `EventBus` — publishes domain events to `@EventsHandler` (1:N fan-out)
|
|
12
12
|
*
|
|
13
13
|
* **vs core EventBus:**
|
|
14
14
|
* - Core `EventBus` (`@OnEvent('string')`) — string-based, fire-and-forget app events
|
|
15
|
-
* - CQRS `
|
|
15
|
+
* - CQRS `EventBus` (`@EventsHandler(Class)`) — class-based domain events
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* ```typescript
|
|
@@ -126,7 +126,7 @@ declare class QueryBus {
|
|
|
126
126
|
* ])
|
|
127
127
|
* ```
|
|
128
128
|
*/
|
|
129
|
-
declare class
|
|
129
|
+
declare class EventBus {
|
|
130
130
|
private handlers;
|
|
131
131
|
/** @internal — called by CqrsExplorer during bootstrap. */
|
|
132
132
|
register(eventClass: Type, handler: IEventHandler): void;
|
|
@@ -258,4 +258,4 @@ declare function QueryHandler(query: Type): ClassDecorator;
|
|
|
258
258
|
*/
|
|
259
259
|
declare function EventsHandler(...events: Type[]): ClassDecorator;
|
|
260
260
|
|
|
261
|
-
export { AggregateRoot, CommandBus, CommandHandler,
|
|
261
|
+
export { AggregateRoot, CommandBus, CommandHandler, CqrsModule, EventBus, EventsHandler, type ICommand, type ICommandHandler, type IEvent, type IEventHandler, type IQuery, type IQueryHandler, QueryBus, QueryHandler };
|
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,"
|
|
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};
|
|
@@ -34,7 +34,7 @@ interface EventBusOptions {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
* In-process async
|
|
37
|
+
* In-process async EventEmitter2.
|
|
38
38
|
*
|
|
39
39
|
* - Handlers are fire-and-forget: errors are caught and reported, never propagated
|
|
40
40
|
* - Multiple handlers can subscribe to the same event type (fan-out)
|
|
@@ -52,7 +52,7 @@ interface EventBusOptions {
|
|
|
52
52
|
* })
|
|
53
53
|
* ```
|
|
54
54
|
*/
|
|
55
|
-
declare class
|
|
55
|
+
declare class EventEmitter2 {
|
|
56
56
|
private handlers;
|
|
57
57
|
private onError;
|
|
58
58
|
constructor();
|
|
@@ -94,4 +94,4 @@ declare class EventBus {
|
|
|
94
94
|
clear(): void;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
export { DomainEvent as D, type EventBusOptions as E,
|
|
97
|
+
export { DomainEvent as D, type EventBusOptions as E, EventEmitter2 as a, type EventHandler as b };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ export { C as ClassProvider, E as ExistingProvider, d as FactoryProvider, e as M
|
|
|
4
4
|
import { E as ExecutionContext, I as ICanActivateGuard } from './interfaces-zvtMSS9r.js';
|
|
5
5
|
export { B as BaseExecutionContext, F as FormDataPart } from './interfaces-zvtMSS9r.js';
|
|
6
6
|
import { ZodSchema } from 'zod';
|
|
7
|
-
import { E as EventBusOptions, a as
|
|
8
|
-
export { D as DomainEvent, b as EventHandler } from './event-bus-
|
|
7
|
+
import { E as EventBusOptions, a as EventEmitter2 } from './event-bus-C58NcKP1.js';
|
|
8
|
+
export { D as DomainEvent, b as EventHandler } from './event-bus-C58NcKP1.js';
|
|
9
9
|
import { W as WsPeer, a as WsMessage } from './types-G2NQp5Jb.js';
|
|
10
10
|
|
|
11
11
|
declare function Injectable(options?: InjectableOptions): ClassDecorator;
|
|
@@ -949,7 +949,7 @@ declare class TruxieApplication {
|
|
|
949
949
|
private initialized;
|
|
950
950
|
private readonly rootModule;
|
|
951
951
|
private readonly options;
|
|
952
|
-
private
|
|
952
|
+
private eventEmitter;
|
|
953
953
|
private prefix;
|
|
954
954
|
private router;
|
|
955
955
|
private filters;
|
|
@@ -998,7 +998,7 @@ declare class TruxieApplication {
|
|
|
998
998
|
getControllers(): Type[];
|
|
999
999
|
getGateways(): Type[];
|
|
1000
1000
|
getProviders(): Provider[];
|
|
1001
|
-
|
|
1001
|
+
getEventEmitter(): EventEmitter2;
|
|
1002
1002
|
getRouter(): ControllerRouter;
|
|
1003
1003
|
createHandler(options: Omit<CreatePipelineOptions, 'handler'> & {
|
|
1004
1004
|
handler: HandlerFn;
|
|
@@ -1014,4 +1014,4 @@ declare class TruxieFactory {
|
|
|
1014
1014
|
static create(rootModule: Type | DynamicModule, options?: ApplicationOptions): Promise<TruxieApplication>;
|
|
1015
1015
|
}
|
|
1016
1016
|
|
|
1017
|
-
export { AppError, type ApplicationOptions, Auth, type AuthExtractorFn, Body, Catch, type CompiledRoute, ConfigurableModuleBuilder, type ConfigurableModuleBuilderResult, type ConfigurableModuleClass, ConflictError, Container, Controller, ControllerRouter, Cookie, type CreatePipelineOptions, DefaultValuePipe, Delete, DiscoveryService, DynamicModule,
|
|
1017
|
+
export { AppError, type ApplicationOptions, Auth, type AuthExtractorFn, Body, Catch, type CompiledRoute, ConfigurableModuleBuilder, type ConfigurableModuleBuilderResult, type ConfigurableModuleClass, ConflictError, Container, Controller, ControllerRouter, Cookie, type CreatePipelineOptions, DefaultValuePipe, Delete, DiscoveryService, DynamicModule, EventBusOptions, EventEmitter2, type ExceptionFilter, ExecutionContext, type ExtraOptions, type FeatureConfig, type FilterRef, ForbiddenError, FormData, ForwardRef, Get, Global, type GuardClass, type GuardInstance, type GuardRef, type HandlerFn, Headers, type HttpDispatchResult, type HttpMethod, ICanActivateGuard, type IUseCase, Inject, Injectable, InjectableOptions, type Interceptor, type InterceptorRef, Ip, type Middleware, type MiddlewareRef, Module, ModuleAsyncOptions, ModuleMetadata, ModuleRegistry, NoGuard, NotFoundError, type OnApplicationBootstrap, type OnApplicationShutdown, OnEvent, type OnModuleDestroy, type OnModuleInit, Optional, Param, type ParamPipe, type ParamPipeRef, ParseIdPipe, ParseIntPipe, Patch, type PipeRef, type PipeTransform, type PipelineOptions, Post, Provider, Put, Query, REDIRECT_BRAND, RawBody, type RedirectResult, RequestAbortedError, RouteGuards, type RouteMatch, type RouteMetadata, type RouteParamMetadata, type RouteParamType, Serialize, SerializeInterceptor, Token, TruxieApplication, TruxieFactory, Type, UOW_INSTANCE_KEY, UOW_SESSION_KEY, UnauthorizedError, type UnitOfWork, type UnitOfWorkFactory, UnitOfWorkInterceptor, UseFilters, UseInterceptors, UseMiddleware, UsePipes, UserAgent, ValidationError, type WsHooks, type WsHooksAdapters, ZodParamPipe, ZodValidatedBody, ZodValidatedParams, ZodValidatedQuery, ZodValidationPipe, createParamDecorator, createPipeline, defineAuth, forwardRef, getControllerGuards, getControllerPath, getEffectiveInterceptors, getEffectiveMiddlewares, getInterceptorsMetadata, getMethodGuards, getMethodInterceptors, getMethodMiddlewares, getMiddlewaresMetadata, getModuleMetadata, getRouteMetadata, getRouteParams, getSerializeSchema, isGlobalModule, isRedirect, redirect, resolveForwardRef, resolveParamArgs };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {l,n,o,c as c$1,p,q as q$1,s}from'./chunk-LUBJE4B3.js';export{c as Container,d as Controller,h as Delete,q as EventBus,e as Get,p as ModuleRegistry,k as NoGuard,r as OnEvent,i as Patch,f as Post,g as Put,j as RouteGuards,a as forwardRef,m as getControllerGuards,l as getControllerPath,o as getMethodGuards,n as getRouteMetadata,b as resolveForwardRef}from'./chunk-LUBJE4B3.js';import {n as n$1,i,j as j$1,k as k$1,m}from'./chunk-RLQ7JJW6.js';import {a as a$1}from'./chunk-NXAGO5NO.js';export{a as DiscoveryService}from'./chunk-NXAGO5NO.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';export{b as Global,a as Module,c as getModuleMetadata,d as isGlobalModule}from'./chunk-XZNMJJJU.js';import {b as b$1}from'./chunk-N277L4OB.js';export{d as Inject,c as Injectable,e as Optional,a as Scope}from'./chunk-N277L4OB.js';import {a}from'./chunk-EI7MMDWY.js';import'reflect-metadata';function mt(o,e){if("useFactory"in e&&e.useFactory){let r=e.useFactory;return [{provide:o,useFactory:r,inject:e.inject??[]}]}if("useClass"in e&&e.useClass){let r=e.useClass;return [{provide:o,useFactory:a(async t=>t.createModuleOptions(),"useFactory"),inject:[r]},r]}if("useExisting"in e&&e.useExisting){let r=e.useExisting;return [{provide:o,useFactory:a(async t=>t.createModuleOptions(),"useFactory"),inject:[r]}]}throw new Error("ModuleAsyncOptions must specify one of: useFactory, useClass, or useExisting")}a(mt,"createAsyncProviders");var _=class{static{a(this,"ConfigurableModuleBuilder");}description;featureDescription;onForRoot;onForFeature;constructor(e="MODULE_OPTIONS"){this.description=e,this.featureDescription=e+"_FEATURE";}setTokenDescription(e){return this.description=e,this}transformDynamicModule(e){return this.onForRoot=e,this}transformFeatureModule(e){return this.onForFeature=e,this}build(){let e=new b$1(this.description),r=new b$1(this.featureDescription),t=this.onForRoot,n=this.onForFeature;return {ConfigurableModuleClass:class{static{a(this,"ConfigurableModuleClassImpl");}static forRoot(c,l={}){let u={module:this,global:l.global??false,providers:[{provide:e,useValue:c}],exports:[e]};return t&&(u=t(u,c)),u}static forRootAsync(c){let l=mt(e,c);return {module:this,imports:c.imports??[],providers:l,exports:[e]}}static forFeature(c,l={}){let u={module:this,global:l.global??false,providers:[{provide:r,useValue:c}],exports:[r]};return n&&(u=n(u,c)),u}},MODULE_OPTIONS_TOKEN:e,MODULE_FEATURE_TOKEN:r}}};var k=class{static{a(this,"BaseExecutionContext");}nativeRequest;handler;container;query;params;body;rawBody;formData;auth;data=new Map;metadata=new Map;abortController;constructor(e,r,t,n={},i={},s){this.nativeRequest=e,this.handler=r,this.container=t,this.query=n,this.params=i,this.abortController=s??new AbortController;}getNativeRequest(){return this.nativeRequest}getHandler(){return this.handler}getBody(){return this.body}setBody(e){this.body=e;}getRawBody(){return this.rawBody}setRawBody(e){this.rawBody=e;}getFormData(){return this.formData}setFormData(e){this.formData=e;}getQuery(){return this.query}getParams(){return this.params}getAuth(){return this.auth}setAuth(e){this.auth=e;}getMetadata(e){return this.metadata.get(e)}setMetadata(e,r){this.metadata.set(e,r);}getData(e){return this.data.get(e)}setData(e,r){this.data.set(e,r);}getContainer(){return this.container}getSignal(){return this.abortController.signal}abort(e){this.abortController.abort(e);}};var qe=Symbol("filters"),Oe=Symbol("catch");function We(...o){return (e,r,t)=>{let n=r?e.constructor:e,i=Reflect.getOwnMetadata(qe,n)??[];Reflect.defineMetadata(qe,[...i,...o],n);}}a(We,"UseFilters");function je(...o){return e=>{Reflect.defineMetadata(Oe,o,e);}}a(je,"Catch");function J(o){return Reflect.getOwnMetadata(Oe,o)??[]}a(J,"getCatchMetadata");function B(o,e$1,r){return async t=>{let n=[...e$1.middlewares??[],...r.middlewares??[]],i=[...e$1.guards??[],...r.guards??[]],s=[...e$1.interceptors??[],...r.interceptors??[]],c=[...e$1.pipes??[],...r.pipes??[]],l=[...e$1.filters??[],...r.filters??[]],u=await b(o,l);try{y(t);let d=await b(o,n);return await gt(t,d,async()=>{y(t);let f=await b(o,i);for(let P of f)if(y(t),!await P.canActivate(t))throw new e("Access denied by guard");y(t);let m=await b(o,c);for(let P of m)y(t),await P.transform(t);y(t);let h=await b(o,s),de=a(async()=>(y(t),r.handler(t)),"handlerCall");return h.length===0?de():h.reduceRight((P,le)=>async()=>(y(t),le.intercept(t,P)),de)()})}catch(d){return yt(d,t,u)}}}a(B,"createPipeline");async function gt(o,e,r){return e.length===0?r():e.reduceRight((n,i)=>()=>i.use(o,n),r)()}a(gt,"runMiddlewareChain");function y(o){if(o.getSignal().aborted)throw new g$1}a(y,"checkAborted");async function yt(o,e,r){for(let t of r){let n=J(t.constructor);if(n.length===0||o instanceof Error&&n.some(s=>o instanceof s))return t.catch(o,e)}throw o}a(yt,"handleError");async function b(o,e){let r=[];for(let t of e)typeof t=="function"?r.push(await o.resolve(t)):r.push(t);return r}a(b,"resolveRefs");var X=Symbol("interceptors"),ee=Symbol("method:interceptors");function He(...o){return (e,r,t)=>{if(r!==void 0){let i=t?.value??e,s=i[ee]??[];return i[ee]=[...s,...o],t}let n=Reflect.getOwnMetadata(X,e)??[];Reflect.defineMetadata(X,[...n,...o],e);}}a(He,"UseInterceptors");function te(o){return Reflect.getOwnMetadata(X,o)??[]}a(te,"getInterceptorsMetadata");function re(o,e){let t=o.prototype?.[e];return typeof t=="function"&&t[ee]||[]}a(re,"getMethodInterceptors");function T(o,e){return [...te(o),...re(o,e)]}a(T,"getEffectiveInterceptors");var oe="uow:session",ae="uow:instance",z=class{static{a(this,"UnitOfWorkInterceptor");}factory;constructor(e){this.factory=e;}async intercept(e,r){let t=this.factory();await t.start(),e.setData(oe,t.getContext()),e.setData(ae,t);try{let n=await r();return await t.commit(),n}catch(n){throw await t.rollback(),n}}};var $=Symbol("serialize:schema"),G=class{static{a(this,"SerializeInterceptor");}async intercept(e,r){let t=await r();if(t==null)return t;let i=e.getHandler()[$];if(!i)return t;if(Array.isArray(t)){let{z:s}=await import('zod');return s.array(i).parse(t)}return i.parse(t)}};function Ze(o){return (e,r,t)=>{if(r!==void 0&&t){let s=t.value;return typeof s=="function"&&(s[$]=o),t}let n=e.prototype,i=Object.getOwnPropertyNames(n).filter(s=>s!=="constructor"&&typeof n[s]=="function");for(let s of i)n[s][$]=o;}}a(Ze,"Serialize");function Le(o){return o[$]}a(Le,"getSerializeSchema");var ne=Symbol("middlewares"),se=Symbol("method:middlewares");function Qe(...o){return (e,r,t)=>{if(r!==void 0){let i=t?.value??e,s=i[se]??[];return i[se]=[...s,...o],t}let n=Reflect.getOwnMetadata(ne,e)??[];Reflect.defineMetadata(ne,[...n,...o],e);}}a(Qe,"UseMiddleware");function ie(o){return Reflect.getOwnMetadata(ne,o)??[]}a(ie,"getMiddlewaresMetadata");function ce(o,e){let t=o.prototype?.[e];return typeof t=="function"&&t[se]||[]}a(ce,"getMethodMiddlewares");function U(o,e){return [...ie(o),...ce(o,e)]}a(U,"getEffectiveMiddlewares");var Ye=Symbol("pipes");function Ke(...o){return (e,r,t)=>{let n=r?e.constructor:e,i=Reflect.getOwnMetadata(Ye,n)??[];Reflect.defineMetadata(Ye,[...i,...o],n);}}a(Ke,"UsePipes");var V=class{static{a(this,"ZodValidationPipe");}schema;constructor(e){this.schema=e;}transform(e){let r=e.getBody(),t=this.schema.safeParse(r);if(!t.success){let n={};for(let i of t.error.issues){let s=i.path.join(".")||"_root";n[s]||(n[s]=[]),n[s].push(i.message);}throw new c("Validation failed",n)}e.setBody(t.data);}};var wt=/^[0-9a-fA-F]{24}$/,q=class{static{a(this,"ParseIdPipe");}paramName;constructor(e="id"){this.paramName=e;}transform(e){let t=e.getParams()[this.paramName];if(!t||!wt.test(t))throw new c(`Invalid ${this.paramName}: must be a valid ObjectId`)}};var O=class{static{a(this,"ParseIntPipe");}transform(e){let r=Number(e);if(!Number.isInteger(r)||e===""||e===null||e===void 0)throw new c(`Expected an integer, received: ${JSON.stringify(e)}`);return r}};var W=class{static{a(this,"ZodParamPipe");}schema;constructor(e){this.schema=e;}transform(e){let r=this.schema.safeParse(e);if(!r.success){let t=r.error.errors.map(n=>`${n.path.join(".")}: ${n.message}`).join(", ");throw new c(t)}return r.data}};function Je(o){return {transform(e){return e??o}}}a(Je,"DefaultValuePipe");var x=Symbol("route:params");function xt(o){return o==null?false:typeof o=="function"||typeof o=="object"&&typeof o.transform=="function"}a(xt,"isParamPipeRef");function j(o,e){return xt(o)?{key:void 0,pipes:[o,...e??[]]}:{key:o,pipes:e??[]}}a(j,"resolveArgs");function g(o,e,r=[]){return (t,n,i)=>{if(n===void 0)return;let s=t[n];if(typeof s!="function")return;let c=s[x]??[];s[x]=[...c,{index:i,type:o,key:e,pipes:r.length>0?r:void 0}];}}a(g,"buildBuiltinDecorator");function Mt(o){return typeof o=="function"?new o:o}a(Mt,"resolveParamPipe");function Xe(o,...e){let{key:r,pipes:t}=j(o,e);return g("query",r,t)}a(Xe,"Query");function et(o,...e){let{key:r,pipes:t}=j(o,e);return g("param",r,t)}a(et,"Param");function tt(o,...e){let{key:r,pipes:t}=j(o,e);return g("body",r,t)}a(tt,"Body");var rt=a(()=>g("rawBody"),"RawBody"),ot=a(()=>g("formData"),"FormData"),at=a(()=>g("ip"),"Ip"),nt=a(()=>g("userAgent"),"UserAgent"),st=a(o=>g("cookie",o),"Cookie");function it(o,...e){let{key:r,pipes:t}=j(o,e);return g("headers",r,t)}a(it,"Headers");function ue(o){return ()=>(e,r,t)=>{if(r===void 0)return;let n=e[r];if(typeof n!="function")return;let i=n[x]??[];n[x]=[...i,{index:t,type:"auth",extractor:o}];}}a(ue,"defineAuth");var ct=ue();function w(o){return ()=>(e,r,t)=>{if(r===void 0)return;let n=e[r];if(typeof n!="function")return;let i=n[x]??[];n[x]=[...i,{index:t,type:"custom",extractor:o}];}}a(w,"createParamDecorator");function H(o,e){let r=o.prototype[e];if(typeof r!="function")return null;let t=r[x];return t&&t.length>0?t:null}a(H,"getRouteParams");async function Z(o,e){let r=Math.max(...o.map(n=>n.index)),t=new Array(r+1).fill(void 0);for(let{index:n,type:i,key:s,pipes:c,extractor:l}of o){let u;switch(i){case "query":{let d=e.getQuery();u=s!==void 0?d[s]:d;break}case "param":{let d=e.getParams();u=s!==void 0?d[s]:d;break}case "body":{let d=e.getBody()??{};u=s!==void 0?d[s]:d;break}case "rawBody":{u=e.getRawBody();break}case "formData":{u=e.getFormData();break}case "headers":{let d=e.getNativeRequest(),f=d?.node?.req?.headers??d?.headers??{};u=s!==void 0?f[s.toLowerCase()]:f;break}case "cookie":{let d=e.getNativeRequest(),f=d?.node?.req?.headers?.cookie??d?.headers?.cookie??"";if(s&&f){let m=f.split(";").map(h=>h.trim()).find(h=>h.startsWith(s+"="));u=m?decodeURIComponent(m.slice(s.length+1)):void 0;}else u=void 0;break}case "ip":{let d=e.getNativeRequest(),f=d?.node?.req?.headers??{},m=f["cf-connecting-ip"];if(m){u=m.trim();break}let h=f["x-forwarded-for"];if(h){u=(String(h).split(",")[0]??"").trim();break}u=d?.node?.req?.socket?.remoteAddress??"";break}case "userAgent":{u=(e.getNativeRequest()?.node?.req?.headers??{})["user-agent"]??"";break}case "auth":{u=l?await l(e):e.getAuth();break}case "custom":{u=l?await l(e):void 0;break}}if(c&&c.length>0)for(let d of c)u=Mt(d).transform(u);t[n]=u;}return t}a(Z,"resolveParamArgs");function ut(o){return w(e=>{let r=e.getBody(),t=o.safeParse(r);if(!t.success){let n={};for(let i of t.error.issues){let s=i.path.join(".")||"_root";(n[s]??=[]).push(i.message);}throw new c("Validation failed",n)}return t.data})}a(ut,"ZodValidatedBody");function dt(o){return w(e=>{let r=e.getQuery(),t=o.safeParse(r);if(!t.success){let n={};for(let i of t.error.issues){let s=i.path.join(".")||"_root";(n[s]??=[]).push(i.message);}throw new c("Query validation failed",n)}return t.data})}a(dt,"ZodValidatedQuery");function lt(o){return w(e=>{let r=e.getParams(),t=o.safeParse(r);if(!t.success){let n={};for(let i of t.error.issues){let s=i.path.join(".")||"_root";(n[s]??=[]).push(i.message);}throw new c("Params validation failed",n)}return t.data})}a(lt,"ZodValidatedParams");var L=class{static{a(this,"DomainEvent");}payload;timestamp;constructor(e){this.payload=e,this.timestamp=Date.now();}};var E=class{static{a(this,"ControllerRouter");}routes=[];globalPrefix;constructor(e=""){this.globalPrefix=e;}register(...e){for(let r of e){let t=l(r)??"",n$1=n(r);for(let i of n$1){let s=Et(`${this.globalPrefix}/${t}/${i.path}`);vt(s,r.name,i.methodName),this.checkDuplicate(s,i.method,r.name,i.methodName);let{pattern:c,paramNames:l}=Pt(s),u=o(r,i.methodName),d=T(r,i.methodName),f=U(r,i.methodName);this.routes.push({method:i.method,pattern:c,paramNames:l,controllerClass:r,methodName:i.methodName,guardClasses:u,interceptorRefs:d,middlewareRefs:f,rawPath:s});}}this.routes.sort((r,t)=>ft(r.rawPath)-ft(t.rawPath));}checkDuplicate(e,r,t,n){let i=this.routes.find(s=>s.method===r&&s.rawPath===e);if(i)throw new Error(`Duplicate route: ${r} ${e}
|
|
1
|
+
import {l,n,o,c as c$1,p,q as q$1,s}from'./chunk-MXBVL723.js';export{c as Container,d as Controller,h as Delete,q as EventEmitter2,e as Get,p as ModuleRegistry,k as NoGuard,r as OnEvent,i as Patch,f as Post,g as Put,j as RouteGuards,a as forwardRef,m as getControllerGuards,l as getControllerPath,o as getMethodGuards,n as getRouteMetadata,b as resolveForwardRef}from'./chunk-MXBVL723.js';import {n as n$1,i,j as j$1,k as k$1,m}from'./chunk-RLQ7JJW6.js';import {a as a$1}from'./chunk-NXAGO5NO.js';export{a as DiscoveryService}from'./chunk-NXAGO5NO.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';export{b as Global,a as Module,c as getModuleMetadata,d as isGlobalModule}from'./chunk-XZNMJJJU.js';import {b as b$1}from'./chunk-N277L4OB.js';export{d as Inject,c as Injectable,e as Optional,a as Scope}from'./chunk-N277L4OB.js';import {a}from'./chunk-EI7MMDWY.js';import'reflect-metadata';function mt(o,e){if("useFactory"in e&&e.useFactory){let r=e.useFactory;return [{provide:o,useFactory:r,inject:e.inject??[]}]}if("useClass"in e&&e.useClass){let r=e.useClass;return [{provide:o,useFactory:a(async t=>t.createModuleOptions(),"useFactory"),inject:[r]},r]}if("useExisting"in e&&e.useExisting){let r=e.useExisting;return [{provide:o,useFactory:a(async t=>t.createModuleOptions(),"useFactory"),inject:[r]}]}throw new Error("ModuleAsyncOptions must specify one of: useFactory, useClass, or useExisting")}a(mt,"createAsyncProviders");var _=class{static{a(this,"ConfigurableModuleBuilder");}description;featureDescription;onForRoot;onForFeature;constructor(e="MODULE_OPTIONS"){this.description=e,this.featureDescription=e+"_FEATURE";}setTokenDescription(e){return this.description=e,this}transformDynamicModule(e){return this.onForRoot=e,this}transformFeatureModule(e){return this.onForFeature=e,this}build(){let e=new b$1(this.description),r=new b$1(this.featureDescription),t=this.onForRoot,n=this.onForFeature;return {ConfigurableModuleClass:class{static{a(this,"ConfigurableModuleClassImpl");}static forRoot(c,l={}){let u={module:this,global:l.global??false,providers:[{provide:e,useValue:c}],exports:[e]};return t&&(u=t(u,c)),u}static forRootAsync(c){let l=mt(e,c);return {module:this,imports:c.imports??[],providers:l,exports:[e]}}static forFeature(c,l={}){let u={module:this,global:l.global??false,providers:[{provide:r,useValue:c}],exports:[r]};return n&&(u=n(u,c)),u}},MODULE_OPTIONS_TOKEN:e,MODULE_FEATURE_TOKEN:r}}};var k=class{static{a(this,"BaseExecutionContext");}nativeRequest;handler;container;query;params;body;rawBody;formData;auth;data=new Map;metadata=new Map;abortController;constructor(e,r,t,n={},i={},s){this.nativeRequest=e,this.handler=r,this.container=t,this.query=n,this.params=i,this.abortController=s??new AbortController;}getNativeRequest(){return this.nativeRequest}getHandler(){return this.handler}getBody(){return this.body}setBody(e){this.body=e;}getRawBody(){return this.rawBody}setRawBody(e){this.rawBody=e;}getFormData(){return this.formData}setFormData(e){this.formData=e;}getQuery(){return this.query}getParams(){return this.params}getAuth(){return this.auth}setAuth(e){this.auth=e;}getMetadata(e){return this.metadata.get(e)}setMetadata(e,r){this.metadata.set(e,r);}getData(e){return this.data.get(e)}setData(e,r){this.data.set(e,r);}getContainer(){return this.container}getSignal(){return this.abortController.signal}abort(e){this.abortController.abort(e);}};var qe=Symbol("filters"),Oe=Symbol("catch");function We(...o){return (e,r,t)=>{let n=r?e.constructor:e,i=Reflect.getOwnMetadata(qe,n)??[];Reflect.defineMetadata(qe,[...i,...o],n);}}a(We,"UseFilters");function je(...o){return e=>{Reflect.defineMetadata(Oe,o,e);}}a(je,"Catch");function J(o){return Reflect.getOwnMetadata(Oe,o)??[]}a(J,"getCatchMetadata");function T(o,e$1,r){return async t=>{let n=[...e$1.middlewares??[],...r.middlewares??[]],i=[...e$1.guards??[],...r.guards??[]],s=[...e$1.interceptors??[],...r.interceptors??[]],c=[...e$1.pipes??[],...r.pipes??[]],l=[...e$1.filters??[],...r.filters??[]],u=await b(o,l);try{y(t);let d=await b(o,n);return await gt(t,d,async()=>{y(t);let f=await b(o,i);for(let P of f)if(y(t),!await P.canActivate(t))throw new e("Access denied by guard");y(t);let m=await b(o,c);for(let P of m)y(t),await P.transform(t);y(t);let h=await b(o,s),de=a(async()=>(y(t),r.handler(t)),"handlerCall");return h.length===0?de():h.reduceRight((P,le)=>async()=>(y(t),le.intercept(t,P)),de)()})}catch(d){return yt(d,t,u)}}}a(T,"createPipeline");async function gt(o,e,r){return e.length===0?r():e.reduceRight((n,i)=>()=>i.use(o,n),r)()}a(gt,"runMiddlewareChain");function y(o){if(o.getSignal().aborted)throw new g$1}a(y,"checkAborted");async function yt(o,e,r){for(let t of r){let n=J(t.constructor);if(n.length===0||o instanceof Error&&n.some(s=>o instanceof s))return t.catch(o,e)}throw o}a(yt,"handleError");async function b(o,e){let r=[];for(let t of e)typeof t=="function"?r.push(await o.resolve(t)):r.push(t);return r}a(b,"resolveRefs");var X=Symbol("interceptors"),ee=Symbol("method:interceptors");function He(...o){return (e,r,t)=>{if(r!==void 0){let i=t?.value??e,s=i[ee]??[];return i[ee]=[...s,...o],t}let n=Reflect.getOwnMetadata(X,e)??[];Reflect.defineMetadata(X,[...n,...o],e);}}a(He,"UseInterceptors");function te(o){return Reflect.getOwnMetadata(X,o)??[]}a(te,"getInterceptorsMetadata");function re(o,e){let t=o.prototype?.[e];return typeof t=="function"&&t[ee]||[]}a(re,"getMethodInterceptors");function z(o,e){return [...te(o),...re(o,e)]}a(z,"getEffectiveInterceptors");var oe="uow:session",ae="uow:instance",$=class{static{a(this,"UnitOfWorkInterceptor");}factory;constructor(e){this.factory=e;}async intercept(e,r){let t=this.factory();await t.start(),e.setData(oe,t.getContext()),e.setData(ae,t);try{let n=await r();return await t.commit(),n}catch(n){throw await t.rollback(),n}}};var B=Symbol("serialize:schema"),G=class{static{a(this,"SerializeInterceptor");}async intercept(e,r){let t=await r();if(t==null)return t;let i=e.getHandler()[B];if(!i)return t;if(Array.isArray(t)){let{z:s}=await import('zod');return s.array(i).parse(t)}return i.parse(t)}};function Ze(o){return (e,r,t)=>{if(r!==void 0&&t){let s=t.value;return typeof s=="function"&&(s[B]=o),t}let n=e.prototype,i=Object.getOwnPropertyNames(n).filter(s=>s!=="constructor"&&typeof n[s]=="function");for(let s of i)n[s][B]=o;}}a(Ze,"Serialize");function Le(o){return o[B]}a(Le,"getSerializeSchema");var ne=Symbol("middlewares"),se=Symbol("method:middlewares");function Qe(...o){return (e,r,t)=>{if(r!==void 0){let i=t?.value??e,s=i[se]??[];return i[se]=[...s,...o],t}let n=Reflect.getOwnMetadata(ne,e)??[];Reflect.defineMetadata(ne,[...n,...o],e);}}a(Qe,"UseMiddleware");function ie(o){return Reflect.getOwnMetadata(ne,o)??[]}a(ie,"getMiddlewaresMetadata");function ce(o,e){let t=o.prototype?.[e];return typeof t=="function"&&t[se]||[]}a(ce,"getMethodMiddlewares");function U(o,e){return [...ie(o),...ce(o,e)]}a(U,"getEffectiveMiddlewares");var Ye=Symbol("pipes");function Ke(...o){return (e,r,t)=>{let n=r?e.constructor:e,i=Reflect.getOwnMetadata(Ye,n)??[];Reflect.defineMetadata(Ye,[...i,...o],n);}}a(Ke,"UsePipes");var V=class{static{a(this,"ZodValidationPipe");}schema;constructor(e){this.schema=e;}transform(e){let r=e.getBody(),t=this.schema.safeParse(r);if(!t.success){let n={};for(let i of t.error.issues){let s=i.path.join(".")||"_root";n[s]||(n[s]=[]),n[s].push(i.message);}throw new c("Validation failed",n)}e.setBody(t.data);}};var wt=/^[0-9a-fA-F]{24}$/,q=class{static{a(this,"ParseIdPipe");}paramName;constructor(e="id"){this.paramName=e;}transform(e){let t=e.getParams()[this.paramName];if(!t||!wt.test(t))throw new c(`Invalid ${this.paramName}: must be a valid ObjectId`)}};var O=class{static{a(this,"ParseIntPipe");}transform(e){let r=Number(e);if(!Number.isInteger(r)||e===""||e===null||e===void 0)throw new c(`Expected an integer, received: ${JSON.stringify(e)}`);return r}};var W=class{static{a(this,"ZodParamPipe");}schema;constructor(e){this.schema=e;}transform(e){let r=this.schema.safeParse(e);if(!r.success){let t=r.error.errors.map(n=>`${n.path.join(".")}: ${n.message}`).join(", ");throw new c(t)}return r.data}};function Je(o){return {transform(e){return e??o}}}a(Je,"DefaultValuePipe");var x=Symbol("route:params");function xt(o){return o==null?false:typeof o=="function"||typeof o=="object"&&typeof o.transform=="function"}a(xt,"isParamPipeRef");function j(o,e){return xt(o)?{key:void 0,pipes:[o,...e??[]]}:{key:o,pipes:e??[]}}a(j,"resolveArgs");function g(o,e,r=[]){return (t,n,i)=>{if(n===void 0)return;let s=t[n];if(typeof s!="function")return;let c=s[x]??[];s[x]=[...c,{index:i,type:o,key:e,pipes:r.length>0?r:void 0}];}}a(g,"buildBuiltinDecorator");function Et(o){return typeof o=="function"?new o:o}a(Et,"resolveParamPipe");function Xe(o,...e){let{key:r,pipes:t}=j(o,e);return g("query",r,t)}a(Xe,"Query");function et(o,...e){let{key:r,pipes:t}=j(o,e);return g("param",r,t)}a(et,"Param");function tt(o,...e){let{key:r,pipes:t}=j(o,e);return g("body",r,t)}a(tt,"Body");var rt=a(()=>g("rawBody"),"RawBody"),ot=a(()=>g("formData"),"FormData"),at=a(()=>g("ip"),"Ip"),nt=a(()=>g("userAgent"),"UserAgent"),st=a(o=>g("cookie",o),"Cookie");function it(o,...e){let{key:r,pipes:t}=j(o,e);return g("headers",r,t)}a(it,"Headers");function ue(o){return ()=>(e,r,t)=>{if(r===void 0)return;let n=e[r];if(typeof n!="function")return;let i=n[x]??[];n[x]=[...i,{index:t,type:"auth",extractor:o}];}}a(ue,"defineAuth");var ct=ue();function w(o){return ()=>(e,r,t)=>{if(r===void 0)return;let n=e[r];if(typeof n!="function")return;let i=n[x]??[];n[x]=[...i,{index:t,type:"custom",extractor:o}];}}a(w,"createParamDecorator");function H(o,e){let r=o.prototype[e];if(typeof r!="function")return null;let t=r[x];return t&&t.length>0?t:null}a(H,"getRouteParams");async function Z(o,e){let r=Math.max(...o.map(n=>n.index)),t=new Array(r+1).fill(void 0);for(let{index:n,type:i,key:s,pipes:c,extractor:l}of o){let u;switch(i){case "query":{let d=e.getQuery();u=s!==void 0?d[s]:d;break}case "param":{let d=e.getParams();u=s!==void 0?d[s]:d;break}case "body":{let d=e.getBody()??{};u=s!==void 0?d[s]:d;break}case "rawBody":{u=e.getRawBody();break}case "formData":{u=e.getFormData();break}case "headers":{let d=e.getNativeRequest(),f=d?.node?.req?.headers??d?.headers??{};u=s!==void 0?f[s.toLowerCase()]:f;break}case "cookie":{let d=e.getNativeRequest(),f=d?.node?.req?.headers?.cookie??d?.headers?.cookie??"";if(s&&f){let m=f.split(";").map(h=>h.trim()).find(h=>h.startsWith(s+"="));u=m?decodeURIComponent(m.slice(s.length+1)):void 0;}else u=void 0;break}case "ip":{let d=e.getNativeRequest(),f=d?.node?.req?.headers??{},m=f["cf-connecting-ip"];if(m){u=m.trim();break}let h=f["x-forwarded-for"];if(h){u=(String(h).split(",")[0]??"").trim();break}u=d?.node?.req?.socket?.remoteAddress??"";break}case "userAgent":{u=(e.getNativeRequest()?.node?.req?.headers??{})["user-agent"]??"";break}case "auth":{u=l?await l(e):e.getAuth();break}case "custom":{u=l?await l(e):void 0;break}}if(c&&c.length>0)for(let d of c)u=Et(d).transform(u);t[n]=u;}return t}a(Z,"resolveParamArgs");function ut(o){return w(e=>{let r=e.getBody(),t=o.safeParse(r);if(!t.success){let n={};for(let i of t.error.issues){let s=i.path.join(".")||"_root";(n[s]??=[]).push(i.message);}throw new c("Validation failed",n)}return t.data})}a(ut,"ZodValidatedBody");function dt(o){return w(e=>{let r=e.getQuery(),t=o.safeParse(r);if(!t.success){let n={};for(let i of t.error.issues){let s=i.path.join(".")||"_root";(n[s]??=[]).push(i.message);}throw new c("Query validation failed",n)}return t.data})}a(dt,"ZodValidatedQuery");function lt(o){return w(e=>{let r=e.getParams(),t=o.safeParse(r);if(!t.success){let n={};for(let i of t.error.issues){let s=i.path.join(".")||"_root";(n[s]??=[]).push(i.message);}throw new c("Params validation failed",n)}return t.data})}a(lt,"ZodValidatedParams");var L=class{static{a(this,"DomainEvent");}payload;timestamp;constructor(e){this.payload=e,this.timestamp=Date.now();}};var M=class{static{a(this,"ControllerRouter");}routes=[];globalPrefix;constructor(e=""){this.globalPrefix=e;}register(...e){for(let r of e){let t=l(r)??"",n$1=n(r);for(let i of n$1){let s=Mt(`${this.globalPrefix}/${t}/${i.path}`);vt(s,r.name,i.methodName),this.checkDuplicate(s,i.method,r.name,i.methodName);let{pattern:c,paramNames:l}=Pt(s),u=o(r,i.methodName),d=z(r,i.methodName),f=U(r,i.methodName);this.routes.push({method:i.method,pattern:c,paramNames:l,controllerClass:r,methodName:i.methodName,guardClasses:u,interceptorRefs:d,middlewareRefs:f,rawPath:s});}}this.routes.sort((r,t)=>ft(r.rawPath)-ft(t.rawPath));}checkDuplicate(e,r,t,n){let i=this.routes.find(s=>s.method===r&&s.rawPath===e);if(i)throw new Error(`Duplicate route: ${r} ${e}
|
|
2
2
|
Already registered by: ${i.controllerClass.name}.${i.methodName}
|
|
3
|
-
Conflicting with: ${t}.${n}`)}match(e,r){let t=e.toUpperCase();for(let n of this.routes){if(n.method!==t)continue;let i=n.pattern.exec(r);if(!i)continue;let s={};for(let c=0;c<n.paramNames.length;c++)s[n.paramNames[c]]=i[c+1]??"";return {route:n,params:s}}return null}getRoutes(){return this.routes}};function
|
|
3
|
+
Conflicting with: ${t}.${n}`)}match(e,r){let t=e.toUpperCase();for(let n of this.routes){if(n.method!==t)continue;let i=n.pattern.exec(r);if(!i)continue;let s={};for(let c=0;c<n.paramNames.length;c++)s[n.paramNames[c]]=i[c+1]??"";return {route:n,params:s}}return null}getRoutes(){return this.routes}};function Mt(o){return "/"+o.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}a(Mt,"normalizePath");function Pt(o){let e=[],r=o.split("/").map(t=>t.startsWith(":")?(e.push(t.slice(1)),"([^/]+)"):Rt(t)).join("/");return {pattern:new RegExp(`^${r}$`),paramNames:e}}a(Pt,"compilePath");function Rt(o){return o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}a(Rt,"escapeRegex");function ft(o){return o.split("/").filter(Boolean).reduce((e,r)=>e+(r.startsWith(":")?1:0),0)}a(ft,"routePriority");function vt(o,e,r){let t=`Invalid path "${o}" on ${e}.${r}:`;if(!o.startsWith("/"))throw new Error(`${t} must start with /`);let n=o.split("/").filter((s,c)=>c>0),i=new Set;for(let s of n){if(s==="")throw new Error(`${t} contains empty segment (double slash)`);if(s.startsWith(":")){let c=s.slice(1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c))throw new Error(`${t} invalid param name ":${c}" \u2014 must be a valid identifier`);if(i.has(c))throw new Error(`${t} duplicate param name ":${c}"`);i.add(c);}}}a(vt,"validatePath");var pt="__redirect";function ht(o,e=302){return {__redirect:true,url:o,statusCode:e}}a(ht,"redirect");function Q(o){return o!==null&&typeof o=="object"&&o.__redirect===true}a(Q,"isRedirect");var C=class{static{a(this,"TruxieApplication");}container;registry;initialized=false;rootModule;options;eventEmitter;prefix="";router;filters=[];gateways=new Map;wsInitialized=false;constructor(e,r={}){this.rootModule=e,this.options=r,this.container=new c$1,this.registry=new p;}async init(){if(this.initialized)return;this.eventEmitter=new q$1,this.options.eventBus&&this.eventEmitter.setOptions(this.options.eventBus),this.container.register({provide:q$1,useValue:this.eventEmitter});let e=new a$1;this.container.register({provide:a$1,useValue:e}),this.registry.scan(this.rootModule),this.registry.registerAll(this.container);let r=this.registry.getAllProviders();e._init(this.container,r),await this.registry.callLifecycleHooks(this.container,"onModuleInit"),await s(this.container,r),await this.registry.callLifecycleHooks(this.container,"onApplicationBootstrap"),this.router=new M(this.prefix),this.router.register(...this.registry.getAllControllers()),this.filters=this.options.globalFilters??[],this.initialized=true;}setGlobalPrefix(e){return this.prefix=e,this}getGlobalPrefix(){return this.prefix}async resolve(e){return this.ensureInitialized(),this.container.resolve(e)}has(e){return this.container.has(e)}getContainer(){return this.container}matchRoute(e,r){return this.ensureInitialized(),this.router.match(e,r)??null}async handleRequest(e$1,r){this.ensureInitialized();let{container:t,dispose:n}=this.createRequestContext();try{let i=await t.resolve(e$1.controllerClass),s=i[e$1.methodName].bind(i),c=H(e$1.controllerClass,e$1.methodName);try{for(let u of e$1.guardClasses)if(!await(t.has(u)?await t.resolve(u):new u).canActivate(r))throw new e("Access denied by guard");let l=c?await s(...await Z(c,r)):await s(r);if(Q(l)){let u=l;return {value:l,isRedirect:!0,redirectUrl:u.url,redirectStatus:u.statusCode}}return {value:l,isRedirect:!1}}catch(l){for(let u of this.filters)try{return {value:await u.catch(l,r),isRedirect:!1}}catch{continue}throw l}}finally{await n();}}hasGateways(){return this.ensureInitialized(),this.registry.getAllGateways().length>0}async createWebSocketHooks(e){this.ensureInitialized(),await this.initGateways();let r=this;return {async open(t){let i="/"+(e.getUrl(t).split("?")[0]??"/").replace(/^\/+|\/+$/g,""),s=r.matchGatewayPath(i);if(!s)return;let c=t.context;c&&(c._gatewayPath=s);let l=r.gateways.get(s),u=e.adaptPeer(t);for(let d of l.serverProps)l.instance[d]={peers:e.getPeers(t)??new Set};if(l.hasConnection)try{await l.instance.handleConnection(u);}catch(d){console.error(`[WS] ${l.className}.handleConnection error:`,d);}},async message(t,n){let s=t.context?._gatewayPath;if(!s)return;let c=r.gateways.get(s);if(!c)return;let l=e.adaptPeer(t),u=e.adaptMessage(n),d;try{d=u.json();}catch{return}if(!d.event||typeof d.event!="string")return;let f=c.messageHandlers.get(d.event);if(f)try{let m=n$1(f.paramMeta,l,u,d.data),h=await f.method(...m);h!=null&&l.send(h);}catch(m){console.error(`[WS] ${c.className}.${d.event} error:`,m);}},async close(t,n){let s=t.context?._gatewayPath;if(!s)return;let c=r.gateways.get(s);if(!c?.hasDisconnect)return;let l=e.adaptPeer(t);try{await c.instance.handleDisconnect(l,n);}catch(u){console.error(`[WS] ${c.className}.handleDisconnect error:`,u);}},async error(t,n){let i=t?.id??"unknown";console.error(`[WS] Peer ${String(i)} error:`,n);}}}getControllers(){return this.ensureInitialized(),this.registry.getAllControllers()}getGateways(){return this.ensureInitialized(),this.registry.getAllGateways()}getProviders(){return this.ensureInitialized(),this.registry.getAllProviders()}getEventEmitter(){return this.ensureInitialized(),this.eventEmitter}getRouter(){return this.ensureInitialized(),this.router}createHandler(e){return this.ensureInitialized(),T(this.container,this.getGlobalOptions(),e)}async shutdown(){this.initialized&&(await this.registry.callLifecycleHooks(this.container,"onModuleDestroy"),await this.registry.callLifecycleHooks(this.container,"onApplicationShutdown"),this.eventEmitter.clear(),await this.container.dispose(),this.initialized=false);}createRequestContext(){if(!this.container.hasRequestScoped())return {container:this.container,dispose:a(async()=>{},"dispose")};let e=this.container.createChild();return {container:e,dispose:a(()=>e.dispose(),"dispose")}}matchGatewayPath(e){if(this.gateways.has(e))return e;for(let r of this.gateways.keys())if(e.endsWith(r))return r;if(this.gateways.has("/"))return "/"}async initGateways(){if(!this.wsInitialized){for(let e of this.registry.getAllGateways()){let r=i(e);if(!r)continue;let t=await this.container.resolve(e),n=new Map;for(let i of j$1(e)){let s=t[i.methodName];typeof s=="function"&&n.set(i.event,{method:s.bind(t),paramMeta:k$1(e.prototype[i.methodName])});}if(this.gateways.set(r.path,{instance:t,className:e.name,messageHandlers:n,hasConnection:typeof t.handleConnection=="function",hasDisconnect:typeof t.handleDisconnect=="function",serverProps:m(e)}),typeof t.afterInit=="function")try{await t.afterInit();}catch{}}this.wsInitialized=true;}}getGlobalOptions(){return {guards:this.options.globalGuards,interceptors:this.options.globalInterceptors,pipes:this.options.globalPipes,filters:this.options.globalFilters}}ensureInitialized(){if(!this.initialized)throw new Error("TruxieApplication not initialized. Call TruxieFactory.create() or app.init().")}},Y=class{static{a(this,"TruxieFactory");}static async create(e,r){let t=new C(e,r);return await t.init(),t}};export{ct as Auth,k as BaseExecutionContext,tt as Body,je as Catch,_ as ConfigurableModuleBuilder,M as ControllerRouter,st as Cookie,Je as DefaultValuePipe,L as DomainEvent,ot as FormData,it as Headers,at as Ip,et as Param,q as ParseIdPipe,O as ParseIntPipe,Xe as Query,pt as REDIRECT_BRAND,rt as RawBody,Ze as Serialize,G as SerializeInterceptor,C as TruxieApplication,Y as TruxieFactory,ae as UOW_INSTANCE_KEY,oe as UOW_SESSION_KEY,$ as UnitOfWorkInterceptor,We as UseFilters,He as UseInterceptors,Qe as UseMiddleware,Ke as UsePipes,nt as UserAgent,W as ZodParamPipe,ut as ZodValidatedBody,lt as ZodValidatedParams,dt as ZodValidatedQuery,V as ZodValidationPipe,w as createParamDecorator,T as createPipeline,ue as defineAuth,z as getEffectiveInterceptors,U as getEffectiveMiddlewares,te as getInterceptorsMetadata,re as getMethodInterceptors,ce as getMethodMiddlewares,ie as getMiddlewaresMetadata,H as getRouteParams,Le as getSerializeSchema,Q as isRedirect,ht as redirect,Z as resolveParamArgs};
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { C as Container } from './container-BQEpLL35.js';
|
|
2
2
|
import { M as ModuleMetadata, a as Type, D as DynamicModule, T as Token } from './types-D-An5cXP.js';
|
|
3
|
-
import { a as
|
|
3
|
+
import { a as EventEmitter2 } from './event-bus-C58NcKP1.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Chain API for overriding a single provider in a testing module.
|
|
@@ -32,8 +32,8 @@ interface TestingModule {
|
|
|
32
32
|
has(token: Token): boolean;
|
|
33
33
|
/** Get the underlying DI container */
|
|
34
34
|
getContainer(): Container;
|
|
35
|
-
/** Get the test
|
|
36
|
-
|
|
35
|
+
/** Get the test EventEmitter2 */
|
|
36
|
+
getEventEmitter(): EventEmitter2;
|
|
37
37
|
/** Shut down the module (calls onModuleDestroy, onApplicationShutdown) */
|
|
38
38
|
shutdown(): Promise<void>;
|
|
39
39
|
}
|
package/dist/testing.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {c,q,p,s}from'./chunk-
|
|
1
|
+
import {c,q,p,s}from'./chunk-MXBVL723.js';import'./chunk-RLQ7JJW6.js';import {a as a$1}from'./chunk-NXAGO5NO.js';import'./chunk-XZNMJJJU.js';import'./chunk-N277L4OB.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(s=>(this.overrides.set(e,{provide:e,useValue:s}),this),"useValue"),useClass:a(s=>(this.overrides.set(e,{provide:e,useClass:s}),this),"useClass"),useFactory:a((s,a)=>(this.overrides.set(e,{provide:e,useFactory:s,inject:a??[]}),this),"useFactory")}}async compile(){let e=new c,s$1=new q;e.register({provide:q,useValue:s$1});let a$2=new a$1;e.register({provide:a$1,useValue:a$2});let o=this.metadata;if(m(o)){let t=o.providers??[];if(e.register(...t),o.imports&&o.imports.length>0){let p$1=new p,h={module:class{static{a(this,"TempTestModule");}},imports:o.imports,providers:t,exports:o.exports??[]};p$1.scan(h),p$1.registerAll(e);}}else {let t=new p;t.scan(o),t.registerAll(e);}for(let[,t]of this.overrides)e.register(t);let i=this.collectProviders(o);return a$2._init(e,i),await this.callHook(e,i,"onModuleInit"),await s(e,i),await this.callHook(e,i,"onApplicationBootstrap"),{resolve:a(t=>e.resolve(t),"resolve"),has:a(t=>e.has(t),"has"),getContainer:a(()=>e,"getContainer"),getEventEmitter:a(()=>s$1,"getEventEmitter"),shutdown:a(async()=>{await this.callHook(e,i,"onModuleDestroy"),await this.callHook(e,i,"onApplicationShutdown"),s$1.clear(),await e.dispose();},"shutdown")}}collectProviders(e){return m(e)?e.providers??[]:[]}async callHook(e,s,a){for(let o of s){let i=typeof o=="function"?o:o.provide;if(e.has(i))try{let t=await e.resolve(i);t&&typeof t=="object"&&typeof t[a]=="function"&&await t[a]();}catch{}}}};function m(n){return !(typeof n=="function"||n&&typeof n=="object"&&"module"in n)}a(m,"isModuleMetadata");var u=class{static{a(this,"Test");}static createTestingModule(e){return new y(e)}};export{u as Test};
|
package/package.json
CHANGED
package/dist/chunk-LUBJE4B3.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import {i as i$1}from'./chunk-RLQ7JJW6.js';import {c,d}from'./chunk-XZNMJJJU.js';import {f,a as a$1,g,h as h$1,i,b,c as c$1}from'./chunk-N277L4OB.js';import {a}from'./chunk-EI7MMDWY.js';import'reflect-metadata';function V(r){return {forwardRef:r}}a(V,"forwardRef");function G(r){return typeof r=="object"&&"forwardRef"in r?r.forwardRef():r}a(G,"resolveForwardRef");var j=class r{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){if(typeof t=="function"){let s=f(t)?.scope??a$1.SINGLETON;this.registrations.set(t,{provider:t,scope:s});return}let e=t.provide,n=a$1.SINGLETON;if("useClass"in t){let o=f(t.useClass);n=t.scope??o?.scope??a$1.SINGLETON;}else "useFactory"in t&&(n=t.scope??a$1.SINGLETON);this.registrations.set(e,{provider:t,scope:n});}async resolve(t){let e=G(t),n=e!==t?e:t,o=this.registrations.get(n)??this.parent?.findRegistration(n);if(!o)throw new Error(`No provider found for ${y(n)}`);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(n))throw new Error(`Circular dependency detected for ${y(n)}`);this.resolving.add(n);try{let s=await this.createInstance(o);return (o.scope===a$1.SINGLETON||o.scope===a$1.REQUEST&&this.parent!==null)&&(o.instance=s),s}finally{this.resolving.delete(n);}}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 r;t.parent=this;for(let[e,n]of this.registrations)n.scope===a$1.REQUEST&&t.registrations.set(e,{provider:n.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 n=e,o=[];if(n.inject)for(let s of n.inject)o.push(await this.resolve(s));return n.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)??[],n=g(t),o=h$1(t),s=i(t),i$1=o.size>0?Math.max(...o.keys())+1:0,a=Math.max(e.length,i$1,n.length),f=[];for(let l=0;l<a;l++){let R=o.get(l)??n[l]??e[l],_=s.has(l);try{f.push(await this.resolve(R));}catch{if(_)f.push(void 0);else throw new Error(`Cannot resolve parameter at index ${l} (${y(R)}) of ${t.name}`)}}return new t(...f)}};function y(r){return typeof r=="string"?r:typeof r=="symbol"||r instanceof b?r.toString():typeof r=="function"?r.name:String(r)}a(y,"tokenToString");var I=Symbol("controller:path"),E=Symbol("controller:guards"),w=Symbol("route:metadata"),M=Symbol("method:route"),h=Symbol("method:guards"),x=Symbol("method:noguard");function K(r){return t=>{Reflect.defineMetadata(I,r,t);}}a(K,"Controller");function m(r){return (t="")=>(e,n,o)=>{let s=o!==void 0,i=String(s?n:n?.name??n),a=s?o?.value:e;if(typeof a=="function"&&(a[M]={method:r,path:t,methodName:i}),s){let f=Reflect.getOwnMetadata(w,e.constructor)??[];return f.push({method:r,path:t,methodName:i}),Reflect.defineMetadata(w,f,e.constructor),o}return e}}a(m,"createMethodDecorator");var tt=m("GET"),et=m("POST"),ot=m("PUT"),nt=m("DELETE"),st=m("PATCH");function rt(...r){return (t,e,n)=>{if(e==null){Reflect.defineMetadata(E,r,t);return}if(n!==void 0){if(n?.value){let o=n.value[h]??[];n.value[h]=[...o,...r];}return n}if(typeof t=="function"){let o=t[h]??[];t[h]=[...o,...r];}return typeof t=="function"&&e?.kind==="class"&&Reflect.defineMetadata(E,r,t),t}}a(rt,"RouteGuards");function it(){return (r,t,e)=>e!==void 0?(e?.value&&(e.value[x]=true),e):(typeof r=="function"&&(r[x]=true),r)}a(it,"NoGuard");function A(r){return Reflect.getOwnMetadata(I,r)}a(A,"getControllerPath");function H(r){return Reflect.getOwnMetadata(E,r)??[]}a(H,"getControllerGuards");function at(r){let t=[],e=r.prototype;if(e){let n=Object.getOwnPropertyNames(e);for(let o of n){if(o==="constructor")continue;let s=e[o];typeof s=="function"&&s[M]&&t.push(s[M]);}}return t.length>0?t:Reflect.getOwnMetadata(w,r)??[]}a(at,"getRouteMetadata");function ct(r,t){let n=r.prototype?.[t],o=typeof n=="function"&&n[x]===true,s=typeof n=="function"&&n[h]||[];return o?s:[...H(r),...s]}a(ct,"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 n of this.sortedModules)if(n.global)for(let o of n.providers)e.add(o);e.size>0&&t.register(...e);for(let n of this.sortedModules){t.register(...n.providers);for(let o of n.metadata.imports??[]){let s=this.getModuleType(o),i=this.resolved.get(s);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 n of this.sortedModules){for(let o of n.controllers)t.has(o)||(t.add(o),e.push(o));for(let o of n.metadata.providers??[])typeof o=="function"&&A(o)!==void 0&&!t.has(o)&&(t.add(o),e.push(o));}return e}getAllGateways(){let t=new Set,e=[];for(let n of this.sortedModules)for(let o of n.providers)typeof o=="function"&&i$1(o)!==void 0&&!t.has(o)&&(t.add(o),e.push(o));return e}async callLifecycleHooks(t,e,n){for(let o of this.sortedModules)for(let s of o.providers){let i=typeof s=="function"?s:s.provide;if(t.has(i))try{let a=await t.resolve(i);a&&typeof a=="object"&&typeof a[e]=="function"&&await a[e](n);}catch{}}}resolveModule(t){let e=typeof t=="object"&&"module"in t,n=e?t.module:t;if(this.resolved.has(n))return this.resolved.get(n);let o=c(n)??{},s=e?t:{},i=[...o.controllers??[],...s.controllers??[]],a={imports:[...o.imports??[],...s.imports??[]],controllers:i,providers:[...o.providers??[],...s.providers??[]],exports:[...o.exports??[],...s.exports??[]]},f={type:n,metadata:a,controllers:i,providers:[...i,...a.providers??[]],exports:new Set(a.exports??[]),global:e?t.global??d(n):d(n)};this.resolved.set(n,f);for(let l of a.imports??[])this.resolveModule(l);return f}getVisibleTokens(t){let e=new Set;for(let n of t.providers)e.add(this.getProviderToken(n));for(let n of t.metadata.imports??[]){let o=this.getModuleType(n),s=this.resolved.get(o);if(s)for(let i of s.exports)e.add(i);}for(let n of this.sortedModules)if(n.global)for(let o of n.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))),n=this.collectImportedExports(t);for(let o of t.exports)if(!e.has(o)&&!n.has(o)){let s=typeof o=="function"?o.name:String(o);throw new Error(`${t.type.name} exports ${s} 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 n of t.providers){if(typeof n!="function")continue;let o=g(n);for(let s of o)if(!e.has(s)){let i=typeof s=="function"?s.name:String(s);throw new Error(`${t.type.name}: ${n.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 n of t.metadata.imports??[]){let o=this.getModuleType(n),s=this.resolved.get(o);if(s)for(let i of s.exports)e.add(i);}return e}findProvider(t,e){return t.providers.find(n=>typeof n=="function"?n===e:n.provide===e)}findReExportedProvider(t,e){for(let n of t.metadata.imports??[]){let o=this.getModuleType(n),s=this.resolved.get(o);if(!s||!s.exports.has(e))continue;let i=this.findProvider(s,e);if(i)return i;let a=this.findReExportedProvider(s,e);if(a)return a}}getModuleType(t){return typeof t=="object"&&"module"in t?t.module:t}topologicalSort(){let t=new Set,e=new Set,n=[],o=a(s=>{if(t.has(s))return;if(e.has(s))throw new Error(`Circular module dependency detected: ${s.name}`);e.add(s);let i=this.resolved.get(s);if(i){for(let a of i.metadata.imports??[])o(this.getModuleType(a));e.delete(s),t.add(s),n.push(i);}},"visit");for(let[s]of this.resolved)o(s);return n}};function D(r,t,e,n){var o=arguments.length,s=o<3?t:n===null?n=Object.getOwnPropertyDescriptor(t,e):n,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(r,t,e,n);else for(var a=r.length-1;a>=0;a--)(i=r[a])&&(s=(o<3?i(s):o>3?i(t,e,s):i(t,e))||s);return o>3&&s&&Object.defineProperty(t,e,s),s}a(D,"_ts_decorate");function L(r,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,t)}a(L,"_ts_metadata");var u=class{static{a(this,"EventBus");}handlers=new Map;onError;constructor(){this.onError=k;}setOptions(t){t.onError&&(this.onError=t.onError);}subscribe(t,e,n){let o=this.handlers.get(t)??[];o.push({instance:n?.instance??{},methodName:n?.methodName??"anonymous",handler:e}),this.handlers.set(t,o);}registerHandler(t,e,n){let o=e[n].bind(e);this.subscribe(t,o,{instance:e,methodName:n});}async emit(t){let e=this.handlers.get(t.type);if(!e||e.length===0)return;let n=await Promise.allSettled(e.map(o=>o.handler(t)));for(let o=0;o<n.length;o++){let s=n[o];if(s.status==="rejected"){let i=e[o],a=`${i.instance.constructor?.name??"Unknown"}.${i.methodName}`;this.onError(s.reason,t.type,a);}}}emitAsync(t){this.emit(t).catch(()=>{});}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();}};u=D([c$1(),L("design:type",Function),L("design:paramtypes",[])],u);function k(r,t,e){console.error(`[EventBus] Handler "${e}" failed for event "${t}":`,r);}a(k,"defaultErrorHandler");var T=Symbol("on-event");function Mt(r){return (t,e,n)=>{let o=Reflect.getOwnMetadata(T,t.constructor)??[];o.push({eventType:r,methodName:String(e)}),Reflect.defineMetadata(T,o,t.constructor);}}a(Mt,"OnEvent");function U(r){return Reflect.getOwnMetadata(T,r)??[]}a(U,"getOnEventMetadata");async function Nt(r,t){let e=await r.resolve(u);for(let n of t){let o=F(n);if(!o)continue;let s=U(o);if(s.length===0)continue;let i=typeof n=="function"?n:n.provide,a;try{a=await r.resolve(i);}catch{continue}for(let f of s)typeof a[f.methodName]=="function"&&e.registerHandler(f.eventType,a,f.methodName);}}a(Nt,"scanEventHandlers");function F(r){return typeof r=="function"?f(r)?r:null:"useClass"in r?r.useClass:null}a(F,"getProviderClass");export{V as a,G as b,j as c,K as d,tt as e,et as f,ot as g,nt as h,st as i,rt as j,it as k,A as l,H as m,at as n,ct as o,$ as p,u as q,Mt as r,Nt as s};
|