@gravito/echo 3.0.1 → 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 (173) 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 +43 -17
  81. package/dist/core/src/CommandKernel.d.ts +33 -0
  82. package/dist/core/src/Container.d.ts +78 -14
  83. package/dist/core/src/HookManager.d.ts +422 -8
  84. package/dist/core/src/PlanetCore.d.ts +52 -7
  85. package/dist/core/src/Router.d.ts +41 -7
  86. package/dist/core/src/ServiceProvider.d.ts +14 -8
  87. package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +1 -0
  88. package/dist/core/src/adapters/PhotonAdapter.d.ts +1 -0
  89. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +1 -0
  90. package/dist/core/src/adapters/types.d.ts +39 -0
  91. package/dist/core/src/engine/AOTRouter.d.ts +1 -11
  92. package/dist/core/src/engine/FastContext.d.ts +4 -2
  93. package/dist/core/src/engine/Gravito.d.ts +1 -1
  94. package/dist/core/src/engine/MinimalContext.d.ts +4 -2
  95. package/dist/core/src/engine/types.d.ts +6 -1
  96. package/dist/core/src/events/CircuitBreaker.d.ts +229 -0
  97. package/dist/core/src/events/DeadLetterQueue.d.ts +145 -0
  98. package/dist/core/src/events/EventBackend.d.ts +11 -0
  99. package/dist/core/src/events/EventOptions.d.ts +109 -0
  100. package/dist/core/src/events/EventPriorityQueue.d.ts +202 -0
  101. package/dist/core/src/events/IdempotencyCache.d.ts +60 -0
  102. package/dist/core/src/events/index.d.ts +14 -0
  103. package/dist/core/src/events/observability/EventMetrics.d.ts +132 -0
  104. package/dist/core/src/events/observability/EventTracer.d.ts +68 -0
  105. package/dist/core/src/events/observability/EventTracing.d.ts +161 -0
  106. package/dist/core/src/events/observability/OTelEventMetrics.d.ts +240 -0
  107. package/dist/core/src/events/observability/ObservableHookManager.d.ts +108 -0
  108. package/dist/core/src/events/observability/index.d.ts +20 -0
  109. package/dist/core/src/events/observability/metrics-types.d.ts +16 -0
  110. package/dist/core/src/events/types.d.ts +75 -0
  111. package/dist/core/src/exceptions/CircularDependencyException.d.ts +9 -0
  112. package/dist/core/src/exceptions/index.d.ts +1 -0
  113. package/dist/core/src/http/cookie.d.ts +29 -0
  114. package/dist/core/src/http/types.d.ts +21 -0
  115. package/dist/core/src/index.d.ts +13 -3
  116. package/dist/core/src/instrumentation/index.d.ts +35 -0
  117. package/dist/core/src/instrumentation/opentelemetry.d.ts +178 -0
  118. package/dist/core/src/instrumentation/types.d.ts +182 -0
  119. package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +316 -0
  120. package/dist/core/src/reliability/RetryPolicy.d.ts +217 -0
  121. package/dist/core/src/reliability/index.d.ts +6 -0
  122. package/dist/core/src/router/ControllerDispatcher.d.ts +12 -0
  123. package/dist/core/src/router/RequestValidator.d.ts +20 -0
  124. package/dist/echo/src/OrbitEcho.d.ts +71 -16
  125. package/dist/echo/src/dlq/DeadLetterQueue.d.ts +94 -0
  126. package/dist/echo/src/dlq/MemoryDeadLetterQueue.d.ts +36 -0
  127. package/dist/echo/src/dlq/index.d.ts +2 -0
  128. package/dist/echo/src/index.d.ts +31 -15
  129. package/dist/echo/src/middleware/RequestBufferMiddleware.d.ts +62 -0
  130. package/dist/echo/src/middleware/index.d.ts +8 -0
  131. package/dist/echo/src/observability/index.d.ts +3 -0
  132. package/dist/echo/src/observability/logging/ConsoleEchoLogger.d.ts +37 -0
  133. package/dist/echo/src/observability/logging/EchoLogger.d.ts +38 -0
  134. package/dist/echo/src/observability/logging/index.d.ts +2 -0
  135. package/dist/echo/src/observability/metrics/MetricsProvider.d.ts +69 -0
  136. package/dist/echo/src/observability/metrics/NoopMetricsProvider.d.ts +17 -0
  137. package/dist/echo/src/observability/metrics/PrometheusMetricsProvider.d.ts +39 -0
  138. package/dist/echo/src/observability/metrics/index.d.ts +3 -0
  139. package/dist/echo/src/observability/tracing/NoopTracer.d.ts +33 -0
  140. package/dist/echo/src/observability/tracing/Tracer.d.ts +75 -0
  141. package/dist/echo/src/observability/tracing/index.d.ts +2 -0
  142. package/dist/echo/src/providers/GenericProvider.d.ts +37 -18
  143. package/dist/echo/src/providers/GitHubProvider.d.ts +21 -12
  144. package/dist/echo/src/providers/LinearProvider.d.ts +27 -0
  145. package/dist/echo/src/providers/PaddleProvider.d.ts +31 -0
  146. package/dist/echo/src/providers/ShopifyProvider.d.ts +27 -0
  147. package/dist/echo/src/providers/SlackProvider.d.ts +27 -0
  148. package/dist/echo/src/providers/StripeProvider.d.ts +20 -12
  149. package/dist/echo/src/providers/TwilioProvider.d.ts +31 -0
  150. package/dist/echo/src/providers/base/BaseProvider.d.ts +87 -0
  151. package/dist/echo/src/providers/base/HeaderUtils.d.ts +34 -0
  152. package/dist/echo/src/providers/index.d.ts +14 -3
  153. package/dist/echo/src/receive/SignatureValidator.d.ts +33 -0
  154. package/dist/echo/src/receive/WebhookReceiver.d.ts +139 -21
  155. package/dist/echo/src/replay/WebhookReplayService.d.ts +35 -0
  156. package/dist/echo/src/replay/index.d.ts +1 -0
  157. package/dist/echo/src/resilience/CircuitBreaker.d.ts +117 -0
  158. package/dist/echo/src/resilience/index.d.ts +10 -0
  159. package/dist/echo/src/rotation/KeyRotationManager.d.ts +127 -0
  160. package/dist/echo/src/rotation/index.d.ts +10 -0
  161. package/dist/echo/src/send/WebhookDispatcher.d.ts +159 -15
  162. package/dist/echo/src/storage/MemoryWebhookStore.d.ts +14 -0
  163. package/dist/echo/src/storage/WebhookStore.d.ts +236 -0
  164. package/dist/echo/src/storage/index.d.ts +2 -0
  165. package/dist/echo/src/types.d.ts +656 -64
  166. package/dist/index.js +1327 -189
  167. package/dist/index.js.map +28 -10
  168. package/dist/photon/src/index.d.ts +69 -5
  169. package/dist/photon/src/middleware/binary.d.ts +12 -15
  170. package/dist/photon/src/middleware/htmx.d.ts +39 -0
  171. package/dist/photon/src/middleware/ratelimit.d.ts +157 -0
  172. package/dist/photon/src/openapi.d.ts +19 -0
  173. package/package.json +7 -5
