@artstesh/postboy 3.4.2 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var rxjs=require('rxjs');var d=class{constructor(){this.metadata={};}get id(){return this.constructor.ID}setMetadata(e){return this.metadata={...this.metadata,...e},this}};var P=class extends d{};function i(o){if(!o.ID)throw new Error(`${o.name} should have a static ID field`);return o.ID}var l=class{constructor(e,t){this.subscription=e;this._subscription=t?t(e):e.asObservable();}sub(){return this._subscription}fire(e){this.subscription.next(e);}finish(){this.subscription.complete();}};var M=(r=>(r[r.Publish=1]="Publish",r[r.Callback=2]="Callback",r[r.Execute=3]="Execute",r))(M||{});var j=(t=>(t[t.Continue=1]="Continue",t[t.Interrupt=2]="Interrupt",t))(j||{});var T=class extends Error{constructor(e){super(e.reason??`Postboy operation was cancelled at stage "${M[e.stage]}"`),this.name="PostboyCancelError",this.details=e;}};var E=class{constructor(){this.middlewares=[];}addMiddleware(e){this.middlewares.push(e);}removeMiddleware(e){this.middlewares=this.middlewares.filter(t=>t!==e?true:(t.dispose(),false));}dispose(){this.middlewares.forEach(e=>e.dispose()),this.middlewares=[];}before(e,t){for(let r of this.middlewares){let a=this.buildContext(e,t);r.canHandle(a)&&r.before(a).type===2&&this.throwIfCancelled(e,r.name,t.id);}}after(e,t,r){for(let a of this.middlewares){let g=this.buildContext(e,t);a.canHandle(g)&&a.after(g,r);}}beforePublish(e){this.before(1,e);}afterPublish(e){this.after(1,e);}beforeCallback(e){this.before(2,e);}afterCallback(e,t){this.after(2,e,t);}beforeExecute(e){this.before(3,e);}afterExecute(e,t){this.after(3,e,t);}buildContext(e,t){return {stage:e,message:t}}throwIfCancelled(e,t,r,a){throw new T({stage:e,middleware:t,messageId:r,namespace:a,reason:t?`Cancelled by middleware "${t}"`:void 0})}};var w=class{constructor(){this.messages=new Map;this.executors=new Map;this.callbacks=new Map;}registerMessage(e,t){this.messages.has(e)&&console.warn(`Message with id ${e} already registered. Overriding...`),this.messages.set(e,t);}registerExecutor(e,t){this.executors.has(e)&&console.warn(`Executor with id ${e} already registered. Overriding...`),this.executors.set(e,t);}callbackFired(e){let t=this.callbacks.get(e.id);t?t.push(()=>e.complete()):this.callbacks.set(e.id,[()=>e.complete()]);}getMessage(e,t){let r=this.messages.get(e);if(!r)throw new Error(`There is no registered event ${t}`);return r}getExecutor(e){let t=this.executors.get(e);if(!t)throw new Error(`There is no registered executor with id ${e}`);return t}unregister(e){this.messages.get(e)?.finish(),this.messages.delete(e),this.callbacks.get(e)?.forEach(t=>t()),this.callbacks.delete(e),this.executors.delete(e);}dispose(){this.messages.forEach((e,t)=>this.unregister(t)),this.callbacks.forEach(e=>e.forEach(t=>t())),this.messages.clear(),this.executors.clear(),this.callbacks.clear();}};var C=class C{static get(){let e=[];for(let t=0;t<7;t++)e.push(C.collection.sort(()=>.5-Math.random()).slice(0,5).join(""));return e.join("-")}};C.collection="ABCDEFGHIJKLMNOPQRSTUVWXTZ0123456789".split("");var S=C;var s=class extends d{};var c=class extends s{constructor(t,r,a){super();this.type=t;this.sub=r;this.pipe=a;}};c.ID="aa03a192-bdc7-402d-9f2f-bf3748229ea2";var n=class extends s{constructor(t){super();this.messageId=t;}};n.ID="94579e43-5bc9-4517-bcda-b595bcda1ae7";var p=class extends s{constructor(t,r){super();this.type=t;this.exec=r;}};p.ID="cb80e8ad-b68c-4b2d-8c44-617ea6017cb3";var b=class extends s{constructor(t,r){super();this.executor=t;this.handler=r;}};b.ID="bf618cea-6f32-417c-9548-8eafe937378b";var R=class{constructor(e,t=null){this.postboy=e;this.ids=[];this.services=[];this._namespace=t??S.get();}get namespace(){return this._namespace}registerServices(e){this.services=e;}up(){this._up?.(),this.services.forEach(e=>e.up());}down(){this.services.forEach(e=>!!e.down&&e.down()),this.services=[],this.ids.forEach(e=>this.postboy.exec(new n(e)));}record(e,t){return this.ids.push(i(e)),this.postboy.exec(new c(e,t)),this}recordWithPipe(e,t,r){return this.ids.push(i(e)),this.postboy.exec(new c(e,t,r)),this}recordExecutor(e,t){return this.ids.push(i(e)),this.postboy.exec(new p(e,t)),this}recordHandler(e,t){return this.ids.push(i(e)),this.postboy.exec(new b(e,t)),this}recordReplay(e,t=1){return this.record(e,new rxjs.ReplaySubject(t)),this}recordBehavior(e,t){return this.record(e,new rxjs.BehaviorSubject(t)),this}recordSubject(e){return this.record(e,new rxjs.Subject),this}};var D=class extends R{constructor(e){super(e);}_up(){}};var v=class{constructor(){this.spaces=new Map;}addSpace(e,t){if(this.spaces.has(e))return this.spaces.get(e);let r=new D(t);return this.spaces.set(e,r),r}eliminateSpace(e){this.spaces.has(e)&&(this.spaces.get(e)?.down(),this.spaces.delete(e));}dispose(){this.spaces.forEach(e=>e.down()),this.spaces.clear();}};var I=class{constructor(){this.getMiddlewareService=()=>new E;this.getMessageStore=()=>new w;this.getNamespaceStore=()=>new v;}};var u=class extends s{constructor(t){super();this.space=t;}};u.ID="6d1a6f7d-6b6e-4c4d-8af8-9cc9a32e850c";var m=class extends s{constructor(t){super();this.space=t;}};m.ID="03bb03bb-53e0-4b74-9aad-64d5c54a8972";var f=class extends s{constructor(t){super();this.middleware=t;}};f.ID="0a8cfe0a-6193-4082-8440-d0793367b21d";var y=class extends s{constructor(t){super();this.middleware=t;}};y.ID="c25c708c-53c9-498d-a28b-936fbaf68b91";var x=class extends s{constructor(t){super();this.type=t;}};x.ID="477df3e2-1f99-4476-9a3b-afd1fa426436";var h=class extends s{constructor(t){super();this.type=t;}};h.ID="d71d25e3-90ac-4009-b972-9e6c6b05611e";var A=class{constructor(e){this.locked=new Set;this.dependencyResolver=e||new I,this.middleware=this.dependencyResolver.getMiddlewareService(),this.store=this.dependencyResolver.getMessageStore(),this.namespaceStore=this.dependencyResolver.getNamespaceStore(),this.registerInfrastructureMessages();}registerInfrastructureMessages(){this.store.registerExecutor(n.ID,e=>this.store.unregister(e.messageId)),this.store.registerExecutor(h.ID,e=>this.locked.delete(i(e.type))),this.store.registerExecutor(x.ID,e=>this.locked.add(i(e.type))),this.store.registerExecutor(f.ID,e=>this.middleware.addMiddleware(e.middleware)),this.store.registerExecutor(y.ID,e=>this.middleware.removeMiddleware(e.middleware)),this.store.registerExecutor(u.ID,e=>this.namespaceStore.addSpace(e.space,this)),this.store.registerExecutor(m.ID,e=>this.namespaceStore.eliminateSpace(e.space)),this.store.registerExecutor(c.ID,e=>{let{type:t,sub:r,pipe:a}=e;this.store.registerMessage(i(t),new l(r,a));}),this.store.registerExecutor(p.ID,e=>{let{type:t,exec:r}=e;this.store.registerExecutor(i(t),r);}),this.store.registerExecutor(b.ID,e=>{let{executor:t,handler:r}=e;this.store.registerExecutor(i(t),a=>r.handle(a));});}fire(e){this.middleware.beforePublish(e),this.locked.has(e.id)||this.store.getMessage(e.id,e.constructor.name).fire(e),this.middleware.afterPublish(e);}fireCallback(e,t){this.middleware.beforeCallback(e),t&&e.result.subscribe(t),this.store.callbackFired(e);let r=t?e.result.pipe(rxjs.tap(t)):e.result,a=this.store.getMessage(e.id,e.constructor.name),g=new rxjs.Observable($=>{let _=r.pipe(rxjs.tap(()=>this.middleware.afterCallback(e))).subscribe($);return this.locked.has(e.id)||a.fire(e),()=>_.unsubscribe()});return t&&g.subscribe(),g}exec(e){this.middleware.beforeExecute(e);let t=this.store.getExecutor(e.id)(e);return this.middleware.afterExecute(e,t),t}sub(e){return this.store.getMessage(i(e),e.name).sub()}once(e){return this.sub(e).pipe(rxjs.first())}record(e,t){this.store.registerMessage(i(e),new l(t,r=>r.asObservable()));}recordWithPipe(e,t,r){this.store.registerMessage(i(e),new l(t,r));}recordExecutor(e,t){this.store.registerExecutor(i(e),t);}recordHandler(e,t){this.store.registerExecutor(i(e),r=>t.handle(r));}dispose(){this.namespaceStore?.dispose(),this.store.dispose(),this.middleware.dispose();}};var H=class{constructor(e){this.name=e??this.constructor.name;}canHandle(e){return true}before(e){return {type:1}}after(e,t){}dispose(){}};var k=class extends P{constructor(){super(...arguments);this.result$=new rxjs.Subject;this.result=this.result$.asObservable();this.next=t=>this.result$.next(t);}finish(t){this.result$.next(t),this.result$.complete();}complete(){this.result$.complete();}};var O=class{};exports.AddMiddleware=f;exports.AddNamespace=u;exports.CancelError=T;exports.ConnectExecutor=p;exports.ConnectHandler=b;exports.ConnectMessage=c;exports.DisconnectMessage=n;exports.EliminateNamespace=m;exports.LockMessage=x;exports.MiddlewareDecisionType=j;exports.MiddlewareStage=M;exports.PostboyAbstractRegistrator=R;exports.PostboyCallbackMessage=k;exports.PostboyExecutionHandler=O;exports.PostboyExecutor=s;exports.PostboyGenericMessage=P;exports.PostboyMessage=d;exports.PostboyMessageStore=w;exports.PostboyMiddleware=H;exports.PostboyMiddlewareService=E;exports.PostboyNamespaceStore=v;exports.PostboyService=A;exports.PostboySubscription=l;exports.RemoveMiddleware=y;exports.UnlockMessage=h;//# sourceMappingURL=index.cjs.map
1
+ 'use strict';var rxjs=require('rxjs');var d=class{constructor(){this.metadata={};}get id(){return this.constructor.ID}setMetadata(e){return this.metadata={...this.metadata,...e},this}};var P=class extends d{};function i(o){if(!o.ID)throw new Error(`${o.name} should have a static ID field`);return o.ID}var l=class{constructor(e,t){this.subscription=e;this._subscription=t?t(e):e.asObservable();}sub(){return this._subscription}fire(e){this.subscription.next(e);}finish(){this.subscription.complete();}};var M=(r=>(r[r.Publish=1]="Publish",r[r.Callback=2]="Callback",r[r.Execute=3]="Execute",r))(M||{});var j=(t=>(t[t.Continue=1]="Continue",t[t.Interrupt=2]="Interrupt",t))(j||{});var T=class extends Error{constructor(e){super(e.reason??`Postboy operation was cancelled at stage "${M[e.stage]}"`),this.name="PostboyCancelError",this.details=e;}};var E=class{constructor(){this.middlewares=[];}addMiddleware(e){this.middlewares.push(e);}removeMiddleware(e){this.middlewares=this.middlewares.filter(t=>t!==e?true:(t.dispose(),false));}dispose(){this.middlewares.forEach(e=>e.dispose()),this.middlewares=[];}before(e,t){for(let r of this.middlewares){let a=this.buildContext(e,t);r.canHandle(a)&&r.before(a).type===2&&this.throwIfCancelled(e,r.name,t.id);}}after(e,t,r){for(let a of this.middlewares){let g=this.buildContext(e,t);a.canHandle(g)&&a.after(g,r);}}beforePublish(e){this.before(1,e);}afterPublish(e){this.after(1,e);}beforeCallback(e){this.before(2,e);}afterCallback(e,t){this.after(2,e,t);}beforeExecute(e){this.before(3,e);}afterExecute(e,t){this.after(3,e,t);}buildContext(e,t){return {stage:e,message:t}}throwIfCancelled(e,t,r,a){throw new T({stage:e,middleware:t,messageId:r,namespace:a,reason:t?`Cancelled by middleware "${t}"`:void 0})}};var w=class{constructor(){this.messages=new Map;this.executors=new Map;this.callbacks=new Map;}registerMessage(e,t){this.messages.has(e)&&console.warn(`Message with id ${e} already registered. Overriding...`),this.messages.set(e,t);}registerExecutor(e,t){this.executors.has(e)&&console.warn(`Executor with id ${e} already registered. Overriding...`),this.executors.set(e,t);}callbackFired(e){let t=this.callbacks.get(e.id);t?t.push(()=>e.complete()):this.callbacks.set(e.id,[()=>e.complete()]);}getMessage(e,t){let r=this.messages.get(e);if(!r)throw new Error(`There is no registered event ${t}`);return r}getExecutor(e){let t=this.executors.get(e);if(!t)throw new Error(`There is no registered executor with id ${e}`);return t}unregister(e){this.messages.get(e)?.finish(),this.messages.delete(e),this.callbacks.get(e)?.forEach(t=>t()),this.callbacks.delete(e),this.executors.delete(e);}dispose(){this.messages.forEach((e,t)=>this.unregister(t)),this.callbacks.forEach(e=>e.forEach(t=>t())),this.messages.clear(),this.executors.clear(),this.callbacks.clear();}};var C=class C{static get(){let e=[];for(let t=0;t<7;t++)e.push(C.collection.sort(()=>.5-Math.random()).slice(0,5).join(""));return e.join("-")}};C.collection="ABCDEFGHIJKLMNOPQRSTUVWXTZ0123456789".split("");var S=C;var s=class extends d{};var c=class extends s{constructor(t,r,a){super();this.type=t;this.sub=r;this.pipe=a;}};c.ID="aa03a192-bdc7-402d-9f2f-bf3748229ea2";var n=class extends s{constructor(t){super();this.messageId=t;}};n.ID="94579e43-5bc9-4517-bcda-b595bcda1ae7";var p=class extends s{constructor(t,r){super();this.type=t;this.exec=r;}};p.ID="cb80e8ad-b68c-4b2d-8c44-617ea6017cb3";var b=class extends s{constructor(t,r){super();this.executor=t;this.handler=r;}};b.ID="bf618cea-6f32-417c-9548-8eafe937378b";var D=class{constructor(e,t=null){this.postboy=e;this.ids=[];this.services=[];this._namespace=t??S.get();}get namespace(){return this._namespace}registerServices(e){this.services=e;}up(){this._up?.(),this.services.forEach(e=>e.up());}down(){this.services.forEach(e=>!!e.down&&e.down()),this.services=[],this.ids.forEach(e=>this.postboy.exec(new n(e)));}record(e,t){return this.ids.push(i(e)),this.postboy.exec(new c(e,t)),this}recordWithPipe(e,t,r){return this.ids.push(i(e)),this.postboy.exec(new c(e,t,r)),this}recordExecutor(e,t){return this.ids.push(i(e)),this.postboy.exec(new p(e,t)),this}recordHandler(e,t){return this.ids.push(i(e)),this.postboy.exec(new b(e,t)),this}recordReplay(e,t=1){return this.record(e,new rxjs.ReplaySubject(t)),this}recordBehavior(e,t){return this.record(e,new rxjs.BehaviorSubject(t)),this}recordSubject(e){return this.record(e,new rxjs.Subject),this}};var I=class extends D{constructor(e){super(e);}_up(){}};var v=class{constructor(){this.spaces=new Map;}addSpace(e,t){if(this.spaces.has(e))return this.spaces.get(e);let r=new I(t);return this.spaces.set(e,r),r}eliminateSpace(e){this.spaces.has(e)&&(this.spaces.get(e)?.down(),this.spaces.delete(e));}dispose(){this.spaces.forEach(e=>e.down()),this.spaces.clear();}};var R=class{constructor(){this.getMiddlewareService=()=>new E;this.getMessageStore=()=>new w;this.getNamespaceStore=()=>new v;}};var u=class extends s{constructor(t){super();this.space=t;}};u.ID="6d1a6f7d-6b6e-4c4d-8af8-9cc9a32e850c";var m=class extends s{constructor(t){super();this.space=t;}};m.ID="03bb03bb-53e0-4b74-9aad-64d5c54a8972";var f=class extends s{constructor(t){super();this.middleware=t;}};f.ID="0a8cfe0a-6193-4082-8440-d0793367b21d";var x=class extends s{constructor(t){super();this.middleware=t;}};x.ID="c25c708c-53c9-498d-a28b-936fbaf68b91";var y=class extends s{constructor(t){super();this.type=t;}};y.ID="477df3e2-1f99-4476-9a3b-afd1fa426436";var h=class extends s{constructor(t){super();this.type=t;}};h.ID="d71d25e3-90ac-4009-b972-9e6c6b05611e";var H=class{constructor(e){this.locked=new Set;this.dependencyResolver=e||new R,this.middleware=this.dependencyResolver.getMiddlewareService(),this.store=this.dependencyResolver.getMessageStore(),this.namespaceStore=this.dependencyResolver.getNamespaceStore(),this.registerInfrastructureMessages();}registerInfrastructureMessages(){this.store.registerExecutor(n.ID,e=>this.store.unregister(e.messageId)),this.store.registerExecutor(h.ID,e=>this.locked.delete(i(e.type))),this.store.registerExecutor(y.ID,e=>this.locked.add(i(e.type))),this.store.registerExecutor(f.ID,e=>this.middleware.addMiddleware(e.middleware)),this.store.registerExecutor(x.ID,e=>this.middleware.removeMiddleware(e.middleware)),this.store.registerExecutor(u.ID,e=>this.namespaceStore.addSpace(e.space,this)),this.store.registerExecutor(m.ID,e=>this.namespaceStore.eliminateSpace(e.space)),this.store.registerExecutor(c.ID,e=>{let{type:t,sub:r,pipe:a}=e;this.store.registerMessage(i(t),new l(r,a));}),this.store.registerExecutor(p.ID,e=>{let{type:t,exec:r}=e;this.store.registerExecutor(i(t),r);}),this.store.registerExecutor(b.ID,e=>{let{executor:t,handler:r}=e;this.store.registerExecutor(i(t),a=>r.handle(a));});}fire(e){this.middleware.beforePublish(e),this.locked.has(e.id)||this.store.getMessage(e.id,e.constructor.name).fire(e),this.middleware.afterPublish(e);}fireCallback(e,t){this.middleware.beforeCallback(e),t&&e.result.subscribe(t),this.store.callbackFired(e);let r=t?e.result.pipe(rxjs.tap(t)):e.result,a=this.store.getMessage(e.id,e.constructor.name),g=new rxjs.Observable($=>{let _=r.pipe(rxjs.tap(()=>this.middleware.afterCallback(e))).subscribe($);return this.locked.has(e.id)||a.fire(e),()=>_.unsubscribe()});return t&&g.subscribe(),g}exec(e){this.middleware.beforeExecute(e);let t=this.store.getExecutor(e.id)(e);return this.middleware.afterExecute(e,t),t}sub(e){return this.store.getMessage(i(e),e.name).sub()}once(e){return this.sub(e).pipe(rxjs.first())}record(e,t){this.store.registerMessage(i(e),new l(t,r=>r.asObservable()));}recordWithPipe(e,t,r){this.store.registerMessage(i(e),new l(t,r));}recordExecutor(e,t){this.store.registerExecutor(i(e),t);}recordHandler(e,t){this.store.registerExecutor(i(e),r=>t.handle(r));}dispose(){this.namespaceStore?.dispose(),this.store.dispose(),this.middleware.dispose();}};var A=class{constructor(e){this.name=e??this.constructor.name;}canHandle(e){return true}before(e){return {type:1}}after(e,t){}dispose(){}};var k=class extends P{constructor(){super(...arguments);this.result$=new rxjs.Subject;this.result=this.result$.asObservable();this.next=t=>this.result$.next(t);}finish(t){this.result$.next(t),this.result$.complete();}complete(){this.result$.complete();}};var O=class{};exports.AddMiddleware=f;exports.AddNamespace=u;exports.CancelError=T;exports.ConnectExecutor=p;exports.ConnectHandler=b;exports.ConnectMessage=c;exports.DisconnectMessage=n;exports.EliminateNamespace=m;exports.LockMessage=y;exports.MiddlewareDecisionType=j;exports.MiddlewareStage=M;exports.PostboyAbstractRegistrator=D;exports.PostboyCallbackMessage=k;exports.PostboyExecutionHandler=O;exports.PostboyExecutor=s;exports.PostboyGenericMessage=P;exports.PostboyMessage=d;exports.PostboyMessageStore=w;exports.PostboyMiddleware=A;exports.PostboyMiddlewareService=E;exports.PostboyNamespaceStore=v;exports.PostboyService=H;exports.PostboySubscription=l;exports.RemoveMiddleware=x;exports.UnlockMessage=h;//# sourceMappingURL=index.cjs.map
2
2
  //# sourceMappingURL=index.cjs.map
