@artstesh/postboy 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/lib/index.cjs +2 -0
  2. package/lib/index.cjs.map +1 -0
  3. package/lib/index.d.mts +701 -0
  4. package/lib/index.d.ts +701 -13
  5. package/lib/index.mjs +2 -0
  6. package/lib/index.mjs.map +1 -0
  7. package/package.json +52 -19
  8. package/lib/i-postboy-depending.service.d.ts +0 -5
  9. package/lib/i-postboy-depending.service.d.ts.map +0 -1
  10. package/lib/i-postboy-depending.service.js +0 -3
  11. package/lib/i-postboy-depending.service.js.map +0 -1
  12. package/lib/index.d.ts.map +0 -1
  13. package/lib/index.js +0 -32
  14. package/lib/index.js.map +0 -1
  15. package/lib/locker.store.d.ts +0 -9
  16. package/lib/locker.store.d.ts.map +0 -1
  17. package/lib/locker.store.js +0 -27
  18. package/lib/locker.store.js.map +0 -1
  19. package/lib/messages/add-middleware.executor.d.ts +0 -19
  20. package/lib/messages/add-middleware.executor.d.ts.map +0 -1
  21. package/lib/messages/add-middleware.executor.js +0 -24
  22. package/lib/messages/add-middleware.executor.js.map +0 -1
  23. package/lib/messages/add-namespace.executor.d.ts +0 -19
  24. package/lib/messages/add-namespace.executor.d.ts.map +0 -1
  25. package/lib/messages/add-namespace.executor.js +0 -24
  26. package/lib/messages/add-namespace.executor.js.map +0 -1
  27. package/lib/messages/connect-executor.executor.d.ts +0 -25
  28. package/lib/messages/connect-executor.executor.d.ts.map +0 -1
  29. package/lib/messages/connect-executor.executor.js +0 -30
  30. package/lib/messages/connect-executor.executor.js.map +0 -1
  31. package/lib/messages/connect-handler.executor.d.ts +0 -25
  32. package/lib/messages/connect-handler.executor.d.ts.map +0 -1
  33. package/lib/messages/connect-handler.executor.js +0 -30
  34. package/lib/messages/connect-handler.executor.js.map +0 -1
  35. package/lib/messages/connect-message.executor.d.ts +0 -28
  36. package/lib/messages/connect-message.executor.d.ts.map +0 -1
  37. package/lib/messages/connect-message.executor.js +0 -31
  38. package/lib/messages/connect-message.executor.js.map +0 -1
  39. package/lib/messages/connect.message.executor.d.ts +0 -28
  40. package/lib/messages/connect.message.executor.d.ts.map +0 -1
  41. package/lib/messages/connect.message.executor.js +0 -31
  42. package/lib/messages/connect.message.executor.js.map +0 -1
  43. package/lib/messages/disconnect-message.executor.d.ts +0 -19
  44. package/lib/messages/disconnect-message.executor.d.ts.map +0 -1
  45. package/lib/messages/disconnect-message.executor.js +0 -25
  46. package/lib/messages/disconnect-message.executor.js.map +0 -1
  47. package/lib/messages/eliminate-namespace.executor.d.ts +0 -16
  48. package/lib/messages/eliminate-namespace.executor.d.ts.map +0 -1
  49. package/lib/messages/eliminate-namespace.executor.js +0 -22
  50. package/lib/messages/eliminate-namespace.executor.js.map +0 -1
  51. package/lib/messages/index.d.ts +0 -11
  52. package/lib/messages/index.d.ts.map +0 -1
  53. package/lib/messages/index.js +0 -24
  54. package/lib/messages/index.js.map +0 -1
  55. package/lib/messages/lock-message.executor.d.ts +0 -22
  56. package/lib/messages/lock-message.executor.d.ts.map +0 -1
  57. package/lib/messages/lock-message.executor.js +0 -26
  58. package/lib/messages/lock-message.executor.js.map +0 -1
  59. package/lib/messages/remove-middleware.executor.d.ts +0 -17
  60. package/lib/messages/remove-middleware.executor.d.ts.map +0 -1
  61. package/lib/messages/remove-middleware.executor.js +0 -22
  62. package/lib/messages/remove-middleware.executor.js.map +0 -1
  63. package/lib/messages/unlock-message.executor.d.ts +0 -21
  64. package/lib/messages/unlock-message.executor.d.ts.map +0 -1
  65. package/lib/messages/unlock-message.executor.js +0 -25
  66. package/lib/messages/unlock-message.executor.js.map +0 -1
  67. package/lib/mocks/message-history-item-mock.d.ts +0 -10
  68. package/lib/mocks/message-history-item-mock.d.ts.map +0 -1
  69. package/lib/mocks/message-history-item-mock.js +0 -26
  70. package/lib/mocks/message-history-item-mock.js.map +0 -1
  71. package/lib/mocks/message-history-mock.d.ts +0 -9
  72. package/lib/mocks/message-history-mock.d.ts.map +0 -1
  73. package/lib/mocks/message-history-mock.js +0 -23
  74. package/lib/mocks/message-history-mock.js.map +0 -1
  75. package/lib/mocks/postboy-service-mock.d.ts +0 -22
  76. package/lib/mocks/postboy-service-mock.d.ts.map +0 -1
  77. package/lib/mocks/postboy-service-mock.js +0 -51
  78. package/lib/mocks/postboy-service-mock.js.map +0 -1
  79. package/lib/models/message-queue.model.d.ts +0 -44
  80. package/lib/models/message-queue.model.d.ts.map +0 -1
  81. package/lib/models/message-queue.model.js +0 -66
  82. package/lib/models/postboy-callback.message.d.ts +0 -48
  83. package/lib/models/postboy-callback.message.d.ts.map +0 -1
  84. package/lib/models/postboy-callback.message.js +0 -60
  85. package/lib/models/postboy-callback.message.js.map +0 -1
  86. package/lib/models/postboy-execution.handler.d.ts +0 -21
  87. package/lib/models/postboy-execution.handler.d.ts.map +0 -1
  88. package/lib/models/postboy-execution.handler.js +0 -17
  89. package/lib/models/postboy-execution.handler.js.map +0 -1
  90. package/lib/models/postboy-executor.d.ts +0 -5
  91. package/lib/models/postboy-executor.d.ts.map +0 -1
  92. package/lib/models/postboy-executor.js +0 -8
  93. package/lib/models/postboy-executor.js.map +0 -1
  94. package/lib/models/postboy-generic-message.d.ts +0 -8
  95. package/lib/models/postboy-generic-message.d.ts.map +0 -1
  96. package/lib/models/postboy-generic-message.js +0 -17
  97. package/lib/models/postboy-generic-message.js.map +0 -1
  98. package/lib/models/postboy-message-metadata.d.ts +0 -26
  99. package/lib/models/postboy-message-metadata.d.ts.map +0 -1
  100. package/lib/models/postboy-message-metadata.js +0 -3
  101. package/lib/models/postboy-message-metadata.js.map +0 -1
  102. package/lib/models/postboy-message.context.d.ts +0 -9
  103. package/lib/models/postboy-message.context.d.ts.map +0 -1
  104. package/lib/models/postboy-message.context.js +0 -3
  105. package/lib/models/postboy-message.context.js.map +0 -1
  106. package/lib/models/postboy-middleware.d.ts +0 -5
  107. package/lib/models/postboy-middleware.d.ts.map +0 -1
  108. package/lib/models/postboy-middleware.js +0 -3
  109. package/lib/models/postboy-middleware.js.map +0 -1
  110. package/lib/models/postboy-subscription.d.ts +0 -39
  111. package/lib/models/postboy-subscription.d.ts.map +0 -1
  112. package/lib/models/postboy-subscription.js +0 -49
  113. package/lib/models/postboy-subscription.js.map +0 -1
  114. package/lib/models/postboy.locker.d.ts +0 -6
  115. package/lib/models/postboy.locker.d.ts.map +0 -1
  116. package/lib/models/postboy.locker.js +0 -3
  117. package/lib/models/postboy.locker.js.map +0 -1
  118. package/lib/models/postboy.message.d.ts +0 -7
  119. package/lib/models/postboy.message.d.ts.map +0 -1
  120. package/lib/models/postboy.message.js +0 -17
  121. package/lib/models/postboy.message.js.map +0 -1
  122. package/lib/models/postboy.settings.d.ts +0 -13
  123. package/lib/models/postboy.settings.d.ts.map +0 -1
  124. package/lib/models/postboy.settings.js +0 -20
  125. package/lib/models/postboy.settings.js.map +0 -1
  126. package/lib/postboy-abstract.registrator.d.ts +0 -97
  127. package/lib/postboy-abstract.registrator.d.ts.map +0 -1
  128. package/lib/postboy-abstract.registrator.js +0 -138
  129. package/lib/postboy-abstract.registrator.js.map +0 -1
  130. package/lib/postboy.service.d.ts +0 -157
  131. package/lib/postboy.service.d.ts.map +0 -1
  132. package/lib/postboy.service.js +0 -235
  133. package/lib/postboy.service.js.map +0 -1
  134. package/lib/services/namespace-registrator.d.ts +0 -14
  135. package/lib/services/namespace-registrator.d.ts.map +0 -1
  136. package/lib/services/namespace-registrator.js +0 -21
  137. package/lib/services/namespace-registrator.js.map +0 -1
  138. package/lib/services/postboy-context.service.d.ts +0 -13
  139. package/lib/services/postboy-context.service.d.ts.map +0 -1
  140. package/lib/services/postboy-context.service.js +0 -50
  141. package/lib/services/postboy-context.service.js.map +0 -1
  142. package/lib/services/postboy-dependency.resolver.d.ts +0 -32
  143. package/lib/services/postboy-dependency.resolver.d.ts.map +0 -1
  144. package/lib/services/postboy-dependency.resolver.js +0 -38
  145. package/lib/services/postboy-dependency.resolver.js.map +0 -1
  146. package/lib/services/postboy-message.store.d.ts +0 -20
  147. package/lib/services/postboy-message.store.d.ts.map +0 -1
  148. package/lib/services/postboy-message.store.js +0 -61
  149. package/lib/services/postboy-message.store.js.map +0 -1
  150. package/lib/services/postboy-middleware.service.d.ts +0 -37
  151. package/lib/services/postboy-middleware.service.d.ts.map +0 -1
  152. package/lib/services/postboy-middleware.service.js +0 -50
  153. package/lib/services/postboy-middleware.service.js.map +0 -1
  154. package/lib/services/postboy-namespace.store.d.ts +0 -34
  155. package/lib/services/postboy-namespace.store.d.ts.map +0 -1
  156. package/lib/services/postboy-namespace.store.js +0 -54
  157. package/lib/services/postboy-namespace.store.js.map +0 -1
  158. package/lib/tests/integration/models/test-callback-message.d.ts +0 -6
  159. package/lib/tests/integration/models/test-callback-message.d.ts.map +0 -1
  160. package/lib/tests/integration/models/test-callback-message.js +0 -13
  161. package/lib/tests/integration/models/test-callback-message.js.map +0 -1
  162. package/lib/tests/integration/models/test-executor.d.ts +0 -7
  163. package/lib/tests/integration/models/test-executor.d.ts.map +0 -1
  164. package/lib/tests/integration/models/test-executor.js +0 -13
  165. package/lib/tests/integration/models/test-executor.js.map +0 -1
  166. package/lib/tests/integration/models/test-handler.d.ts +0 -8
  167. package/lib/tests/integration/models/test-handler.d.ts.map +0 -1
  168. package/lib/tests/integration/models/test-handler.js +0 -15
  169. package/lib/tests/integration/models/test-handler.js.map +0 -1
  170. package/lib/tests/integration/models/test-message.d.ts +0 -6
  171. package/lib/tests/integration/models/test-message.d.ts.map +0 -1
  172. package/lib/tests/integration/models/test-message.js +0 -13
  173. package/lib/tests/integration/models/test-message.js.map +0 -1
  174. package/lib/tests/integration/models/test-postboy.d.ts +0 -4
  175. package/lib/tests/integration/models/test-postboy.d.ts.map +0 -1
  176. package/lib/tests/integration/models/test-postboy.js +0 -8
  177. package/lib/tests/integration/models/test-postboy.js.map +0 -1
  178. package/lib/tests/integration/models/test-registry.d.ts +0 -8
  179. package/lib/tests/integration/models/test-registry.d.ts.map +0 -1
  180. package/lib/tests/integration/models/test-registry.js +0 -15
  181. package/lib/tests/integration/models/test-registry.js.map +0 -1
  182. package/lib/utils/id.generator.d.ts +0 -5
  183. package/lib/utils/id.generator.d.ts.map +0 -1
  184. package/lib/utils/id.generator.js +0 -18
  185. package/lib/utils/id.generator.js.map +0 -1