@@ -1,3 +1,10 @@
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';
1
8
  /**
2
9
  * Callback function for filters (transforms values).
3
10
  * @public
@@ -9,19 +16,123 @@ export type FilterCallback<T = unknown> = (value: T, ...args: unknown[]) => Prom
9
16
  */
10
17
  export type ActionCallback<TArgs = unknown> = (args: TArgs) => Promise<void> | void;
11
18
  /**
12
- * Manager for WordPress-style hooks (actions and filters).
19
+ * Options for listener registration.
13
20
  * @public
14
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
+ }
15
102
  export declare class HookManager {
16
103
  private filters;
17
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);
18
128
  /**
19
129
  * Register a filter hook.
20
130
  *
21
- * Filters are used to transform a value (input/output).
131
+ * Filters are used to transform a value (input/output) through a chain of
132
+ * callbacks. Each callback must return the modified value.
22
133
  *
23
134
  * @template T - The type of value being filtered.
24
- * @param hook - The name of the hook.
135
+ * @param hook - The unique name of the hook.
25
136
  * @param callback - The callback function to execute.
26
137
  *
27
138
  * @example
@@ -52,31 +163,334 @@ export declare class HookManager {
52
163
  /**
53
164
  * Register an action hook.
54
165
  *
55
- * Actions are for side effects (no return value).
166
+ * Actions are used to trigger side effects (e.g., logging, sending emails)
167
+ * at specific points in the application lifecycle.
56
168
  *
57
169
  * @template TArgs - The type of arguments passed to the action.
58
- * @param hook - The name of the hook.
170
+ * @param hook - The unique name of the hook.
59
171
  * @param callback - The callback function to execute.
172
+ * @param options - Optional listener options (type override, circuit breaker).
60
173
  *
61
174
  * @example
62
175
  * ```typescript
63
176
  * core.hooks.addAction('user_registered', async (user: User) => {
64
177
  * await sendWelcomeEmail(user);
65
178
  * });
179
+ *
180
+ * // With explicit type override
181
+ * core.hooks.addAction('sync_handler', handler, { type: 'async' });
66
182
  * ```
67
183
  */
