@gravito/ripple 4.0.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/dist/atlas/src/DB.d.ts +51 -4
- package/dist/atlas/src/config/index.d.ts +1 -1
- package/dist/atlas/src/config/loadConfig.d.ts +0 -7
- package/dist/atlas/src/connection/Connection.d.ts +4 -0
- package/dist/atlas/src/connection/ConnectionManager.d.ts +75 -6
- package/dist/atlas/src/connection/ReplicaConnectionPool.d.ts +54 -0
- package/dist/atlas/src/drivers/MySQLDriver.d.ts +16 -3
- package/dist/atlas/src/drivers/PostgresDriver.d.ts +15 -2
- package/dist/atlas/src/index.d.ts +15 -3
- package/dist/atlas/src/observability/AtlasMetrics.d.ts +22 -0
- package/dist/atlas/src/orm/Repository.d.ts +247 -0
- package/dist/atlas/src/orm/index.d.ts +1 -0
- package/dist/atlas/src/orm/model/Model.d.ts +11 -2
- package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +14 -0
- package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +5 -0
- package/dist/atlas/src/orm/model/decorators.d.ts +29 -0
- package/dist/atlas/src/orm/model/index.d.ts +1 -1
- package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +1 -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/QueryBuilder.d.ts +71 -1
- package/dist/atlas/src/query/RelationshipResolver.d.ts +23 -0
- package/dist/atlas/src/schema/MigrationGenerator.d.ts +45 -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/sharding/ShardingManager.d.ts +59 -0
- package/dist/atlas/src/types/index.d.ts +83 -1
- package/dist/atlas/src/utils/CursorEncoding.d.ts +63 -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 +45 -0
- package/dist/core/src/ErrorHandler.d.ts +3 -0
- package/dist/core/src/HookManager.d.ts +95 -0
- package/dist/core/src/PlanetCore.d.ts +89 -0
- package/dist/core/src/RequestContext.d.ts +97 -0
- package/dist/core/src/ServiceProvider.d.ts +22 -0
- package/dist/core/src/adapters/PhotonAdapter.d.ts +4 -0
- package/dist/core/src/adapters/bun/BunContext.d.ts +4 -0
- package/dist/core/src/cli/queue-commands.d.ts +6 -0
- package/dist/core/src/engine/AOTRouter.d.ts +6 -1
- package/dist/core/src/engine/FastContext.d.ts +23 -0
- package/dist/core/src/engine/Gravito.d.ts +0 -1
- package/dist/core/src/engine/MinimalContext.d.ts +21 -0
- package/dist/core/src/engine/types.d.ts +3 -0
- 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/DeadLetterQueue.d.ts +75 -1
- package/dist/core/src/events/EventBackend.d.ts +2 -1
- package/dist/core/src/events/EventOptions.d.ts +99 -4
- package/dist/core/src/events/EventPriorityQueue.d.ts +105 -6
- package/dist/core/src/events/FlowControlStrategy.d.ts +109 -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 +11 -0
- package/dist/core/src/events/observability/OTelEventMetrics.d.ts +92 -0
- package/dist/core/src/events/observability/StreamWorkerMetrics.d.ts +76 -0
- package/dist/core/src/events/observability/index.d.ts +4 -0
- package/dist/core/src/events/types.d.ts +59 -0
- package/dist/core/src/health/HealthProvider.d.ts +67 -0
- package/dist/core/src/http/types.d.ts +19 -0
- package/dist/core/src/index.d.ts +13 -1
- 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 +34 -0
- package/dist/index.js +403 -40
- package/dist/index.js.map +11 -9
- package/dist/photon/src/index.d.ts +5 -0
- package/dist/photon/src/middleware/ratelimit-redis.d.ts +50 -0
- package/dist/photon/src/middleware/ratelimit.d.ts +4 -0
- package/dist/ripple/src/RippleServer.d.ts +0 -1
- 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 +4 -0
- package/dist/ripple/src/serializers/ISerializer.d.ts +1 -1
- package/dist/ripple/src/serializers/JsonSerializer.d.ts +1 -1
- package/dist/ripple/src/serializers/ProtobufSerializer.d.ts +6 -3
- package/dist/ripple/src/types.d.ts +11 -0
- package/package.json +3 -2
package/dist/atlas/src/DB.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type AtlasMetrics, type AtlasTracer } from './observability';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ShardingManager } from './sharding/ShardingManager';
|
|
3
|
+
import type { AtlasConfig, AtlasConnectionEntry, CacheInterface, ConnectionContract, QueryBuilderContract, QueryResult } from './types';
|
|
3
4
|
/**
|
|
4
5
|
* DB Facade - Static entry point for database operations.
|
|
5
6
|
*
|
|
@@ -24,12 +25,27 @@ import type { AtlasConfig, CacheInterface, ConnectionConfig, ConnectionContract,
|
|
|
24
25
|
*/
|
|
25
26
|
export declare class DB {
|
|
26
27
|
private static manager;
|
|
28
|
+
private static shardingManagers;
|
|
27
29
|
private static initialized;
|
|
28
30
|
private static cache;
|
|
29
31
|
private static _debug;
|
|
30
32
|
private static _queryLog;
|
|
31
33
|
private static readonly MAX_LOG_SIZE;
|
|
32
34
|
private static queryListener?;
|
|
35
|
+
/**
|
|
36
|
+
* Registers a ShardingManager for distributed database architectures.
|
|
37
|
+
*
|
|
38
|
+
* @param name - Unique identifier for the sharding cluster
|
|
39
|
+
* @param manager - The initialized ShardingManager instance
|
|
40
|
+
*/
|
|
41
|
+
static addShardingManager(name: string, manager: ShardingManager): void;
|
|
42
|
+
/**
|
|
43
|
+
* Retrieves a registered ShardingManager.
|
|
44
|
+
*
|
|
45
|
+
* @param name - Name of the sharding cluster (defaults to 'default')
|
|
46
|
+
* @throws Error if the manager is not found
|
|
47
|
+
*/
|
|
48
|
+
static getShardingManager(name?: string): ShardingManager;
|
|
33
49
|
/**
|
|
34
50
|
* Sets the global cache provider for query results.
|
|
35
51
|
*
|
|
@@ -165,9 +181,9 @@ export declare class DB {
|
|
|
165
181
|
* Manually adds a connection to the manager.
|
|
166
182
|
*
|
|
167
183
|
* @param name - Unique connection name.
|
|
168
|
-
* @param config - Connection settings.
|
|
184
|
+
* @param config - Connection settings (standard or read/write replica).
|
|
169
185
|
*/
|
|
170
|
-
static addConnection(name: string, config:
|
|
186
|
+
static addConnection(name: string, config: AtlasConnectionEntry): void;
|
|
171
187
|
/**
|
|
172
188
|
* Adds a connection configured via prefixed environment variables.
|
|
173
189
|
*
|
|
@@ -193,6 +209,23 @@ export declare class DB {
|
|
|
193
209
|
* @throws {Error} If DB is not configured or connection name is unknown.
|
|
194
210
|
*/
|
|
195
211
|
static connection(name?: string): ConnectionContract;
|
|
212
|
+
/**
|
|
213
|
+
* Retrieves the read replica connection for the given connection name.
|
|
214
|
+
*
|
|
215
|
+
* Uses round-robin selection across configured read replicas.
|
|
216
|
+
* Falls back to the primary connection if no replicas are configured.
|
|
217
|
+
*
|
|
218
|
+
* @param name - Connection name (defaults to global default)
|
|
219
|
+
*/
|
|
220
|
+
static readConnection(name?: string): ConnectionContract;
|
|
221
|
+
/**
|
|
222
|
+
* Retrieves the write (primary) connection for the given connection name.
|
|
223
|
+
*
|
|
224
|
+
* Use this to force a query to run on the primary even inside a read context.
|
|
225
|
+
*
|
|
226
|
+
* @param name - Connection name (defaults to global default)
|
|
227
|
+
*/
|
|
228
|
+
static writeConnection(name?: string): ConnectionContract;
|
|
196
229
|
/**
|
|
197
230
|
* Checks if a specific connection has been configured.
|
|
198
231
|
*/
|
|
@@ -204,7 +237,7 @@ export declare class DB {
|
|
|
204
237
|
/**
|
|
205
238
|
* Retrieves the raw configuration for a connection.
|
|
206
239
|
*/
|
|
207
|
-
static getConnectionConfig(name?: string):
|
|
240
|
+
static getConnectionConfig(name?: string): AtlasConnectionEntry | undefined;
|
|
208
241
|
/**
|
|
209
242
|
* Initializes a fluent query builder for a specific table.
|
|
210
243
|
*
|
|
@@ -243,6 +276,20 @@ export declare class DB {
|
|
|
243
276
|
* @returns The callback's return value.
|
|
244
277
|
*/
|
|
245
278
|
static transaction<T>(callback: (connection: ConnectionContract) => Promise<T>, connectionName?: string): Promise<T>;
|
|
279
|
+
/**
|
|
280
|
+
* Executes logic within a managed database transaction with automatic retry on serialization/stale data failures.
|
|
281
|
+
*
|
|
282
|
+
* Particularly useful for high-concurrency environments utilizing optimistic locking,
|
|
283
|
+
* where `StaleModelError` is thrown due to concurrent writes.
|
|
284
|
+
*
|
|
285
|
+
* @template T - Logic result type.
|
|
286
|
+
* @param callback - The transactional logic.
|
|
287
|
+
* @param connectionName - Optional specific connection.
|
|
288
|
+
* @param maxRetries - Maximum number of retries (default: 5).
|
|
289
|
+
* @returns The callback's return value.
|
|
290
|
+
* @throws Rethrows the error if max retries are exceeded.
|
|
291
|
+
*/
|
|
292
|
+
static transactionWithRetry<T>(callback: (connection: ConnectionContract, attempt: number) => Promise<T>, connectionName?: string, maxRetries?: number): Promise<T>;
|
|
246
293
|
/**
|
|
247
294
|
* Manually starts a database transaction.
|
|
248
295
|
*
|
|
@@ -39,10 +39,3 @@ export declare function loadConfig(options?: {
|
|
|
39
39
|
useEnv?: boolean;
|
|
40
40
|
envPrefix?: string;
|
|
41
41
|
}): Promise<AtlasConfig>;
|
|
42
|
-
/**
|
|
43
|
-
* Auto-configure database from config file or environment
|
|
44
|
-
* This is a convenience function that tries config file first, then environment
|
|
45
|
-
*
|
|
46
|
-
* @param configPath - Optional path to config file
|
|
47
|
-
*/
|
|
48
|
-
export declare function autoConfigure(configPath?: string): Promise<void>;
|
|
@@ -52,6 +52,10 @@ export declare class Connection implements ConnectionContract {
|
|
|
52
52
|
* Get the tracer
|
|
53
53
|
*/
|
|
54
54
|
getTracer(): AtlasTracer | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Get the metrics
|
|
57
|
+
*/
|
|
58
|
+
getMetrics(): AtlasMetrics | undefined;
|
|
55
59
|
/**
|
|
56
60
|
* Create a new query builder for a table
|
|
57
61
|
*/
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
* Connection Manager
|
|
3
3
|
* @description Manages multiple database connections
|
|
4
4
|
*/
|
|
5
|
-
import type
|
|
5
|
+
import { type AdaptivePoolConfig, AdaptivePoolManager } from '../pool/AdaptivePoolManager';
|
|
6
|
+
import { type PoolHealthCheckConfig } from '../pool/PoolHealthChecker';
|
|
7
|
+
import { type PoolWarmerConfig } from '../pool/PoolWarmer';
|
|
8
|
+
import type { AtlasConnectionEntry, ConnectionContract, PoolHealth } from '../types';
|
|
6
9
|
/**
|
|
7
10
|
* Connection Manager
|
|
8
11
|
*
|
|
@@ -19,9 +22,14 @@ export declare class ConnectionManager {
|
|
|
19
22
|
private defaultConnectionName;
|
|
20
23
|
private lastUsed;
|
|
21
24
|
private cleanupInterval?;
|
|
25
|
+
private healthChecker?;
|
|
26
|
+
private warmer?;
|
|
27
|
+
private adaptiveManager?;
|
|
28
|
+
/** Replica pools keyed by connection name */
|
|
29
|
+
private replicaPools;
|
|
22
30
|
private readonly MAX_IDLE_TIME;
|
|
23
31
|
private readonly CLEANUP_INTERVAL;
|
|
24
|
-
constructor(configs?: Record<string,
|
|
32
|
+
constructor(configs?: Record<string, AtlasConnectionEntry>);
|
|
25
33
|
/**
|
|
26
34
|
* Get a connection instance by name.
|
|
27
35
|
* If the connection is not already initialized, it will be created.
|
|
@@ -31,13 +39,41 @@ export declare class ConnectionManager {
|
|
|
31
39
|
* @throws Error if the connection is not configured.
|
|
32
40
|
*/
|
|
33
41
|
connection(name?: string): ConnectionContract;
|
|
42
|
+
/**
|
|
43
|
+
* Get the read replica connection for a named connection.
|
|
44
|
+
* Returns the round-robin selected read replica, or the write connection
|
|
45
|
+
* if no replicas are configured.
|
|
46
|
+
*
|
|
47
|
+
* @param name - Connection name (defaults to default)
|
|
48
|
+
*/
|
|
49
|
+
readConnection(name?: string): ConnectionContract;
|
|
50
|
+
/**
|
|
51
|
+
* Get the write (primary) connection for a named connection.
|
|
52
|
+
*
|
|
53
|
+
* @param name - Connection name (defaults to default)
|
|
54
|
+
*/
|
|
55
|
+
writeConnection(name?: string): ConnectionContract;
|
|
56
|
+
/**
|
|
57
|
+
* Check whether a given connection has read replicas.
|
|
58
|
+
*/
|
|
59
|
+
hasReplicas(name?: string): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Build and register a Connection instance, wrapping it in a Proxy.
|
|
62
|
+
* @internal
|
|
63
|
+
*/
|
|
64
|
+
private _buildAndRegisterConnection;
|
|
65
|
+
/**
|
|
66
|
+
* Build a proxy-wrapped Connection from config without registering.
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
private _buildConnection;
|
|
34
70
|
/**
|
|
35
71
|
* Add a connection configuration.
|
|
36
72
|
*
|
|
37
73
|
* @param name - Unique name for the connection.
|
|
38
|
-
* @param config - Connection configuration settings.
|
|
74
|
+
* @param config - Connection configuration settings (standard or read/write replica).
|
|
39
75
|
*/
|
|
40
|
-
addConnection(name: string, config:
|
|
76
|
+
addConnection(name: string, config: AtlasConnectionEntry): void;
|
|
41
77
|
/**
|
|
42
78
|
* Set the default connection name.
|
|
43
79
|
*
|
|
@@ -69,7 +105,7 @@ export declare class ConnectionManager {
|
|
|
69
105
|
* @param name - The connection name.
|
|
70
106
|
* @returns The connection configuration or undefined if not found.
|
|
71
107
|
*/
|
|
72
|
-
getConfig(name: string):
|
|
108
|
+
getConfig(name: string): AtlasConnectionEntry | undefined;
|
|
73
109
|
/**
|
|
74
110
|
* Disconnect all active connections.
|
|
75
111
|
*
|
|
@@ -101,9 +137,42 @@ export declare class ConnectionManager {
|
|
|
101
137
|
private cleanupIdleConnections;
|
|
102
138
|
private startCleanup;
|
|
103
139
|
stopCleanup(): void;
|
|
140
|
+
/**
|
|
141
|
+
* Enable connection pool health checking
|
|
142
|
+
*/
|
|
143
|
+
enableHealthCheck(config?: Partial<PoolHealthCheckConfig>): void;
|
|
144
|
+
/**
|
|
145
|
+
* Disable connection pool health checking
|
|
146
|
+
*/
|
|
147
|
+
disableHealthCheck(): void;
|
|
148
|
+
/**
|
|
149
|
+
* Get connection pool health status
|
|
150
|
+
*/
|
|
151
|
+
getHealthStatus(connectionName?: string): PoolHealth | Map<string, PoolHealth>;
|
|
152
|
+
/**
|
|
153
|
+
* Enable connection pool warming
|
|
154
|
+
*/
|
|
155
|
+
enableWarmup(config?: Partial<PoolWarmerConfig>): void;
|
|
156
|
+
/**
|
|
157
|
+
* Warm up all connection pools
|
|
158
|
+
*/
|
|
159
|
+
warmup(): Promise<any>;
|
|
160
|
+
/**
|
|
161
|
+
* Enable adaptive connection pool management
|
|
162
|
+
* Automatically adjusts pool sizes based on load patterns
|
|
163
|
+
*/
|
|
164
|
+
enableAdaptive(config?: Partial<AdaptivePoolConfig>): void;
|
|
165
|
+
/**
|
|
166
|
+
* Disable adaptive connection pool management
|
|
167
|
+
*/
|
|
168
|
+
disableAdaptive(): void;
|
|
169
|
+
/**
|
|
170
|
+
* Get adaptive pool manager instance (if enabled)
|
|
171
|
+
*/
|
|
172
|
+
getAdaptiveManager(): AdaptivePoolManager | undefined;
|
|
104
173
|
/**
|
|
105
174
|
* Shutdown the connection manager.
|
|
106
|
-
* Stops the idle cleanup interval and disconnects all connections.
|
|
175
|
+
* Stops the idle cleanup interval, health checking, adaptive management, and disconnects all connections.
|
|
107
176
|
*
|
|
108
177
|
* @returns A promise that resolves when shutdown is complete.
|
|
109
178
|
*/
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/atlas - Replica Connection Pool
|
|
3
|
+
* @description Manages read/write replica connections with Round-robin load balancing.
|
|
4
|
+
*
|
|
5
|
+
* Wraps a write (primary) connection and a pool of read (replica) connections.
|
|
6
|
+
* Transparently routes SELECT queries to read replicas and mutations to the primary.
|
|
7
|
+
*/
|
|
8
|
+
import type { ConnectionContract } from '../types';
|
|
9
|
+
/**
|
|
10
|
+
* ReplicaConnectionPool
|
|
11
|
+
*
|
|
12
|
+
* Holds one authoritative write connection and N read replica connections.
|
|
13
|
+
* Applies Round-robin selection across replicas to balance read load.
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const pool = new ReplicaConnectionPool(writeConn, [replica1, replica2])
|
|
18
|
+
* const readConn = pool.getReadConnection() // Round-robin
|
|
19
|
+
* const writeConn = pool.getWriteConnection() // Always primary
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class ReplicaConnectionPool {
|
|
23
|
+
private readonly writeConnection;
|
|
24
|
+
private readonly readConnections;
|
|
25
|
+
private roundRobinIndex;
|
|
26
|
+
constructor(writeConnection: ConnectionContract, readConnections?: ConnectionContract[]);
|
|
27
|
+
/**
|
|
28
|
+
* Get the primary write connection (always the same node).
|
|
29
|
+
*/
|
|
30
|
+
getWriteConnection(): ConnectionContract;
|
|
31
|
+
/**
|
|
32
|
+
* Get a read replica connection using Round-robin selection.
|
|
33
|
+
*
|
|
34
|
+
* Falls back to the write connection if no replicas are configured.
|
|
35
|
+
*/
|
|
36
|
+
getReadConnection(): ConnectionContract;
|
|
37
|
+
/**
|
|
38
|
+
* Whether this pool has any read replicas configured.
|
|
39
|
+
*/
|
|
40
|
+
hasReplicas(): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Total number of replica connections in the pool.
|
|
43
|
+
*/
|
|
44
|
+
replicaCount(): number;
|
|
45
|
+
/**
|
|
46
|
+
* Disconnect all connections (write + all replicas).
|
|
47
|
+
*/
|
|
48
|
+
disconnectAll(): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Reset round-robin index (useful for testing).
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
_resetIndex(): void;
|
|
54
|
+
}
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* MySQL/MariaDB Driver
|
|
3
3
|
* @description Database driver for MySQL and MariaDB using mysql2 package
|
|
4
4
|
*/
|
|
5
|
-
import type { ConnectionConfig, DriverContract, DriverType, ExecuteResult, QueryResult } from '../types';
|
|
5
|
+
import type { ConnectionConfig, DriverContract, DriverType, ExecuteResult, PoolHealth, PoolStats, QueryResult } from '../types';
|
|
6
6
|
export declare class MySQLDriver implements DriverContract {
|
|
7
|
-
private readonly config;
|
|
8
|
-
private readonly driverType;
|
|
9
7
|
private pool;
|
|
10
8
|
private transactionConnection;
|
|
11
9
|
private connected;
|
|
12
10
|
private mysql;
|
|
11
|
+
private poolConfig;
|
|
12
|
+
private readonly driverType;
|
|
13
13
|
constructor(config: ConnectionConfig, driverType?: 'mysql' | 'mariadb');
|
|
14
14
|
/**
|
|
15
15
|
* Get the driver name
|
|
@@ -55,6 +55,19 @@ export declare class MySQLDriver implements DriverContract {
|
|
|
55
55
|
* Check if in transaction
|
|
56
56
|
*/
|
|
57
57
|
inTransaction(): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Get connection pool statistics
|
|
60
|
+
*/
|
|
61
|
+
getPoolStats(): PoolStats | null;
|
|
62
|
+
/**
|
|
63
|
+
* Get connection pool health status
|
|
64
|
+
*/
|
|
65
|
+
getPoolHealth(): PoolHealth;
|
|
66
|
+
/**
|
|
67
|
+
* Adjust the connection pool size
|
|
68
|
+
* Note: mysql2 Pool doesn't support dynamic resizing, so we reconnect with new size
|
|
69
|
+
*/
|
|
70
|
+
adjustPoolSize(targetSize: number): Promise<void>;
|
|
58
71
|
/**
|
|
59
72
|
* Get a connection from the pool
|
|
60
73
|
*/
|
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
* PostgreSQL Driver
|
|
3
3
|
* @description Database driver implementation for PostgreSQL using node-pg
|
|
4
4
|
*/
|
|
5
|
-
import type { DriverContract, DriverType, ExecuteResult, PostgresConfig, QueryResult } from '../types';
|
|
5
|
+
import type { DriverContract, DriverType, ExecuteResult, PoolHealth, PoolStats, PostgresConfig, QueryResult } from '../types';
|
|
6
6
|
/**
|
|
7
7
|
* PostgreSQL Driver
|
|
8
8
|
* Connects and executes queries against PostgreSQL databases
|
|
9
9
|
*/
|
|
10
10
|
export declare class PostgresDriver implements DriverContract {
|
|
11
|
-
private readonly config;
|
|
12
11
|
private pool;
|
|
13
12
|
private connected;
|
|
14
13
|
private transactionActive;
|
|
15
14
|
private transactionClient;
|
|
16
15
|
private preparedStatements;
|
|
17
16
|
private statementCounter;
|
|
17
|
+
private poolConfig;
|
|
18
18
|
constructor(config: PostgresConfig);
|
|
19
19
|
/**
|
|
20
20
|
* Get driver name
|
|
@@ -68,6 +68,19 @@ export declare class PostgresDriver implements DriverContract {
|
|
|
68
68
|
* Check if currently in a transaction
|
|
69
69
|
*/
|
|
70
70
|
inTransaction(): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Get connection pool statistics
|
|
73
|
+
*/
|
|
74
|
+
getPoolStats(): PoolStats | null;
|
|
75
|
+
/**
|
|
76
|
+
* Get connection pool health status
|
|
77
|
+
*/
|
|
78
|
+
getPoolHealth(): PoolHealth;
|
|
79
|
+
/**
|
|
80
|
+
* Adjust the connection pool size
|
|
81
|
+
* Note: pg Pool doesn't support dynamic resizing, so we reconnect with new size
|
|
82
|
+
*/
|
|
83
|
+
adjustPoolSize(targetSize: number): Promise<void>;
|
|
71
84
|
/**
|
|
72
85
|
* Get a client for executing queries
|
|
73
86
|
*/
|
|
@@ -42,10 +42,13 @@
|
|
|
42
42
|
* ```
|
|
43
43
|
*/
|
|
44
44
|
export type { AtlasConfig } from './config';
|
|
45
|
-
export {
|
|
45
|
+
export { defineConfig, fromEnv, loadConfig, loadConfigFile } from './config';
|
|
46
46
|
export { Connection } from './connection/Connection';
|
|
47
47
|
export { ConnectionManager } from './connection/ConnectionManager';
|
|
48
|
+
export { ReplicaConnectionPool } from './connection/ReplicaConnectionPool';
|
|
48
49
|
export { DB } from './DB';
|
|
50
|
+
import { DB } from './DB';
|
|
51
|
+
export declare const autoConfigure: typeof DB.autoConfigure;
|
|
49
52
|
export { BunSQLDriver } from './drivers/BunSQLDriver';
|
|
50
53
|
export { PostgresDriver } from './drivers/PostgresDriver';
|
|
51
54
|
export { SQLiteDriver } from './drivers/SQLiteDriver';
|
|
@@ -56,12 +59,21 @@ export type { Migration, MigrationFile, MigrationRecord, MigrationResult, Migrat
|
|
|
56
59
|
export { MigrationRepository, Migrator } from './migration';
|
|
57
60
|
export { OrbitAtlas } from './OrbitAtlas';
|
|
58
61
|
export type { ColumnSchema as OrmColumnSchema, ModelAttributes, ModelConstructor, ModelStatic, RelationshipMeta, RelationType, SchemaLock, SchemaMode, SchemaRegistryOptions, TableSchema, } from './orm';
|
|
59
|
-
export { BelongsTo, BelongsToMany, ColumnNotFoundError, column, DirtyTracker, eagerLoad, eagerLoadMany, getRelationships, HasMany, HasOne, Model, ModelNotFoundError, ModelRegistry, MorphMany, MorphOne, MorphTo, NullableConstraintError, SchemaRegistry, SchemaSniffer, SoftDeletes, TypeMismatchError, version, } from './orm';
|
|
62
|
+
export { BelongsTo, BelongsToMany, ColumnNotFoundError, column, DirtyTracker, eagerLoad, eagerLoadMany, getRelationships, HasMany, HasOne, Model, ModelNotFoundError, ModelRegistry, ModelRepository, MorphMany, MorphOne, MorphTo, NullableConstraintError, SchemaRegistry, SchemaSniffer, SoftDeletes, TypeMismatchError, version, } from './orm';
|
|
60
63
|
export { Expression, raw } from './query/Expression';
|
|
61
64
|
export { QueryBuilder, QueryBuilderError, RecordNotFoundError } from './query/QueryBuilder';
|
|
62
65
|
export type { ColumnType, ForeignKeyAction, ForeignKeyDefinition, IndexDefinition } from './schema';
|
|
63
66
|
export { Blueprint, ColumnDefinition, Schema } from './schema';
|
|
64
67
|
export { MySQLSchemaGrammar, PostgresSchemaGrammar, SchemaGrammar, SQLiteSchemaGrammar, } from './schema/grammars';
|
|
68
|
+
export { MigrationGenerator } from './schema/MigrationGenerator';
|
|
69
|
+
export type { ColumnDefinition as SchemaColumnDefinition, SchemaDiffResult, } from './schema/SchemaDiff';
|
|
70
|
+
export { SchemaDiff } from './schema/SchemaDiff';
|
|
71
|
+
export type { ModelTypeMap, TypeGeneratorOptions } from './schema/TypeGenerator';
|
|
72
|
+
export { TypeGenerator } from './schema/TypeGenerator';
|
|
73
|
+
export { TypeWriter } from './schema/TypeWriter';
|
|
65
74
|
export type { FactoryDefinition, Seeder, SeederFile, SeederRunnerOptions } from './seed';
|
|
66
75
|
export { Factory, factory, SeederRunner } from './seed';
|
|
67
|
-
export
|
|
76
|
+
export { type ShardingConfig, ShardingManager } from './sharding/ShardingManager';
|
|
77
|
+
export type { AtlasConnectionEntry, BooleanOperator, CompiledQuery, ConnectionConfig, ConnectionContract, CursorPaginateResult, DriverContract, DriverType, ExecuteResult, FieldInfo, GrammarContract, HavingClause, isReadWriteConfig, JoinClause, JoinType, MySQLConfig, Operator, OrderClause, OrderDirection, PaginateResult, PoolConfig, PostgresConfig, QueryBuilderContract, QueryResult, ReadWriteConnectionConfig, SQLiteConfig, SSLConfig, WhereClause, } from './types';
|
|
78
|
+
export type { CursorPayload } from './utils/CursorEncoding';
|
|
79
|
+
export { buildCursorWhereClause, decodeCursor, encodeCursor, } from './utils/CursorEncoding';
|
|
@@ -5,7 +5,29 @@ export interface AtlasMetricsConfig {
|
|
|
5
5
|
export declare class AtlasMetrics {
|
|
6
6
|
private meter;
|
|
7
7
|
private config;
|
|
8
|
+
private poolCallbacks;
|
|
8
9
|
readonly operationDuration?: Histogram;
|
|
9
10
|
readonly operationErrors?: Counter;
|
|
11
|
+
readonly poolSize?: any;
|
|
12
|
+
readonly poolUtilization?: any;
|
|
13
|
+
readonly poolWaitTime?: Histogram;
|
|
14
|
+
readonly poolAcquisitionErrors?: Counter;
|
|
10
15
|
constructor(config: AtlasMetricsConfig);
|
|
16
|
+
/**
|
|
17
|
+
* Register pool statistics callback for ObservableGauge
|
|
18
|
+
*/
|
|
19
|
+
registerPoolStatsCallback(connectionName: string, getStats: () => {
|
|
20
|
+
idle: number;
|
|
21
|
+
active: number;
|
|
22
|
+
pending: number;
|
|
23
|
+
max: number;
|
|
24
|
+
} | null): void;
|
|
25
|
+
/**
|
|
26
|
+
* Record connection wait time
|
|
27
|
+
*/
|
|
28
|
+
recordConnectionWaitTime(connectionName: string, duration: number): void;
|
|
29
|
+
/**
|
|
30
|
+
* Record connection acquisition error
|
|
31
|
+
*/
|
|
32
|
+
recordConnectionAcquisitionError(connectionName: string, error: string): void;
|
|
11
33
|
}
|