@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.
- package/README.md +211 -0
- package/dist/atlas/src/DB.d.ts +301 -0
- package/dist/atlas/src/OrbitAtlas.d.ts +9 -0
- package/dist/atlas/src/config/defineConfig.d.ts +14 -0
- package/dist/atlas/src/config/index.d.ts +7 -0
- package/dist/atlas/src/config/loadConfig.d.ts +48 -0
- package/dist/atlas/src/connection/Connection.d.ts +108 -0
- package/dist/atlas/src/connection/ConnectionManager.d.ts +111 -0
- package/dist/atlas/src/drivers/BunSQLDriver.d.ts +32 -0
- package/dist/atlas/src/drivers/BunSQLPreparedStatement.d.ts +118 -0
- package/dist/atlas/src/drivers/MongoDBDriver.d.ts +36 -0
- package/dist/atlas/src/drivers/MySQLDriver.d.ts +66 -0
- package/dist/atlas/src/drivers/PostgresDriver.d.ts +83 -0
- package/dist/atlas/src/drivers/RedisDriver.d.ts +43 -0
- package/dist/atlas/src/drivers/SQLiteDriver.d.ts +45 -0
- package/dist/atlas/src/drivers/types.d.ts +260 -0
- package/dist/atlas/src/errors/index.d.ts +45 -0
- package/dist/atlas/src/grammar/Grammar.d.ts +342 -0
- package/dist/atlas/src/grammar/MongoGrammar.d.ts +47 -0
- package/dist/atlas/src/grammar/MySQLGrammar.d.ts +54 -0
- package/dist/atlas/src/grammar/NullGrammar.d.ts +35 -0
- package/dist/atlas/src/grammar/PostgresGrammar.d.ts +62 -0
- package/dist/atlas/src/grammar/SQLiteGrammar.d.ts +32 -0
- package/dist/atlas/src/index.d.ts +67 -0
- package/dist/atlas/src/migration/Migration.d.ts +64 -0
- package/dist/atlas/src/migration/MigrationRepository.d.ts +65 -0
- package/dist/atlas/src/migration/Migrator.d.ts +110 -0
- package/dist/atlas/src/migration/index.d.ts +6 -0
- package/dist/atlas/src/observability/AtlasMetrics.d.ts +11 -0
- package/dist/atlas/src/observability/AtlasObservability.d.ts +15 -0
- package/dist/atlas/src/observability/AtlasTracer.d.ts +12 -0
- package/dist/atlas/src/observability/index.d.ts +9 -0
- package/dist/atlas/src/orm/index.d.ts +5 -0
- package/dist/atlas/src/orm/model/DirtyTracker.d.ts +121 -0
- package/dist/atlas/src/orm/model/Model.d.ts +449 -0
- package/dist/atlas/src/orm/model/ModelRegistry.d.ts +20 -0
- package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +136 -0
- package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +36 -0
- package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +87 -0
- package/dist/atlas/src/orm/model/concerns/HasRelationships.d.ts +117 -0
- package/dist/atlas/src/orm/model/concerns/HasSerialization.d.ts +64 -0
- package/dist/atlas/src/orm/model/concerns/applyMixins.d.ts +15 -0
- package/dist/atlas/src/orm/model/concerns/index.d.ts +12 -0
- package/dist/atlas/src/orm/model/decorators.d.ts +109 -0
- package/dist/atlas/src/orm/model/errors.d.ts +52 -0
- package/dist/atlas/src/orm/model/index.d.ts +10 -0
- package/dist/atlas/src/orm/model/relationships.d.ts +207 -0
- package/dist/atlas/src/orm/model/types.d.ts +12 -0
- package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +123 -0
- package/dist/atlas/src/orm/schema/SchemaSniffer.d.ts +54 -0
- package/dist/atlas/src/orm/schema/index.d.ts +6 -0
- package/dist/atlas/src/orm/schema/types.d.ts +85 -0
- package/dist/atlas/src/query/Expression.d.ts +60 -0
- package/dist/atlas/src/query/NPlusOneDetector.d.ts +10 -0
- package/dist/atlas/src/query/QueryBuilder.d.ts +573 -0
- package/dist/atlas/src/query/clauses/GroupByClause.d.ts +51 -0
- package/dist/atlas/src/query/clauses/HavingClause.d.ts +70 -0
- package/dist/atlas/src/query/clauses/JoinClause.d.ts +87 -0
- package/dist/atlas/src/query/clauses/LimitClause.d.ts +82 -0
- package/dist/atlas/src/query/clauses/OrderByClause.d.ts +69 -0
- package/dist/atlas/src/query/clauses/SelectClause.d.ts +71 -0
- package/dist/atlas/src/query/clauses/WhereClause.d.ts +167 -0
- package/dist/atlas/src/query/clauses/index.d.ts +11 -0
- package/dist/atlas/src/schema/Blueprint.d.ts +276 -0
- package/dist/atlas/src/schema/ColumnDefinition.d.ts +154 -0
- package/dist/atlas/src/schema/ForeignKeyDefinition.d.ts +37 -0
- package/dist/atlas/src/schema/Schema.d.ts +131 -0
- package/dist/atlas/src/schema/grammars/MySQLSchemaGrammar.d.ts +23 -0
- package/dist/atlas/src/schema/grammars/PostgresSchemaGrammar.d.ts +26 -0
- package/dist/atlas/src/schema/grammars/SQLiteSchemaGrammar.d.ts +28 -0
- package/dist/atlas/src/schema/grammars/SchemaGrammar.d.ts +97 -0
- package/dist/atlas/src/schema/grammars/index.d.ts +7 -0
- package/dist/atlas/src/schema/index.d.ts +8 -0
- package/dist/atlas/src/seed/Factory.d.ts +90 -0
- package/dist/atlas/src/seed/Seeder.d.ts +28 -0
- package/dist/atlas/src/seed/SeederRunner.d.ts +74 -0
- package/dist/atlas/src/seed/index.d.ts +6 -0
- package/dist/atlas/src/types/index.d.ts +1100 -0
- package/dist/atlas/src/utils/levenshtein.d.ts +9 -0
- package/dist/core/src/Application.d.ts +43 -17
- package/dist/core/src/CommandKernel.d.ts +33 -0
- package/dist/core/src/Container.d.ts +78 -14
- package/dist/core/src/HookManager.d.ts +422 -8
- package/dist/core/src/PlanetCore.d.ts +52 -7
- package/dist/core/src/Router.d.ts +41 -7
- package/dist/core/src/ServiceProvider.d.ts +14 -8
- package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +1 -0
- package/dist/core/src/adapters/PhotonAdapter.d.ts +1 -0
- package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +1 -0
- package/dist/core/src/adapters/types.d.ts +39 -0
- package/dist/core/src/engine/AOTRouter.d.ts +1 -11
- package/dist/core/src/engine/FastContext.d.ts +4 -2
- package/dist/core/src/engine/Gravito.d.ts +1 -1
- package/dist/core/src/engine/MinimalContext.d.ts +4 -2
- package/dist/core/src/engine/types.d.ts +6 -1
- package/dist/core/src/events/CircuitBreaker.d.ts +229 -0
- package/dist/core/src/events/DeadLetterQueue.d.ts +145 -0
- package/dist/core/src/events/EventBackend.d.ts +11 -0
- package/dist/core/src/events/EventOptions.d.ts +109 -0
- package/dist/core/src/events/EventPriorityQueue.d.ts +202 -0
- package/dist/core/src/events/IdempotencyCache.d.ts +60 -0
- package/dist/core/src/events/index.d.ts +14 -0
- package/dist/core/src/events/observability/EventMetrics.d.ts +132 -0
- package/dist/core/src/events/observability/EventTracer.d.ts +68 -0
- package/dist/core/src/events/observability/EventTracing.d.ts +161 -0
- package/dist/core/src/events/observability/OTelEventMetrics.d.ts +240 -0
- package/dist/core/src/events/observability/ObservableHookManager.d.ts +108 -0
- package/dist/core/src/events/observability/index.d.ts +20 -0
- package/dist/core/src/events/observability/metrics-types.d.ts +16 -0
- package/dist/core/src/events/types.d.ts +75 -0
- package/dist/core/src/exceptions/CircularDependencyException.d.ts +9 -0
- package/dist/core/src/exceptions/index.d.ts +1 -0
- package/dist/core/src/http/cookie.d.ts +29 -0
- package/dist/core/src/http/types.d.ts +21 -0
- package/dist/core/src/index.d.ts +13 -3
- package/dist/core/src/instrumentation/index.d.ts +35 -0
- package/dist/core/src/instrumentation/opentelemetry.d.ts +178 -0
- package/dist/core/src/instrumentation/types.d.ts +182 -0
- package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +316 -0
- package/dist/core/src/reliability/RetryPolicy.d.ts +217 -0
- package/dist/core/src/reliability/index.d.ts +6 -0
- package/dist/core/src/router/ControllerDispatcher.d.ts +12 -0
- package/dist/core/src/router/RequestValidator.d.ts +20 -0
- package/dist/echo/src/OrbitEcho.d.ts +71 -16
- package/dist/echo/src/dlq/DeadLetterQueue.d.ts +94 -0
- package/dist/echo/src/dlq/MemoryDeadLetterQueue.d.ts +36 -0
- package/dist/echo/src/dlq/index.d.ts +2 -0
- package/dist/echo/src/index.d.ts +31 -15
- package/dist/echo/src/middleware/RequestBufferMiddleware.d.ts +62 -0
- package/dist/echo/src/middleware/index.d.ts +8 -0
- package/dist/echo/src/observability/index.d.ts +3 -0
- package/dist/echo/src/observability/logging/ConsoleEchoLogger.d.ts +37 -0
- package/dist/echo/src/observability/logging/EchoLogger.d.ts +38 -0
- package/dist/echo/src/observability/logging/index.d.ts +2 -0
- package/dist/echo/src/observability/metrics/MetricsProvider.d.ts +69 -0
- package/dist/echo/src/observability/metrics/NoopMetricsProvider.d.ts +17 -0
- package/dist/echo/src/observability/metrics/PrometheusMetricsProvider.d.ts +39 -0
- package/dist/echo/src/observability/metrics/index.d.ts +3 -0
- package/dist/echo/src/observability/tracing/NoopTracer.d.ts +33 -0
- package/dist/echo/src/observability/tracing/Tracer.d.ts +75 -0
- package/dist/echo/src/observability/tracing/index.d.ts +2 -0
- package/dist/echo/src/providers/GenericProvider.d.ts +37 -18
- package/dist/echo/src/providers/GitHubProvider.d.ts +21 -12
- package/dist/echo/src/providers/LinearProvider.d.ts +27 -0
- package/dist/echo/src/providers/PaddleProvider.d.ts +31 -0
- package/dist/echo/src/providers/ShopifyProvider.d.ts +27 -0
- package/dist/echo/src/providers/SlackProvider.d.ts +27 -0
- package/dist/echo/src/providers/StripeProvider.d.ts +20 -12
- package/dist/echo/src/providers/TwilioProvider.d.ts +31 -0
- package/dist/echo/src/providers/base/BaseProvider.d.ts +87 -0
- package/dist/echo/src/providers/base/HeaderUtils.d.ts +34 -0
- package/dist/echo/src/providers/index.d.ts +14 -3
- package/dist/echo/src/receive/SignatureValidator.d.ts +33 -0
- package/dist/echo/src/receive/WebhookReceiver.d.ts +139 -21
- package/dist/echo/src/replay/WebhookReplayService.d.ts +35 -0
- package/dist/echo/src/replay/index.d.ts +1 -0
- package/dist/echo/src/resilience/CircuitBreaker.d.ts +117 -0
- package/dist/echo/src/resilience/index.d.ts +10 -0
- package/dist/echo/src/rotation/KeyRotationManager.d.ts +127 -0
- package/dist/echo/src/rotation/index.d.ts +10 -0
- package/dist/echo/src/send/WebhookDispatcher.d.ts +159 -15
- package/dist/echo/src/storage/MemoryWebhookStore.d.ts +14 -0
- package/dist/echo/src/storage/WebhookStore.d.ts +236 -0
- package/dist/echo/src/storage/index.d.ts +2 -0
- package/dist/echo/src/types.d.ts +656 -64
- package/dist/index.js +1327 -189
- package/dist/index.js.map +28 -10
- package/dist/photon/src/index.d.ts +69 -5
- package/dist/photon/src/middleware/binary.d.ts +12 -15
- package/dist/photon/src/middleware/htmx.d.ts +39 -0
- package/dist/photon/src/middleware/ratelimit.d.ts +157 -0
- package/dist/photon/src/openapi.d.ts +19 -0
- package/package.json +7 -5
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import type { Span } from '@opentelemetry/api';
|
|
2
|
+
import type { ActionCallback } from '../HookManager';
|
|
3
|
+
import { CircuitBreaker } from './CircuitBreaker';
|
|
4
|
+
import type { DeadLetterQueue } from './DeadLetterQueue';
|
|
5
|
+
import type { EventBackend } from './EventBackend';
|
|
6
|
+
import type { EventOptions } from './EventOptions';
|
|
7
|
+
import type { EventMetrics } from './observability/EventMetrics';
|
|
8
|
+
import type { EventTracing } from './observability/EventTracing';
|
|
9
|
+
import type { BackpressureStrategy, EventQueueConfig, EventTask } from './types';
|
|
10
|
+
export type { EventTask, EventQueueConfig, BackpressureStrategy };
|
|
11
|
+
/**
|
|
12
|
+
* Priority queue for event processing.
|
|
13
|
+
* Events are processed based on their priority level:
|
|
14
|
+
* - High priority events are processed first
|
|
15
|
+
* - Normal priority events are processed second
|
|
16
|
+
* - Low priority events are processed last
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare class EventPriorityQueue implements EventBackend {
|
|
21
|
+
private highPriority;
|
|
22
|
+
private normalPriority;
|
|
23
|
+
private lowPriority;
|
|
24
|
+
private processing;
|
|
25
|
+
private taskIdCounter;
|
|
26
|
+
private dlq?;
|
|
27
|
+
private persistentDLQHandler?;
|
|
28
|
+
private config;
|
|
29
|
+
private processingPartitions;
|
|
30
|
+
private eventCircuitBreakers;
|
|
31
|
+
private eventMetrics?;
|
|
32
|
+
private eventTracing?;
|
|
33
|
+
private currentDispatchSpan?;
|
|
34
|
+
constructor(config?: EventQueueConfig);
|
|
35
|
+
/**
|
|
36
|
+
* Set the Dead Letter Queue for failed events.
|
|
37
|
+
*
|
|
38
|
+
* @param dlq - Dead Letter Queue instance
|
|
39
|
+
*/
|
|
40
|
+
setDeadLetterQueue(dlq: DeadLetterQueue): void;
|
|
41
|
+
/**
|
|
42
|
+
* Set the persistent DLQ handler for failed events.
|
|
43
|
+
*
|
|
44
|
+
* @param handler - Async handler function for persistent DLQ
|
|
45
|
+
*/
|
|
46
|
+
setPersistentDLQHandler(handler: (hook: string, args: unknown, options: EventOptions, error: Error, retryCount: number, firstFailedAt: number) => Promise<void>): void;
|
|
47
|
+
/**
|
|
48
|
+
* Set the EventMetrics instance for recording circuit breaker metrics.
|
|
49
|
+
*
|
|
50
|
+
* @param metrics - EventMetrics instance
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
setEventMetrics(metrics: EventMetrics): void;
|
|
54
|
+
/**
|
|
55
|
+
* Set the EventTracing instance for distributed tracing.
|
|
56
|
+
*
|
|
57
|
+
* @param tracing - EventTracing instance
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
setEventTracing(tracing: EventTracing): void;
|
|
61
|
+
/**
|
|
62
|
+
* Set the current dispatch span for creating child spans.
|
|
63
|
+
*
|
|
64
|
+
* @param span - Parent dispatch span
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
setCurrentDispatchSpan(span: Span | undefined): void;
|
|
68
|
+
/**
|
|
69
|
+
* Get the current dispatch span.
|
|
70
|
+
*
|
|
71
|
+
* @returns Current dispatch span or undefined
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
getCurrentDispatchSpan(): Span | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Get or create a circuit breaker for an event hook.
|
|
77
|
+
*
|
|
78
|
+
* @param hook - Event hook name
|
|
79
|
+
* @param config - Circuit breaker configuration
|
|
80
|
+
* @returns Circuit breaker instance or undefined if not configured
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
private getOrCreateEventCircuitBreaker;
|
|
84
|
+
/**
|
|
85
|
+
* Enqueue an event task for processing.
|
|
86
|
+
*
|
|
87
|
+
* @param hook - Event hook name
|
|
88
|
+
* @param args - Event arguments
|
|
89
|
+
* @param callbacks - Callbacks to execute
|
|
90
|
+
* @param options - Event options
|
|
91
|
+
* @returns Task ID
|
|
92
|
+
*/
|
|
93
|
+
enqueue(task: EventTask): void;
|
|
94
|
+
enqueue(hook: string, args: unknown, callbacks: ActionCallback[], options: EventOptions): string;
|
|
95
|
+
/**
|
|
96
|
+
* Handle backpressure when queue is full.
|
|
97
|
+
* @returns True if space was made, false if event should be dropped
|
|
98
|
+
*/
|
|
99
|
+
private handleBackpressure;
|
|
100
|
+
/**
|
|
101
|
+
* Drop the oldest event from the queue, prioritizing low priority events.
|
|
102
|
+
*/
|
|
103
|
+
private dropOldest;
|
|
104
|
+
/**
|
|
105
|
+
* Process the next task in the queue.
|
|
106
|
+
* Tasks are processed in priority order: high > normal > low
|
|
107
|
+
*
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
110
|
+
private processNext;
|
|
111
|
+
/**
|
|
112
|
+
* Dequeue the next task based on priority and partition ordering.
|
|
113
|
+
*
|
|
114
|
+
* @returns Next task to process, or undefined if queue is empty
|
|
115
|
+
* @internal
|
|
116
|
+
*/
|
|
117
|
+
private dequeue;
|
|
118
|
+
/**
|
|
119
|
+
* Dequeue a task from a priority queue, respecting partition ordering.
|
|
120
|
+
*
|
|
121
|
+
* @param queue - Priority queue to dequeue from
|
|
122
|
+
* @returns Next task to process, or undefined if all tasks are blocked by partition locks
|
|
123
|
+
* @internal
|
|
124
|
+
*/
|
|
125
|
+
private dequeueFromPriority;
|
|
126
|
+
/**
|
|
127
|
+
* Execute an event task by running all its callbacks.
|
|
128
|
+
* Implements circuit breaker protection, retry logic with exponential backoff, and DLQ integration.
|
|
129
|
+
* Also handles partition ordering by acquiring and releasing partition locks.
|
|
130
|
+
*
|
|
131
|
+
* @param task - Event task to execute
|
|
132
|
+
* @internal
|
|
133
|
+
*/
|
|
134
|
+
private executeTask;
|
|
135
|
+
/**
|
|
136
|
+
* Calculate retry delay based on backoff strategy.
|
|
137
|
+
*
|
|
138
|
+
* @param retryCount - Current retry attempt number
|
|
139
|
+
* @param backoff - Backoff strategy
|
|
140
|
+
* @param initialDelay - Initial delay in ms
|
|
141
|
+
* @param maxDelay - Maximum delay in ms
|
|
142
|
+
* @returns Delay in milliseconds
|
|
143
|
+
* @internal
|
|
144
|
+
*/
|
|
145
|
+
private calculateRetryDelay;
|
|
146
|
+
/**
|
|
147
|
+
* Re-enqueue a task for retry.
|
|
148
|
+
*
|
|
149
|
+
* @param task - Task to retry
|
|
150
|
+
* @internal
|
|
151
|
+
*/
|
|
152
|
+
private enqueueRetry;
|
|
153
|
+
/**
|
|
154
|
+
* Execute a callback with timeout.
|
|
155
|
+
*
|
|
156
|
+
* @param callback - Callback to execute
|
|
157
|
+
* @param args - Arguments to pass to callback
|
|
158
|
+
* @param timeoutMs - Timeout in milliseconds
|
|
159
|
+
* @internal
|
|
160
|
+
*/
|
|
161
|
+
private executeWithTimeout;
|
|
162
|
+
/**
|
|
163
|
+
* Get the current depth of the queue.
|
|
164
|
+
*
|
|
165
|
+
* @returns Total number of tasks in the queue
|
|
166
|
+
*/
|
|
167
|
+
getDepth(): number;
|
|
168
|
+
/**
|
|
169
|
+
* Get the depth of a specific priority queue.
|
|
170
|
+
*
|
|
171
|
+
* @param priority - Priority level
|
|
172
|
+
* @returns Number of tasks in the specified priority queue
|
|
173
|
+
*/
|
|
174
|
+
getDepthByPriority(priority: 'high' | 'normal' | 'low'): number;
|
|
175
|
+
/**
|
|
176
|
+
* Clear all tasks from the queue.
|
|
177
|
+
*/
|
|
178
|
+
clear(): void;
|
|
179
|
+
/**
|
|
180
|
+
* Get circuit breaker for an event hook.
|
|
181
|
+
*
|
|
182
|
+
* @param hook - Event hook name
|
|
183
|
+
* @returns Circuit breaker instance or undefined
|
|
184
|
+
* @internal
|
|
185
|
+
*/
|
|
186
|
+
getCircuitBreaker(hook: string): CircuitBreaker | undefined;
|
|
187
|
+
/**
|
|
188
|
+
* Get all circuit breakers.
|
|
189
|
+
*
|
|
190
|
+
* @returns Map of circuit breakers keyed by hook name
|
|
191
|
+
* @internal
|
|
192
|
+
*/
|
|
193
|
+
getCircuitBreakers(): Map<string, CircuitBreaker>;
|
|
194
|
+
/**
|
|
195
|
+
* Reset a circuit breaker for an event hook.
|
|
196
|
+
*
|
|
197
|
+
* @param hook - Event hook name
|
|
198
|
+
* @returns True if reset, false if circuit breaker not found
|
|
199
|
+
* @internal
|
|
200
|
+
*/
|
|
201
|
+
resetCircuitBreaker(hook: string): boolean;
|
|
202
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Idempotency cache for deduplicating events.
|
|
3
|
+
* Prevents duplicate events from being processed within a configurable TTL window.
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare class IdempotencyCache {
|
|
7
|
+
private cache;
|
|
8
|
+
private cleanupInterval;
|
|
9
|
+
private readonly defaultCleanupIntervalMs;
|
|
10
|
+
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Check if an event with the given idempotency key is a duplicate.
|
|
13
|
+
* @param key - Idempotency key
|
|
14
|
+
* @param ttlMs - Time-to-live in milliseconds
|
|
15
|
+
* @returns True if this is a duplicate, false if it's a new event
|
|
16
|
+
*/
|
|
17
|
+
isDuplicate(key: string, ttlMs: number): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Record an event in the cache.
|
|
20
|
+
* @param key - Idempotency key
|
|
21
|
+
*/
|
|
22
|
+
recordEvent(key: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Remove an entry from the cache.
|
|
25
|
+
* @param key - Idempotency key
|
|
26
|
+
* @returns True if entry was removed, false if not found
|
|
27
|
+
*/
|
|
28
|
+
remove(key: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Clear all entries from the cache.
|
|
31
|
+
*/
|
|
32
|
+
clear(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Get the current cache size.
|
|
35
|
+
* @returns Number of entries in cache
|
|
36
|
+
*/
|
|
37
|
+
getSize(): number;
|
|
38
|
+
/**
|
|
39
|
+
* Start periodic cleanup of expired entries.
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
private startCleanup;
|
|
43
|
+
/**
|
|
44
|
+
* Stop the periodic cleanup.
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
stopCleanup(): void;
|
|
48
|
+
/**
|
|
49
|
+
* Clean up expired entries from the cache.
|
|
50
|
+
* This is called periodically and doesn't use strict TTL checking,
|
|
51
|
+
* so entries older than a reasonable default (24 hours) are removed.
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
private cleanup;
|
|
55
|
+
/**
|
|
56
|
+
* Destructor to clean up resources.
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
destroy(): void;
|
|
60
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event system exports for async event dispatch.
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
export type { CircuitBreakerOptions } from './CircuitBreaker';
|
|
6
|
+
export { CircuitBreaker, CircuitBreakerState } from './CircuitBreaker';
|
|
7
|
+
export type { DLQEntry, DLQFilter } from './DeadLetterQueue';
|
|
8
|
+
export { DeadLetterQueue } from './DeadLetterQueue';
|
|
9
|
+
export * from './EventBackend';
|
|
10
|
+
export type { EventOptions } from './EventOptions';
|
|
11
|
+
export { DEFAULT_EVENT_OPTIONS } from './EventOptions';
|
|
12
|
+
export { EventPriorityQueue } from './EventPriorityQueue';
|
|
13
|
+
export * from './observability';
|
|
14
|
+
export type { BackpressureStrategy, EventQueueConfig, EventTask } from './types';
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/core - Event System Metrics
|
|
3
|
+
*
|
|
4
|
+
* Manages metric collection for event dispatch and listener execution.
|
|
5
|
+
*/
|
|
6
|
+
import type { EventMetricGauge, EventMetricHistogram } from './metrics-types';
|
|
7
|
+
/**
|
|
8
|
+
* Event metrics collector for monitoring and observability.
|
|
9
|
+
*
|
|
10
|
+
* Collects 6 core metrics:
|
|
11
|
+
* - Event dispatch latency (Histogram)
|
|
12
|
+
* - Listener execution time (Histogram)
|
|
13
|
+
* - Queue depth by priority (Gauge)
|
|
14
|
+
* - Failure count by error type (Counter)
|
|
15
|
+
* - Timeout count (Counter)
|
|
16
|
+
* - Processed event count by status (Counter)
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export declare class EventMetrics {
|
|
21
|
+
private dispatchLatency;
|
|
22
|
+
private listenerExecutionTime;
|
|
23
|
+
private queueDepthGauge;
|
|
24
|
+
private failureCounter;
|
|
25
|
+
private timeoutCounter;
|
|
26
|
+
private processedCounter;
|
|
27
|
+
private circuitBreakerStateGauge;
|
|
28
|
+
private circuitBreakerTransitionsCounter;
|
|
29
|
+
private circuitBreakerFailuresCounter;
|
|
30
|
+
private circuitBreakerSuccessesCounter;
|
|
31
|
+
private circuitBreakerOpenDurationHistogram;
|
|
32
|
+
/**
|
|
33
|
+
* Create a new EventMetrics instance.
|
|
34
|
+
*
|
|
35
|
+
* @param registry - MetricsRegistry from @gravito/monitor
|
|
36
|
+
* @param prefix - Metric name prefix (default: 'gravito_event_')
|
|
37
|
+
*/
|
|
38
|
+
constructor(registry: any, // MetricsRegistry type
|
|
39
|
+
prefix?: string);
|
|
40
|
+
/**
|
|
41
|
+
* Record event dispatch latency.
|
|
42
|
+
*
|
|
43
|
+
* @param eventName - Name of the event
|
|
44
|
+
* @param priority - Priority level (high, normal, low)
|
|
45
|
+
* @param seconds - Duration in seconds
|
|
46
|
+
*/
|
|
47
|
+
recordDispatchLatency(eventName: string, priority: string, seconds: number): void;
|
|
48
|
+
/**
|
|
49
|
+
* Record listener execution time.
|
|
50
|
+
*
|
|
51
|
+
* @param eventName - Name of the event
|
|
52
|
+
* @param index - Index of the listener in the callback list
|
|
53
|
+
* @param seconds - Duration in seconds
|
|
54
|
+
*/
|
|
55
|
+
recordListenerExecution(eventName: string, index: number, seconds: number): void;
|
|
56
|
+
/**
|
|
57
|
+
* Update queue depth gauge for a specific priority.
|
|
58
|
+
*
|
|
59
|
+
* @param priority - Priority level (high, normal, low)
|
|
60
|
+
* @param depth - Current queue depth
|
|
61
|
+
*/
|
|
62
|
+
updateQueueDepth(priority: string, depth: number): void;
|
|
63
|
+
/**
|
|
64
|
+
* Record event processing failure.
|
|
65
|
+
*
|
|
66
|
+
* @param eventName - Name of the event
|
|
67
|
+
* @param errorType - Type of error (e.g., 'TypeError', 'TimeoutError')
|
|
68
|
+
*/
|
|
69
|
+
recordFailure(eventName: string, errorType: string): void;
|
|
70
|
+
/**
|
|
71
|
+
* Record event processing timeout.
|
|
72
|
+
*
|
|
73
|
+
* @param eventName - Name of the event
|
|
74
|
+
*/
|
|
75
|
+
recordTimeout(eventName: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* Record processed event (success or failure).
|
|
78
|
+
*
|
|
79
|
+
* @param eventName - Name of the event
|
|
80
|
+
* @param status - Processing status ('success' or 'failure')
|
|
81
|
+
*/
|
|
82
|
+
recordProcessed(eventName: string, status: 'success' | 'failure'): void;
|
|
83
|
+
/**
|
|
84
|
+
* Get reference to dispatch latency histogram.
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
getDispatchLatencyHistogram(): EventMetricHistogram;
|
|
88
|
+
/**
|
|
89
|
+
* Get reference to listener execution time histogram.
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
getListenerExecutionHistogram(): EventMetricHistogram;
|
|
93
|
+
/**
|
|
94
|
+
* Get reference to queue depth gauge.
|
|
95
|
+
* @internal
|
|
96
|
+
*/
|
|
97
|
+
getQueueDepthGauge(): EventMetricGauge;
|
|
98
|
+
/**
|
|
99
|
+
* Record circuit breaker state change.
|
|
100
|
+
*
|
|
101
|
+
* @param eventName - Name of the event
|
|
102
|
+
* @param state - Circuit breaker state (0=CLOSED, 1=HALF_OPEN, 2=OPEN)
|
|
103
|
+
*/
|
|
104
|
+
recordCircuitBreakerState(eventName: string, state: number): void;
|
|
105
|
+
/**
|
|
106
|
+
* Record circuit breaker state transition.
|
|
107
|
+
*
|
|
108
|
+
* @param eventName - Name of the event
|
|
109
|
+
* @param fromState - Previous state
|
|
110
|
+
* @param toState - New state
|
|
111
|
+
*/
|
|
112
|
+
recordCircuitBreakerTransition(eventName: string, fromState: string, toState: string): void;
|
|
113
|
+
/**
|
|
114
|
+
* Record circuit breaker failure.
|
|
115
|
+
*
|
|
116
|
+
* @param eventName - Name of the event
|
|
117
|
+
*/
|
|
118
|
+
recordCircuitBreakerFailure(eventName: string): void;
|
|
119
|
+
/**
|
|
120
|
+
* Record circuit breaker success.
|
|
121
|
+
*
|
|
122
|
+
* @param eventName - Name of the event
|
|
123
|
+
*/
|
|
124
|
+
recordCircuitBreakerSuccess(eventName: string): void;
|
|
125
|
+
/**
|
|
126
|
+
* Record circuit breaker OPEN duration.
|
|
127
|
+
*
|
|
128
|
+
* @param eventName - Name of the event
|
|
129
|
+
* @param seconds - Duration in seconds
|
|
130
|
+
*/
|
|
131
|
+
recordCircuitBreakerOpenDuration(eventName: string, seconds: number): void;
|
|
132
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/core - Event System Tracer
|
|
3
|
+
*
|
|
4
|
+
* Manages OpenTelemetry distributed tracing for event dispatch.
|
|
5
|
+
*/
|
|
6
|
+
import type { Span } from '@opentelemetry/api';
|
|
7
|
+
/**
|
|
8
|
+
* Event tracer for distributed tracing support.
|
|
9
|
+
*
|
|
10
|
+
* Integrates with OpenTelemetry to provide:
|
|
11
|
+
* - Event dispatch tracing
|
|
12
|
+
* - Listener execution tracing
|
|
13
|
+
* - Error recording
|
|
14
|
+
* - Span hierarchy
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export declare class EventTracer {
|
|
19
|
+
private tracer;
|
|
20
|
+
/**
|
|
21
|
+
* Create a new EventTracer instance.
|
|
22
|
+
*
|
|
23
|
+
* @param tracerName - Name of the tracer (default: '@gravito/core')
|
|
24
|
+
*/
|
|
25
|
+
constructor(tracerName?: string);
|
|
26
|
+
/**
|
|
27
|
+
* Start a span for event dispatch.
|
|
28
|
+
*
|
|
29
|
+
* @param eventName - Name of the event
|
|
30
|
+
* @param callbackCount - Number of callbacks registered for this event
|
|
31
|
+
* @param priority - Priority level (high, normal, low)
|
|
32
|
+
* @returns Span for the event dispatch
|
|
33
|
+
*/
|
|
34
|
+
startDispatchSpan(eventName: string, callbackCount: number, priority: string): Span;
|
|
35
|
+
/**
|
|
36
|
+
* Start a span for listener execution.
|
|
37
|
+
*
|
|
38
|
+
* @param _parentSpan - Parent span for this listener
|
|
39
|
+
* @param eventName - Name of the event
|
|
40
|
+
* @param listenerIndex - Index of the listener in the callback list
|
|
41
|
+
* @returns Child span for the listener execution
|
|
42
|
+
*/
|
|
43
|
+
startListenerSpan(_parentSpan: Span, eventName: string, listenerIndex: number): Span;
|
|
44
|
+
/**
|
|
45
|
+
* Record an error in the span.
|
|
46
|
+
*
|
|
47
|
+
* @param span - Span to record error in
|
|
48
|
+
* @param error - Error that occurred
|
|
49
|
+
*/
|
|
50
|
+
recordError(span: Span, error: Error): void;
|
|
51
|
+
/**
|
|
52
|
+
* End a span with a specific status.
|
|
53
|
+
*
|
|
54
|
+
* @param span - Span to end
|
|
55
|
+
* @param status - Status ('ok' or 'error')
|
|
56
|
+
*/
|
|
57
|
+
endSpan(span: Span, status?: 'ok' | 'error'): void;
|
|
58
|
+
/**
|
|
59
|
+
* Create a timer span for measuring duration.
|
|
60
|
+
*
|
|
61
|
+
* @param eventName - Name of the event
|
|
62
|
+
* @returns Object with span and duration recording function
|
|
63
|
+
*/
|
|
64
|
+
startTimer(eventName: string): {
|
|
65
|
+
span: Span;
|
|
66
|
+
endTimer: (status?: 'ok' | 'error') => void;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/core - Event System Tracing
|
|
3
|
+
*
|
|
4
|
+
* 使用 OpenTelemetry API 實現事件系統的分佈式追蹤。
|
|
5
|
+
* 提供事件派發、監聽器執行與隊列操作的端到端追蹤。
|
|
6
|
+
*/
|
|
7
|
+
import type { Span } from '@opentelemetry/api';
|
|
8
|
+
/**
|
|
9
|
+
* 事件追蹤配置
|
|
10
|
+
*/
|
|
11
|
+
export interface EventTracingConfig {
|
|
12
|
+
/** Tracer 名稱 */
|
|
13
|
+
tracerName?: string;
|
|
14
|
+
/** 是否記錄詳細的 payload 信息 */
|
|
15
|
+
capturePayload?: boolean;
|
|
16
|
+
/** 最大 payload 大小(字節) */
|
|
17
|
+
maxPayloadSize?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 事件追蹤管理器
|
|
21
|
+
*
|
|
22
|
+
* 提供事件系統的分佈式追蹤能力,包括:
|
|
23
|
+
* - 事件派發追蹤
|
|
24
|
+
* - 監聽器執行追蹤
|
|
25
|
+
* - 隊列操作追蹤
|
|
26
|
+
* - 異常記錄與追蹤
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export declare class EventTracing {
|
|
31
|
+
private tracer;
|
|
32
|
+
private config;
|
|
33
|
+
constructor(config?: EventTracingConfig);
|
|
34
|
+
/**
|
|
35
|
+
* 為事件派發創建追蹤 Span
|
|
36
|
+
*
|
|
37
|
+
* @param eventName - 事件名稱
|
|
38
|
+
* @param listenerCount - 監聽器數量
|
|
39
|
+
* @param priority - 優先級(high, normal, low)
|
|
40
|
+
* @param payload - 事件負載(可選,用於調試)
|
|
41
|
+
* @returns Span 實例
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const tracer = new EventTracing()
|
|
46
|
+
* const span = tracer.startDispatchSpan('order:created', 3, 'high', orderData)
|
|
47
|
+
* try {
|
|
48
|
+
* // 派發事件
|
|
49
|
+
* await dispatchEvent()
|
|
50
|
+
* tracer.endDispatchSpan(span, 'ok')
|
|
51
|
+
* } catch (error) {
|
|
52
|
+
* tracer.endDispatchSpan(span, 'error', error)
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
startDispatchSpan(eventName: string, listenerCount: number, priority?: 'high' | 'normal' | 'low', payload?: unknown): Span;
|
|
57
|
+
/**
|
|
58
|
+
* 為監聽器執行創建追蹤 Span
|
|
59
|
+
*
|
|
60
|
+
* @param _parentSpan - 父 Span
|
|
61
|
+
* @param eventName - 事件名稱
|
|
62
|
+
* @param listenerName - 監聽器名稱/標識
|
|
63
|
+
* @param listenerIndex - 監聽器索引
|
|
64
|
+
* @returns 子 Span 實例
|
|
65
|
+
*/
|
|
66
|
+
startListenerSpan(_parentSpan: Span, eventName: string, listenerName: string, listenerIndex: number): Span;
|
|
67
|
+
/**
|
|
68
|
+
* 為隊列操作創建追蹤 Span
|
|
69
|
+
*
|
|
70
|
+
* @param _parentSpan - 父 Span
|
|
71
|
+
* @param operationType - 操作類型(enqueue, dequeue, requeue)
|
|
72
|
+
* @param eventName - 事件名稱
|
|
73
|
+
* @param priority - 優先級
|
|
74
|
+
* @returns Span 實例
|
|
75
|
+
*/
|
|
76
|
+
startQueueOperationSpan(_parentSpan: Span, operationType: 'enqueue' | 'dequeue' | 'requeue', eventName: string, priority: 'high' | 'normal' | 'low'): Span;
|
|
77
|
+
/**
|
|
78
|
+
* 結束事件派發 Span
|
|
79
|
+
*
|
|
80
|
+
* @param span - Span 實例
|
|
81
|
+
* @param status - 完成狀態(ok, error)
|
|
82
|
+
* @param error - 如果 status 為 error,傳遞錯誤對象
|
|
83
|
+
*/
|
|
84
|
+
endDispatchSpan(span: Span, status?: 'ok' | 'error', error?: Error): void;
|
|
85
|
+
/**
|
|
86
|
+
* 結束監聽器執行 Span
|
|
87
|
+
*
|
|
88
|
+
* @param span - Span 實例
|
|
89
|
+
* @param status - 完成狀態(ok, error)
|
|
90
|
+
* @param duration - 執行時間(毫秒)
|
|
91
|
+
* @param error - 如果發生錯誤,傳遞錯誤對象
|
|
92
|
+
*/
|
|
93
|
+
endListenerSpan(span: Span, status?: 'ok' | 'error', duration?: number, error?: Error): void;
|
|
94
|
+
/**
|
|
95
|
+
* 結束隊列操作 Span
|
|
96
|
+
*
|
|
97
|
+
* @param span - Span 實例
|
|
98
|
+
* @param status - 完成狀態(ok, error)
|
|
99
|
+
* @param queueDepth - 當前隊列深度
|
|
100
|
+
* @param error - 如果發生錯誤,傳遞錯誤對象
|
|
101
|
+
*/
|
|
102
|
+
endQueueOperationSpan(span: Span, status?: 'ok' | 'error', queueDepth?: number, error?: Error): void;
|
|
103
|
+
/**
|
|
104
|
+
* 在 Span 中添加自定義屬性
|
|
105
|
+
*
|
|
106
|
+
* @param span - Span 實例
|
|
107
|
+
* @param attributes - 屬性對象
|
|
108
|
+
*/
|
|
109
|
+
addSpanAttributes(span: Span, attributes: Record<string, string | number | boolean>): void;
|
|
110
|
+
/**
|
|
111
|
+
* 在 Span 中添加自定義事件
|
|
112
|
+
*
|
|
113
|
+
* @param span - Span 實例
|
|
114
|
+
* @param eventName - 事件名稱
|
|
115
|
+
* @param attributes - 事件屬性(可選)
|
|
116
|
+
*/
|
|
117
|
+
addSpanEvent(span: Span, eventName: string, attributes?: Record<string, string | number | boolean>): void;
|
|
118
|
+
/**
|
|
119
|
+
* 記錄異常到 Span
|
|
120
|
+
*
|
|
121
|
+
* @param span - Span 實例
|
|
122
|
+
* @param error - 錯誤對象
|
|
123
|
+
*/
|
|
124
|
+
recordException(span: Span, error: Error | string): void;
|
|
125
|
+
/**
|
|
126
|
+
* 創建定時器 Span(用於測量操作時間)
|
|
127
|
+
*
|
|
128
|
+
* @param operationName - 操作名稱
|
|
129
|
+
* @returns 對象包含 span 和結束函數
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* const { span, endTimer } = tracer.startTimer('slow-operation')
|
|
134
|
+
* try {
|
|
135
|
+
* await slowOperation()
|
|
136
|
+
* endTimer('ok')
|
|
137
|
+
* } catch (error) {
|
|
138
|
+
* endTimer('error', error)
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
startTimer(operationName: string): {
|
|
143
|
+
span: Span;
|
|
144
|
+
endTimer: (status?: 'ok' | 'error', error?: Error) => void;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* 獲取 tracer 實例(用於高級用法)
|
|
148
|
+
*
|
|
149
|
+
* @returns OpenTelemetry Tracer 實例
|
|
150
|
+
*/
|
|
151
|
+
getTracer(): import("@opentelemetry/api").Tracer;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* 獲取或創建全局 EventTracing 實例
|
|
155
|
+
*
|
|
156
|
+
* @param config - 配置選項
|
|
157
|
+
* @returns EventTracing 實例
|
|
158
|
+
*
|
|
159
|
+
* @public
|
|
160
|
+
*/
|
|
161
|
+
export declare function getEventTracing(config?: EventTracingConfig): EventTracing;
|