@gravito/echo 3.0.0 → 3.1.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 (221) hide show
  1. package/README.md +211 -0
  2. package/dist/atlas/src/DB.d.ts +301 -0
  3. package/dist/atlas/src/OrbitAtlas.d.ts +9 -0
  4. package/dist/atlas/src/config/defineConfig.d.ts +14 -0
  5. package/dist/atlas/src/config/index.d.ts +7 -0
  6. package/dist/atlas/src/config/loadConfig.d.ts +48 -0
  7. package/dist/atlas/src/connection/Connection.d.ts +108 -0
  8. package/dist/atlas/src/connection/ConnectionManager.d.ts +111 -0
  9. package/dist/atlas/src/drivers/BunSQLDriver.d.ts +32 -0
  10. package/dist/atlas/src/drivers/BunSQLPreparedStatement.d.ts +118 -0
  11. package/dist/atlas/src/drivers/MongoDBDriver.d.ts +36 -0
  12. package/dist/atlas/src/drivers/MySQLDriver.d.ts +66 -0
  13. package/dist/atlas/src/drivers/PostgresDriver.d.ts +83 -0
  14. package/dist/atlas/src/drivers/RedisDriver.d.ts +43 -0
  15. package/dist/atlas/src/drivers/SQLiteDriver.d.ts +45 -0
  16. package/dist/atlas/src/drivers/types.d.ts +260 -0
  17. package/dist/atlas/src/errors/index.d.ts +45 -0
  18. package/dist/atlas/src/grammar/Grammar.d.ts +342 -0
  19. package/dist/atlas/src/grammar/MongoGrammar.d.ts +47 -0
  20. package/dist/atlas/src/grammar/MySQLGrammar.d.ts +54 -0
  21. package/dist/atlas/src/grammar/NullGrammar.d.ts +35 -0
  22. package/dist/atlas/src/grammar/PostgresGrammar.d.ts +62 -0
  23. package/dist/atlas/src/grammar/SQLiteGrammar.d.ts +32 -0
  24. package/dist/atlas/src/index.d.ts +67 -0
  25. package/dist/atlas/src/migration/Migration.d.ts +64 -0
  26. package/dist/atlas/src/migration/MigrationRepository.d.ts +65 -0
  27. package/dist/atlas/src/migration/Migrator.d.ts +110 -0
  28. package/dist/atlas/src/migration/index.d.ts +6 -0
  29. package/dist/atlas/src/observability/AtlasMetrics.d.ts +11 -0
  30. package/dist/atlas/src/observability/AtlasObservability.d.ts +15 -0
  31. package/dist/atlas/src/observability/AtlasTracer.d.ts +12 -0
  32. package/dist/atlas/src/observability/index.d.ts +9 -0
  33. package/dist/atlas/src/orm/index.d.ts +5 -0
  34. package/dist/atlas/src/orm/model/DirtyTracker.d.ts +121 -0
  35. package/dist/atlas/src/orm/model/Model.d.ts +449 -0
  36. package/dist/atlas/src/orm/model/ModelRegistry.d.ts +20 -0
  37. package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +136 -0
  38. package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +36 -0
  39. package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +87 -0
  40. package/dist/atlas/src/orm/model/concerns/HasRelationships.d.ts +117 -0
  41. package/dist/atlas/src/orm/model/concerns/HasSerialization.d.ts +64 -0
  42. package/dist/atlas/src/orm/model/concerns/applyMixins.d.ts +15 -0
  43. package/dist/atlas/src/orm/model/concerns/index.d.ts +12 -0
  44. package/dist/atlas/src/orm/model/decorators.d.ts +109 -0
  45. package/dist/atlas/src/orm/model/errors.d.ts +52 -0
  46. package/dist/atlas/src/orm/model/index.d.ts +10 -0
  47. package/dist/atlas/src/orm/model/relationships.d.ts +207 -0
  48. package/dist/atlas/src/orm/model/types.d.ts +12 -0
  49. package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +123 -0
  50. package/dist/atlas/src/orm/schema/SchemaSniffer.d.ts +54 -0
  51. package/dist/atlas/src/orm/schema/index.d.ts +6 -0
  52. package/dist/atlas/src/orm/schema/types.d.ts +85 -0
  53. package/dist/atlas/src/query/Expression.d.ts +60 -0
  54. package/dist/atlas/src/query/NPlusOneDetector.d.ts +10 -0
  55. package/dist/atlas/src/query/QueryBuilder.d.ts +573 -0
  56. package/dist/atlas/src/query/clauses/GroupByClause.d.ts +51 -0
  57. package/dist/atlas/src/query/clauses/HavingClause.d.ts +70 -0
  58. package/dist/atlas/src/query/clauses/JoinClause.d.ts +87 -0
  59. package/dist/atlas/src/query/clauses/LimitClause.d.ts +82 -0
  60. package/dist/atlas/src/query/clauses/OrderByClause.d.ts +69 -0
  61. package/dist/atlas/src/query/clauses/SelectClause.d.ts +71 -0
  62. package/dist/atlas/src/query/clauses/WhereClause.d.ts +167 -0
  63. package/dist/atlas/src/query/clauses/index.d.ts +11 -0
  64. package/dist/atlas/src/schema/Blueprint.d.ts +276 -0
  65. package/dist/atlas/src/schema/ColumnDefinition.d.ts +154 -0
  66. package/dist/atlas/src/schema/ForeignKeyDefinition.d.ts +37 -0
  67. package/dist/atlas/src/schema/Schema.d.ts +131 -0
  68. package/dist/atlas/src/schema/grammars/MySQLSchemaGrammar.d.ts +23 -0
  69. package/dist/atlas/src/schema/grammars/PostgresSchemaGrammar.d.ts +26 -0
  70. package/dist/atlas/src/schema/grammars/SQLiteSchemaGrammar.d.ts +28 -0
  71. package/dist/atlas/src/schema/grammars/SchemaGrammar.d.ts +97 -0
  72. package/dist/atlas/src/schema/grammars/index.d.ts +7 -0
  73. package/dist/atlas/src/schema/index.d.ts +8 -0
  74. package/dist/atlas/src/seed/Factory.d.ts +90 -0
  75. package/dist/atlas/src/seed/Seeder.d.ts +28 -0
  76. package/dist/atlas/src/seed/SeederRunner.d.ts +74 -0
  77. package/dist/atlas/src/seed/index.d.ts +6 -0
  78. package/dist/atlas/src/types/index.d.ts +1100 -0
  79. package/dist/atlas/src/utils/levenshtein.d.ts +9 -0
  80. package/dist/core/src/Application.d.ts +215 -0
  81. package/dist/core/src/CommandKernel.d.ts +33 -0
  82. package/dist/core/src/ConfigManager.d.ts +26 -0
  83. package/dist/core/src/Container.d.ts +108 -0
  84. package/dist/core/src/ErrorHandler.d.ts +63 -0
  85. package/dist/core/src/Event.d.ts +5 -0
  86. package/dist/core/src/EventManager.d.ts +123 -0
  87. package/dist/core/src/GlobalErrorHandlers.d.ts +47 -0
  88. package/dist/core/src/GravitoServer.d.ts +28 -0
  89. package/dist/core/src/HookManager.d.ts +496 -0
  90. package/dist/core/src/Listener.d.ts +4 -0
  91. package/dist/core/src/Logger.d.ts +20 -0
  92. package/dist/core/src/PlanetCore.d.ts +289 -0
  93. package/dist/core/src/Route.d.ts +36 -0
  94. package/dist/core/src/Router.d.ts +284 -0
  95. package/dist/core/src/ServiceProvider.d.ts +156 -0
  96. package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +27 -0
  97. package/dist/core/src/adapters/PhotonAdapter.d.ts +171 -0
  98. package/dist/core/src/adapters/bun/BunContext.d.ts +45 -0
  99. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +31 -0
  100. package/dist/core/src/adapters/bun/BunRequest.d.ts +31 -0
  101. package/dist/core/src/adapters/bun/RadixNode.d.ts +19 -0
  102. package/dist/core/src/adapters/bun/RadixRouter.d.ts +31 -0
  103. package/dist/core/src/adapters/bun/types.d.ts +20 -0
  104. package/dist/core/src/adapters/photon-types.d.ts +73 -0
  105. package/dist/core/src/adapters/types.d.ts +235 -0
  106. package/dist/core/src/engine/AOTRouter.d.ts +124 -0
  107. package/dist/core/src/engine/FastContext.d.ts +100 -0
  108. package/dist/core/src/engine/Gravito.d.ts +137 -0
  109. package/dist/core/src/engine/MinimalContext.d.ts +79 -0
  110. package/dist/core/src/engine/analyzer.d.ts +27 -0
  111. package/dist/core/src/engine/constants.d.ts +23 -0
  112. package/dist/core/src/engine/index.d.ts +26 -0
  113. package/dist/core/src/engine/path.d.ts +26 -0
  114. package/dist/core/src/engine/pool.d.ts +83 -0
  115. package/dist/core/src/engine/types.d.ts +143 -0
  116. package/dist/core/src/events/CircuitBreaker.d.ts +229 -0
  117. package/dist/core/src/events/DeadLetterQueue.d.ts +145 -0
  118. package/dist/core/src/events/EventBackend.d.ts +11 -0
  119. package/dist/core/src/events/EventOptions.d.ts +109 -0
  120. package/dist/core/src/events/EventPriorityQueue.d.ts +202 -0
  121. package/dist/core/src/events/IdempotencyCache.d.ts +60 -0
  122. package/dist/core/src/events/index.d.ts +14 -0
  123. package/dist/core/src/events/observability/EventMetrics.d.ts +132 -0
  124. package/dist/core/src/events/observability/EventTracer.d.ts +68 -0
  125. package/dist/core/src/events/observability/EventTracing.d.ts +161 -0
  126. package/dist/core/src/events/observability/OTelEventMetrics.d.ts +240 -0
  127. package/dist/core/src/events/observability/ObservableHookManager.d.ts +108 -0
  128. package/dist/core/src/events/observability/index.d.ts +20 -0
  129. package/dist/core/src/events/observability/metrics-types.d.ts +16 -0
  130. package/dist/core/src/events/types.d.ts +75 -0
  131. package/dist/core/src/exceptions/AuthenticationException.d.ts +8 -0
  132. package/dist/core/src/exceptions/AuthorizationException.d.ts +8 -0
  133. package/dist/core/src/exceptions/CircularDependencyException.d.ts +9 -0
  134. package/dist/core/src/exceptions/GravitoException.d.ts +23 -0
  135. package/dist/core/src/exceptions/HttpException.d.ts +9 -0
  136. package/dist/core/src/exceptions/ModelNotFoundException.d.ts +10 -0
  137. package/dist/core/src/exceptions/ValidationException.d.ts +22 -0
  138. package/dist/core/src/exceptions/index.d.ts +7 -0
  139. package/dist/core/src/helpers/Arr.d.ts +19 -0
  140. package/dist/core/src/helpers/Str.d.ts +23 -0
  141. package/dist/core/src/helpers/data.d.ts +25 -0
  142. package/dist/core/src/helpers/errors.d.ts +34 -0
  143. package/dist/core/src/helpers/response.d.ts +41 -0
  144. package/dist/core/src/helpers.d.ts +338 -0
  145. package/dist/core/src/http/CookieJar.d.ts +51 -0
  146. package/dist/core/src/http/cookie.d.ts +29 -0
  147. package/dist/core/src/http/middleware/BodySizeLimit.d.ts +16 -0
  148. package/dist/core/src/http/middleware/Cors.d.ts +24 -0
  149. package/dist/core/src/http/middleware/Csrf.d.ts +23 -0
  150. package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +28 -0
  151. package/dist/core/src/http/middleware/SecurityHeaders.d.ts +29 -0
  152. package/dist/core/src/http/middleware/ThrottleRequests.d.ts +18 -0
  153. package/dist/core/src/http/types.d.ts +355 -0
  154. package/dist/core/src/index.d.ts +76 -0
  155. package/dist/core/src/instrumentation/index.d.ts +35 -0
  156. package/dist/core/src/instrumentation/opentelemetry.d.ts +178 -0
  157. package/dist/core/src/instrumentation/types.d.ts +182 -0
  158. package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +316 -0
  159. package/dist/core/src/reliability/RetryPolicy.d.ts +217 -0
  160. package/dist/core/src/reliability/index.d.ts +6 -0
  161. package/dist/core/src/router/ControllerDispatcher.d.ts +12 -0
  162. package/dist/core/src/router/RequestValidator.d.ts +20 -0
  163. package/dist/core/src/runtime.d.ts +119 -0
  164. package/dist/core/src/security/Encrypter.d.ts +33 -0
  165. package/dist/core/src/security/Hasher.d.ts +29 -0
  166. package/dist/core/src/testing/HttpTester.d.ts +39 -0
  167. package/dist/core/src/testing/TestResponse.d.ts +78 -0
  168. package/dist/core/src/testing/index.d.ts +2 -0
  169. package/dist/core/src/types/events.d.ts +94 -0
  170. package/dist/echo/src/OrbitEcho.d.ts +115 -0
  171. package/dist/echo/src/dlq/DeadLetterQueue.d.ts +94 -0
  172. package/dist/echo/src/dlq/MemoryDeadLetterQueue.d.ts +36 -0
  173. package/dist/echo/src/dlq/index.d.ts +2 -0
  174. package/dist/echo/src/index.d.ts +64 -0
  175. package/dist/echo/src/middleware/RequestBufferMiddleware.d.ts +62 -0
  176. package/dist/echo/src/middleware/index.d.ts +8 -0
  177. package/dist/echo/src/observability/index.d.ts +3 -0
  178. package/dist/echo/src/observability/logging/ConsoleEchoLogger.d.ts +37 -0
  179. package/dist/echo/src/observability/logging/EchoLogger.d.ts +38 -0
  180. package/dist/echo/src/observability/logging/index.d.ts +2 -0
  181. package/dist/echo/src/observability/metrics/MetricsProvider.d.ts +69 -0
  182. package/dist/echo/src/observability/metrics/NoopMetricsProvider.d.ts +17 -0
  183. package/dist/echo/src/observability/metrics/PrometheusMetricsProvider.d.ts +39 -0
  184. package/dist/echo/src/observability/metrics/index.d.ts +3 -0
  185. package/dist/echo/src/observability/tracing/NoopTracer.d.ts +33 -0
  186. package/dist/echo/src/observability/tracing/Tracer.d.ts +75 -0
  187. package/dist/echo/src/observability/tracing/index.d.ts +2 -0
  188. package/dist/echo/src/providers/GenericProvider.d.ts +53 -0
  189. package/dist/echo/src/providers/GitHubProvider.d.ts +35 -0
  190. package/dist/echo/src/providers/LinearProvider.d.ts +27 -0
  191. package/dist/echo/src/providers/PaddleProvider.d.ts +31 -0
  192. package/dist/echo/src/providers/ShopifyProvider.d.ts +27 -0
  193. package/dist/echo/src/providers/SlackProvider.d.ts +27 -0
  194. package/dist/echo/src/providers/StripeProvider.d.ts +38 -0
  195. package/dist/echo/src/providers/TwilioProvider.d.ts +31 -0
  196. package/dist/echo/src/providers/base/BaseProvider.d.ts +87 -0
  197. package/dist/echo/src/providers/base/HeaderUtils.d.ts +34 -0
  198. package/dist/echo/src/providers/index.d.ts +14 -0
  199. package/dist/echo/src/receive/SignatureValidator.d.ts +67 -0
  200. package/dist/echo/src/receive/WebhookReceiver.d.ts +185 -0
  201. package/dist/echo/src/receive/index.d.ts +2 -0
  202. package/dist/echo/src/replay/WebhookReplayService.d.ts +35 -0
  203. package/dist/echo/src/replay/index.d.ts +1 -0
  204. package/dist/echo/src/resilience/CircuitBreaker.d.ts +117 -0
  205. package/dist/echo/src/resilience/index.d.ts +10 -0
  206. package/dist/echo/src/rotation/KeyRotationManager.d.ts +127 -0
  207. package/dist/echo/src/rotation/index.d.ts +10 -0
  208. package/dist/echo/src/send/WebhookDispatcher.d.ts +198 -0
  209. package/dist/echo/src/send/index.d.ts +1 -0
  210. package/dist/echo/src/storage/MemoryWebhookStore.d.ts +14 -0
  211. package/dist/echo/src/storage/WebhookStore.d.ts +236 -0
  212. package/dist/echo/src/storage/index.d.ts +2 -0
  213. package/dist/echo/src/types.d.ts +756 -0
  214. package/dist/index.js +1332 -190
  215. package/dist/index.js.map +28 -10
  216. package/dist/photon/src/index.d.ts +84 -0
  217. package/dist/photon/src/middleware/binary.d.ts +31 -0
  218. package/dist/photon/src/middleware/htmx.d.ts +39 -0
  219. package/dist/photon/src/middleware/ratelimit.d.ts +157 -0
  220. package/dist/photon/src/openapi.d.ts +19 -0
  221. package/package.json +7 -5
