@artstesh/postboy 3.4.0 → 3.4.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/lib/index.d.mts CHANGED
@@ -1,701 +1,705 @@
1
1
  import { Subject, Observable } from 'rxjs';
2
2
 
3
- /**
4
- * Represents metadata associated with a Postboy message.
5
- *
6
- * This interface can be used to store optional metadata that provides
7
- * additional context or tracking information for a message. It supports
8
- * flexible extension by allowing additional properties through an index signature.
9
- *
10
- * Properties:
11
- * - `correlationId` (optional): A unique identifier used to correlate
12
- * related messages or operations across systems.
13
- * - `causationId` (optional): The identifier of the preceding message
14
- * or event that caused the current message to be produced.
15
- * - `source` (optional): The origin or source of the message, such as
16
- * a particular service or system.
17
- * - `tags` (optional): An array of tags or labels that can be attached
18
- * to the message for categorization, filtering, or logging purposes.
19
- * - `[key: string]` (optional): Additional custom properties can be
20
- * added to capture specific metadata not covered by the predefined fields.
21
- */
22
- interface PostboyMessageMetadata {
23
- correlationId?: string;
24
- causationId?: string;
25
- tags?: Set<string>;
26
- [key: string]: any;
27
- }
28
-
29
- declare abstract class PostboyMessage {
30
- metadata: PostboyMessageMetadata;
31
- get id(): string;
32
- setMetadata(metadata: Partial<PostboyMessageMetadata>): this;
33
- }
34
-
35
- /**
36
- * An inheritor should have a static ID field
37
- */
38
- declare abstract class PostboyGenericMessage extends PostboyMessage {
39
- }
40
- declare function checkId(message: new (...args: any[]) => any): string;
41
-
42
- declare abstract class PostboyExecutor<T> extends PostboyMessage {
43
- protected readonly _postboyResultType?: T;
44
- }
45
-
46
- /**
47
- * An abstract class extending PostboyGenericMessage that provides mechanisms for managing
48
- * asynchronous data communication using RxJS observables. It is designed to work with
49
- * callback-based operations that emit a result of type T.
50
- *
51
- * @template T - The type of the data emitted by the observables in this class.
52
- *
53
- * @extends PostboyGenericMessage
54
- *
55
- * @property {Observable<T>} result - An observable that emits the result of the operation
56
- * and completes once the operation is finished.
57
- *
58
- * @method next - Emits the next value for the result observable.
59
- * @param {T} value - The value to be emitted by the result observable.
60
- *
61
- * @method finish - Emits the final value for the result observable and completes it.
62
- * @param {T} value - The final value for the observable emission.
63
- */
64
- declare abstract class PostboyCallbackMessage<T> extends PostboyGenericMessage {
65
- protected result$: Subject<T>;
66
- result: Observable<T>;
67
- /**
68
- * Emits the provided value.
69
- *
70
- * @template T - The type of the value to emit.
71
- * @param {T} value - The value to emit through the `result$` observable.
72
- * @returns {void}
73
- */
74
- next: (value: T) => void;
75
- /**
76
- * Marks the operation as complete by emitting the provided value and then completing the result stream.
77
- *
78
- * @param {T} value - The value to emit prior to completing the result stream.
79
- * @return {void} This method does not return a value.
80
- */
81
- finish(value: T): void;
82
- /**
83
- * Completes the current observable result stream.
84
- * This method marks the result observable as complete, ensuring no further values
85
- * or events will be emitted from it.
86
- *
87
- * @return {void} No value is returned from this method.
88
- */
89
- complete(): void;
90
- }
91
-
92
- interface IPostboyDependingService {
93
- up(): void;
94
- down?: () => void;
95
- }
96
-
97
- /**
98
- * Abstract class representing a handler for executing a Postboy task.
99
- *
100
- * This class is intended to manage the execution flow of a PostboyExecutor instance.
101
- * Subclasses must implement the `handle` method, which executes a given PostboyExecutor
102
- * and returns a result of type R.
103
- *
104
- * @template R The type of the result returned by the `handle` method.
105
- * @template E The type of the executor extending the PostboyExecutor.
106
- */
107
- declare abstract class PostboyExecutionHandler<R, E extends PostboyExecutor<R>> {
108
- /**
109
- * Abstract method to handle the specified executor and return a result.
110
- *
111
- * @param {E} executor - The executor that will be processed by the method.
112
- * @return {R} The result obtained after handling the executor.
113
- */
114
- abstract handle(executor: E): R;
115
- }
116
-
117
- type MessageType<T extends PostboyGenericMessage> = new (...args: any[]) => T;
118
- declare abstract class PostboyAbstractRegistrator {
119
- protected postboy: PostboyService;
120
- get namespace(): string;
121
- private ids;
122
- private services;
123
- private readonly _namespace;
124
- constructor(postboy: PostboyService, namespace?: string | null);
125
- /**
126
- * Registers a list of services to be used by the application.
127
- *
128
- * @param {IPostboyDependingService[]} services - An array of services to register.
129
- * @return {void} This method does not return a value.
130
- */
131
- registerServices(services: IPostboyDependingService[]): void;
132
- /**
133
- * Initiates the 'up' process for the current instance and all associated services.
134
- *
135
- * @return {void} Does not return a value.
136
- */
137
- up(): void;
138
- protected abstract _up(): void;
139
- down(): void;
140
- /**
141
- * Records a type and its corresponding Subject<T> into the Postboy system and updates the internal identifiers.
142
- *
143
- * @param {MessageType<T>} type - A constructor for the generic message type T.
144
- * @param {Subject<T>} sub - The subject associated with the generic message type.
145
- * @return {this} Returns the current instance for method chaining.
146
- */
147
- record<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>): PostboyAbstractRegistrator;
148
- /**
149
- * Records a message type with a specific subject and applies a transformation pipe to the subject.
150
- *
151
- * @param {MessageType<T>} type - The constructor of the message type to record, which extends PostboyGenericMessage.
152
- * @param {Subject<T>} sub - The Subject instance to associate with the message type.
153
- * @param {(s: Subject<T>) => Observable<T>} pipe - A function that takes the subject as input and returns an Observable with transformations applied.
154
- * @return {this} The current instance of the class for chaining.
155
- */
156
- recordWithPipe<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>, pipe: (s: Subject<T>) => Observable<T>): PostboyAbstractRegistrator;
157
- /**
158
- * Records an executor associated with a specific type and execution logic.
159
- *
160
- * @param type The class constructor of the executor type to be recorded, which extends PostboyExecutor.
161
- * @param exec A callback function that executes the logic using an instance of the specified executor type.
162
- * @return void
163
- */
164
- recordExecutor<E extends PostboyExecutor<T>, T>(type: new (...args: any[]) => E, exec: (e: E) => T): PostboyAbstractRegistrator;
165
- /**
166
- * Records a handler for a specific executor type.
167
- *
168
- * @param executor The constructor of the executor type, which extends `PostboyExecutor`.
169
- * @param handler The execution handler associated with the given executor type.
170
- * @return void
171
- */
172
- recordHandler<E extends PostboyExecutor<R>, R>(executor: new (...args: any[]) => E, handler: PostboyExecutionHandler<R, E>): PostboyAbstractRegistrator;
173
- /**
174
- * A utility function that facilitates the recording and replaying of messages
175
- * using a ReplaySubject. This function is designed to handle messages of a
176
- * specific type and allows specifying a buffer size to determine how many
177
- * of the most recent messages should be replayed.
178
- *
179
- * @template T Extends the PostboyGenericMessage type, representing the type of message
180
- * to be recorded and replayed.
181
- * @param {MessageType<T>} type The constructor of the message type to be recorded and replayed.
182
- * @param {number} [bufferSize=1] The number of recent messages to retain in the ReplaySubject's buffer.
183
- * Defaults to 1 if not specified.
184
- * @returns The result of invoking the `record` method with the given message type and configured ReplaySubject.
185
- */
186
- recordReplay<T extends PostboyGenericMessage>(type: MessageType<T>, bufferSize?: number): PostboyAbstractRegistrator;
187
- /**
188
- * Represents a method that records a specific behavior associated with a message type.
189
- * It creates a `BehaviorSubject` initialized with the provided initial message
190
- * and associates it with the given message type using the `record` method.
191
- *
192
- * @template T - A type parameter extending `PostboyGenericMessage` that defines the message structure.
193
- * @param {MessageType<T>} type - The constructor function of the message type to be recorded.
194
- * @param {T} initial - The initial value of the message that will be set in the `BehaviorSubject`.
195
- * @returns {void} - This function does not return a value; instead, it modifies the internal state.
196
- */
197
- recordBehavior<T extends PostboyGenericMessage>(type: MessageType<T>, initial: T): PostboyAbstractRegistrator;
198
- /**
199
- * A function that creates and returns a new generic message recorder for a specific message type.
200
- *
201
- * @template T - A type parameter extending from `PostboyGenericMessage`.
202
- * @param {MessageType<T>} type - The constructor for the message type being recorded.
203
- * @returns {Subject<T>} A new instance of `Subject<T>` bound to the specified message type.
204
- */
205
- recordSubject<T extends PostboyGenericMessage>(type: MessageType<T>): this;
206
- }
207
-
208
- interface PostboyMiddleware {
209
- handle(message: PostboyMessage): void;
210
- }
211
-
212
- /**
213
- * A service class that manages middleware functions for processing PostboyMessage objects.
214
- * It provides methods to add, remove, and execute middlewares in sequence.
215
- */
216
- declare class PostboyMiddlewareService {
217
- protected middlewares: PostboyMiddleware[];
218
- /**
219
- * Adds a middleware function to the collection of middlewares.
220
- *
221
- * @param {PostboyMiddleware} middleware - The middleware function to be added.
222
- * @return {void}
223
- */
224
- addMiddleware(middleware: PostboyMiddleware): void;
225
- /**
226
- * Removes a middleware from the list of registered middlewares.
227
- *
228
- * @param {PostboyMiddleware} middleware - The middleware instance to be removed.
229
- * @return {void} No return value.
230
- */
231
- removeMiddleware(middleware: PostboyMiddleware): void;
232
- /**
233
- * Manages the processing of a PostboyMessage by sequentially applying all middlewares.
234
- *
235
- * @param {PostboyMessage} msg - The message object to be processed by the middlewares.
236
- * @return {void} - This method does not return any value.
237
- */
238
- manage(msg: PostboyMessage): void;
239
- /**
240
- * Disposes of the current object by clearing its middlewares array.
241
- *
242
- * @return {void} This method does not return a value.
243
- */
244
- dispose(): void;
245
- }
246
-
247
- /**
248
- * A class that manages a reactive subscription using a provided Subject and transformation pipe.
249
- * Offers methods to interact with the subscription, such as emitting data, completing the subscription,
250
- * and accessing the transformed observable.
251
- *
252
- * @template T The type of data managed by the subscription.
253
- */
254
- declare class PostboySubscription<T> {
255
- private subscription;
256
- private readonly _subscription;
257
- /**
258
- * Constructs an instance of the class with a given subscription and a transformation pipe.
259
- *
260
- * @param {Subject<T>} subscription - The source Subject that will be transformed.
261
- * @param {(s: Subject<T>) => Observable<T>} pipe - A function that applies a transformation to the subscription.
262
- */
263
- constructor(subscription: Subject<T>, pipe?: (s: Subject<T>) => Observable<T>);
264
- /**
265
- * Returns an observable subscription.
266
- *
267
- * @return {Observable<T>} An observable instance of type T.
268
- */
269
- sub(): Observable<T>;
270
- /**
271
- * Triggers an event by emitting the provided data to all subscribers.
272
- *
273
- * @param {T} data - The data to emit to the subscribers.
274
- * @return {void} - Does not return any value.
275
- */
276
- fire(data: T): void;
277
- /**
278
- * Completes the subscription, signaling that no further values will be sent.
279
- * This is typically used to finalize or clean up resources.
280
- * @return {void} This method does not return any value.
281
- */
282
- finish(): void;
283
- }
284
-
285
- /**
286
- * The PostboyMessageStore is a utility class for managing message subscriptions and executors.
287
- * It provides functionality to register, retrieve, and unregister subscription-based messages and executors.
288
- */
289
- declare class PostboyMessageStore {
290
- protected messages: Map<string, PostboySubscription<any>>;
291
- protected executors: Map<string, (e: PostboyExecutor<any>) => any>;
292
- protected callbacks: Map<string, (() => void)[]>;
293
- registerMessage(id: string, sub: PostboySubscription<any>): void;
294
- registerExecutor(id: string, executor: (e: PostboyExecutor<any>) => any): void;
295
- callbackFired(message: PostboyCallbackMessage<any>): void;
296
- getMessage(id: string, name: string): PostboySubscription<any>;
297
- getExecutor<T>(id: string): (e: PostboyExecutor<T>) => T;
298
- unregister(id: string): void;
299
- dispose(): void;
300
- }
301
-
302
- /**
303
- * Represents a store for managing namespaces in the Postboy system.
304
- * Provides functionality to add, eliminate, and dispose namespaces.
305
- */
306
- declare class PostboyNamespaceStore {
307
- private spaces;
308
- /**
309
- * Adds a new space or retrieves an existing one if it already exists.
310
- *
311
- * @param {string} space - The name of the space to add or retrieve.
312
- * @param {PostboyService} postboy - The PostboyService instance used to create a namespace registrator.
313
- * @return {PostboyAbstractRegistrator} The registrator associated with the specified space.
314
- */
315
- addSpace(space: string, postboy: PostboyService): PostboyAbstractRegistrator;
316
- /**
317
- * Removes a specified space from the spaces collection if it exists.
318
- * If the space exists, it will be deleted after invoking its down method.
319
- *
320
- * @param {string} space - The name of the space to be removed.
321
- * @return {void} This method does not return a value.
322
- */
323
- eliminateSpace(space: string): void;
324
- /**
325
- * Disposes of the current instance by performing cleanup operations.
326
- * Iterates through all spaces, performs a "down" operation on each,
327
- * and then clears the collection of spaces.
328
- *
329
- * @return {void} No return value.
330
- */
331
- dispose(): void;
332
- }
333
-
334
- declare class PostboyDependencyResolver {
335
- /**
336
- * Retrieves an instance of the PostboyMiddlewareService.
337
- *
338
- * This function initializes and returns a new instance of the
339
- * PostboyMiddlewareService, which can be used to configure and manage
340
- * middleware for a specific module or application.
341
- *
342
- * @returns {PostboyMiddlewareService} A new instance of PostboyMiddlewareService.
343
- */
344
- getMiddlewareService: () => PostboyMiddlewareService;
345
- /**
346
- * A function that instantiates and returns a new instance of PostboyMessageStore.
347
- *
348
- * This function serves as a factory method for creating instances
349
- * of the PostboyMessageStore class.
350
- *
351
- * @returns {PostboyMessageStore} A new instance of the PostboyMessageStore class.
352
- */
353
- getMessageStore: () => PostboyMessageStore;
354
- /**
355
- * Creates and initializes a new instance of PostboyNamespaceStore using the provided PostboyService instance.
356
- *
357
- * @function getNamespaceStore
358
- * @returns {PostboyNamespaceStore} A new instance of PostboyNamespaceStore associated with the given PostboyService.
359
- */
360
- getNamespaceStore: () => PostboyNamespaceStore;
361
- }
362
-
363
- declare class PostboyService {
364
- protected locked: Set<string>;
365
- private middleware;
366
- private store;
367
- private namespaceStore;
368
- private dependencyResolver;
369
- constructor(resolver?: PostboyDependencyResolver);
370
- private registerInfrastructureMessages;
371
- /**
372
- * Locks a specific message type to prevent further modifications or actions.
373
- *
374
- * @deprecated The method should be replaced with firing {@link LockMessage} message.
375
- * @param {MessageType<T>} type - The message type to be locked. It must extend from the `PostboyGenericMessage`.
376
- * @return {void} This method does not return a value.
377
- */
378
- lock<T extends PostboyGenericMessage>(type: MessageType<T>): void;
379
- /**
380
- * Unlocks a previously locked message type by removing its ID from the locked set.
381
- *
382
- * @deprecated The method should be replaced with firing {@link UnlockMessage} message.
383
- * @param {MessageType<T>} type - The message type to unlock, which is a generic type extending PostboyGenericMessage.
384
- * @return {void} This method does not return any value.
385
- */
386
- unlock<T extends PostboyGenericMessage>(type: MessageType<T>): void;
387
- /**
388
- * Adds a middleware to the middleware stack.
389
- *
390
- * @deprecated The method should be replaced with firing {@link AddMiddleware} message.
391
- * @param {PostboyMiddleware} middleware - The middleware instance to be added.
392
- * @return {void}
393
- */
394
- addMiddleware(middleware: PostboyMiddleware): void;
395
- /**
396
- * Removes a middleware from the current middleware stack.
397
- *
398
- * @deprecated The method should be replaced with firing {@link RemoveMiddleware} message.
399
- * @param {PostboyMiddleware} middleware - The middleware instance to be removed.
400
- * @return {void} No return value.
401
- */
402
- removeMiddleware(middleware: PostboyMiddleware): void;
403
- /**
404
- * Unregisters a message identified by the given ID from the store.
405
- *
406
- * @deprecated The method should be replaced with firing {@link DisconnectMessage} message.
407
- * @param {string} id - The unique identifier of the item to unregister.
408
- * @return {void} No value is returned.
409
- */
410
- unregister(id: string): void;
411
- /**
412
- * Fires a registered event and passes the message to its subscribers.
413
- *
414
- * @param {PostboyGenericMessage} message - The message object containing the event data.
415
- * @return {void} This method does not return a value.
416
- * @throws {Error} Throws an error if no registered event is found for the provided message ID.
417
- */
418
- fire(message: PostboyGenericMessage): void;
419
- /**
420
- * Triggers a callback function associated with a given message.
421
- *
422
- * @param {PostboyCallbackMessage<T>} message - The message object used to trigger the callback.
423
- * It contains details about the event and result subscription.
424
- * @param {(e: T) => void} [action] - Optional callback function to execute when the result of the message is emitted.
425
- * @return {void} This method does not return any value.
426
- */
427
- fireCallback<T>(message: PostboyCallbackMessage<T>, action?: (e: T) => void): Observable<T>;
428
- /**
429
- * Executes the provided executor function and returns its result.
430
- *
431
- * @param {PostboyExecutor<T>} executor The executor to be executed, which includes its identifier and logic.
432
- * @return {T} The resulting output from the executed executor function.
433
- * @throws {Error} If the specified executor is not registered.
434
- */
435
- exec<T>(executor: PostboyExecutor<T>): T;
436
- /**
437
- * Subscribes to a specific message type and returns an observable of that type.
438
- *
439
- * @param type The constructor function of the type that extends PostboyGenericMessage.
440
- * @return An Observable of the specified generic message type.
441
- */
442
- sub<T extends PostboyGenericMessage>(type: MessageType<T>): Observable<T>;
443
- /**
444
- * Subscribes to a specific message type and automatically unsubscribes after receiving the first message.
445
- *
446
- * @param type The type of message to subscribe to.
447
- * @return An observable that emits the first message of the specified type and then completes.
448
- */
449
- once<T extends PostboyGenericMessage>(type: MessageType<T>): Observable<T>;
450
- /**
451
- * Registers a given message type and its associated subject subscription with the system.
452
- *
453
- * @deprecated The method should be replaced with firing {@link ConnectMessage} message.
454
- * @param type The constructor function of the message type that extends the PostboyGenericMessage.
455
- * @param sub The Subject instance for the provided message type, used for managing subscriptions.
456
- * @return {void} No return value.
457
- */
458
- record<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>): void;
459
- /**
460
- * Registers a generic message type with a Subject and a transformation pipe.
461
- *
462
- * @deprecated The method should be replaced with firing {@link ConnectMessage} message.
463
- * @param {MessageType<T>} type - The constructor of the message type being registered.
464
- * @param {Subject<T>} sub - The Subject instance used to handle incoming messages of the specified type.
465
- * @param {(s: Subject<T>) => Observable<T>} pipe - A function that applies a transformation or processing logic to the Subject and returns an Observable.
466
- * @return {void} No return value.
467
- */
468
- recordWithPipe<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>, pipe: (s: Subject<T>) => Observable<T>): void;
469
- /**
470
- * Registers an executor for a specified message type.
471
- *
472
- * @deprecated The method should be replaced with firing {@link ConnectExecutor} message.
473
- * @param {MessageType<E>} type - The message type for which the executor is being registered.
474
- * @param {(e: E) => T} exec - The executor function that will handle messages of the specified type.
475
- * @return {void} This method does not return any value.
476
- */
477
- recordExecutor<E extends PostboyExecutor<T>, T>(type: MessageType<E>, exec: (e: E) => T): void;
478
- /**
479
- * Registers a handler for a specific executor type.
480
- *
481
- * @deprecated The method should be replaced with firing {@link ConnectHandler} message.
482
- * @param executor The constructor of the executor class that extends `PostboyExecutor<R>`.
483
- * @param handler An instance of `PostboyExecutionHandler<R, E>` that defines the logic for handling the executor.
484
- * @return void
485
- */
486
- recordHandler<E extends PostboyExecutor<R>, R>(executor: new (...args: any[]) => E, handler: PostboyExecutionHandler<R, E>): void;
487
- /**
488
- * Adds a namespace to the namespace store.
489
- *
490
- * @deprecated The method should be replaced with firing {@link AddNamespace} message.
491
- * @param {string} space - The name of the namespace to be added.
492
- * @return {PostboyAbstractRegistrator} The instance of the namespace after adding the specified namespace.
493
- */
494
- addNamespace(space: string): PostboyAbstractRegistrator;
495
- /**
496
- * Removes the specified namespace from the namespace store.
497
- *
498
- * @deprecated The method should be replaced with firing {@link EliminateNamespace} message.
499
- * @param {string} space - The name of the namespace to be removed.
500
- * @return {void} This method does not return a value.
501
- */
502
- eliminateNamespace(space: string): void;
503
- /**
504
- * Disposes of resources and cleans up any internal components or stores associated with the instance.
505
- * This method ensures that all resources are properly released to avoid memory leaks.
506
- *
507
- * @return {void} This method does not return a value.
508
- */
509
- dispose(): void;
510
- }
511
-
512
- /**
513
- * Represents a {@link PostboyMiddleware} addition operation for Postboy.
514
- * This class extends the functionality of the PostboyExecutor to add middleware to the processing chain.
515
- *
516
- * The middleware to be added is provided during instantiation.
517
- */
518
- declare class AddMiddleware extends PostboyExecutor<void> {
519
- middleware: PostboyMiddleware;
520
- static readonly ID = "0a8cfe0a-6193-4082-8440-d0793367b21d";
521
- /**
522
- * Initializes a new instance of the class with the specified middleware.
523
- *
524
- * @param {PostboyMiddleware} middleware - The {@link PostboyMiddleware} to be used for processing.
525
- */
526
- constructor(middleware: PostboyMiddleware);
527
- }
528
-
529
- /**
530
- * Represents a class responsible for removing {@link PostboyMiddleware} in execution flow.
531
- * This class extends PostboyExecutor and operates with a void return type.
532
- */
533
- declare class RemoveMiddleware extends PostboyExecutor<void> {
534
- middleware: PostboyMiddleware;
535
- static readonly ID = "c25c708c-53c9-498d-a28b-936fbaf68b91";
536
- /**
537
- * Constructs an instance of the class with the specified middleware.
538
- *
539
- * @param {PostboyMiddleware} middleware - The {@link PostboyMiddleware} instance to be removed.
540
- */
541
- constructor(middleware: PostboyMiddleware);
542
- }
543
-
544
- /**
545
- * Locks a specific message type to prevent firing of them.
546
- *
547
- * This class is used to handle operations associated with locking mechanisms
548
- * for a specified message type.
549
- *
550
- * @template T - A type that extends {@link PostboyGenericMessage}.
551
- */
552
- declare class LockMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {
553
- type: MessageType<T>;
554
- static readonly ID = "477df3e2-1f99-4476-9a3b-afd1fa426436";
555
- /**
556
- * Constructs an instance of the class with the specified message type.
557
- *
558
- * @param {MessageType<T>} type - The type of the message to be used for the instance.
559
- */
560
- constructor(type: MessageType<T>);
561
- }
562
-
563
- /**
564
- * A specialized executor that handles the unlocking process for messages of a specified type.
565
- * Unlocks a previously locked message, making it available for processing again.
566
- *
567
- * @template T - The type parameter extending {@link PostboyGenericMessage}, representing the message type handled by the executor.
568
- * @extends {PostboyExecutor<void>}
569
- */
570
- declare class UnlockMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {
571
- type: MessageType<T>;
572
- static readonly ID = "d71d25e3-90ac-4009-b972-9e6c6b05611e";
573
- /**
574
- * Creates an instance of the class with the specified message type.
575
- *
576
- * @param {MessageType<T>} type - The message type for this instance.
577
- */
578
- constructor(type: MessageType<T>);
579
- }
580
-
581
- /**
582
- * AddNamespace is a class that extends the PostboyExecutor with a specific implementation
583
- * for adding namespaces to a PostboyService instance.
584
- *
585
- * This class is identified uniquely by its static ID property for tracking and referencing purposes.
586
- */
587
- declare class AddNamespace extends PostboyExecutor<PostboyAbstractRegistrator> {
588
- space: string;
589
- static readonly ID = "6d1a6f7d-6b6e-4c4d-8af8-9cc9a32e850c";
590
- /**
591
- * Creates an instance of the class with the specified space identifier.
592
- *
593
- * @param {string} space - The identifier for the space.
594
- */
595
- constructor(space: string);
596
- }
597
-
598
- /**
599
- * Represents an executor that eliminates a specific namespace.
600
- * This class extends the PostboyExecutor with a void return type.
601
- */
602
- declare class EliminateNamespace extends PostboyExecutor<void> {
603
- space: string;
604
- static readonly ID = "03bb03bb-53e0-4b74-9aad-64d5c54a8972";
605
- /**
606
- * Creates an instance of the class with the specified space value.
607
- *
608
- * @param {string} space - The string value representing the space configuration.
609
- */
610
- constructor(space: string);
611
- }
612
-
613
- /**
614
- * Represents a connection handler that extends the PostboyExecutor class.
615
- *
616
- * This class encapsulates logic associated with executing a handler in a structured way.
617
- * It is generic and operates on the provided executor and handler types.
618
- *
619
- * Type Parameters:
620
- * E - Represents an extension of the PostboyExecutor class with a specific type parameter R.
621
- * R - Represents the type of the result that the executor is expected to operate on.
622
- */
623
- declare class ConnectHandler<E extends PostboyExecutor<R>, R> extends PostboyExecutor<void> {
624
- executor: new (...args: any[]) => E;
625
- handler: PostboyExecutionHandler<R, E>;
626
- static readonly ID = "bf618cea-6f32-417c-9548-8eafe937378b";
627
- /**
628
- * Constructs an instance of the class.
629
- *
630
- * @param {new (...args: any[]) => E} executor - A constructor function for the executor object.
631
- * @param {PostboyExecutionHandler<R, E>} handler - A handler that processes the execution logic.
632
- */
633
- constructor(executor: new (...args: any[]) => E, handler: PostboyExecutionHandler<R, E>);
634
- }
635
-
636
- /**
637
- * Registers an executor that connects to a specific type of message handler.
638
- * This class extends the functionality of `PostboyExecutor` and is designed to manage
639
- * the execution of a handler defined by a specific message type and an execution function.
640
- *
641
- * @template E The type of the executor extending {@link PostboyExecutor}.
642
- * @template T The return type of the execution function.
643
- *
644
- * @extends {PostboyExecutor<void>}
645
- */
646
- declare class ConnectExecutor<E extends PostboyExecutor<T>, T> extends PostboyExecutor<void> {
647
- type: MessageType<E>;
648
- exec: (e: E) => T;
649
- static readonly ID = "cb80e8ad-b68c-4b2d-8c44-617ea6017cb3";
650
- /**
651
- * Constructs an instance of the class with the specified type and execution function.
652
- *
653
- * @param {MessageType<E>} type - The type of the message.
654
- * @param {(e: E) => T} exec - The function to be executed with the input of type E that returns a value of type T.
655
- */
656
- constructor(type: MessageType<E>, exec: (e: E) => T);
657
- }
658
-
659
- /**
660
- * Represents a message signaling a disconnection event. This class is used
661
- * within the framework to manage and process disconnection notifications.
662
- * Extends the {@link PostboyExecutor} base class.
663
- *
664
- * @extends {PostboyExecutor<void>}
665
- */
666
- declare class DisconnectMessage extends PostboyExecutor<void> {
667
- messageId: string;
668
- static readonly ID = "94579e43-5bc9-4517-bcda-b595bcda1ae7";
669
- /**
670
- * Creates an instance of the class with the specified message identifier.
671
- *
672
- * @param {string} messageId - The unique identifier for the message.
673
- */
674
- constructor(messageId: string);
675
- }
676
-
677
- /**
678
- * Represents a message that facilitates connection functionality
679
- * within the application's messaging system.
680
- *
681
- * @template T - A type that extends {@link PostboyGenericMessage}, representing
682
- * the structure of the message being handled.
683
- *
684
- * @extends PostboyExecutor<void>
685
- */
686
- declare class ConnectMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {
687
- type: MessageType<T>;
688
- sub: Subject<T>;
689
- pipe?: ((s: Subject<T>) => Observable<T>) | undefined;
690
- static readonly ID = "aa03a192-bdc7-402d-9f2f-bf3748229ea2";
691
- /**
692
- * Constructs a new instance of the class.
693
- *
694
- * @param {MessageType<T>} type - The type of the message.
695
- * @param {Subject<T>} sub - The subject to be used for message handling.
696
- * @param {(s: Subject<T>) => Observable<T>} [pipe] - An optional function to transform the subject.
697
- */
698
- constructor(type: MessageType<T>, sub: Subject<T>, pipe?: ((s: Subject<T>) => Observable<T>) | undefined);
699
- }
700
-
701
- export { AddMiddleware, AddNamespace, ConnectExecutor, ConnectHandler, ConnectMessage, DisconnectMessage, EliminateNamespace, type IPostboyDependingService, LockMessage, type MessageType, PostboyAbstractRegistrator, PostboyCallbackMessage, PostboyExecutionHandler, PostboyExecutor, PostboyGenericMessage, PostboyMessage, PostboyMessageStore, type PostboyMiddleware, PostboyMiddlewareService, PostboyService, RemoveMiddleware, UnlockMessage, checkId };
3
+ /**
4
+ * Represents metadata associated with a Postboy message.
5
+ *
6
+ * This interface can be used to store optional metadata that provides
7
+ * additional context or tracking information for a message. It supports
8
+ * flexible extension by allowing additional properties through an index signature.
9
+ *
10
+ * Properties:
11
+ * - `correlationId` (optional): A unique identifier used to correlate
12
+ * related messages or operations across systems.
13
+ * - `causationId` (optional): The identifier of the preceding message
14
+ * or event that caused the current message to be produced.
15
+ * - `source` (optional): The origin or source of the message, such as
16
+ * a particular service or system.
17
+ * - `tags` (optional): An array of tags or labels that can be attached
18
+ * to the message for categorization, filtering, or logging purposes.
19
+ * - `[key: string]` (optional): Additional custom properties can be
20
+ * added to capture specific metadata not covered by the predefined fields.
21
+ */
22
+ interface PostboyMessageMetadata {
23
+ correlationId?: string;
24
+ causationId?: string;
25
+ tags?: Set<string>;
26
+ [key: string]: any;
27
+ }
28
+
29
+ declare abstract class PostboyMessage {
30
+ metadata: PostboyMessageMetadata;
31
+ get id(): string;
32
+ setMetadata(metadata: Partial<PostboyMessageMetadata>): this;
33
+ }
34
+
35
+ /**
36
+ * An inheritor should have a static ID field
37
+ */
38
+ declare abstract class PostboyGenericMessage extends PostboyMessage {
39
+ }
40
+
41
+ declare abstract class PostboyExecutor<T> extends PostboyMessage {
42
+ protected readonly _postboyResultType?: T;
43
+ }
44
+
45
+ /**
46
+ * An abstract class extending PostboyGenericMessage that provides mechanisms for managing
47
+ * asynchronous data communication using RxJS observables. It is designed to work with
48
+ * callback-based operations that emit a result of type T.
49
+ *
50
+ * @template T - The type of the data emitted by the observables in this class.
51
+ *
52
+ * @extends PostboyGenericMessage
53
+ *
54
+ * @property {Observable<T>} result - An observable that emits the result of the operation
55
+ * and completes once the operation is finished.
56
+ *
57
+ * @method next - Emits the next value for the result observable.
58
+ * @param {T} value - The value to be emitted by the result observable.
59
+ *
60
+ * @method finish - Emits the final value for the result observable and completes it.
61
+ * @param {T} value - The final value for the observable emission.
62
+ */
63
+ declare abstract class PostboyCallbackMessage<T> extends PostboyGenericMessage {
64
+ protected result$: Subject<T>;
65
+ result: Observable<T>;
66
+ /**
67
+ * Emits the provided value.
68
+ *
69
+ * @template T - The type of the value to emit.
70
+ * @param {T} value - The value to emit through the `result$` observable.
71
+ * @returns {void}
72
+ */
73
+ next: (value: T) => void;
74
+ /**
75
+ * Marks the operation as complete by emitting the provided value and then completing the result stream.
76
+ *
77
+ * @param {T} value - The value to emit prior to completing the result stream.
78
+ * @return {void} This method does not return a value.
79
+ */
80
+ finish(value: T): void;
81
+ /**
82
+ * Completes the current observable result stream.
83
+ * This method marks the result observable as complete, ensuring no further values
84
+ * or events will be emitted from it.
85
+ *
86
+ * @return {void} No value is returned from this method.
87
+ */
88
+ complete(): void;
89
+ }
90
+
91
+ interface IPostboyDependingService {
92
+ up(): void;
93
+ down?: () => void;
94
+ }
95
+
96
+ /**
97
+ * Abstract class representing a handler for executing a Postboy task.
98
+ *
99
+ * This class is intended to manage the execution flow of a PostboyExecutor instance.
100
+ * Subclasses must implement the `handle` method, which executes a given PostboyExecutor
101
+ * and returns a result of type R.
102
+ *
103
+ * @template R The type of the result returned by the `handle` method.
104
+ * @template E The type of the executor extending the PostboyExecutor.
105
+ */
106
+ declare abstract class PostboyExecutionHandler<R, E extends PostboyExecutor<R>> {
107
+ /**
108
+ * Abstract method to handle the specified executor and return a result.
109
+ *
110
+ * @param {E} executor - The executor that will be processed by the method.
111
+ * @return {R} The result obtained after handling the executor.
112
+ */
113
+ abstract handle(executor: E): R;
114
+ }
115
+
116
+ type MessageType<T extends PostboyGenericMessage> = new (...args: any[]) => T;
117
+ declare abstract class PostboyAbstractRegistrator {
118
+ protected postboy: PostboyService;
119
+ get namespace(): string;
120
+ private ids;
121
+ private services;
122
+ private readonly _namespace;
123
+ constructor(postboy: PostboyService, namespace?: string | null);
124
+ /**
125
+ * Registers a list of services to be used by the application.
126
+ *
127
+ * @param {IPostboyDependingService[]} services - An array of services to register.
128
+ * @return {void} This method does not return a value.
129
+ */
130
+ registerServices(services: IPostboyDependingService[]): void;
131
+ /**
132
+ * Initiates the 'up' process for the current instance and all associated services.
133
+ *
134
+ * @return {void} Does not return a value.
135
+ */
136
+ up(): void;
137
+ protected abstract _up(): void;
138
+ down(): void;
139
+ /**
140
+ * Records a type and its corresponding Subject<T> into the Postboy system and updates the internal identifiers.
141
+ *
142
+ * @param {MessageType<T>} type - A constructor for the generic message type T.
143
+ * @param {Subject<T>} sub - The subject associated with the generic message type.
144
+ * @return {this} Returns the current instance for method chaining.
145
+ */
146
+ record<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>): PostboyAbstractRegistrator;
147
+ /**
148
+ * Records a message type with a specific subject and applies a transformation pipe to the subject.
149
+ *
150
+ * @param {MessageType<T>} type - The constructor of the message type to record, which extends PostboyGenericMessage.
151
+ * @param {Subject<T>} sub - The Subject instance to associate with the message type.
152
+ * @param {(s: Subject<T>) => Observable<T>} pipe - A function that takes the subject as input and returns an Observable with transformations applied.
153
+ * @return {this} The current instance of the class for chaining.
154
+ */
155
+ recordWithPipe<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>, pipe: (s: Subject<T>) => Observable<T>): PostboyAbstractRegistrator;
156
+ /**
157
+ * Records an executor associated with a specific type and execution logic.
158
+ *
159
+ * @param type The class constructor of the executor type to be recorded, which extends PostboyExecutor.
160
+ * @param exec A callback function that executes the logic using an instance of the specified executor type.
161
+ * @return void
162
+ */
163
+ recordExecutor<E extends PostboyExecutor<T>, T>(type: new (...args: any[]) => E, exec: (e: E) => T): PostboyAbstractRegistrator;
164
+ /**
165
+ * Records a handler for a specific executor type.
166
+ *
167
+ * @param executor The constructor of the executor type, which extends `PostboyExecutor`.
168
+ * @param handler The execution handler associated with the given executor type.
169
+ * @return void
170
+ */
171
+ recordHandler<E extends PostboyExecutor<R>, R>(executor: new (...args: any[]) => E, handler: PostboyExecutionHandler<R, E>): PostboyAbstractRegistrator;
172
+ /**
173
+ * A utility function that facilitates the recording and replaying of messages
174
+ * using a ReplaySubject. This function is designed to handle messages of a
175
+ * specific type and allows specifying a buffer size to determine how many
176
+ * of the most recent messages should be replayed.
177
+ *
178
+ * @template T Extends the PostboyGenericMessage type, representing the type of message
179
+ * to be recorded and replayed.
180
+ * @param {MessageType<T>} type The constructor of the message type to be recorded and replayed.
181
+ * @param {number} [bufferSize=1] The number of recent messages to retain in the ReplaySubject's buffer.
182
+ * Defaults to 1 if not specified.
183
+ * @returns The result of invoking the `record` method with the given message type and configured ReplaySubject.
184
+ */
185
+ recordReplay<T extends PostboyGenericMessage>(type: MessageType<T>, bufferSize?: number): PostboyAbstractRegistrator;
186
+ /**
187
+ * Represents a method that records a specific behavior associated with a message type.
188
+ * It creates a `BehaviorSubject` initialized with the provided initial message
189
+ * and associates it with the given message type using the `record` method.
190
+ *
191
+ * @template T - A type parameter extending `PostboyGenericMessage` that defines the message structure.
192
+ * @param {MessageType<T>} type - The constructor function of the message type to be recorded.
193
+ * @param {T} initial - The initial value of the message that will be set in the `BehaviorSubject`.
194
+ * @returns {void} - This function does not return a value; instead, it modifies the internal state.
195
+ */
196
+ recordBehavior<T extends PostboyGenericMessage>(type: MessageType<T>, initial: T): PostboyAbstractRegistrator;
197
+ /**
198
+ * A function that creates and returns a new generic message recorder for a specific message type.
199
+ *
200
+ * @template T - A type parameter extending from `PostboyGenericMessage`.
201
+ * @param {MessageType<T>} type - The constructor for the message type being recorded.
202
+ * @returns {Subject<T>} A new instance of `Subject<T>` bound to the specified message type.
203
+ */
204
+ recordSubject<T extends PostboyGenericMessage>(type: MessageType<T>): this;
205
+ }
206
+
207
+ declare enum MiddlewareStage {
208
+ Publish = 1,
209
+ Callback = 2,
210
+ Execute = 3
211
+ }
212
+
213
+ interface PipelineContext<T extends PostboyMessage = PostboyMessage> {
214
+ stage: MiddlewareStage;
215
+ message: T;
216
+ }
217
+
218
+ declare enum MiddlewareDecisionType {
219
+ Continue = 1,
220
+ Interrupt = 2
221
+ }
222
+
223
+ interface MiddlewareDecision {
224
+ type: MiddlewareDecisionType;
225
+ }
226
+
227
+ interface CancelDetails {
228
+ stage: MiddlewareStage;
229
+ reason?: string;
230
+ middleware?: string;
231
+ messageId?: string;
232
+ namespace?: string;
233
+ }
234
+
235
+ declare class CancelError extends Error {
236
+ readonly details: CancelDetails;
237
+ constructor(details: CancelDetails);
238
+ }
239
+
240
+ type PipelineResult = {
241
+ cancelled: boolean;
242
+ cancelledBy?: string;
243
+ reason?: string;
244
+ };
245
+
246
+ interface PostboyMessageContext {
247
+ correlationId: string;
248
+ currentMessageId: string;
249
+ parentMessageId?: string;
250
+ depth: number;
251
+ startedAt: Date;
252
+ tags?: Set<string>;
253
+ }
254
+
255
+ /**
256
+ * A class that manages a reactive subscription using a provided Subject and transformation pipe.
257
+ * Offers methods to interact with the subscription, such as emitting data, completing the subscription,
258
+ * and accessing the transformed observable.
259
+ *
260
+ * @template T The type of data managed by the subscription.
261
+ */
262
+ declare class PostboySubscription<T> {
263
+ private subscription;
264
+ private readonly _subscription;
265
+ /**
266
+ * Constructs an instance of the class with a given subscription and a transformation pipe.
267
+ *
268
+ * @param {Subject<T>} subscription - The source Subject that will be transformed.
269
+ * @param {(s: Subject<T>) => Observable<T>} pipe - A function that applies a transformation to the subscription.
270
+ */
271
+ constructor(subscription: Subject<T>, pipe?: (s: Subject<T>) => Observable<T>);
272
+ /**
273
+ * Returns an observable subscription.
274
+ *
275
+ * @return {Observable<T>} An observable instance of type T.
276
+ */
277
+ sub(): Observable<T>;
278
+ /**
279
+ * Triggers an event by emitting the provided data to all subscribers.
280
+ *
281
+ * @param {T} data - The data to emit to the subscribers.
282
+ * @return {void} - Does not return any value.
283
+ */
284
+ fire(data: T): void;
285
+ /**
286
+ * Completes the subscription, signaling that no further values will be sent.
287
+ * This is typically used to finalize or clean up resources.
288
+ * @return {void} This method does not return any value.
289
+ */
290
+ finish(): void;
291
+ }
292
+
293
+ /**
294
+ * Abstract base class for defining middleware in a pipeline.
295
+ * Middleware acts on various stages of pipeline execution, allowing operations
296
+ * to be intercepted, modified, or monitored.
297
+ */
298
+ declare abstract class PostboyMiddleware {
299
+ readonly name: string;
300
+ /**
301
+ * Creates an instance of a class, optionally assigning a name.
302
+ *
303
+ * @param {string} [name] - An optional name to be assigned. If not provided, defaults to the class name.
304
+ */
305
+ constructor(name?: string);
306
+ /**
307
+ * Optional filter to skip middleware for unrelated messages/stages.
308
+ */
309
+ canHandle(_context: PipelineContext): boolean;
310
+ /**
311
+ * Called before the stage is executed.
312
+ * Return Interrupt to cancel the operation.
313
+ */
314
+ before(_context: PipelineContext): MiddlewareDecision;
315
+ /**
316
+ * Called after the stage has finished successfully.
317
+ * `result` is typically set for execute-stage.
318
+ */
319
+ after(_context: PipelineContext, _result?: unknown): void;
320
+ /**
321
+ * Optional cleanup hook.
322
+ */
323
+ dispose(): void;
324
+ }
325
+
326
+ declare class PostboyMiddlewareService {
327
+ protected middlewares: PostboyMiddleware[];
328
+ addMiddleware(middleware: PostboyMiddleware): void;
329
+ removeMiddleware(middleware: PostboyMiddleware): void;
330
+ dispose(): void;
331
+ before<T extends PostboyMessage>(stage: MiddlewareStage, message: T): void;
332
+ after<T extends PostboyMessage, R = unknown>(stage: MiddlewareStage, message: T, result?: R): void;
333
+ beforePublish(message: PostboyMessage): void;
334
+ afterPublish(message: PostboyMessage): void;
335
+ beforeCallback(message: PostboyMessage): void;
336
+ afterCallback(message: PostboyMessage, result?: unknown): void;
337
+ beforeExecute<T>(message: PostboyExecutor<T>): void;
338
+ afterExecute<T>(message: PostboyExecutor<T>, result: T): void;
339
+ private buildContext;
340
+ private throwIfCancelled;
341
+ }
342
+
343
+ /**
344
+ * The PostboyMessageStore is a utility class for managing message subscriptions and executors.
345
+ * It provides functionality to register, retrieve, and unregister subscription-based messages and executors.
346
+ */
347
+ declare class PostboyMessageStore {
348
+ protected messages: Map<string, PostboySubscription<any>>;
349
+ protected executors: Map<string, (e: PostboyExecutor<any>) => any>;
350
+ protected callbacks: Map<string, (() => void)[]>;
351
+ registerMessage(id: string, sub: PostboySubscription<any>): void;
352
+ registerExecutor(id: string, executor: (e: PostboyExecutor<any>) => any): void;
353
+ callbackFired(message: PostboyCallbackMessage<any>): void;
354
+ getMessage(id: string, name: string): PostboySubscription<any>;
355
+ getExecutor<T>(id: string): (e: PostboyExecutor<T>) => T;
356
+ unregister(id: string): void;
357
+ dispose(): void;
358
+ }
359
+
360
+ /**
361
+ * Represents a store for managing namespaces in the Postboy system.
362
+ * Provides functionality to add, eliminate, and dispose namespaces.
363
+ */
364
+ declare class PostboyNamespaceStore {
365
+ private spaces;
366
+ /**
367
+ * Adds a new space or retrieves an existing one if it already exists.
368
+ *
369
+ * @param {string} space - The name of the space to add or retrieve.
370
+ * @param {PostboyService} postboy - The PostboyService instance used to create a namespace registrator.
371
+ * @return {PostboyAbstractRegistrator} The registrator associated with the specified space.
372
+ */
373
+ addSpace(space: string, postboy: PostboyService): PostboyAbstractRegistrator;
374
+ /**
375
+ * Removes a specified space from the spaces collection if it exists.
376
+ * If the space exists, it will be deleted after invoking its down method.
377
+ *
378
+ * @param {string} space - The name of the space to be removed.
379
+ * @return {void} This method does not return a value.
380
+ */
381
+ eliminateSpace(space: string): void;
382
+ /**
383
+ * Disposes of the current instance by performing cleanup operations.
384
+ * Iterates through all spaces, performs a "down" operation on each,
385
+ * and then clears the collection of spaces.
386
+ *
387
+ * @return {void} No return value.
388
+ */
389
+ dispose(): void;
390
+ }
391
+
392
+ declare class PostboyDependencyResolver {
393
+ /**
394
+ * Retrieves an instance of the PostboyMiddlewareService.
395
+ *
396
+ * This function initializes and returns a new instance of the
397
+ * PostboyMiddlewareService, which can be used to configure and manage
398
+ * middleware for a specific module or application.
399
+ *
400
+ * @returns {PostboyMiddlewareService} A new instance of PostboyMiddlewareService.
401
+ */
402
+ getMiddlewareService: () => PostboyMiddlewareService;
403
+ /**
404
+ * A function that instantiates and returns a new instance of PostboyMessageStore.
405
+ *
406
+ * This function serves as a factory method for creating instances
407
+ * of the PostboyMessageStore class.
408
+ *
409
+ * @returns {PostboyMessageStore} A new instance of the PostboyMessageStore class.
410
+ */
411
+ getMessageStore: () => PostboyMessageStore;
412
+ /**
413
+ * Creates and initializes a new instance of PostboyNamespaceStore using the provided PostboyService instance.
414
+ *
415
+ * @function getNamespaceStore
416
+ * @returns {PostboyNamespaceStore} A new instance of PostboyNamespaceStore associated with the given PostboyService.
417
+ */
418
+ getNamespaceStore: () => PostboyNamespaceStore;
419
+ }
420
+
421
+ declare class PostboyService {
422
+ protected locked: Set<string>;
423
+ private middleware;
424
+ private store;
425
+ private namespaceStore;
426
+ private dependencyResolver;
427
+ constructor(resolver?: PostboyDependencyResolver);
428
+ private registerInfrastructureMessages;
429
+ /**
430
+ * Fires a registered event and passes the message to its subscribers.
431
+ *
432
+ * @param {PostboyGenericMessage} message - The message object containing the event data.
433
+ * @return {void} This method does not return a value.
434
+ * @throws {Error} Throws an error if no registered event is found for the provided message ID.
435
+ */
436
+ fire(message: PostboyGenericMessage): void;
437
+ /**
438
+ * Triggers a callback function associated with a given message.
439
+ *
440
+ * @param {PostboyCallbackMessage<T>} message - The message object used to trigger the callback.
441
+ * It contains details about the event and result subscription.
442
+ * @param {(e: T) => void} [action] - Optional callback function to execute when the result of the message is emitted.
443
+ * @return {void} This method does not return any value.
444
+ */
445
+ fireCallback<T>(message: PostboyCallbackMessage<T>, action?: (e: T) => void): Observable<T>;
446
+ /**
447
+ * Executes the provided executor function and returns its result.
448
+ *
449
+ * @param {PostboyExecutor<T>} executor The executor to be executed, which includes its identifier and logic.
450
+ * @return {T} The resulting output from the executed executor function.
451
+ * @throws {Error} If the specified executor is not registered.
452
+ */
453
+ exec<T>(executor: PostboyExecutor<T>): T;
454
+ /**
455
+ * Subscribes to a specific message type and returns an observable of that type.
456
+ *
457
+ * @param type The constructor function of the type that extends PostboyGenericMessage.
458
+ * @return An Observable of the specified generic message type.
459
+ */
460
+ sub<T extends PostboyGenericMessage>(type: MessageType<T>): Observable<T>;
461
+ /**
462
+ * Subscribes to a specific message type and automatically unsubscribes after receiving the first message.
463
+ *
464
+ * @param type The type of message to subscribe to.
465
+ * @return An observable that emits the first message of the specified type and then completes.
466
+ */
467
+ once<T extends PostboyGenericMessage>(type: MessageType<T>): Observable<T>;
468
+ /**
469
+ * Registers a given message type and its associated subject subscription with the system.
470
+ *
471
+ * @deprecated The method should be replaced with firing {@link ConnectMessage} message.
472
+ * @param type The constructor function of the message type that extends the PostboyGenericMessage.
473
+ * @param sub The Subject instance for the provided message type, used for managing subscriptions.
474
+ * @return {void} No return value.
475
+ */
476
+ record<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>): void;
477
+ /**
478
+ * Registers a generic message type with a Subject and a transformation pipe.
479
+ *
480
+ * @deprecated The method should be replaced with firing {@link ConnectMessage} message.
481
+ * @param {MessageType<T>} type - The constructor of the message type being registered.
482
+ * @param {Subject<T>} sub - The Subject instance used to handle incoming messages of the specified type.
483
+ * @param {(s: Subject<T>) => Observable<T>} pipe - A function that applies a transformation or processing logic to the Subject and returns an Observable.
484
+ * @return {void} No return value.
485
+ */
486
+ recordWithPipe<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>, pipe: (s: Subject<T>) => Observable<T>): void;
487
+ /**
488
+ * Registers an executor for a specified message type.
489
+ *
490
+ * @deprecated The method should be replaced with firing {@link ConnectExecutor} message.
491
+ * @param {MessageType<E>} type - The message type for which the executor is being registered.
492
+ * @param {(e: E) => T} exec - The executor function that will handle messages of the specified type.
493
+ * @return {void} This method does not return any value.
494
+ */
495
+ recordExecutor<E extends PostboyExecutor<T>, T>(type: MessageType<E>, exec: (e: E) => T): void;
496
+ /**
497
+ * Registers a handler for a specific executor type.
498
+ *
499
+ * @deprecated The method should be replaced with firing {@link ConnectHandler} message.
500
+ * @param executor The constructor of the executor class that extends `PostboyExecutor<R>`.
501
+ * @param handler An instance of `PostboyExecutionHandler<R, E>` that defines the logic for handling the executor.
502
+ * @return void
503
+ */
504
+ recordHandler<E extends PostboyExecutor<R>, R>(executor: new (...args: any[]) => E, handler: PostboyExecutionHandler<R, E>): void;
505
+ /**
506
+ * Disposes of resources and cleans up any internal components or stores associated with the instance.
507
+ * This method ensures that all resources are properly released to avoid memory leaks.
508
+ *
509
+ * @return {void} This method does not return a value.
510
+ */
511
+ dispose(): void;
512
+ }
513
+
514
+ /**
515
+ * Represents a {@link PostboyMiddleware} addition operation for Postboy.
516
+ * This class extends the functionality of the PostboyExecutor to add middleware to the processing chain.
517
+ *
518
+ * The middleware to be added is provided during instantiation.
519
+ */
520
+ declare class AddMiddleware extends PostboyExecutor<void> {
521
+ middleware: PostboyMiddleware;
522
+ static readonly ID = "0a8cfe0a-6193-4082-8440-d0793367b21d";
523
+ /**
524
+ * Initializes a new instance of the class with the specified middleware.
525
+ *
526
+ * @param {PostboyMiddleware} middleware - The {@link PostboyMiddleware} to be used for processing.
527
+ */
528
+ constructor(middleware: PostboyMiddleware);
529
+ }
530
+
531
+ /**
532
+ * Represents a class responsible for removing {@link PostboyMiddleware} in execution flow.
533
+ * This class extends PostboyExecutor and operates with a void return type.
534
+ */
535
+ declare class RemoveMiddleware extends PostboyExecutor<void> {
536
+ middleware: PostboyMiddleware;
537
+ static readonly ID = "c25c708c-53c9-498d-a28b-936fbaf68b91";
538
+ /**
539
+ * Constructs an instance of the class with the specified middleware.
540
+ *
541
+ * @param {PostboyMiddleware} middleware - The {@link PostboyMiddleware} instance to be removed.
542
+ */
543
+ constructor(middleware: PostboyMiddleware);
544
+ }
545
+
546
+ /**
547
+ * Locks a specific message type to prevent firing of them.
548
+ *
549
+ * @deprecated Use {@link PostboyMiddleware}
550
+ * This class is used to handle operations associated with locking mechanisms
551
+ * for a specified message type.
552
+ *
553
+ * @template T - A type that extends {@link PostboyGenericMessage}.
554
+ */
555
+ declare class LockMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {
556
+ type: MessageType<T>;
557
+ static readonly ID = "477df3e2-1f99-4476-9a3b-afd1fa426436";
558
+ /**
559
+ * Constructs an instance of the class with the specified message type.
560
+ *
561
+ * @param {MessageType<T>} type - The type of the message to be used for the instance.
562
+ */
563
+ constructor(type: MessageType<T>);
564
+ }
565
+
566
+ /**
567
+ * A specialized executor that handles the unlocking process for messages of a specified type.
568
+ * Unlocks a previously locked message, making it available for processing again.
569
+ *
570
+ * @deprecated Use {@link PostboyMiddleware}
571
+ * @template T - The type parameter extending {@link PostboyGenericMessage}, representing the message type handled by the executor.
572
+ * @extends {PostboyExecutor<void>}
573
+ */
574
+ declare class UnlockMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {
575
+ type: MessageType<T>;
576
+ static readonly ID = "d71d25e3-90ac-4009-b972-9e6c6b05611e";
577
+ /**
578
+ * Creates an instance of the class with the specified message type.
579
+ *
580
+ * @param {MessageType<T>} type - The message type for this instance.
581
+ */
582
+ constructor(type: MessageType<T>);
583
+ }
584
+
585
+ /**
586
+ * AddNamespace is a class that extends the PostboyExecutor with a specific implementation
587
+ * for adding namespaces to a PostboyService instance.
588
+ *
589
+ * This class is identified uniquely by its static ID property for tracking and referencing purposes.
590
+ */
591
+ declare class AddNamespace extends PostboyExecutor<PostboyAbstractRegistrator> {
592
+ space: string;
593
+ static readonly ID = "6d1a6f7d-6b6e-4c4d-8af8-9cc9a32e850c";
594
+ /**
595
+ * Creates an instance of the class with the specified space identifier.
596
+ *
597
+ * @param {string} space - The identifier for the space.
598
+ */
599
+ constructor(space: string);
600
+ }
601
+
602
+ /**
603
+ * Represents an executor that eliminates a specific namespace.
604
+ * This class extends the PostboyExecutor with a void return type.
605
+ */
606
+ declare class EliminateNamespace extends PostboyExecutor<void> {
607
+ space: string;
608
+ static readonly ID = "03bb03bb-53e0-4b74-9aad-64d5c54a8972";
609
+ /**
610
+ * Creates an instance of the class with the specified space value.
611
+ *
612
+ * @param {string} space - The string value representing the space configuration.
613
+ */
614
+ constructor(space: string);
615
+ }
616
+
617
+ /**
618
+ * Represents a connection handler that extends the PostboyExecutor class.
619
+ *
620
+ * This class encapsulates logic associated with executing a handler in a structured way.
621
+ * It is generic and operates on the provided executor and handler types.
622
+ *
623
+ * Type Parameters:
624
+ * E - Represents an extension of the PostboyExecutor class with a specific type parameter R.
625
+ * R - Represents the type of the result that the executor is expected to operate on.
626
+ */
627
+ declare class ConnectHandler<E extends PostboyExecutor<R>, R> extends PostboyExecutor<void> {
628
+ executor: new (...args: any[]) => E;
629
+ handler: PostboyExecutionHandler<R, E>;
630
+ static readonly ID = "bf618cea-6f32-417c-9548-8eafe937378b";
631
+ /**
632
+ * Constructs an instance of the class.
633
+ *
634
+ * @param {new (...args: any[]) => E} executor - A constructor function for the executor object.
635
+ * @param {PostboyExecutionHandler<R, E>} handler - A handler that processes the execution logic.
636
+ */
637
+ constructor(executor: new (...args: any[]) => E, handler: PostboyExecutionHandler<R, E>);
638
+ }
639
+
640
+ /**
641
+ * Registers an executor that connects to a specific type of message handler.
642
+ * This class extends the functionality of `PostboyExecutor` and is designed to manage
643
+ * the execution of a handler defined by a specific message type and an execution function.
644
+ *
645
+ * @template E The type of the executor extending {@link PostboyExecutor}.
646
+ * @template T The return type of the execution function.
647
+ *
648
+ * @extends {PostboyExecutor<void>}
649
+ */
650
+ declare class ConnectExecutor<E extends PostboyExecutor<T>, T> extends PostboyExecutor<void> {
651
+ type: MessageType<E>;
652
+ exec: (e: E) => T;
653
+ static readonly ID = "cb80e8ad-b68c-4b2d-8c44-617ea6017cb3";
654
+ /**
655
+ * Constructs an instance of the class with the specified type and execution function.
656
+ *
657
+ * @param {MessageType<E>} type - The type of the message.
658
+ * @param {(e: E) => T} exec - The function to be executed with the input of type E that returns a value of type T.
659
+ */
660
+ constructor(type: MessageType<E>, exec: (e: E) => T);
661
+ }
662
+
663
+ /**
664
+ * Represents a message signaling a disconnection event. This class is used
665
+ * within the framework to manage and process disconnection notifications.
666
+ * Extends the {@link PostboyExecutor} base class.
667
+ *
668
+ * @extends {PostboyExecutor<void>}
669
+ */
670
+ declare class DisconnectMessage extends PostboyExecutor<void> {
671
+ messageId: string;
672
+ static readonly ID = "94579e43-5bc9-4517-bcda-b595bcda1ae7";
673
+ /**
674
+ * Creates an instance of the class with the specified message identifier.
675
+ *
676
+ * @param {string} messageId - The unique identifier for the message.
677
+ */
678
+ constructor(messageId: string);
679
+ }
680
+
681
+ /**
682
+ * Represents a message that facilitates connection functionality
683
+ * within the application's messaging system.
684
+ *
685
+ * @template T - A type that extends {@link PostboyGenericMessage}, representing
686
+ * the structure of the message being handled.
687
+ *
688
+ * @extends PostboyExecutor<void>
689
+ */
690
+ declare class ConnectMessage<T extends PostboyGenericMessage> extends PostboyExecutor<void> {
691
+ type: MessageType<T>;
692
+ sub: Subject<T>;
693
+ pipe?: ((s: Subject<T>) => Observable<T>) | undefined;
694
+ static readonly ID = "aa03a192-bdc7-402d-9f2f-bf3748229ea2";
695
+ /**
696
+ * Constructs a new instance of the class.
697
+ *
698
+ * @param {MessageType<T>} type - The type of the message.
699
+ * @param {Subject<T>} sub - The subject to be used for message handling.
700
+ * @param {(s: Subject<T>) => Observable<T>} [pipe] - An optional function to transform the subject.
701
+ */
702
+ constructor(type: MessageType<T>, sub: Subject<T>, pipe?: ((s: Subject<T>) => Observable<T>) | undefined);
703
+ }
704
+
705
+ export { AddMiddleware, AddNamespace, type CancelDetails, CancelError, ConnectExecutor, ConnectHandler, ConnectMessage, DisconnectMessage, EliminateNamespace, type IPostboyDependingService, LockMessage, type MessageType, type MiddlewareDecision, MiddlewareDecisionType, MiddlewareStage, type PipelineContext, type PipelineResult, PostboyAbstractRegistrator, PostboyCallbackMessage, PostboyExecutionHandler, PostboyExecutor, PostboyGenericMessage, PostboyMessage, type PostboyMessageContext, type PostboyMessageMetadata, PostboyMessageStore, PostboyMiddleware, PostboyMiddlewareService, PostboyNamespaceStore, PostboyService, PostboySubscription, RemoveMiddleware, UnlockMessage };