@oldzy/conduit 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  declare abstract class BaseCommunicationObject {
2
- readonly type: string | symbol;
2
+ readonly type: string;
3
3
  constructor(type: string | symbol);
4
4
  }
5
5
 
@@ -1,5 +1,5 @@
1
1
  declare abstract class BaseCommunicationObject {
2
- readonly type: string | symbol;
2
+ readonly type: string;
3
3
  constructor(type: string | symbol);
4
4
  }
5
5
 
@@ -1,5 +1,5 @@
1
- import { S as ServiceProvider } from './ServiceProvider-BcW9XXlN.js';
2
- import { b as BaseResponse, a as BaseRequest } from './IRequestHandler-x0c3xSqH.js';
1
+ import { S as ServiceProvider } from './ServiceProvider-BE1-lOxZ.js';
2
+ import { b as BaseResponse, a as BaseRequest } from './IRequestHandler-Dp4jjwcB.js';
3
3
 
4
4
  declare class Mediator {
5
5
  private serviceProvider;
@@ -1,5 +1,5 @@
1
- import { S as ServiceProvider } from './ServiceProvider-BcW9XXlN.mjs';
2
- import { b as BaseResponse, a as BaseRequest } from './IRequestHandler-x0c3xSqH.mjs';
1
+ import { S as ServiceProvider } from './ServiceProvider-BE1-lOxZ.mjs';
2
+ import { b as BaseResponse, a as BaseRequest } from './IRequestHandler-Dp4jjwcB.mjs';
3
3
 
4
4
  declare class Mediator {
5
5
  private serviceProvider;
@@ -1,4 +1,4 @@
1
- import { S as ServiceProvider, b as ServiceLifetime, a as ServiceDescriptor } from './ServiceProvider-BcW9XXlN.mjs';
1
+ import { S as ServiceProvider, b as ServiceLifetime, a as ServiceDescriptor } from './ServiceProvider-BE1-lOxZ.mjs';
2
2
 
3
3
  declare class ServiceCollection {
4
4
  private serviceDescriptors;
@@ -1,4 +1,4 @@
1
- import { S as ServiceProvider, b as ServiceLifetime, a as ServiceDescriptor } from './ServiceProvider-BcW9XXlN.js';
1
+ import { S as ServiceProvider, b as ServiceLifetime, a as ServiceDescriptor } from './ServiceProvider-BE1-lOxZ.js';
2
2
 
3
3
  declare class ServiceCollection {
4
4
  private serviceDescriptors;
@@ -5,7 +5,7 @@ declare enum ServiceLifetime {
5
5
  }
6
6
 
7
7
  interface ServiceDescriptor {
8
- serviceIdentifier: string | symbol;
8
+ serviceIdentifier: string;
9
9
  implementationType?: new (...args: any[]) => any;
10
10
  implementationInstance?: any;
11
11
  implementationFactory?: (...args: any[]) => any;
@@ -5,7 +5,7 @@ declare enum ServiceLifetime {
5
5
  }
6
6
 
7
7
  interface ServiceDescriptor {
8
- serviceIdentifier: string | symbol;
8
+ serviceIdentifier: string;
9
9
  implementationType?: new (...args: any[]) => any;
10
10
  implementationInstance?: any;
11
11
  implementationFactory?: (...args: any[]) => any;
@@ -1,8 +1,8 @@
1
- import { S as ServiceCollection } from '../ServiceCollection-3wUO7p8g.mjs';
2
- import { S as ServiceProvider, b as ServiceLifetime } from '../ServiceProvider-BcW9XXlN.mjs';
3
- import { b as BaseResponse, a as BaseRequest, I as IRequestHandler } from '../IRequestHandler-x0c3xSqH.mjs';
1
+ import { S as ServiceCollection } from '../ServiceCollection-DbvEQOzY.mjs';
2
+ import { S as ServiceProvider, b as ServiceLifetime } from '../ServiceProvider-BE1-lOxZ.mjs';
3
+ import { b as BaseResponse, a as BaseRequest, I as IRequestHandler } from '../IRequestHandler-Dp4jjwcB.mjs';
4
4
  import { IPipelineBehavior } from '../pipeline/index.mjs';
5
- import { M as Mediator } from '../Mediator-CBq5EqK5.mjs';
5
+ import { M as Mediator } from '../Mediator-IEaPewwN.mjs';
6
6
 
7
7
  interface IApplicationAdapter {
8
8
  readonly name: string;
@@ -1,8 +1,8 @@
1
- import { S as ServiceCollection } from '../ServiceCollection-B8PXr0Uo.js';
2
- import { S as ServiceProvider, b as ServiceLifetime } from '../ServiceProvider-BcW9XXlN.js';
3
- import { b as BaseResponse, a as BaseRequest, I as IRequestHandler } from '../IRequestHandler-x0c3xSqH.js';
1
+ import { S as ServiceCollection } from '../ServiceCollection-DixtW4OW.js';
2
+ import { S as ServiceProvider, b as ServiceLifetime } from '../ServiceProvider-BE1-lOxZ.js';
3
+ import { b as BaseResponse, a as BaseRequest, I as IRequestHandler } from '../IRequestHandler-Dp4jjwcB.js';
4
4
  import { IPipelineBehavior } from '../pipeline/index.js';
5
- import { M as Mediator } from '../Mediator-CnBmWM_n.js';
5
+ import { M as Mediator } from '../Mediator-DsZR19WY.js';
6
6
 
7
7
  interface IApplicationAdapter {
8
8
  readonly name: string;
@@ -1,2 +1,2 @@
1
1
  'use strict';require('reflect-metadata');/* conduit - MIT License */
2
- var E=Object.defineProperty;var T=(o,e,t)=>e in o?E(o,e,{enumerable:true,configurable:true,writable:true,value:t}):o[e]=t;var n=(o,e)=>E(o,"name",{value:e,configurable:true});var s=(o,e,t)=>T(o,typeof e!="symbol"?e+"":e,t);var i=(function(o){return o.Singleton="SINGLETON",o.Scoped="SCOPED",o.Transient="TRANSIENT",o})({});var l=class l{constructor(e,t){s(this,"serviceDescriptors");s(this,"singletons",new Map);s(this,"scopedInstances",new Map);s(this,"parent");s(this,"resolutionStack",[]);this.serviceDescriptors=e,this.parent=t;}getService(e){try{return this.getRequiredService(e)}catch{return}}getRequiredService(e){let t=this.resolutionStack.length===0;if(this.resolutionStack.includes(e)){let r=[...this.resolutionStack,e].map(a=>String(a)).join(" \u2192 ");throw new Error(`Circular dependency detected: ${r}`)}this.resolutionStack.push(e);try{let r=this.serviceDescriptors.find(a=>a.serviceIdentifier===e);if(!r){if(this.parent)return this.parent.getRequiredService(e);throw new Error(`Service '${String(e)}' not registered`)}return this.resolveService(r)}catch(r){throw this.resolutionStack.pop(),r}finally{this.resolutionStack[this.resolutionStack.length-1]===e&&this.resolutionStack.pop(),t&&(this.resolutionStack=[]);}}resolveService(e){switch(e.lifetime){case i.Singleton:return this.resolveSingleton(e);case i.Scoped:return this.resolveScoped(e);case i.Transient:return this.resolveTransient(e);default:throw new Error(`Unknown lifetime: ${e.lifetime}`)}}resolveSingleton(e){let{serviceIdentifier:t}=e;if(this.singletons.has(t))return this.singletons.get(t);let r=this.createInstance(e);return this.singletons.set(t,r),r}resolveScoped(e){let{serviceIdentifier:t}=e;if(!this.parent)throw new Error(`Cannot resolve scoped service '${String(t)}' from root provider. Use createScope() first.`);if(this.scopedInstances.has(t))return this.scopedInstances.get(t);let r=this.createInstance(e);return this.scopedInstances.set(t,r),r}resolveTransient(e){return this.createInstance(e)}createInstance(e){if(e.implementationInstance!==void 0)return e.implementationInstance;if(e.implementationFactory)return e.implementationFactory(this);if(e.implementationType)return this.constructInstance(e);throw new Error(`Cannot create instance for service '${String(e.serviceIdentifier)}'`)}constructInstance(e){let{implementationType:t,dependencies:r}=e;if(!t)throw new Error("Implementation type is required");if(r&&r.length>0){let c=r.map(d=>this.getRequiredService(d));return new t(...c)}let p=(Reflect.getMetadata("design:paramtypes",t)||[]).map((c,d)=>{let P=Reflect.getMetadata("inject:params",t)?.[d];if(P)return this.getRequiredService(P);let R=c.name||c;return this.getRequiredService(R)});return new t(...p)}createScope(){let e=new l(this.serviceDescriptors,this);return {serviceProvider:e,dispose:n(()=>{e.scopedInstances.clear();},"dispose")}}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier===e)||(this.parent?.has(e)??false)}};n(l,"ServiceProvider");var u=l;var g=class g{constructor(){s(this,"serviceDescriptors",[]);}addSingleton(e,t){return typeof t=="function"?this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:i.Singleton}):this.serviceDescriptors.push({serviceIdentifier:e,implementationInstance:t,lifetime:i.Singleton}),this}addScoped(e,t){return this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:i.Scoped}),this}addTransient(e,t){return this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:i.Transient}),this}addFactory(e,t,r=i.Transient){return this.serviceDescriptors.push({serviceIdentifier:e,implementationFactory:t,lifetime:r}),this}addScopedWithDependencies(e,t,r){return this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:i.Scoped,dependencies:r}),this}buildServiceProvider(){return new u([...this.serviceDescriptors])}getDescriptors(){return [...this.serviceDescriptors]}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier===e)}get count(){return this.serviceDescriptors.length}};n(g,"ServiceCollection");var v=g;var S=class S{constructor(e){s(this,"request");s(this,"response");s(this,"metadata",new Map);this.request=e;}setMetadata(e,t){this.metadata.set(e,t);}getMetadata(e){return this.metadata.get(e)}};n(S,"PipelineContext");var f=S;var w=class w{constructor(e){s(this,"serviceProvider");s(this,"behaviors",[]);this.serviceProvider=e;let t=this.serviceProvider.getService("PipelineBehaviors");t&&(this.behaviors=t);}async send(e){let t=this.serviceProvider.createScope();try{let r=await this.executeHandler(e,t.serviceProvider);if(this.isAsyncIterable(r))throw new Error("Handler returned a stream. Use stream() method instead of send().");return r}finally{t.dispose();}}async stream(e){let t=this.serviceProvider.createScope();try{let r=await this.executeHandler(e,t.serviceProvider);if(!this.isAsyncIterable(r))throw new Error("Handler did not return a stream. Use send() method instead of stream().");return r}finally{t.dispose();}}async executeHandler(e,t){let r=t.getService(e.type);if(!r)throw new Error(`No handler registered for request type: ${String(e.type)}`);let a=new f(e);return this.behaviors.length===0?await r.handle(e):await this.executePipeline(a,r,this.behaviors)}async executePipeline(e,t,r){let a=0,p=n(async()=>{if(a<r.length)return await r[a++].handle(e,p);let c=await t.handle(e.request);return e.response=c,c},"next");return await p()}isAsyncIterable(e){return e!=null&&typeof e[Symbol.asyncIterator]=="function"}};n(w,"Mediator");var m=w;var y=class y{constructor(e,t,r){s(this,"serviceProvider");s(this,"mediator");s(this,"isRunning",false);s(this,"adapters");this.serviceProvider=e,this.mediator=t,this.adapters=r;}async run(){if(this.isRunning)throw new Error("Application is already running");for(let e of this.adapters)e.initialize&&await e.initialize(this);this.isRunning=true;}async stop(){if(this.isRunning){for(let e of [...this.adapters].reverse())e.dispose&&await e.dispose();this.isRunning=false;}}async send(e){if(!this.isRunning)throw new Error("Application must be running before sending requests. Call app.run() first.");return this.mediator.send(e)}async stream(e){if(!this.isRunning)throw new Error("Application must be running before streaming requests. Call app.run() first.");return this.mediator.stream(e)}getServiceProvider(){return this.serviceProvider}getMediator(){return this.mediator}get running(){return this.isRunning}};n(y,"Application");var h=y;var b="PipelineBehaviors",D=class D{constructor(){s(this,"services");s(this,"adapters",[]);s(this,"pipelineBehaviors",[]);this.services=new v;}registerHandler(e,t,r=i.Transient){if(typeof t=="function")switch(r){case i.Singleton:this.services.addSingleton(e,t);break;case i.Scoped:this.services.addScoped(e,t);break;case i.Transient:default:this.services.addTransient(e,t);break}else this.services.addSingleton(e,t);return this}registerHandlers(e){return e.forEach((t,r)=>{this.registerHandler(r,t);}),this}registerBehavior(e){return this.pipelineBehaviors.push(e),this}registerSingleton(e,t){return this.services.addSingleton(e,t),this}registerScoped(e,t){return this.services.addScoped(e,t),this}registerTransient(e,t){return this.services.addTransient(e,t),this}registerFactory(e,t,r=i.Transient){return this.services.addFactory(e,t,r),this}use(e){return this.adapters.push(e),this}getServiceCollection(){return this.services}async build(){for(let r of this.adapters)await r.configure(this.services);this.pipelineBehaviors.length>0&&this.services.addSingleton(b,this.pipelineBehaviors.map(r=>typeof r=="function"?new r:r));let e=this.services.buildServiceProvider(),t=new m(e);return new h(e,t,this.adapters)}};n(D,"ApplicationBuilder");var I=D;exports.Application=h;exports.ApplicationBuilder=I;
2
+ var E=Object.defineProperty;var T=(o,e,t)=>e in o?E(o,e,{enumerable:true,configurable:true,writable:true,value:t}):o[e]=t;var n=(o,e)=>E(o,"name",{value:e,configurable:true});var i=(o,e,t)=>T(o,typeof e!="symbol"?e+"":e,t);var s=(function(o){return o.Singleton="SINGLETON",o.Scoped="SCOPED",o.Transient="TRANSIENT",o})({});var l=class l{constructor(e,t){i(this,"serviceDescriptors");i(this,"singletons",new Map);i(this,"scopedInstances",new Map);i(this,"parent");i(this,"resolutionStack",[]);this.serviceDescriptors=e,this.parent=t;}getService(e){try{return this.getRequiredService(e.toString())}catch{return}}getRequiredService(e){let t=this.resolutionStack.length===0;if(this.resolutionStack.includes(e.toString())){let r=[...this.resolutionStack,e.toString()].map(a=>String(a)).join(" \u2192 ");throw new Error(`Circular dependency detected: ${r}`)}this.resolutionStack.push(e.toString());try{let r=this.serviceDescriptors.find(a=>a.serviceIdentifier.toString()===e.toString());if(!r){if(this.parent)return this.parent.getRequiredService(e.toString());throw new Error(`Service '${String(e)}' not registered`)}return this.resolveService(r)}catch(r){throw this.resolutionStack.pop(),r}finally{this.resolutionStack[this.resolutionStack.length-1]===e.toString()&&this.resolutionStack.pop(),t&&(this.resolutionStack=[]);}}resolveService(e){switch(e.lifetime){case s.Singleton:return this.resolveSingleton(e);case s.Scoped:return this.resolveScoped(e);case s.Transient:return this.resolveTransient(e);default:throw new Error(`Unknown lifetime: ${e.lifetime}`)}}resolveSingleton(e){let{serviceIdentifier:t}=e;if(this.singletons.has(t.toString()))return this.singletons.get(t.toString());let r=this.createInstance(e);return this.singletons.set(t.toString(),r),r}resolveScoped(e){let{serviceIdentifier:t}=e;if(!this.parent)throw new Error(`Cannot resolve scoped service '${String(t)}' from root provider. Use createScope() first.`);if(this.scopedInstances.has(t.toString()))return this.scopedInstances.get(t.toString());let r=this.createInstance(e);return this.scopedInstances.set(t.toString(),r),r}resolveTransient(e){return this.createInstance(e)}createInstance(e){if(e.implementationInstance!==void 0)return e.implementationInstance;if(e.implementationFactory)return e.implementationFactory(this);if(e.implementationType)return this.constructInstance(e);throw new Error(`Cannot create instance for service '${String(e.serviceIdentifier)}'`)}constructInstance(e){let{implementationType:t,dependencies:r}=e;if(!t)throw new Error("Implementation type is required");if(r&&r.length>0){let c=r.map(d=>this.getRequiredService(d));return new t(...c)}let p=(Reflect.getMetadata("design:paramtypes",t)||[]).map((c,d)=>{let P=Reflect.getMetadata("inject:params",t)?.[d];if(P)return this.getRequiredService(P);let R=c.name||c;return this.getRequiredService(R)});return new t(...p)}createScope(){let e=new l(this.serviceDescriptors,this);return {serviceProvider:e,dispose:n(()=>{e.scopedInstances.clear();},"dispose")}}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier.toString()===e.toString())||(this.parent?.has(e.toString())??false)}};n(l,"ServiceProvider");var u=l;var S=class S{constructor(){i(this,"serviceDescriptors",[]);}addSingleton(e,t){return typeof t=="function"?this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:s.Singleton}):this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationInstance:t,lifetime:s.Singleton}),this}addScoped(e,t){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:s.Scoped}),this}addTransient(e,t){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:s.Transient}),this}addFactory(e,t,r=s.Transient){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationFactory:t,lifetime:r}),this}addScopedWithDependencies(e,t,r){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:s.Scoped,dependencies:r}),this}buildServiceProvider(){return new u([...this.serviceDescriptors])}getDescriptors(){return [...this.serviceDescriptors]}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier.toString()===e.toString())}get count(){return this.serviceDescriptors.length}};n(S,"ServiceCollection");var v=S;var m=class m{constructor(e){i(this,"request");i(this,"response");i(this,"metadata",new Map);this.request=e;}setMetadata(e,t){this.metadata.set(e,t);}getMetadata(e){return this.metadata.get(e)}};n(m,"PipelineContext");var g=m;var w=class w{constructor(e){i(this,"serviceProvider");i(this,"behaviors",[]);this.serviceProvider=e;let t=this.serviceProvider.getService("PipelineBehaviors");t&&(this.behaviors=t);}async send(e){let t=this.serviceProvider.createScope();try{let r=await this.executeHandler(e,t.serviceProvider);if(this.isAsyncIterable(r))throw new Error("Handler returned a stream. Use stream() method instead of send().");return r}finally{t.dispose();}}async stream(e){let t=this.serviceProvider.createScope();try{let r=await this.executeHandler(e,t.serviceProvider);if(!this.isAsyncIterable(r))throw new Error("Handler did not return a stream. Use send() method instead of stream().");return r}finally{t.dispose();}}async executeHandler(e,t){let r=t.getService(e.type);if(!r)throw new Error(`No handler registered for request type: ${String(e.type)}`);let a=new g(e);return this.behaviors.length===0?await r.handle(e):await this.executePipeline(a,r,this.behaviors)}async executePipeline(e,t,r){let a=0,p=n(async()=>{if(a<r.length)return await r[a++].handle(e,p);let c=await t.handle(e.request);return e.response=c,c},"next");return await p()}isAsyncIterable(e){return e!=null&&typeof e[Symbol.asyncIterator]=="function"}};n(w,"Mediator");var f=w;var y=class y{constructor(e,t,r){i(this,"serviceProvider");i(this,"mediator");i(this,"isRunning",false);i(this,"adapters");this.serviceProvider=e,this.mediator=t,this.adapters=r;}async run(){if(this.isRunning)throw new Error("Application is already running");for(let e of this.adapters)e.initialize&&await e.initialize(this);this.isRunning=true;}async stop(){if(this.isRunning){for(let e of [...this.adapters].reverse())e.dispose&&await e.dispose();this.isRunning=false;}}async send(e){if(!this.isRunning)throw new Error("Application must be running before sending requests. Call app.run() first.");return this.mediator.send(e)}async stream(e){if(!this.isRunning)throw new Error("Application must be running before streaming requests. Call app.run() first.");return this.mediator.stream(e)}getServiceProvider(){return this.serviceProvider}getMediator(){return this.mediator}get running(){return this.isRunning}};n(y,"Application");var h=y;var b="PipelineBehaviors",D=class D{constructor(){i(this,"services");i(this,"adapters",[]);i(this,"pipelineBehaviors",[]);this.services=new v;}registerHandler(e,t,r=s.Transient){if(typeof t=="function")switch(r){case s.Singleton:this.services.addSingleton(e,t);break;case s.Scoped:this.services.addScoped(e,t);break;case s.Transient:default:this.services.addTransient(e,t);break}else this.services.addSingleton(e,t);return this}registerHandlers(e){return e.forEach((t,r)=>{this.registerHandler(r,t);}),this}registerBehavior(e){return this.pipelineBehaviors.push(e),this}registerSingleton(e,t){return this.services.addSingleton(e,t),this}registerScoped(e,t){return this.services.addScoped(e,t),this}registerTransient(e,t){return this.services.addTransient(e,t),this}registerFactory(e,t,r=s.Transient){return this.services.addFactory(e,t,r),this}use(e){return this.adapters.push(e),this}getServiceCollection(){return this.services}async build(){for(let r of this.adapters)await r.configure(this.services);this.pipelineBehaviors.length>0&&this.services.addSingleton(b,this.pipelineBehaviors.map(r=>typeof r=="function"?new r:r));let e=this.services.buildServiceProvider(),t=new f(e);return new h(e,t,this.adapters)}};n(D,"ApplicationBuilder");var I=D;exports.Application=h;exports.ApplicationBuilder=I;
@@ -1,2 +1,2 @@
1
1
  import'reflect-metadata';/* conduit - MIT License */
