@zdavison/matador 2.0.8 → 2.0.10

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 (77) hide show
  1. package/dist/index.d.cts +1 -1
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/package.json +6 -2
  5. package/examples/config.ts +0 -126
  6. package/examples/event.ts +0 -26
  7. package/examples/order-event.json +0 -19
  8. package/src/checkpoint/context.test.ts +0 -510
  9. package/src/checkpoint/context.ts +0 -213
  10. package/src/checkpoint/index.ts +0 -30
  11. package/src/checkpoint/stores/memory.ts +0 -47
  12. package/src/checkpoint/stores/noop.ts +0 -22
  13. package/src/checkpoint/stores/stores.test.ts +0 -177
  14. package/src/checkpoint/types.ts +0 -147
  15. package/src/codec/codec.ts +0 -42
  16. package/src/codec/header-aware-codec.ts +0 -41
  17. package/src/codec/index.ts +0 -11
  18. package/src/codec/json-codec.ts +0 -69
  19. package/src/codec/rabbitmq-codec.test.ts +0 -516
  20. package/src/codec/rabbitmq-codec.ts +0 -336
  21. package/src/core/fanout.test.ts +0 -1350
  22. package/src/core/fanout.ts +0 -184
  23. package/src/core/index.ts +0 -12
  24. package/src/core/matador.test.ts +0 -575
  25. package/src/core/matador.ts +0 -357
  26. package/src/core/shutdown.test.ts +0 -853
  27. package/src/core/shutdown.ts +0 -165
  28. package/src/errors/checkpoint-errors.ts +0 -62
  29. package/src/errors/has-description.ts +0 -25
  30. package/src/errors/index.ts +0 -58
  31. package/src/errors/matador-errors.ts +0 -477
  32. package/src/errors/retry-errors.test.ts +0 -175
  33. package/src/errors/retry-errors.ts +0 -188
  34. package/src/hooks/index.ts +0 -14
  35. package/src/hooks/safe-hooks.ts +0 -200
  36. package/src/hooks/types.ts +0 -226
  37. package/src/index.ts +0 -241
  38. package/src/pipeline/index.ts +0 -2
  39. package/src/pipeline/pipeline.test.ts +0 -1377
  40. package/src/pipeline/pipeline.ts +0 -393
  41. package/src/retry/index.ts +0 -4
  42. package/src/retry/policy.ts +0 -46
  43. package/src/retry/standard-policy.test.ts +0 -290
  44. package/src/retry/standard-policy.ts +0 -156
  45. package/src/schema/index.ts +0 -16
  46. package/src/schema/registry.test.ts +0 -339
  47. package/src/schema/registry.ts +0 -229
  48. package/src/schema/types.test.ts +0 -280
  49. package/src/schema/types.ts +0 -217
  50. package/src/topology/builder.test.ts +0 -451
  51. package/src/topology/builder.ts +0 -238
  52. package/src/topology/index.ts +0 -19
  53. package/src/topology/types.ts +0 -183
  54. package/src/transport/capabilities.ts +0 -88
  55. package/src/transport/connection-manager.ts +0 -218
  56. package/src/transport/index.ts +0 -42
  57. package/src/transport/local/local-transport.test.ts +0 -262
  58. package/src/transport/local/local-transport.ts +0 -330
  59. package/src/transport/multi/multi-transport.test.ts +0 -320
  60. package/src/transport/multi/multi-transport.ts +0 -294
  61. package/src/transport/rabbitmq/rabbitmq-transport.test.ts +0 -120
  62. package/src/transport/rabbitmq/rabbitmq-transport.ts +0 -782
  63. package/src/transport/transport.ts +0 -200
  64. package/src/types/common.ts +0 -53
  65. package/src/types/dispatcher.ts +0 -18
  66. package/src/types/envelope.ts +0 -244
  67. package/src/types/event.test.ts +0 -157
  68. package/src/types/event.ts +0 -112
  69. package/src/types/index.ts +0 -62
  70. package/src/types/subscriber.ts +0 -333
  71. package/test/e2e/multi-transport.e2e.test.ts +0 -237
  72. package/test/e2e/rabbitmq-transport.e2e.test.ts +0 -618
  73. package/test/e2e/transport-compliance.e2e.test.ts +0 -506
  74. package/test/integration/matador.integration.test.ts +0 -634
  75. package/tsconfig.json +0 -29
  76. package/tsconfig.tsbuildinfo +0 -1
  77. package/tsup.config.ts +0 -13
