@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
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import type { QueryBuilderContract } from '../types';
|
|
2
|
+
import type { Model, ModelStatic } from './model/Model';
|
|
3
|
+
/**
|
|
4
|
+
* ModelRepository - Base Repository for Active Record Models
|
|
5
|
+
*
|
|
6
|
+
* Provides a collection-like interface for accessing and persisting domain models.
|
|
7
|
+
* Extends the Active Record pattern with common repository operations.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of Model managed by this repository
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* class UserRepository extends ModelRepository<User> {
|
|
14
|
+
* protected modelClass = User
|
|
15
|
+
*
|
|
16
|
+
* async findByEmail(email: string): Promise<User | null> {
|
|
17
|
+
* return this.findWhere('email', email)
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* async findActive(): Promise<User[]> {
|
|
21
|
+
* return this.query().where('is_active', true).get()
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* // Usage
|
|
26
|
+
* const userRepo = new UserRepository()
|
|
27
|
+
* const user = await userRepo.find(1)
|
|
28
|
+
* const active = await userRepo.findActive()
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
* @since 3.0.0
|
|
33
|
+
*/
|
|
34
|
+
export declare abstract class ModelRepository<T extends Model> {
|
|
35
|
+
/**
|
|
36
|
+
* The model class this repository manages.
|
|
37
|
+
* Must be set by subclasses.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* class UserRepository extends ModelRepository<User> {
|
|
42
|
+
* protected modelClass = User
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
protected abstract modelClass: ModelStatic<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Get a query builder for this model.
|
|
49
|
+
*
|
|
50
|
+
* @returns A new query builder instance
|
|
51
|
+
*/
|
|
52
|
+
protected query(): QueryBuilderContract<T>;
|
|
53
|
+
/**
|
|
54
|
+
* Retrieve all records from the database.
|
|
55
|
+
*
|
|
56
|
+
* @returns Promise resolving to array of all model instances
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const users = await userRepository.all()
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
all(): Promise<T[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Find a single record by its primary key.
|
|
66
|
+
*
|
|
67
|
+
* @param id - The primary key value
|
|
68
|
+
* @returns Promise resolving to the model instance or null if not found
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const user = await userRepository.find(1)
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
find(id: unknown): Promise<T | null>;
|
|
76
|
+
/**
|
|
77
|
+
* Find a single record by its primary key or throw an error.
|
|
78
|
+
*
|
|
79
|
+
* @param id - The primary key value
|
|
80
|
+
* @returns Promise resolving to the model instance
|
|
81
|
+
* @throws ModelNotFoundError if not found
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const user = await userRepository.findOrFail(1)
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
findOrFail(id: unknown): Promise<T>;
|
|
89
|
+
/**
|
|
90
|
+
* Find a single record matching a where clause.
|
|
91
|
+
*
|
|
92
|
+
* @param column - The column name
|
|
93
|
+
* @param value - The value to match
|
|
94
|
+
* @returns Promise resolving to the model instance or null if not found
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const user = await userRepository.findWhere('email', 'john@example.com')
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
findWhere(column: string, value: unknown): Promise<T | null>;
|
|
102
|
+
/**
|
|
103
|
+
* Find multiple records matching a where clause.
|
|
104
|
+
*
|
|
105
|
+
* @param column - The column name
|
|
106
|
+
* @param value - The value to match
|
|
107
|
+
* @returns Promise resolving to array of model instances
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const admins = await userRepository.findManyWhere('role', 'admin')
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
findManyWhere(column: string, value: unknown): Promise<T[]>;
|
|
115
|
+
/**
|
|
116
|
+
* Find records using a callback for complex queries.
|
|
117
|
+
*
|
|
118
|
+
* @param callback - Function that receives the query builder
|
|
119
|
+
* @returns Promise resolving to array of model instances
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const result = await userRepository.findWhere(q =>
|
|
124
|
+
* q.where('role', 'admin').where('is_active', true)
|
|
125
|
+
* )
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
findByQuery(callback: (query: QueryBuilderContract<T>) => QueryBuilderContract<T>): Promise<T[]>;
|
|
129
|
+
/**
|
|
130
|
+
* Find a single record using a callback for complex queries.
|
|
131
|
+
*
|
|
132
|
+
* @param callback - Function that receives the query builder
|
|
133
|
+
* @returns Promise resolving to the model instance or null if not found
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* const user = await userRepository.findOneByQuery(q =>
|
|
138
|
+
* q.where('email', email).where('is_active', true)
|
|
139
|
+
* )
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
findOneByQuery(callback: (query: QueryBuilderContract<T>) => QueryBuilderContract<T>): Promise<T | null>;
|
|
143
|
+
/**
|
|
144
|
+
* Create a new record in the database.
|
|
145
|
+
*
|
|
146
|
+
* @param attributes - Object containing model attributes
|
|
147
|
+
* @returns Promise resolving to the created model instance
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* const user = await userRepository.create({
|
|
152
|
+
* name: 'John Doe',
|
|
153
|
+
* email: 'john@example.com'
|
|
154
|
+
* })
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
create(attributes: Partial<T>): Promise<T>;
|
|
158
|
+
/**
|
|
159
|
+
* Update an existing record by its primary key.
|
|
160
|
+
*
|
|
161
|
+
* @param id - The primary key value
|
|
162
|
+
* @param attributes - Object containing attributes to update
|
|
163
|
+
* @returns Promise resolving to the updated model instance
|
|
164
|
+
* @throws ModelNotFoundError if record not found
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* const user = await userRepository.update(1, { name: 'Jane Doe' })
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
update(id: unknown, attributes: Partial<T>): Promise<T>;
|
|
172
|
+
/**
|
|
173
|
+
* Delete a record by its primary key.
|
|
174
|
+
*
|
|
175
|
+
* @param id - The primary key value
|
|
176
|
+
* @returns Promise that resolves when deletion is complete
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* await userRepository.delete(1)
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
delete(id: unknown): Promise<void>;
|
|
184
|
+
/**
|
|
185
|
+
* Check if a record exists by its primary key.
|
|
186
|
+
*
|
|
187
|
+
* @param id - The primary key value
|
|
188
|
+
* @returns Promise resolving to true if exists, false otherwise
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* const exists = await userRepository.exists(1)
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
exists(id: unknown): Promise<boolean>;
|
|
196
|
+
/**
|
|
197
|
+
* Count the total number of records.
|
|
198
|
+
*
|
|
199
|
+
* @returns Promise resolving to the count
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* const total = await userRepository.count()
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
count(): Promise<number>;
|
|
207
|
+
/**
|
|
208
|
+
* Paginate records.
|
|
209
|
+
*
|
|
210
|
+
* @param page - The page number (1-indexed)
|
|
211
|
+
* @param perPage - The number of records per page
|
|
212
|
+
* @returns Promise resolving to pagination result
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```typescript
|
|
216
|
+
* const result = await userRepository.paginate(1, 20)
|
|
217
|
+
* // result.data: T[]
|
|
218
|
+
* // result.total: number
|
|
219
|
+
* // result.per_page: number
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
paginate(page?: number, perPage?: number): Promise<import("..").PaginateResult<T>>;
|
|
223
|
+
/**
|
|
224
|
+
* Restore soft-deleted records (requires SoftDeletes mixin on model).
|
|
225
|
+
*
|
|
226
|
+
* @param id - The primary key value
|
|
227
|
+
* @returns Promise that resolves when restoration is complete
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* await userRepository.restore(1)
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
restore(id: unknown): Promise<void>;
|
|
235
|
+
/**
|
|
236
|
+
* Permanently delete a soft-deleted record (requires SoftDeletes mixin on model).
|
|
237
|
+
*
|
|
238
|
+
* @param id - The primary key value
|
|
239
|
+
* @returns Promise that resolves when permanent deletion is complete
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```typescript
|
|
243
|
+
* await userRepository.forceDelete(1)
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
forceDelete(id: unknown): Promise<void>;
|
|
247
|
+
}
|
|
@@ -26,7 +26,8 @@ export interface ModelStatic<T extends Model> {
|
|
|
26
26
|
findOrFail(key: unknown): Promise<T>;
|
|
27
27
|
all(): Promise<T[]>;
|
|
28
28
|
create(attributes?: Partial<ModelAttributes>): Promise<T>;
|
|
29
|
-
query(): QueryBuilderContract<T>;
|
|
29
|
+
query(connection?: import('../../types').ConnectionContract): QueryBuilderContract<T>;
|
|
30
|
+
shard(key: string | number): QueryBuilderContract<T>;
|
|
30
31
|
where(column: string | Record<string, unknown>, operatorOrValue?: Operator | unknown, value?: unknown): QueryBuilderContract<T>;
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
@@ -370,11 +371,19 @@ export declare abstract class Model {
|
|
|
370
371
|
* @yields Chunks of model instances.
|
|
371
372
|
*/
|
|
372
373
|
static cursor<T extends Model>(this: ModelConstructor<T> & typeof Model, chunkSize?: number): AsyncGenerator<T[], void, unknown>;
|
|
374
|
+
/**
|
|
375
|
+
* Initializes a fluent query builder for the model on a specific sharded connection.
|
|
376
|
+
*
|
|
377
|
+
* @param key - The shard distribution key
|
|
378
|
+
* @returns A proxied query builder instance connected to the right shard.
|
|
379
|
+
*/
|
|
380
|
+
static shard<T extends Model>(this: ModelConstructor<T> & typeof Model, key: string | number): import('../../types').QueryBuilderContract<T>;
|
|
373
381
|
/**
|
|
374
382
|
* Initializes a fluent query builder for the model.
|
|
375
383
|
*
|
|
376
384
|
* Automatically handles model hydration, soft delete filtering, and scope application.
|
|
377
385
|
*
|
|
386
|
+
* @param connectionContract - Optional specific database connection
|
|
378
387
|
* @returns A proxied query builder instance.
|
|
379
388
|
*
|
|
380
389
|
* @example
|
|
@@ -382,7 +391,7 @@ export declare abstract class Model {
|
|
|
382
391
|
* const users = await User.query().where('active', true).get();
|
|
383
392
|
* ```
|
|
384
393
|
*/
|
|
385
|
-
static query<T extends Model>(this: ModelConstructor<T> & typeof Model): QueryBuilderContract<T>;
|
|
394
|
+
static query<T extends Model>(this: ModelConstructor<T> & typeof Model, connectionContract?: import('../../types').ConnectionContract): QueryBuilderContract<T>;
|
|
386
395
|
/**
|
|
387
396
|
* Starts a query with a standard WHERE clause.
|
|
388
397
|
*
|
|
@@ -6,6 +6,20 @@ export type ModelAttributes = Record<string, unknown>;
|
|
|
6
6
|
* @description Provides attribute management functionality including getting/setting, casting, and dirty tracking.
|
|
7
7
|
*/
|
|
8
8
|
export declare class HasAttributes {
|
|
9
|
+
/**
|
|
10
|
+
* Static schema registry for JIT validation.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
static schemaRegistry?: any;
|
|
14
|
+
/**
|
|
15
|
+
* Static error classes for validation.
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
static validationErrors?: {
|
|
19
|
+
ColumnNotFoundError: any;
|
|
20
|
+
NullableConstraintError: any;
|
|
21
|
+
TypeMismatchError: any;
|
|
22
|
+
};
|
|
9
23
|
/**
|
|
10
24
|
* Model attributes storage
|
|
11
25
|
* @internal
|
|
@@ -14,6 +14,11 @@ export declare class HasPersistence {
|
|
|
14
14
|
* @returns True if the model has been persisted
|
|
15
15
|
*/
|
|
16
16
|
get exists(): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Internal helper to retrieve the correct connection depending on sharding configuration
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
protected _getConnection(): import('../../../types').ConnectionContract;
|
|
17
22
|
/**
|
|
18
23
|
* Save the model instance to the database (insert or update).
|
|
19
24
|
*
|
|
@@ -26,6 +26,35 @@ export declare const COLUMN_KEY: unique symbol;
|
|
|
26
26
|
* @internal
|
|
27
27
|
*/
|
|
28
28
|
export declare const VERSION_KEY: unique symbol;
|
|
29
|
+
/**
|
|
30
|
+
* Metadata key for Sharded configuration.
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export declare const SHARDED_KEY: unique symbol;
|
|
34
|
+
/**
|
|
35
|
+
* Options for the Sharded decorator.
|
|
36
|
+
*/
|
|
37
|
+
export interface ShardedOptions {
|
|
38
|
+
/**
|
|
39
|
+
* The name of the ShardingManager to use.
|
|
40
|
+
* @default 'default'
|
|
41
|
+
*/
|
|
42
|
+
manager?: string;
|
|
43
|
+
/**
|
|
44
|
+
* The property name of the shard key (e.g. 'tenantId').
|
|
45
|
+
*/
|
|
46
|
+
key: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Sharded Decorator
|
|
50
|
+
*
|
|
51
|
+
* Marks a model as being horizontally sharded across multiple databases.
|
|
52
|
+
* Active Record operations will automatically route to the correct connection
|
|
53
|
+
* based on the shard key provided.
|
|
54
|
+
*
|
|
55
|
+
* @param options - Configuration for sharding containing the distribution key
|
|
56
|
+
*/
|
|
57
|
+
export declare function sharded(options: ShardedOptions): ClassDecorator;
|
|
29
58
|
/**
|
|
30
59
|
* Soft Deletes Decorator
|
|
31
60
|
*
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export { applyMixins, HasAttributes, HasEvents, HasPersistence, HasRelationships, HasSerialization, } from './concerns';
|
|
5
5
|
export { DirtyTracker } from './DirtyTracker';
|
|
6
|
-
export { column, SoftDeletes, version } from './decorators';
|
|
6
|
+
export { column, SoftDeletes, sharded, version } from './decorators';
|
|
7
7
|
export { ColumnNotFoundError, ModelNotFoundError, NullableConstraintError, TypeMismatchError, } from './errors';
|
|
8
8
|
export { Model, type ModelAttributes, type ModelConstructor, type ModelStatic } from './Model';
|
|
9
9
|
export { ModelRegistry } from './ModelRegistry';
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/atlas - Adaptive Pool Manager
|
|
3
|
+
* @description Manages adaptive pool sizing based on strategies
|
|
4
|
+
*/
|
|
5
|
+
import type { ConnectionManager } from '../connection/ConnectionManager';
|
|
6
|
+
import type { PoolStats } from '../types';
|
|
7
|
+
import type { PoolStrategy } from './PoolStrategy';
|
|
8
|
+
export interface PoolStatsHistory {
|
|
9
|
+
stats: PoolStats;
|
|
10
|
+
timestamp: number;
|
|
11
|
+
}
|
|
12
|
+
export interface PoolAdjustmentEvent {
|
|
13
|
+
connection: string;
|
|
14
|
+
action: 'increase' | 'decrease' | 'maintain';
|
|
15
|
+
from: number;
|
|
16
|
+
to: number;
|
|
17
|
+
reason: string;
|
|
18
|
+
}
|
|
19
|
+
export interface AdaptivePoolConfig {
|
|
20
|
+
/**
|
|
21
|
+
* Evaluation interval (ms)
|
|
22
|
+
* @default 60000
|
|
23
|
+
*/
|
|
24
|
+
evaluationInterval: number;
|
|
25
|
+
/**
|
|
26
|
+
* Minimum cooldown period (ms) before next adjustment
|
|
27
|
+
* @default 30000
|
|
28
|
+
*/
|
|
29
|
+
cooldownPeriod: number;
|
|
30
|
+
/**
|
|
31
|
+
* Maximum history size
|
|
32
|
+
* @default 10
|
|
33
|
+
*/
|
|
34
|
+
maxHistorySize: number;
|
|
35
|
+
/**
|
|
36
|
+
* Callback when adjustment is made
|
|
37
|
+
*/
|
|
38
|
+
onAdjustment?: (event: PoolAdjustmentEvent) => void;
|
|
39
|
+
}
|
|
40
|
+
export declare const DEFAULT_ADAPTIVE_CONFIG: AdaptivePoolConfig;
|
|
41
|
+
/**
|
|
42
|
+
* Adaptive pool manager
|
|
43
|
+
* Periodically evaluates pool statistics and adjusts size based on strategy
|
|
44
|
+
*/
|
|
45
|
+
export declare class AdaptivePoolManager {
|
|
46
|
+
private connectionManager;
|
|
47
|
+
private strategy;
|
|
48
|
+
private config;
|
|
49
|
+
private intervalHandle?;
|
|
50
|
+
private statsHistory;
|
|
51
|
+
private adjustmentCooldown;
|
|
52
|
+
private lastAdjustment;
|
|
53
|
+
constructor(connectionManager: ConnectionManager, strategy: PoolStrategy, config: AdaptivePoolConfig);
|
|
54
|
+
/**
|
|
55
|
+
* Start adaptive management
|
|
56
|
+
*/
|
|
57
|
+
start(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Stop adaptive management
|
|
60
|
+
*/
|
|
61
|
+
stop(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Get last adjustment for a connection
|
|
64
|
+
*/
|
|
65
|
+
getLastAdjustment(connectionName: string): PoolAdjustmentEvent | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Get history for a connection
|
|
68
|
+
*/
|
|
69
|
+
getHistory(connectionName: string): PoolStatsHistory[];
|
|
70
|
+
/**
|
|
71
|
+
* Evaluate all connection pools
|
|
72
|
+
*/
|
|
73
|
+
private evaluateAllPools;
|
|
74
|
+
/**
|
|
75
|
+
* Evaluate a specific pool
|
|
76
|
+
*/
|
|
77
|
+
private evaluatePool;
|
|
78
|
+
/**
|
|
79
|
+
* Build strategy context from current state
|
|
80
|
+
*/
|
|
81
|
+
private buildContext;
|
|
82
|
+
/**
|
|
83
|
+
* Update historical statistics
|
|
84
|
+
*/
|
|
85
|
+
private updateHistory;
|
|
86
|
+
/**
|
|
87
|
+
* Check if in cooldown period
|
|
88
|
+
*/
|
|
89
|
+
private isInCooldown;
|
|
90
|
+
/**
|
|
91
|
+
* Set cooldown period
|
|
92
|
+
*/
|
|
93
|
+
private setCooldown;
|
|
94
|
+
/**
|
|
95
|
+
* Apply adjustment to pool
|
|
96
|
+
*/
|
|
97
|
+
private applyAdjustment;
|
|
98
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/atlas - Connection Pool Health Checker
|
|
3
|
+
* @description Monitors connection pool health and triggers callbacks on state changes
|
|
4
|
+
*/
|
|
5
|
+
import type { ConnectionManager } from '../connection/ConnectionManager';
|
|
6
|
+
import type { PoolHealth } from '../types';
|
|
7
|
+
export interface PoolHealthCheckConfig {
|
|
8
|
+
/**
|
|
9
|
+
* Interval (ms) to check pool health
|
|
10
|
+
* @default 30000 (30 seconds)
|
|
11
|
+
*/
|
|
12
|
+
checkInterval: number;
|
|
13
|
+
/**
|
|
14
|
+
* Health status thresholds
|
|
15
|
+
*/
|
|
16
|
+
thresholds: {
|
|
17
|
+
/**
|
|
18
|
+
* Utilization ratio (0-1) to trigger warning
|
|
19
|
+
* @default 0.7
|
|
20
|
+
*/
|
|
21
|
+
warningUtilization: number;
|
|
22
|
+
/**
|
|
23
|
+
* Utilization ratio (0-1) to trigger critical
|
|
24
|
+
* @default 0.9
|
|
25
|
+
*/
|
|
26
|
+
criticalUtilization: number;
|
|
27
|
+
/**
|
|
28
|
+
* Pending ratio (0-1) to trigger warning
|
|
29
|
+
* @default 0.5
|
|
30
|
+
*/
|
|
31
|
+
maxPendingRatio: number;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Whether to test connection availability during health check
|
|
35
|
+
* @default true
|
|
36
|
+
*/
|
|
37
|
+
enableConnectionTest: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Timeout (ms) for connection test
|
|
40
|
+
* @default 5000
|
|
41
|
+
*/
|
|
42
|
+
connectionTestTimeout: number;
|
|
43
|
+
/**
|
|
44
|
+
* Callback when health status changes
|
|
45
|
+
*/
|
|
46
|
+
onHealthChange?: (connectionName: string, health: PoolHealth) => void;
|
|
47
|
+
/**
|
|
48
|
+
* Callback when pool health becomes critical
|
|
49
|
+
*/
|
|
50
|
+
onCritical?: (connectionName: string, health: PoolHealth) => void;
|
|
51
|
+
}
|
|
52
|
+
export declare const DEFAULT_HEALTH_CHECK_CONFIG: PoolHealthCheckConfig;
|
|
53
|
+
/**
|
|
54
|
+
* Connection pool health checker
|
|
55
|
+
* Periodically monitors pool health and triggers callbacks
|
|
56
|
+
*/
|
|
57
|
+
export declare class PoolHealthChecker {
|
|
58
|
+
private connectionManager;
|
|
59
|
+
private config;
|
|
60
|
+
private intervalHandle?;
|
|
61
|
+
private lastHealthStatus;
|
|
62
|
+
constructor(connectionManager: ConnectionManager, config: PoolHealthCheckConfig);
|
|
63
|
+
/**
|
|
64
|
+
* Start health checking
|
|
65
|
+
*/
|
|
66
|
+
start(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Stop health checking
|
|
69
|
+
*/
|
|
70
|
+
stop(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Get current health status for a specific connection
|
|
73
|
+
*/
|
|
74
|
+
getHealthStatus(connectionName?: string): PoolHealth | Map<string, PoolHealth>;
|
|
75
|
+
/**
|
|
76
|
+
* Check health of all connections
|
|
77
|
+
*/
|
|
78
|
+
private checkAllConnections;
|
|
79
|
+
/**
|
|
80
|
+
* Check health of a specific connection
|
|
81
|
+
*/
|
|
82
|
+
private checkConnection;
|
|
83
|
+
/**
|
|
84
|
+
* Evaluate pool health based on statistics
|
|
85
|
+
*/
|
|
86
|
+
private evaluateHealth;
|
|
87
|
+
/**
|
|
88
|
+
* Test connection availability
|
|
89
|
+
*/
|
|
90
|
+
private testConnectionAvailability;
|
|
91
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/atlas - Pool Strategy Engine
|
|
3
|
+
* @description Strategies for adaptive connection pool management
|
|
4
|
+
*/
|
|
5
|
+
import type { PoolStats } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Pool strategy decision result
|
|
8
|
+
*/
|
|
9
|
+
export interface PoolAdjustmentDecision {
|
|
10
|
+
/**
|
|
11
|
+
* Action to take: 'increase' | 'decrease' | 'maintain'
|
|
12
|
+
*/
|
|
13
|
+
action: 'increase' | 'decrease' | 'maintain';
|
|
14
|
+
/**
|
|
15
|
+
* Target pool size
|
|
16
|
+
*/
|
|
17
|
+
targetSize: number;
|
|
18
|
+
/**
|
|
19
|
+
* Reason for the decision
|
|
20
|
+
*/
|
|
21
|
+
reason: string;
|
|
22
|
+
/**
|
|
23
|
+
* Confidence level (0-1)
|
|
24
|
+
*/
|
|
25
|
+
confidence: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Strategy context for decision making
|
|
29
|
+
*/
|
|
30
|
+
export interface PoolStrategyContext {
|
|
31
|
+
/**
|
|
32
|
+
* Current pool statistics
|
|
33
|
+
*/
|
|
34
|
+
stats: PoolStats;
|
|
35
|
+
/**
|
|
36
|
+
* Historical statistics (if available)
|
|
37
|
+
*/
|
|
38
|
+
history?: PoolStats[];
|
|
39
|
+
/**
|
|
40
|
+
* Pool configuration
|
|
41
|
+
*/
|
|
42
|
+
config: {
|
|
43
|
+
min?: number;
|
|
44
|
+
max?: number;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Connection name
|
|
48
|
+
*/
|
|
49
|
+
connectionName: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Abstract base class for pool adjustment strategies
|
|
53
|
+
*/
|
|
54
|
+
export declare abstract class PoolStrategy {
|
|
55
|
+
/**
|
|
56
|
+
* Strategy name
|
|
57
|
+
*/
|
|
58
|
+
abstract readonly name: string;
|
|
59
|
+
/**
|
|
60
|
+
* Make an adjustment decision based on pool context
|
|
61
|
+
*/
|
|
62
|
+
abstract decide(context: PoolStrategyContext): PoolAdjustmentDecision;
|
|
63
|
+
/**
|
|
64
|
+
* Validate if an adjustment decision is acceptable
|
|
65
|
+
*/
|
|
66
|
+
validateAdjustment(decision: PoolAdjustmentDecision, context: PoolStrategyContext): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Protected helper: calculate utilization ratio
|
|
69
|
+
*/
|
|
70
|
+
protected calculateUtilization(stats: PoolStats): number;
|
|
71
|
+
/**
|
|
72
|
+
* Protected helper: calculate pending ratio
|
|
73
|
+
*/
|
|
74
|
+
protected calculatePendingRatio(stats: PoolStats): number;
|
|
75
|
+
/**
|
|
76
|
+
* Protected helper: clamp value to bounds
|
|
77
|
+
*/
|
|
78
|
+
protected clampToSize(value: number, context: PoolStrategyContext): number;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Load-aware strategy: adjusts based on current utilization
|
|
82
|
+
*/
|
|
83
|
+
export declare class LoadAwareStrategy extends PoolStrategy {
|
|
84
|
+
readonly name = "load-aware";
|
|
85
|
+
private readonly warningUtilization;
|
|
86
|
+
private readonly criticalUtilization;
|
|
87
|
+
private readonly recoveryUtilization;
|
|
88
|
+
constructor(config?: {
|
|
89
|
+
warningUtilization?: number;
|
|
90
|
+
criticalUtilization?: number;
|
|
91
|
+
recoveryUtilization?: number;
|
|
92
|
+
});
|
|
93
|
+
decide(context: PoolStrategyContext): PoolAdjustmentDecision;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Predictive strategy: adjusts based on historical trends
|
|
97
|
+
*/
|
|
98
|
+
export declare class PredictiveStrategy extends PoolStrategy {
|
|
99
|
+
readonly name = "predictive";
|
|
100
|
+
private readonly minHistorySize;
|
|
101
|
+
constructor(config?: {
|
|
102
|
+
minHistorySize?: number;
|
|
103
|
+
});
|
|
104
|
+
decide(context: PoolStrategyContext): PoolAdjustmentDecision;
|
|
105
|
+
/**
|
|
106
|
+
* Calculate linear trend from data points
|
|
107
|
+
*/
|
|
108
|
+
private calculateTrend;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Hybrid strategy: combines multiple strategies
|
|
112
|
+
*/
|
|
113
|
+
export declare class HybridStrategy extends PoolStrategy {
|
|
114
|
+
private loadAware;
|
|
115
|
+
private predictive;
|
|
116
|
+
private loadWeight;
|
|
117
|
+
private predictiveWeight;
|
|
118
|
+
readonly name = "hybrid";
|
|
119
|
+
constructor(loadAware: LoadAwareStrategy, predictive: PredictiveStrategy, loadWeight?: number, predictiveWeight?: number);
|
|
120
|
+
decide(context: PoolStrategyContext): PoolAdjustmentDecision;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Create default strategies for pool management
|
|
124
|
+
*/
|
|
125
|
+
export declare function createDefaultStrategies(): {
|
|
126
|
+
loadAware: LoadAwareStrategy;
|
|
127
|
+
predictive: PredictiveStrategy;
|
|
128
|
+
hybrid: HybridStrategy;
|
|
129
|
+
};
|