2
- var E=Object.defineProperty;var T=(o,e,t)=>e in o?E(o,e,{enumerable:true,configurable:true,writable:true,value:t}):o[e]=t;var n=(o,e)=>E(o,"name",{value:e,configurable:true});var s=(o,e,t)=>T(o,typeof e!="symbol"?e+"":e,t);var i=(function(o){return o.Singleton="SINGLETON",o.Scoped="SCOPED",o.Transient="TRANSIENT",o})({});var l=class l{constructor(e,t){s(this,"serviceDescriptors");s(this,"singletons",new Map);s(this,"scopedInstances",new Map);s(this,"parent");s(this,"resolutionStack",[]);this.serviceDescriptors=e,this.parent=t;}getService(e){try{return this.getRequiredService(e)}catch{return}}getRequiredService(e){let t=this.resolutionStack.length===0;if(this.resolutionStack.includes(e)){let r=[...this.resolutionStack,e].map(a=>String(a)).join(" \u2192 ");throw new Error(`Circular dependency detected: ${r}`)}this.resolutionStack.push(e);try{let r=this.serviceDescriptors.find(a=>a.serviceIdentifier===e);if(!r){if(this.parent)return this.parent.getRequiredService(e);throw new Error(`Service '${String(e)}' not registered`)}return this.resolveService(r)}catch(r){throw this.resolutionStack.pop(),r}finally{this.resolutionStack[this.resolutionStack.length-1]===e&&this.resolutionStack.pop(),t&&(this.resolutionStack=[]);}}resolveService(e){switch(e.lifetime){case i.Singleton:return this.resolveSingleton(e);case i.Scoped:return this.resolveScoped(e);case i.Transient:return this.resolveTransient(e);default:throw new Error(`Unknown lifetime: ${e.lifetime}`)}}resolveSingleton(e){let{serviceIdentifier:t}=e;if(this.singletons.has(t))return this.singletons.get(t);let r=this.createInstance(e);return this.singletons.set(t,r),r}resolveScoped(e){let{serviceIdentifier:t}=e;if(!this.parent)throw new Error(`Cannot resolve scoped service '${String(t)}' from root provider. Use createScope() first.`);if(this.scopedInstances.has(t))return this.scopedInstances.get(t);let r=this.createInstance(e);return this.scopedInstances.set(t,r),r}resolveTransient(e){return this.createInstance(e)}createInstance(e){if(e.implementationInstance!==void 0)return e.implementationInstance;if(e.implementationFactory)return e.implementationFactory(this);if(e.implementationType)return this.constructInstance(e);throw new Error(`Cannot create instance for service '${String(e.serviceIdentifier)}'`)}constructInstance(e){let{implementationType:t,dependencies:r}=e;if(!t)throw new Error("Implementation type is required");if(r&&r.length>0){let c=r.map(d=>this.getRequiredService(d));return new t(...c)}let p=(Reflect.getMetadata("design:paramtypes",t)||[]).map((c,d)=>{let P=Reflect.getMetadata("inject:params",t)?.[d];if(P)return this.getRequiredService(P);let R=c.name||c;return this.getRequiredService(R)});return new t(...p)}createScope(){let e=new l(this.serviceDescriptors,this);return {serviceProvider:e,dispose:n(()=>{e.scopedInstances.clear();},"dispose")}}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier===e)||(this.parent?.has(e)??false)}};n(l,"ServiceProvider");var u=l;var g=class g{constructor(){s(this,"serviceDescriptors",[]);}addSingleton(e,t){return typeof t=="function"?this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:i.Singleton}):this.serviceDescriptors.push({serviceIdentifier:e,implementationInstance:t,lifetime:i.Singleton}),this}addScoped(e,t){return this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:i.Scoped}),this}addTransient(e,t){return this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:i.Transient}),this}addFactory(e,t,r=i.Transient){return this.serviceDescriptors.push({serviceIdentifier:e,implementationFactory:t,lifetime:r}),this}addScopedWithDependencies(e,t,r){return this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:i.Scoped,dependencies:r}),this}buildServiceProvider(){return new u([...this.serviceDescriptors])}getDescriptors(){return [...this.serviceDescriptors]}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier===e)}get count(){return this.serviceDescriptors.length}};n(g,"ServiceCollection");var v=g;var S=class S{constructor(e){s(this,"request");s(this,"response");s(this,"metadata",new Map);this.request=e;}setMetadata(e,t){this.metadata.set(e,t);}getMetadata(e){return this.metadata.get(e)}};n(S,"PipelineContext");var f=S;var w=class w{constructor(e){s(this,"serviceProvider");s(this,"behaviors",[]);this.serviceProvider=e;let t=this.serviceProvider.getService("PipelineBehaviors");t&&(this.behaviors=t);}async send(e){let t=this.serviceProvider.createScope();try{let r=await this.executeHandler(e,t.serviceProvider);if(this.isAsyncIterable(r))throw new Error("Handler returned a stream. Use stream() method instead of send().");return r}finally{t.dispose();}}async stream(e){let t=this.serviceProvider.createScope();try{let r=await this.executeHandler(e,t.serviceProvider);if(!this.isAsyncIterable(r))throw new Error("Handler did not return a stream. Use send() method instead of stream().");return r}finally{t.dispose();}}async executeHandler(e,t){let r=t.getService(e.type);if(!r)throw new Error(`No handler registered for request type: ${String(e.type)}`);let a=new f(e);return this.behaviors.length===0?await r.handle(e):await this.executePipeline(a,r,this.behaviors)}async executePipeline(e,t,r){let a=0,p=n(async()=>{if(a<r.length)return await r[a++].handle(e,p);let c=await t.handle(e.request);return e.response=c,c},"next");return await p()}isAsyncIterable(e){return e!=null&&typeof e[Symbol.asyncIterator]=="function"}};n(w,"Mediator");var m=w;var y=class y{constructor(e,t,r){s(this,"serviceProvider");s(this,"mediator");s(this,"isRunning",false);s(this,"adapters");this.serviceProvider=e,this.mediator=t,this.adapters=r;}async run(){if(this.isRunning)throw new Error("Application is already running");for(let e of this.adapters)e.initialize&&await e.initialize(this);this.isRunning=true;}async stop(){if(this.isRunning){for(let e of [...this.adapters].reverse())e.dispose&&await e.dispose();this.isRunning=false;}}async send(e){if(!this.isRunning)throw new Error("Application must be running before sending requests. Call app.run() first.");return this.mediator.send(e)}async stream(e){if(!this.isRunning)throw new Error("Application must be running before streaming requests. Call app.run() first.");return this.mediator.stream(e)}getServiceProvider(){return this.serviceProvider}getMediator(){return this.mediator}get running(){return this.isRunning}};n(y,"Application");var h=y;var b="PipelineBehaviors",D=class D{constructor(){s(this,"services");s(this,"adapters",[]);s(this,"pipelineBehaviors",[]);this.services=new v;}registerHandler(e,t,r=i.Transient){if(typeof t=="function")switch(r){case i.Singleton:this.services.addSingleton(e,t);break;case i.Scoped:this.services.addScoped(e,t);break;case i.Transient:default:this.services.addTransient(e,t);break}else this.services.addSingleton(e,t);return this}registerHandlers(e){return e.forEach((t,r)=>{this.registerHandler(r,t);}),this}registerBehavior(e){return this.pipelineBehaviors.push(e),this}registerSingleton(e,t){return this.services.addSingleton(e,t),this}registerScoped(e,t){return this.services.addScoped(e,t),this}registerTransient(e,t){return this.services.addTransient(e,t),this}registerFactory(e,t,r=i.Transient){return this.services.addFactory(e,t,r),this}use(e){return this.adapters.push(e),this}getServiceCollection(){return this.services}async build(){for(let r of this.adapters)await r.configure(this.services);this.pipelineBehaviors.length>0&&this.services.addSingleton(b,this.pipelineBehaviors.map(r=>typeof r=="function"?new r:r));let e=this.services.buildServiceProvider(),t=new m(e);return new h(e,t,this.adapters)}};n(D,"ApplicationBuilder");var I=D;export{h as Application,I as ApplicationBuilder};
2
+ var E=Object.defineProperty;var T=(o,e,t)=>e in o?E(o,e,{enumerable:true,configurable:true,writable:true,value:t}):o[e]=t;var n=(o,e)=>E(o,"name",{value:e,configurable:true});var i=(o,e,t)=>T(o,typeof e!="symbol"?e+"":e,t);var s=(function(o){return o.Singleton="SINGLETON",o.Scoped="SCOPED",o.Transient="TRANSIENT",o})({});var l=class l{constructor(e,t){i(this,"serviceDescriptors");i(this,"singletons",new Map);i(this,"scopedInstances",new Map);i(this,"parent");i(this,"resolutionStack",[]);this.serviceDescriptors=e,this.parent=t;}getService(e){try{return this.getRequiredService(e.toString())}catch{return}}getRequiredService(e){let t=this.resolutionStack.length===0;if(this.resolutionStack.includes(e.toString())){let r=[...this.resolutionStack,e.toString()].map(a=>String(a)).join(" \u2192 ");throw new Error(`Circular dependency detected: ${r}`)}this.resolutionStack.push(e.toString());try{let r=this.serviceDescriptors.find(a=>a.serviceIdentifier.toString()===e.toString());if(!r){if(this.parent)return this.parent.getRequiredService(e.toString());throw new Error(`Service '${String(e)}' not registered`)}return this.resolveService(r)}catch(r){throw this.resolutionStack.pop(),r}finally{this.resolutionStack[this.resolutionStack.length-1]===e.toString()&&this.resolutionStack.pop(),t&&(this.resolutionStack=[]);}}resolveService(e){switch(e.lifetime){case s.Singleton:return this.resolveSingleton(e);case s.Scoped:return this.resolveScoped(e);case s.Transient:return this.resolveTransient(e);default:throw new Error(`Unknown lifetime: ${e.lifetime}`)}}resolveSingleton(e){let{serviceIdentifier:t}=e;if(this.singletons.has(t.toString()))return this.singletons.get(t.toString());let r=this.createInstance(e);return this.singletons.set(t.toString(),r),r}resolveScoped(e){let{serviceIdentifier:t}=e;if(!this.parent)throw new Error(`Cannot resolve scoped service '${String(t)}' from root provider. Use createScope() first.`);if(this.scopedInstances.has(t.toString()))return this.scopedInstances.get(t.toString());let r=this.createInstance(e);return this.scopedInstances.set(t.toString(),r),r}resolveTransient(e){return this.createInstance(e)}createInstance(e){if(e.implementationInstance!==void 0)return e.implementationInstance;if(e.implementationFactory)return e.implementationFactory(this);if(e.implementationType)return this.constructInstance(e);throw new Error(`Cannot create instance for service '${String(e.serviceIdentifier)}'`)}constructInstance(e){let{implementationType:t,dependencies:r}=e;if(!t)throw new Error("Implementation type is required");if(r&&r.length>0){let c=r.map(d=>this.getRequiredService(d));return new t(...c)}let p=(Reflect.getMetadata("design:paramtypes",t)||[]).map((c,d)=>{let P=Reflect.getMetadata("inject:params",t)?.[d];if(P)return this.getRequiredService(P);let R=c.name||c;return this.getRequiredService(R)});return new t(...p)}createScope(){let e=new l(this.serviceDescriptors,this);return {serviceProvider:e,dispose:n(()=>{e.scopedInstances.clear();},"dispose")}}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier.toString()===e.toString())||(this.parent?.has(e.toString())??false)}};n(l,"ServiceProvider");var u=l;var S=class S{constructor(){i(this,"serviceDescriptors",[]);}addSingleton(e,t){return typeof t=="function"?this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:s.Singleton}):this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationInstance:t,lifetime:s.Singleton}),this}addScoped(e,t){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:s.Scoped}),this}addTransient(e,t){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:s.Transient}),this}addFactory(e,t,r=s.Transient){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationFactory:t,lifetime:r}),this}addScopedWithDependencies(e,t,r){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:s.Scoped,dependencies:r}),this}buildServiceProvider(){return new u([...this.serviceDescriptors])}getDescriptors(){return [...this.serviceDescriptors]}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier.toString()===e.toString())}get count(){return this.serviceDescriptors.length}};n(S,"ServiceCollection");var v=S;var m=class m{constructor(e){i(this,"request");i(this,"response");i(this,"metadata",new Map);this.request=e;}setMetadata(e,t){this.metadata.set(e,t);}getMetadata(e){return this.metadata.get(e)}};n(m,"PipelineContext");var g=m;var w=class w{constructor(e){i(this,"serviceProvider");i(this,"behaviors",[]);this.serviceProvider=e;let t=this.serviceProvider.getService("PipelineBehaviors");t&&(this.behaviors=t);}async send(e){let t=this.serviceProvider.createScope();try{let r=await this.executeHandler(e,t.serviceProvider);if(this.isAsyncIterable(r))throw new Error("Handler returned a stream. Use stream() method instead of send().");return r}finally{t.dispose();}}async stream(e){let t=this.serviceProvider.createScope();try{let r=await this.executeHandler(e,t.serviceProvider);if(!this.isAsyncIterable(r))throw new Error("Handler did not return a stream. Use send() method instead of stream().");return r}finally{t.dispose();}}async executeHandler(e,t){let r=t.getService(e.type);if(!r)throw new Error(`No handler registered for request type: ${String(e.type)}`);let a=new g(e);return this.behaviors.length===0?await r.handle(e):await this.executePipeline(a,r,this.behaviors)}async executePipeline(e,t,r){let a=0,p=n(async()=>{if(a<r.length)return await r[a++].handle(e,p);let c=await t.handle(e.request);return e.response=c,c},"next");return await p()}isAsyncIterable(e){return e!=null&&typeof e[Symbol.asyncIterator]=="function"}};n(w,"Mediator");var f=w;var y=class y{constructor(e,t,r){i(this,"serviceProvider");i(this,"mediator");i(this,"isRunning",false);i(this,"adapters");this.serviceProvider=e,this.mediator=t,this.adapters=r;}async run(){if(this.isRunning)throw new Error("Application is already running");for(let e of this.adapters)e.initialize&&await e.initialize(this);this.isRunning=true;}async stop(){if(this.isRunning){for(let e of [...this.adapters].reverse())e.dispose&&await e.dispose();this.isRunning=false;}}async send(e){if(!this.isRunning)throw new Error("Application must be running before sending requests. Call app.run() first.");return this.mediator.send(e)}async stream(e){if(!this.isRunning)throw new Error("Application must be running before streaming requests. Call app.run() first.");return this.mediator.stream(e)}getServiceProvider(){return this.serviceProvider}getMediator(){return this.mediator}get running(){return this.isRunning}};n(y,"Application");var h=y;var b="PipelineBehaviors",D=class D{constructor(){i(this,"services");i(this,"adapters",[]);i(this,"pipelineBehaviors",[]);this.services=new v;}registerHandler(e,t,r=s.Transient){if(typeof t=="function")switch(r){case s.Singleton:this.services.addSingleton(e,t);break;case s.Scoped:this.services.addScoped(e,t);break;case s.Transient:default:this.services.addTransient(e,t);break}else this.services.addSingleton(e,t);return this}registerHandlers(e){return e.forEach((t,r)=>{this.registerHandler(r,t);}),this}registerBehavior(e){return this.pipelineBehaviors.push(e),this}registerSingleton(e,t){return this.services.addSingleton(e,t),this}registerScoped(e,t){return this.services.addScoped(e,t),this}registerTransient(e,t){return this.services.addTransient(e,t),this}registerFactory(e,t,r=s.Transient){return this.services.addFactory(e,t,r),this}use(e){return this.adapters.push(e),this}getServiceCollection(){return this.services}async build(){for(let r of this.adapters)await r.configure(this.services);this.pipelineBehaviors.length>0&&this.services.addSingleton(b,this.pipelineBehaviors.map(r=>typeof r=="function"?new r:r));let e=this.services.buildServiceProvider(),t=new f(e);return new h(e,t,this.adapters)}};n(D,"ApplicationBuilder");var I=D;export{h as Application,I as ApplicationBuilder};
@@ -1,5 +1,5 @@
1
- export { S as ServiceCollection } from '../ServiceCollection-3wUO7p8g.mjs';
2
- export { I as IServiceScope, a as ServiceDescriptor, b as ServiceLifetime, S as ServiceProvider } from '../ServiceProvider-BcW9XXlN.mjs';
1
+ export { S as ServiceCollection } from '../ServiceCollection-DbvEQOzY.mjs';
2
+ export { I as IServiceScope, a as ServiceDescriptor, b as ServiceLifetime, S as ServiceProvider } from '../ServiceProvider-BE1-lOxZ.mjs';
3
3
 
