@artstesh/postboy 3.5.1 → 3.5.2

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/AI_SKILL.md CHANGED
@@ -43,7 +43,7 @@ class PostboyService {
43
43
 
44
44
  // Messaging
45
45
  fire(message: PostboyGenericMessage): void // throws CancelError if middleware interrupts; throws if type not registered
46
- fireCallback<T>(message: PostboyCallbackMessage<T>, action?: (e: T) => void): Observable<T>
46
+ fireCallback<T>(message: PostboyCallbackMessage<T>, action?: (e: T) => void): Observable<T> // action is invoked exactly once per emitted value; without action the dispatch is lazy (see §4)
47
47
  sub<T extends PostboyGenericMessage>(type: MessageType<T>): Observable<T>
48
48
  once<T extends PostboyGenericMessage>(type: MessageType<T>): Observable<T> // = sub(type).pipe(first())
49
49
  exec<T>(executor: PostboyExecutor<T>): T // synchronous; throws if executor not registered or cancelled
@@ -202,7 +202,7 @@ Rules of composition:
202
202
  - Use `recordReplay` for "latest value on subscribe" semantics and `recordBehavior` for state; use `recordWithPipe`/`ConnectMessage` with a pipe for shared/debounced streams.
203
203
  - Prefer registrators over bare `exec(new ConnectMessage(...))` in application code — they track IDs and dispose.
204
204
  - Middleware: move validation/gating to `before` (return `Interrupt` to cancel), logging/side effects to `after`. Catch `CancelError` at call sites where cancellation is expected and check `error.details` (stage, middleware, messageId, reason).
205
- - `fireCallback` with no `action` argument dispatches the message **lazily** — the subject fires only when the returned Observable is subscribed. Pass `action` (or subscribe immediately) when the request must be sent right away. `after` middleware hooks for the Callback stage fire on each result emission.
205
+ - `fireCallback` with no `action` argument dispatches the message **lazily** — the subject fires only when the returned Observable is subscribed. Pass `action` (or subscribe immediately) when the request must be sent right away. When `action` IS passed, it is invoked exactly once per emitted value, no matter how many subscriptions the returned Observable has — do not add extra `subscribe(action)` calls on the result. `after` middleware hooks for the Callback stage fire on each result emission.
206
206
  - Error handling: `checkId` throws `"<ClassName> should have a static ID field"`; `fire` throws for unregistered message IDs; `exec` throws for unregistered executor IDs (TypeError calling undefined). Wrap `exec`/`fire` in try/catch at call sites where registration is not guaranteed; treat a locked message as a no-op, not an error.
207
207
 
208
208
  ## 5. ⚠️ ANTI-PATTERNS & PITFALLS
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 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
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 g=class extends d{};function i(s){if(!s.ID)throw new Error(`${s.name} should have a static ID field`);return s.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 P=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 v=this.buildContext(e,t);a.canHandle(v)&&a.after(v,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 P({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 o=class extends d{};var c=class extends o{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 o{constructor(t){super();this.messageId=t;}};n.ID="94579e43-5bc9-4517-bcda-b595bcda1ae7";var p=class extends o{constructor(t,r){super();this.type=t;this.exec=r;}};p.ID="cb80e8ad-b68c-4b2d-8c44-617ea6017cb3";var b=class extends o{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 T=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 T;}};var u=class extends o{constructor(t){super();this.space=t;}};u.ID="6d1a6f7d-6b6e-4c4d-8af8-9cc9a32e850c";var m=class extends o{constructor(t){super();this.space=t;}};m.ID="03bb03bb-53e0-4b74-9aad-64d5c54a8972";var f=class extends o{constructor(t){super();this.middleware=t;}};f.ID="0a8cfe0a-6193-4082-8440-d0793367b21d";var x=class extends o{constructor(t){super();this.middleware=t;}};x.ID="c25c708c-53c9-498d-a28b-936fbaf68b91";var y=class extends o{constructor(t){super();this.type=t;}};y.ID="477df3e2-1f99-4476-9a3b-afd1fa426436";var h=class extends o{constructor(t){super();this.type=t;}};h.ID="d71d25e3-90ac-4009-b972-9e6c6b05611e";var G=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),this.store.callbackFired(e),t&&e.result.subscribe(t);let r=this.store.getMessage(e.id,e.constructor.name),a=new rxjs.Observable(v=>{let H=e.result.pipe(rxjs.tap(()=>this.middleware.afterCallback(e))).subscribe(v);return this.locked.has(e.id)||r.fire(e),()=>H.unsubscribe()});return t&&a.subscribe(),a}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 g{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=P;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=o;exports.PostboyGenericMessage=g;exports.PostboyMessage=d;exports.PostboyMessageStore=w;exports.PostboyMiddleware=A;exports.PostboyMiddlewareService=E;exports.PostboyNamespaceStore=T;exports.PostboyService=G;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,IACT,CACF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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,ECvMO,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 * 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"]}
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","observable","Observable","subscriber","tap","first","PostboyMiddleware","_context","_result","PostboyCallbackMessage","value","PostboyExecutionHandler"],"mappings":"sCAUO,IAAeA,CAAAA,CAAf,KAA8B,CAA9B,cAEL,IAAA,CAAO,QAAA,CAAmC,GAAC,CAG3C,IAAW,IAAa,CACtB,OAAQ,IAAA,CAAK,WAAA,CAAoB,EACnC,CAQA,YAAYC,CAAAA,CAAiD,CAC3D,YAAK,QAAA,CAAW,CAAE,GAAG,IAAA,CAAK,QAAA,CAAU,GAAGA,CAAS,CAAA,CACzC,IACT,CACF,ECVO,IAAeC,CAAAA,CAAf,cAA6CF,CAAe,GAS5D,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,CCpBO,IAAMC,CAAAA,CAAN,KAA6B,CAOlC,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,CAGO,GAAA,EAAqB,CAC1B,OAAO,IAAA,CAAK,aACd,CAGO,KAAKE,CAAAA,CAAe,CACzB,IAAA,CAAK,YAAA,CAAa,IAAA,CAAKA,CAAI,EAC7B,CAGO,MAAA,EAAe,CACpB,IAAA,CAAK,YAAA,CAAa,QAAA,GACpB,CACF,MCnCYC,CAAAA,CAAAA,CAAAA,CAAAA,GAEVA,CAAAA,CAAAA,CAAAA,CAAA,QAAU,CAAA,CAAA,CAAV,SAAA,CAEAA,CAAAA,CAAAA,CAAAA,CAAA,QAAA,CAA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,CACF,ECzCO,IAAeC,CAAAA,CAAf,KAAwE","file":"index.cjs","sourcesContent":["import { PostboyMessageMetadata } from './postboy-message-metadata';\n\n/**\n * Root of the message hierarchy — anything that travels through the bus.\n *\n * A message is a plain data carrier: dispatch behavior comes from the subclasses.\n * {@link PostboyGenericMessage} is the base for pub/sub messages, and\n * {@link PostboyExecutor} carries a synchronous command. The bus routes every one of\n * them by the static `ID` of the concrete class, exposed per instance by {@link id}.\n */\nexport abstract class PostboyMessage {\n /** Free-form data attached to the message; populate it via {@link setMetadata}. */\n public metadata: PostboyMessageMetadata = {};\n\n /** The static `ID` of the concrete message class — the key the bus routes by. */\n public get id(): string {\n return (this.constructor as any).ID;\n }\n\n /**\n * Shallow-merges the given fields into {@link metadata}.\n *\n * @param metadata - Fields to add or override.\n * @return This message, for chaining.\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 * Base class for pub/sub messages — the \"letters\" carried by the bus.\n *\n * A subclass must declare its own `static readonly ID` (a unique string): registration,\n * subscription, locking, and dispatch are all keyed by that `ID`, not by class identity.\n * Inheriting a parent's `ID` makes two message types silently collide on one registration.\n *\n * @example\n * ```ts\n * class PingMessage extends PostboyGenericMessage {\n * static readonly ID = 'app.ping';\n * constructor(public text: string) {\n * super();\n * }\n * }\n * ```\n */\nexport abstract class PostboyGenericMessage extends PostboyMessage {}\n\n/**\n * Returns the static `ID` of a message class, refusing classes that declare none.\n *\n * @param message - The constructor to read the `ID` from.\n * @return The static `ID` value.\n * @throws Error When the class declares no static `ID`.\n */\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 * The internal pairing of a registered subject with the observable handed out to\n * subscribers — the pipe, when given, is applied exactly once, here.\n *\n * Created by the registration paths (`ConnectMessage` and the deprecated `record*`\n * methods); consumer code never constructs it directly.\n *\n * @template T - The message type the stream carries.\n */\nexport class PostboySubscription<T> {\n private readonly _subscription: Observable<T>;\n\n /**\n * @param subscription - The subject `fire` pushes messages into.\n * @param pipe - Optional wrapper producing the observable subscribers receive; defaults to the plain subject.\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 /** The observable handed out on every `PostboyService.sub` call — one shared stream for all subscribers. */\n public sub(): Observable<T> {\n return this._subscription;\n }\n\n /** Pushes a message into the underlying subject, notifying all subscribers synchronously. */\n public fire(data: T): void {\n this.subscription.next(data);\n }\n\n /** Completes the underlying subject, ending every subscriber's stream. */\n public finish(): void {\n this.subscription.complete();\n }\n}\n","/**\n * The pipeline phase a middleware hook is running for. Each bus verb has its own stage:\n * `Publish` for `fire`, `Callback` for `fireCallback`, `Execute` for `exec`.\n */\nexport enum MiddlewareStage {\n /** `PostboyService.fire` — pub/sub dispatch. */\n Publish = 1,\n /** `PostboyService.fireCallback` — async request/response dispatch. */\n Callback,\n /** `PostboyService.exec` — synchronous command execution, including infrastructure messages. */\n Execute,\n}\n","/**\n * The verdict a middleware returns from its `before` hook: let the operation proceed,\n * or cancel it.\n */\nexport enum MiddlewareDecisionType {\n /** Run the operation; the pipeline moves on to the next middleware. */\n Continue = 1,\n /** Cancel the operation: the bus throws a {@link CancelError} and the `after` hooks are skipped. */\n Interrupt,\n}\n","import { CancelDetails } from './cancel-details';\nimport { MiddlewareStage } from './middleware-stage.enum';\n\n/**\n * The error thrown when a middleware interrupts an operation by returning an interrupt\n * decision from its `before` hook — the operation does not run.\n *\n * Thrown by `PostboyService.fire`, `fireCallback`, and `exec`. Distinguish it from other\n * errors via `error.name === 'PostboyCancelError'` or `error instanceof CancelError`,\n * then inspect {@link details} to find the cancelling middleware and stage.\n */\nexport class CancelError extends Error {\n /** Structured information about the cancellation. */\n public readonly details: CancelDetails;\n\n /**\n * @param details - What was cancelled, where, and why; `details.reason` — or a generated\n * stage message — becomes the error message.\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\n/**\n * Type guard checking whether an unknown error is a {@link CancelError}.\n *\n * @param error - The caught value.\n * @return True when the error was produced by a middleware interruption.\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\n/**\n * The middleware pipeline of the bus: keeps the chain in insertion order and drives the\n * hooks around every operation. Consumer code does not call it directly — middleware is\n * managed through the `AddMiddleware`/`RemoveMiddleware` messages.\n */\nexport class PostboyMiddlewareService {\n /** The middleware chain, in insertion order. */\n protected middlewares: PostboyMiddleware[] = [];\n\n /** Appends the middleware to the end of the chain; appending the same instance twice runs its hooks twice. */\n public addMiddleware(middleware: PostboyMiddleware): void {\n this.middlewares.push(middleware);\n }\n\n /** Removes the middleware by identity and calls its `dispose()` hook; unknown instances are ignored. */\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 /** Disposes every middleware in the chain and empties it. */\n public dispose(): void {\n this.middlewares.forEach((m) => m.dispose());\n this.middlewares = [];\n }\n\n /**\n * Runs the `before` hooks for the stage, consulting `canHandle` on each middleware.\n * Stops and throws {@link CancelError} as soon as one returns an interrupt decision.\n *\n * @throws CancelError With the stage, middleware name, and message id of the interruption.\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 /** Runs the `after` hooks for the stage, passing the executor result when there is one. */\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 /** `before` hooks for the `Publish` stage (`PostboyService.fire`). */\n public beforePublish(message: PostboyMessage): void {\n this.before(MiddlewareStage.Publish, message);\n }\n\n /** `after` hooks for the `Publish` stage (`PostboyService.fire`). */\n public afterPublish(message: PostboyMessage): void {\n this.after(MiddlewareStage.Publish, message);\n }\n\n /** `before` hooks for the `Callback` stage (`PostboyService.fireCallback`). */\n public beforeCallback(message: PostboyMessage): void {\n this.before(MiddlewareStage.Callback, message);\n }\n\n /** `after` hooks for the `Callback` stage — run on every emitted result value. */\n public afterCallback(message: PostboyMessage, result?: unknown): void {\n this.after(MiddlewareStage.Callback, message, result);\n }\n\n /** `before` hooks for the `Execute` stage (`PostboyService.exec`). */\n public beforeExecute<T>(message: PostboyExecutor<T>): void {\n this.before(MiddlewareStage.Execute, message);\n }\n\n /** `after` hooks for the `Execute` stage, receiving the executor's return value. */\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 registry behind the bus: message subscriptions and executor handlers keyed by\n * their static `ID`, plus completion callbacks for fired callback messages. Consumer\n * code reaches it only through `PostboyService` and the infrastructure messages.\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 /**\n * Registers a message subscription under the id, logging a warning and overriding\n * when the id is already taken.\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 /**\n * Registers an executor handler under the id, logging a warning and overriding\n * when the id is already taken.\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 /** Records a callback completing the message's result when its type is unregistered or the bus disposed. */\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 /**\n * @param id - The static `ID` the subscription was registered under.\n * @param name - Used only in the error message.\n * @throws Error When no message is registered under the id.\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 /**\n * @param id - The static `ID` the handler was registered under.\n * @throws Error When no executor is registered under the id.\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 /**\n * Removes an id completely: completes its subscription stream, runs the recorded\n * completion callbacks (completing fired callback results), and deletes the message,\n * executor, and callback entries.\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 /**\n * Tears the store down: unregisters every message, runs the remaining callbacks, and\n * clears all maps — including the infrastructure handlers, so the bus must be\n * re-created to work again.\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","/**\n * Generates random ids of the form `XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX`\n * (seven groups of five alphanumeric characters) — used for auto-generated registrator\n * namespaces. Not cryptographically secure.\n */\nexport class IdGenerator {\n private static collection = 'ABCDEFGHIJKLMNOPQRSTUVWXTZ0123456789'.split('');\n\n /** Returns a fresh random id. */\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\n/**\n * Base class for synchronous commands executed via `PostboyService.exec`.\n *\n * An executor is a short-lived value object: construct it with the command arguments and\n * pass it to `exec`, which invokes the handler registered for the class's static `ID`\n * and returns its result synchronously. For asynchronous results use a\n * {@link PostboyCallbackMessage} instead.\n *\n * @example\n * ```ts\n * class GetDataExecutor extends PostboyExecutor<string> {\n * static readonly ID = 'app.get-data';\n * constructor(public key: string) {\n * super();\n * }\n * }\n *\n * postboy.exec(new ConnectExecutor(GetDataExecutor, (e) => store.get(e.key)));\n * const value: string = postboy.exec(new GetDataExecutor('foo'));\n * ```\n */\nexport abstract class PostboyExecutor<T> extends PostboyMessage {\n /**\n * Phantom marker existing only at the type level: it ties the class to its result type\n * `T` so `exec` can infer it. Erased at runtime — never assign to it.\n */\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 * Infrastructure message that registers a pub/sub message type on the bus.\n *\n * Executing it via `PostboyService.exec` binds the type's static `ID` to the given\n * subject: `sub()` and `once()` start returning its (piped) stream, and `fire()`\n * delivers into it. Re-registering the same `ID` logs a warning and overrides the\n * previous registration. The non-deprecated replacement for the `PostboyService.record*`\n * methods.\n *\n * @example\n * ```ts\n * postboy.exec(new ConnectMessage(PingMessage, new Subject<PingMessage>()));\n * // with a pipe — subscribers see the transformed stream\n * postboy.exec(new ConnectMessage(PingMessage, new Subject<PingMessage>(), (s) => s.pipe(share())));\n * ```\n */\nexport class ConnectMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {\n static readonly ID = 'aa03a192-bdc7-402d-9f2f-bf3748229ea2';\n\n /**\n * @param type - The constructor of the message type; must declare its own static `ID`.\n * @param sub - The subject the message type is served from.\n * @param pipe - Optional wrapper producing the observable subscribers receive, e.g. to apply operators.\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 * Infrastructure message that unregisters a message or executor type from the bus.\n *\n * Executing it via `PostboyService.exec` completes the registered stream (ending every\n * subscriber's subscription), runs the registered completion callbacks — in particular,\n * it completes the result of a fired callback message — and forgets the `ID`, so\n * further `fire`, `sub`, and `exec` for it throw until it is registered again. This is\n * the teardown primitive behind `PostboyAbstractRegistrator.down()`.\n */\nexport class DisconnectMessage extends PostboyExecutor<void> {\n static readonly ID = '94579e43-5bc9-4517-bcda-b595bcda1ae7';\n\n /**\n * @param messageId - The static `ID` of the message or executor type to remove — not an instance id.\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 * Infrastructure message that registers a synchronous handler for an executor type.\n *\n * Executing it via `PostboyService.exec` binds the type's static `ID` to the given\n * function: every subsequent `exec` of that executor type invokes it and returns its\n * result. Re-registering the same `ID` logs a warning and overrides the previous\n * registration. The non-deprecated replacement for `PostboyService.recordExecutor`.\n *\n * @template E - The executor type being registered.\n * @template T - The result its handler returns.\n */\nexport class ConnectExecutor<E extends PostboyExecutor<T>, T> extends PostboyExecutor<void> {\n static readonly ID = 'cb80e8ad-b68c-4b2d-8c44-617ea6017cb3';\n\n /**\n * @param type - The constructor of the executor class; must declare its own static `ID`.\n * @param exec - The handler invoked with the executor instance on every `exec` of this type.\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 * Infrastructure message that registers a {@link PostboyExecutionHandler} for an\n * executor type.\n *\n * Executing it via `PostboyService.exec` binds the executor class's static `ID` to the\n * handler: every subsequent `exec` of that type calls `handler.handle(...)` and returns\n * its result. Re-registering the same `ID` logs a warning and overrides the previous\n * registration. The non-deprecated replacement for `PostboyService.recordHandler`.\n *\n * @template E - The executor type being served.\n * @template R - The result its handler returns.\n */\nexport class ConnectHandler<E extends PostboyExecutor<R>, R> extends PostboyExecutor<void> {\n static readonly ID = 'bf618cea-6f32-417c-9548-8eafe937378b';\n\n /**\n * @param executor - The constructor of the executor class; must declare its own static `ID`.\n * @param handler - The handler whose `handle` method receives the executor.\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\n/**\n * Constructor signature of a message class.\n *\n * The bus identifies message types by the static `ID` such a constructor carries (see\n * {@link PostboyGenericMessage}), not by class identity — two different classes sharing\n * an `ID` collide on the same registration (the later one overrides the earlier one\n * with a warning).\n */\nexport type MessageType<T extends PostboyGenericMessage> = new (...args: any[]) => T;\n\n/**\n * Base class for feature registrators: registers messages and executors for one feature\n * and remembers every recorded `ID`, so that a single {@link down} disconnects them all.\n *\n * Subclasses make their `record*` calls inside the abstract {@link _up} hook; services\n * attached via {@link registerServices} share the same lifecycle. Create one registrator\n * per feature (or per namespace, via `AddNamespace`) and keep the instance to tear the\n * feature down later.\n *\n * @example\n * ```ts\n * class FeatureRegistrator extends PostboyAbstractRegistrator {\n * protected _up(): void {\n * this.recordSubject(PingMessage).recordExecutor(GetDataExecutor, (e) => e.payload);\n * }\n * }\n *\n * const reg = new FeatureRegistrator(postboy, 'feature-a');\n * reg.up(); // registrations are live\n * reg.down(); // everything recorded above is disconnected\n * ```\n */\nexport abstract class PostboyAbstractRegistrator {\n /**\n * Identifier of this registrator: the name passed to the constructor, or a generated\n * unique id when none was given. It identifies the registrator only — message routing\n * is not affected by it.\n */\n get namespace(): string {\n return this._namespace;\n }\n private ids: string[] = [];\n private services: IPostboyDependingService[] = [];\n private readonly _namespace: string;\n\n /**\n * @param postboy - The bus every `record*` call is executed on.\n * @param namespace - Optional name exposed by {@link namespace}; a random unique id is generated when omitted.\n */\n constructor(\n protected postboy: PostboyService,\n namespace: string | null = null,\n ) {\n this._namespace = namespace ?? IdGenerator.get();\n }\n\n /**\n * Sets the services that share this registrator's lifecycle: their `up()` runs on\n * {@link up} (after the registrations), their `down()` on {@link down} (before the\n * disconnection). Replaces any previously registered list.\n *\n * @param services - Services to attach to the lifecycle.\n */\n public registerServices(services: IPostboyDependingService[]): void {\n this.services = services;\n }\n\n /**\n * Activates the registrator: runs the {@link _up} registration hook, then calls `up()`\n * on every attached service.\n */\n public up(): void {\n this._up?.();\n this.services.forEach((s) => s.up());\n }\n\n /**\n * Registration hook executed by {@link up}. Subclasses make all their `record*` calls\n * here so that {@link down} can disconnect them.\n */\n protected abstract _up(): void;\n\n /**\n * Tears the registrator down, in order: calls `down()` on every attached service (then\n * clears the service list), then executes a `DisconnectMessage` for each recorded `ID`,\n * completing subscriber streams and removing handlers registered by this registrator.\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 * Registers a message type with the given subject and remembers its `ID` for {@link down}.\n *\n * @param type - The constructor of the message type; must declare its own static `ID`.\n * @param sub - The subject subscribers will observe.\n * @return This registrator, for 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 * Registers a message type whose stream is transformed by a pipe before reaching\n * subscribers, and remembers its `ID` for {@link down}.\n *\n * @param type - The constructor of the message type; must declare its own static `ID`.\n * @param sub - The subject subscribers will observe.\n * @param pipe - Wraps the subject into the observable handed out by `PostboyService.sub`, e.g. to apply operators.\n * @return This registrator, 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 * Registers a synchronous handler for an executor type and remembers its `ID` for {@link down}.\n *\n * @param type - The constructor of the executor class; must declare its own static `ID`.\n * @param exec - Called with the executor instance on every `PostboyService.exec` of this type.\n * @return This registrator, for chaining.\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 * Registers a {@link PostboyExecutionHandler} for an executor type and remembers its\n * `ID` for {@link down}. The handler's `handle` method is invoked on every\n * `PostboyService.exec` of this type.\n *\n * @param executor - The constructor of the executor class; must declare its own static `ID`.\n * @param handler - The handler instance receiving the executor.\n * @return This registrator, for chaining.\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 * Registers the type with a `ReplaySubject`: new subscribers first receive up to\n * `bufferSize` most recently fired messages, then live ones. Suited for\n * \"latest events\" streams where late subscribers need recent history.\n *\n * @param type - The constructor of the message type; must declare its own static `ID`.\n * @param bufferSize - How many past messages to replay to new subscribers; defaults to 1.\n * @return This registrator, for chaining.\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 * Registers the type with a `BehaviorSubject` seeded with `initial`: every new\n * subscriber immediately receives the most recent message — the seed itself until\n * anything is fired. Suited for state-like messages rather than one-off events.\n *\n * @param type - The constructor of the message type; must declare its own static `ID`.\n * @param initial - The message instance new subscribers receive before any `PostboyService.fire`.\n * @return This registrator, for chaining.\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 * Registers the type with a plain `Subject`: subscribers only see messages fired after\n * they subscribed. The default choice for event-like messages.\n *\n * @param type - The constructor of the message type; must declare its own static `ID`.\n * @return This registrator, for chaining.\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 * The concrete registrator created for each namespace by `PostboyNamespaceStore.addSpace`:\n * a plain {@link PostboyAbstractRegistrator} with no registration logic of its own —\n * everything is recorded on it through the public `record*` methods.\n */\nexport class NamespaceRegistrator extends PostboyAbstractRegistrator {\n constructor(postboy: PostboyService) {\n super(postboy);\n }\n\n /** No-op: namespaces record via the public `record*` methods, not in the `up()` hook. */\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 * The registry of namespaces behind `AddNamespace`/`EliminateNamespace`: maps each name\n * to the registrator managing its registrations.\n */\nexport class PostboyNamespaceStore {\n private spaces: Map<string, PostboyAbstractRegistrator> = new Map();\n\n /**\n * Returns the registrator of the given name, creating it on first use.\n *\n * @param space - The unique namespace name.\n * @param postboy - The bus the new registrator executes its registration messages on.\n * @return The registrator of the namespace — the existing one when the name is known.\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 * Tears the namespace down — `down()` on its registrator, disconnecting everything it\n * recorded — and removes it. Unknown names are ignored.\n *\n * @param space - The namespace name to remove.\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 /** Tears down every namespace and clears the store; called by `PostboyService.dispose()`. */\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\n/**\n * Assembles the internal collaborators of a `PostboyService`: its middleware pipeline,\n * message store, and namespace store. The default factories create fresh instances with\n * no shared state; substitute stubs (e.g. in tests) by passing a custom resolver to the\n * `PostboyService` constructor.\n */\nexport class PostboyDependencyResolver {\n /** Factory for the bus middleware pipeline — one fresh instance per call. */\n getMiddlewareService = () => new PostboyMiddlewareService();\n\n /** Factory for the message registry — one fresh instance per call. */\n getMessageStore = () => new PostboyMessageStore();\n\n /** Factory for the namespace registry — one fresh instance per call. */\n getNamespaceStore = () => new PostboyNamespaceStore();\n}\n","import { PostboyAbstractRegistrator } from '../postboy-abstract.registrator';\nimport { PostboyExecutor } from '../models/postboy-executor';\n\n/**\n * Infrastructure message that creates — or returns the existing — registrator of a\n * namespace.\n *\n * Executing it via `PostboyService.exec` registers the given name in the namespace\n * store and returns the {@link PostboyAbstractRegistrator} for it: record messages and\n * executors on that registrator, then tear them all down at once with\n * `EliminateNamespace` (or the registrator's own `down()`). Executing it again with the\n * same name returns the same registrator without recreating it.\n *\n * @example\n * ```ts\n * const reg = postboy.exec(new AddNamespace('feature-a'));\n * reg.recordSubject(PingMessage);\n * // later: postboy.exec(new EliminateNamespace('feature-a')); — disconnects everything recorded\n * ```\n */\nexport class AddNamespace extends PostboyExecutor<PostboyAbstractRegistrator> {\n static readonly ID = '6d1a6f7d-6b6e-4c4d-8af8-9cc9a32e850c';\n\n /**\n * @param space - The unique name of the namespace.\n */\n constructor(public space: string) {\n super();\n }\n}\n","import { PostboyExecutor } from '../models/postboy-executor';\n\n/**\n * Infrastructure message that tears down a namespace created by `AddNamespace`.\n *\n * Executing it via `PostboyService.exec` calls `down()` on the namespace's registrator —\n * disconnecting every message and executor it recorded — and removes the namespace.\n * Eliminating an unknown name changes nothing.\n */\nexport class EliminateNamespace extends PostboyExecutor<void> {\n static readonly ID = '03bb03bb-53e0-4b74-9aad-64d5c54a8972';\n\n /**\n * @param space - The name the namespace was created with.\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 * Infrastructure message that appends a {@link PostboyMiddleware} to the pipeline.\n *\n * Executing it via `PostboyService.exec` adds the middleware to the end of the chain:\n * hooks then run for every stage its `canHandle` accepts, in insertion order. Adding\n * the same instance twice makes its hooks run twice.\n *\n * @example\n * ```ts\n * postboy.exec(new AddMiddleware(new LoggingMiddleware()));\n * ```\n */\nexport class AddMiddleware extends PostboyExecutor<void> {\n static readonly ID = '0a8cfe0a-6193-4082-8440-d0793367b21d';\n\n /**\n * @param middleware - The middleware instance to append.\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 * Infrastructure message that removes a {@link PostboyMiddleware} from the pipeline.\n *\n * Executing it via `PostboyService.exec` drops the instance from the chain — matched by\n * identity, not by name or class — and calls its `dispose()` hook. Pass the very same\n * instance that was added via `AddMiddleware`.\n */\nexport class RemoveMiddleware extends PostboyExecutor<void> {\n static readonly ID = 'c25c708c-53c9-498d-a28b-936fbaf68b91';\n\n /**\n * @param middleware - The middleware instance previously added via `AddMiddleware`.\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 * Infrastructure message that locks a message type on the bus.\n *\n * Executing it via `PostboyService.exec` adds the type's static `ID` to the locked set:\n * subsequent `fire()` and `fireCallback()` calls for that type silently skip delivery —\n * subscribers receive nothing — while middleware `before`/`after` hooks still run and\n * `exec()` is unaffected. Registration stays intact, so unlocking resumes delivery\n * immediately. Treat a locked message as a no-op, not an error.\n *\n * @example\n * ```ts\n * postboy.exec(new LockMessage(PingMessage)); // PingMessage stops being delivered\n * postboy.exec(new UnlockMessage(PingMessage)); // delivery resumes\n * ```\n */\nexport class LockMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {\n static readonly ID = '477df3e2-1f99-4476-9a3b-afd1fa426436';\n\n /**\n * @param type - The constructor of the message type to lock.\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 * Infrastructure message that unlocks a message type locked by `LockMessage`.\n *\n * Executing it via `PostboyService.exec` removes the type's static `ID` from the locked\n * set, so `fire()` and `fireCallback()` deliver it again. Unlocking a type that was\n * never locked changes nothing.\n */\nexport class UnlockMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {\n static readonly ID = 'd71d25e3-90ac-4009-b972-9e6c6b05611e';\n\n /**\n * @param type - The constructor of the message type to unlock.\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\n/**\n * The central message bus of the postboy library.\n *\n * All routing is keyed by the static `ID` declared on message and executor classes —\n * not by class identity. Three kinds of traffic are supported:\n * - pub/sub: register a message type with a `ConnectMessage`, subscribe via {@link sub},\n * dispatch via {@link fire};\n * - synchronous commands: register a handler with a `ConnectExecutor`/`ConnectHandler`,\n * invoke it via {@link exec};\n * - async request/response: a {@link PostboyCallbackMessage} fired via {@link fireCallback}.\n *\n * Every bus mutation — registration, middleware, locking, namespaces — is performed by\n * executing one of the infrastructure messages via {@link exec}; the constructor wires\n * their handlers automatically.\n *\n * @example\n * ```ts\n * class PingMessage extends PostboyGenericMessage {\n * static readonly ID = 'app.ping';\n * constructor(public text: string) {\n * super();\n * }\n * }\n *\n * const postboy = new PostboyService();\n * postboy.exec(new ConnectMessage(PingMessage, new Subject<PingMessage>()));\n * postboy.sub(PingMessage).subscribe((m) => console.log(m.text));\n * postboy.fire(new PingMessage('hello'));\n * ```\n */\nexport class PostboyService {\n /** Ids of message types locked via `LockMessage`; {@link fire} and {@link fireCallback} skip their delivery. */\n protected locked = new Set<string>();\n private middleware: PostboyMiddlewareService;\n private store: PostboyMessageStore;\n private namespaceStore: PostboyNamespaceStore;\n private dependencyResolver: PostboyDependencyResolver;\n\n /**\n * Creates a bus and registers handlers for all infrastructure messages.\n *\n * @param resolver - Supplies the internal collaborators (middleware pipeline, message store, namespace store).\n * Defaults to a `PostboyDependencyResolver` with fresh instances; pass a custom one to inject test doubles.\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 /** Registers handlers for the infrastructure messages — the only way to mutate the bus. */\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 * Publishes a message to all current subscribers of its type.\n *\n * Runs the `Publish`-stage middleware `before` hooks, delivers the message to the\n * registered subject, then runs the `after` hooks. If the type is locked (see\n * `LockMessage`), delivery is silently skipped — subscribers receive nothing — but\n * both middleware hooks still run.\n *\n * @param message - The message instance to publish.\n * @throws CancelError When a `Publish`-stage middleware returns an interrupt decision.\n * @throws Error When no message of this type is registered; the `after` hooks are then skipped.\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 * Fires a {@link PostboyCallbackMessage} and returns an observable of its result (async request/response).\n *\n * The responder side subscribes to the message type via {@link sub} and produces the\n * result with `message.next(...)` / `message.finish(...)`.\n *\n * Dispatch semantics depend on `action`:\n * - with `action`, the message is dispatched immediately and `action` is invoked once\n * per emitted result value, independently of any subscriptions to the returned\n * observable;\n * - without `action`, dispatch is lazy: it happens on the first subscription to the\n * returned observable.\n *\n * `Callback`-stage middleware `before` hooks run at call time; `after` hooks run on\n * every emitted result value. If the type is locked, dispatch is silently skipped.\n * The result observable completes when the message type is disconnected\n * (see `DisconnectMessage`) or the bus is disposed.\n *\n * @param message - The callback message carrying the request.\n * @param action - Optional callback invoked once per emitted result value.\n * @return An observable emitting the result values produced by the responder.\n * @throws CancelError When a `Callback`-stage middleware returns an interrupt decision.\n * @throws Error When no message of this type is registered; thrown synchronously, before any dispatch.\n *\n * @example\n * ```ts\n * postboy.exec(new ConnectMessage(FetchDataMessage, new Subject<FetchDataMessage>()));\n * // responder: produces the result\n * postboy.sub(FetchDataMessage).subscribe((m) => m.finish('payload'));\n * // requester: consumes it\n * postboy.fireCallback(new FetchDataMessage()).subscribe((payload) => console.log(payload));\n * ```\n */\n public fireCallback<T>(message: PostboyCallbackMessage<T>, action?: (e: T) => void): Observable<T> {\n this.middleware.beforeCallback(message);\n this.store.callbackFired(message);\n if (action) message.result.subscribe(action);\n const msg = this.store.getMessage(message.id, message.constructor.name);\n const observable = new Observable<T>((subscriber) => {\n const subscription = message.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 * Synchronously executes a registered executor command and returns its result — never `await` it.\n *\n * Runs the `Execute`-stage middleware `before` hooks, invokes the handler registered\n * for the executor's static `ID`, then the `after` hooks with the result. For async\n * results use a {@link PostboyCallbackMessage} with {@link fireCallback} instead.\n *\n * This is also the entry point for the infrastructure messages themselves\n * (`ConnectMessage`, `AddMiddleware`, ...), so middleware sees them on the `Execute`\n * stage too — filter them out with `canHandle` if needed.\n *\n * @param executor - The executor instance carrying the command.\n * @return Whatever the registered handler returns.\n * @throws CancelError When an `Execute`-stage middleware returns an interrupt decision.\n * @throws Error When no handler is registered for this executor type.\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 * Returns the observable stream of a registered message type.\n *\n * Every call returns a view of the one registered subject — or of its pipe, when the\n * type was registered via `ConnectMessage` with a pipe. It is an `Observable`, not a\n * `Subject`: never call `next` on it, emit via {@link fire}. Subscribers only receive\n * messages fired after their subscription, unless the type was registered with a\n * replay or behavior subject.\n *\n * @param type - The constructor of the message type; must declare its own static `ID`.\n * @throws Error When the class has no static `ID` or no message of this type is registered.\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 * Like {@link sub}, but completes right after the first message of the type arrives.\n *\n * @param type - The constructor of the message type; must declare its own static `ID`.\n * @return An observable that emits one message and then completes.\n * @throws Error When the class has no static `ID` or no message of this type is registered.\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 message type with the given subject.\n *\n * Re-registering the same `ID` logs a warning and overrides the previous registration.\n *\n * @deprecated The method should be replaced with firing {@link ConnectMessage} message.\n * @param type - The constructor of the message type; must declare its own static `ID`.\n * @param sub - The subject subscribers will observe.\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 message type whose stream is transformed by a pipe before reaching subscribers.\n *\n * Re-registering the same `ID` logs a warning and overrides the previous registration.\n *\n * @deprecated The method should be replaced with firing {@link ConnectMessage} message.\n * @param type - The constructor of the message type; must declare its own static `ID`.\n * @param sub - The subject subscribers will observe.\n * @param pipe - Wraps the subject into the observable handed out by {@link sub}, e.g. to apply operators.\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 a synchronous handler for an executor type, invoked by {@link exec}.\n *\n * Re-registering the same `ID` logs a warning and overrides the previous registration.\n *\n * @deprecated The method should be replaced with firing {@link ConnectExecutor} message.\n * @param type - The constructor of the executor class; must declare its own static `ID`.\n * @param exec - Called with the executor instance on every {@link exec} of this type.\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 {@link PostboyExecutionHandler} instance for an executor type, invoked by {@link exec}.\n *\n * Re-registering the same `ID` logs a warning and overrides the previous registration.\n *\n * @deprecated The method should be replaced with firing {@link ConnectHandler} message.\n * @param executor - The constructor of the executor class; must declare its own static `ID`.\n * @param handler - Its `handle` method is called with the executor instance on every {@link exec} of this type.\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 * Tears down the whole bus: calls `down()` on every namespace registrator (completing\n * everything they registered), completes all remaining message subscriptions and\n * callback results, and disposes every middleware.\n *\n * Infrastructure registrations are re-created only by constructing a new service.\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 * Base class for custom middleware — the \"customs officers\" inspecting everything that\n * travels through the bus.\n *\n * A middleware joins the pipeline via `AddMiddleware` and leaves it via\n * `RemoveMiddleware`, which also calls {@link dispose}. For every operation the hooks\n * run per stage (`Publish` for `fire`, `Callback` for `fireCallback`, `Execute` for\n * `exec` — see {@link MiddlewareStage}): {@link canHandle} is consulted first, then\n * {@link before} ahead of the operation, then {@link after} once it has finished.\n * Hooks run for infrastructure messages too — filter with {@link canHandle} if needed.\n *\n * Put validation and gating into {@link before}: returning an interrupt decision there\n * cancels the operation with a {@link CancelError}. Put logging and other side effects\n * into {@link after}.\n *\n * @example\n * ```ts\n * class AuthMiddleware extends PostboyMiddleware {\n * canHandle(context: PipelineContext): boolean {\n * return context.stage === MiddlewareStage.Execute;\n * }\n *\n * before(context: PipelineContext): MiddlewareDecision {\n * return isAllowed(context.message)\n * ? { type: MiddlewareDecisionType.Continue }\n * : { type: MiddlewareDecisionType.Interrupt };\n * }\n * }\n *\n * postboy.exec(new AddMiddleware(new AuthMiddleware()));\n * ```\n */\nexport abstract class PostboyMiddleware {\n /** Identifies the middleware in {@link CancelError} details; defaults to the class name. */\n public readonly name: string;\n\n /**\n * @param name - Custom name reported on cancellation; defaults to the class name.\n */\n constructor(name?: string) {\n this.name = name ?? this.constructor.name;\n }\n\n /**\n * Decides whether this middleware participates for the given context. Override to\n * narrow the middleware by stage or message id. Default: handle everything.\n */\n public canHandle(_context: PipelineContext): boolean {\n return true;\n }\n\n /**\n * Runs ahead of the operation. Return an interrupt decision\n * ({@link MiddlewareDecisionType.Interrupt}) to cancel it: the bus then throws a\n * {@link CancelError}, and the operation and all `after` hooks are skipped.\n * Default: continue.\n */\n public before(_context: PipelineContext): MiddlewareDecision {\n return { type: MiddlewareDecisionType.Continue };\n }\n\n /**\n * Runs after the operation has finished successfully. `result` carries the executor's\n * return value on the `Execute` stage and is `undefined` on `Publish` and `Callback`.\n * Default: no-op.\n */\n public after(_context: PipelineContext, _result?: unknown): void {\n // noop\n }\n\n /** Cleanup hook called on `RemoveMiddleware` and on bus disposal. Default: no-op. */\n public dispose(): void {\n // noop\n }\n}\n","import { Observable, Subject } from 'rxjs';\nimport { PostboyGenericMessage } from './postboy-generic-message';\n\n/**\n * Base class for async request/response messages: the requester fires it via\n * `PostboyService.fireCallback`, a responder — subscribed to the message type — produces\n * the result through {@link next} or {@link finish}, and the requester observes the\n * values on {@link result}.\n *\n * Use a callback message when the result arrives asynchronously; for synchronous\n * results use a {@link PostboyExecutor} instead.\n *\n * @example\n * ```ts\n * class FetchDataMessage extends PostboyCallbackMessage<string> {\n * static readonly ID = 'app.fetch-data';\n * }\n *\n * // responder: produces the result\n * postboy.sub(FetchDataMessage).subscribe((m) => m.finish('payload'));\n * // requester: consumes it\n * postboy.fireCallback(new FetchDataMessage()).subscribe((payload) => console.log(payload));\n * ```\n */\nexport abstract class PostboyCallbackMessage<T> extends PostboyGenericMessage {\n /** The subject backing {@link result}; protected so only subclass/responder code can emit. */\n protected result$ = new Subject<T>();\n\n /** The observable of result values; completed by {@link finish}, {@link complete}, or a `DisconnectMessage`. */\n public result: Observable<T> = this.result$.asObservable();\n\n /**\n * Emits an intermediate result value to every {@link result} subscriber without\n * completing the stream — for operations that produce several values.\n *\n * @param value - The value to emit.\n */\n public next = (value: T): void => this.result$.next(value);\n\n /**\n * Emits the final result value and completes {@link result}.\n *\n * @param value - The last value to emit.\n */\n public finish(value: T): void {\n this.result$.next(value);\n this.result$.complete();\n }\n\n /** Completes {@link result} without emitting another value. */\n public complete(): void {\n this.result$.complete();\n }\n}\n","import { PostboyExecutor } from './postboy-executor';\n\n/**\n * Base class for class-based executor handlers — the object-oriented alternative to the\n * `(e) => result` function accepted by `ConnectExecutor`.\n *\n * Register an instance with `ConnectHandler` (or `PostboyAbstractRegistrator.recordHandler`);\n * {@link handle} is then invoked on every `PostboyService.exec` of the executor type.\n *\n * @template R - Result type returned by {@link handle}.\n * @template E - The executor type this handler serves.\n */\nexport abstract class PostboyExecutionHandler<R, E extends PostboyExecutor<R>> {\n /**\n * Processes an executor command and returns its result synchronously.\n *\n * @param executor - The executor instance passed to `PostboyService.exec`.\n * @return The result handed back to the caller of `exec`.\n */\n abstract handle(executor: E): R;\n}\n"]}