@gravito/core 1.6.1 → 2.0.1

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 (168) hide show
  1. package/README.md +100 -6
  2. package/README.zh-TW.md +101 -6
  3. package/dist/Application.d.ts +256 -0
  4. package/dist/CommandKernel.d.ts +33 -0
  5. package/dist/ConfigManager.d.ts +65 -0
  6. package/dist/Container/RequestScopeManager.d.ts +62 -0
  7. package/dist/Container/RequestScopeMetrics.d.ts +144 -0
  8. package/dist/Container.d.ts +153 -0
  9. package/dist/ErrorHandler.d.ts +66 -0
  10. package/dist/Event.d.ts +5 -0
  11. package/dist/EventManager.d.ts +123 -0
  12. package/dist/GlobalErrorHandlers.d.ts +47 -0
  13. package/dist/GravitoServer.d.ts +28 -0
  14. package/dist/HookManager.d.ts +435 -0
  15. package/dist/Listener.d.ts +4 -0
  16. package/dist/Logger.d.ts +20 -0
  17. package/dist/PlanetCore.d.ts +402 -0
  18. package/dist/RequestContext.d.ts +97 -0
  19. package/dist/Route.d.ts +36 -0
  20. package/dist/Router.d.ts +270 -0
  21. package/dist/ServiceProvider.d.ts +178 -0
  22. package/dist/adapters/GravitoEngineAdapter.d.ts +27 -0
  23. package/dist/adapters/bun/AdaptiveAdapter.d.ts +99 -0
  24. package/dist/adapters/bun/BunContext.d.ts +54 -0
  25. package/dist/adapters/bun/BunNativeAdapter.d.ts +66 -0
  26. package/dist/adapters/bun/BunRequest.d.ts +31 -0
  27. package/dist/adapters/bun/BunWebSocketHandler.d.ts +48 -0
  28. package/dist/adapters/bun/RadixNode.d.ts +19 -0
  29. package/dist/adapters/bun/RadixRouter.d.ts +32 -0
  30. package/dist/adapters/bun/index.d.ts +7 -0
  31. package/dist/adapters/bun/types.d.ts +20 -0
  32. package/dist/adapters/index.d.ts +12 -0
  33. package/dist/adapters/types.d.ts +235 -0
  34. package/dist/binary/BinaryUtils.d.ts +105 -0
  35. package/dist/binary/index.d.ts +5 -0
  36. package/dist/cli/queue-commands.d.ts +6 -0
  37. package/dist/compat/async-local-storage.browser.d.ts +9 -0
  38. package/dist/compat/async-local-storage.d.ts +7 -0
  39. package/dist/compat/crypto.browser.d.ts +5 -0
  40. package/dist/compat/crypto.d.ts +6 -0
  41. package/dist/compat.d.ts +23 -1
  42. package/dist/compat.js +3 -0
  43. package/dist/compat.js.map +9 -0
  44. package/dist/engine/AOTRouter.d.ts +139 -0
  45. package/dist/engine/FastContext.d.ts +141 -0
  46. package/dist/engine/Gravito.d.ts +131 -0
  47. package/dist/engine/MinimalContext.d.ts +102 -0
  48. package/dist/engine/analyzer.d.ts +113 -0
  49. package/dist/engine/constants.d.ts +23 -0
  50. package/dist/engine/index.d.ts +14 -910
  51. package/dist/engine/index.js +623 -622
  52. package/dist/engine/index.js.map +23 -0
  53. package/dist/engine/path.d.ts +26 -0
  54. package/dist/engine/pool.d.ts +83 -0
  55. package/dist/engine/types.d.ts +149 -0
  56. package/dist/error-handling/RequestScopeErrorContext.d.ts +126 -0
  57. package/dist/events/BackpressureManager.d.ts +215 -0
  58. package/dist/events/CircuitBreaker.d.ts +229 -0
  59. package/dist/events/DeadLetterQueue.d.ts +219 -0
  60. package/dist/events/EventBackend.d.ts +12 -0
  61. package/dist/events/EventOptions.d.ts +204 -0
  62. package/dist/events/EventPriorityQueue.d.ts +63 -0
  63. package/dist/events/FlowControlStrategy.d.ts +109 -0
  64. package/dist/events/IdempotencyCache.d.ts +60 -0
  65. package/dist/events/MessageQueueBridge.d.ts +184 -0
  66. package/dist/events/PriorityEscalationManager.d.ts +82 -0
  67. package/dist/events/RetryScheduler.d.ts +104 -0
  68. package/dist/events/WorkerPool.d.ts +98 -0
  69. package/dist/events/WorkerPoolConfig.d.ts +153 -0
  70. package/dist/events/WorkerPoolMetrics.d.ts +65 -0
  71. package/dist/events/aggregation/AggregationWindow.d.ts +77 -0
  72. package/dist/events/aggregation/DeduplicationManager.d.ts +135 -0
  73. package/dist/events/aggregation/EventAggregationManager.d.ts +108 -0
  74. package/dist/events/aggregation/EventBatcher.d.ts +99 -0
  75. package/dist/events/aggregation/index.d.ts +10 -0
  76. package/dist/events/aggregation/types.d.ts +117 -0
  77. package/dist/events/index.d.ts +26 -0
  78. package/dist/events/observability/EventMetrics.d.ts +132 -0
  79. package/dist/events/observability/EventTracer.d.ts +68 -0
  80. package/dist/events/observability/EventTracing.d.ts +161 -0
  81. package/dist/events/observability/OTelEventMetrics.d.ts +332 -0
  82. package/dist/events/observability/ObservableHookManager.d.ts +108 -0
  83. package/dist/events/observability/StreamWorkerMetrics.d.ts +76 -0
  84. package/dist/events/observability/index.d.ts +24 -0
  85. package/dist/events/observability/metrics-types.d.ts +16 -0
  86. package/dist/events/queue-core.d.ts +77 -0
  87. package/dist/events/task-executor.d.ts +51 -0
  88. package/dist/events/types.d.ts +134 -0
  89. package/dist/exceptions/AuthenticationException.d.ts +8 -0
  90. package/dist/exceptions/AuthorizationException.d.ts +8 -0
  91. package/dist/exceptions/CircularDependencyException.d.ts +9 -0
  92. package/dist/exceptions/GravitoException.d.ts +23 -0
  93. package/dist/exceptions/HttpException.d.ts +9 -0
  94. package/dist/exceptions/ModelNotFoundException.d.ts +10 -0
  95. package/dist/exceptions/ValidationException.d.ts +22 -0
  96. package/dist/exceptions/index.d.ts +7 -0
  97. package/dist/ffi/NativeAccelerator.d.ts +69 -0
  98. package/dist/ffi/NativeHasher.d.ts +139 -0
  99. package/dist/ffi/cbor-fallback.d.ts +96 -0
  100. package/dist/ffi/hash-fallback.d.ts +33 -0
  101. package/dist/ffi/index.d.ts +10 -0
  102. package/dist/ffi/index.js +131 -0
  103. package/dist/ffi/index.js.map +11 -0
  104. package/dist/ffi/types.d.ts +135 -0
  105. package/dist/health/HealthProvider.d.ts +67 -0
  106. package/dist/helpers/Arr.d.ts +19 -0
  107. package/dist/helpers/Str.d.ts +38 -0
  108. package/dist/helpers/data.d.ts +25 -0
  109. package/dist/helpers/errors.d.ts +34 -0
  110. package/dist/helpers/response.d.ts +41 -0
  111. package/dist/helpers.d.ts +338 -0
  112. package/dist/hooks/ActionManager.d.ts +132 -0
  113. package/dist/hooks/AsyncDetector.d.ts +84 -0
  114. package/dist/hooks/FilterManager.d.ts +71 -0
  115. package/dist/hooks/MigrationWarner.d.ts +24 -0
  116. package/dist/hooks/dlq-operations.d.ts +60 -0
  117. package/dist/hooks/index.d.ts +11 -0
  118. package/dist/hooks/types.d.ts +107 -0
  119. package/dist/http/CookieJar.d.ts +51 -0
  120. package/dist/http/cookie.d.ts +29 -0
  121. package/dist/http/index.d.ts +12 -0
  122. package/dist/{compat-CI8hiulX.d.cts → http/types.d.ts} +35 -16
  123. package/dist/index.browser.d.ts +34 -0
  124. package/dist/index.d.ts +60 -10981
  125. package/dist/index.js +10808 -11273
  126. package/dist/index.js.map +166 -0
  127. package/dist/observability/QueueDashboard.d.ts +136 -0
  128. package/dist/observability/contracts.d.ts +137 -0
  129. package/dist/observability/index.d.ts +13 -0
  130. package/dist/reliability/DeadLetterQueueManager.d.ts +349 -0
  131. package/dist/reliability/RetryPolicy.d.ts +217 -0
  132. package/dist/reliability/index.d.ts +6 -0
  133. package/dist/router/ControllerDispatcher.d.ts +12 -0
  134. package/dist/router/RequestValidator.d.ts +20 -0
  135. package/dist/runtime/adapter-bun.d.ts +12 -0
  136. package/dist/runtime/adapter-deno.d.ts +12 -0
  137. package/dist/runtime/adapter-node.d.ts +12 -0
  138. package/dist/runtime/adapter-unknown.d.ts +13 -0
  139. package/dist/runtime/archive.d.ts +17 -0
  140. package/dist/runtime/compression.d.ts +21 -0
  141. package/dist/runtime/deep-equals.d.ts +56 -0
  142. package/dist/runtime/detection.d.ts +22 -0
  143. package/dist/runtime/escape.d.ts +34 -0
  144. package/dist/runtime/index.browser.d.ts +20 -0
  145. package/dist/runtime/index.d.ts +44 -0
  146. package/dist/runtime/markdown.d.ts +44 -0
  147. package/dist/runtime/types.d.ts +436 -0
  148. package/dist/runtime-helpers.d.ts +67 -0
  149. package/dist/runtime.d.ts +11 -0
  150. package/dist/security/Encrypter.d.ts +33 -0
  151. package/dist/security/Hasher.d.ts +29 -0
  152. package/dist/testing/HttpTester.d.ts +39 -0
  153. package/dist/testing/TestResponse.d.ts +78 -0
  154. package/dist/testing/index.d.ts +2 -0
  155. package/dist/transpiler-utils.d.ts +170 -0
  156. package/dist/types/events.d.ts +94 -0
  157. package/dist/types.d.ts +13 -0
  158. package/package.json +25 -56
  159. package/src/ffi/native/cbor.c +1148 -0
  160. package/dist/Metrics-VOWWRNNR.js +0 -219
  161. package/dist/chunk-R5U7XKVJ.js +0 -16
  162. package/dist/compat-CI8hiulX.d.ts +0 -376
  163. package/dist/compat.cjs +0 -18
  164. package/dist/compat.d.cts +0 -1
  165. package/dist/engine/index.cjs +0 -1764
  166. package/dist/engine/index.d.cts +0 -922
  167. package/dist/index.cjs +0 -14906
  168. package/dist/index.d.cts +0 -11008
