@gravito/ripple 3.1.0 → 4.0.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 +260 -19
- 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/CommandKernel.d.ts +33 -0
- package/dist/core/src/Container.d.ts +41 -11
- package/dist/core/src/HookManager.d.ts +416 -4
- package/dist/core/src/Router.d.ts +1 -5
- 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 +27 -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/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/types.d.ts +21 -0
- package/dist/core/src/index.d.ts +12 -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/index.js +5944 -9486
- package/dist/index.js.map +62 -62
- package/dist/photon/src/index.d.ts +14 -0
- package/dist/photon/src/middleware/ratelimit.d.ts +157 -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 -444
- 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/index.d.ts +11 -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 +38 -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 +177 -12
- package/dist/ripple/src/utils/MessageSerializer.d.ts +33 -23
- package/dist/ripple/src/utils/TokenBucket.d.ts +25 -0
- package/package.json +23 -7
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate Levenshtein distance between two strings
|
|
3
|
+
* Used for "Did you mean?" suggestions
|
|
4
|
+
*/
|
|
5
|
+
export declare function levenshtein(a: string, b: string): number;
|
|
6
|
+
/**
|
|
7
|
+
* Find similar strings from a list
|
|
8
|
+
*/
|
|
9
|
+
export declare function findSimilar(target: string, candidates: string[], maxDistance?: number, maxResults?: number): string[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Container } from './Container';
|
|
2
|
+
/**
|
|
3
|
+
* CommandHandler type for custom CLI commands.
|
|
4
|
+
*/
|
|
5
|
+
export type CommandHandler = (args: string[], container: Container) => Promise<void> | void;
|
|
6
|
+
/**
|
|
7
|
+
* CommandKernel - Structured CLI Command handling.
|
|
8
|
+
*
|
|
9
|
+
* Manages registration and execution of custom CLI commands that can
|
|
10
|
+
* reuse the application container and providers.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const kernel = new CommandKernel(container);
|
|
15
|
+
* kernel.register('greet', (args) => console.log('Hello', args[0]));
|
|
16
|
+
* await kernel.handle(['greet', 'Universe']);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare class CommandKernel {
|
|
20
|
+
private container;
|
|
21
|
+
private commands;
|
|
22
|
+
constructor(container: Container);
|
|
23
|
+
/**
|
|
24
|
+
* Register a new command handler.
|
|
25
|
+
*/
|
|
26
|
+
register(name: string, handler: CommandHandler): void;
|
|
27
|
+
/**
|
|
28
|
+
* Handle an incoming CLI command.
|
|
29
|
+
*
|
|
30
|
+
* @param argv - Array of command line arguments (e.g. process.argv.slice(2))
|
|
31
|
+
*/
|
|
32
|
+
handle(argv: string[]): Promise<void>;
|
|
33
|
+
}
|
|
@@ -2,7 +2,26 @@
|
|
|
2
2
|
* Factory type for creating service instances
|
|
3
3
|
*/
|
|
4
4
|
export type Factory<T> = (container: Container) => T;
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* ServiceMap interface for type-safe IoC resolution.
|
|
7
|
+
*
|
|
8
|
+
* Extend this interface via module augmentation to get type inference:
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* declare module '@gravito/core' {
|
|
12
|
+
* interface ServiceMap {
|
|
13
|
+
* logger: Logger
|
|
14
|
+
* db: DatabaseConnection
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export type ServiceMap = {};
|
|
20
|
+
/**
|
|
21
|
+
* ServiceKey represents the allowed keys for service resolution.
|
|
22
|
+
* Includes keys from ServiceMap, generic strings, or symbols.
|
|
23
|
+
*/
|
|
24
|
+
export type ServiceKey = keyof ServiceMap | (string & {}) | symbol;
|
|
6
25
|
/**
|
|
7
26
|
* Container - Simple Dependency Injection Container.
|
|
8
27
|
* Manages service bindings and singleton instances.
|
|
@@ -11,6 +30,7 @@ export type BindingKey = string | symbol;
|
|
|
11
30
|
export declare class Container {
|
|
12
31
|
private bindings;
|
|
13
32
|
private instances;
|
|
33
|
+
private resolutionStack;
|
|
14
34
|
/**
|
|
15
35
|
* Bind a service to the container.
|
|
16
36
|
*
|
|
@@ -26,7 +46,7 @@ export declare class Container {
|
|
|
26
46
|
* container.bind('logger', (c) => new ConsoleLogger());
|
|
27
47
|
* ```
|
|
28
48
|
*/
|
|
29
|
-
bind<T>(key:
|
|
49
|
+
bind<T>(key: ServiceKey, factory: Factory<T>): void;
|
|
30
50
|
/**
|
|
31
51
|
* Bind a shared service to the container (Singleton).
|
|
32
52
|
*
|
|
@@ -42,11 +62,14 @@ export declare class Container {
|
|
|
42
62
|
* container.singleton('db', (c) => new DatabaseConnection());
|
|
43
63
|
* ```
|
|
44
64
|
*/
|
|
45
|
-
singleton<T>(key:
|
|
65
|
+
singleton<T>(key: ServiceKey, factory: Factory<T>): void;
|
|
46
66
|
/**
|
|
47
|
-
* Register an existing instance as shared service.
|
|
67
|
+
* Register an existing instance as a shared service.
|
|
68
|
+
*
|
|
69
|
+
* @param key - The unique identifier for the service.
|
|
70
|
+
* @param instance - The instance to register.
|
|
48
71
|
*/
|
|
49
|
-
instance<T>(key:
|
|
72
|
+
instance<T>(key: ServiceKey, instance: T): void;
|
|
50
73
|
/**
|
|
51
74
|
* Resolve a service instance from the container.
|
|
52
75
|
*
|
|
@@ -62,17 +85,24 @@ export declare class Container {
|
|
|
62
85
|
* const logger = container.make<Logger>('logger');
|
|
63
86
|
* ```
|
|
64
87
|
*/
|
|
65
|
-
make<
|
|
88
|
+
make<K extends keyof ServiceMap>(key: K): ServiceMap[K];
|
|
89
|
+
make<T>(key: ServiceKey): T;
|
|
66
90
|
/**
|
|
67
|
-
* Check if a service is bound.
|
|
91
|
+
* Check if a service is bound or has an instance in the container.
|
|
92
|
+
*
|
|
93
|
+
* @param key - The service key to check.
|
|
94
|
+
* @returns True if the service exists.
|
|
68
95
|
*/
|
|
69
|
-
has(key:
|
|
96
|
+
has(key: ServiceKey): boolean;
|
|
70
97
|
/**
|
|
71
|
-
* Flush all instances and bindings.
|
|
98
|
+
* Flush all instances and bindings from the container.
|
|
99
|
+
* Resets the container to an empty state.
|
|
72
100
|
*/
|
|
73
101
|
flush(): void;
|
|
74
102
|
/**
|
|
75
|
-
* Forget a specific instance
|
|
103
|
+
* Forget a specific instance while keeping its binding.
|
|
104
|
+
*
|
|
105
|
+
* @param key - The service key to forget.
|
|
76
106
|
*/
|
|
77
|
-
forget(key:
|
|
107
|
+
forget(key: ServiceKey): void;
|
|
78
108
|
}
|
|
@@ -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,115 @@ 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
|
+
}
|
|
15
102
|
export declare class HookManager {
|
|
16
103
|
private filters;
|
|
17
104
|
private actions;
|
|
105
|
+
private eventQueue;
|
|
106
|
+
private backend;
|
|
107
|
+
private dlq?;
|
|
108
|
+
private persistentDlqManager?;
|
|
109
|
+
private idempotencyCache;
|
|
110
|
+
private config;
|
|
111
|
+
private migrationWarner;
|
|
112
|
+
/**
|
|
113
|
+
* Cache for async detection results (WeakMap for automatic garbage collection).
|
|
114
|
+
* @internal
|
|
115
|
+
*/
|
|
116
|
+
private asyncDetectionCache;
|
|
117
|
+
/**
|
|
118
|
+
* Count of items in the async detection cache (for testing/debugging).
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
private asyncDetectionCacheCount;
|
|
122
|
+
/**
|
|
123
|
+
* Map of listener type overrides (callback -> type).
|
|
124
|
+
* @internal
|
|
125
|
+
*/
|
|
126
|
+
private listenerTypeOverrides;
|
|
127
|
+
constructor(config?: HookManagerConfig);
|
|
18
128
|
/**
|
|
19
129
|
* Register a filter hook.
|
|
20
130
|
*
|
|
@@ -59,26 +169,328 @@ export declare class HookManager {
|
|
|
59
169
|
* @template TArgs - The type of arguments passed to the action.
|
|
60
170
|
* @param hook - The unique name of the hook.
|
|
61
171
|
* @param callback - The callback function to execute.
|
|
172
|
+
* @param options - Optional listener options (type override, circuit breaker).
|
|
62
173
|
*
|
|
63
174
|
* @example
|
|
64
175
|
* ```typescript
|
|
65
176
|
* core.hooks.addAction('user_registered', async (user: User) => {
|
|
66
177
|
* await sendWelcomeEmail(user);
|
|
67
178
|
* });
|
|
179
|
+
*
|
|
180
|
+
* // With explicit type override
|
|
181
|
+
* core.hooks.addAction('sync_handler', handler, { type: 'async' });
|
|
68
182
|
* ```
|
|
69
183
|
*/
|
|
70
|
-
addAction<TArgs = unknown>(hook: string, callback: ActionCallback<TArgs
|
|
184
|
+
addAction<TArgs = unknown>(hook: string, callback: ActionCallback<TArgs>, options?: ListenerOptions): void;
|
|
71
185
|
/**
|
|
72
|
-
* Run all registered actions
|
|
186
|
+
* Run all registered actions.
|
|
187
|
+
*
|
|
188
|
+
* This method supports both synchronous and asynchronous dispatch based on configuration.
|
|
189
|
+
* In hybrid mode, it auto-detects async listeners and uses async dispatch.
|
|
73
190
|
*
|
|
74
191
|
* @template TArgs - The type of arguments passed to the action.
|
|
75
192
|
* @param hook - The name of the hook.
|
|
76
193
|
* @param args - The arguments to pass to the callbacks.
|
|
194
|
+
* @param options - Optional event options for async dispatch.
|
|
77
195
|
*
|
|
78
196
|
* @example
|
|
79
197
|
* ```typescript
|
|
80
198
|
* await core.hooks.doAction('user_registered', user);
|
|
81
199
|
* ```
|
|
82
200
|
*/
|
|
83
|
-
doAction<TArgs = unknown>(hook: string, args: TArgs): Promise<void>;
|
|
201
|
+
doAction<TArgs = unknown>(hook: string, args: TArgs, options?: EventOptions): Promise<void>;
|
|
202
|
+
/**
|
|
203
|
+
* Run all registered actions synchronously (legacy mode).
|
|
204
|
+
*
|
|
205
|
+
* @template TArgs - The type of arguments passed to the action.
|
|
206
|
+
* @param hook - The name of the hook.
|
|
207
|
+
* @param args - The arguments to pass to the callbacks.
|
|
208
|
+
* @internal
|
|
209
|
+
*/
|
|
210
|
+
doActionSync<TArgs = unknown>(hook: string, args: TArgs): Promise<void>;
|
|
211
|
+
/**
|
|
212
|
+
* Run all registered actions asynchronously via priority queue.
|
|
213
|
+
*
|
|
214
|
+
* This method uses EventPriorityQueue for async dispatch with support for:
|
|
215
|
+
* - Priority-based processing (high > normal > low)
|
|
216
|
+
* - Timeout handling
|
|
217
|
+
* - Ordering guarantees (strict, partition, none)
|
|
218
|
+
* - Idempotency
|
|
219
|
+
*
|
|
220
|
+
* @template TArgs - The type of arguments passed to the action.
|
|
221
|
+
* @param hook - The name of the hook.
|
|
222
|
+
* @param args - The arguments to pass to the callbacks.
|
|
223
|
+
* @param options - Event options for async dispatch.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```typescript
|
|
227
|
+
* await core.hooks.doActionAsync('order:created', order, {
|
|
228
|
+
* priority: 'high',
|
|
229
|
+
* ordering: 'partition',
|
|
230
|
+
* partitionKey: order.id,
|
|
231
|
+
* timeout: 5000,
|
|
232
|
+
* });
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
doActionAsync<TArgs = unknown>(hook: string, args: TArgs, options?: EventOptions): Promise<void>;
|
|
236
|
+
/**
|
|
237
|
+
* Determine if async dispatch should be used.
|
|
238
|
+
*
|
|
239
|
+
* @param callbacks - Callbacks to check
|
|
240
|
+
* @param options - Event options
|
|
241
|
+
* @returns True if async dispatch should be used
|
|
242
|
+
* @internal
|
|
243
|
+
*/
|
|
244
|
+
/**
|
|
245
|
+
* Determine the dispatch mode for an event.
|
|
246
|
+
*
|
|
247
|
+
* @param eventName - The name of the event
|
|
248
|
+
* @param options - Optional event options
|
|
249
|
+
* @returns The dispatch mode: 'sync' or 'async'
|
|
250
|
+
* @public
|
|
251
|
+
*/
|
|
252
|
+
detectMode(eventName: string, options?: EventOptions): 'sync' | 'async';
|
|
253
|
+
/**
|
|
254
|
+
* Check if a callback is an async function (with caching).
|
|
255
|
+
*
|
|
256
|
+
* Detection methods:
|
|
257
|
+
* 1. Check cache first
|
|
258
|
+
* 2. Check type override
|
|
259
|
+
* 3. Check constructor.name === 'AsyncFunction'
|
|
260
|
+
* 4. Fallback: Check function string representation
|
|
261
|
+
*
|
|
262
|
+
* @param callback - The callback to check
|
|
263
|
+
* @returns True if the callback is async
|
|
264
|
+
* @public
|
|
265
|
+
*/
|
|
266
|
+
isAsyncListener(callback: ActionCallback): boolean;
|
|
267
|
+
/**
|
|
268
|
+
* Cache async detection result.
|
|
269
|
+
* @internal
|
|
270
|
+
*/
|
|
271
|
+
private cacheAsyncResult;
|
|
272
|
+
/**
|
|
273
|
+
* Runtime detection for functions that return Promises but aren't declared async.
|
|
274
|
+
*
|
|
275
|
+
* This method executes the callback with test args and checks if the result is a Promise.
|
|
276
|
+
* Use with caution as it actually invokes the callback.
|
|
277
|
+
*
|
|
278
|
+
* @param callback - The callback to check
|
|
279
|
+
* @param testArgs - Arguments to pass to the callback for testing
|
|
280
|
+
* @returns True if the callback returns a Promise
|
|
281
|
+
* @public
|
|
282
|
+
*/
|
|
283
|
+
isAsyncListenerRuntime<TArgs = unknown>(callback: ActionCallback<TArgs>, testArgs: TArgs): Promise<boolean>;
|
|
284
|
+
/**
|
|
285
|
+
* Get the size of the async detection cache (for testing/debugging).
|
|
286
|
+
*
|
|
287
|
+
* @returns Number of cached detection results
|
|
288
|
+
* @public
|
|
289
|
+
*/
|
|
290
|
+
getAsyncDetectionCacheSize(): number;
|
|
291
|
+
/**
|
|
292
|
+
* Clear the async detection cache.
|
|
293
|
+
*
|
|
294
|
+
* @public
|
|
295
|
+
*/
|
|
296
|
+
clearAsyncDetectionCache(): void;
|
|
297
|
+
/**
|
|
298
|
+
* Check if any listener for a hook is async (including type overrides).
|
|
299
|
+
*
|
|
300
|
+
* @param hook - Hook name
|
|
301
|
+
* @returns True if any listener is async
|
|
302
|
+
* @public
|
|
303
|
+
*/
|
|
304
|
+
hasAsyncListeners(hook: string): boolean;
|
|
305
|
+
/**
|
|
306
|
+
* Check if a listener is effectively async (considering type override).
|
|
307
|
+
*
|
|
308
|
+
* @param callback - The callback to check
|
|
309
|
+
* @returns True if the listener should be treated as async
|
|
310
|
+
* @internal
|
|
311
|
+
*/
|
|
312
|
+
private isListenerEffectivelyAsync;
|
|
313
|
+
/**
|
|
314
|
+
* Get detailed information about all listeners for a hook.
|
|
315
|
+
*
|
|
316
|
+
* @param hook - Hook name
|
|
317
|
+
* @returns Array of listener info objects
|
|
318
|
+
* @public
|
|
319
|
+
*/
|
|
320
|
+
getListenerInfo(hook: string): ListenerInfo[];
|
|
321
|
+
private shouldUseAsyncDispatch;
|
|
322
|
+
/**
|
|
323
|
+
* Get the current event queue depth.
|
|
324
|
+
*
|
|
325
|
+
* @returns Total number of events in the queue
|
|
326
|
+
*/
|
|
327
|
+
getQueueDepth(): number;
|
|
328
|
+
/**
|
|
329
|
+
* Get the event queue depth for a specific priority.
|
|
330
|
+
*
|
|
331
|
+
* @param priority - Priority level
|
|
332
|
+
* @returns Number of events in the specified priority queue
|
|
333
|
+
*/
|
|
334
|
+
getQueueDepthByPriority(priority: 'high' | 'normal' | 'low'): number;
|
|
335
|
+
/**
|
|
336
|
+
* Get the EventPriorityQueue instance.
|
|
337
|
+
*
|
|
338
|
+
* @returns EventPriorityQueue instance
|
|
339
|
+
* @protected
|
|
340
|
+
*/
|
|
341
|
+
protected getEventQueue(): EventPriorityQueue;
|
|
342
|
+
/**
|
|
343
|
+
* Get all registered listeners for a hook.
|
|
344
|
+
*
|
|
345
|
+
* @param hook - Hook name
|
|
346
|
+
* @returns Array of callbacks
|
|
347
|
+
* @internal
|
|
348
|
+
*/
|
|
349
|
+
getListeners(hook: string): ActionCallback[];
|
|
350
|
+
/**
|
|
351
|
+
* Update HookManager configuration.
|
|
352
|
+
*
|
|
353
|
+
* @param config - New configuration
|
|
354
|
+
*/
|
|
355
|
+
configure(config: Partial<HookManagerConfig>): void;
|
|
356
|
+
/**
|
|
357
|
+
* Get current configuration.
|
|
358
|
+
*
|
|
359
|
+
* @returns Current configuration
|
|
360
|
+
*/
|
|
361
|
+
getConfig(): HookManagerConfig;
|
|
362
|
+
/**
|
|
363
|
+
* Suppress migration warnings for a specific event.
|
|
364
|
+
*
|
|
365
|
+
* @param eventName - The name of the event to suppress warnings for
|
|
366
|
+
* @public
|
|
367
|
+
*/
|
|
368
|
+
suppressMigrationWarning(eventName: string): void;
|
|
369
|
+
/**
|
|
370
|
+
* Set the event backend for distributed processing.
|
|
371
|
+
*
|
|
372
|
+
* @param backend - Event backend instance
|
|
373
|
+
*/
|
|
374
|
+
setBackend(backend: EventBackend): void;
|
|
375
|
+
/**
|
|
376
|
+
* Get the Dead Letter Queue instance.
|
|
377
|
+
*
|
|
378
|
+
* @returns Dead Letter Queue
|
|
379
|
+
*/
|
|
380
|
+
getDLQ(): DeadLetterQueue | undefined;
|
|
381
|
+
/**
|
|
382
|
+
* Requeue a failed event from the Dead Letter Queue.
|
|
383
|
+
*
|
|
384
|
+
* @param dlqEntryId - DLQ entry ID
|
|
385
|
+
* @returns True if requeued successfully, false if entry not found
|
|
386
|
+
*/
|
|
387
|
+
requeueDLQEntry(dlqEntryId: string): Promise<boolean>;
|
|
388
|
+
/**
|
|
389
|
+
* Requeue all failed events for a specific event name.
|
|
390
|
+
*
|
|
391
|
+
* @param eventName - Event name to requeue
|
|
392
|
+
* @returns Number of events requeued
|
|
393
|
+
*/
|
|
394
|
+
requeueDLQBatch(eventName: string): Promise<number>;
|
|
395
|
+
/**
|
|
396
|
+
* Get Dead Letter Queue entries with optional filtering.
|
|
397
|
+
*
|
|
398
|
+
* @param filter - Filter options
|
|
399
|
+
* @returns Array of DLQ entries
|
|
400
|
+
*/
|
|
401
|
+
getDLQEntries(filter?: {
|
|
402
|
+
eventName?: string;
|
|
403
|
+
from?: number;
|
|
404
|
+
to?: number;
|
|
405
|
+
limit?: number;
|
|
406
|
+
}): import("@gravito/core").DLQEntry[];
|
|
407
|
+
/**
|
|
408
|
+
* Get count of Dead Letter Queue entries for an event.
|
|
409
|
+
*
|
|
410
|
+
* @param eventName - Event name
|
|
411
|
+
* @returns Count of entries
|
|
412
|
+
*/
|
|
413
|
+
getDLQCount(eventName: string): number;
|
|
414
|
+
/**
|
|
415
|
+
* Delete a DLQ entry.
|
|
416
|
+
*
|
|
417
|
+
* @param entryId - DLQ entry ID
|
|
418
|
+
* @returns True if deleted, false if not found
|
|
419
|
+
*/
|
|
420
|
+
deleteDLQEntry(entryId: string): boolean;
|
|
421
|
+
/**
|
|
422
|
+
* Get circuit breaker statistics for all events.
|
|
423
|
+
*
|
|
424
|
+
* @returns Array of circuit breaker statistics
|
|
425
|
+
*/
|
|
426
|
+
getCircuitBreakerStats(): Array<{
|
|
427
|
+
eventName: string;
|
|
428
|
+
state: string;
|
|
429
|
+
failureCount: number;
|
|
430
|
+
successCount: number;
|
|
431
|
+
lastFailureAt?: Date;
|
|
432
|
+
lastSuccessAt?: Date;
|
|
433
|
+
openedAt?: Date;
|
|
434
|
+
totalRequests: number;
|
|
435
|
+
totalFailures: number;
|
|
436
|
+
totalSuccesses: number;
|
|
437
|
+
}>;
|
|
438
|
+
/**
|
|
439
|
+
* Reset a circuit breaker for an event.
|
|
440
|
+
*
|
|
441
|
+
* @param eventName - Event name
|
|
442
|
+
* @returns True if reset, false if circuit breaker not found
|
|
443
|
+
*/
|
|
444
|
+
resetCircuitBreaker(eventName: string): boolean;
|
|
445
|
+
/**
|
|
446
|
+
* Remove all listeners for a specific action hook.
|
|
447
|
+
*
|
|
448
|
+
* @param hook - Hook name
|
|
449
|
+
*/
|
|
450
|
+
removeAction(hook: string): void;
|
|
451
|
+
/**
|
|
452
|
+
* Get the persistent DLQ manager instance.
|
|
453
|
+
*
|
|
454
|
+
* @returns DeadLetterQueueManager or undefined if not configured
|
|
455
|
+
* @public
|
|
456
|
+
*/
|
|
457
|
+
getPersistentDLQManager(): DeadLetterQueueManager | undefined;
|
|
458
|
+
/**
|
|
459
|
+
* Create a handler function for persistent DLQ.
|
|
460
|
+
* This handler is used by EventPriorityQueue to persist failed events.
|
|
461
|
+
*
|
|
462
|
+
* @returns Handler function
|
|
463
|
+
* @internal
|
|
464
|
+
*/
|
|
465
|
+
private createPersistentDLQHandler;
|
|
466
|
+
/**
|
|
467
|
+
* Requeue a failed event from the persistent DLQ.
|
|
468
|
+
*
|
|
469
|
+
* @param dlqId - DLQ entry UUID
|
|
470
|
+
* @returns True if requeued successfully
|
|
471
|
+
* @public
|
|
472
|
+
*/
|
|
473
|
+
requeuePersistentDLQEntry(dlqId: string): Promise<boolean>;
|
|
474
|
+
/**
|
|
475
|
+
* Requeue multiple events from persistent DLQ.
|
|
476
|
+
*
|
|
477
|
+
* @param filter - Filter criteria
|
|
478
|
+
* @returns Result statistics
|
|
479
|
+
* @public
|
|
480
|
+
*/
|
|
481
|
+
requeuePersistentDLQBatch(filter?: {
|
|
482
|
+
eventName?: string;
|
|
483
|
+
status?: 'pending' | 'requeued' | 'resolved' | 'abandoned';
|
|
484
|
+
}): Promise<{
|
|
485
|
+
total: number;
|
|
486
|
+
succeeded: number;
|
|
487
|
+
failed: number;
|
|
488
|
+
}>;
|
|
489
|
+
/**
|
|
490
|
+
* Get persistent DLQ statistics.
|
|
491
|
+
*
|
|
492
|
+
* @returns Statistics object with total, byEvent, and byStatus counts
|
|
493
|
+
* @public
|
|
494
|
+
*/
|
|
495
|
+
getPersistentDLQStats(): Promise<import("@gravito/core").DLQStats | undefined>;
|
|
84
496
|
}
|
|
@@ -125,7 +125,7 @@ export declare class Router {
|
|
|
125
125
|
path: string;
|
|
126
126
|
domain?: string;
|
|
127
127
|
}>;
|
|
128
|
-
private
|
|
128
|
+
private dispatcher;
|
|
129
129
|
private namedRoutes;
|
|
130
130
|
private bindings;
|
|
131
131
|
/**
|
|
@@ -268,10 +268,6 @@ export declare class Router {
|
|
|
268
268
|
* Internal Request Registration
|
|
269
269
|
*/
|
|
270
270
|
req(method: HttpMethod, path: string, requestOrHandlerOrMiddleware: FormRequestClass | RouteHandler | GravitoMiddleware | GravitoMiddleware[], handler?: RouteHandler, options?: RouteOptions): Route;
|
|
271
|
-
/**
|
|
272
|
-
* Resolve Controller Instance and Method
|
|
273
|
-
*/
|
|
274
|
-
private resolveControllerHandler;
|
|
275
271
|
}
|
|
276
272
|
/**
|
|
277
273
|
* Standard RESTful resource action names.
|
|
@@ -23,4 +23,5 @@ export declare class GravitoEngineAdapter<V extends GravitoVariables = GravitoVa
|
|
|
23
23
|
fetch: (request: Request, _server?: unknown) => Response | Promise<Response>;
|
|
24
24
|
warmup(paths: string[]): Promise<void>;
|
|
25
25
|
createContext(_request: Request): GravitoContext<V>;
|
|
26
|
+
useScoped(scope: string, path: string, ...middleware: GravitoMiddleware<V>[]): void;
|
|
26
27
|
}
|
|
@@ -136,6 +136,7 @@ export declare class PhotonAdapter<V extends GravitoVariables = GravitoVariables
|
|
|
136
136
|
routes(routes: RouteDefinition[]): void;
|
|
137
137
|
use(path: string, ...middleware: GravitoMiddleware<V>[]): void;
|
|
138
138
|
useGlobal(...middleware: GravitoMiddleware<V>[]): void;
|
|
139
|
+
useScoped(scope: string, path: string, ...middleware: GravitoMiddleware<V>[]): void;
|
|
139
140
|
mount(path: string, subAdapter: HttpAdapter<V>): void;
|
|
140
141
|
onError(handler: GravitoErrorHandler<V>): void;
|
|
141
142
|
onNotFound(handler: GravitoNotFoundHandler<V>): void;
|
|
@@ -17,6 +17,7 @@ export declare class BunNativeAdapter implements HttpAdapter {
|
|
|
17
17
|
routes(routes: RouteDefinition[]): void;
|
|
18
18
|
use(path: string, ...middleware: GravitoMiddleware[]): void;
|
|
19
19
|
useGlobal(...middleware: GravitoMiddleware[]): void;
|
|
20
|
+
useScoped(scope: string, path: string, ...middleware: GravitoMiddleware[]): void;
|
|
20
21
|
mount(path: string, subAdapter: HttpAdapter): void;
|
|
21
22
|
createContext(request: Request): GravitoContext;
|
|
22
23
|
onError(handler: GravitoErrorHandler): void;
|
|
@@ -115,6 +115,33 @@ export interface HttpAdapter<V extends GravitoVariables = GravitoVariables> {
|
|
|
115
115
|
* @param middleware - Middleware function
|
|
116
116
|
*/
|
|
117
117
|
useGlobal(...middleware: GravitoMiddleware<V>[]): void;
|
|
118
|
+
/**
|
|
119
|
+
* Register a scoped middleware for Orbit-level isolation
|
|
120
|
+
*
|
|
121
|
+
* Unlike regular `use()`, this method enforces stricter scoping rules:
|
|
122
|
+
* - REJECTS '*' wildcard paths (prevents global middleware in Orbits)
|
|
123
|
+
* - ENFORCES that all middleware paths must include the scope prefix
|
|
124
|
+
* - Throws error if attempting to register global middleware within an Orbit scope
|
|
125
|
+
*
|
|
126
|
+
* This is designed to prevent accidental middleware cross-contamination
|
|
127
|
+
* when multiple Orbits are mounted to a single PlanetCore instance.
|
|
128
|
+
*
|
|
129
|
+
* @param scope - The scope/path prefix (e.g., '/api', '/blog')
|
|
130
|
+
* @param path - Path pattern to match (cannot be '*')
|
|
131
|
+
* @param middleware - One or more middleware functions
|
|
132
|
+
* @throws {Error} If path is '*' when in Orbit scope
|
|
133
|
+
* @since 2.3.0
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* // Correct: Scoped to specific path
|
|
138
|
+
* adapter.useScoped('/api', '/users/*', authMiddleware)
|
|
139
|
+
*
|
|
140
|
+
* // Error: Cannot use wildcard in Orbit scope
|
|
141
|
+
* adapter.useScoped('/api', '*', loggerMiddleware)
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
useScoped(scope: string, path: string, ...middleware: GravitoMiddleware<V>[]): void;
|
|
118
145
|
/**
|
|
119
146
|
* Mount a sub-adapter at a path
|
|
120
147
|
*
|