68
- addAction<TArgs = unknown>(hook: string, callback: ActionCallback<TArgs>): void;
184
+ addAction<TArgs = unknown>(hook: string, callback: ActionCallback<TArgs>, options?: ListenerOptions): void;
69
185
  /**
70
- * Run all registered actions sequentially.
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.
71
190
  *
72
191
  * @template TArgs - The type of arguments passed to the action.
73
192
  * @param hook - The name of the hook.
74
193
  * @param args - The arguments to pass to the callbacks.
194
+ * @param options - Optional event options for async dispatch.
75
195
  *
76
196
  * @example
77
197
  * ```typescript
78
198
  * await core.hooks.doAction('user_registered', user);
79
199
  * ```
80
200
  */
81
- doAction<TArgs = unknown>(hook: string, args: TArgs): Promise<void>;
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>;
82
496
  }
@@ -123,7 +123,10 @@ export declare class PlanetCore {
123
123
  private deferredProviders;
124
124
  private bootedProviders;
125
125
  /**
126
- * Register a service provider.
126
+ * Register a service provider to the core.
127
+ *
128
+ * Service providers are the central place to configure your application.
129
+ * They bind services to the container and bootstrap application features.
127
130
  *
128
131
  * @param provider - The ServiceProvider instance to register.
129
132
  * @returns The PlanetCore instance for chaining.
@@ -137,12 +140,19 @@ export declare class PlanetCore {
137
140
  /**
138
141
  * Bootstrap the application by registering and booting providers.
139
142
  *
140
- * This method must be called before the application starts handling requests.
141
- * It calls `register()` on all providers first, then `boot()` on all providers.
143
+ * This method orchestrates the two-phase startup sequence:
144
+ * 1. Registration: Calls `register()` on all providers to bind services.
145
+ * 2. Booting: Calls `boot()` on all providers once all bindings are ready.
142
146
  *
143
- * Supports async register() methods.
147
+ * This method must be called before the application starts handling requests.
144
148
  *
145
149
  * @returns Promise that resolves when bootstrapping is complete.
150
+ * @throws Error if a deferred provider has an asynchronous register method.
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * await core.bootstrap();
155
+ * ```
146
156
  */
147
157
  bootstrap(): Promise<void>;
148
158
  /**
@@ -197,11 +207,36 @@ export declare class PlanetCore {
197
207
  * ```
198
208
  */
199
209
  use(satellite: ServiceProvider | ((core: PlanetCore) => void | Promise<void>)): Promise<this>;
210
+ /**
211
+ * Register a global error handler for process-level exceptions.
212
+ *
213
+ * Captures `unhandledRejection` and `uncaughtException` to prevent process crashes
214
+ * and allow for graceful shutdown or error reporting.
215
+ *
216
+ * @param options - Configuration for global error handling.
217
+ * @returns A function to unregister the global error handlers.
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * const unregister = core.registerGlobalErrorHandlers({
222
+ * exitOnFatal: true
223
+ * });
224
+ * ```
225
+ */
200
226
  registerGlobalErrorHandlers(options?: Omit<RegisterGlobalErrorHandlersOptions, 'core'>): () => void;
201
227
  /**
202
- * Predictive Route Warming (JIT Optimization)
228
+ * Predictive Route Warming (JIT Optimization).
229
+ *
230
+ * Pre-compiles or warms up the specified paths in the HTTP adapter to reduce
231
+ * latency for the first request to these endpoints.
203
232
  *
204
- * @param paths List of paths to warm up
233
+ * @param paths - List of paths to warm up.
234
+ * @returns Promise that resolves when warming is complete.
235
+ *
236
+ * @example
237
+ * ```typescript
238
+ * await core.warmup(['/api/v1/products', '/api/v1/categories']);
239
+ * ```
205
240
  */
206
241
  warmup(paths: string[]): Promise<void>;
207
242
  /**
@@ -217,10 +252,19 @@ export declare class PlanetCore {
217
252
  */
218
253
  static boot(config: GravitoConfig): Promise<PlanetCore>;
219
254
  /**
220
- * Mount an Orbit (a PlanetCore instance or native app) to a path.
255
+ * Mount an Orbit (a PlanetCore instance or native app) to a specific URL path.
256
+ *
257
+ * This allows for micro-service like composition where different parts of the
258
+ * application can be developed as independent Orbits and mounted together.
221
259
  *
222
260
  * @param path - The URL path to mount the orbit at.
223
261
  * @param orbitApp - The application instance (PlanetCore, HttpAdapter, or native app).
262
+ *
263
+ * @example
264
+ * ```typescript
265
+ * const blogOrbit = new PlanetCore();
266
+ * core.mountOrbit('/blog', blogOrbit);
267
+ * ```
224
268
  */
225
269
  mountOrbit(path: string, orbitApp: unknown): void;
226
270
  /**
@@ -240,5 +284,6 @@ export declare class PlanetCore {
240
284
  port: number;
241
285
  fetch: (request: Request, server?: unknown) => Response | Promise<Response>;
242
286
  core: PlanetCore;
287
+ websocket?: HttpAdapter['websocket'];
243
288
  };
244
289
  }
@@ -5,7 +5,7 @@ import { Route } from './Route';
5
5
  * Type for Controller Class Constructor
6
6
  * @public
7
7
  */
8
- export type ControllerClass = new (core: PlanetCore) => Record<string, unknown>;
8
+ export type ControllerClass = new (core: PlanetCore) => any;
9
9
  /**
10
10
  * Handler can be a function or [Class, 'methodName']
11
11
  * @public
@@ -125,7 +125,7 @@ export declare class Router {
125
125
  path: string;
126
126
  domain?: string;
127
127
  }>;
128
- private controllers;
128
+ private dispatcher;
129
129
  private namedRoutes;
130
130
  private bindings;
131
131
  /**
@@ -144,6 +144,21 @@ export declare class Router {
144
144
  registerName(name: string, method: string, path: string, options?: RouteOptions): void;
145
145
  /**
146
146
  * Generate a URL from a named route.
147
+ *
148
+ * Replaces route parameters (e.g., `:id`) with provided values and appends
149
+ * query parameters to the URL.
150
+ *
151
+ * @param name - The name of the route.
152
+ * @param params - Key-value pairs for route parameters.
153
+ * @param query - Key-value pairs for query string parameters.
154
+ * @returns The generated URL string.
155
+ * @throws Error if the named route is not found or if a required parameter is missing.
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * const url = router.url('users.show', { id: 1 }, { tab: 'profile' });
160
+ * // Result: "/users/1?tab=profile"
161
+ * ```
147
162
  */
148
163
  url(name: string, params?: Record<string, string | number>, query?: Record<string, string | number | boolean | null | undefined>): string;
149
164
  /**
@@ -164,6 +179,17 @@ export declare class Router {
164
179
  }>): void;
165
180
  /**
166
181
  * Register a route model binding.
182
+ *
183
+ * Automatically resolves a route parameter to an object using the provided
184
+ * resolver function. The resolved object is then available in the request context.
185
+ *
186
+ * @param param - The name of the route parameter to bind.
187
+ * @param resolver - An async function that resolves the parameter value to an object.
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * router.bind('user', async (id) => await User.find(id));
192
+ * ```
167
193
  */
168
194
  bind(param: string, resolver: (id: string) => Promise<unknown>): void;
169
195
  /**
@@ -223,17 +249,25 @@ export declare class Router {
223
249
  */
224
250
  forward(method: HttpMethod | HttpMethod[] | 'all', path: string, target: string, options?: ProxyOptions): void;
225
251
  /**
226
- * Register a resource route (Laravel-style).
252
+ * Register a resource route (RESTful).
253
+ *
254
+ * Automatically creates multiple routes for a resource (index, create, store,
255
+ * show, edit, update, destroy) mapping to specific controller methods.
256
+ *
257
+ * @param name - The resource name (e.g., 'users').
258
+ * @param controller - The controller class handling the resource.
259
+ * @param options - Optional constraints (only/except) for resource actions.
260
+ *
261
+ * @example
262
+ * ```typescript
263
+ * router.resource('photos', PhotoController);
264
+ * ```
227
265
  */
228
266
  resource(name: string, controller: ControllerClass, options?: ResourceOptions): void;
229
267
  /**
230
268
  * Internal Request Registration
231
269
  */
232
270
  req(method: HttpMethod, path: string, requestOrHandlerOrMiddleware: FormRequestClass | RouteHandler | GravitoMiddleware | GravitoMiddleware[], handler?: RouteHandler, options?: RouteOptions): Route;
233
- /**
234
- * Resolve Controller Instance and Method
235
- */
236
- private resolveControllerHandler;
237
271
  }