4
4
  declare function Inject(serviceIdentifier: string | symbol): ParameterDecorator;
5
5
 
@@ -1,5 +1,5 @@
1
- export { S as ServiceCollection } from '../ServiceCollection-B8PXr0Uo.js';
2
- export { I as IServiceScope, a as ServiceDescriptor, b as ServiceLifetime, S as ServiceProvider } from '../ServiceProvider-BcW9XXlN.js';
1
+ export { S as ServiceCollection } from '../ServiceCollection-DixtW4OW.js';
2
+ export { I as IServiceScope, a as ServiceDescriptor, b as ServiceLifetime, S as ServiceProvider } from '../ServiceProvider-BE1-lOxZ.js';
3
3
 
4
4
  declare function Inject(serviceIdentifier: string | symbol): ParameterDecorator;
5
5
 
package/dist/di/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  'use strict';require('reflect-metadata');/* conduit - MIT License */
2
- var S=Object.defineProperty;var g=(i,e,t)=>e in i?S(i,e,{enumerable:true,configurable:true,writable:true,value:t}):i[e]=t;var o=(i,e)=>S(i,"name",{value:e,configurable:true});var n=(i,e,t)=>g(i,typeof e!="symbol"?e+"":e,t);var s=(function(i){return i.Singleton="SINGLETON",i.Scoped="SCOPED",i.Transient="TRANSIENT",i})({});var l=class l{constructor(e,t){n(this,"serviceDescriptors");n(this,"singletons",new Map);n(this,"scopedInstances",new Map);n(this,"parent");n(this,"resolutionStack",[]);this.serviceDescriptors=e,this.parent=t;}getService(e){try{return this.getRequiredService(e)}catch{return}}getRequiredService(e){let t=this.resolutionStack.length===0;if(this.resolutionStack.includes(e)){let r=[...this.resolutionStack,e].map(c=>String(c)).join(" \u2192 ");throw new Error(`Circular dependency detected: ${r}`)}this.resolutionStack.push(e);try{let r=this.serviceDescriptors.find(c=>c.serviceIdentifier===e);if(!r){if(this.parent)return this.parent.getRequiredService(e);throw new Error(`Service '${String(e)}' not registered`)}return this.resolveService(r)}catch(r){throw this.resolutionStack.pop(),r}finally{this.resolutionStack[this.resolutionStack.length-1]===e&&this.resolutionStack.pop(),t&&(this.resolutionStack=[]);}}resolveService(e){switch(e.lifetime){case s.Singleton:return this.resolveSingleton(e);case s.Scoped:return this.resolveScoped(e);case s.Transient:return this.resolveTransient(e);default:throw new Error(`Unknown lifetime: ${e.lifetime}`)}}resolveSingleton(e){let{serviceIdentifier:t}=e;if(this.singletons.has(t))return this.singletons.get(t);let r=this.createInstance(e);return this.singletons.set(t,r),r}resolveScoped(e){let{serviceIdentifier:t}=e;if(!this.parent)throw new Error(`Cannot resolve scoped service '${String(t)}' from root provider. Use createScope() first.`);if(this.scopedInstances.has(t))return this.scopedInstances.get(t);let r=this.createInstance(e);return this.scopedInstances.set(t,r),r}resolveTransient(e){return this.createInstance(e)}createInstance(e){if(e.implementationInstance!==void 0)return e.implementationInstance;if(e.implementationFactory)return e.implementationFactory(this);if(e.implementationType)return this.constructInstance(e);throw new Error(`Cannot create instance for service '${String(e.serviceIdentifier)}'`)}constructInstance(e){let{implementationType:t,dependencies:r}=e;if(!t)throw new Error("Implementation type is required");if(r&&r.length>0){let h=r.map(u=>this.getRequiredService(u));return new t(...h)}let p=(Reflect.getMetadata("design:paramtypes",t)||[]).map((h,u)=>{let f=Reflect.getMetadata("inject:params",t)?.[u];if(f)return this.getRequiredService(f);let v=h.name||h;return this.getRequiredService(v)});return new t(...p)}createScope(){let e=new l(this.serviceDescriptors,this);return {serviceProvider:e,dispose:o(()=>{e.scopedInstances.clear();},"dispose")}}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier===e)||(this.parent?.has(e)??false)}};o(l,"ServiceProvider");var a=l;var d=class d{constructor(){n(this,"serviceDescriptors",[]);}addSingleton(e,t){return typeof t=="function"?this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:s.Singleton}):this.serviceDescriptors.push({serviceIdentifier:e,implementationInstance:t,lifetime:s.Singleton}),this}addScoped(e,t){return this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:s.Scoped}),this}addTransient(e,t){return this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:s.Transient}),this}addFactory(e,t,r=s.Transient){return this.serviceDescriptors.push({serviceIdentifier:e,implementationFactory:t,lifetime:r}),this}addScopedWithDependencies(e,t,r){return this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:s.Scoped,dependencies:r}),this}buildServiceProvider(){return new a([...this.serviceDescriptors])}getDescriptors(){return [...this.serviceDescriptors]}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier===e)}get count(){return this.serviceDescriptors.length}};o(d,"ServiceCollection");var m=d;function w(i){return (e,t,r)=>{let p={...Reflect.getOwnMetadata("inject:params",e)||{}};p[r]=i,Reflect.defineMetadata("inject:params",p,e);}}o(w,"Inject");exports.Inject=w;exports.ServiceCollection=m;exports.ServiceLifetime=s;exports.ServiceProvider=a;
2
+ var f=Object.defineProperty;var v=(i,e,t)=>e in i?f(i,e,{enumerable:true,configurable:true,writable:true,value:t}):i[e]=t;var o=(i,e)=>f(i,"name",{value:e,configurable:true});var s=(i,e,t)=>v(i,typeof e!="symbol"?e+"":e,t);var n=(function(i){return i.Singleton="SINGLETON",i.Scoped="SCOPED",i.Transient="TRANSIENT",i})({});var l=class l{constructor(e,t){s(this,"serviceDescriptors");s(this,"singletons",new Map);s(this,"scopedInstances",new Map);s(this,"parent");s(this,"resolutionStack",[]);this.serviceDescriptors=e,this.parent=t;}getService(e){try{return this.getRequiredService(e.toString())}catch{return}}getRequiredService(e){let t=this.resolutionStack.length===0;if(this.resolutionStack.includes(e.toString())){let r=[...this.resolutionStack,e.toString()].map(c=>String(c)).join(" \u2192 ");throw new Error(`Circular dependency detected: ${r}`)}this.resolutionStack.push(e.toString());try{let r=this.serviceDescriptors.find(c=>c.serviceIdentifier.toString()===e.toString());if(!r){if(this.parent)return this.parent.getRequiredService(e.toString());throw new Error(`Service '${String(e)}' not registered`)}return this.resolveService(r)}catch(r){throw this.resolutionStack.pop(),r}finally{this.resolutionStack[this.resolutionStack.length-1]===e.toString()&&this.resolutionStack.pop(),t&&(this.resolutionStack=[]);}}resolveService(e){switch(e.lifetime){case n.Singleton:return this.resolveSingleton(e);case n.Scoped:return this.resolveScoped(e);case n.Transient:return this.resolveTransient(e);default:throw new Error(`Unknown lifetime: ${e.lifetime}`)}}resolveSingleton(e){let{serviceIdentifier:t}=e;if(this.singletons.has(t.toString()))return this.singletons.get(t.toString());let r=this.createInstance(e);return this.singletons.set(t.toString(),r),r}resolveScoped(e){let{serviceIdentifier:t}=e;if(!this.parent)throw new Error(`Cannot resolve scoped service '${String(t)}' from root provider. Use createScope() first.`);if(this.scopedInstances.has(t.toString()))return this.scopedInstances.get(t.toString());let r=this.createInstance(e);return this.scopedInstances.set(t.toString(),r),r}resolveTransient(e){return this.createInstance(e)}createInstance(e){if(e.implementationInstance!==void 0)return e.implementationInstance;if(e.implementationFactory)return e.implementationFactory(this);if(e.implementationType)return this.constructInstance(e);throw new Error(`Cannot create instance for service '${String(e.serviceIdentifier)}'`)}constructInstance(e){let{implementationType:t,dependencies:r}=e;if(!t)throw new Error("Implementation type is required");if(r&&r.length>0){let h=r.map(u=>this.getRequiredService(u));return new t(...h)}let p=(Reflect.getMetadata("design:paramtypes",t)||[]).map((h,u)=>{let d=Reflect.getMetadata("inject:params",t)?.[u];if(d)return this.getRequiredService(d);let m=h.name||h;return this.getRequiredService(m)});return new t(...p)}createScope(){let e=new l(this.serviceDescriptors,this);return {serviceProvider:e,dispose:o(()=>{e.scopedInstances.clear();},"dispose")}}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier.toString()===e.toString())||(this.parent?.has(e.toString())??false)}};o(l,"ServiceProvider");var a=l;var g=class g{constructor(){s(this,"serviceDescriptors",[]);}addSingleton(e,t){return typeof t=="function"?this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:n.Singleton}):this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationInstance:t,lifetime:n.Singleton}),this}addScoped(e,t){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:n.Scoped}),this}addTransient(e,t){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:n.Transient}),this}addFactory(e,t,r=n.Transient){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationFactory:t,lifetime:r}),this}addScopedWithDependencies(e,t,r){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:n.Scoped,dependencies:r}),this}buildServiceProvider(){return new a([...this.serviceDescriptors])}getDescriptors(){return [...this.serviceDescriptors]}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier.toString()===e.toString())}get count(){return this.serviceDescriptors.length}};o(g,"ServiceCollection");var S=g;function I(i){return (e,t,r)=>{let p={...Reflect.getOwnMetadata("inject:params",e)||{}};p[r]=i,Reflect.defineMetadata("inject:params",p,e);}}o(I,"Inject");exports.Inject=I;exports.ServiceCollection=S;exports.ServiceLifetime=n;exports.ServiceProvider=a;
package/dist/di/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  import'reflect-metadata';/* conduit - MIT License */
2
- var S=Object.defineProperty;var g=(i,e,t)=>e in i?S(i,e,{enumerable:true,configurable:true,writable:true,value:t}):i[e]=t;var o=(i,e)=>S(i,"name",{value:e,configurable:true});var n=(i,e,t)=>g(i,typeof e!="symbol"?e+"":e,t);var s=(function(i){return i.Singleton="SINGLETON",i.Scoped="SCOPED",i.Transient="TRANSIENT",i})({});var l=class l{constructor(e,t){n(this,"serviceDescriptors");n(this,"singletons",new Map);n(this,"scopedInstances",new Map);n(this,"parent");n(this,"resolutionStack",[]);this.serviceDescriptors=e,this.parent=t;}getService(e){try{return this.getRequiredService(e)}catch{return}}getRequiredService(e){let t=this.resolutionStack.length===0;if(this.resolutionStack.includes(e)){let r=[...this.resolutionStack,e].map(c=>String(c)).join(" \u2192 ");throw new Error(`Circular dependency detected: ${r}`)}this.resolutionStack.push(e);try{let r=this.serviceDescriptors.find(c=>c.serviceIdentifier===e);if(!r){if(this.parent)return this.parent.getRequiredService(e);throw new Error(`Service '${String(e)}' not registered`)}return this.resolveService(r)}catch(r){throw this.resolutionStack.pop(),r}finally{this.resolutionStack[this.resolutionStack.length-1]===e&&this.resolutionStack.pop(),t&&(this.resolutionStack=[]);}}resolveService(e){switch(e.lifetime){case s.Singleton:return this.resolveSingleton(e);case s.Scoped:return this.resolveScoped(e);case s.Transient:return this.resolveTransient(e);default:throw new Error(`Unknown lifetime: ${e.lifetime}`)}}resolveSingleton(e){let{serviceIdentifier:t}=e;if(this.singletons.has(t))return this.singletons.get(t);let r=this.createInstance(e);return this.singletons.set(t,r),r}resolveScoped(e){let{serviceIdentifier:t}=e;if(!this.parent)throw new Error(`Cannot resolve scoped service '${String(t)}' from root provider. Use createScope() first.`);if(this.scopedInstances.has(t))return this.scopedInstances.get(t);let r=this.createInstance(e);return this.scopedInstances.set(t,r),r}resolveTransient(e){return this.createInstance(e)}createInstance(e){if(e.implementationInstance!==void 0)return e.implementationInstance;if(e.implementationFactory)return e.implementationFactory(this);if(e.implementationType)return this.constructInstance(e);throw new Error(`Cannot create instance for service '${String(e.serviceIdentifier)}'`)}constructInstance(e){let{implementationType:t,dependencies:r}=e;if(!t)throw new Error("Implementation type is required");if(r&&r.length>0){let h=r.map(u=>this.getRequiredService(u));return new t(...h)}let p=(Reflect.getMetadata("design:paramtypes",t)||[]).map((h,u)=>{let f=Reflect.getMetadata("inject:params",t)?.[u];if(f)return this.getRequiredService(f);let v=h.name||h;return this.getRequiredService(v)});return new t(...p)}createScope(){let e=new l(this.serviceDescriptors,this);return {serviceProvider:e,dispose:o(()=>{e.scopedInstances.clear();},"dispose")}}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier===e)||(this.parent?.has(e)??false)}};o(l,"ServiceProvider");var a=l;var d=class d{constructor(){n(this,"serviceDescriptors",[]);}addSingleton(e,t){return typeof t=="function"?this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:s.Singleton}):this.serviceDescriptors.push({serviceIdentifier:e,implementationInstance:t,lifetime:s.Singleton}),this}addScoped(e,t){return this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:s.Scoped}),this}addTransient(e,t){return this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:s.Transient}),this}addFactory(e,t,r=s.Transient){return this.serviceDescriptors.push({serviceIdentifier:e,implementationFactory:t,lifetime:r}),this}addScopedWithDependencies(e,t,r){return this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:s.Scoped,dependencies:r}),this}buildServiceProvider(){return new a([...this.serviceDescriptors])}getDescriptors(){return [...this.serviceDescriptors]}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier===e)}get count(){return this.serviceDescriptors.length}};o(d,"ServiceCollection");var m=d;function w(i){return (e,t,r)=>{let p={...Reflect.getOwnMetadata("inject:params",e)||{}};p[r]=i,Reflect.defineMetadata("inject:params",p,e);}}o(w,"Inject");export{w as Inject,m as ServiceCollection,s as ServiceLifetime,a as ServiceProvider};
2
+ var f=Object.defineProperty;var v=(i,e,t)=>e in i?f(i,e,{enumerable:true,configurable:true,writable:true,value:t}):i[e]=t;var o=(i,e)=>f(i,"name",{value:e,configurable:true});var s=(i,e,t)=>v(i,typeof e!="symbol"?e+"":e,t);var n=(function(i){return i.Singleton="SINGLETON",i.Scoped="SCOPED",i.Transient="TRANSIENT",i})({});var l=class l{constructor(e,t){s(this,"serviceDescriptors");s(this,"singletons",new Map);s(this,"scopedInstances",new Map);s(this,"parent");s(this,"resolutionStack",[]);this.serviceDescriptors=e,this.parent=t;}getService(e){try{return this.getRequiredService(e.toString())}catch{return}}getRequiredService(e){let t=this.resolutionStack.length===0;if(this.resolutionStack.includes(e.toString())){let r=[...this.resolutionStack,e.toString()].map(c=>String(c)).join(" \u2192 ");throw new Error(`Circular dependency detected: ${r}`)}this.resolutionStack.push(e.toString());try{let r=this.serviceDescriptors.find(c=>c.serviceIdentifier.toString()===e.toString());if(!r){if(this.parent)return this.parent.getRequiredService(e.toString());throw new Error(`Service '${String(e)}' not registered`)}return this.resolveService(r)}catch(r){throw this.resolutionStack.pop(),r}finally{this.resolutionStack[this.resolutionStack.length-1]===e.toString()&&this.resolutionStack.pop(),t&&(this.resolutionStack=[]);}}resolveService(e){switch(e.lifetime){case n.Singleton:return this.resolveSingleton(e);case n.Scoped:return this.resolveScoped(e);case n.Transient:return this.resolveTransient(e);default:throw new Error(`Unknown lifetime: ${e.lifetime}`)}}resolveSingleton(e){let{serviceIdentifier:t}=e;if(this.singletons.has(t.toString()))return this.singletons.get(t.toString());let r=this.createInstance(e);return this.singletons.set(t.toString(),r),r}resolveScoped(e){let{serviceIdentifier:t}=e;if(!this.parent)throw new Error(`Cannot resolve scoped service '${String(t)}' from root provider. Use createScope() first.`);if(this.scopedInstances.has(t.toString()))return this.scopedInstances.get(t.toString());let r=this.createInstance(e);return this.scopedInstances.set(t.toString(),r),r}resolveTransient(e){return this.createInstance(e)}createInstance(e){if(e.implementationInstance!==void 0)return e.implementationInstance;if(e.implementationFactory)return e.implementationFactory(this);if(e.implementationType)return this.constructInstance(e);throw new Error(`Cannot create instance for service '${String(e.serviceIdentifier)}'`)}constructInstance(e){let{implementationType:t,dependencies:r}=e;if(!t)throw new Error("Implementation type is required");if(r&&r.length>0){let h=r.map(u=>this.getRequiredService(u));return new t(...h)}let p=(Reflect.getMetadata("design:paramtypes",t)||[]).map((h,u)=>{let d=Reflect.getMetadata("inject:params",t)?.[u];if(d)return this.getRequiredService(d);let m=h.name||h;return this.getRequiredService(m)});return new t(...p)}createScope(){let e=new l(this.serviceDescriptors,this);return {serviceProvider:e,dispose:o(()=>{e.scopedInstances.clear();},"dispose")}}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier.toString()===e.toString())||(this.parent?.has(e.toString())??false)}};o(l,"ServiceProvider");var a=l;var g=class g{constructor(){s(this,"serviceDescriptors",[]);}addSingleton(e,t){return typeof t=="function"?this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:n.Singleton}):this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationInstance:t,lifetime:n.Singleton}),this}addScoped(e,t){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:n.Scoped}),this}addTransient(e,t){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:n.Transient}),this}addFactory(e,t,r=n.Transient){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationFactory:t,lifetime:r}),this}addScopedWithDependencies(e,t,r){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:n.Scoped,dependencies:r}),this}buildServiceProvider(){return new a([...this.serviceDescriptors])}getDescriptors(){return [...this.serviceDescriptors]}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier.toString()===e.toString())}get count(){return this.serviceDescriptors.length}};o(g,"ServiceCollection");var S=g;function I(i){return (e,t,r)=>{let p={...Reflect.getOwnMetadata("inject:params",e)||{}};p[r]=i,Reflect.defineMetadata("inject:params",p,e);}}o(I,"Inject");export{I as Inject,S as ServiceCollection,n as ServiceLifetime,a as ServiceProvider};
package/dist/index.d.mts CHANGED
@@ -1,8 +1,8 @@
1
- export { S as ServiceCollection } from './ServiceCollection-3wUO7p8g.mjs';
2
- export { I as IServiceScope, a as ServiceDescriptor, b as ServiceLifetime, S as ServiceProvider } from './ServiceProvider-BcW9XXlN.mjs';
1
+ export { S as ServiceCollection } from './ServiceCollection-DbvEQOzY.mjs';
2
+ export { I as IServiceScope, a as ServiceDescriptor, b as ServiceLifetime, S as ServiceProvider } from './ServiceProvider-BE1-lOxZ.mjs';
3
3
  export { Inject } from './di/index.mjs';