@@ -0,0 +1,229 @@
1
+ /**
2
+ * Circuit Breaker state enum.
3
+ * @public
4
+ */
5
+ export declare enum CircuitBreakerState {
6
+ CLOSED = "CLOSED",
7
+ OPEN = "OPEN",
8
+ HALF_OPEN = "HALF_OPEN"
9
+ }
10
+ /**
11
+ * Circuit Breaker metrics snapshot.
12
+ * @public
13
+ */
14
+ export interface CircuitBreakerMetrics {
15
+ /**
16
+ * Current state of the circuit breaker
17
+ */
18
+ state: CircuitBreakerState;
19
+ /**
20
+ * Number of failures in the current window
21
+ */
22
+ failures: number;
23
+ /**
24
+ * Number of successes in the current window
25
+ */
26
+ successes: number;
27
+ /**
28
+ * Timestamp of the last failure
29
+ */
30
+ lastFailureAt?: Date;
31
+ /**
32
+ * Timestamp of the last success
33
+ */
34
+ lastSuccessAt?: Date;
35
+ /**
36
+ * Timestamp when the circuit was opened
37
+ */
38
+ openedAt?: Date;
39
+ /**
40
+ * Total requests processed
41
+ */
42
+ totalRequests: number;
43
+ /**
44
+ * Total failures recorded
45
+ */
46
+ totalFailures: number;
47
+ /**
48
+ * Total successes recorded
49
+ */
50
+ totalSuccesses: number;
51
+ }
52
+ /**
53
+ * Circuit Breaker metrics recorder interface.
54
+ * @public
55
+ */
56
+ export interface CircuitBreakerMetricsRecorder {
57
+ /**
58
+ * Record current state of the circuit breaker.
59
+ * @param eventName - Name of the event
60
+ * @param state - State as number (0=CLOSED, 1=HALF_OPEN, 2=OPEN)
61
+ */
62
+ recordState: (eventName: string, state: number) => void;
63
+ /**
64
+ * Record state transition.
65
+ */
66
+ recordTransition: (eventName: string, fromState: string, toState: string) => void;
67
+ /**
68
+ * Record a failure.
69
+ */
70
+ recordFailure: (eventName: string) => void;
71
+ /**
72
+ * Record a success.
73
+ */
74
+ recordSuccess: (eventName: string) => void;
75
+ /**
76
+ * Record OPEN state duration.
77
+ */
78
+ recordOpenDuration: (eventName: string, seconds: number) => void;
79
+ }
80
+ /**
81
+ * Circuit Breaker configuration options.
82
+ * @public
83
+ */
84
+ export interface CircuitBreakerOptions {
85
+ /**
86
+ * Number of consecutive failures before opening the circuit.
87
+ * @default 5
88
+ */
89
+ failureThreshold?: number;
90
+ /**
91
+ * Time in milliseconds to wait before attempting to close the circuit (move to HALF_OPEN).
92
+ * @default 30000
93
+ */
94
+ resetTimeout?: number;
95
+ /**
96
+ * Number of test requests to allow given the circuit is in HALF_OPEN state.
97
+ * If these succeed, the circuit closes. If any fail, it opens again.
98
+ * @default 3
99
+ */
100
+ halfOpenRequests?: number;
101
+ /**
102
+ * Number of successes required in HALF_OPEN state to close the circuit.
103
+ * @default 2
104
+ */
105
+ successThreshold?: number;
106
+ /**
107
+ * Time in milliseconds for the sliding window to track failures.
108
+ * Failures outside this window are not counted.
109
+ * @default 60000
110
+ */
111
+ windowSize?: number;
112
+ /**
113
+ * Enable or disable the circuit breaker.
114
+ * @default true
115
+ */
116
+ enabled?: boolean;
117
+ /**
118
+ * Callback when circuit opens.
119
+ */
120
+ onOpen?: (name?: string) => void;
121
+ /**
122
+ * Callback when circuit moves to half-open.
123
+ */
124
+ onHalfOpen?: (name?: string) => void;
125
+ /**
126
+ * Callback when circuit closes.
127
+ */
128
+ onClose?: (name?: string) => void;
129
+ /**
130
+ * Metrics recorder for recording circuit breaker events.
131
+ * Optional - if not provided, metrics will not be recorded.
132
+ */
133
+ metricsRecorder?: CircuitBreakerMetricsRecorder | undefined;
134
+ }
135
+ /**
136
+ * Required Circuit Breaker configuration (with defaults applied).
137
+ * @internal
138
+ */
139
+ export interface RequiredCircuitBreakerOptions extends Required<Omit<CircuitBreakerOptions, 'metricsRecorder'>> {
140
+ metricsRecorder?: CircuitBreakerMetricsRecorder;
141
+ }
142
+ /**
143
+ * Circuit Breaker implementation for fault tolerance.
144
+ *
145
+ * Prevents cascading failures by stopping execution of a failing operation
146
+ * for a specified period after a threshold of failures is reached.
147
+ *
148
+ * Supports sliding window algorithm, enabling/disabling, and detailed metrics.
149
+ *
150
+ * @public
151
+ */
152
+ export declare class CircuitBreaker {
153
+ private state;
154
+ private failureCount;
155
+ private successCount;
156
+ private name;
157
+ private config;
158
+ private metricsRecorder?;
159
+ private lastFailureAt?;
160
+ private lastSuccessAt?;
161
+ private openedAt?;
162
+ private totalRequests;
163
+ private totalFailures;
164
+ private totalSuccesses;
165
+ private halfOpenAttempts;
166
+ /**
167
+ * Create a new Circuit Breaker.
168
+ *
169
+ * Supports two signatures for backward compatibility:
170
+ * - CircuitBreaker(options?: CircuitBreakerOptions) - anonymous breaker
171
+ * - CircuitBreaker(name: string, options?: CircuitBreakerOptions) - named breaker
172
+ *
173
+ * @param nameOrOptions - Circuit breaker name or options
174
+ * @param maybeOptions - Options (used when first param is a string)
175
+ */
176
+ constructor(nameOrOptions?: string | CircuitBreakerOptions, maybeOptions?: CircuitBreakerOptions);
177
+ /**
178
+ * Execute an operation through the circuit breaker.
179
+ *
180
+ * @param operation - Async operation to execute
181
+ * @returns Operation result
182
+ * @throws Error if circuit is open or operation fails
183
+ */
184
+ execute<T>(operation: () => Promise<T>): Promise<T>;
185
+ /**
186
+ * Check if the circuit breaker is currently OPEN.
187
+ */
188
+ isOpen(): boolean;
189
+ /**
190
+ * Check if the circuit breaker is currently HALF_OPEN.
191
+ */
192
+ isHalfOpen(): boolean;
193
+ /**
194
+ * Check if the circuit breaker is currently CLOSED.
195
+ */
196
+ isClosed(): boolean;
197
+ /**
198
+ * Get current state of the circuit breaker.
199
+ */
200
+ getState(): CircuitBreakerState;
201
+ /**
202
+ * Get failure count (deprecated, use getMetrics for complete information).
203
+ */
204
+ getFailureCount(): number;
205
+ /**
206
+ * Get the name of this circuit breaker.
207
+ */
208
+ getName(): string;
209
+ /**
210
+ * Get detailed metrics snapshot of the circuit breaker.
211
+ */
212
+ getMetrics(): CircuitBreakerMetrics;
213
+ /**
214
+ * Manually reset the circuit breaker to CLOSED state.
215
+ */
216
+ reset(): void;
217
+ /**
218
+ * Forcefully reset the circuit breaker (alias for reset).
219
+ */
220
+ manualReset(): void;
221
+ /**
222
+ * Check for automatic state transitions based on time and sliding window.
223
+ */
224
+ checkStateTransition(): void;
225
+ private onSuccess;
226
+ private onFailure;
227
+ private transitionTo;
228
+ private stateToNumber;
229
+ }
@@ -0,0 +1,219 @@
1
+ import type { EventOptions } from './EventOptions';
2
+ /**
3
+ * Source of DLQ entry - reason why event entered the DLQ.
4
+ * @public
5
+ */
6
+ export type DLQEntrySource = 'retry_exhausted' | 'circuit_breaker' | 'backpressure_overflow' | 'manual';
7
+ /**
8
+ * Dead Letter Queue entry representing a failed event.
9
+ * @public
10
+ */
11
+ export interface DLQEntry {
12
+ /**
13
+ * Unique identifier for this DLQ entry.
14
+ */
15
+ id: string;
16
+ /**
17
+ * Event hook name.
18
+ */
19
+ eventName: string;
20
+ /**
21
+ * Event payload.
22
+ */
23
+ payload: unknown;
24
+ /**
25
+ * Event options used when dispatching.
26
+ */
27
+ options: EventOptions;
28
+ /**
29
+ * Error that caused the event to fail.
30
+ */
31
+ error: {
32
+ message: string;
33
+ stack?: string;
34
+ code?: string;
35
+ };
36
+ /**
37
+ * Number of retry attempts made.
38
+ */
39
+ retryCount: number;
40
+ /**
41
+ * Timestamp when the event first failed.
42
+ */
43
+ firstFailedAt: number;
44
+ /**
45
+ * Timestamp when the event was added to DLQ.
46
+ */
47
+ failedAt: number;
48
+ /**
49
+ * Timestamp when the event was last retried (if any).
50
+ */
51
+ lastRetriedAt?: number;
52
+ /**
53
+ * Source of the DLQ entry - reason why event entered the DLQ.
54
+ */
55
+ source: DLQEntrySource;
56
+ }
57
+ /**
58
+ * Filter options for querying DLQ entries.
59
+ * @public
60
+ */
61
+ export interface DLQFilter {
62
+ /**
63
+ * Filter by event name.
64
+ */
65
+ eventName?: string;
66
+ /**
67
+ * Filter by entries failed after this timestamp.
68
+ */
69
+ from?: number;
70
+ /**
71
+ * Filter by entries failed before this timestamp.
72
+ */
73
+ to?: number;
74
+ /**
75
+ * Maximum number of entries to return.
76
+ */
77
+ limit?: number;
78
+ }
79
+ /**
80
+ * Callback type for DLQ entry events.
81
+ * @public
82
+ */
83
+ export type DLQEntryCallback = (entry: DLQEntry) => void;
84
+ /**
85
+ * Dead Letter Queue Manager for handling failed events.
86
+ *
87
+ * The DLQ stores events that have exceeded their retry limit,
88
+ * allowing for manual inspection, reprocessing, or analysis.
89
+ *
90
+ * @public
91
+ */
92
+ export declare class DeadLetterQueue {
93
+ private entries;
94
+ private entryIdCounter;
95
+ private maxEntries?;
96
+ private onEntryAdded?;
97
+ private onEntryRemoved?;
98
+ /**
99
+ * Create a new DeadLetterQueue instance.
100
+ *
101
+ * @param maxEntries - Maximum number of entries to keep (optional, no limit if not set)
102
+ */
103
+ constructor(maxEntries?: number);
104
+ /**
105
+ * Add a failed event to the Dead Letter Queue.
106
+ *
107
+ * @param eventName - Name of the failed event
108
+ * @param payload - Event payload
109
+ * @param options - Event options
110
+ * @param error - Error that caused the failure
111
+ * @param retryCount - Number of retry attempts made
112
+ * @param firstFailedAt - Timestamp of first failure
113
+ * @param source - Source of the DLQ entry (default: 'retry_exhausted')
114
+ * @returns DLQ entry ID
115
+ */
116
+ add(eventName: string, payload: unknown, options: EventOptions, error: Error, retryCount: number, firstFailedAt: number, source?: DLQEntrySource): string;
117
+ /**
118
+ * Get a specific DLQ entry by ID.
119
+ *
120
+ * @param entryId - DLQ entry ID
121
+ * @returns DLQ entry or undefined if not found
122
+ */
123
+ get(entryId: string): DLQEntry | undefined;
124
+ /**
125
+ * List DLQ entries with optional filtering.
126
+ *
127
+ * @param filter - Filter options
128
+ * @returns Array of DLQ entries
129
+ */
130
+ list(filter?: DLQFilter): DLQEntry[];
131
+ /**
132
+ * Delete a DLQ entry.
133
+ *
134
+ * @param entryId - DLQ entry ID
135
+ * @returns True if entry was deleted, false if not found
136
+ */
137
+ delete(entryId: string): boolean;
138
+ /**
139
+ * Delete all DLQ entries matching the filter.
140
+ *
141
+ * @param filter - Filter options
142
+ * @returns Number of entries deleted
143
+ */
144
+ deleteAll(filter?: DLQFilter): number;
145
+ /**
146
+ * Get the total number of entries in the DLQ.
147
+ *
148
+ * @returns Total entry count
149
+ */
150
+ getCount(): number;
151
+ /**
152
+ * Get the count of entries for a specific event.
153
+ *
154
+ * @param eventName - Event name
155
+ * @returns Entry count for the event
156
+ */
157
+ getCountByEvent(eventName: string): number;
158
+ /**
159
+ * Clear all entries from the DLQ.
160
+ */
161
+ clear(): void;
162
+ /**
163
+ * Update the last retried timestamp for an entry.
164
+ *
165
+ * @param entryId - DLQ entry ID
166
+ * @internal
167
+ */
168
+ updateLastRetried(entryId: string): void;
169
+ /**
170
+ * Evict the oldest entry from the DLQ.
171
+ * Used when capacity limit is reached.
172
+ *
173
+ * @private
174
+ */
175
+ private evictOldest;
176
+ /**
177
+ * Get the oldest entry in the DLQ.
178
+ *
179
+ * @returns Oldest DLQ entry or undefined if empty
180
+ */
181
+ getOldestEntry(): DLQEntry | undefined;
182
+ /**
183
+ * Get the newest entry in the DLQ.
184
+ *
185
+ * @returns Newest DLQ entry or undefined if empty
186
+ */
187
+ getNewestEntry(): DLQEntry | undefined;
188
+ /**
189
+ * Get all entries grouped by source.
190
+ *
191
+ * @param source - Source to filter by
192
+ * @returns Array of entries matching the source
193
+ */
194
+ getEntriesBySource(source: DLQEntrySource): DLQEntry[];
195
+ /**
196
+ * Set callback for when an entry is added to the DLQ.
197
+ *
198
+ * @param callback - Callback function or undefined to clear
199
+ */
200
+ setOnEntryAdded(callback?: DLQEntryCallback): void;
201
+ /**
202
+ * Set callback for when an entry is removed from the DLQ.
203
+ *
204
+ * @param callback - Callback function or undefined to clear
205
+ */
206
+ setOnEntryRemoved(callback?: DLQEntryCallback): void;
207
+ /**
208
+ * Get the maximum number of entries allowed in the DLQ.
209
+ *
210
+ * @returns Max entries limit or undefined if no limit
211
+ */
212
+ getMaxEntries(): number | undefined;
213
+ /**
214
+ * Set the maximum number of entries allowed in the DLQ.
215
+ *
216
+ * @param maxEntries - Maximum entries or undefined to remove limit
217
+ */
218
+ setMaxEntries(maxEntries?: number): void;
219
+ }
@@ -0,0 +1,12 @@
1
+ import type { EventTask } from './types';
2
+ /**
3
+ * Interface for event dispatch backends.
4
+ */
5
+ export interface EventBackend {
6
+ /**
7
+ * Enqueue an event for processing.
8
+ * @param task - The event task to process
9
+ * @returns Task ID or 'dropped' if event was rejected (can be async for some backends)
10
+ */
11
+ enqueue(task: EventTask): string | Promise<void>;
12
+ }
@@ -0,0 +1,204 @@
1
+ /**
2
+ * Event dispatch options for async event handling.
3
+ * @public
4
+ */
5
+ export interface EventOptions {
6
+ /**
7
+ * Whether to dispatch the event asynchronously.
8
+ * @default false
9
+ */
10
+ async?: boolean;
11
+ /**
12
+ * Priority level for event processing.
13
+ * - 'critical': Immediate processing, bypass queue (< 1ms)
14
+ * - 'high': High priority events (< 50ms)
15
+ * - 'normal': Standard events (< 200ms)
16
+ * - 'low': Non-critical events (< 500ms)
17
+ * @default 'normal'
18
+ */
19
+ priority?: 'critical' | 'high' | 'normal' | 'low';
20
+ /**
21
+ * Automatic priority escalation configuration.
22
+ * Events can be automatically upgraded to higher priority based on wait time.
23
+ */
24
+ escalation?: {
25
+ /**
26
+ * Whether to enable automatic priority escalation.
27
+ * @default true
28
+ */
29
+ enabled?: boolean;
30
+ /**
31
+ * Escalation thresholds in milliseconds.
32
+ * Events exceeding these wait times are promoted.
33
+ */
34
+ thresholds?: {
35
+ /**
36
+ * Wait time before LOW events are promoted to NORMAL.
37
+ * @default 200
38
+ */
39
+ lowToNormal?: number;
40
+ /**
41
+ * Wait time before NORMAL events are promoted to HIGH.
42
+ * @default 100
43
+ */
44
+ normalToHigh?: number;
45
+ /**
46
+ * Wait time before HIGH events are promoted to CRITICAL.
47
+ * @default 50
48
+ */
49
+ highToCritical?: number;
50
+ };
51
+ /**
52
+ * Maximum wait time before forcing CRITICAL priority.
53
+ * @default 500
54
+ */
55
+ maxWaitTimeMs?: number;
56
+ };
57
+ /**
58
+ * Execution timeout in milliseconds.
59
+ * If a listener exceeds this timeout, it will be terminated.
60
+ * @default 5000
61
+ */
62
+ timeout?: number;
63
+ /**
64
+ * Ordering guarantee strategy.
65
+ * - 'strict': Global strict ordering (slow, serialized)
66
+ * - 'partition': Partition-based ordering (recommended, balanced)
67
+ * - 'none': No ordering guarantee (fastest, parallel)
68
+ * @default 'none'
69
+ */
70
+ ordering?: 'strict' | 'partition' | 'none';
71
+ /**
72
+ * Partition key for partition-based ordering.
73
+ * Events with the same partition key are processed in order.
74
+ * Only used when ordering is 'partition'.
75
+ * @example 'order:123' or 'user:456'
76
+ */
77
+ partitionKey?: string;
78
+ /**
79
+ * Idempotency key for deduplication.
80
+ * Events with the same idempotency key within the TTL window
81
+ * will be processed only once.
82
+ * @example 'order:123:created'
83
+ */
84
+ idempotencyKey?: string;
85
+ /**
86
+ * Time-to-live for idempotency key in milliseconds.
87
+ * @default 3600000 (1 hour)
88
+ */
89
+ ttl?: number;
90
+ /**
91
+ * Retry policy for failed event processing.
92
+ */
93
+ retry?: {
94
+ /**
95
+ * Maximum number of retry attempts.
96
+ * @default 0
97
+ */
98
+ maxRetries?: number;
99
+ /**
100
+ * Backoff strategy for retries.
101
+ * - 'exponential': Delay doubles with each retry (1s, 2s, 4s, 8s...)
102
+ * - 'linear': Fixed delay between retries
103
+ * @default 'exponential'
104
+ */
105
+ backoff?: 'exponential' | 'linear';
106
+ /**
107
+ * Initial delay in milliseconds before first retry.
108
+ * @default 1000
109
+ */
110
+ initialDelayMs?: number;
111
+ /**
112
+ * Maximum delay in milliseconds between retries.
113
+ * @default 30000
114
+ */
115
+ maxDelayMs?: number;
116
+ /**
117
+ * Whether to send failed events to Dead Letter Queue after max retries.
118
+ * @default false
119
+ */
120
+ dlqAfterMaxRetries?: boolean;
121
+ };
122
+ /**
123
+ * Circuit breaker options for this event.
124
+ */
125
+ circuitBreaker?: {
126
+ /**
127
+ * Number of consecutive failures before opening the circuit.
128
+ * @default 5
129
+ */
130
+ failureThreshold?: number;
131
+ /**
132
+ * Time in milliseconds to wait before attempting to close the circuit.
133
+ * @default 30000
134
+ */
135
+ resetTimeout?: number;
136
+ /**
137
+ * Number of test requests to allow in half-open state.
138
+ * @default 3
139
+ */
140
+ halfOpenRequests?: number;
141
+ };
142
+ /**
143
+ * Event aggregation configuration (FS-102).
144
+ * Enables deduplication and micro-batching for improved throughput.
145
+ * @default undefined (disabled)
146
+ */
147
+ aggregation?: {
148
+ /**
149
+ * Enable event aggregation.
150
+ * @default false
151
+ */
152
+ enabled?: boolean;
153
+ /**
154
+ * Aggregation window size in milliseconds.
155
+ * Backpressure-aware adjustment: 50-500ms
156
+ * @default 200
157
+ */
158
+ windowMs?: number;
159
+ /**
160
+ * Batch size threshold for auto-flush.
161
+ * @default 50
162
+ */
163
+ batchSize?: number;
164
+ /**
165
+ * Deduplication strategy.
166
+ * @default 'pattern'
167
+ */
168
+ deduplication?: 'pattern' | 'idempotencyKey' | 'off';
169
+ /**
170
+ * Deduplication pattern (string or function).
171
+ * String: hook-based pattern
172
+ * Function: custom pattern from event args
173
+ */
174
+ pattern?: string | ((args: unknown) => string);
175
+ /**
176
+ * Priority merge strategy.
177
+ * - 'highest': keep highest priority event
178
+ * - 'earliest': keep earliest event
179
+ * - 'latest': keep latest event
180
+ * @default 'highest'
181
+ */
182
+ mergePriority?: 'highest' | 'earliest' | 'latest';
183
+ /**
184
+ * Enable automatic cleanup of expired entries.
185
+ * @default true
186
+ */
187
+ enableCleanup?: boolean;
188
+ /**
189
+ * Cleanup interval in milliseconds.
190
+ * @default 300000 (5 minutes)
191
+ */
192
+ cleanupIntervalMs?: number;
193
+ /**
194
+ * TTL for entries in milliseconds.
195
+ * @default 600000 (10 minutes)
196
+ */
197
+ ttlMs?: number;
198
+ };
199
+ }
200
+ /**
201
+ * Default event options.
202
+ * @internal
203
+ */
204
+ export declare const DEFAULT_EVENT_OPTIONS: Required<EventOptions>;