package/lib/index.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/models/postboy.message.ts","../src/models/postboy-generic-message.ts","../src/models/postboy-subscription.ts","../src/models/middleware-stage.enum.ts","../src/models/middleware-decision.enum.ts","../src/models/cancel-error.ts","../src/services/postboy-middleware.service.ts","../src/services/postboy-message.store.ts","../src/utils/id.generator.ts","../src/models/postboy-executor.ts","../src/messages/connect-message.executor.ts","../src/messages/disconnect-message.executor.ts","../src/messages/connect-executor.executor.ts","../src/messages/connect-handler.executor.ts","../src/postboy-abstract.registrator.ts","../src/services/namespace-registrator.ts","../src/services/postboy-namespace.store.ts","../src/services/postboy-dependency.resolver.ts","../src/messages/add-namespace.executor.ts","../src/messages/eliminate-namespace.executor.ts","../src/messages/add-middleware.executor.ts","../src/messages/remove-middleware.executor.ts","../src/messages/lock-message.executor.ts","../src/messages/unlock-message.executor.ts","../src/postboy.service.ts","../src/services/postboy-middleware.ts","../src/models/postboy-callback.message.ts","../src/models/postboy-execution.handler.ts"],"names":["PostboyMessage","metadata","PostboyGenericMessage","checkId","message","PostboySubscription","subscription","pipe","data","MiddlewareStage","MiddlewareDecisionType","CancelError","details","PostboyMiddlewareService","middleware","m","stage","context","result","cancelledBy","messageId","namespace","PostboyMessageStore","id","sub","executor","existingCallbacks","name","msg","executorFunction","c","fs","f","_IdGenerator","i","IdGenerator","PostboyExecutor","ConnectMessage","type","DisconnectMessage","ConnectExecutor","exec","ConnectHandler","handler","PostboyAbstractRegistrator","postboy","services","s","bufferSize","ReplaySubject","initial","BehaviorSubject","Subject","NamespaceRegistrator","PostboyNamespaceStore","space","registrator","PostboyDependencyResolver","AddNamespace","EliminateNamespace","AddMiddleware","RemoveMiddleware","LockMessage","UnlockMessage","PostboyService","resolver","e","action","result$","tap","observable","Observable","subscriber","first","PostboyMiddleware","_context","_result","PostboyCallbackMessage","value","PostboyExecutionHandler"],"mappings":"sCAEO,IAAeA,CAAAA,CAAf,KAA8B,CAA9B,cACL,IAAA,CAAO,QAAA,CAAmC,GAAC,CAC3C,IAAW,IAAa,CACtB,OAAQ,IAAA,CAAK,WAAA,CAAoB,EACnC,CAEA,YAAYC,CAAAA,CAAiD,CAC3D,YAAK,QAAA,CAAW,CAAE,GAAG,IAAA,CAAK,QAAA,CAAU,GAAGA,CAAS,CAAA,CACzC,I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MAAA,CAAOuB,CAAM,CAAC,EAC9E,CAQO,OAAA,EAAgB,CACrB,KAAK,cAAA,EAAgB,OAAA,GACrB,IAAA,CAAK,KAAA,CAAM,OAAA,EAAQ,CACnB,IAAA,CAAK,UAAA,CAAW,UAClB,CACF,EC3MO,IAAeQ,CAAAA,CAAf,KAAiC,CAQtC,WAAA,CAAY/C,CAAAA,CAAe,CACzB,IAAA,CAAK,IAAA,CAAOA,CAAAA,EAAQ,KAAK,WAAA,CAAY,KACvC,CAKO,SAAA,CAAUgD,CAAAA,CAAoC,CACnD,OAAO,KACT,CAMO,MAAA,CAAOA,CAAAA,CAA+C,CAC3D,OAAO,CAAE,IAAA,CAAA,CAAsC,CACjD,CAMO,KAAA,CAAMA,CAAAA,CAA2BC,EAAyB,CAEjE,CAKO,OAAA,EAAgB,CAEvB,CACF,EC7BO,IAAeC,CAAAA,CAAf,cAAiD3E,CAAsB,CAAvE,WAAA,EAAA,CAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CACL,IAAA,CAAU,OAAA,CAAU,IAAIkD,aACxB,IAAA,CAAO,MAAA,CAAwB,IAAA,CAAK,OAAA,CAAQ,YAAA,EAAa,CASzD,KAAO,IAAA,CAAQ0B,CAAAA,EAAmB,IAAA,CAAK,OAAA,CAAQ,IAAA,CAAKA,CAAK,GAQlD,MAAA,CAAOA,CAAAA,CAAgB,CAC5B,IAAA,CAAK,OAAA,CAAQ,KAAKA,CAAK,CAAA,CACvB,IAAA,CAAK,OAAA,CAAQ,QAAA,GACf,CASO,QAAA,EAAiB,CACtB,IAAA,CAAK,OAAA,CAAQ,QAAA,GACf,CACF,EC3CO,IAAeC,CAAAA,CAAf,KAAwE","file":"index.cjs","sourcesContent":["import { PostboyMessageMetadata } from './postboy-message-metadata';\n\nexport abstract class PostboyMessage {\n public metadata: PostboyMessageMetadata = {};\n public get id(): string {\n return (this.constructor as any).ID;\n }\n\n setMetadata(metadata: Partial<PostboyMessageMetadata>): this {\n this.metadata = { ...this.metadata, ...metadata };\n return this;\n }\n}\n","import { PostboyMessage } from './postboy.message';\n\n/**\n * An inheritor should have a static ID field\n */\nexport abstract class PostboyGenericMessage extends PostboyMessage {}\nexport function checkId(message: new (...args: any[]) => any): string {\n if (!(message as any).ID) throw new Error(`${message.name} should have a static ID field`);\n return (message as any).ID;\n}\n","import { Observable, Subject } from 'rxjs';\n\n/**\n * A class that manages a reactive subscription using a provided Subject and transformation pipe.\n * Offers methods to interact with the subscription, such as emitting data, completing the subscription,\n * and accessing the transformed observable.\n *\n * @template T The type of data managed by the subscription.\n */\nexport class PostboySubscription<T> {\n private readonly _subscription: Observable<T>;\n\n /**\n * Constructs an instance of the class with a given subscription and a transformation pipe.\n *\n * @param {Subject<T>} subscription - The source Subject that will be transformed.\n * @param {(s: Subject<T>) => Observable<T>} pipe - A function that applies a transformation to the subscription.\n */\n constructor(\n private subscription: Subject<T>,\n pipe?: (s: Subject<T>) => Observable<T>,\n ) {\n this._subscription = !!pipe ? pipe(subscription) : subscription.asObservable();\n }\n\n /**\n * Returns an observable subscription.\n *\n * @return {Observable<T>} An observable instance of type T.\n */\n public sub(): Observable<T> {\n return this._subscription;\n }\n\n /**\n * Triggers an event by emitting the provided data to all subscribers.\n *\n * @param {T} data - The data to emit to the subscribers.\n * @return {void} - Does not return any value.\n */\n public fire(data: T): void {\n this.subscription.next(data);\n }\n\n /**\n * Completes the subscription, signaling that no further values will be sent.\n * This is typically used to finalize or clean up resources.\n * @return {void} This method does not return any value.\n */\n public finish(): void {\n this.subscription.complete();\n }\n}\n","export enum MiddlewareStage {\n Publish = 1,\n Callback,\n Execute,\n}\n","export enum MiddlewareDecisionType {\n Continue = 1,\n Interrupt,\n}\n","import { CancelDetails } from './cancel-details';\nimport { MiddlewareStage } from './middleware-stage.enum';\n\nexport class CancelError extends Error {\n public readonly details: CancelDetails;\n\n constructor(details: CancelDetails) {\n super(details.reason ?? `Postboy operation was cancelled at stage \"${MiddlewareStage[details.stage]}\"`);\n this.name = 'PostboyCancelError';\n this.details = details;\n }\n}\n\nexport function isCancelError(error: unknown): error is CancelError {\n return error instanceof CancelError;\n}\n","import { PostboyMessage } from '../models/postboy.message';\nimport { PostboyMessageContext } from '../models/postboy-message.context';\nimport { PostboyExecutor } from '../models/postboy-executor';\nimport { PipelineContext } from '../models/pipeline-context';\nimport { PostboyMiddleware } from './postboy-middleware';\nimport { MiddlewareStage } from '../models/middleware-stage.enum';\nimport { MiddlewareDecisionType } from '../models/middleware-decision.enum';\nimport { CancelError } from '../models/cancel-error';\n\nexport class PostboyMiddlewareService {\n protected middlewares: PostboyMiddleware[] = [];\n\n public addMiddleware(middleware: PostboyMiddleware): void {\n this.middlewares.push(middleware);\n }\n\n public removeMiddleware(middleware: PostboyMiddleware): void {\n this.middlewares = this.middlewares.filter((m) => {\n if (m !== middleware) return true;\n m.dispose();\n return false;\n });\n }\n\n public dispose(): void {\n this.middlewares.forEach((m) => m.dispose());\n this.middlewares = [];\n }\n\n public before<T extends PostboyMessage>(stage: MiddlewareStage, message: T): void {\n for (const middleware of this.middlewares) {\n const context = this.buildContext(stage, message);\n if (!middleware.canHandle(context)) continue;\n if (middleware.before(context).type === MiddlewareDecisionType.Interrupt)\n this.throwIfCancelled(stage, middleware.name, message.id);\n }\n }\n\n public after<T extends PostboyMessage, R = unknown>(stage: MiddlewareStage, message: T, result?: R): void {\n for (const middleware of this.middlewares) {\n const context = this.buildContext(stage, message);\n if (!middleware.canHandle(context)) continue;\n middleware.after(context, result);\n }\n }\n\n public beforePublish(message: PostboyMessage): void {\n this.before(MiddlewareStage.Publish, message);\n }\n\n public afterPublish(message: PostboyMessage): void {\n this.after(MiddlewareStage.Publish, message);\n }\n\n public beforeCallback(message: PostboyMessage): void {\n this.before(MiddlewareStage.Callback, message);\n }\n\n public afterCallback(message: PostboyMessage, result?: unknown): void {\n this.after(MiddlewareStage.Callback, message, result);\n }\n\n public beforeExecute<T>(message: PostboyExecutor<T>): void {\n this.before(MiddlewareStage.Execute, message);\n }\n\n public afterExecute<T>(message: PostboyExecutor<T>, result: T): void {\n this.after(MiddlewareStage.Execute, message, result);\n }\n\n private buildContext<T extends PostboyMessage>(stage: MiddlewareStage, message: T): PipelineContext<T> {\n return { stage, message };\n }\n\n private throwIfCancelled(\n stage: MiddlewareStage,\n cancelledBy?: string,\n messageId?: string,\n namespace?: string,\n ): never {\n throw new CancelError({\n stage,\n middleware: cancelledBy,\n messageId,\n namespace,\n reason: cancelledBy ? `Cancelled by middleware \"${cancelledBy}\"` : undefined,\n });\n }\n}\n","import { PostboySubscription } from '../models/postboy-subscription';\nimport { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyCallbackMessage } from '../models/postboy-callback.message';\n\n/**\n * The PostboyMessageStore is a utility class for managing message subscriptions and executors.\n * It provides functionality to register, retrieve, and unregister subscription-based messages and executors.\n */\nexport class PostboyMessageStore {\n protected messages = new Map<string, PostboySubscription<any>>();\n protected executors = new Map<string, (e: PostboyExecutor<any>) => any>();\n protected callbacks = new Map<string, (() => void)[]>();\n\n public registerMessage(id: string, sub: PostboySubscription<any>): void {\n // tslint:disable-next-line:no-console\n if (this.messages.has(id)) console.warn(`Message with id ${id} already registered. Overriding...`);\n this.messages.set(id, sub);\n }\n\n public registerExecutor(id: string, executor: (e: PostboyExecutor<any>) => any): void {\n // tslint:disable-next-line:no-console\n if (this.executors.has(id)) console.warn(`Executor with id ${id} already registered. Overriding...`);\n this.executors.set(id, executor);\n }\n\n callbackFired(message: PostboyCallbackMessage<any>): void {\n const existingCallbacks = this.callbacks.get(message.id);\n existingCallbacks\n ? existingCallbacks.push(() => message.complete())\n : this.callbacks.set(message.id, [() => message.complete()]);\n }\n\n public getMessage(id: string, name: string): PostboySubscription<any> {\n const msg = this.messages.get(id);\n if (!msg) throw new Error(`There is no registered event ${name}`);\n return msg;\n }\n\n public getExecutor<T>(id: string): (e: PostboyExecutor<T>) => T {\n const executorFunction = this.executors.get(id);\n if (!executorFunction) throw new Error(`There is no registered executor with id ${id}`);\n return executorFunction;\n }\n\n public unregister(id: string): void {\n this.messages.get(id)?.finish();\n this.messages.delete(id);\n this.callbacks.get(id)?.forEach((c) => c());\n this.callbacks.delete(id);\n this.executors.delete(id);\n }\n\n public dispose(): void {\n this.messages.forEach((m, id) => this.unregister(id));\n this.callbacks.forEach((fs) => fs.forEach((f) => f()));\n this.messages.clear();\n this.executors.clear();\n this.callbacks.clear();\n }\n}\n","export class IdGenerator {\n private static collection = 'ABCDEFGHIJKLMNOPQRSTUVWXTZ0123456789'.split('');\n\n public static get(): string {\n const result: string[] = [];\n for (let i = 0; i < 7; i++) {\n result.push(\n IdGenerator.collection\n .sort(() => 0.5 - Math.random())\n .slice(0, 5)\n .join(''),\n );\n }\n return result.join('-');\n }\n}\n","import { PostboyMessage } from './postboy.message';\n\nexport abstract class PostboyExecutor<T> extends PostboyMessage {\n declare protected readonly _postboyResultType?: T;\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyGenericMessage } from '../models/postboy-generic-message';\nimport { MessageType } from '../postboy-abstract.registrator';\nimport { Observable, Subject } from 'rxjs';\n\n/**\n * Represents a message that facilitates connection functionality\n * within the application's messaging system.\n *\n * @template T - A type that extends {@link PostboyGenericMessage}, representing\n * the structure of the message being handled.\n *\n * @extends PostboyExecutor<void>\n */\nexport class ConnectMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {\n static readonly ID = 'aa03a192-bdc7-402d-9f2f-bf3748229ea2';\n\n /**\n * Constructs a new instance of the class.\n *\n * @param {MessageType<T>} type - The type of the message.\n * @param {Subject<T>} sub - The subject to be used for message handling.\n * @param {(s: Subject<T>) => Observable<T>} [pipe] - An optional function to transform the subject.\n */\n constructor(\n public type: MessageType<T>,\n public sub: Subject<T>,\n public pipe?: (s: Subject<T>) => Observable<T>,\n ) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\n\n/**\n * Represents a message signaling a disconnection event. This class is used\n * within the framework to manage and process disconnection notifications.\n * Extends the {@link PostboyExecutor} base class.\n *\n * @extends {PostboyExecutor<void>}\n */\nexport class DisconnectMessage extends PostboyExecutor<void> {\n static readonly ID = '94579e43-5bc9-4517-bcda-b595bcda1ae7';\n\n /**\n * Creates an instance of the class with the specified message identifier.\n *\n * @param {string} messageId - The unique identifier for the message.\n */\n constructor(public messageId: string) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\nimport { MessageType } from '../postboy-abstract.registrator';\n\n/**\n * Registers an executor that connects to a specific type of message handler.\n * This class extends the functionality of `PostboyExecutor` and is designed to manage\n * the execution of a handler defined by a specific message type and an execution function.\n *\n * @template E The type of the executor extending {@link PostboyExecutor}.\n * @template T The return type of the execution function.\n *\n * @extends {PostboyExecutor<void>}\n */\nexport class ConnectExecutor<E extends PostboyExecutor<T>, T> extends PostboyExecutor<void> {\n static readonly ID = 'cb80e8ad-b68c-4b2d-8c44-617ea6017cb3';\n\n /**\n * Constructs an instance of the class with the specified type and execution function.\n *\n * @param {MessageType<E>} type - The type of the message.\n * @param {(e: E) => T} exec - The function to be executed with the input of type E that returns a value of type T.\n */\n constructor(\n public type: MessageType<E>,\n public exec: (e: E) => T,\n ) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyExecutionHandler } from '../models/postboy-execution.handler';\n\n/**\n * Represents a connection handler that extends the PostboyExecutor class.\n *\n * This class encapsulates logic associated with executing a handler in a structured way.\n * It is generic and operates on the provided executor and handler types.\n *\n * Type Parameters:\n * E - Represents an extension of the PostboyExecutor class with a specific type parameter R.\n * R - Represents the type of the result that the executor is expected to operate on.\n */\nexport class ConnectHandler<E extends PostboyExecutor<R>, R> extends PostboyExecutor<void> {\n static readonly ID = 'bf618cea-6f32-417c-9548-8eafe937378b';\n\n /**\n * Constructs an instance of the class.\n *\n * @param {new (...args: any[]) => E} executor - A constructor function for the executor object.\n * @param {PostboyExecutionHandler<R, E>} handler - A handler that processes the execution logic.\n */\n constructor(\n public executor: new (...args: any[]) => E,\n public handler: PostboyExecutionHandler<R, E>,\n ) {\n super();\n }\n}\n","import { PostboyService } from './postboy.service';\nimport { BehaviorSubject, Observable, pipe, ReplaySubject, Subject } from 'rxjs';\nimport { IPostboyDependingService } from './i-postboy-depending.service';\nimport { PostboyExecutor } from './models/postboy-executor';\nimport { checkId, PostboyGenericMessage } from './models/postboy-generic-message';\nimport { PostboyExecutionHandler } from './models/postboy-execution.handler';\nimport { IdGenerator } from './utils/id.generator';\nimport { ConnectMessage } from './messages/connect-message.executor';\nimport { DisconnectMessage } from './messages/disconnect-message.executor';\nimport { ConnectExecutor } from './messages/connect-executor.executor';\nimport { ConnectHandler } from './messages/connect-handler.executor';\n\nexport type MessageType<T extends PostboyGenericMessage> = new (...args: any[]) => T;\n\nexport abstract class PostboyAbstractRegistrator {\n get namespace(): string {\n return this._namespace;\n }\n private ids: string[] = [];\n private services: IPostboyDependingService[] = [];\n private readonly _namespace: string;\n\n constructor(\n protected postboy: PostboyService,\n namespace: string | null = null,\n ) {\n this._namespace = namespace ?? IdGenerator.get();\n }\n\n /**\n * Registers a list of services to be used by the application.\n *\n * @param {IPostboyDependingService[]} services - An array of services to register.\n * @return {void} This method does not return a value.\n */\n public registerServices(services: IPostboyDependingService[]): void {\n this.services = services;\n }\n\n /**\n * Initiates the 'up' process for the current instance and all associated services.\n *\n * @return {void} Does not return a value.\n */\n public up(): void {\n this._up?.();\n this.services.forEach((s) => s.up());\n }\n\n protected abstract _up(): void;\n\n public down(): void {\n this.services.forEach((s) => !!s.down && s.down());\n this.services = [];\n this.ids.forEach((id) => this.postboy.exec(new DisconnectMessage(id)));\n }\n\n /**\n * Records a type and its corresponding Subject<T> into the Postboy system and updates the internal identifiers.\n *\n * @param {MessageType<T>} type - A constructor for the generic message type T.\n * @param {Subject<T>} sub - The subject associated with the generic message type.\n * @return {this} Returns the current instance for method chaining.\n */\n public record<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>): PostboyAbstractRegistrator {\n this.ids.push(checkId(type));\n this.postboy.exec(new ConnectMessage(type, sub));\n return this;\n }\n\n /**\n * Records a message type with a specific subject and applies a transformation pipe to the subject.\n *\n * @param {MessageType<T>} type - The constructor of the message type to record, which extends PostboyGenericMessage.\n * @param {Subject<T>} sub - The Subject instance to associate with the message type.\n * @param {(s: Subject<T>) => Observable<T>} pipe - A function that takes the subject as input and returns an Observable with transformations applied.\n * @return {this} The current instance of the class for chaining.\n */\n public recordWithPipe<T extends PostboyGenericMessage>(\n type: MessageType<T>,\n sub: Subject<T>,\n pipe: (s: Subject<T>) => Observable<T>,\n ): PostboyAbstractRegistrator {\n this.ids.push(checkId(type));\n this.postboy.exec(new ConnectMessage(type, sub, pipe));\n return this;\n }\n\n /**\n * Records an executor associated with a specific type and execution logic.\n *\n * @param type The class constructor of the executor type to be recorded, which extends PostboyExecutor.\n * @param exec A callback function that executes the logic using an instance of the specified executor type.\n * @return void\n */\n public recordExecutor<E extends PostboyExecutor<T>, T>(\n type: new (...args: any[]) => E,\n exec: (e: E) => T,\n ): PostboyAbstractRegistrator {\n this.ids.push(checkId(type));\n this.postboy.exec(new ConnectExecutor(type, exec));\n return this;\n }\n\n /**\n * Records a handler for a specific executor type.\n *\n * @param executor The constructor of the executor type, which extends `PostboyExecutor`.\n * @param handler The execution handler associated with the given executor type.\n * @return void\n */\n public recordHandler<E extends PostboyExecutor<R>, R>(\n executor: new (...args: any[]) => E,\n handler: PostboyExecutionHandler<R, E>,\n ): PostboyAbstractRegistrator {\n this.ids.push(checkId(executor));\n this.postboy.exec(new ConnectHandler(executor, handler));\n return this;\n }\n\n /**\n * A utility function that facilitates the recording and replaying of messages\n * using a ReplaySubject. This function is designed to handle messages of a\n * specific type and allows specifying a buffer size to determine how many\n * of the most recent messages should be replayed.\n *\n * @template T Extends the PostboyGenericMessage type, representing the type of message\n * to be recorded and replayed.\n * @param {MessageType<T>} type The constructor of the message type to be recorded and replayed.\n * @param {number} [bufferSize=1] The number of recent messages to retain in the ReplaySubject's buffer.\n * Defaults to 1 if not specified.\n * @returns The result of invoking the `record` method with the given message type and configured ReplaySubject.\n */\n public recordReplay<T extends PostboyGenericMessage>(\n type: MessageType<T>,\n bufferSize = 1,\n ): PostboyAbstractRegistrator {\n this.record(type, new ReplaySubject<T>(bufferSize));\n return this;\n }\n\n /**\n * Represents a method that records a specific behavior associated with a message type.\n * It creates a `BehaviorSubject` initialized with the provided initial message\n * and associates it with the given message type using the `record` method.\n *\n * @template T - A type parameter extending `PostboyGenericMessage` that defines the message structure.\n * @param {MessageType<T>} type - The constructor function of the message type to be recorded.\n * @param {T} initial - The initial value of the message that will be set in the `BehaviorSubject`.\n * @returns {void} - This function does not return a value; instead, it modifies the internal state.\n */\n public recordBehavior<T extends PostboyGenericMessage>(type: MessageType<T>, initial: T): PostboyAbstractRegistrator {\n this.record(type, new BehaviorSubject<T>(initial));\n return this;\n }\n\n /**\n * A function that creates and returns a new generic message recorder for a specific message type.\n *\n * @template T - A type parameter extending from `PostboyGenericMessage`.\n * @param {MessageType<T>} type - The constructor for the message type being recorded.\n * @returns {Subject<T>} A new instance of `Subject<T>` bound to the specified message type.\n */\n public recordSubject<T extends PostboyGenericMessage>(type: MessageType<T>) {\n this.record(type, new Subject<T>());\n return this;\n }\n}\n","import { PostboyAbstractRegistrator } from '../postboy-abstract.registrator';\nimport { PostboyService } from '../postboy.service';\n\n/**\n * NamespaceRegistrator is a specialized class that extends PostboyAbstractRegistrator.\n *\n * @class NamespaceRegistrator\n * @extends PostboyAbstractRegistrator\n * @param {PostboyService} postboy - An instance of the PostboyService, used for managing registrations.\n */\nexport class NamespaceRegistrator extends PostboyAbstractRegistrator {\n constructor(postboy: PostboyService) {\n super(postboy);\n }\n\n protected _up(): void {\n // ignore\n }\n}\n","import { PostboyAbstractRegistrator } from '../postboy-abstract.registrator';\nimport { NamespaceRegistrator } from './namespace-registrator';\nimport { PostboyService } from '../postboy.service';\n\n/**\n * Represents a store for managing namespaces in the Postboy system.\n * Provides functionality to add, eliminate, and dispose namespaces.\n */\nexport class PostboyNamespaceStore {\n private spaces: Map<string, PostboyAbstractRegistrator> = new Map();\n\n /**\n * Adds a new space or retrieves an existing one if it already exists.\n *\n * @param {string} space - The name of the space to add or retrieve.\n * @param {PostboyService} postboy - The PostboyService instance used to create a namespace registrator.\n * @return {PostboyAbstractRegistrator} The registrator associated with the specified space.\n */\n public addSpace(space: string, postboy: PostboyService): PostboyAbstractRegistrator {\n if (this.spaces.has(space)) return this.spaces.get(space)!;\n const registrator = new NamespaceRegistrator(postboy);\n this.spaces.set(space, registrator);\n return registrator;\n }\n\n /**\n * Removes a specified space from the spaces collection if it exists.\n * If the space exists, it will be deleted after invoking its down method.\n *\n * @param {string} space - The name of the space to be removed.\n * @return {void} This method does not return a value.\n */\n public eliminateSpace(space: string): void {\n if (!this.spaces.has(space)) return;\n this.spaces.get(space)?.down();\n this.spaces.delete(space);\n }\n\n /**\n * Disposes of the current instance by performing cleanup operations.\n * Iterates through all spaces, performs a \"down\" operation on each,\n * and then clears the collection of spaces.\n *\n * @return {void} No return value.\n */\n public dispose(): void {\n this.spaces.forEach((space) => space.down());\n this.spaces.clear();\n }\n}\n","import { PostboyMiddlewareService } from './postboy-middleware.service';\nimport { PostboyMessageStore } from './postboy-message.store';\nimport { PostboyNamespaceStore } from './postboy-namespace.store';\n\nexport class PostboyDependencyResolver {\n /**\n * Retrieves an instance of the PostboyMiddlewareService.\n *\n * This function initializes and returns a new instance of the\n * PostboyMiddlewareService, which can be used to configure and manage\n * middleware for a specific module or application.\n *\n * @returns {PostboyMiddlewareService} A new instance of PostboyMiddlewareService.\n */\n getMiddlewareService = () => new PostboyMiddlewareService();\n /**\n * A function that instantiates and returns a new instance of PostboyMessageStore.\n *\n * This function serves as a factory method for creating instances\n * of the PostboyMessageStore class.\n *\n * @returns {PostboyMessageStore} A new instance of the PostboyMessageStore class.\n */\n getMessageStore = () => new PostboyMessageStore();\n /**\n * Creates and initializes a new instance of PostboyNamespaceStore using the provided PostboyService instance.\n *\n * @function getNamespaceStore\n * @returns {PostboyNamespaceStore} A new instance of PostboyNamespaceStore associated with the given PostboyService.\n */\n getNamespaceStore = () => new PostboyNamespaceStore();\n}\n","import { PostboyAbstractRegistrator } from '../postboy-abstract.registrator';\nimport { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyExecutionHandler } from '../models/postboy-execution.handler';\nimport { PostboyNamespaceStore } from '../services/postboy-namespace.store';\nimport { PostboyService } from '../postboy.service';\n\n/**\n * AddNamespace is a class that extends the PostboyExecutor with a specific implementation\n * for adding namespaces to a PostboyService instance.\n *\n * This class is identified uniquely by its static ID property for tracking and referencing purposes.\n */\nexport class AddNamespace extends PostboyExecutor<PostboyAbstractRegistrator> {\n static readonly ID = '6d1a6f7d-6b6e-4c4d-8af8-9cc9a32e850c';\n\n /**\n * Creates an instance of the class with the specified space identifier.\n *\n * @param {string} space - The identifier for the space.\n */\n constructor(public space: string) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\n\n/**\n * Represents an executor that eliminates a specific namespace.\n * This class extends the PostboyExecutor with a void return type.\n */\nexport class EliminateNamespace extends PostboyExecutor<void> {\n static readonly ID = '03bb03bb-53e0-4b74-9aad-64d5c54a8972';\n\n /**\n * Creates an instance of the class with the specified space value.\n *\n * @param {string} space - The string value representing the space configuration.\n */\n constructor(public space: string) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyMiddleware } from '../services/postboy-middleware';\n\n/**\n * Represents a {@link PostboyMiddleware} addition operation for Postboy.\n * This class extends the functionality of the PostboyExecutor to add middleware to the processing chain.\n *\n * The middleware to be added is provided during instantiation.\n */\nexport class AddMiddleware extends PostboyExecutor<void> {\n static readonly ID = '0a8cfe0a-6193-4082-8440-d0793367b21d';\n\n /**\n * Initializes a new instance of the class with the specified middleware.\n *\n * @param {PostboyMiddleware} middleware - The {@link PostboyMiddleware} to be used for processing.\n */\n constructor(public middleware: PostboyMiddleware) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyMiddleware } from '../services/postboy-middleware';\n\n/**\n * Represents a class responsible for removing {@link PostboyMiddleware} in execution flow.\n * This class extends PostboyExecutor and operates with a void return type.\n */\nexport class RemoveMiddleware extends PostboyExecutor<void> {\n static readonly ID = 'c25c708c-53c9-498d-a28b-936fbaf68b91';\n\n /**\n * Constructs an instance of the class with the specified middleware.\n *\n * @param {PostboyMiddleware} middleware - The {@link PostboyMiddleware} instance to be removed.\n */\n constructor(public middleware: PostboyMiddleware) {\n super();\n }\n}\n","import { PostboyGenericMessage } from '../models/postboy-generic-message';\nimport { MessageType } from '../postboy-abstract.registrator';\nimport { PostboyExecutor } from '../models/postboy-executor';\n\n/**\n * Locks a specific message type to prevent firing of them.\n *\n * @deprecated Use {@link PostboyMiddleware}\n * This class is used to handle operations associated with locking mechanisms\n * for a specified message type.\n *\n * @template T - A type that extends {@link PostboyGenericMessage}.\n */\nexport class LockMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {\n static readonly ID = '477df3e2-1f99-4476-9a3b-afd1fa426436';\n\n /**\n * Constructs an instance of the class with the specified message type.\n *\n * @param {MessageType<T>} type - The type of the message to be used for the instance.\n */\n constructor(public type: MessageType<T>) {\n super();\n }\n}\n","import { PostboyGenericMessage } from '../models/postboy-generic-message';\nimport { PostboyExecutor } from '../models/postboy-executor';\nimport { MessageType } from '../postboy-abstract.registrator';\n\n/**\n * A specialized executor that handles the unlocking process for messages of a specified type.\n * Unlocks a previously locked message, making it available for processing again.\n *\n * @deprecated Use {@link PostboyMiddleware}\n * @template T - The type parameter extending {@link PostboyGenericMessage}, representing the message type handled by the executor.\n * @extends {PostboyExecutor<void>}\n */\nexport class UnlockMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {\n static readonly ID = 'd71d25e3-90ac-4009-b972-9e6c6b05611e';\n\n /**\n * Creates an instance of the class with the specified message type.\n *\n * @param {MessageType<T>} type - The message type for this instance.\n */\n constructor(public type: MessageType<T>) {\n super();\n }\n}\n","import { first, Observable, Subject, tap } from 'rxjs';\nimport { checkId, PostboyGenericMessage } from './models/postboy-generic-message';\nimport { PostboySubscription } from './models/postboy-subscription';\nimport { PostboyExecutor } from './models/postboy-executor';\nimport { PostboyCallbackMessage } from './models/postboy-callback.message';\nimport { MessageType, PostboyAbstractRegistrator } from './postboy-abstract.registrator';\nimport { PostboyExecutionHandler } from './models/postboy-execution.handler';\nimport { PostboyDependencyResolver } from './services/postboy-dependency.resolver';\nimport { PostboyMiddlewareService } from './services/postboy-middleware.service';\nimport { PostboyMessageStore } from './services/postboy-message.store';\nimport { PostboyNamespaceStore } from './services/postboy-namespace.store';\nimport { PostboyContextService } from './services/postboy-context.service';\nimport { PostboySettings } from './models/postboy.settings';\nimport { AddNamespace } from './messages/add-namespace.executor';\nimport { EliminateNamespace } from './messages/eliminate-namespace.executor';\nimport { AddMiddleware } from './messages/add-middleware.executor';\nimport { RemoveMiddleware } from './messages/remove-middleware.executor';\nimport { LockMessage } from './messages/lock-message.executor';\nimport { UnlockMessage } from './messages/unlock-message.executor';\nimport { DisconnectMessage } from './messages/disconnect-message.executor';\nimport { MiddlewareStage } from './models/middleware-stage.enum';\nimport { CancelError } from './models/cancel-error';\nimport { ConnectMessage } from './messages/connect-message.executor';\nimport { ConnectExecutor } from './messages/connect-executor.executor';\nimport { ConnectHandler } from './messages/connect-handler.executor';\n\nexport class PostboyService {\n protected locked = new Set<string>();\n private middleware: PostboyMiddlewareService;\n private store: PostboyMessageStore;\n private namespaceStore: PostboyNamespaceStore;\n private dependencyResolver: PostboyDependencyResolver;\n\n constructor(resolver?: PostboyDependencyResolver) {\n this.dependencyResolver = resolver || new PostboyDependencyResolver();\n this.middleware = this.dependencyResolver.getMiddlewareService();\n this.store = this.dependencyResolver.getMessageStore();\n this.namespaceStore = this.dependencyResolver.getNamespaceStore();\n this.registerInfrastructureMessages();\n }\n\n private registerInfrastructureMessages() {\n this.store.registerExecutor(DisconnectMessage.ID, (e) => this.store.unregister((e as DisconnectMessage).messageId));\n this.store.registerExecutor(UnlockMessage.ID, (e) => this.locked.delete(checkId((e as UnlockMessage<any>).type)));\n this.store.registerExecutor(LockMessage.ID, (e) => this.locked.add(checkId((e as LockMessage<any>).type)));\n this.store.registerExecutor(AddMiddleware.ID, (e) =>\n this.middleware.addMiddleware((e as AddMiddleware).middleware),\n );\n this.store.registerExecutor(RemoveMiddleware.ID, (e) =>\n this.middleware.removeMiddleware((e as RemoveMiddleware).middleware),\n );\n this.store.registerExecutor(AddNamespace.ID, (e) => this.namespaceStore.addSpace((e as AddNamespace).space, this));\n this.store.registerExecutor(EliminateNamespace.ID, (e) =>\n this.namespaceStore.eliminateSpace((e as EliminateNamespace).space),\n );\n this.store.registerExecutor(ConnectMessage.ID, (e) => {\n const { type, sub, pipe } = e as ConnectMessage<any>;\n this.store.registerMessage(checkId(type), new PostboySubscription<any>(sub, pipe));\n });\n this.store.registerExecutor(ConnectExecutor.ID, (e) => {\n const { type, exec } = e as ConnectExecutor<any, any>;\n this.store.registerExecutor(checkId(type), exec);\n });\n this.store.registerExecutor(ConnectHandler.ID, (e) => {\n const { executor, handler } = e as ConnectHandler<any, any>;\n this.store.registerExecutor(checkId(executor), (e) => handler.handle(e));\n });\n }\n\n /**\n * Fires a registered event and passes the message to its subscribers.\n *\n * @param {PostboyGenericMessage} message - The message object containing the event data.\n * @return {void} This method does not return a value.\n * @throws {Error} Throws an error if no registered event is found for the provided message ID.\n */\n public fire(message: PostboyGenericMessage): void {\n this.middleware.beforePublish(message);\n if (!this.locked.has(message.id)) {\n this.store.getMessage(message.id, message.constructor.name).fire(message);\n }\n this.middleware.afterPublish(message);\n }\n\n /**\n * Triggers a callback function associated with a given message.\n *\n * @param {PostboyCallbackMessage<T>} message - The message object used to trigger the callback.\n * It contains details about the event and result subscription.\n * @param {(e: T) => void} [action] - Optional callback function to execute when the result of the message is emitted.\n * @return {void} This method does not return any value.\n */\n public fireCallback<T>(message: PostboyCallbackMessage<T>, action?: (e: T) => void): Observable<T> {\n this.middleware.beforeCallback(message);\n if (action) message.result.subscribe(action);\n this.store.callbackFired(message);\n const result$ = action ? message.result.pipe(tap(action)) : message.result;\n const msg = this.store.getMessage(message.id, message.constructor.name);\n const observable = new Observable<T>((subscriber) => {\n const subscription = result$.pipe(tap(() => this.middleware.afterCallback(message))).subscribe(subscriber);\n\n if (!this.locked.has(message.id)) {\n msg.fire(message);\n }\n\n return () => subscription.unsubscribe();\n });\n if (!!action) observable.subscribe();\n return observable;\n }\n\n /**\n * Executes the provided executor function and returns its result.\n *\n * @param {PostboyExecutor<T>} executor The executor to be executed, which includes its identifier and logic.\n * @return {T} The resulting output from the executed executor function.\n * @throws {Error} If the specified executor is not registered.\n */\n public exec<T>(executor: PostboyExecutor<T>): T {\n this.middleware.beforeExecute(executor);\n const result = this.store.getExecutor<T>(executor.id)(executor);\n this.middleware.afterExecute(executor, result);\n return result;\n }\n\n /**\n * Subscribes to a specific message type and returns an observable of that type.\n *\n * @param type The constructor function of the type that extends PostboyGenericMessage.\n * @return An Observable of the specified generic message type.\n */\n public sub<T extends PostboyGenericMessage>(type: MessageType<T>): Observable<T> {\n return this.store.getMessage(checkId(type), type.name).sub();\n }\n\n /**\n * Subscribes to a specific message type and automatically unsubscribes after receiving the first message.\n *\n * @param type The type of message to subscribe to.\n * @return An observable that emits the first message of the specified type and then completes.\n */\n public once<T extends PostboyGenericMessage>(type: MessageType<T>): Observable<T> {\n return this.sub(type).pipe(first());\n }\n\n /**\n * Registers a given message type and its associated subject subscription with the system.\n *\n * @deprecated The method should be replaced with firing {@link ConnectMessage} message.\n * @param type The constructor function of the message type that extends the PostboyGenericMessage.\n * @param sub The Subject instance for the provided message type, used for managing subscriptions.\n * @return {void} No return value.\n */\n public record<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>): void {\n this.store.registerMessage(checkId(type), new PostboySubscription<T>(sub, (s) => s.asObservable()));\n }\n\n /**\n * Registers a generic message type with a Subject and a transformation pipe.\n *\n * @deprecated The method should be replaced with firing {@link ConnectMessage} message.\n * @param {MessageType<T>} type - The constructor of the message type being registered.\n * @param {Subject<T>} sub - The Subject instance used to handle incoming messages of the specified type.\n * @param {(s: Subject<T>) => Observable<T>} pipe - A function that applies a transformation or processing logic to the Subject and returns an Observable.\n * @return {void} No return value.\n */\n public recordWithPipe<T extends PostboyGenericMessage>(\n type: MessageType<T>,\n sub: Subject<T>,\n pipe: (s: Subject<T>) => Observable<T>,\n ): void {\n this.store.registerMessage(checkId(type), new PostboySubscription<T>(sub, pipe));\n }\n\n /**\n * Registers an executor for a specified message type.\n *\n * @deprecated The method should be replaced with firing {@link ConnectExecutor} message.\n * @param {MessageType<E>} type - The message type for which the executor is being registered.\n * @param {(e: E) => T} exec - The executor function that will handle messages of the specified type.\n * @return {void} This method does not return any value.\n */\n public recordExecutor<E extends PostboyExecutor<T>, T>(type: MessageType<E>, exec: (e: E) => T): void {\n this.store.registerExecutor(checkId(type), exec as (e: PostboyExecutor<T>) => T);\n }\n\n /**\n * Registers a handler for a specific executor type.\n *\n * @deprecated The method should be replaced with firing {@link ConnectHandler} message.\n * @param executor The constructor of the executor class that extends `PostboyExecutor<R>`.\n * @param handler An instance of `PostboyExecutionHandler<R, E>` that defines the logic for handling the executor.\n * @return void\n */\n public recordHandler<E extends PostboyExecutor<R>, R>(\n executor: new (...args: any[]) => E,\n handler: PostboyExecutionHandler<R, E>,\n ): void {\n this.store.registerExecutor(checkId(executor), (e) => handler.handle(e as E));\n }\n\n /**\n * Disposes of resources and cleans up any internal components or stores associated with the instance.\n * This method ensures that all resources are properly released to avoid memory leaks.\n *\n * @return {void} This method does not return a value.\n */\n public dispose(): void {\n this.namespaceStore?.dispose();\n this.store.dispose();\n this.middleware.dispose();\n }\n}\n","import { PipelineContext } from '../models/pipeline-context';\nimport { MiddlewareDecisionType } from '../models/middleware-decision.enum';\nimport { MiddlewareDecision } from '../models';\n\n/**\n * Abstract base class for defining middleware in a pipeline.\n * Middleware acts on various stages of pipeline execution, allowing operations\n * to be intercepted, modified, or monitored.\n */\nexport abstract class PostboyMiddleware {\n public readonly name: string;\n\n /**\n * Creates an instance of a class, optionally assigning a name.\n *\n * @param {string} [name] - An optional name to be assigned. If not provided, defaults to the class name.\n */\n constructor(name?: string) {\n this.name = name ?? this.constructor.name;\n }\n\n /**\n * Optional filter to skip middleware for unrelated messages/stages.\n */\n public canHandle(_context: PipelineContext): boolean {\n return true;\n }\n\n /**\n * Called before the stage is executed.\n * Return Interrupt to cancel the operation.\n */\n public before(_context: PipelineContext): MiddlewareDecision {\n return { type: MiddlewareDecisionType.Continue };\n }\n\n /**\n * Called after the stage has finished successfully.\n * `result` is typically set for execute-stage.\n */\n public after(_context: PipelineContext, _result?: unknown): void {\n // noop\n }\n\n /**\n * Optional cleanup hook.\n */\n public dispose(): void {\n // noop\n }\n}\n","import { Observable, Subject } from 'rxjs';\nimport { PostboyGenericMessage } from './postboy-generic-message';\n\n/**\n * An abstract class extending PostboyGenericMessage that provides mechanisms for managing\n * asynchronous data communication using RxJS observables. It is designed to work with\n * callback-based operations that emit a result of type T.\n *\n * @template T - The type of the data emitted by the observables in this class.\n *\n * @extends PostboyGenericMessage\n *\n * @property {Observable<T>} result - An observable that emits the result of the operation\n * and completes once the operation is finished.\n *\n * @method next - Emits the next value for the result observable.\n * @param {T} value - The value to be emitted by the result observable.\n *\n * @method finish - Emits the final value for the result observable and completes it.\n * @param {T} value - The final value for the observable emission.\n */\nexport abstract class PostboyCallbackMessage<T> extends PostboyGenericMessage {\n protected result$ = new Subject<T>();\n public result: Observable<T> = this.result$.asObservable();\n\n /**\n * Emits the provided value.\n *\n * @template T - The type of the value to emit.\n * @param {T} value - The value to emit through the `result$` observable.\n * @returns {void}\n */\n public next = (value: T): void => this.result$.next(value);\n\n /**\n * Marks the operation as complete by emitting the provided value and then completing the result stream.\n *\n * @param {T} value - The value to emit prior to completing the result stream.\n * @return {void} This method does not return a value.\n */\n public finish(value: T): void {\n this.result$.next(value);\n this.result$.complete();\n }\n\n /**\n * Completes the current observable result stream.\n * This method marks the result observable as complete, ensuring no further values\n * or events will be emitted from it.\n *\n * @return {void} No value is returned from this method.\n */\n public complete(): void {\n this.result$.complete();\n }\n}\n","import { PostboyExecutor } from './postboy-executor';\n\n/**\n * Abstract class representing a handler for executing a Postboy task.\n *\n * This class is intended to manage the execution flow of a PostboyExecutor instance.\n * Subclasses must implement the `handle` method, which executes a given PostboyExecutor\n * and returns a result of type R.\n *\n * @template R The type of the result returned by the `handle` method.\n * @template E The type of the executor extending the PostboyExecutor.\n */\nexport abstract class PostboyExecutionHandler<R, E extends PostboyExecutor<R>> {\n /**\n * Abstract method to handle the specified executor and return a result.\n *\n * @param {E} executor - The executor that will be processed by the method.\n * @return {R} The result obtained after handling the executor.\n */\n abstract handle(executor: E): R;\n}\n"]}
1
+ {"version":3,"sources":["../src/models/postboy.message.ts","../src/models/postboy-generic-message.ts","../src/models/postboy-subscription.ts","../src/models/middleware-stage.enum.ts","../src/models/middleware-decision.enum.ts","../src/models/cancel-error.ts","../src/services/postboy-middleware.service.ts","../src/services/postboy-message.store.ts","../src/utils/id.generator.ts","../src/models/postboy-executor.ts","../src/messages/connect-message.executor.ts","../src/messages/disconnect-message.executor.ts","../src/messages/connect-executor.executor.ts","../src/messages/connect-handler.executor.ts","../src/postboy-abstract.registrator.ts","../src/services/namespace-registrator.ts","../src/services/postboy-namespace.store.ts","../src/services/postboy-dependency.resolver.ts","../src/messages/add-namespace.executor.ts","../src/messages/eliminate-namespace.executor.ts","../src/messages/add-middleware.executor.ts","../src/messages/remove-middleware.executor.ts","../src/messages/lock-message.executor.ts","../src/messages/unlock-message.executor.ts","../src/postboy.service.ts","../src/services/postboy-middleware.ts","../src/models/postboy-callback.message.ts","../src/models/postboy-execution.handler.ts"],"names":["PostboyMessage","metadata","PostboyGenericMessage","checkId","message","PostboySubscription","subscription","pipe","data","MiddlewareStage","MiddlewareDecisionType","CancelError","details","PostboyMiddlewareService","middleware","m","stage","context","result","cancelledBy","messageId","namespace","PostboyMessageStore","id","sub","executor","existingCallbacks","name","msg","executorFunction","c","fs","f","_IdGenerator","i","IdGenerator","PostboyExecutor","ConnectMessage","type","DisconnectMessage","ConnectExecutor","exec","ConnectHandler","handler","PostboyAbstractRegistrator","postboy","services","s","bufferSize","ReplaySubject","initial","BehaviorSubject","Subject","NamespaceRegistrator","PostboyNamespaceStore","space","registrator","PostboyDependencyResolver","AddNamespace","EliminateNamespace","AddMiddleware","RemoveMiddleware","LockMessage","UnlockMessage","PostboyService","resolver","e","action","result$","tap","observable","Observable","subscriber","first","PostboyMiddleware","_context","_result","PostboyCallbackMessage","value","PostboyExecutionHandler"],"mappings":"sCAEO,IAAeA,CAAAA,CAAf,KAA8B,CAA9B,cACL,IAAA,CAAO,QAAA,CAAmC,GAAC,CAC3C,IAAW,IAAa,CACtB,OAAQ,IAAA,CAAK,WAAA,CAAoB,EACnC,CAEA,YAAYC,CAAAA,CAAiD,CAC3D,YAAK,QAAA,CAAW,CAAE,GAAG,IAAA,CAAK,QAAA,CAAU,GAAGA,CAAS,CAAA,CACzC,IACT,CACF,ECPO,IAAeC,CAAAA,CAAf,cAA6CF,CAAe,GAC5D,SAASG,CAAAA,CAAQC,CAAAA,CAA8C,CACpE,GAAI,CAAEA,EAAgB,EAAA,CAAI,MAAM,IAAI,KAAA,CAAM,CAAA,EAAGA,EAAQ,IAAI,CAAA,8BAAA,CAAgC,CAAA,CACzF,OAAQA,CAAAA,CAAgB,EAC1B,CCAO,IAAMC,CAAAA,CAAN,KAA6B,CASlC,WAAA,CACUC,CAAAA,CACRC,EACA,CAFQ,IAAA,CAAA,YAAA,CAAAD,CAAAA,CAGR,IAAA,CAAK,aAAA,CAAkBC,CAAAA,CAAOA,EAAKD,CAAY,CAAA,CAAIA,EAAa,YAAA,GAClE,CAOO,GAAA,EAAqB,CAC1B,OAAO,IAAA,CAAK,aACd,CAQO,KAAKE,CAAAA,CAAe,CACzB,IAAA,CAAK,YAAA,CAAa,IAAA,CAAKA,CAAI,EAC7B,CAOO,MAAA,EAAe,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AA,CAAA,GAAA,SAAA,CAAA,CACL,IAAA,CAAU,OAAA,CAAU,IAAIkD,aACxB,IAAA,CAAO,MAAA,CAAwB,IAAA,CAAK,OAAA,CAAQ,YAAA,EAAa,CASzD,KAAO,IAAA,CAAQ0B,CAAAA,EAAmB,IAAA,CAAK,OAAA,CAAQ,IAAA,CAAKA,CAAK,GAQlD,MAAA,CAAOA,CAAAA,CAAgB,CAC5B,IAAA,CAAK,OAAA,CAAQ,KAAKA,CAAK,CAAA,CACvB,IAAA,CAAK,OAAA,CAAQ,QAAA,GACf,CASO,QAAA,EAAiB,CACtB,IAAA,CAAK,OAAA,CAAQ,QAAA,GACf,CACF,EC3CO,IAAeC,CAAAA,CAAf,KAAwE","file":"index.cjs","sourcesContent":["import { PostboyMessageMetadata } from './postboy-message-metadata';\n\nexport abstract class PostboyMessage {\n public metadata: PostboyMessageMetadata = {};\n public get id(): string {\n return (this.constructor as any).ID;\n }\n\n setMetadata(metadata: Partial<PostboyMessageMetadata>): this {\n this.metadata = { ...this.metadata, ...metadata };\n return this;\n }\n}\n","import { PostboyMessage } from './postboy.message';\n\n/**\n * An inheritor should have a static ID field\n */\nexport abstract class PostboyGenericMessage extends PostboyMessage {}\nexport function checkId(message: new (...args: any[]) => any): string {\n if (!(message as any).ID) throw new Error(`${message.name} should have a static ID field`);\n return (message as any).ID;\n}\n","import { Observable, Subject } from 'rxjs';\n\n/**\n * A class that manages a reactive subscription using a provided Subject and transformation pipe.\n * Offers methods to interact with the subscription, such as emitting data, completing the subscription,\n * and accessing the transformed observable.\n *\n * @template T The type of data managed by the subscription.\n */\nexport class PostboySubscription<T> {\n private readonly _subscription: Observable<T>;\n\n /**\n * Constructs an instance of the class with a given subscription and a transformation pipe.\n *\n * @param {Subject<T>} subscription - The source Subject that will be transformed.\n * @param {(s: Subject<T>) => Observable<T>} pipe - A function that applies a transformation to the subscription.\n */\n constructor(\n private subscription: Subject<T>,\n pipe?: (s: Subject<T>) => Observable<T>,\n ) {\n this._subscription = !!pipe ? pipe(subscription) : subscription.asObservable();\n }\n\n /**\n * Returns an observable subscription.\n *\n * @return {Observable<T>} An observable instance of type T.\n */\n public sub(): Observable<T> {\n return this._subscription;\n }\n\n /**\n * Triggers an event by emitting the provided data to all subscribers.\n *\n * @param {T} data - The data to emit to the subscribers.\n * @return {void} - Does not return any value.\n */\n public fire(data: T): void {\n this.subscription.next(data);\n }\n\n /**\n * Completes the subscription, signaling that no further values will be sent.\n * This is typically used to finalize or clean up resources.\n * @return {void} This method does not return any value.\n */\n public finish(): void {\n this.subscription.complete();\n }\n}\n","export enum MiddlewareStage {\n Publish = 1,\n Callback,\n Execute,\n}\n","export enum MiddlewareDecisionType {\n Continue = 1,\n Interrupt,\n}\n","import { CancelDetails } from './cancel-details';\nimport { MiddlewareStage } from './middleware-stage.enum';\n\nexport class CancelError extends Error {\n public readonly details: CancelDetails;\n\n constructor(details: CancelDetails) {\n super(details.reason ?? `Postboy operation was cancelled at stage \"${MiddlewareStage[details.stage]}\"`);\n this.name = 'PostboyCancelError';\n this.details = details;\n }\n}\n\nexport function isCancelError(error: unknown): error is CancelError {\n return error instanceof CancelError;\n}\n","import { PostboyMessage } from '../models/postboy.message';\nimport { PostboyMessageContext } from '../models/postboy-message.context';\nimport { PostboyExecutor } from '../models/postboy-executor';\nimport { PipelineContext } from '../models/pipeline-context';\nimport { PostboyMiddleware } from './postboy-middleware';\nimport { MiddlewareStage } from '../models/middleware-stage.enum';\nimport { MiddlewareDecisionType } from '../models/middleware-decision.enum';\nimport { CancelError } from '../models/cancel-error';\n\nexport class PostboyMiddlewareService {\n protected middlewares: PostboyMiddleware[] = [];\n\n public addMiddleware(middleware: PostboyMiddleware): void {\n this.middlewares.push(middleware);\n }\n\n public removeMiddleware(middleware: PostboyMiddleware): void {\n this.middlewares = this.middlewares.filter((m) => {\n if (m !== middleware) return true;\n m.dispose();\n return false;\n });\n }\n\n public dispose(): void {\n this.middlewares.forEach((m) => m.dispose());\n this.middlewares = [];\n }\n\n public before<T extends PostboyMessage>(stage: MiddlewareStage, message: T): void {\n for (const middleware of this.middlewares) {\n const context = this.buildContext(stage, message);\n if (!middleware.canHandle(context)) continue;\n if (middleware.before(context).type === MiddlewareDecisionType.Interrupt)\n this.throwIfCancelled(stage, middleware.name, message.id);\n }\n }\n\n public after<T extends PostboyMessage, R = unknown>(stage: MiddlewareStage, message: T, result?: R): void {\n for (const middleware of this.middlewares) {\n const context = this.buildContext(stage, message);\n if (!middleware.canHandle(context)) continue;\n middleware.after(context, result);\n }\n }\n\n public beforePublish(message: PostboyMessage): void {\n this.before(MiddlewareStage.Publish, message);\n }\n\n public afterPublish(message: PostboyMessage): void {\n this.after(MiddlewareStage.Publish, message);\n }\n\n public beforeCallback(message: PostboyMessage): void {\n this.before(MiddlewareStage.Callback, message);\n }\n\n public afterCallback(message: PostboyMessage, result?: unknown): void {\n this.after(MiddlewareStage.Callback, message, result);\n }\n\n public beforeExecute<T>(message: PostboyExecutor<T>): void {\n this.before(MiddlewareStage.Execute, message);\n }\n\n public afterExecute<T>(message: PostboyExecutor<T>, result: T): void {\n this.after(MiddlewareStage.Execute, message, result);\n }\n\n private buildContext<T extends PostboyMessage>(stage: MiddlewareStage, message: T): PipelineContext<T> {\n return { stage, message };\n }\n\n private throwIfCancelled(\n stage: MiddlewareStage,\n cancelledBy?: string,\n messageId?: string,\n namespace?: string,\n ): never {\n throw new CancelError({\n stage,\n middleware: cancelledBy,\n messageId,\n namespace,\n reason: cancelledBy ? `Cancelled by middleware \"${cancelledBy}\"` : undefined,\n });\n }\n}\n","import { PostboySubscription } from '../models/postboy-subscription';\nimport { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyCallbackMessage } from '../models/postboy-callback.message';\n\n/**\n * The PostboyMessageStore is a utility class for managing message subscriptions and executors.\n * It provides functionality to register, retrieve, and unregister subscription-based messages and executors.\n */\nexport class PostboyMessageStore {\n protected messages = new Map<string, PostboySubscription<any>>();\n protected executors = new Map<string, (e: PostboyExecutor<any>) => any>();\n protected callbacks = new Map<string, (() => void)[]>();\n\n public registerMessage(id: string, sub: PostboySubscription<any>): void {\n // tslint:disable-next-line:no-console\n if (this.messages.has(id)) console.warn(`Message with id ${id} already registered. Overriding...`);\n this.messages.set(id, sub);\n }\n\n public registerExecutor(id: string, executor: (e: PostboyExecutor<any>) => any): void {\n // tslint:disable-next-line:no-console\n if (this.executors.has(id)) console.warn(`Executor with id ${id} already registered. Overriding...`);\n this.executors.set(id, executor);\n }\n\n callbackFired(message: PostboyCallbackMessage<any>): void {\n const existingCallbacks = this.callbacks.get(message.id);\n existingCallbacks\n ? existingCallbacks.push(() => message.complete())\n : this.callbacks.set(message.id, [() => message.complete()]);\n }\n\n public getMessage(id: string, name: string): PostboySubscription<any> {\n const msg = this.messages.get(id);\n if (!msg) throw new Error(`There is no registered event ${name}`);\n return msg;\n }\n\n public getExecutor<T>(id: string): (e: PostboyExecutor<T>) => T {\n const executorFunction = this.executors.get(id);\n if (!executorFunction) throw new Error(`There is no registered executor with id ${id}`);\n return executorFunction;\n }\n\n public unregister(id: string): void {\n this.messages.get(id)?.finish();\n this.messages.delete(id);\n this.callbacks.get(id)?.forEach((c) => c());\n this.callbacks.delete(id);\n this.executors.delete(id);\n }\n\n public dispose(): void {\n this.messages.forEach((m, id) => this.unregister(id));\n this.callbacks.forEach((fs) => fs.forEach((f) => f()));\n this.messages.clear();\n this.executors.clear();\n this.callbacks.clear();\n }\n}\n","export class IdGenerator {\n private static collection = 'ABCDEFGHIJKLMNOPQRSTUVWXTZ0123456789'.split('');\n\n public static get(): string {\n const result: string[] = [];\n for (let i = 0; i < 7; i++) {\n result.push(\n IdGenerator.collection\n .sort(() => 0.5 - Math.random())\n .slice(0, 5)\n .join(''),\n );\n }\n return result.join('-');\n }\n}\n","import { PostboyMessage } from './postboy.message';\n\nexport abstract class PostboyExecutor<T> extends PostboyMessage {\n declare protected readonly _postboyResultType?: T;\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyGenericMessage } from '../models/postboy-generic-message';\nimport { MessageType } from '../postboy-abstract.registrator';\nimport { Observable, Subject } from 'rxjs';\n\n/**\n * Represents a message that facilitates connection functionality\n * within the application's messaging system.\n *\n * @template T - A type that extends {@link PostboyGenericMessage}, representing\n * the structure of the message being handled.\n *\n * @extends PostboyExecutor<void>\n */\nexport class ConnectMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {\n static readonly ID = 'aa03a192-bdc7-402d-9f2f-bf3748229ea2';\n\n /**\n * Constructs a new instance of the class.\n *\n * @param {MessageType<T>} type - The type of the message.\n * @param {Subject<T>} sub - The subject to be used for message handling.\n * @param {(s: Subject<T>) => Observable<T>} [pipe] - An optional function to transform the subject.\n */\n constructor(\n public type: MessageType<T>,\n public sub: Subject<T>,\n public pipe?: (s: Subject<T>) => Observable<T>,\n ) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\n\n/**\n * Represents a message signaling a disconnection event. This class is used\n * within the framework to manage and process disconnection notifications.\n * Extends the {@link PostboyExecutor} base class.\n *\n * @extends {PostboyExecutor<void>}\n */\nexport class DisconnectMessage extends PostboyExecutor<void> {\n static readonly ID = '94579e43-5bc9-4517-bcda-b595bcda1ae7';\n\n /**\n * Creates an instance of the class with the specified message identifier.\n *\n * @param {string} messageId - The unique identifier for the message.\n */\n constructor(public messageId: string) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\nimport { MessageType } from '../postboy-abstract.registrator';\n\n/**\n * Registers an executor that connects to a specific type of message handler.\n * This class extends the functionality of `PostboyExecutor` and is designed to manage\n * the execution of a handler defined by a specific message type and an execution function.\n *\n * @template E The type of the executor extending {@link PostboyExecutor}.\n * @template T The return type of the execution function.\n *\n * @extends {PostboyExecutor<void>}\n */\nexport class ConnectExecutor<E extends PostboyExecutor<T>, T> extends PostboyExecutor<void> {\n static readonly ID = 'cb80e8ad-b68c-4b2d-8c44-617ea6017cb3';\n\n /**\n * Constructs an instance of the class with the specified type and execution function.\n *\n * @param {MessageType<E>} type - The type of the message.\n * @param {(e: E) => T} exec - The function to be executed with the input of type E that returns a value of type T.\n */\n constructor(\n public type: MessageType<E>,\n public exec: (e: E) => T,\n ) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyExecutionHandler } from '../models/postboy-execution.handler';\n\n/**\n * Represents a connection handler that extends the PostboyExecutor class.\n *\n * This class encapsulates logic associated with executing a handler in a structured way.\n * It is generic and operates on the provided executor and handler types.\n *\n * Type Parameters:\n * E - Represents an extension of the PostboyExecutor class with a specific type parameter R.\n * R - Represents the type of the result that the executor is expected to operate on.\n */\nexport class ConnectHandler<E extends PostboyExecutor<R>, R> extends PostboyExecutor<void> {\n static readonly ID = 'bf618cea-6f32-417c-9548-8eafe937378b';\n\n /**\n * Constructs an instance of the class.\n *\n * @param {new (...args: any[]) => E} executor - A constructor function for the executor object.\n * @param {PostboyExecutionHandler<R, E>} handler - A handler that processes the execution logic.\n */\n constructor(\n public executor: new (...args: any[]) => E,\n public handler: PostboyExecutionHandler<R, E>,\n ) {\n super();\n }\n}\n","import { PostboyService } from './postboy.service';\nimport { BehaviorSubject, Observable, pipe, ReplaySubject, Subject } from 'rxjs';\nimport { IPostboyDependingService } from './i-postboy-depending.service';\nimport { PostboyExecutor } from './models/postboy-executor';\nimport { checkId, PostboyGenericMessage } from './models/postboy-generic-message';\nimport { PostboyExecutionHandler } from './models/postboy-execution.handler';\nimport { IdGenerator } from './utils/id.generator';\nimport { ConnectMessage } from './messages/connect-message.executor';\nimport { DisconnectMessage } from './messages/disconnect-message.executor';\nimport { ConnectExecutor } from './messages/connect-executor.executor';\nimport { ConnectHandler } from './messages/connect-handler.executor';\n\nexport type MessageType<T extends PostboyGenericMessage> = new (...args: any[]) => T;\n\nexport abstract class PostboyAbstractRegistrator {\n get namespace(): string {\n return this._namespace;\n }\n private ids: string[] = [];\n private services: IPostboyDependingService[] = [];\n private readonly _namespace: string;\n\n constructor(\n protected postboy: PostboyService,\n namespace: string | null = null,\n ) {\n this._namespace = namespace ?? IdGenerator.get();\n }\n\n /**\n * Registers a list of services to be used by the application.\n *\n * @param {IPostboyDependingService[]} services - An array of services to register.\n * @return {void} This method does not return a value.\n */\n public registerServices(services: IPostboyDependingService[]): void {\n this.services = services;\n }\n\n /**\n * Initiates the 'up' process for the current instance and all associated services.\n *\n * @return {void} Does not return a value.\n */\n public up(): void {\n this._up?.();\n this.services.forEach((s) => s.up());\n }\n\n protected abstract _up(): void;\n\n public down(): void {\n this.services.forEach((s) => !!s.down && s.down());\n this.services = [];\n this.ids.forEach((id) => this.postboy.exec(new DisconnectMessage(id)));\n }\n\n /**\n * Records a type and its corresponding Subject<T> into the Postboy system and updates the internal identifiers.\n *\n * @param {MessageType<T>} type - A constructor for the generic message type T.\n * @param {Subject<T>} sub - The subject associated with the generic message type.\n * @return {this} Returns the current instance for method chaining.\n */\n public record<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>): PostboyAbstractRegistrator {\n this.ids.push(checkId(type));\n this.postboy.exec(new ConnectMessage(type, sub));\n return this;\n }\n\n /**\n * Records a message type with a specific subject and applies a transformation pipe to the subject.\n *\n * @param {MessageType<T>} type - The constructor of the message type to record, which extends PostboyGenericMessage.\n * @param {Subject<T>} sub - The Subject instance to associate with the message type.\n * @param {(s: Subject<T>) => Observable<T>} pipe - A function that takes the subject as input and returns an Observable with transformations applied.\n * @return {this} The current instance of the class for chaining.\n */\n public recordWithPipe<T extends PostboyGenericMessage>(\n type: MessageType<T>,\n sub: Subject<T>,\n pipe: (s: Subject<T>) => Observable<T>,\n ): PostboyAbstractRegistrator {\n this.ids.push(checkId(type));\n this.postboy.exec(new ConnectMessage(type, sub, pipe));\n return this;\n }\n\n /**\n * Records an executor associated with a specific type and execution logic.\n *\n * @param type The class constructor of the executor type to be recorded, which extends PostboyExecutor.\n * @param exec A callback function that executes the logic using an instance of the specified executor type.\n * @return void\n */\n public recordExecutor<E extends PostboyExecutor<T>, T>(\n type: new (...args: any[]) => E,\n exec: (e: E) => T,\n ): PostboyAbstractRegistrator {\n this.ids.push(checkId(type));\n this.postboy.exec(new ConnectExecutor(type, exec));\n return this;\n }\n\n /**\n * Records a handler for a specific executor type.\n *\n * @param executor The constructor of the executor type, which extends `PostboyExecutor`.\n * @param handler The execution handler associated with the given executor type.\n * @return void\n */\n public recordHandler<E extends PostboyExecutor<R>, R>(\n executor: new (...args: any[]) => E,\n handler: PostboyExecutionHandler<R, E>,\n ): PostboyAbstractRegistrator {\n this.ids.push(checkId(executor));\n this.postboy.exec(new ConnectHandler(executor, handler));\n return this;\n }\n\n /**\n * A utility function that facilitates the recording and replaying of messages\n * using a ReplaySubject. This function is designed to handle messages of a\n * specific type and allows specifying a buffer size to determine how many\n * of the most recent messages should be replayed.\n *\n * @template T Extends the PostboyGenericMessage type, representing the type of message\n * to be recorded and replayed.\n * @param {MessageType<T>} type The constructor of the message type to be recorded and replayed.\n * @param {number} [bufferSize=1] The number of recent messages to retain in the ReplaySubject's buffer.\n * Defaults to 1 if not specified.\n * @returns The result of invoking the `record` method with the given message type and configured ReplaySubject.\n */\n public recordReplay<T extends PostboyGenericMessage>(\n type: MessageType<T>,\n bufferSize = 1,\n ): PostboyAbstractRegistrator {\n this.record(type, new ReplaySubject<T>(bufferSize));\n return this;\n }\n\n /**\n * Represents a method that records a specific behavior associated with a message type.\n * It creates a `BehaviorSubject` initialized with the provided initial message\n * and associates it with the given message type using the `record` method.\n *\n * @template T - A type parameter extending `PostboyGenericMessage` that defines the message structure.\n * @param {MessageType<T>} type - The constructor function of the message type to be recorded.\n * @param {T} initial - The initial value of the message that will be set in the `BehaviorSubject`.\n * @returns {void} - This function does not return a value; instead, it modifies the internal state.\n */\n public recordBehavior<T extends PostboyGenericMessage>(type: MessageType<T>, initial: T): PostboyAbstractRegistrator {\n this.record(type, new BehaviorSubject<T>(initial));\n return this;\n }\n\n /**\n * A function that creates and returns a new generic message recorder for a specific message type.\n *\n * @template T - A type parameter extending from `PostboyGenericMessage`.\n * @param {MessageType<T>} type - The constructor for the message type being recorded.\n * @returns {Subject<T>} A new instance of `Subject<T>` bound to the specified message type.\n */\n public recordSubject<T extends PostboyGenericMessage>(type: MessageType<T>) {\n this.record(type, new Subject<T>());\n return this;\n }\n}\n","import { PostboyAbstractRegistrator } from '../postboy-abstract.registrator';\nimport { PostboyService } from '../postboy.service';\n\n/**\n * NamespaceRegistrator is a specialized class that extends PostboyAbstractRegistrator.\n *\n * @class NamespaceRegistrator\n * @extends PostboyAbstractRegistrator\n * @param {PostboyService} postboy - An instance of the PostboyService, used for managing registrations.\n */\nexport class NamespaceRegistrator extends PostboyAbstractRegistrator {\n constructor(postboy: PostboyService) {\n super(postboy);\n }\n\n protected _up(): void {\n // ignore\n }\n}\n","import { PostboyAbstractRegistrator } from '../postboy-abstract.registrator';\nimport { NamespaceRegistrator } from './namespace-registrator';\nimport { PostboyService } from '../postboy.service';\n\n/**\n * Represents a store for managing namespaces in the Postboy system.\n * Provides functionality to add, eliminate, and dispose namespaces.\n */\nexport class PostboyNamespaceStore {\n private spaces: Map<string, PostboyAbstractRegistrator> = new Map();\n\n /**\n * Adds a new space or retrieves an existing one if it already exists.\n *\n * @param {string} space - The name of the space to add or retrieve.\n * @param {PostboyService} postboy - The PostboyService instance used to create a namespace registrator.\n * @return {PostboyAbstractRegistrator} The registrator associated with the specified space.\n */\n public addSpace(space: string, postboy: PostboyService): PostboyAbstractRegistrator {\n if (this.spaces.has(space)) return this.spaces.get(space)!;\n const registrator = new NamespaceRegistrator(postboy);\n this.spaces.set(space, registrator);\n return registrator;\n }\n\n /**\n * Removes a specified space from the spaces collection if it exists.\n * If the space exists, it will be deleted after invoking its down method.\n *\n * @param {string} space - The name of the space to be removed.\n * @return {void} This method does not return a value.\n */\n public eliminateSpace(space: string): void {\n if (!this.spaces.has(space)) return;\n this.spaces.get(space)?.down();\n this.spaces.delete(space);\n }\n\n /**\n * Disposes of the current instance by performing cleanup operations.\n * Iterates through all spaces, performs a \"down\" operation on each,\n * and then clears the collection of spaces.\n *\n * @return {void} No return value.\n */\n public dispose(): void {\n this.spaces.forEach((space) => space.down());\n this.spaces.clear();\n }\n}\n","import { PostboyMiddlewareService } from './postboy-middleware.service';\nimport { PostboyMessageStore } from './postboy-message.store';\nimport { PostboyNamespaceStore } from './postboy-namespace.store';\n\nexport class PostboyDependencyResolver {\n /**\n * Retrieves an instance of the PostboyMiddlewareService.\n *\n * This function initializes and returns a new instance of the\n * PostboyMiddlewareService, which can be used to configure and manage\n * middleware for a specific module or application.\n *\n * @returns {PostboyMiddlewareService} A new instance of PostboyMiddlewareService.\n */\n getMiddlewareService = () => new PostboyMiddlewareService();\n /**\n * A function that instantiates and returns a new instance of PostboyMessageStore.\n *\n * This function serves as a factory method for creating instances\n * of the PostboyMessageStore class.\n *\n * @returns {PostboyMessageStore} A new instance of the PostboyMessageStore class.\n */\n getMessageStore = () => new PostboyMessageStore();\n /**\n * Creates and initializes a new instance of PostboyNamespaceStore using the provided PostboyService instance.\n *\n * @function getNamespaceStore\n * @returns {PostboyNamespaceStore} A new instance of PostboyNamespaceStore associated with the given PostboyService.\n */\n getNamespaceStore = () => new PostboyNamespaceStore();\n}\n","import { PostboyAbstractRegistrator } from '../postboy-abstract.registrator';\nimport { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyExecutionHandler } from '../models/postboy-execution.handler';\nimport { PostboyNamespaceStore } from '../services/postboy-namespace.store';\nimport { PostboyService } from '../postboy.service';\n\n/**\n * AddNamespace is a class that extends the PostboyExecutor with a specific implementation\n * for adding namespaces to a PostboyService instance.\n *\n * This class is identified uniquely by its static ID property for tracking and referencing purposes.\n */\nexport class AddNamespace extends PostboyExecutor<PostboyAbstractRegistrator> {\n static readonly ID = '6d1a6f7d-6b6e-4c4d-8af8-9cc9a32e850c';\n\n /**\n * Creates an instance of the class with the specified space identifier.\n *\n * @param {string} space - The identifier for the space.\n */\n constructor(public space: string) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\n\n/**\n * Represents an executor that eliminates a specific namespace.\n * This class extends the PostboyExecutor with a void return type.\n */\nexport class EliminateNamespace extends PostboyExecutor<void> {\n static readonly ID = '03bb03bb-53e0-4b74-9aad-64d5c54a8972';\n\n /**\n * Creates an instance of the class with the specified space value.\n *\n * @param {string} space - The string value representing the space configuration.\n */\n constructor(public space: string) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyMiddleware } from '../services/postboy-middleware';\n\n/**\n * Represents a {@link PostboyMiddleware} addition operation for Postboy.\n * This class extends the functionality of the PostboyExecutor to add middleware to the processing chain.\n *\n * The middleware to be added is provided during instantiation.\n */\nexport class AddMiddleware extends PostboyExecutor<void> {\n static readonly ID = '0a8cfe0a-6193-4082-8440-d0793367b21d';\n\n /**\n * Initializes a new instance of the class with the specified middleware.\n *\n * @param {PostboyMiddleware} middleware - The {@link PostboyMiddleware} to be used for processing.\n */\n constructor(public middleware: PostboyMiddleware) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyMiddleware } from '../services/postboy-middleware';\n\n/**\n * Represents a class responsible for removing {@link PostboyMiddleware} in execution flow.\n * This class extends PostboyExecutor and operates with a void return type.\n */\nexport class RemoveMiddleware extends PostboyExecutor<void> {\n static readonly ID = 'c25c708c-53c9-498d-a28b-936fbaf68b91';\n\n /**\n * Constructs an instance of the class with the specified middleware.\n *\n * @param {PostboyMiddleware} middleware - The {@link PostboyMiddleware} instance to be removed.\n */\n constructor(public middleware: PostboyMiddleware) {\n super();\n }\n}\n","import { PostboyGenericMessage } from '../models/postboy-generic-message';\nimport { MessageType } from '../postboy-abstract.registrator';\nimport { PostboyExecutor } from '../models/postboy-executor';\n\n/**\n * Locks a specific message type to prevent firing of them.\n *\n * This class is used to handle operations associated with locking mechanisms\n * for a specified message type.\n *\n * @template T - A type that extends {@link PostboyGenericMessage}.\n */\nexport class LockMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {\n static readonly ID = '477df3e2-1f99-4476-9a3b-afd1fa426436';\n\n /**\n * Constructs an instance of the class with the specified message type.\n *\n * @param {MessageType<T>} type - The type of the message to be used for the instance.\n */\n constructor(public type: MessageType<T>) {\n super();\n }\n}\n","import { PostboyGenericMessage } from '../models/postboy-generic-message';\nimport { PostboyExecutor } from '../models/postboy-executor';\nimport { MessageType } from '../postboy-abstract.registrator';\n\n/**\n * A specialized executor that handles the unlocking process for messages of a specified type.\n * Unlocks a previously locked message, making it available for processing again.\n *\n * @template T - The type parameter extending {@link PostboyGenericMessage}, representing the message type handled by the executor.\n * @extends {PostboyExecutor<void>}\n */\nexport class UnlockMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {\n static readonly ID = 'd71d25e3-90ac-4009-b972-9e6c6b05611e';\n\n /**\n * Creates an instance of the class with the specified message type.\n *\n * @param {MessageType<T>} type - The message type for this instance.\n */\n constructor(public type: MessageType<T>) {\n super();\n }\n}\n","import { first, Observable, Subject, tap } from 'rxjs';\nimport { checkId, PostboyGenericMessage } from './models/postboy-generic-message';\nimport { PostboySubscription } from './models/postboy-subscription';\nimport { PostboyExecutor } from './models/postboy-executor';\nimport { PostboyCallbackMessage } from './models/postboy-callback.message';\nimport { MessageType } from './postboy-abstract.registrator';\nimport { PostboyExecutionHandler } from './models/postboy-execution.handler';\nimport { PostboyDependencyResolver } from './services/postboy-dependency.resolver';\nimport { PostboyMiddlewareService } from './services/postboy-middleware.service';\nimport { PostboyMessageStore } from './services/postboy-message.store';\nimport { PostboyNamespaceStore } from './services/postboy-namespace.store';\nimport { AddNamespace } from './messages/add-namespace.executor';\nimport { EliminateNamespace } from './messages/eliminate-namespace.executor';\nimport { AddMiddleware } from './messages/add-middleware.executor';\nimport { RemoveMiddleware } from './messages/remove-middleware.executor';\nimport { LockMessage } from './messages/lock-message.executor';\nimport { UnlockMessage } from './messages/unlock-message.executor';\nimport { DisconnectMessage } from './messages/disconnect-message.executor';\nimport { ConnectMessage } from './messages/connect-message.executor';\nimport { ConnectExecutor } from './messages/connect-executor.executor';\nimport { ConnectHandler } from './messages/connect-handler.executor';\n\nexport class PostboyService {\n protected locked = new Set<string>();\n private middleware: PostboyMiddlewareService;\n private store: PostboyMessageStore;\n private namespaceStore: PostboyNamespaceStore;\n private dependencyResolver: PostboyDependencyResolver;\n\n constructor(resolver?: PostboyDependencyResolver) {\n this.dependencyResolver = resolver || new PostboyDependencyResolver();\n this.middleware = this.dependencyResolver.getMiddlewareService();\n this.store = this.dependencyResolver.getMessageStore();\n this.namespaceStore = this.dependencyResolver.getNamespaceStore();\n this.registerInfrastructureMessages();\n }\n\n private registerInfrastructureMessages() {\n this.store.registerExecutor(DisconnectMessage.ID, (e) => this.store.unregister((e as DisconnectMessage).messageId));\n this.store.registerExecutor(UnlockMessage.ID, (e) => this.locked.delete(checkId((e as UnlockMessage<any>).type)));\n this.store.registerExecutor(LockMessage.ID, (e) => this.locked.add(checkId((e as LockMessage<any>).type)));\n this.store.registerExecutor(AddMiddleware.ID, (e) =>\n this.middleware.addMiddleware((e as AddMiddleware).middleware),\n );\n this.store.registerExecutor(RemoveMiddleware.ID, (e) =>\n this.middleware.removeMiddleware((e as RemoveMiddleware).middleware),\n );\n this.store.registerExecutor(AddNamespace.ID, (e) => this.namespaceStore.addSpace((e as AddNamespace).space, this));\n this.store.registerExecutor(EliminateNamespace.ID, (e) =>\n this.namespaceStore.eliminateSpace((e as EliminateNamespace).space),\n );\n this.store.registerExecutor(ConnectMessage.ID, (e) => {\n const { type, sub, pipe } = e as ConnectMessage<any>;\n this.store.registerMessage(checkId(type), new PostboySubscription<any>(sub, pipe));\n });\n this.store.registerExecutor(ConnectExecutor.ID, (e) => {\n const { type, exec } = e as ConnectExecutor<any, any>;\n this.store.registerExecutor(checkId(type), exec);\n });\n this.store.registerExecutor(ConnectHandler.ID, (e) => {\n const { executor, handler } = e as ConnectHandler<any, any>;\n this.store.registerExecutor(checkId(executor), (e) => handler.handle(e));\n });\n }\n\n /**\n * Fires a registered event and passes the message to its subscribers.\n *\n * @param {PostboyGenericMessage} message - The message object containing the event data.\n * @return {void} This method does not return a value.\n * @throws {Error} Throws an error if no registered event is found for the provided message ID.\n */\n public fire(message: PostboyGenericMessage): void {\n this.middleware.beforePublish(message);\n if (!this.locked.has(message.id)) {\n this.store.getMessage(message.id, message.constructor.name).fire(message);\n }\n this.middleware.afterPublish(message);\n }\n\n /**\n * Triggers a callback function associated with a given message.\n *\n * @param {PostboyCallbackMessage<T>} message - The message object used to trigger the callback.\n * It contains details about the event and result subscription.\n * @param {(e: T) => void} [action] - Optional callback function to execute when the result of the message is emitted.\n * @return {void} This method does not return any value.\n */\n public fireCallback<T>(message: PostboyCallbackMessage<T>, action?: (e: T) => void): Observable<T> {\n this.middleware.beforeCallback(message);\n if (action) message.result.subscribe(action);\n this.store.callbackFired(message);\n const result$ = action ? message.result.pipe(tap(action)) : message.result;\n const msg = this.store.getMessage(message.id, message.constructor.name);\n const observable = new Observable<T>((subscriber) => {\n const subscription = result$.pipe(tap(() => this.middleware.afterCallback(message))).subscribe(subscriber);\n\n if (!this.locked.has(message.id)) {\n msg.fire(message);\n }\n\n return () => subscription.unsubscribe();\n });\n if (!!action) observable.subscribe();\n return observable;\n }\n\n /**\n * Executes the provided executor function and returns its result.\n *\n * @param {PostboyExecutor<T>} executor The executor to be executed, which includes its identifier and logic.\n * @return {T} The resulting output from the executed executor function.\n * @throws {Error} If the specified executor is not registered.\n */\n public exec<T>(executor: PostboyExecutor<T>): T {\n this.middleware.beforeExecute(executor);\n const result = this.store.getExecutor<T>(executor.id)(executor);\n this.middleware.afterExecute(executor, result);\n return result;\n }\n\n /**\n * Subscribes to a specific message type and returns an observable of that type.\n *\n * @param type The constructor function of the type that extends PostboyGenericMessage.\n * @return An Observable of the specified generic message type.\n */\n public sub<T extends PostboyGenericMessage>(type: MessageType<T>): Observable<T> {\n return this.store.getMessage(checkId(type), type.name).sub();\n }\n\n /**\n * Subscribes to a specific message type and automatically unsubscribes after receiving the first message.\n *\n * @param type The type of message to subscribe to.\n * @return An observable that emits the first message of the specified type and then completes.\n */\n public once<T extends PostboyGenericMessage>(type: MessageType<T>): Observable<T> {\n return this.sub(type).pipe(first());\n }\n\n /**\n * Registers a given message type and its associated subject subscription with the system.\n *\n * @deprecated The method should be replaced with firing {@link ConnectMessage} message.\n * @param type The constructor function of the message type that extends the PostboyGenericMessage.\n * @param sub The Subject instance for the provided message type, used for managing subscriptions.\n * @return {void} No return value.\n */\n public record<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>): void {\n this.store.registerMessage(checkId(type), new PostboySubscription<T>(sub, (s) => s.asObservable()));\n }\n\n /**\n * Registers a generic message type with a Subject and a transformation pipe.\n *\n * @deprecated The method should be replaced with firing {@link ConnectMessage} message.\n * @param {MessageType<T>} type - The constructor of the message type being registered.\n * @param {Subject<T>} sub - The Subject instance used to handle incoming messages of the specified type.\n * @param {(s: Subject<T>) => Observable<T>} pipe - A function that applies a transformation or processing logic to the Subject and returns an Observable.\n * @return {void} No return value.\n */\n public recordWithPipe<T extends PostboyGenericMessage>(\n type: MessageType<T>,\n sub: Subject<T>,\n pipe: (s: Subject<T>) => Observable<T>,\n ): void {\n this.store.registerMessage(checkId(type), new PostboySubscription<T>(sub, pipe));\n }\n\n /**\n * Registers an executor for a specified message type.\n *\n * @deprecated The method should be replaced with firing {@link ConnectExecutor} message.\n * @param {MessageType<E>} type - The message type for which the executor is being registered.\n * @param {(e: E) => T} exec - The executor function that will handle messages of the specified type.\n * @return {void} This method does not return any value.\n */\n public recordExecutor<E extends PostboyExecutor<T>, T>(type: MessageType<E>, exec: (e: E) => T): void {\n this.store.registerExecutor(checkId(type), exec as (e: PostboyExecutor<T>) => T);\n }\n\n /**\n * Registers a handler for a specific executor type.\n *\n * @deprecated The method should be replaced with firing {@link ConnectHandler} message.\n * @param executor The constructor of the executor class that extends `PostboyExecutor<R>`.\n * @param handler An instance of `PostboyExecutionHandler<R, E>` that defines the logic for handling the executor.\n * @return void\n */\n public recordHandler<E extends PostboyExecutor<R>, R>(\n executor: new (...args: any[]) => E,\n handler: PostboyExecutionHandler<R, E>,\n ): void {\n this.store.registerExecutor(checkId(executor), (e) => handler.handle(e as E));\n }\n\n /**\n * Disposes of resources and cleans up any internal components or stores associated with the instance.\n * This method ensures that all resources are properly released to avoid memory leaks.\n *\n * @return {void} This method does not return a value.\n */\n public dispose(): void {\n this.namespaceStore?.dispose();\n this.store.dispose();\n this.middleware.dispose();\n }\n}\n","import { PipelineContext } from '../models/pipeline-context';\nimport { MiddlewareDecisionType } from '../models/middleware-decision.enum';\nimport { MiddlewareDecision } from '../models';\n\n/**\n * Abstract base class for defining middleware in a pipeline.\n * Middleware acts on various stages of pipeline execution, allowing operations\n * to be intercepted, modified, or monitored.\n */\nexport abstract class PostboyMiddleware {\n public readonly name: string;\n\n /**\n * Creates an instance of a class, optionally assigning a name.\n *\n * @param {string} [name] - An optional name to be assigned. If not provided, defaults to the class name.\n */\n constructor(name?: string) {\n this.name = name ?? this.constructor.name;\n }\n\n /**\n * Optional filter to skip middleware for unrelated messages/stages.\n */\n public canHandle(_context: PipelineContext): boolean {\n return true;\n }\n\n /**\n * Called before the stage is executed.\n * Return Interrupt to cancel the operation.\n */\n public before(_context: PipelineContext): MiddlewareDecision {\n return { type: MiddlewareDecisionType.Continue };\n }\n\n /**\n * Called after the stage has finished successfully.\n * `result` is typically set for execute-stage.\n */\n public after(_context: PipelineContext, _result?: unknown): void {\n // noop\n }\n\n /**\n * Optional cleanup hook.\n */\n public dispose(): void {\n // noop\n }\n}\n","import { Observable, Subject } from 'rxjs';\nimport { PostboyGenericMessage } from './postboy-generic-message';\n\n/**\n * An abstract class extending PostboyGenericMessage that provides mechanisms for managing\n * asynchronous data communication using RxJS observables. It is designed to work with\n * callback-based operations that emit a result of type T.\n *\n * @template T - The type of the data emitted by the observables in this class.\n *\n * @extends PostboyGenericMessage\n *\n * @property {Observable<T>} result - An observable that emits the result of the operation\n * and completes once the operation is finished.\n *\n * @method next - Emits the next value for the result observable.\n * @param {T} value - The value to be emitted by the result observable.\n *\n * @method finish - Emits the final value for the result observable and completes it.\n * @param {T} value - The final value for the observable emission.\n */\nexport abstract class PostboyCallbackMessage<T> extends PostboyGenericMessage {\n protected result$ = new Subject<T>();\n public result: Observable<T> = this.result$.asObservable();\n\n /**\n * Emits the provided value.\n *\n * @template T - The type of the value to emit.\n * @param {T} value - The value to emit through the `result$` observable.\n * @returns {void}\n */\n public next = (value: T): void => this.result$.next(value);\n\n /**\n * Marks the operation as complete by emitting the provided value and then completing the result stream.\n *\n * @param {T} value - The value to emit prior to completing the result stream.\n * @return {void} This method does not return a value.\n */\n public finish(value: T): void {\n this.result$.next(value);\n this.result$.complete();\n }\n\n /**\n * Completes the current observable result stream.\n * This method marks the result observable as complete, ensuring no further values\n * or events will be emitted from it.\n *\n * @return {void} No value is returned from this method.\n */\n public complete(): void {\n this.result$.complete();\n }\n}\n","import { PostboyExecutor } from './postboy-executor';\n\n/**\n * Abstract class representing a handler for executing a Postboy task.\n *\n * This class is intended to manage the execution flow of a PostboyExecutor instance.\n * Subclasses must implement the `handle` method, which executes a given PostboyExecutor\n * and returns a result of type R.\n *\n * @template R The type of the result returned by the `handle` method.\n * @template E The type of the executor extending the PostboyExecutor.\n */\nexport abstract class PostboyExecutionHandler<R, E extends PostboyExecutor<R>> {\n /**\n * Abstract method to handle the specified executor and return a result.\n *\n * @param {E} executor - The executor that will be processed by the method.\n * @return {R} The result obtained after handling the executor.\n */\n abstract handle(executor: E): R;\n}\n"]}
package/lib/index.d.mts CHANGED
@@ -546,7 +546,6 @@ declare class RemoveMiddleware extends PostboyExecutor<void> {
546
546
  /**
547
547
  * Locks a specific message type to prevent firing of them.
548
548
  *
549
- * @deprecated Use {@link PostboyMiddleware}
550
549
  * This class is used to handle operations associated with locking mechanisms
551
550
  * for a specified message type.
552
551
  *
@@ -567,7 +566,6 @@ declare class LockMessage<T extends PostboyGenericMessage> extends PostboyExecut
567
566
  * A specialized executor that handles the unlocking process for messages of a specified type.
568
567
  * Unlocks a previously locked message, making it available for processing again.
569
568
  *
570
- * @deprecated Use {@link PostboyMiddleware}
571
569
  * @template T - The type parameter extending {@link PostboyGenericMessage}, representing the message type handled by the executor.
572
570
  * @extends {PostboyExecutor<void>}
573
571
  */
package/lib/index.d.ts CHANGED
@@ -546,7 +546,6 @@ declare class RemoveMiddleware extends PostboyExecutor<void> {
546
546
  /**
547
547
  * Locks a specific message type to prevent firing of them.
548
548
  *
549
- * @deprecated Use {@link PostboyMiddleware}
550
549
  * This class is used to handle operations associated with locking mechanisms
551
550
  * for a specified message type.
552
551
  *
@@ -567,7 +566,6 @@ declare class LockMessage<T extends PostboyGenericMessage> extends PostboyExecut
567
566
  * A specialized executor that handles the unlocking process for messages of a specified type.
568
567
  * Unlocks a previously locked message, making it available for processing again.
569
568
  *
570
- * @deprecated Use {@link PostboyMiddleware}
571
569
  * @template T - The type parameter extending {@link PostboyGenericMessage}, representing the message type handled by the executor.
572
570
  * @extends {PostboyExecutor<void>}
573
571
  */
package/lib/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import {ReplaySubject,BehaviorSubject,Subject,tap,Observable,first}from'rxjs';var d=class{constructor(){this.metadata={};}get id(){return this.constructor.ID}setMetadata(e){return this.metadata={...this.metadata,...e},this}};var P=class extends d{};function i(o){if(!o.ID)throw new Error(`${o.name} should have a static ID field`);return o.ID}var l=class{constructor(e,t){this.subscription=e;this._subscription=t?t(e):e.asObservable();}sub(){return this._subscription}fire(e){this.subscription.next(e);}finish(){this.subscription.complete();}};var M=(r=>(r[r.Publish=1]="Publish",r[r.Callback=2]="Callback",r[r.Execute=3]="Execute",r))(M||{});var j=(t=>(t[t.Continue=1]="Continue",t[t.Interrupt=2]="Interrupt",t))(j||{});var T=class extends Error{constructor(e){super(e.reason??`Postboy operation was cancelled at stage "${M[e.stage]}"`),this.name="PostboyCancelError",this.details=e;}};var E=class{constructor(){this.middlewares=[];}addMiddleware(e){this.middlewares.push(e);}removeMiddleware(e){this.middlewares=this.middlewares.filter(t=>t!==e?true:(t.dispose(),false));}dispose(){this.middlewares.forEach(e=>e.dispose()),this.middlewares=[];}before(e,t){for(let r of this.middlewares){let a=this.buildContext(e,t);r.canHandle(a)&&r.before(a).type===2&&this.throwIfCancelled(e,r.name,t.id);}}after(e,t,r){for(let a of this.middlewares){let g=this.buildContext(e,t);a.canHandle(g)&&a.after(g,r);}}beforePublish(e){this.before(1,e);}afterPublish(e){this.after(1,e);}beforeCallback(e){this.before(2,e);}afterCallback(e,t){this.after(2,e,t);}beforeExecute(e){this.before(3,e);}afterExecute(e,t){this.after(3,e,t);}buildContext(e,t){return {stage:e,message:t}}throwIfCancelled(e,t,r,a){throw new T({stage:e,middleware:t,messageId:r,namespace:a,reason:t?`Cancelled by middleware "${t}"`:void 0})}};var w=class{constructor(){this.messages=new Map;this.executors=new Map;this.callbacks=new Map;}registerMessage(e,t){this.messages.has(e)&&console.warn(`Message with id ${e} already registered. Overriding...`),this.messages.set(e,t);}registerExecutor(e,t){this.executors.has(e)&&console.warn(`Executor with id ${e} already registered. Overriding...`),this.executors.set(e,t);}callbackFired(e){let t=this.callbacks.get(e.id);t?t.push(()=>e.complete()):this.callbacks.set(e.id,[()=>e.complete()]);}getMessage(e,t){let r=this.messages.get(e);if(!r)throw new Error(`There is no registered event ${t}`);return r}getExecutor(e){let t=this.executors.get(e);if(!t)throw new Error(`There is no registered executor with id ${e}`);return t}unregister(e){this.messages.get(e)?.finish(),this.messages.delete(e),this.callbacks.get(e)?.forEach(t=>t()),this.callbacks.delete(e),this.executors.delete(e);}dispose(){this.messages.forEach((e,t)=>this.unregister(t)),this.callbacks.forEach(e=>e.forEach(t=>t())),this.messages.clear(),this.executors.clear(),this.callbacks.clear();}};var C=class C{static get(){let e=[];for(let t=0;t<7;t++)e.push(C.collection.sort(()=>.5-Math.random()).slice(0,5).join(""));return e.join("-")}};C.collection="ABCDEFGHIJKLMNOPQRSTUVWXTZ0123456789".split("");var S=C;var s=class extends d{};var c=class extends s{constructor(t,r,a){super();this.type=t;this.sub=r;this.pipe=a;}};c.ID="aa03a192-bdc7-402d-9f2f-bf3748229ea2";var n=class extends s{constructor(t){super();this.messageId=t;}};n.ID="94579e43-5bc9-4517-bcda-b595bcda1ae7";var p=class extends s{constructor(t,r){super();this.type=t;this.exec=r;}};p.ID="cb80e8ad-b68c-4b2d-8c44-617ea6017cb3";var b=class extends s{constructor(t,r){super();this.executor=t;this.handler=r;}};b.ID="bf618cea-6f32-417c-9548-8eafe937378b";var R=class{constructor(e,t=null){this.postboy=e;this.ids=[];this.services=[];this._namespace=t??S.get();}get namespace(){return this._namespace}registerServices(e){this.services=e;}up(){this._up?.(),this.services.forEach(e=>e.up());}down(){this.services.forEach(e=>!!e.down&&e.down()),this.services=[],this.ids.forEach(e=>this.postboy.exec(new n(e)));}record(e,t){return this.ids.push(i(e)),this.postboy.exec(new c(e,t)),this}recordWithPipe(e,t,r){return this.ids.push(i(e)),this.postboy.exec(new c(e,t,r)),this}recordExecutor(e,t){return this.ids.push(i(e)),this.postboy.exec(new p(e,t)),this}recordHandler(e,t){return this.ids.push(i(e)),this.postboy.exec(new b(e,t)),this}recordReplay(e,t=1){return this.record(e,new ReplaySubject(t)),this}recordBehavior(e,t){return this.record(e,new BehaviorSubject(t)),this}recordSubject(e){return this.record(e,new Subject),this}};var D=class extends R{constructor(e){super(e);}_up(){}};var v=class{constructor(){this.spaces=new Map;}addSpace(e,t){if(this.spaces.has(e))return this.spaces.get(e);let r=new D(t);return this.spaces.set(e,r),r}eliminateSpace(e){this.spaces.has(e)&&(this.spaces.get(e)?.down(),this.spaces.delete(e));}dispose(){this.spaces.forEach(e=>e.down()),this.spaces.clear();}};var I=class{constructor(){this.getMiddlewareService=()=>new E;this.getMessageStore=()=>new w;this.getNamespaceStore=()=>new v;}};var u=class extends s{constructor(t){super();this.space=t;}};u.ID="6d1a6f7d-6b6e-4c4d-8af8-9cc9a32e850c";var m=class extends s{constructor(t){super();this.space=t;}};m.ID="03bb03bb-53e0-4b74-9aad-64d5c54a8972";var f=class extends s{constructor(t){super();this.middleware=t;}};f.ID="0a8cfe0a-6193-4082-8440-d0793367b21d";var y=class extends s{constructor(t){super();this.middleware=t;}};y.ID="c25c708c-53c9-498d-a28b-936fbaf68b91";var x=class extends s{constructor(t){super();this.type=t;}};x.ID="477df3e2-1f99-4476-9a3b-afd1fa426436";var h=class extends s{constructor(t){super();this.type=t;}};h.ID="d71d25e3-90ac-4009-b972-9e6c6b05611e";var A=class{constructor(e){this.locked=new Set;this.dependencyResolver=e||new I,this.middleware=this.dependencyResolver.getMiddlewareService(),this.store=this.dependencyResolver.getMessageStore(),this.namespaceStore=this.dependencyResolver.getNamespaceStore(),this.registerInfrastructureMessages();}registerInfrastructureMessages(){this.store.registerExecutor(n.ID,e=>this.store.unregister(e.messageId)),this.store.registerExecutor(h.ID,e=>this.locked.delete(i(e.type))),this.store.registerExecutor(x.ID,e=>this.locked.add(i(e.type))),this.store.registerExecutor(f.ID,e=>this.middleware.addMiddleware(e.middleware)),this.store.registerExecutor(y.ID,e=>this.middleware.removeMiddleware(e.middleware)),this.store.registerExecutor(u.ID,e=>this.namespaceStore.addSpace(e.space,this)),this.store.registerExecutor(m.ID,e=>this.namespaceStore.eliminateSpace(e.space)),this.store.registerExecutor(c.ID,e=>{let{type:t,sub:r,pipe:a}=e;this.store.registerMessage(i(t),new l(r,a));}),this.store.registerExecutor(p.ID,e=>{let{type:t,exec:r}=e;this.store.registerExecutor(i(t),r);}),this.store.registerExecutor(b.ID,e=>{let{executor:t,handler:r}=e;this.store.registerExecutor(i(t),a=>r.handle(a));});}fire(e){this.middleware.beforePublish(e),this.locked.has(e.id)||this.store.getMessage(e.id,e.constructor.name).fire(e),this.middleware.afterPublish(e);}fireCallback(e,t){this.middleware.beforeCallback(e),t&&e.result.subscribe(t),this.store.callbackFired(e);let r=t?e.result.pipe(tap(t)):e.result,a=this.store.getMessage(e.id,e.constructor.name),g=new Observable($=>{let _=r.pipe(tap(()=>this.middleware.afterCallback(e))).subscribe($);return this.locked.has(e.id)||a.fire(e),()=>_.unsubscribe()});return t&&g.subscribe(),g}exec(e){this.middleware.beforeExecute(e);let t=this.store.getExecutor(e.id)(e);return this.middleware.afterExecute(e,t),t}sub(e){return this.store.getMessage(i(e),e.name).sub()}once(e){return this.sub(e).pipe(first())}record(e,t){this.store.registerMessage(i(e),new l(t,r=>r.asObservable()));}recordWithPipe(e,t,r){this.store.registerMessage(i(e),new l(t,r));}recordExecutor(e,t){this.store.registerExecutor(i(e),t);}recordHandler(e,t){this.store.registerExecutor(i(e),r=>t.handle(r));}dispose(){this.namespaceStore?.dispose(),this.store.dispose(),this.middleware.dispose();}};var H=class{constructor(e){this.name=e??this.constructor.name;}canHandle(e){return true}before(e){return {type:1}}after(e,t){}dispose(){}};var k=class extends P{constructor(){super(...arguments);this.result$=new Subject;this.result=this.result$.asObservable();this.next=t=>this.result$.next(t);}finish(t){this.result$.next(t),this.result$.complete();}complete(){this.result$.complete();}};var O=class{};export{f as AddMiddleware,u as AddNamespace,T as CancelError,p as ConnectExecutor,b as ConnectHandler,c as ConnectMessage,n as DisconnectMessage,m as EliminateNamespace,x as LockMessage,j as MiddlewareDecisionType,M as MiddlewareStage,R as PostboyAbstractRegistrator,k as PostboyCallbackMessage,O as PostboyExecutionHandler,s as PostboyExecutor,P as PostboyGenericMessage,d as PostboyMessage,w as PostboyMessageStore,H as PostboyMiddleware,E as PostboyMiddlewareService,v as PostboyNamespaceStore,A as PostboyService,l as PostboySubscription,y as RemoveMiddleware,h as UnlockMessage};//# sourceMappingURL=index.mjs.map
1
+ import {ReplaySubject,BehaviorSubject,Subject,tap,Observable,first}from'rxjs';var d=class{constructor(){this.metadata={};}get id(){return this.constructor.ID}setMetadata(e){return this.metadata={...this.metadata,...e},this}};var P=class extends d{};function i(o){if(!o.ID)throw new Error(`${o.name} should have a static ID field`);return o.ID}var l=class{constructor(e,t){this.subscription=e;this._subscription=t?t(e):e.asObservable();}sub(){return this._subscription}fire(e){this.subscription.next(e);}finish(){this.subscription.complete();}};var M=(r=>(r[r.Publish=1]="Publish",r[r.Callback=2]="Callback",r[r.Execute=3]="Execute",r))(M||{});var j=(t=>(t[t.Continue=1]="Continue",t[t.Interrupt=2]="Interrupt",t))(j||{});var T=class extends Error{constructor(e){super(e.reason??`Postboy operation was cancelled at stage "${M[e.stage]}"`),this.name="PostboyCancelError",this.details=e;}};var E=class{constructor(){this.middlewares=[];}addMiddleware(e){this.middlewares.push(e);}removeMiddleware(e){this.middlewares=this.middlewares.filter(t=>t!==e?true:(t.dispose(),false));}dispose(){this.middlewares.forEach(e=>e.dispose()),this.middlewares=[];}before(e,t){for(let r of this.middlewares){let a=this.buildContext(e,t);r.canHandle(a)&&r.before(a).type===2&&this.throwIfCancelled(e,r.name,t.id);}}after(e,t,r){for(let a of this.middlewares){let g=this.buildContext(e,t);a.canHandle(g)&&a.after(g,r);}}beforePublish(e){this.before(1,e);}afterPublish(e){this.after(1,e);}beforeCallback(e){this.before(2,e);}afterCallback(e,t){this.after(2,e,t);}beforeExecute(e){this.before(3,e);}afterExecute(e,t){this.after(3,e,t);}buildContext(e,t){return {stage:e,message:t}}throwIfCancelled(e,t,r,a){throw new T({stage:e,middleware:t,messageId:r,namespace:a,reason:t?`Cancelled by middleware "${t}"`:void 0})}};var w=class{constructor(){this.messages=new Map;this.executors=new Map;this.callbacks=new Map;}registerMessage(e,t){this.messages.has(e)&&console.warn(`Message with id ${e} already registered. Overriding...`),this.messages.set(e,t);}registerExecutor(e,t){this.executors.has(e)&&console.warn(`Executor with id ${e} already registered. Overriding...`),this.executors.set(e,t);}callbackFired(e){let t=this.callbacks.get(e.id);t?t.push(()=>e.complete()):this.callbacks.set(e.id,[()=>e.complete()]);}getMessage(e,t){let r=this.messages.get(e);if(!r)throw new Error(`There is no registered event ${t}`);return r}getExecutor(e){let t=this.executors.get(e);if(!t)throw new Error(`There is no registered executor with id ${e}`);return t}unregister(e){this.messages.get(e)?.finish(),this.messages.delete(e),this.callbacks.get(e)?.forEach(t=>t()),this.callbacks.delete(e),this.executors.delete(e);}dispose(){this.messages.forEach((e,t)=>this.unregister(t)),this.callbacks.forEach(e=>e.forEach(t=>t())),this.messages.clear(),this.executors.clear(),this.callbacks.clear();}};var C=class C{static get(){let e=[];for(let t=0;t<7;t++)e.push(C.collection.sort(()=>.5-Math.random()).slice(0,5).join(""));return e.join("-")}};C.collection="ABCDEFGHIJKLMNOPQRSTUVWXTZ0123456789".split("");var S=C;var s=class extends d{};var c=class extends s{constructor(t,r,a){super();this.type=t;this.sub=r;this.pipe=a;}};c.ID="aa03a192-bdc7-402d-9f2f-bf3748229ea2";var n=class extends s{constructor(t){super();this.messageId=t;}};n.ID="94579e43-5bc9-4517-bcda-b595bcda1ae7";var p=class extends s{constructor(t,r){super();this.type=t;this.exec=r;}};p.ID="cb80e8ad-b68c-4b2d-8c44-617ea6017cb3";var b=class extends s{constructor(t,r){super();this.executor=t;this.handler=r;}};b.ID="bf618cea-6f32-417c-9548-8eafe937378b";var D=class{constructor(e,t=null){this.postboy=e;this.ids=[];this.services=[];this._namespace=t??S.get();}get namespace(){return this._namespace}registerServices(e){this.services=e;}up(){this._up?.(),this.services.forEach(e=>e.up());}down(){this.services.forEach(e=>!!e.down&&e.down()),this.services=[],this.ids.forEach(e=>this.postboy.exec(new n(e)));}record(e,t){return this.ids.push(i(e)),this.postboy.exec(new c(e,t)),this}recordWithPipe(e,t,r){return this.ids.push(i(e)),this.postboy.exec(new c(e,t,r)),this}recordExecutor(e,t){return this.ids.push(i(e)),this.postboy.exec(new p(e,t)),this}recordHandler(e,t){return this.ids.push(i(e)),this.postboy.exec(new b(e,t)),this}recordReplay(e,t=1){return this.record(e,new ReplaySubject(t)),this}recordBehavior(e,t){return this.record(e,new BehaviorSubject(t)),this}recordSubject(e){return this.record(e,new Subject),this}};var I=class extends D{constructor(e){super(e);}_up(){}};var v=class{constructor(){this.spaces=new Map;}addSpace(e,t){if(this.spaces.has(e))return this.spaces.get(e);let r=new I(t);return this.spaces.set(e,r),r}eliminateSpace(e){this.spaces.has(e)&&(this.spaces.get(e)?.down(),this.spaces.delete(e));}dispose(){this.spaces.forEach(e=>e.down()),this.spaces.clear();}};var R=class{constructor(){this.getMiddlewareService=()=>new E;this.getMessageStore=()=>new w;this.getNamespaceStore=()=>new v;}};var u=class extends s{constructor(t){super();this.space=t;}};u.ID="6d1a6f7d-6b6e-4c4d-8af8-9cc9a32e850c";var m=class extends s{constructor(t){super();this.space=t;}};m.ID="03bb03bb-53e0-4b74-9aad-64d5c54a8972";var f=class extends s{constructor(t){super();this.middleware=t;}};f.ID="0a8cfe0a-6193-4082-8440-d0793367b21d";var x=class extends s{constructor(t){super();this.middleware=t;}};x.ID="c25c708c-53c9-498d-a28b-936fbaf68b91";var y=class extends s{constructor(t){super();this.type=t;}};y.ID="477df3e2-1f99-4476-9a3b-afd1fa426436";var h=class extends s{constructor(t){super();this.type=t;}};h.ID="d71d25e3-90ac-4009-b972-9e6c6b05611e";var H=class{constructor(e){this.locked=new Set;this.dependencyResolver=e||new R,this.middleware=this.dependencyResolver.getMiddlewareService(),this.store=this.dependencyResolver.getMessageStore(),this.namespaceStore=this.dependencyResolver.getNamespaceStore(),this.registerInfrastructureMessages();}registerInfrastructureMessages(){this.store.registerExecutor(n.ID,e=>this.store.unregister(e.messageId)),this.store.registerExecutor(h.ID,e=>this.locked.delete(i(e.type))),this.store.registerExecutor(y.ID,e=>this.locked.add(i(e.type))),this.store.registerExecutor(f.ID,e=>this.middleware.addMiddleware(e.middleware)),this.store.registerExecutor(x.ID,e=>this.middleware.removeMiddleware(e.middleware)),this.store.registerExecutor(u.ID,e=>this.namespaceStore.addSpace(e.space,this)),this.store.registerExecutor(m.ID,e=>this.namespaceStore.eliminateSpace(e.space)),this.store.registerExecutor(c.ID,e=>{let{type:t,sub:r,pipe:a}=e;this.store.registerMessage(i(t),new l(r,a));}),this.store.registerExecutor(p.ID,e=>{let{type:t,exec:r}=e;this.store.registerExecutor(i(t),r);}),this.store.registerExecutor(b.ID,e=>{let{executor:t,handler:r}=e;this.store.registerExecutor(i(t),a=>r.handle(a));});}fire(e){this.middleware.beforePublish(e),this.locked.has(e.id)||this.store.getMessage(e.id,e.constructor.name).fire(e),this.middleware.afterPublish(e);}fireCallback(e,t){this.middleware.beforeCallback(e),t&&e.result.subscribe(t),this.store.callbackFired(e);let r=t?e.result.pipe(tap(t)):e.result,a=this.store.getMessage(e.id,e.constructor.name),g=new Observable($=>{let _=r.pipe(tap(()=>this.middleware.afterCallback(e))).subscribe($);return this.locked.has(e.id)||a.fire(e),()=>_.unsubscribe()});return t&&g.subscribe(),g}exec(e){this.middleware.beforeExecute(e);let t=this.store.getExecutor(e.id)(e);return this.middleware.afterExecute(e,t),t}sub(e){return this.store.getMessage(i(e),e.name).sub()}once(e){return this.sub(e).pipe(first())}record(e,t){this.store.registerMessage(i(e),new l(t,r=>r.asObservable()));}recordWithPipe(e,t,r){this.store.registerMessage(i(e),new l(t,r));}recordExecutor(e,t){this.store.registerExecutor(i(e),t);}recordHandler(e,t){this.store.registerExecutor(i(e),r=>t.handle(r));}dispose(){this.namespaceStore?.dispose(),this.store.dispose(),this.middleware.dispose();}};var A=class{constructor(e){this.name=e??this.constructor.name;}canHandle(e){return true}before(e){return {type:1}}after(e,t){}dispose(){}};var k=class extends P{constructor(){super(...arguments);this.result$=new Subject;this.result=this.result$.asObservable();this.next=t=>this.result$.next(t);}finish(t){this.result$.next(t),this.result$.complete();}complete(){this.result$.complete();}};var O=class{};export{f as AddMiddleware,u as AddNamespace,T as CancelError,p as ConnectExecutor,b as ConnectHandler,c as ConnectMessage,n as DisconnectMessage,m as EliminateNamespace,y as LockMessage,j as MiddlewareDecisionType,M as MiddlewareStage,D as PostboyAbstractRegistrator,k as PostboyCallbackMessage,O as PostboyExecutionHandler,s as PostboyExecutor,P as PostboyGenericMessage,d as PostboyMessage,w as PostboyMessageStore,A as PostboyMiddleware,E as PostboyMiddlewareService,v as PostboyNamespaceStore,H as PostboyService,l as PostboySubscription,x as RemoveMiddleware,h as UnlockMessage};//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
package/lib/index.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/models/postboy.message.ts","../src/models/postboy-generic-message.ts","../src/models/postboy-subscription.ts","../src/models/middleware-stage.enum.ts","../src/models/middleware-decision.enum.ts","../src/models/cancel-error.ts","../src/services/postboy-middleware.service.ts","../src/services/postboy-message.store.ts","../src/utils/id.generator.ts","../src/models/postboy-executor.ts","../src/messages/connect-message.executor.ts","../src/messages/disconnect-message.executor.ts","../src/messages/connect-executor.executor.ts","../src/messages/connect-handler.executor.ts","../src/postboy-abstract.registrator.ts","../src/services/namespace-registrator.ts","../src/services/postboy-namespace.store.ts","../src/services/postboy-dependency.resolver.ts","../src/messages/add-namespace.executor.ts","../src/messages/eliminate-namespace.executor.ts","../src/messages/add-middleware.executor.ts","../src/messages/remove-middleware.executor.ts","../src/messages/lock-message.executor.ts","../src/messages/unlock-message.executor.ts","../src/postboy.service.ts","../src/services/postboy-middleware.ts","../src/models/postboy-callback.message.ts","../src/models/postboy-execution.handler.ts"],"names":["PostboyMessage","metadata","PostboyGenericMessage","checkId","message","PostboySubscription","subscription","pipe","data","MiddlewareStage","MiddlewareDecisionType","CancelError","details","PostboyMiddlewareService","middleware","m","stage","context","result","cancelledBy","messageId","namespace","PostboyMessageStore","id","sub","executor","existingCallbacks","name","msg","executorFunction","c","fs","f","_IdGenerator","i","IdGenerator","PostboyExecutor","ConnectMessage","type","DisconnectMessage","ConnectExecutor","exec","ConnectHandler","handler","PostboyAbstractRegistrator","postboy","services","s","bufferSize","ReplaySubject","initial","BehaviorSubject","Subject","NamespaceRegistrator","PostboyNamespaceStore","space","registrator","PostboyDependencyResolver","AddNamespace","EliminateNamespace","AddMiddleware","RemoveMiddleware","LockMessage","UnlockMessage","PostboyService","resolver","e","action","result$","tap","observable","Observable","subscriber","first","PostboyMiddleware","_context","_result","PostboyCallbackMessage","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EAAiB,CACtB,IAAA,CAAK,OAAA,CAAQ,QAAA,GACf,CACF,EC3CO,IAAeC,CAAAA,CAAf,KAAwE","file":"index.mjs","sourcesContent":["import { PostboyMessageMetadata } from './postboy-message-metadata';\n\nexport abstract class PostboyMessage {\n public metadata: PostboyMessageMetadata = {};\n public get id(): string {\n return (this.constructor as any).ID;\n }\n\n setMetadata(metadata: Partial<PostboyMessageMetadata>): this {\n this.metadata = { ...this.metadata, ...metadata };\n return this;\n }\n}\n","import { PostboyMessage } from './postboy.message';\n\n/**\n * An inheritor should have a static ID field\n */\nexport abstract class PostboyGenericMessage extends PostboyMessage {}\nexport function checkId(message: new (...args: any[]) => any): string {\n if (!(message as any).ID) throw new Error(`${message.name} should have a static ID field`);\n return (message as any).ID;\n}\n","import { Observable, Subject } from 'rxjs';\n\n/**\n * A class that manages a reactive subscription using a provided Subject and transformation pipe.\n * Offers methods to interact with the subscription, such as emitting data, completing the subscription,\n * and accessing the transformed observable.\n *\n * @template T The type of data managed by the subscription.\n */\nexport class PostboySubscription<T> {\n private readonly _subscription: Observable<T>;\n\n /**\n * Constructs an instance of the class with a given subscription and a transformation pipe.\n *\n * @param {Subject<T>} subscription - The source Subject that will be transformed.\n * @param {(s: Subject<T>) => Observable<T>} pipe - A function that applies a transformation to the subscription.\n */\n constructor(\n private subscription: Subject<T>,\n pipe?: (s: Subject<T>) => Observable<T>,\n ) {\n this._subscription = !!pipe ? pipe(subscription) : subscription.asObservable();\n }\n\n /**\n * Returns an observable subscription.\n *\n * @return {Observable<T>} An observable instance of type T.\n */\n public sub(): Observable<T> {\n return this._subscription;\n }\n\n /**\n * Triggers an event by emitting the provided data to all subscribers.\n *\n * @param {T} data - The data to emit to the subscribers.\n * @return {void} - Does not return any value.\n */\n public fire(data: T): void {\n this.subscription.next(data);\n }\n\n /**\n * Completes the subscription, signaling that no further values will be sent.\n * This is typically used to finalize or clean up resources.\n * @return {void} This method does not return any value.\n */\n public finish(): void {\n this.subscription.complete();\n }\n}\n","export enum MiddlewareStage {\n Publish = 1,\n Callback,\n Execute,\n}\n","export enum MiddlewareDecisionType {\n Continue = 1,\n Interrupt,\n}\n","import { CancelDetails } from './cancel-details';\nimport { MiddlewareStage } from './middleware-stage.enum';\n\nexport class CancelError extends Error {\n public readonly details: CancelDetails;\n\n constructor(details: CancelDetails) {\n super(details.reason ?? `Postboy operation was cancelled at stage \"${MiddlewareStage[details.stage]}\"`);\n this.name = 'PostboyCancelError';\n this.details = details;\n }\n}\n\nexport function isCancelError(error: unknown): error is CancelError {\n return error instanceof CancelError;\n}\n","import { PostboyMessage } from '../models/postboy.message';\nimport { PostboyMessageContext } from '../models/postboy-message.context';\nimport { PostboyExecutor } from '../models/postboy-executor';\nimport { PipelineContext } from '../models/pipeline-context';\nimport { PostboyMiddleware } from './postboy-middleware';\nimport { MiddlewareStage } from '../models/middleware-stage.enum';\nimport { MiddlewareDecisionType } from '../models/middleware-decision.enum';\nimport { CancelError } from '../models/cancel-error';\n\nexport class PostboyMiddlewareService {\n protected middlewares: PostboyMiddleware[] = [];\n\n public addMiddleware(middleware: PostboyMiddleware): void {\n this.middlewares.push(middleware);\n }\n\n public removeMiddleware(middleware: PostboyMiddleware): void {\n this.middlewares = this.middlewares.filter((m) => {\n if (m !== middleware) return true;\n m.dispose();\n return false;\n });\n }\n\n public dispose(): void {\n this.middlewares.forEach((m) => m.dispose());\n this.middlewares = [];\n }\n\n public before<T extends PostboyMessage>(stage: MiddlewareStage, message: T): void {\n for (const middleware of this.middlewares) {\n const context = this.buildContext(stage, message);\n if (!middleware.canHandle(context)) continue;\n if (middleware.before(context).type === MiddlewareDecisionType.Interrupt)\n this.throwIfCancelled(stage, middleware.name, message.id);\n }\n }\n\n public after<T extends PostboyMessage, R = unknown>(stage: MiddlewareStage, message: T, result?: R): void {\n for (const middleware of this.middlewares) {\n const context = this.buildContext(stage, message);\n if (!middleware.canHandle(context)) continue;\n middleware.after(context, result);\n }\n }\n\n public beforePublish(message: PostboyMessage): void {\n this.before(MiddlewareStage.Publish, message);\n }\n\n public afterPublish(message: PostboyMessage): void {\n this.after(MiddlewareStage.Publish, message);\n }\n\n public beforeCallback(message: PostboyMessage): void {\n this.before(MiddlewareStage.Callback, message);\n }\n\n public afterCallback(message: PostboyMessage, result?: unknown): void {\n this.after(MiddlewareStage.Callback, message, result);\n }\n\n public beforeExecute<T>(message: PostboyExecutor<T>): void {\n this.before(MiddlewareStage.Execute, message);\n }\n\n public afterExecute<T>(message: PostboyExecutor<T>, result: T): void {\n this.after(MiddlewareStage.Execute, message, result);\n }\n\n private buildContext<T extends PostboyMessage>(stage: MiddlewareStage, message: T): PipelineContext<T> {\n return { stage, message };\n }\n\n private throwIfCancelled(\n stage: MiddlewareStage,\n cancelledBy?: string,\n messageId?: string,\n namespace?: string,\n ): never {\n throw new CancelError({\n stage,\n middleware: cancelledBy,\n messageId,\n namespace,\n reason: cancelledBy ? `Cancelled by middleware \"${cancelledBy}\"` : undefined,\n });\n }\n}\n","import { PostboySubscription } from '../models/postboy-subscription';\nimport { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyCallbackMessage } from '../models/postboy-callback.message';\n\n/**\n * The PostboyMessageStore is a utility class for managing message subscriptions and executors.\n * It provides functionality to register, retrieve, and unregister subscription-based messages and executors.\n */\nexport class PostboyMessageStore {\n protected messages = new Map<string, PostboySubscription<any>>();\n protected executors = new Map<string, (e: PostboyExecutor<any>) => any>();\n protected callbacks = new Map<string, (() => void)[]>();\n\n public registerMessage(id: string, sub: PostboySubscription<any>): void {\n // tslint:disable-next-line:no-console\n if (this.messages.has(id)) console.warn(`Message with id ${id} already registered. Overriding...`);\n this.messages.set(id, sub);\n }\n\n public registerExecutor(id: string, executor: (e: PostboyExecutor<any>) => any): void {\n // tslint:disable-next-line:no-console\n if (this.executors.has(id)) console.warn(`Executor with id ${id} already registered. Overriding...`);\n this.executors.set(id, executor);\n }\n\n callbackFired(message: PostboyCallbackMessage<any>): void {\n const existingCallbacks = this.callbacks.get(message.id);\n existingCallbacks\n ? existingCallbacks.push(() => message.complete())\n : this.callbacks.set(message.id, [() => message.complete()]);\n }\n\n public getMessage(id: string, name: string): PostboySubscription<any> {\n const msg = this.messages.get(id);\n if (!msg) throw new Error(`There is no registered event ${name}`);\n return msg;\n }\n\n public getExecutor<T>(id: string): (e: PostboyExecutor<T>) => T {\n const executorFunction = this.executors.get(id);\n if (!executorFunction) throw new Error(`There is no registered executor with id ${id}`);\n return executorFunction;\n }\n\n public unregister(id: string): void {\n this.messages.get(id)?.finish();\n this.messages.delete(id);\n this.callbacks.get(id)?.forEach((c) => c());\n this.callbacks.delete(id);\n this.executors.delete(id);\n }\n\n public dispose(): void {\n this.messages.forEach((m, id) => this.unregister(id));\n this.callbacks.forEach((fs) => fs.forEach((f) => f()));\n this.messages.clear();\n this.executors.clear();\n this.callbacks.clear();\n }\n}\n","export class IdGenerator {\n private static collection = 'ABCDEFGHIJKLMNOPQRSTUVWXTZ0123456789'.split('');\n\n public static get(): string {\n const result: string[] = [];\n for (let i = 0; i < 7; i++) {\n result.push(\n IdGenerator.collection\n .sort(() => 0.5 - Math.random())\n .slice(0, 5)\n .join(''),\n );\n }\n return result.join('-');\n }\n}\n","import { PostboyMessage } from './postboy.message';\n\nexport abstract class PostboyExecutor<T> extends PostboyMessage {\n declare protected readonly _postboyResultType?: T;\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyGenericMessage } from '../models/postboy-generic-message';\nimport { MessageType } from '../postboy-abstract.registrator';\nimport { Observable, Subject } from 'rxjs';\n\n/**\n * Represents a message that facilitates connection functionality\n * within the application's messaging system.\n *\n * @template T - A type that extends {@link PostboyGenericMessage}, representing\n * the structure of the message being handled.\n *\n * @extends PostboyExecutor<void>\n */\nexport class ConnectMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {\n static readonly ID = 'aa03a192-bdc7-402d-9f2f-bf3748229ea2';\n\n /**\n * Constructs a new instance of the class.\n *\n * @param {MessageType<T>} type - The type of the message.\n * @param {Subject<T>} sub - The subject to be used for message handling.\n * @param {(s: Subject<T>) => Observable<T>} [pipe] - An optional function to transform the subject.\n */\n constructor(\n public type: MessageType<T>,\n public sub: Subject<T>,\n public pipe?: (s: Subject<T>) => Observable<T>,\n ) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\n\n/**\n * Represents a message signaling a disconnection event. This class is used\n * within the framework to manage and process disconnection notifications.\n * Extends the {@link PostboyExecutor} base class.\n *\n * @extends {PostboyExecutor<void>}\n */\nexport class DisconnectMessage extends PostboyExecutor<void> {\n static readonly ID = '94579e43-5bc9-4517-bcda-b595bcda1ae7';\n\n /**\n * Creates an instance of the class with the specified message identifier.\n *\n * @param {string} messageId - The unique identifier for the message.\n */\n constructor(public messageId: string) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\nimport { MessageType } from '../postboy-abstract.registrator';\n\n/**\n * Registers an executor that connects to a specific type of message handler.\n * This class extends the functionality of `PostboyExecutor` and is designed to manage\n * the execution of a handler defined by a specific message type and an execution function.\n *\n * @template E The type of the executor extending {@link PostboyExecutor}.\n * @template T The return type of the execution function.\n *\n * @extends {PostboyExecutor<void>}\n */\nexport class ConnectExecutor<E extends PostboyExecutor<T>, T> extends PostboyExecutor<void> {\n static readonly ID = 'cb80e8ad-b68c-4b2d-8c44-617ea6017cb3';\n\n /**\n * Constructs an instance of the class with the specified type and execution function.\n *\n * @param {MessageType<E>} type - The type of the message.\n * @param {(e: E) => T} exec - The function to be executed with the input of type E that returns a value of type T.\n */\n constructor(\n public type: MessageType<E>,\n public exec: (e: E) => T,\n ) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyExecutionHandler } from '../models/postboy-execution.handler';\n\n/**\n * Represents a connection handler that extends the PostboyExecutor class.\n *\n * This class encapsulates logic associated with executing a handler in a structured way.\n * It is generic and operates on the provided executor and handler types.\n *\n * Type Parameters:\n * E - Represents an extension of the PostboyExecutor class with a specific type parameter R.\n * R - Represents the type of the result that the executor is expected to operate on.\n */\nexport class ConnectHandler<E extends PostboyExecutor<R>, R> extends PostboyExecutor<void> {\n static readonly ID = 'bf618cea-6f32-417c-9548-8eafe937378b';\n\n /**\n * Constructs an instance of the class.\n *\n * @param {new (...args: any[]) => E} executor - A constructor function for the executor object.\n * @param {PostboyExecutionHandler<R, E>} handler - A handler that processes the execution logic.\n */\n constructor(\n public executor: new (...args: any[]) => E,\n public handler: PostboyExecutionHandler<R, E>,\n ) {\n super();\n }\n}\n","import { PostboyService } from './postboy.service';\nimport { BehaviorSubject, Observable, pipe, ReplaySubject, Subject } from 'rxjs';\nimport { IPostboyDependingService } from './i-postboy-depending.service';\nimport { PostboyExecutor } from './models/postboy-executor';\nimport { checkId, PostboyGenericMessage } from './models/postboy-generic-message';\nimport { PostboyExecutionHandler } from './models/postboy-execution.handler';\nimport { IdGenerator } from './utils/id.generator';\nimport { ConnectMessage } from './messages/connect-message.executor';\nimport { DisconnectMessage } from './messages/disconnect-message.executor';\nimport { ConnectExecutor } from './messages/connect-executor.executor';\nimport { ConnectHandler } from './messages/connect-handler.executor';\n\nexport type MessageType<T extends PostboyGenericMessage> = new (...args: any[]) => T;\n\nexport abstract class PostboyAbstractRegistrator {\n get namespace(): string {\n return this._namespace;\n }\n private ids: string[] = [];\n private services: IPostboyDependingService[] = [];\n private readonly _namespace: string;\n\n constructor(\n protected postboy: PostboyService,\n namespace: string | null = null,\n ) {\n this._namespace = namespace ?? IdGenerator.get();\n }\n\n /**\n * Registers a list of services to be used by the application.\n *\n * @param {IPostboyDependingService[]} services - An array of services to register.\n * @return {void} This method does not return a value.\n */\n public registerServices(services: IPostboyDependingService[]): void {\n this.services = services;\n }\n\n /**\n * Initiates the 'up' process for the current instance and all associated services.\n *\n * @return {void} Does not return a value.\n */\n public up(): void {\n this._up?.();\n this.services.forEach((s) => s.up());\n }\n\n protected abstract _up(): void;\n\n public down(): void {\n this.services.forEach((s) => !!s.down && s.down());\n this.services = [];\n this.ids.forEach((id) => this.postboy.exec(new DisconnectMessage(id)));\n }\n\n /**\n * Records a type and its corresponding Subject<T> into the Postboy system and updates the internal identifiers.\n *\n * @param {MessageType<T>} type - A constructor for the generic message type T.\n * @param {Subject<T>} sub - The subject associated with the generic message type.\n * @return {this} Returns the current instance for method chaining.\n */\n public record<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>): PostboyAbstractRegistrator {\n this.ids.push(checkId(type));\n this.postboy.exec(new ConnectMessage(type, sub));\n return this;\n }\n\n /**\n * Records a message type with a specific subject and applies a transformation pipe to the subject.\n *\n * @param {MessageType<T>} type - The constructor of the message type to record, which extends PostboyGenericMessage.\n * @param {Subject<T>} sub - The Subject instance to associate with the message type.\n * @param {(s: Subject<T>) => Observable<T>} pipe - A function that takes the subject as input and returns an Observable with transformations applied.\n * @return {this} The current instance of the class for chaining.\n */\n public recordWithPipe<T extends PostboyGenericMessage>(\n type: MessageType<T>,\n sub: Subject<T>,\n pipe: (s: Subject<T>) => Observable<T>,\n ): PostboyAbstractRegistrator {\n this.ids.push(checkId(type));\n this.postboy.exec(new ConnectMessage(type, sub, pipe));\n return this;\n }\n\n /**\n * Records an executor associated with a specific type and execution logic.\n *\n * @param type The class constructor of the executor type to be recorded, which extends PostboyExecutor.\n * @param exec A callback function that executes the logic using an instance of the specified executor type.\n * @return void\n */\n public recordExecutor<E extends PostboyExecutor<T>, T>(\n type: new (...args: any[]) => E,\n exec: (e: E) => T,\n ): PostboyAbstractRegistrator {\n this.ids.push(checkId(type));\n this.postboy.exec(new ConnectExecutor(type, exec));\n return this;\n }\n\n /**\n * Records a handler for a specific executor type.\n *\n * @param executor The constructor of the executor type, which extends `PostboyExecutor`.\n * @param handler The execution handler associated with the given executor type.\n * @return void\n */\n public recordHandler<E extends PostboyExecutor<R>, R>(\n executor: new (...args: any[]) => E,\n handler: PostboyExecutionHandler<R, E>,\n ): PostboyAbstractRegistrator {\n this.ids.push(checkId(executor));\n this.postboy.exec(new ConnectHandler(executor, handler));\n return this;\n }\n\n /**\n * A utility function that facilitates the recording and replaying of messages\n * using a ReplaySubject. This function is designed to handle messages of a\n * specific type and allows specifying a buffer size to determine how many\n * of the most recent messages should be replayed.\n *\n * @template T Extends the PostboyGenericMessage type, representing the type of message\n * to be recorded and replayed.\n * @param {MessageType<T>} type The constructor of the message type to be recorded and replayed.\n * @param {number} [bufferSize=1] The number of recent messages to retain in the ReplaySubject's buffer.\n * Defaults to 1 if not specified.\n * @returns The result of invoking the `record` method with the given message type and configured ReplaySubject.\n */\n public recordReplay<T extends PostboyGenericMessage>(\n type: MessageType<T>,\n bufferSize = 1,\n ): PostboyAbstractRegistrator {\n this.record(type, new ReplaySubject<T>(bufferSize));\n return this;\n }\n\n /**\n * Represents a method that records a specific behavior associated with a message type.\n * It creates a `BehaviorSubject` initialized with the provided initial message\n * and associates it with the given message type using the `record` method.\n *\n * @template T - A type parameter extending `PostboyGenericMessage` that defines the message structure.\n * @param {MessageType<T>} type - The constructor function of the message type to be recorded.\n * @param {T} initial - The initial value of the message that will be set in the `BehaviorSubject`.\n * @returns {void} - This function does not return a value; instead, it modifies the internal state.\n */\n public recordBehavior<T extends PostboyGenericMessage>(type: MessageType<T>, initial: T): PostboyAbstractRegistrator {\n this.record(type, new BehaviorSubject<T>(initial));\n return this;\n }\n\n /**\n * A function that creates and returns a new generic message recorder for a specific message type.\n *\n * @template T - A type parameter extending from `PostboyGenericMessage`.\n * @param {MessageType<T>} type - The constructor for the message type being recorded.\n * @returns {Subject<T>} A new instance of `Subject<T>` bound to the specified message type.\n */\n public recordSubject<T extends PostboyGenericMessage>(type: MessageType<T>) {\n this.record(type, new Subject<T>());\n return this;\n }\n}\n","import { PostboyAbstractRegistrator } from '../postboy-abstract.registrator';\nimport { PostboyService } from '../postboy.service';\n\n/**\n * NamespaceRegistrator is a specialized class that extends PostboyAbstractRegistrator.\n *\n * @class NamespaceRegistrator\n * @extends PostboyAbstractRegistrator\n * @param {PostboyService} postboy - An instance of the PostboyService, used for managing registrations.\n */\nexport class NamespaceRegistrator extends PostboyAbstractRegistrator {\n constructor(postboy: PostboyService) {\n super(postboy);\n }\n\n protected _up(): void {\n // ignore\n }\n}\n","import { PostboyAbstractRegistrator } from '../postboy-abstract.registrator';\nimport { NamespaceRegistrator } from './namespace-registrator';\nimport { PostboyService } from '../postboy.service';\n\n/**\n * Represents a store for managing namespaces in the Postboy system.\n * Provides functionality to add, eliminate, and dispose namespaces.\n */\nexport class PostboyNamespaceStore {\n private spaces: Map<string, PostboyAbstractRegistrator> = new Map();\n\n /**\n * Adds a new space or retrieves an existing one if it already exists.\n *\n * @param {string} space - The name of the space to add or retrieve.\n * @param {PostboyService} postboy - The PostboyService instance used to create a namespace registrator.\n * @return {PostboyAbstractRegistrator} The registrator associated with the specified space.\n */\n public addSpace(space: string, postboy: PostboyService): PostboyAbstractRegistrator {\n if (this.spaces.has(space)) return this.spaces.get(space)!;\n const registrator = new NamespaceRegistrator(postboy);\n this.spaces.set(space, registrator);\n return registrator;\n }\n\n /**\n * Removes a specified space from the spaces collection if it exists.\n * If the space exists, it will be deleted after invoking its down method.\n *\n * @param {string} space - The name of the space to be removed.\n * @return {void} This method does not return a value.\n */\n public eliminateSpace(space: string): void {\n if (!this.spaces.has(space)) return;\n this.spaces.get(space)?.down();\n this.spaces.delete(space);\n }\n\n /**\n * Disposes of the current instance by performing cleanup operations.\n * Iterates through all spaces, performs a \"down\" operation on each,\n * and then clears the collection of spaces.\n *\n * @return {void} No return value.\n */\n public dispose(): void {\n this.spaces.forEach((space) => space.down());\n this.spaces.clear();\n }\n}\n","import { PostboyMiddlewareService } from './postboy-middleware.service';\nimport { PostboyMessageStore } from './postboy-message.store';\nimport { PostboyNamespaceStore } from './postboy-namespace.store';\n\nexport class PostboyDependencyResolver {\n /**\n * Retrieves an instance of the PostboyMiddlewareService.\n *\n * This function initializes and returns a new instance of the\n * PostboyMiddlewareService, which can be used to configure and manage\n * middleware for a specific module or application.\n *\n * @returns {PostboyMiddlewareService} A new instance of PostboyMiddlewareService.\n */\n getMiddlewareService = () => new PostboyMiddlewareService();\n /**\n * A function that instantiates and returns a new instance of PostboyMessageStore.\n *\n * This function serves as a factory method for creating instances\n * of the PostboyMessageStore class.\n *\n * @returns {PostboyMessageStore} A new instance of the PostboyMessageStore class.\n */\n getMessageStore = () => new PostboyMessageStore();\n /**\n * Creates and initializes a new instance of PostboyNamespaceStore using the provided PostboyService instance.\n *\n * @function getNamespaceStore\n * @returns {PostboyNamespaceStore} A new instance of PostboyNamespaceStore associated with the given PostboyService.\n */\n getNamespaceStore = () => new PostboyNamespaceStore();\n}\n","import { PostboyAbstractRegistrator } from '../postboy-abstract.registrator';\nimport { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyExecutionHandler } from '../models/postboy-execution.handler';\nimport { PostboyNamespaceStore } from '../services/postboy-namespace.store';\nimport { PostboyService } from '../postboy.service';\n\n/**\n * AddNamespace is a class that extends the PostboyExecutor with a specific implementation\n * for adding namespaces to a PostboyService instance.\n *\n * This class is identified uniquely by its static ID property for tracking and referencing purposes.\n */\nexport class AddNamespace extends PostboyExecutor<PostboyAbstractRegistrator> {\n static readonly ID = '6d1a6f7d-6b6e-4c4d-8af8-9cc9a32e850c';\n\n /**\n * Creates an instance of the class with the specified space identifier.\n *\n * @param {string} space - The identifier for the space.\n */\n constructor(public space: string) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\n\n/**\n * Represents an executor that eliminates a specific namespace.\n * This class extends the PostboyExecutor with a void return type.\n */\nexport class EliminateNamespace extends PostboyExecutor<void> {\n static readonly ID = '03bb03bb-53e0-4b74-9aad-64d5c54a8972';\n\n /**\n * Creates an instance of the class with the specified space value.\n *\n * @param {string} space - The string value representing the space configuration.\n */\n constructor(public space: string) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyMiddleware } from '../services/postboy-middleware';\n\n/**\n * Represents a {@link PostboyMiddleware} addition operation for Postboy.\n * This class extends the functionality of the PostboyExecutor to add middleware to the processing chain.\n *\n * The middleware to be added is provided during instantiation.\n */\nexport class AddMiddleware extends PostboyExecutor<void> {\n static readonly ID = '0a8cfe0a-6193-4082-8440-d0793367b21d';\n\n /**\n * Initializes a new instance of the class with the specified middleware.\n *\n * @param {PostboyMiddleware} middleware - The {@link PostboyMiddleware} to be used for processing.\n */\n constructor(public middleware: PostboyMiddleware) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyMiddleware } from '../services/postboy-middleware';\n\n/**\n * Represents a class responsible for removing {@link PostboyMiddleware} in execution flow.\n * This class extends PostboyExecutor and operates with a void return type.\n */\nexport class RemoveMiddleware extends PostboyExecutor<void> {\n static readonly ID = 'c25c708c-53c9-498d-a28b-936fbaf68b91';\n\n /**\n * Constructs an instance of the class with the specified middleware.\n *\n * @param {PostboyMiddleware} middleware - The {@link PostboyMiddleware} instance to be removed.\n */\n constructor(public middleware: PostboyMiddleware) {\n super();\n }\n}\n","import { PostboyGenericMessage } from '../models/postboy-generic-message';\nimport { MessageType } from '../postboy-abstract.registrator';\nimport { PostboyExecutor } from '../models/postboy-executor';\n\n/**\n * Locks a specific message type to prevent firing of them.\n *\n * @deprecated Use {@link PostboyMiddleware}\n * This class is used to handle operations associated with locking mechanisms\n * for a specified message type.\n *\n * @template T - A type that extends {@link PostboyGenericMessage}.\n */\nexport class LockMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {\n static readonly ID = '477df3e2-1f99-4476-9a3b-afd1fa426436';\n\n /**\n * Constructs an instance of the class with the specified message type.\n *\n * @param {MessageType<T>} type - The type of the message to be used for the instance.\n */\n constructor(public type: MessageType<T>) {\n super();\n }\n}\n","import { PostboyGenericMessage } from '../models/postboy-generic-message';\nimport { PostboyExecutor } from '../models/postboy-executor';\nimport { MessageType } from '../postboy-abstract.registrator';\n\n/**\n * A specialized executor that handles the unlocking process for messages of a specified type.\n * Unlocks a previously locked message, making it available for processing again.\n *\n * @deprecated Use {@link PostboyMiddleware}\n * @template T - The type parameter extending {@link PostboyGenericMessage}, representing the message type handled by the executor.\n * @extends {PostboyExecutor<void>}\n */\nexport class UnlockMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {\n static readonly ID = 'd71d25e3-90ac-4009-b972-9e6c6b05611e';\n\n /**\n * Creates an instance of the class with the specified message type.\n *\n * @param {MessageType<T>} type - The message type for this instance.\n */\n constructor(public type: MessageType<T>) {\n super();\n }\n}\n","import { first, Observable, Subject, tap } from 'rxjs';\nimport { checkId, PostboyGenericMessage } from './models/postboy-generic-message';\nimport { PostboySubscription } from './models/postboy-subscription';\nimport { PostboyExecutor } from './models/postboy-executor';\nimport { PostboyCallbackMessage } from './models/postboy-callback.message';\nimport { MessageType, PostboyAbstractRegistrator } from './postboy-abstract.registrator';\nimport { PostboyExecutionHandler } from './models/postboy-execution.handler';\nimport { PostboyDependencyResolver } from './services/postboy-dependency.resolver';\nimport { PostboyMiddlewareService } from './services/postboy-middleware.service';\nimport { PostboyMessageStore } from './services/postboy-message.store';\nimport { PostboyNamespaceStore } from './services/postboy-namespace.store';\nimport { PostboyContextService } from './services/postboy-context.service';\nimport { PostboySettings } from './models/postboy.settings';\nimport { AddNamespace } from './messages/add-namespace.executor';\nimport { EliminateNamespace } from './messages/eliminate-namespace.executor';\nimport { AddMiddleware } from './messages/add-middleware.executor';\nimport { RemoveMiddleware } from './messages/remove-middleware.executor';\nimport { LockMessage } from './messages/lock-message.executor';\nimport { UnlockMessage } from './messages/unlock-message.executor';\nimport { DisconnectMessage } from './messages/disconnect-message.executor';\nimport { MiddlewareStage } from './models/middleware-stage.enum';\nimport { CancelError } from './models/cancel-error';\nimport { ConnectMessage } from './messages/connect-message.executor';\nimport { ConnectExecutor } from './messages/connect-executor.executor';\nimport { ConnectHandler } from './messages/connect-handler.executor';\n\nexport class PostboyService {\n protected locked = new Set<string>();\n private middleware: PostboyMiddlewareService;\n private store: PostboyMessageStore;\n private namespaceStore: PostboyNamespaceStore;\n private dependencyResolver: PostboyDependencyResolver;\n\n constructor(resolver?: PostboyDependencyResolver) {\n this.dependencyResolver = resolver || new PostboyDependencyResolver();\n this.middleware = this.dependencyResolver.getMiddlewareService();\n this.store = this.dependencyResolver.getMessageStore();\n this.namespaceStore = this.dependencyResolver.getNamespaceStore();\n this.registerInfrastructureMessages();\n }\n\n private registerInfrastructureMessages() {\n this.store.registerExecutor(DisconnectMessage.ID, (e) => this.store.unregister((e as DisconnectMessage).messageId));\n this.store.registerExecutor(UnlockMessage.ID, (e) => this.locked.delete(checkId((e as UnlockMessage<any>).type)));\n this.store.registerExecutor(LockMessage.ID, (e) => this.locked.add(checkId((e as LockMessage<any>).type)));\n this.store.registerExecutor(AddMiddleware.ID, (e) =>\n this.middleware.addMiddleware((e as AddMiddleware).middleware),\n );\n this.store.registerExecutor(RemoveMiddleware.ID, (e) =>\n this.middleware.removeMiddleware((e as RemoveMiddleware).middleware),\n );\n this.store.registerExecutor(AddNamespace.ID, (e) => this.namespaceStore.addSpace((e as AddNamespace).space, this));\n this.store.registerExecutor(EliminateNamespace.ID, (e) =>\n this.namespaceStore.eliminateSpace((e as EliminateNamespace).space),\n );\n this.store.registerExecutor(ConnectMessage.ID, (e) => {\n const { type, sub, pipe } = e as ConnectMessage<any>;\n this.store.registerMessage(checkId(type), new PostboySubscription<any>(sub, pipe));\n });\n this.store.registerExecutor(ConnectExecutor.ID, (e) => {\n const { type, exec } = e as ConnectExecutor<any, any>;\n this.store.registerExecutor(checkId(type), exec);\n });\n this.store.registerExecutor(ConnectHandler.ID, (e) => {\n const { executor, handler } = e as ConnectHandler<any, any>;\n this.store.registerExecutor(checkId(executor), (e) => handler.handle(e));\n });\n }\n\n /**\n * Fires a registered event and passes the message to its subscribers.\n *\n * @param {PostboyGenericMessage} message - The message object containing the event data.\n * @return {void} This method does not return a value.\n * @throws {Error} Throws an error if no registered event is found for the provided message ID.\n */\n public fire(message: PostboyGenericMessage): void {\n this.middleware.beforePublish(message);\n if (!this.locked.has(message.id)) {\n this.store.getMessage(message.id, message.constructor.name).fire(message);\n }\n this.middleware.afterPublish(message);\n }\n\n /**\n * Triggers a callback function associated with a given message.\n *\n * @param {PostboyCallbackMessage<T>} message - The message object used to trigger the callback.\n * It contains details about the event and result subscription.\n * @param {(e: T) => void} [action] - Optional callback function to execute when the result of the message is emitted.\n * @return {void} This method does not return any value.\n */\n public fireCallback<T>(message: PostboyCallbackMessage<T>, action?: (e: T) => void): Observable<T> {\n this.middleware.beforeCallback(message);\n if (action) message.result.subscribe(action);\n this.store.callbackFired(message);\n const result$ = action ? message.result.pipe(tap(action)) : message.result;\n const msg = this.store.getMessage(message.id, message.constructor.name);\n const observable = new Observable<T>((subscriber) => {\n const subscription = result$.pipe(tap(() => this.middleware.afterCallback(message))).subscribe(subscriber);\n\n if (!this.locked.has(message.id)) {\n msg.fire(message);\n }\n\n return () => subscription.unsubscribe();\n });\n if (!!action) observable.subscribe();\n return observable;\n }\n\n /**\n * Executes the provided executor function and returns its result.\n *\n * @param {PostboyExecutor<T>} executor The executor to be executed, which includes its identifier and logic.\n * @return {T} The resulting output from the executed executor function.\n * @throws {Error} If the specified executor is not registered.\n */\n public exec<T>(executor: PostboyExecutor<T>): T {\n this.middleware.beforeExecute(executor);\n const result = this.store.getExecutor<T>(executor.id)(executor);\n this.middleware.afterExecute(executor, result);\n return result;\n }\n\n /**\n * Subscribes to a specific message type and returns an observable of that type.\n *\n * @param type The constructor function of the type that extends PostboyGenericMessage.\n * @return An Observable of the specified generic message type.\n */\n public sub<T extends PostboyGenericMessage>(type: MessageType<T>): Observable<T> {\n return this.store.getMessage(checkId(type), type.name).sub();\n }\n\n /**\n * Subscribes to a specific message type and automatically unsubscribes after receiving the first message.\n *\n * @param type The type of message to subscribe to.\n * @return An observable that emits the first message of the specified type and then completes.\n */\n public once<T extends PostboyGenericMessage>(type: MessageType<T>): Observable<T> {\n return this.sub(type).pipe(first());\n }\n\n /**\n * Registers a given message type and its associated subject subscription with the system.\n *\n * @deprecated The method should be replaced with firing {@link ConnectMessage} message.\n * @param type The constructor function of the message type that extends the PostboyGenericMessage.\n * @param sub The Subject instance for the provided message type, used for managing subscriptions.\n * @return {void} No return value.\n */\n public record<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>): void {\n this.store.registerMessage(checkId(type), new PostboySubscription<T>(sub, (s) => s.asObservable()));\n }\n\n /**\n * Registers a generic message type with a Subject and a transformation pipe.\n *\n * @deprecated The method should be replaced with firing {@link ConnectMessage} message.\n * @param {MessageType<T>} type - The constructor of the message type being registered.\n * @param {Subject<T>} sub - The Subject instance used to handle incoming messages of the specified type.\n * @param {(s: Subject<T>) => Observable<T>} pipe - A function that applies a transformation or processing logic to the Subject and returns an Observable.\n * @return {void} No return value.\n */\n public recordWithPipe<T extends PostboyGenericMessage>(\n type: MessageType<T>,\n sub: Subject<T>,\n pipe: (s: Subject<T>) => Observable<T>,\n ): void {\n this.store.registerMessage(checkId(type), new PostboySubscription<T>(sub, pipe));\n }\n\n /**\n * Registers an executor for a specified message type.\n *\n * @deprecated The method should be replaced with firing {@link ConnectExecutor} message.\n * @param {MessageType<E>} type - The message type for which the executor is being registered.\n * @param {(e: E) => T} exec - The executor function that will handle messages of the specified type.\n * @return {void} This method does not return any value.\n */\n public recordExecutor<E extends PostboyExecutor<T>, T>(type: MessageType<E>, exec: (e: E) => T): void {\n this.store.registerExecutor(checkId(type), exec as (e: PostboyExecutor<T>) => T);\n }\n\n /**\n * Registers a handler for a specific executor type.\n *\n * @deprecated The method should be replaced with firing {@link ConnectHandler} message.\n * @param executor The constructor of the executor class that extends `PostboyExecutor<R>`.\n * @param handler An instance of `PostboyExecutionHandler<R, E>` that defines the logic for handling the executor.\n * @return void\n */\n public recordHandler<E extends PostboyExecutor<R>, R>(\n executor: new (...args: any[]) => E,\n handler: PostboyExecutionHandler<R, E>,\n ): void {\n this.store.registerExecutor(checkId(executor), (e) => handler.handle(e as E));\n }\n\n /**\n * Disposes of resources and cleans up any internal components or stores associated with the instance.\n * This method ensures that all resources are properly released to avoid memory leaks.\n *\n * @return {void} This method does not return a value.\n */\n public dispose(): void {\n this.namespaceStore?.dispose();\n this.store.dispose();\n this.middleware.dispose();\n }\n}\n","import { PipelineContext } from '../models/pipeline-context';\nimport { MiddlewareDecisionType } from '../models/middleware-decision.enum';\nimport { MiddlewareDecision } from '../models';\n\n/**\n * Abstract base class for defining middleware in a pipeline.\n * Middleware acts on various stages of pipeline execution, allowing operations\n * to be intercepted, modified, or monitored.\n */\nexport abstract class PostboyMiddleware {\n public readonly name: string;\n\n /**\n * Creates an instance of a class, optionally assigning a name.\n *\n * @param {string} [name] - An optional name to be assigned. If not provided, defaults to the class name.\n */\n constructor(name?: string) {\n this.name = name ?? this.constructor.name;\n }\n\n /**\n * Optional filter to skip middleware for unrelated messages/stages.\n */\n public canHandle(_context: PipelineContext): boolean {\n return true;\n }\n\n /**\n * Called before the stage is executed.\n * Return Interrupt to cancel the operation.\n */\n public before(_context: PipelineContext): MiddlewareDecision {\n return { type: MiddlewareDecisionType.Continue };\n }\n\n /**\n * Called after the stage has finished successfully.\n * `result` is typically set for execute-stage.\n */\n public after(_context: PipelineContext, _result?: unknown): void {\n // noop\n }\n\n /**\n * Optional cleanup hook.\n */\n public dispose(): void {\n // noop\n }\n}\n","import { Observable, Subject } from 'rxjs';\nimport { PostboyGenericMessage } from './postboy-generic-message';\n\n/**\n * An abstract class extending PostboyGenericMessage that provides mechanisms for managing\n * asynchronous data communication using RxJS observables. It is designed to work with\n * callback-based operations that emit a result of type T.\n *\n * @template T - The type of the data emitted by the observables in this class.\n *\n * @extends PostboyGenericMessage\n *\n * @property {Observable<T>} result - An observable that emits the result of the operation\n * and completes once the operation is finished.\n *\n * @method next - Emits the next value for the result observable.\n * @param {T} value - The value to be emitted by the result observable.\n *\n * @method finish - Emits the final value for the result observable and completes it.\n * @param {T} value - The final value for the observable emission.\n */\nexport abstract class PostboyCallbackMessage<T> extends PostboyGenericMessage {\n protected result$ = new Subject<T>();\n public result: Observable<T> = this.result$.asObservable();\n\n /**\n * Emits the provided value.\n *\n * @template T - The type of the value to emit.\n * @param {T} value - The value to emit through the `result$` observable.\n * @returns {void}\n */\n public next = (value: T): void => this.result$.next(value);\n\n /**\n * Marks the operation as complete by emitting the provided value and then completing the result stream.\n *\n * @param {T} value - The value to emit prior to completing the result stream.\n * @return {void} This method does not return a value.\n */\n public finish(value: T): void {\n this.result$.next(value);\n this.result$.complete();\n }\n\n /**\n * Completes the current observable result stream.\n * This method marks the result observable as complete, ensuring no further values\n * or events will be emitted from it.\n *\n * @return {void} No value is returned from this method.\n */\n public complete(): void {\n this.result$.complete();\n }\n}\n","import { PostboyExecutor } from './postboy-executor';\n\n/**\n * Abstract class representing a handler for executing a Postboy task.\n *\n * This class is intended to manage the execution flow of a PostboyExecutor instance.\n * Subclasses must implement the `handle` method, which executes a given PostboyExecutor\n * and returns a result of type R.\n *\n * @template R The type of the result returned by the `handle` method.\n * @template E The type of the executor extending the PostboyExecutor.\n */\nexport abstract class PostboyExecutionHandler<R, E extends PostboyExecutor<R>> {\n /**\n * Abstract method to handle the specified executor and return a result.\n *\n * @param {E} executor - The executor that will be processed by the method.\n * @return {R} The result obtained after handling the executor.\n */\n abstract handle(executor: E): R;\n}\n"]}
1
+ {"version":3,"sources":["../src/models/postboy.message.ts","../src/models/postboy-generic-message.ts","../src/models/postboy-subscription.ts","../src/models/middleware-stage.enum.ts","../src/models/middleware-decision.enum.ts","../src/models/cancel-error.ts","../src/services/postboy-middleware.service.ts","../src/services/postboy-message.store.ts","../src/utils/id.generator.ts","../src/models/postboy-executor.ts","../src/messages/connect-message.executor.ts","../src/messages/disconnect-message.executor.ts","../src/messages/connect-executor.executor.ts","../src/messages/connect-handler.executor.ts","../src/postboy-abstract.registrator.ts","../src/services/namespace-registrator.ts","../src/services/postboy-namespace.store.ts","../src/services/postboy-dependency.resolver.ts","../src/messages/add-namespace.executor.ts","../src/messages/eliminate-namespace.executor.ts","../src/messages/add-middleware.executor.ts","../src/messages/remove-middleware.executor.ts","../src/messages/lock-message.executor.ts","../src/messages/unlock-message.executor.ts","../src/postboy.service.ts","../src/services/postboy-middleware.ts","../src/models/postboy-callback.message.ts","../src/models/postboy-execution.handler.ts"],"names":["PostboyMessage","metadata","PostboyGenericMessage","checkId","message","PostboySubscription","subscription","pipe","data","MiddlewareStage","MiddlewareDecisionType","CancelError","details","PostboyMiddlewareService","middleware","m","stage","context","result","cancelledBy","messageId","namespace","PostboyMessageStore","id","sub","executor","existingCallbacks","name","msg","executorFunction","c","fs","f","_IdGenerator","i","IdGenerator","PostboyExecutor","ConnectMessage","type","DisconnectMessage","ConnectExecutor","exec","ConnectHandler","handler","PostboyAbstractRegistrator","postboy","services","s","bufferSize","ReplaySubject","initial","BehaviorSubject","Subject","NamespaceRegistrator","PostboyNamespaceStore","space","registrator","PostboyDependencyResolver","AddNamespace","EliminateNamespace","AddMiddleware","RemoveMiddleware","LockMessage","UnlockMessage","PostboyService","resolver","e","action","result$","tap","observable","Observable","subscriber","first","PostboyMiddleware","_context","_result","PostboyCallbackMessage","value","PostboyExecutionHandler"],"mappings":"8EAEO,IAAeA,CAAAA,CAAf,KAA8B,CAA9B,cACL,IAAA,CAAO,QAAA,CAAmC,GAAC,CAC3C,IAAW,IAAa,CACtB,OAAQ,IAAA,CAAK,WAAA,CAAoB,EACnC,CAEA,YAAYC,CAAAA,CAAiD,CAC3D,YAAK,QAAA,CAAW,CAAE,GAAG,IAAA,CAAK,QAAA,CAAU,GAAGA,CAAS,CAAA,CACzC,IACT,CACF,ECPO,IAAeC,CAAAA,CAAf,cAA6CF,CAAe,GAC5D,SAASG,CAAAA,CAAQC,CAAAA,CAA8C,CACpE,GAAI,CAAEA,EAAgB,EAAA,CAAI,MAAM,IAAI,KAAA,CAAM,CAAA,EAAGA,EAAQ,IAAI,CAAA,8BAAA,CAAgC,CAAA,CACzF,OAAQA,CAAAA,CAAgB,EAC1B,CCAO,IAAMC,CAAAA,CAAN,KAA6B,CASlC,WAAA,CACUC,CAAAA,CACRC,EACA,C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,SAAA,CAAUgD,CAAAA,CAAoC,CACnD,OAAO,KACT,CAMO,MAAA,CAAOA,CAAAA,CAA+C,CAC3D,OAAO,CAAE,IAAA,CAAA,CAAsC,CACjD,CAMO,KAAA,CAAMA,CAAAA,CAA2BC,EAAyB,CAEjE,CAKO,OAAA,EAAgB,CAEvB,CACF,EC7BO,IAAeC,CAAAA,CAAf,cAAiD3E,CAAsB,CAAvE,WAAA,EAAA,CAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CACL,IAAA,CAAU,OAAA,CAAU,IAAIkD,QACxB,IAAA,CAAO,MAAA,CAAwB,IAAA,CAAK,OAAA,CAAQ,YAAA,EAAa,CASzD,KAAO,IAAA,CAAQ0B,CAAAA,EAAmB,IAAA,CAAK,OAAA,CAAQ,IAAA,CAAKA,CAAK,GAQlD,MAAA,CAAOA,CAAAA,CAAgB,CAC5B,IAAA,CAAK,OAAA,CAAQ,KAAKA,CAAK,CAAA,CACvB,IAAA,CAAK,OAAA,CAAQ,QAAA,GACf,CASO,QAAA,EAAiB,CACtB,IAAA,CAAK,OAAA,CAAQ,QAAA,GACf,CACF,EC3CO,IAAeC,CAAAA,CAAf,KAAwE","file":"index.mjs","sourcesContent":["import { PostboyMessageMetadata } from './postboy-message-metadata';\n\nexport abstract class PostboyMessage {\n public metadata: PostboyMessageMetadata = {};\n public get id(): string {\n return (this.constructor as any).ID;\n }\n\n setMetadata(metadata: Partial<PostboyMessageMetadata>): this {\n this.metadata = { ...this.metadata, ...metadata };\n return this;\n }\n}\n","import { PostboyMessage } from './postboy.message';\n\n/**\n * An inheritor should have a static ID field\n */\nexport abstract class PostboyGenericMessage extends PostboyMessage {}\nexport function checkId(message: new (...args: any[]) => any): string {\n if (!(message as any).ID) throw new Error(`${message.name} should have a static ID field`);\n return (message as any).ID;\n}\n","import { Observable, Subject } from 'rxjs';\n\n/**\n * A class that manages a reactive subscription using a provided Subject and transformation pipe.\n * Offers methods to interact with the subscription, such as emitting data, completing the subscription,\n * and accessing the transformed observable.\n *\n * @template T The type of data managed by the subscription.\n */\nexport class PostboySubscription<T> {\n private readonly _subscription: Observable<T>;\n\n /**\n * Constructs an instance of the class with a given subscription and a transformation pipe.\n *\n * @param {Subject<T>} subscription - The source Subject that will be transformed.\n * @param {(s: Subject<T>) => Observable<T>} pipe - A function that applies a transformation to the subscription.\n */\n constructor(\n private subscription: Subject<T>,\n pipe?: (s: Subject<T>) => Observable<T>,\n ) {\n this._subscription = !!pipe ? pipe(subscription) : subscription.asObservable();\n }\n\n /**\n * Returns an observable subscription.\n *\n * @return {Observable<T>} An observable instance of type T.\n */\n public sub(): Observable<T> {\n return this._subscription;\n }\n\n /**\n * Triggers an event by emitting the provided data to all subscribers.\n *\n * @param {T} data - The data to emit to the subscribers.\n * @return {void} - Does not return any value.\n */\n public fire(data: T): void {\n this.subscription.next(data);\n }\n\n /**\n * Completes the subscription, signaling that no further values will be sent.\n * This is typically used to finalize or clean up resources.\n * @return {void} This method does not return any value.\n */\n public finish(): void {\n this.subscription.complete();\n }\n}\n","export enum MiddlewareStage {\n Publish = 1,\n Callback,\n Execute,\n}\n","export enum MiddlewareDecisionType {\n Continue = 1,\n Interrupt,\n}\n","import { CancelDetails } from './cancel-details';\nimport { MiddlewareStage } from './middleware-stage.enum';\n\nexport class CancelError extends Error {\n public readonly details: CancelDetails;\n\n constructor(details: CancelDetails) {\n super(details.reason ?? `Postboy operation was cancelled at stage \"${MiddlewareStage[details.stage]}\"`);\n this.name = 'PostboyCancelError';\n this.details = details;\n }\n}\n\nexport function isCancelError(error: unknown): error is CancelError {\n return error instanceof CancelError;\n}\n","import { PostboyMessage } from '../models/postboy.message';\nimport { PostboyMessageContext } from '../models/postboy-message.context';\nimport { PostboyExecutor } from '../models/postboy-executor';\nimport { PipelineContext } from '../models/pipeline-context';\nimport { PostboyMiddleware } from './postboy-middleware';\nimport { MiddlewareStage } from '../models/middleware-stage.enum';\nimport { MiddlewareDecisionType } from '../models/middleware-decision.enum';\nimport { CancelError } from '../models/cancel-error';\n\nexport class PostboyMiddlewareService {\n protected middlewares: PostboyMiddleware[] = [];\n\n public addMiddleware(middleware: PostboyMiddleware): void {\n this.middlewares.push(middleware);\n }\n\n public removeMiddleware(middleware: PostboyMiddleware): void {\n this.middlewares = this.middlewares.filter((m) => {\n if (m !== middleware) return true;\n m.dispose();\n return false;\n });\n }\n\n public dispose(): void {\n this.middlewares.forEach((m) => m.dispose());\n this.middlewares = [];\n }\n\n public before<T extends PostboyMessage>(stage: MiddlewareStage, message: T): void {\n for (const middleware of this.middlewares) {\n const context = this.buildContext(stage, message);\n if (!middleware.canHandle(context)) continue;\n if (middleware.before(context).type === MiddlewareDecisionType.Interrupt)\n this.throwIfCancelled(stage, middleware.name, message.id);\n }\n }\n\n public after<T extends PostboyMessage, R = unknown>(stage: MiddlewareStage, message: T, result?: R): void {\n for (const middleware of this.middlewares) {\n const context = this.buildContext(stage, message);\n if (!middleware.canHandle(context)) continue;\n middleware.after(context, result);\n }\n }\n\n public beforePublish(message: PostboyMessage): void {\n this.before(MiddlewareStage.Publish, message);\n }\n\n public afterPublish(message: PostboyMessage): void {\n this.after(MiddlewareStage.Publish, message);\n }\n\n public beforeCallback(message: PostboyMessage): void {\n this.before(MiddlewareStage.Callback, message);\n }\n\n public afterCallback(message: PostboyMessage, result?: unknown): void {\n this.after(MiddlewareStage.Callback, message, result);\n }\n\n public beforeExecute<T>(message: PostboyExecutor<T>): void {\n this.before(MiddlewareStage.Execute, message);\n }\n\n public afterExecute<T>(message: PostboyExecutor<T>, result: T): void {\n this.after(MiddlewareStage.Execute, message, result);\n }\n\n private buildContext<T extends PostboyMessage>(stage: MiddlewareStage, message: T): PipelineContext<T> {\n return { stage, message };\n }\n\n private throwIfCancelled(\n stage: MiddlewareStage,\n cancelledBy?: string,\n messageId?: string,\n namespace?: string,\n ): never {\n throw new CancelError({\n stage,\n middleware: cancelledBy,\n messageId,\n namespace,\n reason: cancelledBy ? `Cancelled by middleware \"${cancelledBy}\"` : undefined,\n });\n }\n}\n","import { PostboySubscription } from '../models/postboy-subscription';\nimport { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyCallbackMessage } from '../models/postboy-callback.message';\n\n/**\n * The PostboyMessageStore is a utility class for managing message subscriptions and executors.\n * It provides functionality to register, retrieve, and unregister subscription-based messages and executors.\n */\nexport class PostboyMessageStore {\n protected messages = new Map<string, PostboySubscription<any>>();\n protected executors = new Map<string, (e: PostboyExecutor<any>) => any>();\n protected callbacks = new Map<string, (() => void)[]>();\n\n public registerMessage(id: string, sub: PostboySubscription<any>): void {\n // tslint:disable-next-line:no-console\n if (this.messages.has(id)) console.warn(`Message with id ${id} already registered. Overriding...`);\n this.messages.set(id, sub);\n }\n\n public registerExecutor(id: string, executor: (e: PostboyExecutor<any>) => any): void {\n // tslint:disable-next-line:no-console\n if (this.executors.has(id)) console.warn(`Executor with id ${id} already registered. Overriding...`);\n this.executors.set(id, executor);\n }\n\n callbackFired(message: PostboyCallbackMessage<any>): void {\n const existingCallbacks = this.callbacks.get(message.id);\n existingCallbacks\n ? existingCallbacks.push(() => message.complete())\n : this.callbacks.set(message.id, [() => message.complete()]);\n }\n\n public getMessage(id: string, name: string): PostboySubscription<any> {\n const msg = this.messages.get(id);\n if (!msg) throw new Error(`There is no registered event ${name}`);\n return msg;\n }\n\n public getExecutor<T>(id: string): (e: PostboyExecutor<T>) => T {\n const executorFunction = this.executors.get(id);\n if (!executorFunction) throw new Error(`There is no registered executor with id ${id}`);\n return executorFunction;\n }\n\n public unregister(id: string): void {\n this.messages.get(id)?.finish();\n this.messages.delete(id);\n this.callbacks.get(id)?.forEach((c) => c());\n this.callbacks.delete(id);\n this.executors.delete(id);\n }\n\n public dispose(): void {\n this.messages.forEach((m, id) => this.unregister(id));\n this.callbacks.forEach((fs) => fs.forEach((f) => f()));\n this.messages.clear();\n this.executors.clear();\n this.callbacks.clear();\n }\n}\n","export class IdGenerator {\n private static collection = 'ABCDEFGHIJKLMNOPQRSTUVWXTZ0123456789'.split('');\n\n public static get(): string {\n const result: string[] = [];\n for (let i = 0; i < 7; i++) {\n result.push(\n IdGenerator.collection\n .sort(() => 0.5 - Math.random())\n .slice(0, 5)\n .join(''),\n );\n }\n return result.join('-');\n }\n}\n","import { PostboyMessage } from './postboy.message';\n\nexport abstract class PostboyExecutor<T> extends PostboyMessage {\n declare protected readonly _postboyResultType?: T;\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyGenericMessage } from '../models/postboy-generic-message';\nimport { MessageType } from '../postboy-abstract.registrator';\nimport { Observable, Subject } from 'rxjs';\n\n/**\n * Represents a message that facilitates connection functionality\n * within the application's messaging system.\n *\n * @template T - A type that extends {@link PostboyGenericMessage}, representing\n * the structure of the message being handled.\n *\n * @extends PostboyExecutor<void>\n */\nexport class ConnectMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {\n static readonly ID = 'aa03a192-bdc7-402d-9f2f-bf3748229ea2';\n\n /**\n * Constructs a new instance of the class.\n *\n * @param {MessageType<T>} type - The type of the message.\n * @param {Subject<T>} sub - The subject to be used for message handling.\n * @param {(s: Subject<T>) => Observable<T>} [pipe] - An optional function to transform the subject.\n */\n constructor(\n public type: MessageType<T>,\n public sub: Subject<T>,\n public pipe?: (s: Subject<T>) => Observable<T>,\n ) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\n\n/**\n * Represents a message signaling a disconnection event. This class is used\n * within the framework to manage and process disconnection notifications.\n * Extends the {@link PostboyExecutor} base class.\n *\n * @extends {PostboyExecutor<void>}\n */\nexport class DisconnectMessage extends PostboyExecutor<void> {\n static readonly ID = '94579e43-5bc9-4517-bcda-b595bcda1ae7';\n\n /**\n * Creates an instance of the class with the specified message identifier.\n *\n * @param {string} messageId - The unique identifier for the message.\n */\n constructor(public messageId: string) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\nimport { MessageType } from '../postboy-abstract.registrator';\n\n/**\n * Registers an executor that connects to a specific type of message handler.\n * This class extends the functionality of `PostboyExecutor` and is designed to manage\n * the execution of a handler defined by a specific message type and an execution function.\n *\n * @template E The type of the executor extending {@link PostboyExecutor}.\n * @template T The return type of the execution function.\n *\n * @extends {PostboyExecutor<void>}\n */\nexport class ConnectExecutor<E extends PostboyExecutor<T>, T> extends PostboyExecutor<void> {\n static readonly ID = 'cb80e8ad-b68c-4b2d-8c44-617ea6017cb3';\n\n /**\n * Constructs an instance of the class with the specified type and execution function.\n *\n * @param {MessageType<E>} type - The type of the message.\n * @param {(e: E) => T} exec - The function to be executed with the input of type E that returns a value of type T.\n */\n constructor(\n public type: MessageType<E>,\n public exec: (e: E) => T,\n ) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyExecutionHandler } from '../models/postboy-execution.handler';\n\n/**\n * Represents a connection handler that extends the PostboyExecutor class.\n *\n * This class encapsulates logic associated with executing a handler in a structured way.\n * It is generic and operates on the provided executor and handler types.\n *\n * Type Parameters:\n * E - Represents an extension of the PostboyExecutor class with a specific type parameter R.\n * R - Represents the type of the result that the executor is expected to operate on.\n */\nexport class ConnectHandler<E extends PostboyExecutor<R>, R> extends PostboyExecutor<void> {\n static readonly ID = 'bf618cea-6f32-417c-9548-8eafe937378b';\n\n /**\n * Constructs an instance of the class.\n *\n * @param {new (...args: any[]) => E} executor - A constructor function for the executor object.\n * @param {PostboyExecutionHandler<R, E>} handler - A handler that processes the execution logic.\n */\n constructor(\n public executor: new (...args: any[]) => E,\n public handler: PostboyExecutionHandler<R, E>,\n ) {\n super();\n }\n}\n","import { PostboyService } from './postboy.service';\nimport { BehaviorSubject, Observable, pipe, ReplaySubject, Subject } from 'rxjs';\nimport { IPostboyDependingService } from './i-postboy-depending.service';\nimport { PostboyExecutor } from './models/postboy-executor';\nimport { checkId, PostboyGenericMessage } from './models/postboy-generic-message';\nimport { PostboyExecutionHandler } from './models/postboy-execution.handler';\nimport { IdGenerator } from './utils/id.generator';\nimport { ConnectMessage } from './messages/connect-message.executor';\nimport { DisconnectMessage } from './messages/disconnect-message.executor';\nimport { ConnectExecutor } from './messages/connect-executor.executor';\nimport { ConnectHandler } from './messages/connect-handler.executor';\n\nexport type MessageType<T extends PostboyGenericMessage> = new (...args: any[]) => T;\n\nexport abstract class PostboyAbstractRegistrator {\n get namespace(): string {\n return this._namespace;\n }\n private ids: string[] = [];\n private services: IPostboyDependingService[] = [];\n private readonly _namespace: string;\n\n constructor(\n protected postboy: PostboyService,\n namespace: string | null = null,\n ) {\n this._namespace = namespace ?? IdGenerator.get();\n }\n\n /**\n * Registers a list of services to be used by the application.\n *\n * @param {IPostboyDependingService[]} services - An array of services to register.\n * @return {void} This method does not return a value.\n */\n public registerServices(services: IPostboyDependingService[]): void {\n this.services = services;\n }\n\n /**\n * Initiates the 'up' process for the current instance and all associated services.\n *\n * @return {void} Does not return a value.\n */\n public up(): void {\n this._up?.();\n this.services.forEach((s) => s.up());\n }\n\n protected abstract _up(): void;\n\n public down(): void {\n this.services.forEach((s) => !!s.down && s.down());\n this.services = [];\n this.ids.forEach((id) => this.postboy.exec(new DisconnectMessage(id)));\n }\n\n /**\n * Records a type and its corresponding Subject<T> into the Postboy system and updates the internal identifiers.\n *\n * @param {MessageType<T>} type - A constructor for the generic message type T.\n * @param {Subject<T>} sub - The subject associated with the generic message type.\n * @return {this} Returns the current instance for method chaining.\n */\n public record<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>): PostboyAbstractRegistrator {\n this.ids.push(checkId(type));\n this.postboy.exec(new ConnectMessage(type, sub));\n return this;\n }\n\n /**\n * Records a message type with a specific subject and applies a transformation pipe to the subject.\n *\n * @param {MessageType<T>} type - The constructor of the message type to record, which extends PostboyGenericMessage.\n * @param {Subject<T>} sub - The Subject instance to associate with the message type.\n * @param {(s: Subject<T>) => Observable<T>} pipe - A function that takes the subject as input and returns an Observable with transformations applied.\n * @return {this} The current instance of the class for chaining.\n */\n public recordWithPipe<T extends PostboyGenericMessage>(\n type: MessageType<T>,\n sub: Subject<T>,\n pipe: (s: Subject<T>) => Observable<T>,\n ): PostboyAbstractRegistrator {\n this.ids.push(checkId(type));\n this.postboy.exec(new ConnectMessage(type, sub, pipe));\n return this;\n }\n\n /**\n * Records an executor associated with a specific type and execution logic.\n *\n * @param type The class constructor of the executor type to be recorded, which extends PostboyExecutor.\n * @param exec A callback function that executes the logic using an instance of the specified executor type.\n * @return void\n */\n public recordExecutor<E extends PostboyExecutor<T>, T>(\n type: new (...args: any[]) => E,\n exec: (e: E) => T,\n ): PostboyAbstractRegistrator {\n this.ids.push(checkId(type));\n this.postboy.exec(new ConnectExecutor(type, exec));\n return this;\n }\n\n /**\n * Records a handler for a specific executor type.\n *\n * @param executor The constructor of the executor type, which extends `PostboyExecutor`.\n * @param handler The execution handler associated with the given executor type.\n * @return void\n */\n public recordHandler<E extends PostboyExecutor<R>, R>(\n executor: new (...args: any[]) => E,\n handler: PostboyExecutionHandler<R, E>,\n ): PostboyAbstractRegistrator {\n this.ids.push(checkId(executor));\n this.postboy.exec(new ConnectHandler(executor, handler));\n return this;\n }\n\n /**\n * A utility function that facilitates the recording and replaying of messages\n * using a ReplaySubject. This function is designed to handle messages of a\n * specific type and allows specifying a buffer size to determine how many\n * of the most recent messages should be replayed.\n *\n * @template T Extends the PostboyGenericMessage type, representing the type of message\n * to be recorded and replayed.\n * @param {MessageType<T>} type The constructor of the message type to be recorded and replayed.\n * @param {number} [bufferSize=1] The number of recent messages to retain in the ReplaySubject's buffer.\n * Defaults to 1 if not specified.\n * @returns The result of invoking the `record` method with the given message type and configured ReplaySubject.\n */\n public recordReplay<T extends PostboyGenericMessage>(\n type: MessageType<T>,\n bufferSize = 1,\n ): PostboyAbstractRegistrator {\n this.record(type, new ReplaySubject<T>(bufferSize));\n return this;\n }\n\n /**\n * Represents a method that records a specific behavior associated with a message type.\n * It creates a `BehaviorSubject` initialized with the provided initial message\n * and associates it with the given message type using the `record` method.\n *\n * @template T - A type parameter extending `PostboyGenericMessage` that defines the message structure.\n * @param {MessageType<T>} type - The constructor function of the message type to be recorded.\n * @param {T} initial - The initial value of the message that will be set in the `BehaviorSubject`.\n * @returns {void} - This function does not return a value; instead, it modifies the internal state.\n */\n public recordBehavior<T extends PostboyGenericMessage>(type: MessageType<T>, initial: T): PostboyAbstractRegistrator {\n this.record(type, new BehaviorSubject<T>(initial));\n return this;\n }\n\n /**\n * A function that creates and returns a new generic message recorder for a specific message type.\n *\n * @template T - A type parameter extending from `PostboyGenericMessage`.\n * @param {MessageType<T>} type - The constructor for the message type being recorded.\n * @returns {Subject<T>} A new instance of `Subject<T>` bound to the specified message type.\n */\n public recordSubject<T extends PostboyGenericMessage>(type: MessageType<T>) {\n this.record(type, new Subject<T>());\n return this;\n }\n}\n","import { PostboyAbstractRegistrator } from '../postboy-abstract.registrator';\nimport { PostboyService } from '../postboy.service';\n\n/**\n * NamespaceRegistrator is a specialized class that extends PostboyAbstractRegistrator.\n *\n * @class NamespaceRegistrator\n * @extends PostboyAbstractRegistrator\n * @param {PostboyService} postboy - An instance of the PostboyService, used for managing registrations.\n */\nexport class NamespaceRegistrator extends PostboyAbstractRegistrator {\n constructor(postboy: PostboyService) {\n super(postboy);\n }\n\n protected _up(): void {\n // ignore\n }\n}\n","import { PostboyAbstractRegistrator } from '../postboy-abstract.registrator';\nimport { NamespaceRegistrator } from './namespace-registrator';\nimport { PostboyService } from '../postboy.service';\n\n/**\n * Represents a store for managing namespaces in the Postboy system.\n * Provides functionality to add, eliminate, and dispose namespaces.\n */\nexport class PostboyNamespaceStore {\n private spaces: Map<string, PostboyAbstractRegistrator> = new Map();\n\n /**\n * Adds a new space or retrieves an existing one if it already exists.\n *\n * @param {string} space - The name of the space to add or retrieve.\n * @param {PostboyService} postboy - The PostboyService instance used to create a namespace registrator.\n * @return {PostboyAbstractRegistrator} The registrator associated with the specified space.\n */\n public addSpace(space: string, postboy: PostboyService): PostboyAbstractRegistrator {\n if (this.spaces.has(space)) return this.spaces.get(space)!;\n const registrator = new NamespaceRegistrator(postboy);\n this.spaces.set(space, registrator);\n return registrator;\n }\n\n /**\n * Removes a specified space from the spaces collection if it exists.\n * If the space exists, it will be deleted after invoking its down method.\n *\n * @param {string} space - The name of the space to be removed.\n * @return {void} This method does not return a value.\n */\n public eliminateSpace(space: string): void {\n if (!this.spaces.has(space)) return;\n this.spaces.get(space)?.down();\n this.spaces.delete(space);\n }\n\n /**\n * Disposes of the current instance by performing cleanup operations.\n * Iterates through all spaces, performs a \"down\" operation on each,\n * and then clears the collection of spaces.\n *\n * @return {void} No return value.\n */\n public dispose(): void {\n this.spaces.forEach((space) => space.down());\n this.spaces.clear();\n }\n}\n","import { PostboyMiddlewareService } from './postboy-middleware.service';\nimport { PostboyMessageStore } from './postboy-message.store';\nimport { PostboyNamespaceStore } from './postboy-namespace.store';\n\nexport class PostboyDependencyResolver {\n /**\n * Retrieves an instance of the PostboyMiddlewareService.\n *\n * This function initializes and returns a new instance of the\n * PostboyMiddlewareService, which can be used to configure and manage\n * middleware for a specific module or application.\n *\n * @returns {PostboyMiddlewareService} A new instance of PostboyMiddlewareService.\n */\n getMiddlewareService = () => new PostboyMiddlewareService();\n /**\n * A function that instantiates and returns a new instance of PostboyMessageStore.\n *\n * This function serves as a factory method for creating instances\n * of the PostboyMessageStore class.\n *\n * @returns {PostboyMessageStore} A new instance of the PostboyMessageStore class.\n */\n getMessageStore = () => new PostboyMessageStore();\n /**\n * Creates and initializes a new instance of PostboyNamespaceStore using the provided PostboyService instance.\n *\n * @function getNamespaceStore\n * @returns {PostboyNamespaceStore} A new instance of PostboyNamespaceStore associated with the given PostboyService.\n */\n getNamespaceStore = () => new PostboyNamespaceStore();\n}\n","import { PostboyAbstractRegistrator } from '../postboy-abstract.registrator';\nimport { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyExecutionHandler } from '../models/postboy-execution.handler';\nimport { PostboyNamespaceStore } from '../services/postboy-namespace.store';\nimport { PostboyService } from '../postboy.service';\n\n/**\n * AddNamespace is a class that extends the PostboyExecutor with a specific implementation\n * for adding namespaces to a PostboyService instance.\n *\n * This class is identified uniquely by its static ID property for tracking and referencing purposes.\n */\nexport class AddNamespace extends PostboyExecutor<PostboyAbstractRegistrator> {\n static readonly ID = '6d1a6f7d-6b6e-4c4d-8af8-9cc9a32e850c';\n\n /**\n * Creates an instance of the class with the specified space identifier.\n *\n * @param {string} space - The identifier for the space.\n */\n constructor(public space: string) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\n\n/**\n * Represents an executor that eliminates a specific namespace.\n * This class extends the PostboyExecutor with a void return type.\n */\nexport class EliminateNamespace extends PostboyExecutor<void> {\n static readonly ID = '03bb03bb-53e0-4b74-9aad-64d5c54a8972';\n\n /**\n * Creates an instance of the class with the specified space value.\n *\n * @param {string} space - The string value representing the space configuration.\n */\n constructor(public space: string) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyMiddleware } from '../services/postboy-middleware';\n\n/**\n * Represents a {@link PostboyMiddleware} addition operation for Postboy.\n * This class extends the functionality of the PostboyExecutor to add middleware to the processing chain.\n *\n * The middleware to be added is provided during instantiation.\n */\nexport class AddMiddleware extends PostboyExecutor<void> {\n static readonly ID = '0a8cfe0a-6193-4082-8440-d0793367b21d';\n\n /**\n * Initializes a new instance of the class with the specified middleware.\n *\n * @param {PostboyMiddleware} middleware - The {@link PostboyMiddleware} to be used for processing.\n */\n constructor(public middleware: PostboyMiddleware) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\nimport { PostboyMiddleware } from '../services/postboy-middleware';\n\n/**\n * Represents a class responsible for removing {@link PostboyMiddleware} in execution flow.\n * This class extends PostboyExecutor and operates with a void return type.\n */\nexport class RemoveMiddleware extends PostboyExecutor<void> {\n static readonly ID = 'c25c708c-53c9-498d-a28b-936fbaf68b91';\n\n /**\n * Constructs an instance of the class with the specified middleware.\n *\n * @param {PostboyMiddleware} middleware - The {@link PostboyMiddleware} instance to be removed.\n */\n constructor(public middleware: PostboyMiddleware) {\n super();\n }\n}\n","import { PostboyGenericMessage } from '../models/postboy-generic-message';\nimport { MessageType } from '../postboy-abstract.registrator';\nimport { PostboyExecutor } from '../models/postboy-executor';\n\n/**\n * Locks a specific message type to prevent firing of them.\n *\n * This class is used to handle operations associated with locking mechanisms\n * for a specified message type.\n *\n * @template T - A type that extends {@link PostboyGenericMessage}.\n */\nexport class LockMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {\n static readonly ID = '477df3e2-1f99-4476-9a3b-afd1fa426436';\n\n /**\n * Constructs an instance of the class with the specified message type.\n *\n * @param {MessageType<T>} type - The type of the message to be used for the instance.\n */\n constructor(public type: MessageType<T>) {\n super();\n }\n}\n","import { PostboyGenericMessage } from '../models/postboy-generic-message';\nimport { PostboyExecutor } from '../models/postboy-executor';\nimport { MessageType } from '../postboy-abstract.registrator';\n\n/**\n * A specialized executor that handles the unlocking process for messages of a specified type.\n * Unlocks a previously locked message, making it available for processing again.\n *\n * @template T - The type parameter extending {@link PostboyGenericMessage}, representing the message type handled by the executor.\n * @extends {PostboyExecutor<void>}\n */\nexport class UnlockMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {\n static readonly ID = 'd71d25e3-90ac-4009-b972-9e6c6b05611e';\n\n /**\n * Creates an instance of the class with the specified message type.\n *\n * @param {MessageType<T>} type - The message type for this instance.\n */\n constructor(public type: MessageType<T>) {\n super();\n }\n}\n","import { first, Observable, Subject, tap } from 'rxjs';\nimport { checkId, PostboyGenericMessage } from './models/postboy-generic-message';\nimport { PostboySubscription } from './models/postboy-subscription';\nimport { PostboyExecutor } from './models/postboy-executor';\nimport { PostboyCallbackMessage } from './models/postboy-callback.message';\nimport { MessageType } from './postboy-abstract.registrator';\nimport { PostboyExecutionHandler } from './models/postboy-execution.handler';\nimport { PostboyDependencyResolver } from './services/postboy-dependency.resolver';\nimport { PostboyMiddlewareService } from './services/postboy-middleware.service';\nimport { PostboyMessageStore } from './services/postboy-message.store';\nimport { PostboyNamespaceStore } from './services/postboy-namespace.store';\nimport { AddNamespace } from './messages/add-namespace.executor';\nimport { EliminateNamespace } from './messages/eliminate-namespace.executor';\nimport { AddMiddleware } from './messages/add-middleware.executor';\nimport { RemoveMiddleware } from './messages/remove-middleware.executor';\nimport { LockMessage } from './messages/lock-message.executor';\nimport { UnlockMessage } from './messages/unlock-message.executor';\nimport { DisconnectMessage } from './messages/disconnect-message.executor';\nimport { ConnectMessage } from './messages/connect-message.executor';\nimport { ConnectExecutor } from './messages/connect-executor.executor';\nimport { ConnectHandler } from './messages/connect-handler.executor';\n\nexport class PostboyService {\n protected locked = new Set<string>();\n private middleware: PostboyMiddlewareService;\n private store: PostboyMessageStore;\n private namespaceStore: PostboyNamespaceStore;\n private dependencyResolver: PostboyDependencyResolver;\n\n constructor(resolver?: PostboyDependencyResolver) {\n this.dependencyResolver = resolver || new PostboyDependencyResolver();\n this.middleware = this.dependencyResolver.getMiddlewareService();\n this.store = this.dependencyResolver.getMessageStore();\n this.namespaceStore = this.dependencyResolver.getNamespaceStore();\n this.registerInfrastructureMessages();\n }\n\n private registerInfrastructureMessages() {\n this.store.registerExecutor(DisconnectMessage.ID, (e) => this.store.unregister((e as DisconnectMessage).messageId));\n this.store.registerExecutor(UnlockMessage.ID, (e) => this.locked.delete(checkId((e as UnlockMessage<any>).type)));\n this.store.registerExecutor(LockMessage.ID, (e) => this.locked.add(checkId((e as LockMessage<any>).type)));\n this.store.registerExecutor(AddMiddleware.ID, (e) =>\n this.middleware.addMiddleware((e as AddMiddleware).middleware),\n );\n this.store.registerExecutor(RemoveMiddleware.ID, (e) =>\n this.middleware.removeMiddleware((e as RemoveMiddleware).middleware),\n );\n this.store.registerExecutor(AddNamespace.ID, (e) => this.namespaceStore.addSpace((e as AddNamespace).space, this));\n this.store.registerExecutor(EliminateNamespace.ID, (e) =>\n this.namespaceStore.eliminateSpace((e as EliminateNamespace).space),\n );\n this.store.registerExecutor(ConnectMessage.ID, (e) => {\n const { type, sub, pipe } = e as ConnectMessage<any>;\n this.store.registerMessage(checkId(type), new PostboySubscription<any>(sub, pipe));\n });\n this.store.registerExecutor(ConnectExecutor.ID, (e) => {\n const { type, exec } = e as ConnectExecutor<any, any>;\n this.store.registerExecutor(checkId(type), exec);\n });\n this.store.registerExecutor(ConnectHandler.ID, (e) => {\n const { executor, handler } = e as ConnectHandler<any, any>;\n this.store.registerExecutor(checkId(executor), (e) => handler.handle(e));\n });\n }\n\n /**\n * Fires a registered event and passes the message to its subscribers.\n *\n * @param {PostboyGenericMessage} message - The message object containing the event data.\n * @return {void} This method does not return a value.\n * @throws {Error} Throws an error if no registered event is found for the provided message ID.\n */\n public fire(message: PostboyGenericMessage): void {\n this.middleware.beforePublish(message);\n if (!this.locked.has(message.id)) {\n this.store.getMessage(message.id, message.constructor.name).fire(message);\n }\n this.middleware.afterPublish(message);\n }\n\n /**\n * Triggers a callback function associated with a given message.\n *\n * @param {PostboyCallbackMessage<T>} message - The message object used to trigger the callback.\n * It contains details about the event and result subscription.\n * @param {(e: T) => void} [action] - Optional callback function to execute when the result of the message is emitted.\n * @return {void} This method does not return any value.\n */\n public fireCallback<T>(message: PostboyCallbackMessage<T>, action?: (e: T) => void): Observable<T> {\n this.middleware.beforeCallback(message);\n if (action) message.result.subscribe(action);\n this.store.callbackFired(message);\n const result$ = action ? message.result.pipe(tap(action)) : message.result;\n const msg = this.store.getMessage(message.id, message.constructor.name);\n const observable = new Observable<T>((subscriber) => {\n const subscription = result$.pipe(tap(() => this.middleware.afterCallback(message))).subscribe(subscriber);\n\n if (!this.locked.has(message.id)) {\n msg.fire(message);\n }\n\n return () => subscription.unsubscribe();\n });\n if (!!action) observable.subscribe();\n return observable;\n }\n\n /**\n * Executes the provided executor function and returns its result.\n *\n * @param {PostboyExecutor<T>} executor The executor to be executed, which includes its identifier and logic.\n * @return {T} The resulting output from the executed executor function.\n * @throws {Error} If the specified executor is not registered.\n */\n public exec<T>(executor: PostboyExecutor<T>): T {\n this.middleware.beforeExecute(executor);\n const result = this.store.getExecutor<T>(executor.id)(executor);\n this.middleware.afterExecute(executor, result);\n return result;\n }\n\n /**\n * Subscribes to a specific message type and returns an observable of that type.\n *\n * @param type The constructor function of the type that extends PostboyGenericMessage.\n * @return An Observable of the specified generic message type.\n */\n public sub<T extends PostboyGenericMessage>(type: MessageType<T>): Observable<T> {\n return this.store.getMessage(checkId(type), type.name).sub();\n }\n\n /**\n * Subscribes to a specific message type and automatically unsubscribes after receiving the first message.\n *\n * @param type The type of message to subscribe to.\n * @return An observable that emits the first message of the specified type and then completes.\n */\n public once<T extends PostboyGenericMessage>(type: MessageType<T>): Observable<T> {\n return this.sub(type).pipe(first());\n }\n\n /**\n * Registers a given message type and its associated subject subscription with the system.\n *\n * @deprecated The method should be replaced with firing {@link ConnectMessage} message.\n * @param type The constructor function of the message type that extends the PostboyGenericMessage.\n * @param sub The Subject instance for the provided message type, used for managing subscriptions.\n * @return {void} No return value.\n */\n public record<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>): void {\n this.store.registerMessage(checkId(type), new PostboySubscription<T>(sub, (s) => s.asObservable()));\n }\n\n /**\n * Registers a generic message type with a Subject and a transformation pipe.\n *\n * @deprecated The method should be replaced with firing {@link ConnectMessage} message.\n * @param {MessageType<T>} type - The constructor of the message type being registered.\n * @param {Subject<T>} sub - The Subject instance used to handle incoming messages of the specified type.\n * @param {(s: Subject<T>) => Observable<T>} pipe - A function that applies a transformation or processing logic to the Subject and returns an Observable.\n * @return {void} No return value.\n */\n public recordWithPipe<T extends PostboyGenericMessage>(\n type: MessageType<T>,\n sub: Subject<T>,\n pipe: (s: Subject<T>) => Observable<T>,\n ): void {\n this.store.registerMessage(checkId(type), new PostboySubscription<T>(sub, pipe));\n }\n\n /**\n * Registers an executor for a specified message type.\n *\n * @deprecated The method should be replaced with firing {@link ConnectExecutor} message.\n * @param {MessageType<E>} type - The message type for which the executor is being registered.\n * @param {(e: E) => T} exec - The executor function that will handle messages of the specified type.\n * @return {void} This method does not return any value.\n */\n public recordExecutor<E extends PostboyExecutor<T>, T>(type: MessageType<E>, exec: (e: E) => T): void {\n this.store.registerExecutor(checkId(type), exec as (e: PostboyExecutor<T>) => T);\n }\n\n /**\n * Registers a handler for a specific executor type.\n *\n * @deprecated The method should be replaced with firing {@link ConnectHandler} message.\n * @param executor The constructor of the executor class that extends `PostboyExecutor<R>`.\n * @param handler An instance of `PostboyExecutionHandler<R, E>` that defines the logic for handling the executor.\n * @return void\n */\n public recordHandler<E extends PostboyExecutor<R>, R>(\n executor: new (...args: any[]) => E,\n handler: PostboyExecutionHandler<R, E>,\n ): void {\n this.store.registerExecutor(checkId(executor), (e) => handler.handle(e as E));\n }\n\n /**\n * Disposes of resources and cleans up any internal components or stores associated with the instance.\n * This method ensures that all resources are properly released to avoid memory leaks.\n *\n * @return {void} This method does not return a value.\n */\n public dispose(): void {\n this.namespaceStore?.dispose();\n this.store.dispose();\n this.middleware.dispose();\n }\n}\n","import { PipelineContext } from '../models/pipeline-context';\nimport { MiddlewareDecisionType } from '../models/middleware-decision.enum';\nimport { MiddlewareDecision } from '../models';\n\n/**\n * Abstract base class for defining middleware in a pipeline.\n * Middleware acts on various stages of pipeline execution, allowing operations\n * to be intercepted, modified, or monitored.\n */\nexport abstract class PostboyMiddleware {\n public readonly name: string;\n\n /**\n * Creates an instance of a class, optionally assigning a name.\n *\n * @param {string} [name] - An optional name to be assigned. If not provided, defaults to the class name.\n */\n constructor(name?: string) {\n this.name = name ?? this.constructor.name;\n }\n\n /**\n * Optional filter to skip middleware for unrelated messages/stages.\n */\n public canHandle(_context: PipelineContext): boolean {\n return true;\n }\n\n /**\n * Called before the stage is executed.\n * Return Interrupt to cancel the operation.\n */\n public before(_context: PipelineContext): MiddlewareDecision {\n return { type: MiddlewareDecisionType.Continue };\n }\n\n /**\n * Called after the stage has finished successfully.\n * `result` is typically set for execute-stage.\n */\n public after(_context: PipelineContext, _result?: unknown): void {\n // noop\n }\n\n /**\n * Optional cleanup hook.\n */\n public dispose(): void {\n // noop\n }\n}\n","import { Observable, Subject } from 'rxjs';\nimport { PostboyGenericMessage } from './postboy-generic-message';\n\n/**\n * An abstract class extending PostboyGenericMessage that provides mechanisms for managing\n * asynchronous data communication using RxJS observables. It is designed to work with\n * callback-based operations that emit a result of type T.\n *\n * @template T - The type of the data emitted by the observables in this class.\n *\n * @extends PostboyGenericMessage\n *\n * @property {Observable<T>} result - An observable that emits the result of the operation\n * and completes once the operation is finished.\n *\n * @method next - Emits the next value for the result observable.\n * @param {T} value - The value to be emitted by the result observable.\n *\n * @method finish - Emits the final value for the result observable and completes it.\n * @param {T} value - The final value for the observable emission.\n */\nexport abstract class PostboyCallbackMessage<T> extends PostboyGenericMessage {\n protected result$ = new Subject<T>();\n public result: Observable<T> = this.result$.asObservable();\n\n /**\n * Emits the provided value.\n *\n * @template T - The type of the value to emit.\n * @param {T} value - The value to emit through the `result$` observable.\n * @returns {void}\n */\n public next = (value: T): void => this.result$.next(value);\n\n /**\n * Marks the operation as complete by emitting the provided value and then completing the result stream.\n *\n * @param {T} value - The value to emit prior to completing the result stream.\n * @return {void} This method does not return a value.\n */\n public finish(value: T): void {\n this.result$.next(value);\n this.result$.complete();\n }\n\n /**\n * Completes the current observable result stream.\n * This method marks the result observable as complete, ensuring no further values\n * or events will be emitted from it.\n *\n * @return {void} No value is returned from this method.\n */\n public complete(): void {\n this.result$.complete();\n }\n}\n","import { PostboyExecutor } from './postboy-executor';\n\n/**\n * Abstract class representing a handler for executing a Postboy task.\n *\n * This class is intended to manage the execution flow of a PostboyExecutor instance.\n * Subclasses must implement the `handle` method, which executes a given PostboyExecutor\n * and returns a result of type R.\n *\n * @template R The type of the result returned by the `handle` method.\n * @template E The type of the executor extending the PostboyExecutor.\n */\nexport abstract class PostboyExecutionHandler<R, E extends PostboyExecutor<R>> {\n /**\n * Abstract method to handle the specified executor and return a result.\n *\n * @param {E} executor - The executor that will be processed by the method.\n * @return {R} The result obtained after handling the executor.\n */\n abstract handle(executor: E): R;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artstesh/postboy",
3
- "version": "3.4.2",
3
+ "version": "3.5.0",
4
4
  "author": "artstesh",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.mjs",