4
- export { B as BaseCommunicationObject, a as BaseRequest, b as BaseResponse, H as HandlerResult, I as IRequestHandler } from './IRequestHandler-x0c3xSqH.mjs';
5
- export { M as Mediator } from './Mediator-CBq5EqK5.mjs';
4
+ export { B as BaseCommunicationObject, a as BaseRequest, b as BaseResponse, H as HandlerResult, I as IRequestHandler } from './IRequestHandler-Dp4jjwcB.mjs';
5
+ export { M as Mediator } from './Mediator-IEaPewwN.mjs';
6
6
  export { SimpleHandler, StreamingHandler } from './mediator/index.mjs';
7
7
  export { IPipelineBehavior, PipelineContext, PipelineDelegate } from './pipeline/index.mjs';
8
8
  export { Application, ApplicationBuilder, IApplicationAdapter } from './application/index.mjs';
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- export { S as ServiceCollection } from './ServiceCollection-B8PXr0Uo.js';
2
- export { I as IServiceScope, a as ServiceDescriptor, b as ServiceLifetime, S as ServiceProvider } from './ServiceProvider-BcW9XXlN.js';
1
+ export { S as ServiceCollection } from './ServiceCollection-DixtW4OW.js';
2
+ export { I as IServiceScope, a as ServiceDescriptor, b as ServiceLifetime, S as ServiceProvider } from './ServiceProvider-BE1-lOxZ.js';
3
3
  export { Inject } from './di/index.js';
