@gravito/ripple 3.1.0 → 4.0.1
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 +260 -19
- package/dist/atlas/src/DB.d.ts +348 -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 +41 -0
- package/dist/atlas/src/connection/Connection.d.ts +112 -0
- package/dist/atlas/src/connection/ConnectionManager.d.ts +180 -0
- package/dist/atlas/src/connection/ReplicaConnectionPool.d.ts +54 -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 +79 -0
- package/dist/atlas/src/drivers/PostgresDriver.d.ts +96 -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 +79 -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 +33 -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/Repository.d.ts +247 -0
- package/dist/atlas/src/orm/index.d.ts +6 -0
- package/dist/atlas/src/orm/model/DirtyTracker.d.ts +121 -0
- package/dist/atlas/src/orm/model/Model.d.ts +458 -0
- package/dist/atlas/src/orm/model/ModelRegistry.d.ts +20 -0
- package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +150 -0
- package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +36 -0
- package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +92 -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 +138 -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 +124 -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/pool/AdaptivePoolManager.d.ts +98 -0
- package/dist/atlas/src/pool/PoolHealthChecker.d.ts +91 -0
- package/dist/atlas/src/pool/PoolStrategy.d.ts +129 -0
- package/dist/atlas/src/pool/PoolWarmer.d.ts +92 -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 +643 -0
- package/dist/atlas/src/query/RelationshipResolver.d.ts +23 -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/MigrationGenerator.d.ts +45 -0
- package/dist/atlas/src/schema/Schema.d.ts +131 -0
- package/dist/atlas/src/schema/SchemaDiff.d.ts +73 -0
- package/dist/atlas/src/schema/TypeGenerator.d.ts +57 -0
- package/dist/atlas/src/schema/TypeWriter.d.ts +42 -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/sharding/ShardingManager.d.ts +59 -0
- package/dist/atlas/src/types/index.d.ts +1182 -0
- package/dist/atlas/src/utils/CursorEncoding.d.ts +63 -0
- package/dist/atlas/src/utils/levenshtein.d.ts +9 -0
- package/dist/core/src/CommandKernel.d.ts +33 -0
- package/dist/core/src/ConfigManager.d.ts +39 -0
- package/dist/core/src/Container/RequestScopeManager.d.ts +62 -0
- package/dist/core/src/Container/RequestScopeMetrics.d.ts +144 -0
- package/dist/core/src/Container.d.ts +86 -11
- package/dist/core/src/ErrorHandler.d.ts +3 -0
- package/dist/core/src/HookManager.d.ts +511 -4
- package/dist/core/src/PlanetCore.d.ts +89 -0
- package/dist/core/src/RequestContext.d.ts +97 -0
- package/dist/core/src/Router.d.ts +1 -5
- package/dist/core/src/ServiceProvider.d.ts +22 -0
- package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +1 -0
- package/dist/core/src/adapters/PhotonAdapter.d.ts +5 -0
- package/dist/core/src/adapters/bun/BunContext.d.ts +4 -0
- package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +1 -0
- package/dist/core/src/adapters/types.d.ts +27 -0
- package/dist/core/src/cli/queue-commands.d.ts +6 -0
- package/dist/core/src/engine/AOTRouter.d.ts +7 -12
- package/dist/core/src/engine/FastContext.d.ts +27 -2
- package/dist/core/src/engine/Gravito.d.ts +0 -1
- package/dist/core/src/engine/MinimalContext.d.ts +25 -2
- package/dist/core/src/engine/types.d.ts +9 -1
- package/dist/core/src/error-handling/RequestScopeErrorContext.d.ts +126 -0
- package/dist/core/src/events/BackpressureManager.d.ts +215 -0
- package/dist/core/src/events/CircuitBreaker.d.ts +229 -0
- package/dist/core/src/events/DeadLetterQueue.d.ts +219 -0
- package/dist/core/src/events/EventBackend.d.ts +12 -0
- package/dist/core/src/events/EventOptions.d.ts +204 -0
- package/dist/core/src/events/EventPriorityQueue.d.ts +301 -0
- package/dist/core/src/events/FlowControlStrategy.d.ts +109 -0
- package/dist/core/src/events/IdempotencyCache.d.ts +60 -0
- package/dist/core/src/events/MessageQueueBridge.d.ts +184 -0
- package/dist/core/src/events/PriorityEscalationManager.d.ts +82 -0
- package/dist/core/src/events/RetryScheduler.d.ts +104 -0
- package/dist/core/src/events/WorkerPool.d.ts +98 -0
- package/dist/core/src/events/WorkerPoolConfig.d.ts +153 -0
- package/dist/core/src/events/WorkerPoolMetrics.d.ts +65 -0
- package/dist/core/src/events/aggregation/AggregationWindow.d.ts +77 -0
- package/dist/core/src/events/aggregation/DeduplicationManager.d.ts +135 -0
- package/dist/core/src/events/aggregation/EventAggregationManager.d.ts +108 -0
- package/dist/core/src/events/aggregation/EventBatcher.d.ts +99 -0
- package/dist/core/src/events/aggregation/types.d.ts +117 -0
- package/dist/core/src/events/index.d.ts +25 -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 +332 -0
- package/dist/core/src/events/observability/ObservableHookManager.d.ts +108 -0
- package/dist/core/src/events/observability/StreamWorkerMetrics.d.ts +76 -0
- package/dist/core/src/events/observability/index.d.ts +24 -0
- package/dist/core/src/events/observability/metrics-types.d.ts +16 -0
- package/dist/core/src/events/types.d.ts +134 -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/health/HealthProvider.d.ts +67 -0
- package/dist/core/src/http/types.d.ts +40 -0
- package/dist/core/src/index.d.ts +25 -4
- 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/observability/Metrics.d.ts +244 -0
- package/dist/core/src/observability/QueueDashboard.d.ts +136 -0
- package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +350 -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/index.js +6709 -9888
- package/dist/index.js.map +64 -62
- package/dist/photon/src/index.d.ts +19 -0
- package/dist/photon/src/middleware/ratelimit-redis.d.ts +50 -0
- package/dist/photon/src/middleware/ratelimit.d.ts +161 -0
- package/dist/photon/src/openapi.d.ts +19 -0
- package/dist/proto/ripple.proto +120 -0
- package/dist/ripple/src/RippleServer.d.ts +64 -445
- package/dist/ripple/src/channels/ChannelManager.d.ts +25 -10
- package/dist/ripple/src/drivers/NATSDriver.d.ts +87 -0
- package/dist/ripple/src/drivers/RedisDriver.d.ts +30 -1
- package/dist/ripple/src/drivers/index.d.ts +1 -0
- package/dist/ripple/src/engines/BunEngine.d.ts +98 -0
- package/dist/ripple/src/engines/IRippleEngine.d.ts +205 -0
- package/dist/ripple/src/engines/UWebSocketsEngine.d.ts +97 -0
- package/dist/ripple/src/engines/WsEngine.d.ts +69 -0
- package/dist/ripple/src/engines/index.d.ts +15 -0
- package/dist/ripple/src/index.d.ts +2 -0
- package/dist/ripple/src/middleware/InterceptorManager.d.ts +21 -0
- package/dist/ripple/src/observability/RippleMetrics.d.ts +24 -0
- package/dist/ripple/src/reliability/AckManager.d.ts +48 -0
- package/dist/ripple/src/serializers/ISerializer.d.ts +39 -0
- package/dist/ripple/src/serializers/JsonSerializer.d.ts +19 -0
- package/dist/ripple/src/serializers/ProtobufSerializer.d.ts +41 -0
- package/dist/ripple/src/serializers/index.d.ts +3 -0
- package/dist/ripple/src/tracking/SessionManager.d.ts +104 -0
- package/dist/ripple/src/tracking/index.d.ts +1 -0
- package/dist/ripple/src/types.d.ts +188 -12
- package/dist/ripple/src/utils/MessageSerializer.d.ts +33 -23
- package/dist/ripple/src/utils/TokenBucket.d.ts +25 -0
- package/package.json +25 -8
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import type { ConnectionContract } from '@gravito/atlas';
|
|
2
|
+
import { type CircuitBreakerOptions } from './events/CircuitBreaker';
|
|
3
|
+
import { DeadLetterQueue } from './events/DeadLetterQueue';
|
|
4
|
+
import type { EventBackend } from './events/EventBackend';
|
|
5
|
+
import type { EventOptions } from './events/EventOptions';
|
|
6
|
+
import { EventPriorityQueue, type EventQueueConfig } from './events/EventPriorityQueue';
|
|
7
|
+
import { DeadLetterQueueManager } from './reliability/DeadLetterQueueManager';
|
|
1
8
|
/**
|
|
2
9
|
* Callback function for filters (transforms values).
|
|
3
10
|
* @public
|
|
@@ -9,12 +16,127 @@ export type FilterCallback<T = unknown> = (value: T, ...args: unknown[]) => Prom
|
|
|
9
16
|
*/
|
|
10
17
|
export type ActionCallback<TArgs = unknown> = (args: TArgs) => Promise<void> | void;
|
|
11
18
|
/**
|
|
12
|
-
*
|
|
19
|
+
* Options for listener registration.
|
|
13
20
|
* @public
|
|
14
21
|
*/
|
|
22
|
+
export interface ListenerOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Explicitly specify the listener type.
|
|
25
|
+
* - 'sync': Force synchronous dispatch for this listener
|
|
26
|
+
* - 'async': Force asynchronous dispatch for this listener
|
|
27
|
+
* - 'auto': Auto-detect based on function signature (default)
|
|
28
|
+
* @default 'auto'
|
|
29
|
+
*/
|
|
30
|
+
type?: 'sync' | 'async' | 'auto';
|
|
31
|
+
/**
|
|
32
|
+
* Circuit breaker configuration for this listener.
|
|
33
|
+
*/
|
|
34
|
+
circuitBreaker?: CircuitBreakerOptions;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Information about a registered listener.
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
export interface ListenerInfo {
|
|
41
|
+
/**
|
|
42
|
+
* The callback function.
|
|
43
|
+
*/
|
|
44
|
+
callback: ActionCallback;
|
|
45
|
+
/**
|
|
46
|
+
* Whether the listener is considered async.
|
|
47
|
+
*/
|
|
48
|
+
isAsync: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* The explicit type override, if any.
|
|
51
|
+
*/
|
|
52
|
+
typeOverride?: 'sync' | 'async' | 'auto';
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Configuration for HookManager.
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
export interface HookManagerConfig {
|
|
59
|
+
/**
|
|
60
|
+
* Enable async event dispatch by default.
|
|
61
|
+
* When true, doAction() will automatically use async dispatch if any listener is async.
|
|
62
|
+
* @default false
|
|
63
|
+
*/
|
|
64
|
+
asyncByDefault?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Migration mode for backward compatibility.
|
|
67
|
+
* - 'sync': All events use synchronous dispatch (legacy mode)
|
|
68
|
+
* - 'hybrid': Auto-detect and use async for async listeners (recommended)
|
|
69
|
+
* - 'async': All events use async dispatch (future mode)
|
|
70
|
+
* @default 'sync'
|
|
71
|
+
*/
|
|
72
|
+
migrationMode?: 'sync' | 'hybrid' | 'async';
|
|
73
|
+
/**
|
|
74
|
+
* Enable deprecation warnings for synchronous event dispatch.
|
|
75
|
+
* @default false
|
|
76
|
+
*/
|
|
77
|
+
showDeprecationWarnings?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Enable Dead Letter Queue for failed events.
|
|
80
|
+
* @default true
|
|
81
|
+
*/
|
|
82
|
+
enableDLQ?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Configuration for the event priority queue (Backpressure).
|
|
85
|
+
*/
|
|
86
|
+
queue?: EventQueueConfig;
|
|
87
|
+
/**
|
|
88
|
+
* Custom event backend for distributed processing.
|
|
89
|
+
*/
|
|
90
|
+
backend?: EventBackend;
|
|
91
|
+
/**
|
|
92
|
+
* Database connection for persistent DLQ (optional).
|
|
93
|
+
* If provided, failed events after max retries will be persisted to database.
|
|
94
|
+
*/
|
|
95
|
+
db?: ConnectionContract;
|
|
96
|
+
/**
|
|
97
|
+
* Enable persistent DLQ for failed events (requires db).
|
|
98
|
+
* @default false
|
|
99
|
+
*/
|
|
100
|
+
enablePersistentDLQ?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Message Queue Bridge for distributed event processing via Bull Queue.
|
|
103
|
+
* When provided, enables dispatchQueued() method for routing events to Redis-backed queue.
|
|
104
|
+
*/
|
|
105
|
+
messageQueueBridge?: any;
|
|
106
|
+
/**
|
|
107
|
+
* Event aggregation configuration (FS-102).
|
|
108
|
+
* Enables deduplication and micro-batching for improved throughput.
|
|
109
|
+
*/
|
|
110
|
+
aggregation?: any;
|
|
111
|
+
}
|
|
15
112
|
export declare class HookManager {
|
|
16
113
|
private filters;
|
|
17
114
|
private actions;
|
|
115
|
+
private eventQueue;
|
|
116
|
+
private backend;
|
|
117
|
+
private dlq?;
|
|
118
|
+
private persistentDlqManager?;
|
|
119
|
+
private messageQueueBridge?;
|
|
120
|
+
private idempotencyCache;
|
|
121
|
+
private config;
|
|
122
|
+
private migrationWarner;
|
|
123
|
+
private aggregationManager?;
|
|
124
|
+
/**
|
|
125
|
+
* Cache for async detection results (WeakMap for automatic garbage collection).
|
|
126
|
+
* @internal
|
|
127
|
+
*/
|
|
128
|
+
private asyncDetectionCache;
|
|
129
|
+
/**
|
|
130
|
+
* Count of items in the async detection cache (for testing/debugging).
|
|
131
|
+
* @internal
|
|
132
|
+
*/
|
|
133
|
+
private asyncDetectionCacheCount;
|
|
134
|
+
/**
|
|
135
|
+
* Map of listener type overrides (callback -> type).
|
|
136
|
+
* @internal
|
|
137
|
+
*/
|
|
138
|
+
private listenerTypeOverrides;
|
|
139
|
+
constructor(config?: HookManagerConfig);
|
|
18
140
|
/**
|
|
19
141
|
* Register a filter hook.
|
|
20
142
|
*
|
|
@@ -59,26 +181,411 @@ export declare class HookManager {
|
|
|
59
181
|
* @template TArgs - The type of arguments passed to the action.
|
|
60
182
|
* @param hook - The unique name of the hook.
|
|
61
183
|
* @param callback - The callback function to execute.
|
|
184
|
+
* @param options - Optional listener options (type override, circuit breaker).
|
|
62
185
|
*
|
|
63
186
|
* @example
|
|
64
187
|
* ```typescript
|
|
65
188
|
* core.hooks.addAction('user_registered', async (user: User) => {
|
|
66
189
|
* await sendWelcomeEmail(user);
|
|
67
190
|
* });
|
|
191
|
+
*
|
|
192
|
+
* // With explicit type override
|
|
193
|
+
* core.hooks.addAction('sync_handler', handler, { type: 'async' });
|
|
68
194
|
* ```
|
|
69
195
|
*/
|
|
70
|
-
addAction<TArgs = unknown>(hook: string, callback: ActionCallback<TArgs
|
|
196
|
+
addAction<TArgs = unknown>(hook: string, callback: ActionCallback<TArgs>, options?: ListenerOptions): void;
|
|
71
197
|
/**
|
|
72
|
-
* Run all registered actions
|
|
198
|
+
* Run all registered actions.
|
|
199
|
+
*
|
|
200
|
+
* This method supports both synchronous and asynchronous dispatch based on configuration.
|
|
201
|
+
* In hybrid mode, it auto-detects async listeners and uses async dispatch.
|
|
73
202
|
*
|
|
74
203
|
* @template TArgs - The type of arguments passed to the action.
|
|
75
204
|
* @param hook - The name of the hook.
|
|
76
205
|
* @param args - The arguments to pass to the callbacks.
|
|
206
|
+
* @param options - Optional event options for async dispatch.
|
|
77
207
|
*
|
|
78
208
|
* @example
|
|
79
209
|
* ```typescript
|
|
80
210
|
* await core.hooks.doAction('user_registered', user);
|
|
81
211
|
* ```
|
|
82
212
|
*/
|
|
83
|
-
doAction<TArgs = unknown>(hook: string, args: TArgs): Promise<void>;
|
|
213
|
+
doAction<TArgs = unknown>(hook: string, args: TArgs, options?: EventOptions): Promise<void>;
|
|
214
|
+
/**
|
|
215
|
+
* Run all registered actions synchronously (legacy mode).
|
|
216
|
+
*
|
|
217
|
+
* @template TArgs - The type of arguments passed to the action.
|
|
218
|
+
* @param hook - The name of the hook.
|
|
219
|
+
* @param args - The arguments to pass to the callbacks.
|
|
220
|
+
* @internal
|
|
221
|
+
*/
|
|
222
|
+
doActionSync<TArgs = unknown>(hook: string, args: TArgs): Promise<void>;
|
|
223
|
+
/**
|
|
224
|
+
* Run all registered actions asynchronously via priority queue.
|
|
225
|
+
*
|
|
226
|
+
* This method uses EventPriorityQueue for async dispatch with support for:
|
|
227
|
+
* - Priority-based processing (high > normal > low)
|
|
228
|
+
* - Timeout handling
|
|
229
|
+
* - Ordering guarantees (strict, partition, none)
|
|
230
|
+
* - Idempotency
|
|
231
|
+
*
|
|
232
|
+
* @template TArgs - The type of arguments passed to the action.
|
|
233
|
+
* @param hook - The name of the hook.
|
|
234
|
+
* @param args - The arguments to pass to the callbacks.
|
|
235
|
+
* @param options - Event options for async dispatch.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```typescript
|
|
239
|
+
* await core.hooks.doActionAsync('order:created', order, {
|
|
240
|
+
* priority: 'high',
|
|
241
|
+
* ordering: 'partition',
|
|
242
|
+
* partitionKey: order.id,
|
|
243
|
+
* timeout: 5000,
|
|
244
|
+
* });
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
doActionAsync<TArgs = unknown>(hook: string, args: TArgs, options?: EventOptions): Promise<void>;
|
|
248
|
+
/**
|
|
249
|
+
* Determine if async dispatch should be used.
|
|
250
|
+
*
|
|
251
|
+
* @param callbacks - Callbacks to check
|
|
252
|
+
* @param options - Event options
|
|
253
|
+
* @returns True if async dispatch should be used
|
|
254
|
+
* @internal
|
|
255
|
+
*/
|
|
256
|
+
/**
|
|
257
|
+
* Determine the dispatch mode for an event.
|
|
258
|
+
*
|
|
259
|
+
* @param eventName - The name of the event
|
|
260
|
+
* @param options - Optional event options
|
|
261
|
+
* @returns The dispatch mode: 'sync' or 'async'
|
|
262
|
+
* @public
|
|
263
|
+
*/
|
|
264
|
+
detectMode(eventName: string, options?: EventOptions): 'sync' | 'async';
|
|
265
|
+
/**
|
|
266
|
+
* Check if a callback is an async function (with caching).
|
|
267
|
+
*
|
|
268
|
+
* Detection methods:
|
|
269
|
+
* 1. Check cache first
|
|
270
|
+
* 2. Check type override
|
|
271
|
+
* 3. Check constructor.name === 'AsyncFunction'
|
|
272
|
+
* 4. Fallback: Check function string representation
|
|
273
|
+
*
|
|
274
|
+
* @param callback - The callback to check
|
|
275
|
+
* @returns True if the callback is async
|
|
276
|
+
* @public
|
|
277
|
+
*/
|
|
278
|
+
isAsyncListener(callback: ActionCallback): boolean;
|
|
279
|
+
/**
|
|
280
|
+
* Cache async detection result.
|
|
281
|
+
* @internal
|
|
282
|
+
*/
|
|
283
|
+
private cacheAsyncResult;
|
|
284
|
+
/**
|
|
285
|
+
* Runtime detection for functions that return Promises but aren't declared async.
|
|
286
|
+
*
|
|
287
|
+
* This method executes the callback with test args and checks if the result is a Promise.
|
|
288
|
+
* Use with caution as it actually invokes the callback.
|
|
289
|
+
*
|
|
290
|
+
* @param callback - The callback to check
|
|
291
|
+
* @param testArgs - Arguments to pass to the callback for testing
|
|
292
|
+
* @returns True if the callback returns a Promise
|
|
293
|
+
* @public
|
|
294
|
+
*/
|
|
295
|
+
isAsyncListenerRuntime<TArgs = unknown>(callback: ActionCallback<TArgs>, testArgs: TArgs): Promise<boolean>;
|
|
296
|
+
/**
|
|
297
|
+
* Get the size of the async detection cache (for testing/debugging).
|
|
298
|
+
*
|
|
299
|
+
* @returns Number of cached detection results
|
|
300
|
+
* @public
|
|
301
|
+
*/
|
|
302
|
+
getAsyncDetectionCacheSize(): number;
|
|
303
|
+
/**
|
|
304
|
+
* Clear the async detection cache.
|
|
305
|
+
*
|
|
306
|
+
* @public
|
|
307
|
+
*/
|
|
308
|
+
clearAsyncDetectionCache(): void;
|
|
309
|
+
/**
|
|
310
|
+
* Check if any listener for a hook is async (including type overrides).
|
|
311
|
+
*
|
|
312
|
+
* @param hook - Hook name
|
|
313
|
+
* @returns True if any listener is async
|
|
314
|
+
* @public
|
|
315
|
+
*/
|
|
316
|
+
hasAsyncListeners(hook: string): boolean;
|
|
317
|
+
/**
|
|
318
|
+
* Check if a listener is effectively async (considering type override).
|
|
319
|
+
*
|
|
320
|
+
* @param callback - The callback to check
|
|
321
|
+
* @returns True if the listener should be treated as async
|
|
322
|
+
* @internal
|
|
323
|
+
*/
|
|
324
|
+
private isListenerEffectivelyAsync;
|
|
325
|
+
/**
|
|
326
|
+
* Get detailed information about all listeners for a hook.
|
|
327
|
+
*
|
|
328
|
+
* @param hook - Hook name
|
|
329
|
+
* @returns Array of listener info objects
|
|
330
|
+
* @public
|
|
331
|
+
*/
|
|
332
|
+
getListenerInfo(hook: string): ListenerInfo[];
|
|
333
|
+
private shouldUseAsyncDispatch;
|
|
334
|
+
/**
|
|
335
|
+
* Get the current event queue depth.
|
|
336
|
+
*
|
|
337
|
+
* @returns Total number of events in the queue
|
|
338
|
+
*/
|
|
339
|
+
getQueueDepth(): number;
|
|
340
|
+
/**
|
|
341
|
+
* Get the event queue depth for a specific priority.
|
|
342
|
+
*
|
|
343
|
+
* @param priority - Priority level
|
|
344
|
+
* @returns Number of events in the specified priority queue
|
|
345
|
+
*/
|
|
346
|
+
getQueueDepthByPriority(priority: 'high' | 'normal' | 'low'): number;
|
|
347
|
+
/**
|
|
348
|
+
* Get the EventPriorityQueue instance.
|
|
349
|
+
*
|
|
350
|
+
* @returns EventPriorityQueue instance
|
|
351
|
+
* @protected
|
|
352
|
+
*/
|
|
353
|
+
protected getEventQueue(): EventPriorityQueue;
|
|
354
|
+
/**
|
|
355
|
+
* Get all registered listeners for a hook.
|
|
356
|
+
*
|
|
357
|
+
* @param hook - Hook name
|
|
358
|
+
* @returns Array of callbacks
|
|
359
|
+
* @internal
|
|
360
|
+
*/
|
|
361
|
+
getListeners(hook: string): ActionCallback[];
|
|
362
|
+
/**
|
|
363
|
+
* Update HookManager configuration.
|
|
364
|
+
*
|
|
365
|
+
* @param config - New configuration
|
|
366
|
+
*/
|
|
367
|
+
configure(config: Partial<HookManagerConfig>): void;
|
|
368
|
+
/**
|
|
369
|
+
* Get current configuration.
|
|
370
|
+
*
|
|
371
|
+
* @returns Current configuration
|
|
372
|
+
*/
|
|
373
|
+
getConfig(): HookManagerConfig;
|
|
374
|
+
/**
|
|
375
|
+
* Suppress migration warnings for a specific event.
|
|
376
|
+
*
|
|
377
|
+
* @param eventName - The name of the event to suppress warnings for
|
|
378
|
+
* @public
|
|
379
|
+
*/
|
|
380
|
+
suppressMigrationWarning(eventName: string): void;
|
|
381
|
+
/**
|
|
382
|
+
* Set the event backend for distributed processing.
|
|
383
|
+
*
|
|
384
|
+
* @param backend - Event backend instance
|
|
385
|
+
*/
|
|
386
|
+
setBackend(backend: EventBackend): void;
|
|
387
|
+
/**
|
|
388
|
+
* Get the Dead Letter Queue instance.
|
|
389
|
+
*
|
|
390
|
+
* @returns Dead Letter Queue
|
|
391
|
+
*/
|
|
392
|
+
getDLQ(): DeadLetterQueue | undefined;
|
|
393
|
+
/**
|
|
394
|
+
* Requeue a failed event from the Dead Letter Queue.
|
|
395
|
+
*
|
|
396
|
+
* @param dlqEntryId - DLQ entry ID
|
|
397
|
+
* @returns True if requeued successfully, false if entry not found
|
|
398
|
+
*/
|
|
399
|
+
requeueDLQEntry(dlqEntryId: string): Promise<boolean>;
|
|
400
|
+
/**
|
|
401
|
+
* Requeue all failed events for a specific event name.
|
|
402
|
+
*
|
|
403
|
+
* @param eventName - Event name to requeue
|
|
404
|
+
* @returns Number of events requeued
|
|
405
|
+
*/
|
|
406
|
+
requeueDLQBatch(eventName: string): Promise<number>;
|
|
407
|
+
/**
|
|
408
|
+
* Get Dead Letter Queue entries with optional filtering.
|
|
409
|
+
*
|
|
410
|
+
* @param filter - Filter options
|
|
411
|
+
* @returns Array of DLQ entries
|
|
412
|
+
*/
|
|
413
|
+
getDLQEntries(filter?: {
|
|
414
|
+
eventName?: string;
|
|
415
|
+
from?: number;
|
|
416
|
+
to?: number;
|
|
417
|
+
limit?: number;
|
|
418
|
+
}): import("@gravito/core").DLQEntry[];
|
|
419
|
+
/**
|
|
420
|
+
* Get count of Dead Letter Queue entries for an event.
|
|
421
|
+
*
|
|
422
|
+
* @param eventName - Event name
|
|
423
|
+
* @returns Count of entries
|
|
424
|
+
*/
|
|
425
|
+
getDLQCount(eventName: string): number;
|
|
426
|
+
/**
|
|
427
|
+
* Delete a DLQ entry.
|
|
428
|
+
*
|
|
429
|
+
* @param entryId - DLQ entry ID
|
|
430
|
+
* @returns True if deleted, false if not found
|
|
431
|
+
*/
|
|
432
|
+
deleteDLQEntry(entryId: string): boolean;
|
|
433
|
+
/**
|
|
434
|
+
* Get circuit breaker statistics for all events.
|
|
435
|
+
*
|
|
436
|
+
* @returns Array of circuit breaker statistics
|
|
437
|
+
*/
|
|
438
|
+
getCircuitBreakerStats(): Array<{
|
|
439
|
+
eventName: string;
|
|
440
|
+
state: string;
|
|
441
|
+
failureCount: number;
|
|
442
|
+
successCount: number;
|
|
443
|
+
lastFailureAt?: Date;
|
|
444
|
+
lastSuccessAt?: Date;
|
|
445
|
+
openedAt?: Date;
|
|
446
|
+
totalRequests: number;
|
|
447
|
+
totalFailures: number;
|
|
448
|
+
totalSuccesses: number;
|
|
449
|
+
}>;
|
|
450
|
+
/**
|
|
451
|
+
* Reset a circuit breaker for an event.
|
|
452
|
+
*
|
|
453
|
+
* @param eventName - Event name
|
|
454
|
+
* @returns True if reset, false if circuit breaker not found
|
|
455
|
+
*/
|
|
456
|
+
resetCircuitBreaker(eventName: string): boolean;
|
|
457
|
+
/**
|
|
458
|
+
* Get the current backpressure state.
|
|
459
|
+
*
|
|
460
|
+
* @returns Backpressure state ('NORMAL', 'WARNING', 'CRITICAL', 'OVERFLOW') or undefined if not enabled
|
|
461
|
+
*/
|
|
462
|
+
getBackpressureState(): string | undefined;
|
|
463
|
+
/**
|
|
464
|
+
* Get backpressure metrics snapshot.
|
|
465
|
+
*
|
|
466
|
+
* @returns Backpressure metrics snapshot or undefined if not enabled
|
|
467
|
+
*/
|
|
468
|
+
getBackpressureMetrics(): object | undefined;
|
|
469
|
+
/**
|
|
470
|
+
* Remove all listeners for a specific action hook.
|
|
471
|
+
*
|
|
472
|
+
* @param hook - Hook name
|
|
473
|
+
*/
|
|
474
|
+
removeAction(hook: string): void;
|
|
475
|
+
/**
|
|
476
|
+
* Get the persistent DLQ manager instance.
|
|
477
|
+
*
|
|
478
|
+
* @returns DeadLetterQueueManager or undefined if not configured
|
|
479
|
+
* @public
|
|
480
|
+
*/
|
|
481
|
+
getPersistentDLQManager(): DeadLetterQueueManager | undefined;
|
|
482
|
+
/**
|
|
483
|
+
* Create a handler function for persistent DLQ.
|
|
484
|
+
* This handler is used by EventPriorityQueue to persist failed events.
|
|
485
|
+
*
|
|
486
|
+
* @returns Handler function
|
|
487
|
+
* @internal
|
|
488
|
+
*/
|
|
489
|
+
private createPersistentDLQHandler;
|
|
490
|
+
/**
|
|
491
|
+
* Requeue a failed event from the persistent DLQ.
|
|
492
|
+
*
|
|
493
|
+
* @param dlqId - DLQ entry UUID
|
|
494
|
+
* @returns True if requeued successfully
|
|
495
|
+
* @public
|
|
496
|
+
*/
|
|
497
|
+
requeuePersistentDLQEntry(dlqId: string): Promise<boolean>;
|
|
498
|
+
/**
|
|
499
|
+
* Requeue multiple events from persistent DLQ.
|
|
500
|
+
*
|
|
501
|
+
* @param filter - Filter criteria
|
|
502
|
+
* @returns Result statistics
|
|
503
|
+
* @public
|
|
504
|
+
*/
|
|
505
|
+
requeuePersistentDLQBatch(filter?: {
|
|
506
|
+
eventName?: string;
|
|
507
|
+
status?: 'pending' | 'requeued' | 'resolved' | 'abandoned';
|
|
508
|
+
}): Promise<{
|
|
509
|
+
total: number;
|
|
510
|
+
succeeded: number;
|
|
511
|
+
failed: number;
|
|
512
|
+
}>;
|
|
513
|
+
/**
|
|
514
|
+
* Dispatch an event through Bull Queue (分佈式異步處理).
|
|
515
|
+
*
|
|
516
|
+
* 與 doActionAsync() 不同:
|
|
517
|
+
* - doActionAsync() 使用 EventPriorityQueue (Memory-based)
|
|
518
|
+
* - dispatchQueued() 使用 Bull Queue (Redis-backed, 分佈式)
|
|
519
|
+
*
|
|
520
|
+
* 適用於需要持久化和跨進程處理的事件。
|
|
521
|
+
*
|
|
522
|
+
* @template TArgs - 事件參數類型
|
|
523
|
+
* @param event - 事件名稱
|
|
524
|
+
* @param args - 事件參數
|
|
525
|
+
* @param options - 事件選項(可選)
|
|
526
|
+
* @returns Job ID
|
|
527
|
+
* @throws 如果未配置 MessageQueueBridge 或沒有 listeners
|
|
528
|
+
*
|
|
529
|
+
* @example
|
|
530
|
+
* ```typescript
|
|
531
|
+
* const jobId = await hookManager.dispatchQueued('order:created', {
|
|
532
|
+
* orderId: 'ORD-123',
|
|
533
|
+
* amount: 999.99
|
|
534
|
+
* })
|
|
535
|
+
* ```
|
|
536
|
+
*
|
|
537
|
+
* @public
|
|
538
|
+
*/
|
|
539
|
+
dispatchQueued<TArgs = unknown>(event: string, args: TArgs, options?: any): Promise<string>;
|
|
540
|
+
/**
|
|
541
|
+
* Dispatch an event through Bull Queue with delay (延遲隊列分發).
|
|
542
|
+
*
|
|
543
|
+
* 通過 Bull Queue 的 delayed jobs 功能實現延遲處理。
|
|
544
|
+
*
|
|
545
|
+
* @template TArgs - 事件參數類型
|
|
546
|
+
* @param event - 事件名稱
|
|
547
|
+
* @param args - 事件參數
|
|
548
|
+
* @param delay - 延遲時間(毫秒)
|
|
549
|
+
* @param options - 事件選項(可選)
|
|
550
|
+
* @returns Job ID
|
|
551
|
+
* @throws 如果未配置 MessageQueueBridge
|
|
552
|
+
*
|
|
553
|
+
* @example
|
|
554
|
+
* ```typescript
|
|
555
|
+
* // 延遲 5 秒後處理
|
|
556
|
+
* const jobId = await hookManager.dispatchDeferredQueued(
|
|
557
|
+
* 'reminder:send',
|
|
558
|
+
* { userId: '123' },
|
|
559
|
+
* 5000
|
|
560
|
+
* )
|
|
561
|
+
* ```
|
|
562
|
+
*
|
|
563
|
+
* @public
|
|
564
|
+
*/
|
|
565
|
+
dispatchDeferredQueued<TArgs = unknown>(event: string, args: TArgs, delay: number, options?: any): Promise<string>;
|
|
566
|
+
/**
|
|
567
|
+
* Get the execution status of an event.
|
|
568
|
+
*
|
|
569
|
+
* 查詢事件執行狀態,支持查詢 Bull Queue 和 DLQ 中的事件。
|
|
570
|
+
*
|
|
571
|
+
* @param eventId - 事件 ID (task.id 或 jobId)
|
|
572
|
+
* @returns 事件狀態信息
|
|
573
|
+
* @throws 如果未配置 MessageQueueBridge
|
|
574
|
+
*
|
|
575
|
+
* @example
|
|
576
|
+
* ```typescript
|
|
577
|
+
* const status = await hookManager.getEventStatus('queue-1707000000000-abc123')
|
|
578
|
+
* console.log(status) // { eventId, status, attempts, createdAt, ... }
|
|
579
|
+
* ```
|
|
580
|
+
*
|
|
581
|
+
* @public
|
|
582
|
+
*/
|
|
583
|
+
getEventStatus(eventId: string): Promise<any>;
|
|
584
|
+
/**
|
|
585
|
+
* Get persistent DLQ statistics.
|
|
586
|
+
*
|
|
587
|
+
* @returns Statistics object with total, byEvent, and byStatus counts
|
|
588
|
+
* @public
|
|
589
|
+
*/
|
|
590
|
+
getPersistentDLQStats(): Promise<import("@gravito/core").DLQStats | undefined>;
|
|
84
591
|
}
|
|
@@ -82,6 +82,47 @@ export type GravitoConfig = {
|
|
|
82
82
|
* @since 2.0.0
|
|
83
83
|
*/
|
|
84
84
|
container?: Container;
|
|
85
|
+
/**
|
|
86
|
+
* Observability configuration for event system.
|
|
87
|
+
* @since 2.1.0
|
|
88
|
+
*/
|
|
89
|
+
observability?: {
|
|
90
|
+
/**
|
|
91
|
+
* Enable event system observability (metrics, tracing).
|
|
92
|
+
* @default false
|
|
93
|
+
*/
|
|
94
|
+
enabled?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Enable OpenTelemetry distributed tracing.
|
|
97
|
+
* @default false
|
|
98
|
+
*/
|
|
99
|
+
tracing?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Prefix for metric names.
|
|
102
|
+
* @default 'gravito_event_'
|
|
103
|
+
*/
|
|
104
|
+
metricsPrefix?: string;
|
|
105
|
+
/**
|
|
106
|
+
* Prometheus metrics configuration.
|
|
107
|
+
*/
|
|
108
|
+
prometheus?: {
|
|
109
|
+
/**
|
|
110
|
+
* Enable Prometheus metrics endpoint.
|
|
111
|
+
* @default true
|
|
112
|
+
*/
|
|
113
|
+
enabled?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Port for Prometheus metrics endpoint.
|
|
116
|
+
* @default 9090
|
|
117
|
+
*/
|
|
118
|
+
port?: number;
|
|
119
|
+
/**
|
|
120
|
+
* Endpoint path for metrics.
|
|
121
|
+
* @default '/metrics'
|
|
122
|
+
*/
|
|
123
|
+
endpoint?: string;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
85
126
|
};
|
|
86
127
|
import { Router } from './Router';
|
|
87
128
|
import { Encrypter } from './security/Encrypter';
|
|
@@ -122,6 +163,20 @@ export declare class PlanetCore {
|
|
|
122
163
|
private providers;
|
|
123
164
|
private deferredProviders;
|
|
124
165
|
private bootedProviders;
|
|
166
|
+
private isShuttingDown;
|
|
167
|
+
/**
|
|
168
|
+
* Initialize observability asynchronously (metrics, tracing, Prometheus).
|
|
169
|
+
* This is called from constructor but doesn't block initialization.
|
|
170
|
+
*
|
|
171
|
+
* @internal
|
|
172
|
+
*/
|
|
173
|
+
private initializeObservabilityAsync;
|
|
174
|
+
/**
|
|
175
|
+
* Initialize Prometheus metrics asynchronously.
|
|
176
|
+
*
|
|
177
|
+
* @internal
|
|
178
|
+
*/
|
|
179
|
+
private initializePrometheusAsync;
|
|
125
180
|
/**
|
|
126
181
|
* Register a service provider to the core.
|
|
127
182
|
*
|
|
@@ -155,6 +210,34 @@ export declare class PlanetCore {
|
|
|
155
210
|
* ```
|
|
156
211
|
*/
|
|
157
212
|
bootstrap(): Promise<void>;
|
|
213
|
+
/**
|
|
214
|
+
* Called when the application is ready to accept requests.
|
|
215
|
+
*
|
|
216
|
+
* Invokes the `onReady()` lifecycle hook on all providers.
|
|
217
|
+
* Called automatically at the end of `bootstrap()`.
|
|
218
|
+
*
|
|
219
|
+
* @returns Promise that resolves when all providers are ready.
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* await core.ready();
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
ready(): Promise<void>;
|
|
227
|
+
/**
|
|
228
|
+
* Gracefully shutdown the application.
|
|
229
|
+
*
|
|
230
|
+
* Invokes the `onShutdown()` lifecycle hook on all providers in reverse order (LIFO).
|
|
231
|
+
* Should be called when the application receives a termination signal.
|
|
232
|
+
*
|
|
233
|
+
* @returns Promise that resolves when all providers have shut down.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* process.on('SIGTERM', () => core.shutdown());
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
shutdown(): Promise<void>;
|
|
158
241
|
/**
|
|
159
242
|
* Setup deferred provider resolution.
|
|
160
243
|
* Wraps container.make to auto-register deferred providers on first request.
|
|
@@ -180,6 +263,12 @@ export declare class PlanetCore {
|
|
|
180
263
|
adapter?: HttpAdapter;
|
|
181
264
|
container?: Container;
|
|
182
265
|
});
|
|
266
|
+
/**
|
|
267
|
+
* Setup process signal handlers for graceful shutdown
|
|
268
|
+
*
|
|
269
|
+
* @internal
|
|
270
|
+
*/
|
|
271
|
+
private setupSignalHandlers;
|
|
183
272
|
/**
|
|
184
273
|
* Programmatically register an infrastructure module (Orbit).
|
|
185
274
|
* @since 2.0.0
|