@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
@@ -0,0 +1,240 @@
1
+ /**
2
+ * @gravito/core - OpenTelemetry Event Metrics
3
+ *
4
+ * Provides event system metrics using OpenTelemetry API directly.
5
+ * This enables Prometheus export without requiring @gravito/monitor dependency.
6
+ *
7
+ * Metrics:
8
+ * - gravito_event_dispatch_duration_seconds (Histogram)
9
+ * - gravito_event_listener_duration_seconds (Histogram)
10
+ * - gravito_event_queue_depth (Observable Gauge)
11
+ *
12
+ * @packageDocumentation
13
+ */
14
+ import type { Meter } from '@opentelemetry/api';
15
+ import type { CircuitBreakerMetricsRecorder } from '../CircuitBreaker';
16
+ /**
17
+ * Queue depth callback type.
18
+ * Returns the current queue depths for each priority level.
19
+ */
20
+ export type QueueDepthCallback = () => {
21
+ high: number;
22
+ normal: number;
23
+ low: number;
24
+ };
25
+ /**
26
+ * Circuit breaker state callback type.
27
+ * Returns the current state of a circuit breaker.
28
+ */
29
+ export type CircuitBreakerStateCallback = () => {
30
+ eventName: string;
31
+ listenerIndex: number;
32
+ state: 0 | 1 | 2;
33
+ };
34
+ /**
35
+ * OpenTelemetry-based Event Metrics collector.
36
+ *
37
+ * Uses OpenTelemetry API directly for metrics collection, enabling
38
+ * Prometheus export through the OpenTelemetry SDK.
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * import { metrics } from '@opentelemetry/api'
43
+ * import { OTelEventMetrics } from '@gravito/core'
44
+ *
45
+ * const meter = metrics.getMeter('@gravito/core', '1.0.0')
46
+ * const eventMetrics = new OTelEventMetrics(meter)
47
+ *
48
+ * // Record dispatch duration
49
+ * eventMetrics.recordDispatchDuration('order:created', 'high', 0.123)
50
+ *
51
+ * // Record listener duration
52
+ * eventMetrics.recordListenerDuration('order:created', 0, 0.456)
53
+ *
54
+ * // Set queue depth callback
55
+ * eventMetrics.setQueueDepthCallback(() => ({
56
+ * high: 10,
57
+ * normal: 50,
58
+ * low: 100
59
+ * }))
60
+ * ```
61
+ *
62
+ * @public
63
+ */
64
+ export declare class OTelEventMetrics implements CircuitBreakerMetricsRecorder {
65
+ private readonly meter;
66
+ private readonly prefix;
67
+ private readonly dispatchDurationHistogram;
68
+ private readonly listenerDurationHistogram;
69
+ private readonly queueDepthGauge;
70
+ private readonly cbStateGauge;
71
+ private readonly cbFailuresCounter;
72
+ private readonly cbSuccessesCounter;
73
+ private readonly cbTransitionsCounter;
74
+ private readonly cbOpenDurationHistogram;
75
+ private queueDepthCallback?;
76
+ private circuitBreakerStateCallbacks;
77
+ private recordedCircuitBreakerStates;
78
+ /**
79
+ * Bucket boundaries for dispatch duration histogram.
80
+ */
81
+ private readonly dispatchDurationBuckets;
82
+ /**
83
+ * Bucket boundaries for listener duration histogram.
84
+ */
85
+ private readonly listenerDurationBuckets;
86
+ /**
87
+ * Bucket boundaries for circuit breaker open duration histogram.
88
+ */
89
+ private readonly cbOpenDurationBuckets;
90
+ /**
91
+ * Create a new OTelEventMetrics instance.
92
+ *
93
+ * @param meter - OpenTelemetry Meter instance
94
+ * @param prefix - Metric name prefix (default: 'gravito_event_')
95
+ */
96
+ constructor(meter: Meter, prefix?: string);
97
+ /**
98
+ * Record event dispatch duration.
99
+ *
100
+ * @param eventName - Name of the event
101
+ * @param priority - Priority level (high, normal, low)
102
+ * @param durationSeconds - Duration in seconds
103
+ */
104
+ recordDispatchDuration(eventName: string, priority: string, durationSeconds: number): void;
105
+ /**
106
+ * Record listener execution duration.
107
+ *
108
+ * @param eventName - Name of the event
109
+ * @param listenerIndex - Index of the listener in the callback list
110
+ * @param durationSeconds - Duration in seconds
111
+ */
112
+ recordListenerDuration(eventName: string, listenerIndex: number, durationSeconds: number): void;
113
+ /**
114
+ * Set the callback for queue depth observable gauge.
115
+ *
116
+ * The callback will be invoked when metrics are collected,
117
+ * allowing real-time reporting of queue depths.
118
+ *
119
+ * @param callback - Function returning current queue depths
120
+ */
121
+ setQueueDepthCallback(callback: QueueDepthCallback): void;
122
+ /**
123
+ * Register a circuit breaker state callback for monitoring.
124
+ *
125
+ * @param key - Unique identifier for the circuit breaker (e.g., "order:created-0")
126
+ * @param callback - Function returning current circuit breaker state
127
+ */
128
+ registerCircuitBreakerStateCallback(key: string, callback: CircuitBreakerStateCallback): void;
129
+ /**
130
+ * Unregister a circuit breaker state callback.
131
+ *
132
+ * @param key - Unique identifier for the circuit breaker
133
+ */
134
+ unregisterCircuitBreakerStateCallback(key: string): void;
135
+ /**
136
+ * Record circuit breaker state change.
137
+ *
138
+ * @param name - Name of the circuit breaker (usually event name)
139
+ * @param state - State as number (0=CLOSED, 1=HALF_OPEN, 2=OPEN)
140
+ */
141
+ recordState(name: string, state: number): void;
142
+ /**
143
+ * Record circuit breaker state transition.
144
+ *
145
+ * @param name - Name of the circuit breaker
146
+ * @param fromState - Previous state
147
+ * @param toState - New state
148
+ */
149
+ recordTransition(name: string, fromState: string, toState: string): void;
150
+ /**
151
+ * Record circuit breaker failure.
152
+ *
153
+ * @param name - Name of the circuit breaker
154
+ */
155
+ recordFailure(name: string): void;
156
+ /**
157
+ * Record circuit breaker success.
158
+ *
159
+ * @param name - Name of the circuit breaker
160
+ */
161
+ recordSuccess(name: string): void;
162
+ /**
163
+ * Record circuit breaker open duration.
164
+ *
165
+ * @param name - Name of the circuit breaker
166
+ * @param seconds - Duration in seconds
167
+ */
168
+ recordOpenDuration(name: string, seconds: number): void;
169
+ /**
170
+ * Record circuit breaker failure.
171
+ *
172
+ * @param eventName - Name of the event
173
+ * @param listenerIndex - Index of the listener
174
+ */
175
+ recordCircuitBreakerFailure(eventName: string, listenerIndex: number): void;
176
+ /**
177
+ * Record circuit breaker success.
178
+ *
179
+ * @param eventName - Name of the event
180
+ * @param listenerIndex - Index of the listener
181
+ */
182
+ recordCircuitBreakerSuccess(eventName: string, listenerIndex: number): void;
183
+ /**
184
+ * Record circuit breaker state transition.
185
+ *
186
+ * @param eventName - Name of the event
187
+ * @param listenerIndex - Index of the listener
188
+ * @param fromState - Previous state (CLOSED, HALF_OPEN, OPEN)
189
+ * @param toState - New state (CLOSED, HALF_OPEN, OPEN)
190
+ */
191
+ recordCircuitBreakerTransition(eventName: string, listenerIndex: number, fromState: string, toState: string): void;
192
+ /**
193
+ * Record circuit breaker open duration.
194
+ *
195
+ * @param eventName - Name of the event
196
+ * @param listenerIndex - Index of the listener
197
+ * @param durationSeconds - Duration in seconds
198
+ */
199
+ recordCircuitBreakerOpenDuration(eventName: string, listenerIndex: number, durationSeconds: number): void;
200
+ /**
201
+ * Get the bucket boundaries for dispatch duration histogram.
202
+ *
203
+ * @returns Array of bucket boundaries in seconds
204
+ */
205
+ getDispatchDurationBuckets(): number[];
206
+ /**
207
+ * Get the bucket boundaries for listener duration histogram.
208
+ *
209
+ * @returns Array of bucket boundaries in seconds
210
+ */
211
+ getListenerDurationBuckets(): number[];
212
+ /**
213
+ * Get the OpenTelemetry Meter instance.
214
+ *
215
+ * @returns Meter instance
216
+ */
217
+ getMeter(): Meter;
218
+ /**
219
+ * Get the metric name prefix.
220
+ *
221
+ * @returns Metric name prefix
222
+ */
223
+ getPrefix(): string;
224
+ /**
225
+ * Get the bucket boundaries for circuit breaker open duration histogram.
226
+ *
227
+ * @returns Array of bucket boundaries in seconds
228
+ */
229
+ getCircuitBreakerOpenDurationBuckets(): number[];
230
+ /**
231
+ * Get all registered circuit breaker state callback keys.
232
+ *
233
+ * @returns Array of registered keys
234
+ */
235
+ getRegisteredCircuitBreakers(): string[];
236
+ /**
237
+ * Clear all circuit breaker state callbacks.
238
+ */
239
+ clearCircuitBreakerCallbacks(): void;
240
+ }
@@ -0,0 +1,108 @@
1
+ /**
2
+ * @gravito/core - Observable Hook Manager
3
+ *
4
+ * Wraps HookManager with observability support (metrics and tracing).
5
+ */
6
+ import { HookManager, type HookManagerConfig } from '../../HookManager';
7
+ import type { EventOptions } from '../EventOptions';
8
+ import { EventMetrics } from './EventMetrics';
9
+ import { EventTracer } from './EventTracer';
10
+ import { EventTracing } from './EventTracing';
11
+ /**
12
+ * Configuration for observability features.
13
+ * @public
14
+ */
15
+ export interface ObservabilityConfig {
16
+ /**
17
+ * Enable observability features.
18
+ * @default false
19
+ */
20
+ enabled?: boolean;
21
+ /**
22
+ * MetricsRegistry instance from @gravito/monitor.
23
+ * Required if metrics collection is enabled.
24
+ */
25
+ metrics?: any;
26
+ /**
27
+ * Enable OpenTelemetry distributed tracing.
28
+ * @default false
29
+ */
30
+ tracing?: boolean;
31
+ /**
32
+ * Prefix for metric names.
33
+ * @default 'gravito_event_'
34
+ */
35
+ metricsPrefix?: string;
36
+ }
37
+ /**
38
+ * Observable Hook Manager - extends HookManager with observability.
39
+ *
40
+ * Provides metrics and distributed tracing for event dispatch and listener execution.
41
+ * Maintains 100% backward compatibility with HookManager.
42
+ *
43
+ * @public
44
+ */
45
+ export declare class ObservableHookManager extends HookManager {
46
+ private eventMetrics?;
47
+ private eventTracer?;
48
+ private eventTracing?;
49
+ private obsConfig;
50
+ /**
51
+ * Create a new ObservableHookManager instance.
52
+ *
53
+ * @param config - HookManager configuration
54
+ * @param obsConfig - Observability configuration
55
+ */
56
+ constructor(config?: HookManagerConfig, obsConfig?: ObservabilityConfig);
57
+ /**
58
+ * Run all registered actions asynchronously via priority queue with observability.
59
+ *
60
+ * This override adds metrics and tracing to the base implementation.
61
+ *
62
+ * @template TArgs - The type of arguments passed to the action.
63
+ * @param hook - The name of the hook.
64
+ * @param args - The arguments to pass to the callbacks.
65
+ * @param options - Event options for async dispatch.
66
+ */
67
+ doActionAsync<TArgs = unknown>(hook: string, args: TArgs, options?: EventOptions): Promise<void>;
68
+ /**
69
+ * Run all registered actions synchronously with observability.
70
+ *
71
+ * This override adds metrics and tracing to the base implementation.
72
+ *
73
+ * @template TArgs - The type of arguments passed to the action.
74
+ * @param hook - The name of the hook.
75
+ * @param args - The arguments to pass to the callbacks.
76
+ */
77
+ doActionSync<TArgs = unknown>(hook: string, args: TArgs): Promise<void>;
78
+ /**
79
+ * Get the EventMetrics instance.
80
+ *
81
+ * @returns EventMetrics instance if observability is enabled, undefined otherwise
82
+ */
83
+ getMetrics(): EventMetrics | undefined;
84
+ /**
85
+ * Get the EventTracer instance.
86
+ *
87
+ * @returns EventTracer instance if tracing is enabled, undefined otherwise
88
+ */
89
+ getTracer(): EventTracer | undefined;
90
+ /**
91
+ * Update observability configuration at runtime.
92
+ *
93
+ * @param config - New observability configuration
94
+ */
95
+ setObservabilityConfig(config: Partial<ObservabilityConfig>): void;
96
+ /**
97
+ * Get the EventTracing instance.
98
+ *
99
+ * @returns EventTracing instance if tracing is enabled, undefined otherwise
100
+ */
101
+ getEventTracing(): EventTracing | undefined;
102
+ /**
103
+ * Get current observability configuration.
104
+ *
105
+ * @returns Current observability configuration
106
+ */
107
+ getObservabilityConfig(): ObservabilityConfig;
108
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @public
3
+ */
4
+ export { EventMetrics } from './EventMetrics';
5
+ /**
6
+ * @public
7
+ */
8
+ export { EventTracer } from './EventTracer';
9
+ /**
10
+ * @public
11
+ */
12
+ export { EventTracing, type EventTracingConfig, getEventTracing } from './EventTracing';
13
+ /**
14
+ * @public
15
+ */
16
+ export { type ObservabilityConfig, ObservableHookManager } from './ObservableHookManager';
17
+ /**
18
+ * @public
19
+ */
20
+ export { OTelEventMetrics, type QueueDepthCallback } from './OTelEventMetrics';
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Minimal metric types for event observability.
3
+ * Avoids importing @gravito/monitor from core to prevent circular dependency.
4
+ * Runtime implementations are provided by @gravito/monitor MetricsRegistry.
5
+ *
6
+ * @internal
7
+ */
8
+ export interface EventMetricCounter {
9
+ inc(labels: Record<string, string>): void;
10
+ }
11
+ export interface EventMetricGauge {
12
+ set(value: number, labels: Record<string, string>): void;
13
+ }
14
+ export interface EventMetricHistogram {
15
+ observe(value: number, labels: Record<string, string>): void;
16
+ }
@@ -0,0 +1,75 @@
1
+ import type { ActionCallback } from '../HookManager';
2
+ import type { EventOptions } from './EventOptions';
3
+ /**
4
+ * Event task for priority queue processing.
5
+ * @internal
6
+ */
7
+ export interface EventTask {
8
+ /**
9
+ * Unique identifier for this event task.
10
+ */
11
+ id: string;
12
+ /**
13
+ * Event hook name.
14
+ */
15
+ hook: string;
16
+ /**
17
+ * Event payload/arguments.
18
+ */
19
+ args: unknown;
20
+ /**
21
+ * Event options.
22
+ */
23
+ options: EventOptions;
24
+ /**
25
+ * Callbacks to execute for this event.
26
+ */
27
+ callbacks: ActionCallback[];
28
+ /**
29
+ * Timestamp when the event was created.
30
+ */
31
+ createdAt: number;
32
+ /**
33
+ * Partition key for ordering (if applicable).
34
+ */
35
+ partitionKey?: string;
36
+ /**
37
+ * Number of retry attempts made.
38
+ * @internal
39
+ */
40
+ retryCount?: number;
41
+ /**
42
+ * Timestamp when the event first failed.
43
+ * @internal
44
+ */
45
+ firstFailedAt?: number;
46
+ /**
47
+ * Last error encountered.
48
+ * @internal
49
+ */
50
+ lastError?: Error;
51
+ }
52
+ /**
53
+ * Strategy for handling backpressure when the queue is full.
54
+ */
55
+ export type BackpressureStrategy = 'reject' | 'drop-oldest' | 'drop-newest' | 'ignore';
56
+ /**
57
+ * Configuration for the event priority queue.
58
+ */
59
+ export interface EventQueueConfig {
60
+ /**
61
+ * Maximum number of pending events in the queue.
62
+ * If exceeded, the backpressure strategy is applied.
63
+ * @default undefined (unbounded)
64
+ */
65
+ maxSize?: number;
66
+ /**
67
+ * Strategy to use when the queue is full.
68
+ * - 'reject': Throw an error (default)
69
+ * - 'drop-oldest': Drop the oldest lowest-priority event
70
+ * - 'drop-newest': Drop the incoming event
71
+ * - 'ignore': Silently drop the incoming event
72
+ * @default 'reject'
73
+ */
74
+ strategy?: BackpressureStrategy;
75
+ }
@@ -0,0 +1,9 @@
1
+ import type { ServiceKey } from '../Container';
2
+ /**
3
+ * CircularDependencyException - Thrown when the container detects an infinite loop.
4
+ *
5
+ * @module @gravito/core
6
+ */
7
+ export declare class CircularDependencyException extends Error {
8
+ constructor(key: ServiceKey, stack: ServiceKey[]);
9
+ }
@@ -1,5 +1,6 @@
1
1
  export * from './AuthenticationException';
2
2
  export * from './AuthorizationException';
3
+ export * from './CircularDependencyException';
3
4
  export * from './GravitoException';
4
5
  export * from './HttpException';
5
6
  export * from './ModelNotFoundException';
@@ -0,0 +1,29 @@
1
+ import { type CookieOptions } from './CookieJar';
2
+ import type { GravitoContext } from './types';
3
+ /**
4
+ * Get a cookie value from the request
5
+ * @param c - Context object
6
+ * @param name - Cookie name
7
+ * @returns Cookie value or undefined
8
+ * @public
9
+ */
10
+ export declare function getCookie(c: GravitoContext, name: string): string | undefined;
11
+ /**
12
+ * Set a cookie in the response
13
+ * @param c - Context object
14
+ * @param name - Cookie name
15
+ * @param value - Cookie value
16
+ * @param options - Cookie options
17
+ * @public
18
+ */
19
+ export declare function setCookie(c: GravitoContext, name: string, value: string, options?: CookieOptions & {
20
+ maxAge?: number;
21
+ }): void;
22
+ /**
23
+ * Delete a cookie (expire it)
24
+ * @param c - Context object
25
+ * @param name - Cookie name
26
+ * @param options - Cookie options (path, domain, etc.)
27
+ * @public
28
+ */
29
+ export declare function deleteCookie(c: GravitoContext, name: string, options?: CookieOptions): void;
@@ -57,6 +57,13 @@ export interface GravitoVariables {
57
57
  * Cookie jar for managing response cookies
58
58
  */
59
59
  cookieJar?: unknown;
60
+ /**
61
+ * Middleware scope tracking for Orbit isolation
62
+ * Tracks which Orbit/scope this request belongs to
63
+ * Used to prevent cross-Orbit middleware contamination
64
+ * @since 2.3.0
65
+ */
66
+ middlewareScope?: string;
60
67
  /** @deprecated Use ctx.route() instead */
61
68
  route?: unknown;
62
69
  [key: string]: unknown;
@@ -85,6 +92,20 @@ export interface GravitoRequest {
85
92
  readonly method: string;
86
93
  /** Request path without query string */
87
94
  readonly path: string;
95
+ /**
96
+ * Route pattern (e.g., /users/:id) for the matched route
97
+ *
98
+ * This provides the parameterized route pattern instead of the concrete path,
99
+ * which is critical for preventing high cardinality issues in metrics systems.
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * // For request: GET /users/123
104
+ * ctx.req.path // => "/users/123"
105
+ * ctx.req.routePattern // => "/users/:id"
106
+ * ```
107
+ */
108
+ readonly routePattern?: string;
88
109
  /**
89
110
  * Get a route parameter value
90
111
  * @param name - Parameter name (e.g., 'id' for route '/users/:id')
@@ -17,29 +17,39 @@ export type { AdapterConfig, AdapterFactory, HttpAdapter, RouteDefinition } from
17
17
  export { isHttpAdapter } from './adapters/types';
18
18
  export type { ContentfulStatusCode, GravitoContext, GravitoErrorHandler, GravitoHandler, GravitoMiddleware, GravitoNext, GravitoNotFoundHandler, GravitoRequest, GravitoVariables, HttpMethod, StatusCode, ValidationTarget, } from './http/types';
19
19
  export { Application, type ApplicationConfig } from './Application';
20
+ export { type CommandHandler, CommandKernel } from './CommandKernel';
20
21
  export { ConfigManager } from './ConfigManager';
21
- export { Container, type Factory } from './Container';
22
+ export { Container, type Factory, type ServiceKey, type ServiceMap } from './Container';
22
23
  export { codeFromStatus, ErrorHandler, type ErrorHandlerDeps, messageFromStatus, } from './ErrorHandler';
23
24
  export { EventManager } from './EventManager';
25
+ export type { CircuitBreakerOptions, DLQEntry, DLQFilter, EventBackend, EventOptions, EventTask, } from './events';
26
+ export { CircuitBreaker, CircuitBreakerState, DEFAULT_EVENT_OPTIONS, DeadLetterQueue, EventPriorityQueue, } from './events';
27
+ export type { EventTracingConfig, ObservabilityConfig, QueueDepthCallback, } from './events/observability';
28
+ export { EventMetrics, EventTracer, EventTracing, getEventTracing, ObservableHookManager, OTelEventMetrics, } from './events/observability';
24
29
  export * from './exceptions';
25
30
  export { type GlobalErrorHandlersMode, type GlobalProcessErrorHandlerContext, type GlobalProcessErrorKind, type RegisterGlobalErrorHandlersOptions, registerGlobalErrorHandlers, } from './GlobalErrorHandlers';
26
31
  export { type GravitoManifest, GravitoServer } from './GravitoServer';
27
- export type { ActionCallback, FilterCallback } from './HookManager';
28
- export { HookManager } from './HookManager';
32
+ export type { ActionCallback, FilterCallback, ListenerInfo, ListenerOptions } from './HookManager';
33
+ export { HookManager, type HookManagerConfig } from './HookManager';
29
34
  export * from './helpers';
30
35
  export { CookieJar, type CookieOptions } from './http/CookieJar';
36
+ export { deleteCookie, getCookie, setCookie } from './http/cookie';
31
37
  export { type BodySizeLimitOptions, bodySizeLimit } from './http/middleware/BodySizeLimit';
32
38
  export { type CorsOptions, type CorsOrigin, cors } from './http/middleware/Cors';
33
39
  export { type CsrfOptions, csrfProtection, getCsrfToken } from './http/middleware/Csrf';
34
40
  export { createHeaderGate, type HeaderTokenGateOptions, type RequireHeaderTokenOptions, requireHeaderToken, } from './http/middleware/HeaderTokenGate';
35
41
  export { type HstsOptions, type SecurityHeadersOptions, securityHeaders, } from './http/middleware/SecurityHeaders';
36
42
  export { ThrottleRequests } from './http/middleware/ThrottleRequests';
43
+ export * as instrumentation from './instrumentation';
44
+ export { DEFAULT_CONFIG as OTEL_DEFAULT_CONFIG, getMeter, getOpenTelemetrySDK, getTracer as getOtelTracer, isOpenTelemetryInitialized, type MetricsConfig as OtelMetricsConfig, type MetricsExporter, type OpenTelemetryConfig, type OpenTelemetrySDK, OTEL_ENV_VARS, resetOpenTelemetry, setupOpenTelemetry, shutdownOpenTelemetry, type TracingConfig as OtelTracingConfig, type TracingExporter, } from './instrumentation';
37
45
  export type { Listener, ShouldQueue } from './Listener';
38
46
  export type { Logger } from './Logger';
39
47
  export { ConsoleLogger } from './Logger';
40
48
  export { type CacheService, type ErrorHandlerContext, type GravitoConfig, type GravitoOrbit, PlanetCore, type ViewService, } from './PlanetCore';
41
49
  export { Route } from './Route';
42
50
  export { type ControllerClass, FORM_REQUEST_SYMBOL, type FormRequestClass, type FormRequestLike, RouteGroup, type RouteHandler, type RouteOptions, Router, } from './Router';
51
+ export type { DLQManagerFilter, DLQRecord, DLQStats, RetryPolicy } from './reliability';
52
+ export { DeadLetterQueueManager, getDefaultRetryPolicy, getPresetRetryPolicy, RetryEngine, } from './reliability';
43
53
  export { ServiceProvider } from './ServiceProvider';
44
54
  export { Encrypter, type EncrypterOptions } from './security/Encrypter';
45
55
  export type { Channel, ShouldBroadcast } from './types/events';
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @gravito/core - Instrumentation Module
3
+ *
4
+ * 提供 OpenTelemetry SDK 集成功能,包括分佈式追蹤與指標收集。
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import {
9
+ * setupOpenTelemetry,
10
+ * getOpenTelemetrySDK,
11
+ * getTracer,
12
+ * getMeter
13
+ * } from '@gravito/core'
14
+ *
15
+ * // 初始化 SDK
16
+ * await setupOpenTelemetry({
17
+ * serviceName: 'my-service',
18
+ * tracing: { enabled: true, exporter: 'jaeger' },
19
+ * metrics: { enabled: true, exporter: 'prometheus' }
20
+ * })
21
+ *
22
+ * // 獲取 Tracer
23
+ * const tracer = await getTracer('my-module')
24
+ * const span = tracer.startSpan('my-operation')
25
+ *
26
+ * // 獲取 Meter
27
+ * const meter = await getMeter('my-module')
28
+ * const counter = meter.createCounter('request_count')
29
+ * ```
30
+ *
31
+ * @packageDocumentation
32
+ */
33
+ export { getMeter, getOpenTelemetrySDK, getTracer, isOpenTelemetryInitialized, resetOpenTelemetry, setupOpenTelemetry, shutdownOpenTelemetry, } from './opentelemetry';
34
+ export type { MetricsConfig, MetricsExporter, OpenTelemetryConfig, OpenTelemetrySDK, TracingConfig, TracingExporter, } from './types';
35
+ export { DEFAULT_CONFIG, OTEL_ENV_VARS } from './types';