4
- export { B as BaseCommunicationObject, a as BaseRequest, b as BaseResponse, H as HandlerResult, I as IRequestHandler } from './IRequestHandler-x0c3xSqH.js';
5
- export { M as Mediator } from './Mediator-CnBmWM_n.js';
4
+ export { B as BaseCommunicationObject, a as BaseRequest, b as BaseResponse, H as HandlerResult, I as IRequestHandler } from './IRequestHandler-Dp4jjwcB.js';
5
+ export { M as Mediator } from './Mediator-DsZR19WY.js';
6
6
  export { SimpleHandler, StreamingHandler } from './mediator/index.js';
7
7
  export { IPipelineBehavior, PipelineContext, PipelineDelegate } from './pipeline/index.js';
8
8
  export { Application, ApplicationBuilder, IApplicationAdapter } from './application/index.js';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  'use strict';require('reflect-metadata');var uuid=require('uuid');/* conduit - MIT License */
2
- var H=Object.defineProperty;var F=(o,e,t)=>e in o?H(o,e,{enumerable:true,configurable:true,writable:true,value:t}):o[e]=t;var i=(o,e)=>H(o,"name",{value:e,configurable:true});var s=(o,e,t)=>F(o,typeof e!="symbol"?e+"":e,t);var n=(function(o){return o.Singleton="SINGLETON",o.Scoped="SCOPED",o.Transient="TRANSIENT",o})({});var g=class g{constructor(e,t){s(this,"serviceDescriptors");s(this,"singletons",new Map);s(this,"scopedInstances",new Map);s(this,"parent");s(this,"resolutionStack",[]);this.serviceDescriptors=e,this.parent=t;}getService(e){try{return this.getRequiredService(e)}catch{return}}getRequiredService(e){let t=this.resolutionStack.length===0;if(this.resolutionStack.includes(e)){let r=[...this.resolutionStack,e].map(a=>String(a)).join(" \u2192 ");throw new Error(`Circular dependency detected: ${r}`)}this.resolutionStack.push(e);try{let r=this.serviceDescriptors.find(a=>a.serviceIdentifier===e);if(!r){if(this.parent)return this.parent.getRequiredService(e);throw new Error(`Service '${String(e)}' not registered`)}return this.resolveService(r)}catch(r){throw this.resolutionStack.pop(),r}finally{this.resolutionStack[this.resolutionStack.length-1]===e&&this.resolutionStack.pop(),t&&(this.resolutionStack=[]);}}resolveService(e){switch(e.lifetime){case n.Singleton:return this.resolveSingleton(e);case n.Scoped:return this.resolveScoped(e);case n.Transient:return this.resolveTransient(e);default:throw new Error(`Unknown lifetime: ${e.lifetime}`)}}resolveSingleton(e){let{serviceIdentifier:t}=e;if(this.singletons.has(t))return this.singletons.get(t);let r=this.createInstance(e);return this.singletons.set(t,r),r}resolveScoped(e){let{serviceIdentifier:t}=e;if(!this.parent)throw new Error(`Cannot resolve scoped service '${String(t)}' from root provider. Use createScope() first.`);if(this.scopedInstances.has(t))return this.scopedInstances.get(t);let r=this.createInstance(e);return this.scopedInstances.set(t,r),r}resolveTransient(e){return this.createInstance(e)}createInstance(e){if(e.implementationInstance!==void 0)return e.implementationInstance;if(e.implementationFactory)return e.implementationFactory(this);if(e.implementationType)return this.constructInstance(e);throw new Error(`Cannot create instance for service '${String(e.serviceIdentifier)}'`)}constructInstance(e){let{implementationType:t,dependencies:r}=e;if(!t)throw new Error("Implementation type is required");if(r&&r.length>0){let h=r.map(v=>this.getRequiredService(v));return new t(...h)}let c=(Reflect.getMetadata("design:paramtypes",t)||[]).map((h,v)=>{let A=Reflect.getMetadata("inject:params",t)?.[v];if(A)return this.getRequiredService(A);let q=h.name||h;return this.getRequiredService(q)});return new t(...c)}createScope(){let e=new g(this.serviceDescriptors,this);return {serviceProvider:e,dispose:i(()=>{e.scopedInstances.clear();},"dispose")}}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier===e)||(this.parent?.has(e)??false)}};i(g,"ServiceProvider");var u=g;var S=class S{constructor(){s(this,"serviceDescriptors",[]);}addSingleton(e,t){return typeof t=="function"?this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:n.Singleton}):this.serviceDescriptors.push({serviceIdentifier:e,implementationInstance:t,lifetime:n.Singleton}),this}addScoped(e,t){return this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:n.Scoped}),this}addTransient(e,t){return this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:n.Transient}),this}addFactory(e,t,r=n.Transient){return this.serviceDescriptors.push({serviceIdentifier:e,implementationFactory:t,lifetime:r}),this}addScopedWithDependencies(e,t,r){return this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:n.Scoped,dependencies:r}),this}buildServiceProvider(){return new u([...this.serviceDescriptors])}getDescriptors(){return [...this.serviceDescriptors]}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier===e)}get count(){return this.serviceDescriptors.length}};i(S,"ServiceCollection");var d=S;function N(o){return (e,t,r)=>{let c={...Reflect.getOwnMetadata("inject:params",e)||{}};c[r]=o,Reflect.defineMetadata("inject:params",c,e);}}i(N,"Inject");var w=class w{constructor(e){s(this,"request");s(this,"response");s(this,"metadata",new Map);this.request=e;}setMetadata(e,t){this.metadata.set(e,t);}getMetadata(e){return this.metadata.get(e)}};i(w,"PipelineContext");var l=w;var y=class y{constructor(e){s(this,"serviceProvider");s(this,"behaviors",[]);this.serviceProvider=e;let t=this.serviceProvider.getService("PipelineBehaviors");t&&(this.behaviors=t);}async send(e){let t=this.serviceProvider.createScope();try{let r=await this.executeHandler(e,t.serviceProvider);if(this.isAsyncIterable(r))throw new Error("Handler returned a stream. Use stream() method instead of send().");return r}finally{t.dispose();}}async stream(e){let t=this.serviceProvider.createScope();try{let r=await this.executeHandler(e,t.serviceProvider);if(!this.isAsyncIterable(r))throw new Error("Handler did not return a stream. Use send() method instead of stream().");return r}finally{t.dispose();}}async executeHandler(e,t){let r=t.getService(e.type);if(!r)throw new Error(`No handler registered for request type: ${String(e.type)}`);let a=new l(e);return this.behaviors.length===0?await r.handle(e):await this.executePipeline(a,r,this.behaviors)}async executePipeline(e,t,r){let a=0,c=i(async()=>{if(a<r.length)return await r[a++].handle(e,c);let h=await t.handle(e.request);return e.response=h,h},"next");return await c()}isAsyncIterable(e){return e!=null&&typeof e[Symbol.asyncIterator]=="function"}};i(y,"Mediator");var m=y;var D=class D{handle(e){return this.handleSimple(e)}};i(D,"SimpleHandler");var x=D,P=class P{handle(e){return this.handleStream(e)}};i(P,"StreamingHandler");var I=P;var E=class E{constructor(e){s(this,"type");this.type=e;}};i(E,"BaseCommunicationObject");var p=E;var R=class R extends p{constructor(t){super(t);s(this,"uuid");s(this,"timestamp");this.uuid=uuid.v4(),this.timestamp=new Date;}};i(R,"BaseRequest");var b=R;var k=class k extends p{constructor(t){super(t);s(this,"success");s(this,"errors");s(this,"timestamp");this.timestamp=new Date,this.success=true;}setErrors(t){return this.success=false,this.errors=t,this}addError(t){return this.errors||(this.errors=[]),this.errors.push(t),this.success=false,this}};i(k,"BaseResponse");var T=k;var M=class M{constructor(e,t,r){s(this,"serviceProvider");s(this,"mediator");s(this,"isRunning",false);s(this,"adapters");this.serviceProvider=e,this.mediator=t,this.adapters=r;}async run(){if(this.isRunning)throw new Error("Application is already running");for(let e of this.adapters)e.initialize&&await e.initialize(this);this.isRunning=true;}async stop(){if(this.isRunning){for(let e of [...this.adapters].reverse())e.dispose&&await e.dispose();this.isRunning=false;}}async send(e){if(!this.isRunning)throw new Error("Application must be running before sending requests. Call app.run() first.");return this.mediator.send(e)}async stream(e){if(!this.isRunning)throw new Error("Application must be running before streaming requests. Call app.run() first.");return this.mediator.stream(e)}getServiceProvider(){return this.serviceProvider}getMediator(){return this.mediator}get running(){return this.isRunning}};i(M,"Application");var f=M;var B="PipelineBehaviors",C=class C{constructor(){s(this,"services");s(this,"adapters",[]);s(this,"pipelineBehaviors",[]);this.services=new d;}registerHandler(e,t,r=n.Transient){if(typeof t=="function")switch(r){case n.Singleton:this.services.addSingleton(e,t);break;case n.Scoped:this.services.addScoped(e,t);break;case n.Transient:default:this.services.addTransient(e,t);break}else this.services.addSingleton(e,t);return this}registerHandlers(e){return e.forEach((t,r)=>{this.registerHandler(r,t);}),this}registerBehavior(e){return this.pipelineBehaviors.push(e),this}registerSingleton(e,t){return this.services.addSingleton(e,t),this}registerScoped(e,t){return this.services.addScoped(e,t),this}registerTransient(e,t){return this.services.addTransient(e,t),this}registerFactory(e,t,r=n.Transient){return this.services.addFactory(e,t,r),this}use(e){return this.adapters.push(e),this}getServiceCollection(){return this.services}async build(){for(let r of this.adapters)await r.configure(this.services);this.pipelineBehaviors.length>0&&this.services.addSingleton(B,this.pipelineBehaviors.map(r=>typeof r=="function"?new r:r));let e=this.services.buildServiceProvider(),t=new m(e);return new f(e,t,this.adapters)}};i(C,"ApplicationBuilder");var j=C;exports.Application=f;exports.ApplicationBuilder=j;exports.BaseCommunicationObject=p;exports.BaseRequest=b;exports.BaseResponse=T;exports.Inject=N;exports.Mediator=m;exports.PipelineContext=l;exports.ServiceCollection=d;exports.ServiceLifetime=n;exports.ServiceProvider=u;exports.SimpleHandler=x;exports.StreamingHandler=I;
2
+ var H=Object.defineProperty;var F=(o,e,t)=>e in o?H(o,e,{enumerable:true,configurable:true,writable:true,value:t}):o[e]=t;var s=(o,e)=>H(o,"name",{value:e,configurable:true});var i=(o,e,t)=>F(o,typeof e!="symbol"?e+"":e,t);var n=(function(o){return o.Singleton="SINGLETON",o.Scoped="SCOPED",o.Transient="TRANSIENT",o})({});var g=class g{constructor(e,t){i(this,"serviceDescriptors");i(this,"singletons",new Map);i(this,"scopedInstances",new Map);i(this,"parent");i(this,"resolutionStack",[]);this.serviceDescriptors=e,this.parent=t;}getService(e){try{return this.getRequiredService(e.toString())}catch{return}}getRequiredService(e){let t=this.resolutionStack.length===0;if(this.resolutionStack.includes(e.toString())){let r=[...this.resolutionStack,e.toString()].map(a=>String(a)).join(" \u2192 ");throw new Error(`Circular dependency detected: ${r}`)}this.resolutionStack.push(e.toString());try{let r=this.serviceDescriptors.find(a=>a.serviceIdentifier.toString()===e.toString());if(!r){if(this.parent)return this.parent.getRequiredService(e.toString());throw new Error(`Service '${String(e)}' not registered`)}return this.resolveService(r)}catch(r){throw this.resolutionStack.pop(),r}finally{this.resolutionStack[this.resolutionStack.length-1]===e.toString()&&this.resolutionStack.pop(),t&&(this.resolutionStack=[]);}}resolveService(e){switch(e.lifetime){case n.Singleton:return this.resolveSingleton(e);case n.Scoped:return this.resolveScoped(e);case n.Transient:return this.resolveTransient(e);default:throw new Error(`Unknown lifetime: ${e.lifetime}`)}}resolveSingleton(e){let{serviceIdentifier:t}=e;if(this.singletons.has(t.toString()))return this.singletons.get(t.toString());let r=this.createInstance(e);return this.singletons.set(t.toString(),r),r}resolveScoped(e){let{serviceIdentifier:t}=e;if(!this.parent)throw new Error(`Cannot resolve scoped service '${String(t)}' from root provider. Use createScope() first.`);if(this.scopedInstances.has(t.toString()))return this.scopedInstances.get(t.toString());let r=this.createInstance(e);return this.scopedInstances.set(t.toString(),r),r}resolveTransient(e){return this.createInstance(e)}createInstance(e){if(e.implementationInstance!==void 0)return e.implementationInstance;if(e.implementationFactory)return e.implementationFactory(this);if(e.implementationType)return this.constructInstance(e);throw new Error(`Cannot create instance for service '${String(e.serviceIdentifier)}'`)}constructInstance(e){let{implementationType:t,dependencies:r}=e;if(!t)throw new Error("Implementation type is required");if(r&&r.length>0){let h=r.map(v=>this.getRequiredService(v));return new t(...h)}let c=(Reflect.getMetadata("design:paramtypes",t)||[]).map((h,v)=>{let A=Reflect.getMetadata("inject:params",t)?.[v];if(A)return this.getRequiredService(A);let q=h.name||h;return this.getRequiredService(q)});return new t(...c)}createScope(){let e=new g(this.serviceDescriptors,this);return {serviceProvider:e,dispose:s(()=>{e.scopedInstances.clear();},"dispose")}}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier.toString()===e.toString())||(this.parent?.has(e.toString())??false)}};s(g,"ServiceProvider");var d=g;var S=class S{constructor(){i(this,"serviceDescriptors",[]);}addSingleton(e,t){return typeof t=="function"?this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:n.Singleton}):this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationInstance:t,lifetime:n.Singleton}),this}addScoped(e,t){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:n.Scoped}),this}addTransient(e,t){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:n.Transient}),this}addFactory(e,t,r=n.Transient){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationFactory:t,lifetime:r}),this}addScopedWithDependencies(e,t,r){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:n.Scoped,dependencies:r}),this}buildServiceProvider(){return new d([...this.serviceDescriptors])}getDescriptors(){return [...this.serviceDescriptors]}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier.toString()===e.toString())}get count(){return this.serviceDescriptors.length}};s(S,"ServiceCollection");var u=S;function N(o){return (e,t,r)=>{let c={...Reflect.getOwnMetadata("inject:params",e)||{}};c[r]=o,Reflect.defineMetadata("inject:params",c,e);}}s(N,"Inject");var w=class w{constructor(e){i(this,"request");i(this,"response");i(this,"metadata",new Map);this.request=e;}setMetadata(e,t){this.metadata.set(e,t);}getMetadata(e){return this.metadata.get(e)}};s(w,"PipelineContext");var l=w;var y=class y{constructor(e){i(this,"serviceProvider");i(this,"behaviors",[]);this.serviceProvider=e;let t=this.serviceProvider.getService("PipelineBehaviors");t&&(this.behaviors=t);}async send(e){let t=this.serviceProvider.createScope();try{let r=await this.executeHandler(e,t.serviceProvider);if(this.isAsyncIterable(r))throw new Error("Handler returned a stream. Use stream() method instead of send().");return r}finally{t.dispose();}}async stream(e){let t=this.serviceProvider.createScope();try{let r=await this.executeHandler(e,t.serviceProvider);if(!this.isAsyncIterable(r))throw new Error("Handler did not return a stream. Use send() method instead of stream().");return r}finally{t.dispose();}}async executeHandler(e,t){let r=t.getService(e.type);if(!r)throw new Error(`No handler registered for request type: ${String(e.type)}`);let a=new l(e);return this.behaviors.length===0?await r.handle(e):await this.executePipeline(a,r,this.behaviors)}async executePipeline(e,t,r){let a=0,c=s(async()=>{if(a<r.length)return await r[a++].handle(e,c);let h=await t.handle(e.request);return e.response=h,h},"next");return await c()}isAsyncIterable(e){return e!=null&&typeof e[Symbol.asyncIterator]=="function"}};s(y,"Mediator");var f=y;var D=class D{handle(e){return this.handleSimple(e)}};s(D,"SimpleHandler");var x=D,P=class P{handle(e){return this.handleStream(e)}};s(P,"StreamingHandler");var I=P;var E=class E{constructor(e){i(this,"type");this.type=e.toString();}};s(E,"BaseCommunicationObject");var p=E;var R=class R extends p{constructor(t){super(t);i(this,"uuid");i(this,"timestamp");this.uuid=uuid.v4(),this.timestamp=new Date;}};s(R,"BaseRequest");var b=R;var k=class k extends p{constructor(t){super(t);i(this,"success");i(this,"errors");i(this,"timestamp");this.timestamp=new Date,this.success=true;}setErrors(t){return this.success=false,this.errors=t,this}addError(t){return this.errors||(this.errors=[]),this.errors.push(t),this.success=false,this}};s(k,"BaseResponse");var T=k;var M=class M{constructor(e,t,r){i(this,"serviceProvider");i(this,"mediator");i(this,"isRunning",false);i(this,"adapters");this.serviceProvider=e,this.mediator=t,this.adapters=r;}async run(){if(this.isRunning)throw new Error("Application is already running");for(let e of this.adapters)e.initialize&&await e.initialize(this);this.isRunning=true;}async stop(){if(this.isRunning){for(let e of [...this.adapters].reverse())e.dispose&&await e.dispose();this.isRunning=false;}}async send(e){if(!this.isRunning)throw new Error("Application must be running before sending requests. Call app.run() first.");return this.mediator.send(e)}async stream(e){if(!this.isRunning)throw new Error("Application must be running before streaming requests. Call app.run() first.");return this.mediator.stream(e)}getServiceProvider(){return this.serviceProvider}getMediator(){return this.mediator}get running(){return this.isRunning}};s(M,"Application");var m=M;var B="PipelineBehaviors",C=class C{constructor(){i(this,"services");i(this,"adapters",[]);i(this,"pipelineBehaviors",[]);this.services=new u;}registerHandler(e,t,r=n.Transient){if(typeof t=="function")switch(r){case n.Singleton:this.services.addSingleton(e,t);break;case n.Scoped:this.services.addScoped(e,t);break;case n.Transient:default:this.services.addTransient(e,t);break}else this.services.addSingleton(e,t);return this}registerHandlers(e){return e.forEach((t,r)=>{this.registerHandler(r,t);}),this}registerBehavior(e){return this.pipelineBehaviors.push(e),this}registerSingleton(e,t){return this.services.addSingleton(e,t),this}registerScoped(e,t){return this.services.addScoped(e,t),this}registerTransient(e,t){return this.services.addTransient(e,t),this}registerFactory(e,t,r=n.Transient){return this.services.addFactory(e,t,r),this}use(e){return this.adapters.push(e),this}getServiceCollection(){return this.services}async build(){for(let r of this.adapters)await r.configure(this.services);this.pipelineBehaviors.length>0&&this.services.addSingleton(B,this.pipelineBehaviors.map(r=>typeof r=="function"?new r:r));let e=this.services.buildServiceProvider(),t=new f(e);return new m(e,t,this.adapters)}};s(C,"ApplicationBuilder");var j=C;exports.Application=m;exports.ApplicationBuilder=j;exports.BaseCommunicationObject=p;exports.BaseRequest=b;exports.BaseResponse=T;exports.Inject=N;exports.Mediator=f;exports.PipelineContext=l;exports.ServiceCollection=u;exports.ServiceLifetime=n;exports.ServiceProvider=d;exports.SimpleHandler=x;exports.StreamingHandler=I;
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  import'reflect-metadata';import {v4}from'uuid';/* conduit - MIT License */
2
- var H=Object.defineProperty;var F=(o,e,t)=>e in o?H(o,e,{enumerable:true,configurable:true,writable:true,value:t}):o[e]=t;var i=(o,e)=>H(o,"name",{value:e,configurable:true});var s=(o,e,t)=>F(o,typeof e!="symbol"?e+"":e,t);var n=(function(o){return o.Singleton="SINGLETON",o.Scoped="SCOPED",o.Transient="TRANSIENT",o})({});var g=class g{constructor(e,t){s(this,"serviceDescriptors");s(this,"singletons",new Map);s(this,"scopedInstances",new Map);s(this,"parent");s(this,"resolutionStack",[]);this.serviceDescriptors=e,this.parent=t;}getService(e){try{return this.getRequiredService(e)}catch{return}}getRequiredService(e){let t=this.resolutionStack.length===0;if(this.resolutionStack.includes(e)){let r=[...this.resolutionStack,e].map(a=>String(a)).join(" \u2192 ");throw new Error(`Circular dependency detected: ${r}`)}this.resolutionStack.push(e);try{let r=this.serviceDescriptors.find(a=>a.serviceIdentifier===e);if(!r){if(this.parent)return this.parent.getRequiredService(e);throw new Error(`Service '${String(e)}' not registered`)}return this.resolveService(r)}catch(r){throw this.resolutionStack.pop(),r}finally{this.resolutionStack[this.resolutionStack.length-1]===e&&this.resolutionStack.pop(),t&&(this.resolutionStack=[]);}}resolveService(e){switch(e.lifetime){case n.Singleton:return this.resolveSingleton(e);case n.Scoped:return this.resolveScoped(e);case n.Transient:return this.resolveTransient(e);default:throw new Error(`Unknown lifetime: ${e.lifetime}`)}}resolveSingleton(e){let{serviceIdentifier:t}=e;if(this.singletons.has(t))return this.singletons.get(t);let r=this.createInstance(e);return this.singletons.set(t,r),r}resolveScoped(e){let{serviceIdentifier:t}=e;if(!this.parent)throw new Error(`Cannot resolve scoped service '${String(t)}' from root provider. Use createScope() first.`);if(this.scopedInstances.has(t))return this.scopedInstances.get(t);let r=this.createInstance(e);return this.scopedInstances.set(t,r),r}resolveTransient(e){return this.createInstance(e)}createInstance(e){if(e.implementationInstance!==void 0)return e.implementationInstance;if(e.implementationFactory)return e.implementationFactory(this);if(e.implementationType)return this.constructInstance(e);throw new Error(`Cannot create instance for service '${String(e.serviceIdentifier)}'`)}constructInstance(e){let{implementationType:t,dependencies:r}=e;if(!t)throw new Error("Implementation type is required");if(r&&r.length>0){let h=r.map(v=>this.getRequiredService(v));return new t(...h)}let c=(Reflect.getMetadata("design:paramtypes",t)||[]).map((h,v)=>{let A=Reflect.getMetadata("inject:params",t)?.[v];if(A)return this.getRequiredService(A);let q=h.name||h;return this.getRequiredService(q)});return new t(...c)}createScope(){let e=new g(this.serviceDescriptors,this);return {serviceProvider:e,dispose:i(()=>{e.scopedInstances.clear();},"dispose")}}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier===e)||(this.parent?.has(e)??false)}};i(g,"ServiceProvider");var u=g;var S=class S{constructor(){s(this,"serviceDescriptors",[]);}addSingleton(e,t){return typeof t=="function"?this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:n.Singleton}):this.serviceDescriptors.push({serviceIdentifier:e,implementationInstance:t,lifetime:n.Singleton}),this}addScoped(e,t){return this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:n.Scoped}),this}addTransient(e,t){return this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:n.Transient}),this}addFactory(e,t,r=n.Transient){return this.serviceDescriptors.push({serviceIdentifier:e,implementationFactory:t,lifetime:r}),this}addScopedWithDependencies(e,t,r){return this.serviceDescriptors.push({serviceIdentifier:e,implementationType:t,lifetime:n.Scoped,dependencies:r}),this}buildServiceProvider(){return new u([...this.serviceDescriptors])}getDescriptors(){return [...this.serviceDescriptors]}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier===e)}get count(){return this.serviceDescriptors.length}};i(S,"ServiceCollection");var d=S;function N(o){return (e,t,r)=>{let c={...Reflect.getOwnMetadata("inject:params",e)||{}};c[r]=o,Reflect.defineMetadata("inject:params",c,e);}}i(N,"Inject");var w=class w{constructor(e){s(this,"request");s(this,"response");s(this,"metadata",new Map);this.request=e;}setMetadata(e,t){this.metadata.set(e,t);}getMetadata(e){return this.metadata.get(e)}};i(w,"PipelineContext");var l=w;var y=class y{constructor(e){s(this,"serviceProvider");s(this,"behaviors",[]);this.serviceProvider=e;let t=this.serviceProvider.getService("PipelineBehaviors");t&&(this.behaviors=t);}async send(e){let t=this.serviceProvider.createScope();try{let r=await this.executeHandler(e,t.serviceProvider);if(this.isAsyncIterable(r))throw new Error("Handler returned a stream. Use stream() method instead of send().");return r}finally{t.dispose();}}async stream(e){let t=this.serviceProvider.createScope();try{let r=await this.executeHandler(e,t.serviceProvider);if(!this.isAsyncIterable(r))throw new Error("Handler did not return a stream. Use send() method instead of stream().");return r}finally{t.dispose();}}async executeHandler(e,t){let r=t.getService(e.type);if(!r)throw new Error(`No handler registered for request type: ${String(e.type)}`);let a=new l(e);return this.behaviors.length===0?await r.handle(e):await this.executePipeline(a,r,this.behaviors)}async executePipeline(e,t,r){let a=0,c=i(async()=>{if(a<r.length)return await r[a++].handle(e,c);let h=await t.handle(e.request);return e.response=h,h},"next");return await c()}isAsyncIterable(e){return e!=null&&typeof e[Symbol.asyncIterator]=="function"}};i(y,"Mediator");var m=y;var D=class D{handle(e){return this.handleSimple(e)}};i(D,"SimpleHandler");var x=D,P=class P{handle(e){return this.handleStream(e)}};i(P,"StreamingHandler");var I=P;var E=class E{constructor(e){s(this,"type");this.type=e;}};i(E,"BaseCommunicationObject");var p=E;var R=class R extends p{constructor(t){super(t);s(this,"uuid");s(this,"timestamp");this.uuid=v4(),this.timestamp=new Date;}};i(R,"BaseRequest");var b=R;var k=class k extends p{constructor(t){super(t);s(this,"success");s(this,"errors");s(this,"timestamp");this.timestamp=new Date,this.success=true;}setErrors(t){return this.success=false,this.errors=t,this}addError(t){return this.errors||(this.errors=[]),this.errors.push(t),this.success=false,this}};i(k,"BaseResponse");var T=k;var M=class M{constructor(e,t,r){s(this,"serviceProvider");s(this,"mediator");s(this,"isRunning",false);s(this,"adapters");this.serviceProvider=e,this.mediator=t,this.adapters=r;}async run(){if(this.isRunning)throw new Error("Application is already running");for(let e of this.adapters)e.initialize&&await e.initialize(this);this.isRunning=true;}async stop(){if(this.isRunning){for(let e of [...this.adapters].reverse())e.dispose&&await e.dispose();this.isRunning=false;}}async send(e){if(!this.isRunning)throw new Error("Application must be running before sending requests. Call app.run() first.");return this.mediator.send(e)}async stream(e){if(!this.isRunning)throw new Error("Application must be running before streaming requests. Call app.run() first.");return this.mediator.stream(e)}getServiceProvider(){return this.serviceProvider}getMediator(){return this.mediator}get running(){return this.isRunning}};i(M,"Application");var f=M;var B="PipelineBehaviors",C=class C{constructor(){s(this,"services");s(this,"adapters",[]);s(this,"pipelineBehaviors",[]);this.services=new d;}registerHandler(e,t,r=n.Transient){if(typeof t=="function")switch(r){case n.Singleton:this.services.addSingleton(e,t);break;case n.Scoped:this.services.addScoped(e,t);break;case n.Transient:default:this.services.addTransient(e,t);break}else this.services.addSingleton(e,t);return this}registerHandlers(e){return e.forEach((t,r)=>{this.registerHandler(r,t);}),this}registerBehavior(e){return this.pipelineBehaviors.push(e),this}registerSingleton(e,t){return this.services.addSingleton(e,t),this}registerScoped(e,t){return this.services.addScoped(e,t),this}registerTransient(e,t){return this.services.addTransient(e,t),this}registerFactory(e,t,r=n.Transient){return this.services.addFactory(e,t,r),this}use(e){return this.adapters.push(e),this}getServiceCollection(){return this.services}async build(){for(let r of this.adapters)await r.configure(this.services);this.pipelineBehaviors.length>0&&this.services.addSingleton(B,this.pipelineBehaviors.map(r=>typeof r=="function"?new r:r));let e=this.services.buildServiceProvider(),t=new m(e);return new f(e,t,this.adapters)}};i(C,"ApplicationBuilder");var j=C;export{f as Application,j as ApplicationBuilder,p as BaseCommunicationObject,b as BaseRequest,T as BaseResponse,N as Inject,m as Mediator,l as PipelineContext,d as ServiceCollection,n as ServiceLifetime,u as ServiceProvider,x as SimpleHandler,I as StreamingHandler};
2
+ var H=Object.defineProperty;var F=(o,e,t)=>e in o?H(o,e,{enumerable:true,configurable:true,writable:true,value:t}):o[e]=t;var s=(o,e)=>H(o,"name",{value:e,configurable:true});var i=(o,e,t)=>F(o,typeof e!="symbol"?e+"":e,t);var n=(function(o){return o.Singleton="SINGLETON",o.Scoped="SCOPED",o.Transient="TRANSIENT",o})({});var g=class g{constructor(e,t){i(this,"serviceDescriptors");i(this,"singletons",new Map);i(this,"scopedInstances",new Map);i(this,"parent");i(this,"resolutionStack",[]);this.serviceDescriptors=e,this.parent=t;}getService(e){try{return this.getRequiredService(e.toString())}catch{return}}getRequiredService(e){let t=this.resolutionStack.length===0;if(this.resolutionStack.includes(e.toString())){let r=[...this.resolutionStack,e.toString()].map(a=>String(a)).join(" \u2192 ");throw new Error(`Circular dependency detected: ${r}`)}this.resolutionStack.push(e.toString());try{let r=this.serviceDescriptors.find(a=>a.serviceIdentifier.toString()===e.toString());if(!r){if(this.parent)return this.parent.getRequiredService(e.toString());throw new Error(`Service '${String(e)}' not registered`)}return this.resolveService(r)}catch(r){throw this.resolutionStack.pop(),r}finally{this.resolutionStack[this.resolutionStack.length-1]===e.toString()&&this.resolutionStack.pop(),t&&(this.resolutionStack=[]);}}resolveService(e){switch(e.lifetime){case n.Singleton:return this.resolveSingleton(e);case n.Scoped:return this.resolveScoped(e);case n.Transient:return this.resolveTransient(e);default:throw new Error(`Unknown lifetime: ${e.lifetime}`)}}resolveSingleton(e){let{serviceIdentifier:t}=e;if(this.singletons.has(t.toString()))return this.singletons.get(t.toString());let r=this.createInstance(e);return this.singletons.set(t.toString(),r),r}resolveScoped(e){let{serviceIdentifier:t}=e;if(!this.parent)throw new Error(`Cannot resolve scoped service '${String(t)}' from root provider. Use createScope() first.`);if(this.scopedInstances.has(t.toString()))return this.scopedInstances.get(t.toString());let r=this.createInstance(e);return this.scopedInstances.set(t.toString(),r),r}resolveTransient(e){return this.createInstance(e)}createInstance(e){if(e.implementationInstance!==void 0)return e.implementationInstance;if(e.implementationFactory)return e.implementationFactory(this);if(e.implementationType)return this.constructInstance(e);throw new Error(`Cannot create instance for service '${String(e.serviceIdentifier)}'`)}constructInstance(e){let{implementationType:t,dependencies:r}=e;if(!t)throw new Error("Implementation type is required");if(r&&r.length>0){let h=r.map(v=>this.getRequiredService(v));return new t(...h)}let c=(Reflect.getMetadata("design:paramtypes",t)||[]).map((h,v)=>{let A=Reflect.getMetadata("inject:params",t)?.[v];if(A)return this.getRequiredService(A);let q=h.name||h;return this.getRequiredService(q)});return new t(...c)}createScope(){let e=new g(this.serviceDescriptors,this);return {serviceProvider:e,dispose:s(()=>{e.scopedInstances.clear();},"dispose")}}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier.toString()===e.toString())||(this.parent?.has(e.toString())??false)}};s(g,"ServiceProvider");var d=g;var S=class S{constructor(){i(this,"serviceDescriptors",[]);}addSingleton(e,t){return typeof t=="function"?this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:n.Singleton}):this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationInstance:t,lifetime:n.Singleton}),this}addScoped(e,t){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:n.Scoped}),this}addTransient(e,t){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:n.Transient}),this}addFactory(e,t,r=n.Transient){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationFactory:t,lifetime:r}),this}addScopedWithDependencies(e,t,r){return this.serviceDescriptors.push({serviceIdentifier:e.toString(),implementationType:t,lifetime:n.Scoped,dependencies:r}),this}buildServiceProvider(){return new d([...this.serviceDescriptors])}getDescriptors(){return [...this.serviceDescriptors]}has(e){return this.serviceDescriptors.some(t=>t.serviceIdentifier.toString()===e.toString())}get count(){return this.serviceDescriptors.length}};s(S,"ServiceCollection");var u=S;function N(o){return (e,t,r)=>{let c={...Reflect.getOwnMetadata("inject:params",e)||{}};c[r]=o,Reflect.defineMetadata("inject:params",c,e);}}s(N,"Inject");var w=class w{constructor(e){i(this,"request");i(this,"response");i(this,"metadata",new Map);this.request=e;}setMetadata(e,t){this.metadata.set(e,t);}getMetadata(e){return this.metadata.get(e)}};s(w,"PipelineContext");var l=w;var y=class y{constructor(e){i(this,"serviceProvider");i(this,"behaviors",[]);this.serviceProvider=e;let t=this.serviceProvider.getService("PipelineBehaviors");t&&(this.behaviors=t);}async send(e){let t=this.serviceProvider.createScope();try{let r=await this.executeHandler(e,t.serviceProvider);if(this.isAsyncIterable(r))throw new Error("Handler returned a stream. Use stream() method instead of send().");return r}finally{t.dispose();}}async stream(e){let t=this.serviceProvider.createScope();try{let r=await this.executeHandler(e,t.serviceProvider);if(!this.isAsyncIterable(r))throw new Error("Handler did not return a stream. Use send() method instead of stream().");return r}finally{t.dispose();}}async executeHandler(e,t){let r=t.getService(e.type);if(!r)throw new Error(`No handler registered for request type: ${String(e.type)}`);let a=new l(e);return this.behaviors.length===0?await r.handle(e):await this.executePipeline(a,r,this.behaviors)}async executePipeline(e,t,r){let a=0,c=s(async()=>{if(a<r.length)return await r[a++].handle(e,c);let h=await t.handle(e.request);return e.response=h,h},"next");return await c()}isAsyncIterable(e){return e!=null&&typeof e[Symbol.asyncIterator]=="function"}};s(y,"Mediator");var f=y;var D=class D{handle(e){return this.handleSimple(e)}};s(D,"SimpleHandler");var x=D,P=class P{handle(e){return this.handleStream(e)}};s(P,"StreamingHandler");var I=P;var E=class E{constructor(e){i(this,"type");this.type=e.toString();}};s(E,"BaseCommunicationObject");var p=E;var R=class R extends p{constructor(t){super(t);i(this,"uuid");i(this,"timestamp");this.uuid=v4(),this.timestamp=new Date;}};s(R,"BaseRequest");var b=R;var k=class k extends p{constructor(t){super(t);i(this,"success");i(this,"errors");i(this,"timestamp");this.timestamp=new Date,this.success=true;}setErrors(t){return this.success=false,this.errors=t,this}addError(t){return this.errors||(this.errors=[]),this.errors.push(t),this.success=false,this}};s(k,"BaseResponse");var T=k;var M=class M{constructor(e,t,r){i(this,"serviceProvider");i(this,"mediator");i(this,"isRunning",false);i(this,"adapters");this.serviceProvider=e,this.mediator=t,this.adapters=r;}async run(){if(this.isRunning)throw new Error("Application is already running");for(let e of this.adapters)e.initialize&&await e.initialize(this);this.isRunning=true;}async stop(){if(this.isRunning){for(let e of [...this.adapters].reverse())e.dispose&&await e.dispose();this.isRunning=false;}}async send(e){if(!this.isRunning)throw new Error("Application must be running before sending requests. Call app.run() first.");return this.mediator.send(e)}async stream(e){if(!this.isRunning)throw new Error("Application must be running before streaming requests. Call app.run() first.");return this.mediator.stream(e)}getServiceProvider(){return this.serviceProvider}getMediator(){return this.mediator}get running(){return this.isRunning}};s(M,"Application");var m=M;var B="PipelineBehaviors",C=class C{constructor(){i(this,"services");i(this,"adapters",[]);i(this,"pipelineBehaviors",[]);this.services=new u;}registerHandler(e,t,r=n.Transient){if(typeof t=="function")switch(r){case n.Singleton:this.services.addSingleton(e,t);break;case n.Scoped:this.services.addScoped(e,t);break;case n.Transient:default:this.services.addTransient(e,t);break}else this.services.addSingleton(e,t);return this}registerHandlers(e){return e.forEach((t,r)=>{this.registerHandler(r,t);}),this}registerBehavior(e){return this.pipelineBehaviors.push(e),this}registerSingleton(e,t){return this.services.addSingleton(e,t),this}registerScoped(e,t){return this.services.addScoped(e,t),this}registerTransient(e,t){return this.services.addTransient(e,t),this}registerFactory(e,t,r=n.Transient){return this.services.addFactory(e,t,r),this}use(e){return this.adapters.push(e),this}getServiceCollection(){return this.services}async build(){for(let r of this.adapters)await r.configure(this.services);this.pipelineBehaviors.length>0&&this.services.addSingleton(B,this.pipelineBehaviors.map(r=>typeof r=="function"?new r:r));let e=this.services.buildServiceProvider(),t=new f(e);return new m(e,t,this.adapters)}};s(C,"ApplicationBuilder");var j=C;export{m as Application,j as ApplicationBuilder,p as BaseCommunicationObject,b as BaseRequest,T as BaseResponse,N as Inject,f as Mediator,l as PipelineContext,u as ServiceCollection,n as ServiceLifetime,d as ServiceProvider,x as SimpleHandler,I as StreamingHandler};
@@ -1,7 +1,7 @@
1
- import { a as BaseRequest, b as BaseResponse, I as IRequestHandler } from '../IRequestHandler-x0c3xSqH.mjs';
2
- export { H as HandlerResult } from '../IRequestHandler-x0c3xSqH.mjs';
3
- export { M as Mediator } from '../Mediator-CBq5EqK5.mjs';
4
- import '../ServiceProvider-BcW9XXlN.mjs';
1
+ import { a as BaseRequest, b as BaseResponse, I as IRequestHandler } from '../IRequestHandler-Dp4jjwcB.mjs';
2
+ export { H as HandlerResult } from '../IRequestHandler-Dp4jjwcB.mjs';
3
+ export { M as Mediator } from '../Mediator-IEaPewwN.mjs';
4
+ import '../ServiceProvider-BE1-lOxZ.mjs';
5
5
 