238
272
  /**
239
273
  * Standard RESTful resource action names.
@@ -82,11 +82,15 @@ export declare abstract class ServiceProvider {
82
82
  */
83
83
  setCore(core: PlanetCore): void;
84
84
  /**
85
- * Merge configuration from a file into the application config.
85
+ * Merge configuration from a value into the application config.
86
86
  *
87
- * @param config - The ConfigManager instance
88
- * @param key - The configuration key to set
89
- * @param value - The configuration value or object
87
+ * If the configuration key already exists and both the existing value and
88
+ * the new value are objects, they will be shallow-merged. Otherwise, the
89
+ * new value will overwrite the existing one.
90
+ *
91
+ * @param config - The ConfigManager instance.
92
+ * @param key - The configuration key to set (supports dot notation).
93
+ * @param value - The configuration value or object to merge.
90
94
  *
91
95
  * @example
92
96
  * ```typescript
@@ -119,11 +123,13 @@ export declare abstract class ServiceProvider {
119
123
  */
120
124
  private static publishables;
121
125
  /**
122
- * Register paths to be published.
123
- * Used by CLI commands like `gravito vendor:publish`.
126
+ * Register paths to be published by the CLI.
127
+ *
128
+ * Used by CLI commands like `gravito vendor:publish` to copy configuration,
129
+ * views, or assets from the package to the application directory.
124
130
  *
125
- * @param paths - Map of source to destination paths
126
- * @param group - Optional group name for selective publishing
131
+ * @param paths - A record mapping source paths to destination paths.
132
+ * @param group - Optional group name for selective publishing (e.g., 'config', 'views').
127
133
  *
128
134
  * @example
129
135
  * ```typescript