@@ -1,97 +0,0 @@
1
- import { PostboyService } from './postboy.service';
2
- import { Observable, Subject } from 'rxjs';
3
- import { IPostboyDependingService } from './i-postboy-depending.service';
4
- import { PostboyExecutor } from './models/postboy-executor';
5
- import { PostboyGenericMessage } from './models/postboy-generic-message';
6
- import { PostboyExecutionHandler } from './models/postboy-execution.handler';
7
- export type MessageType<T extends PostboyGenericMessage> = new (...args: any[]) => T;
8
- export declare abstract class PostboyAbstractRegistrator {
9
- protected postboy: PostboyService;
10
- get namespace(): string;
11
- private ids;
12
- private services;
13
- private readonly _namespace;
14
- constructor(postboy: PostboyService, namespace?: string | null);
15
- /**
16
- * Registers a list of services to be used by the application.
17
- *
18
- * @param {IPostboyDependingService[]} services - An array of services to register.
19
- * @return {void} This method does not return a value.
20
- */
21
- registerServices(services: IPostboyDependingService[]): void;
22
- /**
23
- * Initiates the 'up' process for the current instance and all associated services.
24
- *
25
- * @return {void} Does not return a value.
26
- */
27
- up(): void;
28
- protected abstract _up(): void;
29
- down(): void;
30
- /**
31
- * Records a type and its corresponding Subject<T> into the Postboy system and updates the internal identifiers.
32
- *
33
- * @param {MessageType<T>} type - A constructor for the generic message type T.
34
- * @param {Subject<T>} sub - The subject associated with the generic message type.
35
- * @return {this} Returns the current instance for method chaining.
36
- */
37
- record<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>): PostboyAbstractRegistrator;
38
- /**
39
- * Records a message type with a specific subject and applies a transformation pipe to the subject.
40
- *
41
- * @param {MessageType<T>} type - The constructor of the message type to record, which extends PostboyGenericMessage.
42
- * @param {Subject<T>} sub - The Subject instance to associate with the message type.
43
- * @param {(s: Subject<T>) => Observable<T>} pipe - A function that takes the subject as input and returns an Observable with transformations applied.
44
- * @return {this} The current instance of the class for chaining.
45
- */
46
- recordWithPipe<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>, pipe: (s: Subject<T>) => Observable<T>): PostboyAbstractRegistrator;
47
- /**
48
- * Records an executor associated with a specific type and execution logic.
49
- *
50
- * @param type The class constructor of the executor type to be recorded, which extends PostboyExecutor.
51
- * @param exec A callback function that executes the logic using an instance of the specified executor type.
52
- * @return void
53
- */
54
- recordExecutor<E extends PostboyExecutor<T>, T>(type: new (...args: any[]) => E, exec: (e: E) => T): PostboyAbstractRegistrator;
55
- /**
56
- * Records a handler for a specific executor type.
57
- *
58
- * @param executor The constructor of the executor type, which extends `PostboyExecutor`.
59
- * @param handler The execution handler associated with the given executor type.
60
- * @return void
61
- */
62
- recordHandler<E extends PostboyExecutor<R>, R>(executor: new (...args: any[]) => E, handler: PostboyExecutionHandler<R, E>): PostboyAbstractRegistrator;
63
- /**
64
- * A utility function that facilitates the recording and replaying of messages
65
- * using a ReplaySubject. This function is designed to handle messages of a
66
- * specific type and allows specifying a buffer size to determine how many
67
- * of the most recent messages should be replayed.
68
- *
69
- * @template T Extends the PostboyGenericMessage type, representing the type of message
70
- * to be recorded and replayed.
71
- * @param {MessageType<T>} type The constructor of the message type to be recorded and replayed.
72
- * @param {number} [bufferSize=1] The number of recent messages to retain in the ReplaySubject's buffer.
73
- * Defaults to 1 if not specified.
74
- * @returns The result of invoking the `record` method with the given message type and configured ReplaySubject.
75
- */
76
- recordReplay<T extends PostboyGenericMessage>(type: MessageType<T>, bufferSize?: number): PostboyAbstractRegistrator;
77
- /**
78
- * Represents a method that records a specific behavior associated with a message type.
79
- * It creates a `BehaviorSubject` initialized with the provided initial message
80
- * and associates it with the given message type using the `record` method.
81
- *
82
- * @template T - A type parameter extending `PostboyGenericMessage` that defines the message structure.
83
- * @param {MessageType<T>} type - The constructor function of the message type to be recorded.
84
- * @param {T} initial - The initial value of the message that will be set in the `BehaviorSubject`.
85
- * @returns {void} - This function does not return a value; instead, it modifies the internal state.
86
- */
87
- recordBehavior<T extends PostboyGenericMessage>(type: MessageType<T>, initial: T): PostboyAbstractRegistrator;
88
- /**
89
- * A function that creates and returns a new generic message recorder for a specific message type.
90
- *
91
- * @template T - A type parameter extending from `PostboyGenericMessage`.
92
- * @param {MessageType<T>} type - The constructor for the message type being recorded.
93
- * @returns {Subject<T>} A new instance of `Subject<T>` bound to the specified message type.
94
- */
95
- recordSubject<T extends PostboyGenericMessage>(type: MessageType<T>): this;
96
- }
97
- //# sourceMappingURL=postboy-abstract.registrator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"postboy-abstract.registrator.d.ts","sourceRoot":"","sources":["../src/postboy-abstract.registrator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAmB,UAAU,EAAuB,OAAO,EAAE,MAAM,MAAM,CAAC;AACjF,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAW,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAO7E,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,qBAAqB,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAErF,8BAAsB,0BAA0B;IAS5C,SAAS,CAAC,OAAO,EAAE,cAAc;IARnC,IAAI,SAAS,IAAI,MAAM,CAEtB;IACD,OAAO,CAAC,GAAG,CAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAGxB,OAAO,EAAE,cAAc,EACjC,SAAS,GAAE,MAAM,GAAG,IAAW;IAKjC;;;;;OAKG;IACI,gBAAgB,CAAC,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AC,EAAE,OAAO,EAAE,CAAC,GAAG,0BAA0B;IAKpH;;;;;;OAMG;IACI,aAAa,CAAC,CAAC,SAAS,qBAAqB,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;CAI3E"}
@@ -1,138 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PostboyAbstractRegistrator = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const postboy_generic_message_1 = require("./models/postboy-generic-message");
6
- const id_generator_1 = require("./utils/id.generator");
7
- const connect_message_executor_1 = require("./messages/connect-message.executor");
8
- const disconnect_message_executor_1 = require("./messages/disconnect-message.executor");
9
- const connect_executor_executor_1 = require("./messages/connect-executor.executor");
10
- const connect_handler_executor_1 = require("./messages/connect-handler.executor");
11
- class PostboyAbstractRegistrator {
12
- get namespace() {
13
- return this._namespace;
14
- }
15
- constructor(postboy, namespace = null) {
16
- this.postboy = postboy;
17
- this.ids = [];
18
- this.services = [];
19
- this._namespace = namespace !== null && namespace !== void 0 ? namespace : id_generator_1.IdGenerator.get();
20
- }
21
- /**
22
- * Registers a list of services to be used by the application.
23
- *
24
- * @param {IPostboyDependingService[]} services - An array of services to register.
25
- * @return {void} This method does not return a value.
26
- */
27
- registerServices(services) {
28
- this.services = services;
29
- }
30
- /**
31
- * Initiates the 'up' process for the current instance and all associated services.
32
- *
33
- * @return {void} Does not return a value.
34
- */
35
- up() {
36
- var _a;
37
- (_a = this._up) === null || _a === void 0 ? void 0 : _a.call(this);
38
- this.services.forEach((s) => s.up());
39
- }
40
- down() {
41
- this.services.forEach((s) => !!s.down && s.down());
42
- this.services = [];
43
- this.ids.forEach((id) => this.postboy.exec(new disconnect_message_executor_1.DisconnectMessage(id)));
44
- }
45
- /**
46
- * Records a type and its corresponding Subject<T> into the Postboy system and updates the internal identifiers.
47
- *
48
- * @param {MessageType<T>} type - A constructor for the generic message type T.
49
- * @param {Subject<T>} sub - The subject associated with the generic message type.
50
- * @return {this} Returns the current instance for method chaining.
51
- */
52
- record(type, sub) {
53
- this.ids.push((0, postboy_generic_message_1.checkId)(type));
54
- this.postboy.exec(new connect_message_executor_1.ConnectMessage(type, sub));
55
- return this;
56
- }
57
- /**
58
- * Records a message type with a specific subject and applies a transformation pipe to the subject.
59
- *
60
- * @param {MessageType<T>} type - The constructor of the message type to record, which extends PostboyGenericMessage.
61
- * @param {Subject<T>} sub - The Subject instance to associate with the message type.
62
- * @param {(s: Subject<T>) => Observable<T>} pipe - A function that takes the subject as input and returns an Observable with transformations applied.
63
- * @return {this} The current instance of the class for chaining.
64
- */
65
- recordWithPipe(type, sub, pipe) {
66
- this.ids.push((0, postboy_generic_message_1.checkId)(type));
67
- this.postboy.exec(new connect_message_executor_1.ConnectMessage(type, sub, pipe));
68
- return this;
69
- }
70
- /**
71
- * Records an executor associated with a specific type and execution logic.
72
- *
73
- * @param type The class constructor of the executor type to be recorded, which extends PostboyExecutor.
74
- * @param exec A callback function that executes the logic using an instance of the specified executor type.
75
- * @return void
76
- */
77
- recordExecutor(type, exec) {
78
- this.ids.push((0, postboy_generic_message_1.checkId)(type));
79
- this.postboy.exec(new connect_executor_executor_1.ConnectExecutor(type, exec));
80
- return this;
81
- }
82
- /**
83
- * Records a handler for a specific executor type.
84
- *
85
- * @param executor The constructor of the executor type, which extends `PostboyExecutor`.
86
- * @param handler The execution handler associated with the given executor type.
87
- * @return void
88
- */
89
- recordHandler(executor, handler) {
90
- this.ids.push((0, postboy_generic_message_1.checkId)(executor));
91
- this.postboy.exec(new connect_handler_executor_1.ConnectHandler(executor, handler));
92
- return this;
93
- }
94
- /**
95
- * A utility function that facilitates the recording and replaying of messages
96
- * using a ReplaySubject. This function is designed to handle messages of a
97
- * specific type and allows specifying a buffer size to determine how many
98
- * of the most recent messages should be replayed.
99
- *
100
- * @template T Extends the PostboyGenericMessage type, representing the type of message
101
- * to be recorded and replayed.
102
- * @param {MessageType<T>} type The constructor of the message type to be recorded and replayed.
103
- * @param {number} [bufferSize=1] The number of recent messages to retain in the ReplaySubject's buffer.
104
- * Defaults to 1 if not specified.
105
- * @returns The result of invoking the `record` method with the given message type and configured ReplaySubject.
106
- */
107
- recordReplay(type, bufferSize = 1) {
108
- this.record(type, new rxjs_1.ReplaySubject(bufferSize));
109
- return this;
110
- }
111
- /**
112
- * Represents a method that records a specific behavior associated with a message type.
113
- * It creates a `BehaviorSubject` initialized with the provided initial message
114
- * and associates it with the given message type using the `record` method.
115
- *
116
- * @template T - A type parameter extending `PostboyGenericMessage` that defines the message structure.
117
- * @param {MessageType<T>} type - The constructor function of the message type to be recorded.
118
- * @param {T} initial - The initial value of the message that will be set in the `BehaviorSubject`.
119
- * @returns {void} - This function does not return a value; instead, it modifies the internal state.
120
- */
121
- recordBehavior(type, initial) {
122
- this.record(type, new rxjs_1.BehaviorSubject(initial));
123
- return this;
124
- }
125
- /**
126
- * A function that creates and returns a new generic message recorder for a specific message type.
127
- *
128
- * @template T - A type parameter extending from `PostboyGenericMessage`.
129
- * @param {MessageType<T>} type - The constructor for the message type being recorded.
130
- * @returns {Subject<T>} A new instance of `Subject<T>` bound to the specified message type.
131
- */
132
- recordSubject(type) {
133
- this.record(type, new rxjs_1.Subject());
134
- return this;
135
- }
136
- }
137
- exports.PostboyAbstractRegistrator = PostboyAbstractRegistrator;
138
- //# sourceMappingURL=postboy-abstract.registrator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"postboy-abstract.registrator.js","sourceRoot":"","sources":["../src/postboy-abstract.registrator.ts"],"names":[],"mappings":";;;AACA,+BAAiF;AAGjF,8EAAkF;AAElF,uDAAmD;AACnD,kFAAqE;AACrE,wFAA2E;AAC3E,oFAAuE;AACvE,kFAAqE;AAIrE,MAAsB,0BAA0B;IAC9C,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAKD,YACY,OAAuB,EACjC,YAA2B,IAAI;QADrB,YAAO,GAAP,OAAO,CAAgB;QAL3B,QAAG,GAAa,EAAE,CAAC;QACn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@@ -1,157 +0,0 @@
1
- import { Observable, Subject } from 'rxjs';
2
- import { PostboyGenericMessage } from './models/postboy-generic-message';
3
- import { PostboyExecutor } from './models/postboy-executor';
4
- import { PostboyCallbackMessage } from './models/postboy-callback.message';
5
- import { MessageType, PostboyAbstractRegistrator } from './postboy-abstract.registrator';
6
- import { PostboyExecutionHandler } from './models/postboy-execution.handler';
7
- import { PostboyMiddleware } from './models/postboy-middleware';
8
- import { PostboyDependencyResolver } from './services/postboy-dependency.resolver';
9
- export declare class PostboyService {
10
- protected locked: Set<string>;
11
- private middleware;
12
- private store;
13
- private namespaceStore;
14
- private dependencyResolver;
15
- constructor(resolver?: PostboyDependencyResolver);
16
- private registerInfrastructureMessages;
17
- /**
18
- * Locks a specific message type to prevent further modifications or actions.
19
- *
20
- * @deprecated The method should be replaced with firing {@link LockMessage} message.
21
- * @param {MessageType<T>} type - The message type to be locked. It must extend from the `PostboyGenericMessage`.
22
- * @return {void} This method does not return a value.
23
- */
24
- lock<T extends PostboyGenericMessage>(type: MessageType<T>): void;
25
- /**
26
- * Unlocks a previously locked message type by removing its ID from the locked set.
27
- *
28
- * @deprecated The method should be replaced with firing {@link UnlockMessage} message.
29
- * @param {MessageType<T>} type - The message type to unlock, which is a generic type extending PostboyGenericMessage.
30
- * @return {void} This method does not return any value.
31
- */
32
- unlock<T extends PostboyGenericMessage>(type: MessageType<T>): void;
33
- /**
34
- * Adds a middleware to the middleware stack.
35
- *
36
- * @deprecated The method should be replaced with firing {@link AddMiddleware} message.
37
- * @param {PostboyMiddleware} middleware - The middleware instance to be added.
38
- * @return {void}
39
- */
40
- addMiddleware(middleware: PostboyMiddleware): void;
41
- /**
42
- * Removes a middleware from the current middleware stack.
43
- *
44
- * @deprecated The method should be replaced with firing {@link RemoveMiddleware} message.
45
- * @param {PostboyMiddleware} middleware - The middleware instance to be removed.
46
- * @return {void} No return value.
47
- */
48
- removeMiddleware(middleware: PostboyMiddleware): void;
49
- /**
50
- * Unregisters a message identified by the given ID from the store.
51
- *
52
- * @deprecated The method should be replaced with firing {@link DisconnectMessage} message.
53
- * @param {string} id - The unique identifier of the item to unregister.
54
- * @return {void} No value is returned.
55
- */
56
- unregister(id: string): void;
57
- /**
58
- * Fires a registered event and passes the message to its subscribers.
59
- *
60
- * @param {PostboyGenericMessage} message - The message object containing the event data.
61
- * @return {void} This method does not return a value.
62
- * @throws {Error} Throws an error if no registered event is found for the provided message ID.
63
- */
64
- fire(message: PostboyGenericMessage): void;
65
- /**
66
- * Triggers a callback function associated with a given message.
67
- *
68
- * @param {PostboyCallbackMessage<T>} message - The message object used to trigger the callback.
69
- * It contains details about the event and result subscription.
70
- * @param {(e: T) => void} [action] - Optional callback function to execute when the result of the message is emitted.
71
- * @return {void} This method does not return any value.
72
- */
73
- fireCallback<T>(message: PostboyCallbackMessage<T>, action?: (e: T) => void): Observable<T>;
74
- /**
75
- * Executes the provided executor function and returns its result.
76
- *
77
- * @param {PostboyExecutor<T>} executor The executor to be executed, which includes its identifier and logic.
78
- * @return {T} The resulting output from the executed executor function.
79
- * @throws {Error} If the specified executor is not registered.
80
- */
81
- exec<T>(executor: PostboyExecutor<T>): T;
82
- /**
83
- * Subscribes to a specific message type and returns an observable of that type.
84
- *
85
- * @param type The constructor function of the type that extends PostboyGenericMessage.
86
- * @return An Observable of the specified generic message type.
87
- */
88
- sub<T extends PostboyGenericMessage>(type: MessageType<T>): Observable<T>;
89
- /**
90
- * Subscribes to a specific message type and automatically unsubscribes after receiving the first message.
91
- *
92
- * @param type The type of message to subscribe to.
93
- * @return An observable that emits the first message of the specified type and then completes.
94
- */
95
- once<T extends PostboyGenericMessage>(type: MessageType<T>): Observable<T>;
96
- /**
97
- * Registers a given message type and its associated subject subscription with the system.
98
- *
99
- * @deprecated The method should be replaced with firing {@link ConnectMessage} message.
100
- * @param type The constructor function of the message type that extends the PostboyGenericMessage.
101
- * @param sub The Subject instance for the provided message type, used for managing subscriptions.
102
- * @return {void} No return value.
103
- */
104
- record<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>): void;
105
- /**
106
- * Registers a generic message type with a Subject and a transformation pipe.
107
- *
108
- * @deprecated The method should be replaced with firing {@link ConnectMessage} message.
109
- * @param {MessageType<T>} type - The constructor of the message type being registered.
110
- * @param {Subject<T>} sub - The Subject instance used to handle incoming messages of the specified type.
111
- * @param {(s: Subject<T>) => Observable<T>} pipe - A function that applies a transformation or processing logic to the Subject and returns an Observable.
112
- * @return {void} No return value.
113
- */
114
- recordWithPipe<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>, pipe: (s: Subject<T>) => Observable<T>): void;
115
- /**
116
- * Registers an executor for a specified message type.
117
- *
118
- * @deprecated The method should be replaced with firing {@link ConnectExecutor} message.
119
- * @param {MessageType<E>} type - The message type for which the executor is being registered.
120
- * @param {(e: E) => T} exec - The executor function that will handle messages of the specified type.
121
- * @return {void} This method does not return any value.
122
- */
123
- recordExecutor<E extends PostboyExecutor<T>, T>(type: MessageType<E>, exec: (e: E) => T): void;
124
- /**
125
- * Registers a handler for a specific executor type.
126
- *
127
- * @deprecated The method should be replaced with firing {@link ConnectHandler} message.
128
- * @param executor The constructor of the executor class that extends `PostboyExecutor<R>`.
129
- * @param handler An instance of `PostboyExecutionHandler<R, E>` that defines the logic for handling the executor.
130
- * @return void
131
- */
132
- recordHandler<E extends PostboyExecutor<R>, R>(executor: new (...args: any[]) => E, handler: PostboyExecutionHandler<R, E>): void;
133
- /**
134
- * Adds a namespace to the namespace store.
135
- *
136
- * @deprecated The method should be replaced with firing {@link AddNamespace} message.
137
- * @param {string} space - The name of the namespace to be added.
138
- * @return {PostboyAbstractRegistrator} The instance of the namespace after adding the specified namespace.
139
- */
140
- addNamespace(space: string): PostboyAbstractRegistrator;
141
- /**
142
- * Removes the specified namespace from the namespace store.
143
- *
144
- * @deprecated The method should be replaced with firing {@link EliminateNamespace} message.
145
- * @param {string} space - The name of the namespace to be removed.
146
- * @return {void} This method does not return a value.
147
- */
148
- eliminateNamespace(space: string): void;
149
- /**
150
- * Disposes of resources and cleans up any internal components or stores associated with the instance.
151
- * This method ensures that all resources are properly released to avoid memory leaks.
152
- *
153
- * @return {void} This method does not return a value.
154
- */
155
- dispose(): void;
156
- }
157
- //# sourceMappingURL=postboy.service.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"postboy.service.d.ts","sourceRoot":"","sources":["../src/postboy.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,UAAU,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAClD,OAAO,EAAW,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAElF,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AACzF,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAC;AAenF,qBAAa,cAAc;IACzB,SAAS,CAAC,MAAM,cAAqB;IACrC,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,KAAK,CAAsB;IACnC,OAAO,CAAC,cAAc,CAAwB;IAC9C,OAAO,CAAC,kBAAkB,CAA4B;gBAE1C,QAAQ,CAAC,EAAE,yBAAyB;IAQhD,OAAO,CAAC,8BAA8B;IA4BtC;;;;;;OAMG;IACI,IAAI,CAAC,CAAC,SAAS,qBAAqB,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI;IAIxE;;;;;;OAMG;IACI,MAAM,CAAC,CAAC,SAAS,qBAAqB,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI;IAI1E;;;;;;OAMG;IACI,aAAa,CAAC,UAAU,EAAE,iBAAiB,GAA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AAI,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI;IAIrG;;;;;;;OAOG;IACI,aAAa,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,EAClD,QAAQ,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EACnC,OAAO,EAAE,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,GACrC,IAAI;IAIP;;;;;;OAMG;IACI,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,0BAA0B;IAI9D;;;;;;OAMG;IACI,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI9C;;;;;OAKG;IACI,OAAO,IAAI,IAAI;CAKvB"}
@@ -1,235 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PostboyService = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const postboy_generic_message_1 = require("./models/postboy-generic-message");
6
- const postboy_subscription_1 = require("./models/postboy-subscription");
7
- const postboy_dependency_resolver_1 = require("./services/postboy-dependency.resolver");
8
- const add_namespace_executor_1 = require("./messages/add-namespace.executor");
9
- const eliminate_namespace_executor_1 = require("./messages/eliminate-namespace.executor");
10
- const add_middleware_executor_1 = require("./messages/add-middleware.executor");
11
- const remove_middleware_executor_1 = require("./messages/remove-middleware.executor");
12
- const lock_message_executor_1 = require("./messages/lock-message.executor");
13
- const unlock_message_executor_1 = require("./messages/unlock-message.executor");
14
- const disconnect_message_executor_1 = require("./messages/disconnect-message.executor");
15
- const connect_message_executor_1 = require("./messages/connect-message.executor");
16
- const connect_executor_executor_1 = require("./messages/connect-executor.executor");
17
- const connect_handler_executor_1 = require("./messages/connect-handler.executor");
18
- class PostboyService {
19
- constructor(resolver) {
20
- this.locked = new Set();
21
- this.dependencyResolver = resolver || new postboy_dependency_resolver_1.PostboyDependencyResolver();
22
- this.middleware = this.dependencyResolver.getMiddlewareService();
23
- this.store = this.dependencyResolver.getMessageStore();
24
- this.namespaceStore = this.dependencyResolver.getNamespaceStore();
25
- this.registerInfrastructureMessages();
26
- }
27
- registerInfrastructureMessages() {
28
- this.store.registerExecutor(disconnect_message_executor_1.DisconnectMessage.ID, (e) => this.store.unregister(e.messageId));
29
- this.store.registerExecutor(unlock_message_executor_1.UnlockMessage.ID, (e) => this.locked.delete((0, postboy_generic_message_1.checkId)(e.type)));
30
- this.store.registerExecutor(lock_message_executor_1.LockMessage.ID, (e) => this.locked.add((0, postboy_generic_message_1.checkId)(e.type)));
31
- this.store.registerExecutor(add_middleware_executor_1.AddMiddleware.ID, (e) => this.middleware.addMiddleware(e.middleware));
32
- this.store.registerExecutor(remove_middleware_executor_1.RemoveMiddleware.ID, (e) => this.middleware.removeMiddleware(e.middleware));
33
- this.store.registerExecutor(add_namespace_executor_1.AddNamespace.ID, (e) => this.namespaceStore.addSpace(e.space, this));
34
- this.store.registerExecutor(eliminate_namespace_executor_1.EliminateNamespace.ID, (e) => this.namespaceStore.eliminateSpace(e.space));
35
- this.store.registerExecutor(connect_message_executor_1.ConnectMessage.ID, (e) => {
36
- const { type, sub, pipe } = e;
37
- this.store.registerMessage((0, postboy_generic_message_1.checkId)(type), new postboy_subscription_1.PostboySubscription(sub, pipe));
38
- });
39
- this.store.registerExecutor(connect_executor_executor_1.ConnectExecutor.ID, (e) => {
40
- const { type, exec } = e;
41
- this.store.registerExecutor((0, postboy_generic_message_1.checkId)(type), exec);
42
- });
43
- this.store.registerExecutor(connect_handler_executor_1.ConnectHandler.ID, (e) => {
44
- const { executor, handler } = e;
45
- this.store.registerExecutor((0, postboy_generic_message_1.checkId)(executor), (e) => handler.handle(e));
46
- });
47
- }
48
- /**
49
- * Locks a specific message type to prevent further modifications or actions.
50
- *
51
- * @deprecated The method should be replaced with firing {@link LockMessage} message.
52
- * @param {MessageType<T>} type - The message type to be locked. It must extend from the `PostboyGenericMessage`.
53
- * @return {void} This method does not return a value.
54
- */
55
- lock(type) {
56
- this.locked.add((0, postboy_generic_message_1.checkId)(type));
57
- }
58
- /**
59
- * Unlocks a previously locked message type by removing its ID from the locked set.
60
- *
61
- * @deprecated The method should be replaced with firing {@link UnlockMessage} message.
62
- * @param {MessageType<T>} type - The message type to unlock, which is a generic type extending PostboyGenericMessage.
63
- * @return {void} This method does not return any value.
64
- */
65
- unlock(type) {
66
- this.locked.delete((0, postboy_generic_message_1.checkId)(type));
67
- }
68
- /**
69
- * Adds a middleware to the middleware stack.
70
- *
71
- * @deprecated The method should be replaced with firing {@link AddMiddleware} message.
72
- * @param {PostboyMiddleware} middleware - The middleware instance to be added.
73
- * @return {void}
74
- */
75
- addMiddleware(middleware) {
76
- return this.middleware.addMiddleware(middleware);
77
- }
78
- /**
79
- * Removes a middleware from the current middleware stack.
80
- *
81
- * @deprecated The method should be replaced with firing {@link RemoveMiddleware} message.
82
- * @param {PostboyMiddleware} middleware - The middleware instance to be removed.
83
- * @return {void} No return value.
84
- */
85
- removeMiddleware(middleware) {
86
- return this.middleware.removeMiddleware(middleware);
87
- }
88
- /**
89
- * Unregisters a message identified by the given ID from the store.
90
- *
91
- * @deprecated The method should be replaced with firing {@link DisconnectMessage} message.
92
- * @param {string} id - The unique identifier of the item to unregister.
93
- * @return {void} No value is returned.
94
- */
95
- unregister(id) {
96
- return this.store.unregister(id);
97
- }
98
- /**
99
- * Fires a registered event and passes the message to its subscribers.
100
- *
101
- * @param {PostboyGenericMessage} message - The message object containing the event data.
102
- * @return {void} This method does not return a value.
103
- * @throws {Error} Throws an error if no registered event is found for the provided message ID.
104
- */
105
- fire(message) {
106
- this.middleware.manage(message);
107
- if (!this.locked.has(message.id))
108
- this.store.getMessage(message.id, message.constructor.name).fire(message);
109
- }
110
- /**
111
- * Triggers a callback function associated with a given message.
112
- *
113
- * @param {PostboyCallbackMessage<T>} message - The message object used to trigger the callback.
114
- * It contains details about the event and result subscription.
115
- * @param {(e: T) => void} [action] - Optional callback function to execute when the result of the message is emitted.
116
- * @return {void} This method does not return any value.
117
- */
118
- fireCallback(message, action) {
119
- this.middleware.manage(message);
120
- this.store.callbackFired(message);
121
- message.result.subscribe(action);
122
- if (!this.locked.has(message.id))
123
- setTimeout(() => this.store.getMessage(message.id, message.constructor.name).fire(message));
124
- return message.result;
125
- }
126
- /**
127
- * Executes the provided executor function and returns its result.
128
- *
129
- * @param {PostboyExecutor<T>} executor The executor to be executed, which includes its identifier and logic.
130
- * @return {T} The resulting output from the executed executor function.
131
- * @throws {Error} If the specified executor is not registered.
132
- */
133
- exec(executor) {
134
- this.middleware.manage(executor);
135
- return this.store.getExecutor(executor.id)(executor);
136
- }
137
- /**
138
- * Subscribes to a specific message type and returns an observable of that type.
139
- *
140
- * @param type The constructor function of the type that extends PostboyGenericMessage.
141
- * @return An Observable of the specified generic message type.
142
- */
143
- sub(type) {
144
- return this.store.getMessage((0, postboy_generic_message_1.checkId)(type), type.name).sub();
145
- }
146
- /**
147
- * Subscribes to a specific message type and automatically unsubscribes after receiving the first message.
148
- *
149
- * @param type The type of message to subscribe to.
150
- * @return An observable that emits the first message of the specified type and then completes.
151
- */
152
- once(type) {
153
- return this.sub(type).pipe((0, rxjs_1.first)());
154
- }
155
- /**
156
- * Registers a given message type and its associated subject subscription with the system.
157
- *
158
- * @deprecated The method should be replaced with firing {@link ConnectMessage} message.
159
- * @param type The constructor function of the message type that extends the PostboyGenericMessage.
160
- * @param sub The Subject instance for the provided message type, used for managing subscriptions.
161
- * @return {void} No return value.
162
- */
163
- record(type, sub) {
164
- this.store.registerMessage((0, postboy_generic_message_1.checkId)(type), new postboy_subscription_1.PostboySubscription(sub, (s) => s.asObservable()));
165
- }
166
- /**
167
- * Registers a generic message type with a Subject and a transformation pipe.
168
- *
169
- * @deprecated The method should be replaced with firing {@link ConnectMessage} message.
170
- * @param {MessageType<T>} type - The constructor of the message type being registered.
171
- * @param {Subject<T>} sub - The Subject instance used to handle incoming messages of the specified type.
172
- * @param {(s: Subject<T>) => Observable<T>} pipe - A function that applies a transformation or processing logic to the Subject and returns an Observable.
173
- * @return {void} No return value.
174
- */
175
- recordWithPipe(type, sub, pipe) {
176
- this.store.registerMessage((0, postboy_generic_message_1.checkId)(type), new postboy_subscription_1.PostboySubscription(sub, pipe));
177
- }
178
- /**
179
- * Registers an executor for a specified message type.
180
- *
181
- * @deprecated The method should be replaced with firing {@link ConnectExecutor} message.
182
- * @param {MessageType<E>} type - The message type for which the executor is being registered.
183
- * @param {(e: E) => T} exec - The executor function that will handle messages of the specified type.
184
- * @return {void} This method does not return any value.
185
- */
186
- recordExecutor(type, exec) {
187
- this.store.registerExecutor((0, postboy_generic_message_1.checkId)(type), exec);
188
- }
189
- /**
190
- * Registers a handler for a specific executor type.
191
- *
192
- * @deprecated The method should be replaced with firing {@link ConnectHandler} message.
193
- * @param executor The constructor of the executor class that extends `PostboyExecutor<R>`.
194
- * @param handler An instance of `PostboyExecutionHandler<R, E>` that defines the logic for handling the executor.
195
- * @return void
196
- */
197
- recordHandler(executor, handler) {
198
- this.store.registerExecutor((0, postboy_generic_message_1.checkId)(executor), (e) => handler.handle(e));
199
- }
200
- /**
201
- * Adds a namespace to the namespace store.
202
- *
203
- * @deprecated The method should be replaced with firing {@link AddNamespace} message.
204
- * @param {string} space - The name of the namespace to be added.
205
- * @return {PostboyAbstractRegistrator} The instance of the namespace after adding the specified namespace.
206
- */
207
- addNamespace(space) {
208
- return this.namespaceStore.addSpace(space, this);
209
- }
210
- /**
211
- * Removes the specified namespace from the namespace store.
212
- *
213
- * @deprecated The method should be replaced with firing {@link EliminateNamespace} message.
214
- * @param {string} space - The name of the namespace to be removed.
215
- * @return {void} This method does not return a value.
216
- */
217
- eliminateNamespace(space) {
218
- var _a;
219
- return (_a = this.namespaceStore) === null || _a === void 0 ? void 0 : _a.eliminateSpace(space);
220
- }
221
- /**
222
- * Disposes of resources and cleans up any internal components or stores associated with the instance.
223
- * This method ensures that all resources are properly released to avoid memory leaks.
224
- *
225
- * @return {void} This method does not return a value.
226
- */
227
- dispose() {
228
- var _a;
229
- (_a = this.namespaceStore) === null || _a === void 0 ? void 0 : _a.dispose();
230
- this.store.dispose();
231
- this.middleware.dispose();
232
- }
233
- }
234
- exports.PostboyService = PostboyService;
235
- //# sourceMappingURL=postboy.service.js.map