6
6
  declare abstract class SimpleHandler<TRequest extends BaseRequest, TResponse extends BaseResponse> implements IRequestHandler<TRequest, TResponse> {
7
7
  protected abstract handleSimple(request: TRequest): Promise<TResponse>;
@@ -1,7 +1,7 @@
1
- import { a as BaseRequest, b as BaseResponse, I as IRequestHandler } from '../IRequestHandler-x0c3xSqH.js';
2
- export { H as HandlerResult } from '../IRequestHandler-x0c3xSqH.js';
3
- export { M as Mediator } from '../Mediator-CnBmWM_n.js';
4
- import '../ServiceProvider-BcW9XXlN.js';
1
+ import { a as BaseRequest, b as BaseResponse, I as IRequestHandler } from '../IRequestHandler-Dp4jjwcB.js';
2
+ export { H as HandlerResult } from '../IRequestHandler-Dp4jjwcB.js';
3
+ export { M as Mediator } from '../Mediator-DsZR19WY.js';
4
+ import '../ServiceProvider-BE1-lOxZ.js';
5
5
 
6
6
  declare abstract class SimpleHandler<TRequest extends BaseRequest, TResponse extends BaseResponse> implements IRequestHandler<TRequest, TResponse> {
7
7
  protected abstract handleSimple(request: TRequest): Promise<TResponse>;
@@ -1,4 +1,4 @@
1
- import { a as BaseRequest, b as BaseResponse, H as HandlerResult } from '../IRequestHandler-x0c3xSqH.mjs';
1
+ import { a as BaseRequest, b as BaseResponse, H as HandlerResult } from '../IRequestHandler-Dp4jjwcB.mjs';
2
2
 
3
3
  declare class PipelineContext {
4
4
  readonly request: BaseRequest;
@@ -1,4 +1,4 @@
1
- import { a as BaseRequest, b as BaseResponse, H as HandlerResult } from '../IRequestHandler-x0c3xSqH.js';
1
+ import { a as BaseRequest, b as BaseResponse, H as HandlerResult } from '../IRequestHandler-Dp4jjwcB.js';
2
2
 
3
3
  declare class PipelineContext {
4
4
  readonly request: BaseRequest;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oldzy/conduit",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Transport-agnostic request/response pipeline framework with mediator pattern, dependency injection, and middleware support",
5
5
  "author": "oldzy",
6
6
  "license": "MIT",