@@ -1,165 +0,0 @@
1
- import { type Logger, consoleLogger } from '../hooks/index.js';
2
-
3
- /**
4
- * Shutdown state.
5
- */
6
- export type ShutdownState =
7
- | 'running'
8
- | 'stopping-receive'
9
- | 'waiting-handlers'
10
- | 'stopping-enqueue'
11
- | 'disconnecting'
12
- | 'stopped';
13
-
14
- /**
15
- * Configuration for shutdown manager.
16
- */
17
- export interface ShutdownConfig {
18
- /** Timeout for graceful shutdown in milliseconds */
19
- readonly gracefulShutdownTimeout: number;
20
-
21
- /** Polling interval when waiting for handlers to idle */
22
- readonly idlePollingInterval: number;
23
-
24
- /** Logger for shutdown events (defaults to console) */
25
- readonly logger: Logger;
26
- }
27
-
28
- /**
29
- * Default shutdown configuration.
30
- */
31
- export const defaultShutdownConfig: ShutdownConfig = {
32
- gracefulShutdownTimeout: 30000,
33
- idlePollingInterval: 1000,
34
- logger: consoleLogger,
35
- };
36
-
37
- /**
38
- * Handler state tracking.
39
- */
40
- export interface HandlersState {
41
- readonly eventsBeingProcessed: number;
42
- readonly eventsBeingEnqueued: number;
43
- readonly isIdle: boolean;
44
- }
45
-
46
- /**
47
- * Manages graceful shutdown of Matador.
48
- *
49
- * Shutdown sequence:
50
- * 1. Stop receiving new messages
51
- * 2. Wait for in-flight processing to complete
52
- * 3. Stop accepting new enqueue requests
53
- * 4. Disconnect transport
54
- */
55
- export class ShutdownManager {
56
- private _state: ShutdownState = 'running';
57
- private readonly config: ShutdownConfig;
58
- private eventsBeingProcessed = 0;
59
- private acceptingEnqueue = true;
60
-
61
- constructor(
62
- private readonly getEnqueueCount: () => number,
63
- private readonly stopReceiving: () => Promise<void>,
64
- private readonly disconnectTransport: () => Promise<void>,
65
- config: Partial<ShutdownConfig> = {},
66
- ) {
67
- this.config = { ...defaultShutdownConfig, ...config };
68
- }
69
-
70
- /**
71
- * Current shutdown state.
72
- */
73
- get state(): ShutdownState {
74
- return this._state;
75
- }
76
-
77
- /**
78
- * Whether enqueue is currently allowed.
79
- */
80
- get isEnqueueAllowed(): boolean {
81
- return this.acceptingEnqueue;
82
- }
83
-
84
- /**
85
- * Gets current handler state.
86
- */
87
- getHandlersState(): HandlersState {
88
- const eventsBeingEnqueued = this.getEnqueueCount();
89
- return {
90
- eventsBeingProcessed: this.eventsBeingProcessed,
91
- eventsBeingEnqueued,
92
- isIdle: this.eventsBeingProcessed === 0 && eventsBeingEnqueued === 0,
93
- };
94
- }
95
-
96
- /**
97
- * Increment processing counter.
98
- */
99
- incrementProcessing(): void {
100
- this.eventsBeingProcessed++;
101
- }
102
-
103
- /**
104
- * Decrement processing counter.
105
- */
106
- decrementProcessing(): void {
107
- this.eventsBeingProcessed--;
108
- }
109
-
110
- /**
111
- * Performs graceful shutdown.
112
- */
113
- async shutdown(): Promise<void> {
114
- if (this._state !== 'running') {
115
- return;
116
- }
117
-
118
- // 1. Stop receiving new messages
119
- this._state = 'stopping-receive';
120
- await this.stopReceiving();
121
-
122
- // 2. Wait for handlers to idle
123
- this._state = 'waiting-handlers';
124
- await this.waitForIdle();
125
-
126
- // 3. Stop accepting new enqueue requests
127
- this._state = 'stopping-enqueue';
128
- this.acceptingEnqueue = false;
129
-
130
- // 4. Disconnect transport
131
- this._state = 'disconnecting';
132
- await this.disconnectTransport();
133
-
134
- this._state = 'stopped';
135
- }
136
-
137
- /**
138
- * Forcefully stops without waiting.
139
- */
140
- async forceStop(): Promise<void> {
141
- this.acceptingEnqueue = false;
142
- await this.stopReceiving();
143
- await this.disconnectTransport();
144
- this._state = 'stopped';
145
- }
146
-
147
- private async waitForIdle(): Promise<void> {
148
- const deadline = Date.now() + this.config.gracefulShutdownTimeout;
149
-
150
- while (!this.getHandlersState().isIdle) {
151
- if (Date.now() > deadline) {
152
- this.config.logger.warn(
153
- `[Matador] 🟡 Shutdown timeout reached with ${this.eventsBeingProcessed} events still processing`,
154
- );
155
- break;
156
- }
157
-
158
- await this.sleep(this.config.idlePollingInterval);
159
- }
160
- }
161
-
162
- private sleep(ms: number): Promise<void> {
163
- return new Promise((resolve) => setTimeout(resolve, ms));
164
- }
165
- }
@@ -1,62 +0,0 @@
1
- import { MatadorError } from './matador-errors.js';
2
-
3
- /**
4
- * Thrown when a duplicate io() key is used within a single subscriber execution.
5
- * Each io() call must have a unique key to prevent cache collisions.
6
- */
7
- export class DuplicateIoKeyError extends MatadorError {
8
- readonly description =
9
- 'The same io() key was used multiple times in a single subscriber execution. ' +
10
- 'Each io() call must have a unique key to ensure correct checkpoint behavior. ' +
11
- 'ACTION: Ensure all io() keys are unique within the subscriber. ' +
12
- 'For dynamic operations (e.g., loops), include a unique identifier in the key ' +
13
- '(e.g., `process-item-${item.id}`).';
14
-
15
- constructor(
16
- public readonly key: string,
17
- public readonly subscriberName: string,
18
- ) {
19
- super(
20
- `Duplicate io key "${key}" in subscriber "${subscriberName}". ` +
21
- `Each io() call must have a unique key.`,
22
- );
23
- }
24
- }
25
-
26
- /**
27
- * Thrown when checkpoint store operations fail.
28
- */
29
- export class CheckpointStoreError extends MatadorError {
30
- readonly description =
31
- 'A checkpoint store operation failed. This may cause issues with resumable subscribers. ' +
32
- 'ACTION: Check the underlying storage system (Redis, etc.) for connectivity issues. ' +
33
- 'The subscriber may re-execute operations that were already completed.';
34
-
35
- constructor(
36
- public readonly operation: 'get' | 'set' | 'delete',
37
- public readonly envelopeId: string,
38
- public readonly cause: Error,
39
- ) {
40
- super(
41
- `Checkpoint store ${operation} failed for envelope "${envelopeId}": ${cause.message}`,
42
- );
43
- }
44
- }
45
-
46
- /**
47
- * Type guard for DuplicateIoKeyError.
48
- */
49
- export function isDuplicateIoKeyError(
50
- error: unknown,
51
- ): error is DuplicateIoKeyError {
52
- return error instanceof DuplicateIoKeyError;
53
- }
54
-
55
- /**
56
- * Type guard for CheckpointStoreError.
57
- */
58
- export function isCheckpointStoreError(
59
- error: unknown,
60
- ): error is CheckpointStoreError {
61
- return error instanceof CheckpointStoreError;
62
- }
@@ -1,25 +0,0 @@
1
- /**
2
- * Interface for errors that provide a human-readable description.
3
- * The description explains what the error means and what actions
4
- * users should take when encountering it in logs/observability.
5
- */
6
- export interface HasDescription {
7
- /**
8
- * Human-readable description of the error type.
9
- * Intended for logging and observability to help users understand
10
- * the error and determine appropriate remediation steps.
11
- */
12
- readonly description: string;
13
- }
14
-
15
- /**
16
- * Type guard to check if an error implements HasDescription.
17
- */
18
- export function hasDescription(error: unknown): error is HasDescription {
19
- return (
20
- typeof error === 'object' &&
21
- error !== null &&
22
- 'description' in error &&
23
- typeof (error as HasDescription).description === 'string'
24
- );
25
- }
@@ -1,58 +0,0 @@
1
- export type { HasDescription } from './has-description.js';
2
- export { hasDescription } from './has-description.js';
3
-
4
- export {
5
- assertEvent,
6
- DontRetry,
7
- DoRetry,
8
- EventAssertionError,
9
- isAssertionError,
10
- isDontRetry,
11
- isDoRetry,
12
- RetryControlError,
13
- } from './retry-errors.js';
14
-
15
- export {
16
- // Base class
17
- MatadorError,
18
- isMatadorError,
19
- // Lifecycle errors
20
- NotStartedError,
21
- isNotStartedError,
22
- ShutdownInProgressError,
23
- // Transport errors
24
- TransportNotConnectedError,
25
- isTransportNotConnectedError,
26
- TransportClosedError,
27
- TransportSendError,
28
- AllTransportsFailedError,
29
- DelayedMessagesNotSupportedError,
30
- // Schema & configuration errors
31
- EventNotRegisteredError,
32
- isEventNotRegisteredError,
33
- SubscriberNotRegisteredError,
34
- isSubscriberNotRegisteredError,
35
- NoSubscribersExistError,
36
- InvalidSchemaError,
37
- SubscriberIsStubError,
38
- LocalTransportCannotProcessStubError,
39
- // Queue errors
40
- QueueNotFoundError,
41
- // Event validation errors
42
- InvalidEventError,
43
- // Message processing errors
44
- MessageMaybePoisonedError,
45
- isMessageMaybePoisonedError,
46
- IdempotentMessageCannotRetryError,
47
- isIdempotentMessageCannotRetryError,
48
- // Timeout errors
49
- TimeoutError,
50
- } from './matador-errors.js';
51
-
52
- export {
53
- // Checkpoint errors
54
- CheckpointStoreError,
55
- DuplicateIoKeyError,
56
- isCheckpointStoreError,
57
- isDuplicateIoKeyError,
58
- } from './checkpoint-errors.js';