@@ -0,0 +1,496 @@
1
+ import type { ConnectionContract } from '@gravito/atlas';
2
+ import { type CircuitBreakerOptions } from './events/CircuitBreaker';
3
+ import { DeadLetterQueue } from './events/DeadLetterQueue';
4
+ import type { EventBackend } from './events/EventBackend';
5
+ import type { EventOptions } from './events/EventOptions';
6
+ import { EventPriorityQueue, type EventQueueConfig } from './events/EventPriorityQueue';
7
+ import { DeadLetterQueueManager } from './reliability/DeadLetterQueueManager';
8
+ /**
9
+ * Callback function for filters (transforms values).
10
+ * @public
11
+ */
12
+ export type FilterCallback<T = unknown> = (value: T, ...args: unknown[]) => Promise<T> | T;
13
+ /**
14
+ * Callback function for actions (side effects).
15
+ * @public
16
+ */
17
+ export type ActionCallback<TArgs = unknown> = (args: TArgs) => Promise<void> | void;
18
+ /**
19
+ * Options for listener registration.
20
+ * @public
21
+ */
22
+ export interface ListenerOptions {
23
+ /**
24
+ * Explicitly specify the listener type.
25
+ * - 'sync': Force synchronous dispatch for this listener
26
+ * - 'async': Force asynchronous dispatch for this listener
27
+ * - 'auto': Auto-detect based on function signature (default)
28
+ * @default 'auto'
29
+ */
30
+ type?: 'sync' | 'async' | 'auto';
31
+ /**
32
+ * Circuit breaker configuration for this listener.
33
+ */
34
+ circuitBreaker?: CircuitBreakerOptions;
35
+ }
36
+ /**
37
+ * Information about a registered listener.
38
+ * @public
39
+ */
40
+ export interface ListenerInfo {
41
+ /**
42
+ * The callback function.
43
+ */
44
+ callback: ActionCallback;
45
+ /**
46
+ * Whether the listener is considered async.
47
+ */
48
+ isAsync: boolean;
49
+ /**
50
+ * The explicit type override, if any.
51
+ */
52
+ typeOverride?: 'sync' | 'async' | 'auto';
53
+ }
54
+ /**
55
+ * Configuration for HookManager.
56
+ * @public
57
+ */
58
+ export interface HookManagerConfig {
59
+ /**
60
+ * Enable async event dispatch by default.
61
+ * When true, doAction() will automatically use async dispatch if any listener is async.
62
+ * @default false
63
+ */
64
+ asyncByDefault?: boolean;
65
+ /**
66
+ * Migration mode for backward compatibility.
67
+ * - 'sync': All events use synchronous dispatch (legacy mode)
68
+ * - 'hybrid': Auto-detect and use async for async listeners (recommended)
69
+ * - 'async': All events use async dispatch (future mode)
70
+ * @default 'sync'
71
+ */
72
+ migrationMode?: 'sync' | 'hybrid' | 'async';
73
+ /**
74
+ * Enable deprecation warnings for synchronous event dispatch.
75
+ * @default false
76
+ */
77
+ showDeprecationWarnings?: boolean;
78
+ /**
79
+ * Enable Dead Letter Queue for failed events.
80
+ * @default true
81
+ */
82
+ enableDLQ?: boolean;
83
+ /**
84
+ * Configuration for the event priority queue (Backpressure).
85
+ */
86
+ queue?: EventQueueConfig;
87
+ /**
88
+ * Custom event backend for distributed processing.
89
+ */
90
+ backend?: EventBackend;
91
+ /**
92
+ * Database connection for persistent DLQ (optional).
93
+ * If provided, failed events after max retries will be persisted to database.
94
+ */
95
+ db?: ConnectionContract;
96
+ /**
97
+ * Enable persistent DLQ for failed events (requires db).
98
+ * @default false
99
+ */
100
+ enablePersistentDLQ?: boolean;
101
+ }
102
+ export declare class HookManager {
103
+ private filters;
104
+ private actions;
105
+ private eventQueue;
106
+ private backend;
107
+ private dlq?;
108
+ private persistentDlqManager?;
109
+ private idempotencyCache;
110
+ private config;
111
+ private migrationWarner;
112
+ /**
113
+ * Cache for async detection results (WeakMap for automatic garbage collection).
114
+ * @internal
115
+ */
116
+ private asyncDetectionCache;
117
+ /**
118
+ * Count of items in the async detection cache (for testing/debugging).
119
+ * @internal
120
+ */
121
+ private asyncDetectionCacheCount;
122
+ /**
123
+ * Map of listener type overrides (callback -> type).
124
+ * @internal
125
+ */
126
+ private listenerTypeOverrides;
127
+ constructor(config?: HookManagerConfig);
128
+ /**
129
+ * Register a filter hook.
130
+ *
131
+ * Filters are used to transform a value (input/output) through a chain of
132
+ * callbacks. Each callback must return the modified value.
133
+ *
134
+ * @template T - The type of value being filtered.
135
+ * @param hook - The unique name of the hook.
136
+ * @param callback - The callback function to execute.
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * core.hooks.addFilter('content', async (content: string) => {
141
+ * return content.toUpperCase();
142
+ * });
143
+ * ```
144
+ */
145
+ addFilter<T = unknown>(hook: string, callback: FilterCallback<T>): void;
146
+ /**
147
+ * Apply all registered filters sequentially.
148
+ *
149
+ * Each callback receives the previous callback's return value.
150
+ *
151
+ * @template T - The type of value being filtered.
152
+ * @param hook - The name of the hook.
153
+ * @param initialValue - The initial value to filter.
154
+ * @param args - Additional arguments to pass to the callbacks.
155
+ * @returns The final filtered value.
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * const content = await core.hooks.applyFilters('content', 'hello world');
160
+ * ```
161
+ */
162
+ applyFilters<T = unknown>(hook: string, initialValue: T, ...args: unknown[]): Promise<T>;
163
+ /**
164
+ * Register an action hook.
165
+ *
166
+ * Actions are used to trigger side effects (e.g., logging, sending emails)
167
+ * at specific points in the application lifecycle.
168
+ *
169
+ * @template TArgs - The type of arguments passed to the action.
170
+ * @param hook - The unique name of the hook.
171
+ * @param callback - The callback function to execute.
172
+ * @param options - Optional listener options (type override, circuit breaker).
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * core.hooks.addAction('user_registered', async (user: User) => {
177
+ * await sendWelcomeEmail(user);
178
+ * });
179
+ *
180
+ * // With explicit type override
181
+ * core.hooks.addAction('sync_handler', handler, { type: 'async' });
182
+ * ```
183
+ */
184
+ addAction<TArgs = unknown>(hook: string, callback: ActionCallback<TArgs>, options?: ListenerOptions): void;
185
+ /**
186
+ * Run all registered actions.
187
+ *
188
+ * This method supports both synchronous and asynchronous dispatch based on configuration.
189
+ * In hybrid mode, it auto-detects async listeners and uses async dispatch.
190
+ *
191
+ * @template TArgs - The type of arguments passed to the action.
192
+ * @param hook - The name of the hook.
193
+ * @param args - The arguments to pass to the callbacks.
194
+ * @param options - Optional event options for async dispatch.
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * await core.hooks.doAction('user_registered', user);
199
+ * ```
200
+ */
201
+ doAction<TArgs = unknown>(hook: string, args: TArgs, options?: EventOptions): Promise<void>;
202
+ /**
203
+ * Run all registered actions synchronously (legacy mode).
204
+ *
205
+ * @template TArgs - The type of arguments passed to the action.
206
+ * @param hook - The name of the hook.
207
+ * @param args - The arguments to pass to the callbacks.
208
+ * @internal
209
+ */
210
+ doActionSync<TArgs = unknown>(hook: string, args: TArgs): Promise<void>;
211
+ /**
212
+ * Run all registered actions asynchronously via priority queue.
213
+ *
214
+ * This method uses EventPriorityQueue for async dispatch with support for:
215
+ * - Priority-based processing (high > normal > low)
216
+ * - Timeout handling
217
+ * - Ordering guarantees (strict, partition, none)
218
+ * - Idempotency
219
+ *
220
+ * @template TArgs - The type of arguments passed to the action.
221
+ * @param hook - The name of the hook.
222
+ * @param args - The arguments to pass to the callbacks.
223
+ * @param options - Event options for async dispatch.
224
+ *
225
+ * @example
226
+ * ```typescript
227
+ * await core.hooks.doActionAsync('order:created', order, {
228
+ * priority: 'high',
229
+ * ordering: 'partition',
230
+ * partitionKey: order.id,
231
+ * timeout: 5000,
232
+ * });
233
+ * ```
234
+ */
235
+ doActionAsync<TArgs = unknown>(hook: string, args: TArgs, options?: EventOptions): Promise<void>;
236
+ /**
237
+ * Determine if async dispatch should be used.
238
+ *
239
+ * @param callbacks - Callbacks to check
240
+ * @param options - Event options
241
+ * @returns True if async dispatch should be used
242
+ * @internal
243
+ */
244
+ /**
245
+ * Determine the dispatch mode for an event.
246
+ *
247
+ * @param eventName - The name of the event
248
+ * @param options - Optional event options
249
+ * @returns The dispatch mode: 'sync' or 'async'
250
+ * @public
251
+ */
252
+ detectMode(eventName: string, options?: EventOptions): 'sync' | 'async';
253
+ /**
254
+ * Check if a callback is an async function (with caching).
255
+ *
256
+ * Detection methods:
257
+ * 1. Check cache first
258
+ * 2. Check type override
259
+ * 3. Check constructor.name === 'AsyncFunction'
260
+ * 4. Fallback: Check function string representation
261
+ *
262
+ * @param callback - The callback to check
263
+ * @returns True if the callback is async
264
+ * @public
265
+ */
266
+ isAsyncListener(callback: ActionCallback): boolean;
267
+ /**
268
+ * Cache async detection result.
269
+ * @internal
270
+ */
271
+ private cacheAsyncResult;
272
+ /**
273
+ * Runtime detection for functions that return Promises but aren't declared async.
274
+ *
275
+ * This method executes the callback with test args and checks if the result is a Promise.
276
+ * Use with caution as it actually invokes the callback.
277
+ *
278
+ * @param callback - The callback to check
279
+ * @param testArgs - Arguments to pass to the callback for testing
280
+ * @returns True if the callback returns a Promise
281
+ * @public
282
+ */
283
+ isAsyncListenerRuntime<TArgs = unknown>(callback: ActionCallback<TArgs>, testArgs: TArgs): Promise<boolean>;
284
+ /**
285
+ * Get the size of the async detection cache (for testing/debugging).
286
+ *
287
+ * @returns Number of cached detection results
288
+ * @public
289
+ */
290
+ getAsyncDetectionCacheSize(): number;
291
+ /**
292
+ * Clear the async detection cache.
293
+ *
294
+ * @public
295
+ */
296
+ clearAsyncDetectionCache(): void;
297
+ /**
298
+ * Check if any listener for a hook is async (including type overrides).
299
+ *
300
+ * @param hook - Hook name
301
+ * @returns True if any listener is async
302
+ * @public
303
+ */
304
+ hasAsyncListeners(hook: string): boolean;
305
+ /**
306
+ * Check if a listener is effectively async (considering type override).
307
+ *
308
+ * @param callback - The callback to check
309
+ * @returns True if the listener should be treated as async
310
+ * @internal
311
+ */
312
+ private isListenerEffectivelyAsync;
313
+ /**
314
+ * Get detailed information about all listeners for a hook.
315
+ *
316
+ * @param hook - Hook name
317
+ * @returns Array of listener info objects
318
+ * @public
319
+ */
320
+ getListenerInfo(hook: string): ListenerInfo[];
321
+ private shouldUseAsyncDispatch;
322
+ /**
323
+ * Get the current event queue depth.
324
+ *
325
+ * @returns Total number of events in the queue
326
+ */
327
+ getQueueDepth(): number;
328
+ /**
329
+ * Get the event queue depth for a specific priority.
330
+ *
331
+ * @param priority - Priority level
332
+ * @returns Number of events in the specified priority queue
333
+ */
334
+ getQueueDepthByPriority(priority: 'high' | 'normal' | 'low'): number;
335
+ /**
336
+ * Get the EventPriorityQueue instance.
337
+ *
338
+ * @returns EventPriorityQueue instance
339
+ * @protected
340
+ */
341
+ protected getEventQueue(): EventPriorityQueue;
342
+ /**
343
+ * Get all registered listeners for a hook.
344
+ *
345
+ * @param hook - Hook name
346
+ * @returns Array of callbacks
347
+ * @internal
348
+ */
349
+ getListeners(hook: string): ActionCallback[];
350
+ /**
351
+ * Update HookManager configuration.
352
+ *
353
+ * @param config - New configuration
354
+ */
355
+ configure(config: Partial<HookManagerConfig>): void;
356
+ /**
357
+ * Get current configuration.
358
+ *
359
+ * @returns Current configuration
360
+ */
361
+ getConfig(): HookManagerConfig;
362
+ /**
363
+ * Suppress migration warnings for a specific event.
364
+ *
365
+ * @param eventName - The name of the event to suppress warnings for
366
+ * @public
367
+ */
368
+ suppressMigrationWarning(eventName: string): void;
369
+ /**
370
+ * Set the event backend for distributed processing.
371
+ *
372
+ * @param backend - Event backend instance
373
+ */
374
+ setBackend(backend: EventBackend): void;
375
+ /**
376
+ * Get the Dead Letter Queue instance.
377
+ *
378
+ * @returns Dead Letter Queue
379
+ */
380
+ getDLQ(): DeadLetterQueue | undefined;
381
+ /**
382
+ * Requeue a failed event from the Dead Letter Queue.
383
+ *
384
+ * @param dlqEntryId - DLQ entry ID
385
+ * @returns True if requeued successfully, false if entry not found
386
+ */
387
+ requeueDLQEntry(dlqEntryId: string): Promise<boolean>;
388
+ /**
389
+ * Requeue all failed events for a specific event name.
390
+ *
391
+ * @param eventName - Event name to requeue
392
+ * @returns Number of events requeued
393
+ */
394
+ requeueDLQBatch(eventName: string): Promise<number>;
395
+ /**
396
+ * Get Dead Letter Queue entries with optional filtering.
397
+ *
398
+ * @param filter - Filter options
399
+ * @returns Array of DLQ entries
400
+ */
401
+ getDLQEntries(filter?: {
402
+ eventName?: string;
403
+ from?: number;
404
+ to?: number;
405
+ limit?: number;
406
+ }): import("@gravito/core").DLQEntry[];
407
+ /**
408
+ * Get count of Dead Letter Queue entries for an event.
409
+ *
410
+ * @param eventName - Event name
411
+ * @returns Count of entries
412
+ */
413
+ getDLQCount(eventName: string): number;
414
+ /**
415
+ * Delete a DLQ entry.
416
+ *
417
+ * @param entryId - DLQ entry ID
418
+ * @returns True if deleted, false if not found
419
+ */
420
+ deleteDLQEntry(entryId: string): boolean;
421
+ /**
422
+ * Get circuit breaker statistics for all events.
423
+ *
424
+ * @returns Array of circuit breaker statistics
425
+ */
426
+ getCircuitBreakerStats(): Array<{
427
+ eventName: string;
428
+ state: string;
429
+ failureCount: number;
430
+ successCount: number;
431
+ lastFailureAt?: Date;
432
+ lastSuccessAt?: Date;
433
+ openedAt?: Date;
434
+ totalRequests: number;
435
+ totalFailures: number;
436
+ totalSuccesses: number;
437
+ }>;
438
+ /**
439
+ * Reset a circuit breaker for an event.
440
+ *
441
+ * @param eventName - Event name
442
+ * @returns True if reset, false if circuit breaker not found
443
+ */
444
+ resetCircuitBreaker(eventName: string): boolean;
445
+ /**
446
+ * Remove all listeners for a specific action hook.
447
+ *
448
+ * @param hook - Hook name
449
+ */
450
+ removeAction(hook: string): void;
451
+ /**
452
+ * Get the persistent DLQ manager instance.
453
+ *
454
+ * @returns DeadLetterQueueManager or undefined if not configured
455
+ * @public
456
+ */
457
+ getPersistentDLQManager(): DeadLetterQueueManager | undefined;
458
+ /**
459
+ * Create a handler function for persistent DLQ.
460
+ * This handler is used by EventPriorityQueue to persist failed events.
461
+ *
462
+ * @returns Handler function
463
+ * @internal
464
+ */
465
+ private createPersistentDLQHandler;
466
+ /**
467
+ * Requeue a failed event from the persistent DLQ.
468
+ *
469
+ * @param dlqId - DLQ entry UUID
470
+ * @returns True if requeued successfully
471
+ * @public
472
+ */
473
+ requeuePersistentDLQEntry(dlqId: string): Promise<boolean>;
474
+ /**
475
+ * Requeue multiple events from persistent DLQ.
476
+ *
477
+ * @param filter - Filter criteria
478
+ * @returns Result statistics
479
+ * @public
480
+ */
481
+ requeuePersistentDLQBatch(filter?: {
482
+ eventName?: string;
483
+ status?: 'pending' | 'requeued' | 'resolved' | 'abandoned';
484
+ }): Promise<{
485
+ total: number;
486
+ succeeded: number;
487
+ failed: number;
488
+ }>;
489
+ /**
490
+ * Get persistent DLQ statistics.
491
+ *
492
+ * @returns Statistics object with total, byEvent, and byStatus counts
493
+ * @public
494
+ */
495
+ getPersistentDLQStats(): Promise<import("@gravito/core").DLQStats | undefined>;
496
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Listener-related types and interfaces.
3
+ */
4
+ export type { Listener, ShouldQueue } from './types/events';
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Standard logger interface.
3
+ *
4
+ * PSR-3 inspired API for easy swapping (e.g., Winston, Pino).
5
+ */
6
+ export interface Logger {
7
+ debug(message: string, ...args: unknown[]): void;
8
+ info(message: string, ...args: unknown[]): void;
9
+ warn(message: string, ...args: unknown[]): void;
10
+ error(message: string, ...args: unknown[]): void;
11
+ }
12
+ /**
13
+ * Default console logger implementation.
14
+ */
15
+ export declare class ConsoleLogger implements Logger {
16
+ debug(message: string, ...args: unknown[]): void;
17
+ info(message: string, ...args: unknown[]): void;
18
+ warn(message: string, ...args: unknown[]): void;
19
+ error(message: string, ...args: unknown[]): void;
20
+ }