@gravito/echo 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +215 -0
- package/dist/core/src/CommandKernel.d.ts +33 -0
- package/dist/core/src/ConfigManager.d.ts +26 -0
- package/dist/core/src/Container.d.ts +108 -0
- package/dist/core/src/ErrorHandler.d.ts +63 -0
- package/dist/core/src/Event.d.ts +5 -0
- package/dist/core/src/EventManager.d.ts +123 -0
- package/dist/core/src/GlobalErrorHandlers.d.ts +47 -0
- package/dist/core/src/GravitoServer.d.ts +28 -0
- package/dist/core/src/HookManager.d.ts +496 -0
- package/dist/core/src/Listener.d.ts +4 -0
- package/dist/core/src/Logger.d.ts +20 -0
- package/dist/core/src/PlanetCore.d.ts +289 -0
- package/dist/core/src/Route.d.ts +36 -0
- package/dist/core/src/Router.d.ts +284 -0
- package/dist/core/src/ServiceProvider.d.ts +156 -0
- package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +27 -0
- package/dist/core/src/adapters/PhotonAdapter.d.ts +171 -0
- package/dist/core/src/adapters/bun/BunContext.d.ts +45 -0
- package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +31 -0
- package/dist/core/src/adapters/bun/BunRequest.d.ts +31 -0
- package/dist/core/src/adapters/bun/RadixNode.d.ts +19 -0
- package/dist/core/src/adapters/bun/RadixRouter.d.ts +31 -0
- package/dist/core/src/adapters/bun/types.d.ts +20 -0
- package/dist/core/src/adapters/photon-types.d.ts +73 -0
- package/dist/core/src/adapters/types.d.ts +235 -0
- package/dist/core/src/engine/AOTRouter.d.ts +124 -0
- package/dist/core/src/engine/FastContext.d.ts +100 -0
- package/dist/core/src/engine/Gravito.d.ts +137 -0
- package/dist/core/src/engine/MinimalContext.d.ts +79 -0
- package/dist/core/src/engine/analyzer.d.ts +27 -0
- package/dist/core/src/engine/constants.d.ts +23 -0
- package/dist/core/src/engine/index.d.ts +26 -0
- package/dist/core/src/engine/path.d.ts +26 -0
- package/dist/core/src/engine/pool.d.ts +83 -0
- package/dist/core/src/engine/types.d.ts +143 -0
- 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/AuthenticationException.d.ts +8 -0
- package/dist/core/src/exceptions/AuthorizationException.d.ts +8 -0
- package/dist/core/src/exceptions/CircularDependencyException.d.ts +9 -0
- package/dist/core/src/exceptions/GravitoException.d.ts +23 -0
- package/dist/core/src/exceptions/HttpException.d.ts +9 -0
- package/dist/core/src/exceptions/ModelNotFoundException.d.ts +10 -0
- package/dist/core/src/exceptions/ValidationException.d.ts +22 -0
- package/dist/core/src/exceptions/index.d.ts +7 -0
- package/dist/core/src/helpers/Arr.d.ts +19 -0
- package/dist/core/src/helpers/Str.d.ts +23 -0
- package/dist/core/src/helpers/data.d.ts +25 -0
- package/dist/core/src/helpers/errors.d.ts +34 -0
- package/dist/core/src/helpers/response.d.ts +41 -0
- package/dist/core/src/helpers.d.ts +338 -0
- package/dist/core/src/http/CookieJar.d.ts +51 -0
- package/dist/core/src/http/cookie.d.ts +29 -0
- package/dist/core/src/http/middleware/BodySizeLimit.d.ts +16 -0
- package/dist/core/src/http/middleware/Cors.d.ts +24 -0
- package/dist/core/src/http/middleware/Csrf.d.ts +23 -0
- package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +28 -0
- package/dist/core/src/http/middleware/SecurityHeaders.d.ts +29 -0
- package/dist/core/src/http/middleware/ThrottleRequests.d.ts +18 -0
- package/dist/core/src/http/types.d.ts +355 -0
- package/dist/core/src/index.d.ts +76 -0
- 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/core/src/runtime.d.ts +119 -0
- package/dist/core/src/security/Encrypter.d.ts +33 -0
- package/dist/core/src/security/Hasher.d.ts +29 -0
- package/dist/core/src/testing/HttpTester.d.ts +39 -0
- package/dist/core/src/testing/TestResponse.d.ts +78 -0
- package/dist/core/src/testing/index.d.ts +2 -0
- package/dist/core/src/types/events.d.ts +94 -0
- package/dist/echo/src/OrbitEcho.d.ts +115 -0
- 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 +64 -0
- 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 +53 -0
- package/dist/echo/src/providers/GitHubProvider.d.ts +35 -0
- 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 +38 -0
- 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 -0
- package/dist/echo/src/receive/SignatureValidator.d.ts +67 -0
- package/dist/echo/src/receive/WebhookReceiver.d.ts +185 -0
- package/dist/echo/src/receive/index.d.ts +2 -0
- 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 +198 -0
- package/dist/echo/src/send/index.d.ts +1 -0
- 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 +756 -0
- package/dist/index.js +1332 -190
- package/dist/index.js.map +28 -10
- package/dist/photon/src/index.d.ts +84 -0
- package/dist/photon/src/middleware/binary.d.ts +31 -0
- 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,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event dispatch options for async event handling.
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export interface EventOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Whether to dispatch the event asynchronously.
|
|
8
|
+
* @default false
|
|
9
|
+
*/
|
|
10
|
+
async?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Priority level for event processing.
|
|
13
|
+
* - 'high': Critical events (e.g., order:created, payment:succeeded)
|
|
14
|
+
* - 'normal': Standard events (e.g., order:confirmed)
|
|
15
|
+
* - 'low': Non-critical events (e.g., analytics, logging)
|
|
16
|
+
* @default 'normal'
|
|
17
|
+
*/
|
|
18
|
+
priority?: 'high' | 'normal' | 'low';
|
|
19
|
+
/**
|
|
20
|
+
* Execution timeout in milliseconds.
|
|
21
|
+
* If a listener exceeds this timeout, it will be terminated.
|
|
22
|
+
* @default 5000
|
|
23
|
+
*/
|
|
24
|
+
timeout?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Ordering guarantee strategy.
|
|
27
|
+
* - 'strict': Global strict ordering (slow, serialized)
|
|
28
|
+
* - 'partition': Partition-based ordering (recommended, balanced)
|
|
29
|
+
* - 'none': No ordering guarantee (fastest, parallel)
|
|
30
|
+
* @default 'none'
|
|
31
|
+
*/
|
|
32
|
+
ordering?: 'strict' | 'partition' | 'none';
|
|
33
|
+
/**
|
|
34
|
+
* Partition key for partition-based ordering.
|
|
35
|
+
* Events with the same partition key are processed in order.
|
|
36
|
+
* Only used when ordering is 'partition'.
|
|
37
|
+
* @example 'order:123' or 'user:456'
|
|
38
|
+
*/
|
|
39
|
+
partitionKey?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Idempotency key for deduplication.
|
|
42
|
+
* Events with the same idempotency key within the TTL window
|
|
43
|
+
* will be processed only once.
|
|
44
|
+
* @example 'order:123:created'
|
|
45
|
+
*/
|
|
46
|
+
idempotencyKey?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Time-to-live for idempotency key in milliseconds.
|
|
49
|
+
* @default 3600000 (1 hour)
|
|
50
|
+
*/
|
|
51
|
+
ttl?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Retry policy for failed event processing.
|
|
54
|
+
*/
|
|
55
|
+
retry?: {
|
|
56
|
+
/**
|
|
57
|
+
* Maximum number of retry attempts.
|
|
58
|
+
* @default 0
|
|
59
|
+
*/
|
|
60
|
+
maxRetries?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Backoff strategy for retries.
|
|
63
|
+
* - 'exponential': Delay doubles with each retry (1s, 2s, 4s, 8s...)
|
|
64
|
+
* - 'linear': Fixed delay between retries
|
|
65
|
+
* @default 'exponential'
|
|
66
|
+
*/
|
|
67
|
+
backoff?: 'exponential' | 'linear';
|
|
68
|
+
/**
|
|
69
|
+
* Initial delay in milliseconds before first retry.
|
|
70
|
+
* @default 1000
|
|
71
|
+
*/
|
|
72
|
+
initialDelayMs?: number;
|
|
73
|
+
/**
|
|
74
|
+
* Maximum delay in milliseconds between retries.
|
|
75
|
+
* @default 30000
|
|
76
|
+
*/
|
|
77
|
+
maxDelayMs?: number;
|
|
78
|
+
/**
|
|
79
|
+
* Whether to send failed events to Dead Letter Queue after max retries.
|
|
80
|
+
* @default false
|
|
81
|
+
*/
|
|
82
|
+
dlqAfterMaxRetries?: boolean;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Circuit breaker options for this event.
|
|
86
|
+
*/
|
|
87
|
+
circuitBreaker?: {
|
|
88
|
+
/**
|
|
89
|
+
* Number of consecutive failures before opening the circuit.
|
|
90
|
+
* @default 5
|
|
91
|
+
*/
|
|
92
|
+
failureThreshold?: number;
|
|
93
|
+
/**
|
|
94
|
+
* Time in milliseconds to wait before attempting to close the circuit.
|
|
95
|
+
* @default 30000
|
|
96
|
+
*/
|
|
97
|
+
resetTimeout?: number;
|
|
98
|
+
/**
|
|
99
|
+
* Number of test requests to allow in half-open state.
|
|
100
|
+
* @default 3
|
|
101
|
+
*/
|
|
102
|
+
halfOpenRequests?: number;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Default event options.
|
|
107
|
+
* @internal
|
|
108
|
+
*/
|
|
109
|
+
export declare const DEFAULT_EVENT_OPTIONS: Required<EventOptions>;
|
|
@@ -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
|
+
}
|