@gravito/ripple 3.1.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/README.md +260 -19
  2. package/dist/atlas/src/DB.d.ts +348 -0
  3. package/dist/atlas/src/OrbitAtlas.d.ts +9 -0
  4. package/dist/atlas/src/config/defineConfig.d.ts +14 -0
  5. package/dist/atlas/src/config/index.d.ts +7 -0
  6. package/dist/atlas/src/config/loadConfig.d.ts +41 -0
  7. package/dist/atlas/src/connection/Connection.d.ts +112 -0
  8. package/dist/atlas/src/connection/ConnectionManager.d.ts +180 -0
  9. package/dist/atlas/src/connection/ReplicaConnectionPool.d.ts +54 -0
  10. package/dist/atlas/src/drivers/BunSQLDriver.d.ts +32 -0
  11. package/dist/atlas/src/drivers/BunSQLPreparedStatement.d.ts +118 -0
  12. package/dist/atlas/src/drivers/MongoDBDriver.d.ts +36 -0
  13. package/dist/atlas/src/drivers/MySQLDriver.d.ts +79 -0
  14. package/dist/atlas/src/drivers/PostgresDriver.d.ts +96 -0
  15. package/dist/atlas/src/drivers/RedisDriver.d.ts +43 -0
  16. package/dist/atlas/src/drivers/SQLiteDriver.d.ts +45 -0
  17. package/dist/atlas/src/drivers/types.d.ts +260 -0
  18. package/dist/atlas/src/errors/index.d.ts +45 -0
  19. package/dist/atlas/src/grammar/Grammar.d.ts +342 -0
  20. package/dist/atlas/src/grammar/MongoGrammar.d.ts +47 -0
  21. package/dist/atlas/src/grammar/MySQLGrammar.d.ts +54 -0
  22. package/dist/atlas/src/grammar/NullGrammar.d.ts +35 -0
  23. package/dist/atlas/src/grammar/PostgresGrammar.d.ts +62 -0
  24. package/dist/atlas/src/grammar/SQLiteGrammar.d.ts +32 -0
  25. package/dist/atlas/src/index.d.ts +79 -0
  26. package/dist/atlas/src/migration/Migration.d.ts +64 -0
  27. package/dist/atlas/src/migration/MigrationRepository.d.ts +65 -0
  28. package/dist/atlas/src/migration/Migrator.d.ts +110 -0
  29. package/dist/atlas/src/migration/index.d.ts +6 -0
  30. package/dist/atlas/src/observability/AtlasMetrics.d.ts +33 -0
  31. package/dist/atlas/src/observability/AtlasObservability.d.ts +15 -0
  32. package/dist/atlas/src/observability/AtlasTracer.d.ts +12 -0
  33. package/dist/atlas/src/observability/index.d.ts +9 -0
  34. package/dist/atlas/src/orm/Repository.d.ts +247 -0
  35. package/dist/atlas/src/orm/index.d.ts +6 -0
  36. package/dist/atlas/src/orm/model/DirtyTracker.d.ts +121 -0
  37. package/dist/atlas/src/orm/model/Model.d.ts +458 -0
  38. package/dist/atlas/src/orm/model/ModelRegistry.d.ts +20 -0
  39. package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +150 -0
  40. package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +36 -0
  41. package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +92 -0
  42. package/dist/atlas/src/orm/model/concerns/HasRelationships.d.ts +117 -0
  43. package/dist/atlas/src/orm/model/concerns/HasSerialization.d.ts +64 -0
  44. package/dist/atlas/src/orm/model/concerns/applyMixins.d.ts +15 -0
  45. package/dist/atlas/src/orm/model/concerns/index.d.ts +12 -0
  46. package/dist/atlas/src/orm/model/decorators.d.ts +138 -0
  47. package/dist/atlas/src/orm/model/errors.d.ts +52 -0
  48. package/dist/atlas/src/orm/model/index.d.ts +10 -0
  49. package/dist/atlas/src/orm/model/relationships.d.ts +207 -0
  50. package/dist/atlas/src/orm/model/types.d.ts +12 -0
  51. package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +124 -0
  52. package/dist/atlas/src/orm/schema/SchemaSniffer.d.ts +54 -0
  53. package/dist/atlas/src/orm/schema/index.d.ts +6 -0
  54. package/dist/atlas/src/orm/schema/types.d.ts +85 -0
  55. package/dist/atlas/src/pool/AdaptivePoolManager.d.ts +98 -0
  56. package/dist/atlas/src/pool/PoolHealthChecker.d.ts +91 -0
  57. package/dist/atlas/src/pool/PoolStrategy.d.ts +129 -0
  58. package/dist/atlas/src/pool/PoolWarmer.d.ts +92 -0
  59. package/dist/atlas/src/query/Expression.d.ts +60 -0
  60. package/dist/atlas/src/query/NPlusOneDetector.d.ts +10 -0
  61. package/dist/atlas/src/query/QueryBuilder.d.ts +643 -0
  62. package/dist/atlas/src/query/RelationshipResolver.d.ts +23 -0
  63. package/dist/atlas/src/query/clauses/GroupByClause.d.ts +51 -0
  64. package/dist/atlas/src/query/clauses/HavingClause.d.ts +70 -0
  65. package/dist/atlas/src/query/clauses/JoinClause.d.ts +87 -0
  66. package/dist/atlas/src/query/clauses/LimitClause.d.ts +82 -0
  67. package/dist/atlas/src/query/clauses/OrderByClause.d.ts +69 -0
  68. package/dist/atlas/src/query/clauses/SelectClause.d.ts +71 -0
  69. package/dist/atlas/src/query/clauses/WhereClause.d.ts +167 -0
  70. package/dist/atlas/src/query/clauses/index.d.ts +11 -0
  71. package/dist/atlas/src/schema/Blueprint.d.ts +276 -0
  72. package/dist/atlas/src/schema/ColumnDefinition.d.ts +154 -0
  73. package/dist/atlas/src/schema/ForeignKeyDefinition.d.ts +37 -0
  74. package/dist/atlas/src/schema/MigrationGenerator.d.ts +45 -0
  75. package/dist/atlas/src/schema/Schema.d.ts +131 -0
  76. package/dist/atlas/src/schema/SchemaDiff.d.ts +73 -0
  77. package/dist/atlas/src/schema/TypeGenerator.d.ts +57 -0
  78. package/dist/atlas/src/schema/TypeWriter.d.ts +42 -0
  79. package/dist/atlas/src/schema/grammars/MySQLSchemaGrammar.d.ts +23 -0
  80. package/dist/atlas/src/schema/grammars/PostgresSchemaGrammar.d.ts +26 -0
  81. package/dist/atlas/src/schema/grammars/SQLiteSchemaGrammar.d.ts +28 -0
  82. package/dist/atlas/src/schema/grammars/SchemaGrammar.d.ts +97 -0
  83. package/dist/atlas/src/schema/grammars/index.d.ts +7 -0
  84. package/dist/atlas/src/schema/index.d.ts +8 -0
  85. package/dist/atlas/src/seed/Factory.d.ts +90 -0
  86. package/dist/atlas/src/seed/Seeder.d.ts +28 -0
  87. package/dist/atlas/src/seed/SeederRunner.d.ts +74 -0
  88. package/dist/atlas/src/seed/index.d.ts +6 -0
  89. package/dist/atlas/src/sharding/ShardingManager.d.ts +59 -0
  90. package/dist/atlas/src/types/index.d.ts +1182 -0
  91. package/dist/atlas/src/utils/CursorEncoding.d.ts +63 -0
  92. package/dist/atlas/src/utils/levenshtein.d.ts +9 -0
  93. package/dist/core/src/CommandKernel.d.ts +33 -0
  94. package/dist/core/src/ConfigManager.d.ts +39 -0
  95. package/dist/core/src/Container/RequestScopeManager.d.ts +62 -0
  96. package/dist/core/src/Container/RequestScopeMetrics.d.ts +144 -0
  97. package/dist/core/src/Container.d.ts +86 -11
  98. package/dist/core/src/ErrorHandler.d.ts +3 -0
  99. package/dist/core/src/HookManager.d.ts +511 -4
  100. package/dist/core/src/PlanetCore.d.ts +89 -0
  101. package/dist/core/src/RequestContext.d.ts +97 -0
  102. package/dist/core/src/Router.d.ts +1 -5
  103. package/dist/core/src/ServiceProvider.d.ts +22 -0
  104. package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +1 -0
  105. package/dist/core/src/adapters/PhotonAdapter.d.ts +5 -0
  106. package/dist/core/src/adapters/bun/BunContext.d.ts +4 -0
  107. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +1 -0
  108. package/dist/core/src/adapters/types.d.ts +27 -0
  109. package/dist/core/src/cli/queue-commands.d.ts +6 -0
  110. package/dist/core/src/engine/AOTRouter.d.ts +7 -12
  111. package/dist/core/src/engine/FastContext.d.ts +27 -2
  112. package/dist/core/src/engine/Gravito.d.ts +0 -1
  113. package/dist/core/src/engine/MinimalContext.d.ts +25 -2
  114. package/dist/core/src/engine/types.d.ts +9 -1
  115. package/dist/core/src/error-handling/RequestScopeErrorContext.d.ts +126 -0
  116. package/dist/core/src/events/BackpressureManager.d.ts +215 -0
  117. package/dist/core/src/events/CircuitBreaker.d.ts +229 -0
  118. package/dist/core/src/events/DeadLetterQueue.d.ts +219 -0
  119. package/dist/core/src/events/EventBackend.d.ts +12 -0
  120. package/dist/core/src/events/EventOptions.d.ts +204 -0
  121. package/dist/core/src/events/EventPriorityQueue.d.ts +301 -0
  122. package/dist/core/src/events/FlowControlStrategy.d.ts +109 -0
  123. package/dist/core/src/events/IdempotencyCache.d.ts +60 -0
  124. package/dist/core/src/events/MessageQueueBridge.d.ts +184 -0
  125. package/dist/core/src/events/PriorityEscalationManager.d.ts +82 -0
  126. package/dist/core/src/events/RetryScheduler.d.ts +104 -0
  127. package/dist/core/src/events/WorkerPool.d.ts +98 -0
  128. package/dist/core/src/events/WorkerPoolConfig.d.ts +153 -0
  129. package/dist/core/src/events/WorkerPoolMetrics.d.ts +65 -0
  130. package/dist/core/src/events/aggregation/AggregationWindow.d.ts +77 -0
  131. package/dist/core/src/events/aggregation/DeduplicationManager.d.ts +135 -0
  132. package/dist/core/src/events/aggregation/EventAggregationManager.d.ts +108 -0
  133. package/dist/core/src/events/aggregation/EventBatcher.d.ts +99 -0
  134. package/dist/core/src/events/aggregation/types.d.ts +117 -0
  135. package/dist/core/src/events/index.d.ts +25 -0
  136. package/dist/core/src/events/observability/EventMetrics.d.ts +132 -0
  137. package/dist/core/src/events/observability/EventTracer.d.ts +68 -0
  138. package/dist/core/src/events/observability/EventTracing.d.ts +161 -0
  139. package/dist/core/src/events/observability/OTelEventMetrics.d.ts +332 -0
  140. package/dist/core/src/events/observability/ObservableHookManager.d.ts +108 -0
  141. package/dist/core/src/events/observability/StreamWorkerMetrics.d.ts +76 -0
  142. package/dist/core/src/events/observability/index.d.ts +24 -0
  143. package/dist/core/src/events/observability/metrics-types.d.ts +16 -0
  144. package/dist/core/src/events/types.d.ts +134 -0
  145. package/dist/core/src/exceptions/CircularDependencyException.d.ts +9 -0
  146. package/dist/core/src/exceptions/index.d.ts +1 -0
  147. package/dist/core/src/health/HealthProvider.d.ts +67 -0
  148. package/dist/core/src/http/types.d.ts +40 -0
  149. package/dist/core/src/index.d.ts +25 -4
  150. package/dist/core/src/instrumentation/index.d.ts +35 -0
  151. package/dist/core/src/instrumentation/opentelemetry.d.ts +178 -0
  152. package/dist/core/src/instrumentation/types.d.ts +182 -0
  153. package/dist/core/src/observability/Metrics.d.ts +244 -0
  154. package/dist/core/src/observability/QueueDashboard.d.ts +136 -0
  155. package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +350 -0
  156. package/dist/core/src/reliability/RetryPolicy.d.ts +217 -0
  157. package/dist/core/src/reliability/index.d.ts +6 -0
  158. package/dist/core/src/router/ControllerDispatcher.d.ts +12 -0
  159. package/dist/core/src/router/RequestValidator.d.ts +20 -0
  160. package/dist/index.js +6709 -9888
  161. package/dist/index.js.map +64 -62
  162. package/dist/photon/src/index.d.ts +19 -0
  163. package/dist/photon/src/middleware/ratelimit-redis.d.ts +50 -0
  164. package/dist/photon/src/middleware/ratelimit.d.ts +161 -0
  165. package/dist/photon/src/openapi.d.ts +19 -0
  166. package/dist/proto/ripple.proto +120 -0
  167. package/dist/ripple/src/RippleServer.d.ts +64 -445
  168. package/dist/ripple/src/channels/ChannelManager.d.ts +25 -10
  169. package/dist/ripple/src/drivers/NATSDriver.d.ts +87 -0
  170. package/dist/ripple/src/drivers/RedisDriver.d.ts +30 -1
  171. package/dist/ripple/src/drivers/index.d.ts +1 -0
  172. package/dist/ripple/src/engines/BunEngine.d.ts +98 -0
  173. package/dist/ripple/src/engines/IRippleEngine.d.ts +205 -0
  174. package/dist/ripple/src/engines/UWebSocketsEngine.d.ts +97 -0
  175. package/dist/ripple/src/engines/WsEngine.d.ts +69 -0
  176. package/dist/ripple/src/engines/index.d.ts +15 -0
  177. package/dist/ripple/src/index.d.ts +2 -0
  178. package/dist/ripple/src/middleware/InterceptorManager.d.ts +21 -0
  179. package/dist/ripple/src/observability/RippleMetrics.d.ts +24 -0
  180. package/dist/ripple/src/reliability/AckManager.d.ts +48 -0
  181. package/dist/ripple/src/serializers/ISerializer.d.ts +39 -0
  182. package/dist/ripple/src/serializers/JsonSerializer.d.ts +19 -0
  183. package/dist/ripple/src/serializers/ProtobufSerializer.d.ts +41 -0
  184. package/dist/ripple/src/serializers/index.d.ts +3 -0
  185. package/dist/ripple/src/tracking/SessionManager.d.ts +104 -0
  186. package/dist/ripple/src/tracking/index.d.ts +1 -0
  187. package/dist/ripple/src/types.d.ts +188 -12
  188. package/dist/ripple/src/utils/MessageSerializer.d.ts +33 -23
  189. package/dist/ripple/src/utils/TokenBucket.d.ts +25 -0
  190. package/package.json +25 -8
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Migration Interface
3
+ * @description Contract for database migration classes
4
+ */
5
+ /**
6
+ * Migration Interface
7
+ *
8
+ * All database migration classes must implement this interface.
9
+ * The `up` method is used to apply changes (e.g., create tables),
10
+ * while the `down` method is used to reverse those changes.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { Migration, Schema } from '@gravito/atlas'
15
+ *
16
+ * export default class CreateUsersTable implements Migration {
17
+ * async up(): Promise<void> {
18
+ * await Schema.create('users', (table) => {
19
+ * table.id()
20
+ * table.string('email').unique()
21
+ * table.timestamps()
22
+ * })
23
+ * }
24
+ *
25
+ * async down(): Promise<void> {
26
+ * await Schema.dropIfExists('users')
27
+ * }
28
+ * }
29
+ * ```
30
+ */
31
+ export interface Migration {
32
+ /**
33
+ * Run the migration (create tables, add columns, etc.)
34
+ */
35
+ up(): Promise<void>;
36
+ /**
37
+ * Reverse the migration (drop tables, remove columns, etc.)
38
+ */
39
+ down(): Promise<void>;
40
+ }
41
+ /**
42
+ * Migration constructor type
43
+ */
44
+ export type MigrationConstructor = new () => Migration;
45
+ /**
46
+ * Migration record stored in the database
47
+ */
48
+ export interface MigrationRecord {
49
+ /** Migration ID */
50
+ id: number;
51
+ /** Migration file name (without path) */
52
+ migration: string;
53
+ /** Batch number when the migration was run */
54
+ batch: number;
55
+ }
56
+ /**
57
+ * Migration file info
58
+ */
59
+ export interface MigrationFile {
60
+ /** Migration file name (without path) */
61
+ name: string;
62
+ /** Full file path */
63
+ path: string;
64
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Migration Repository
3
+ * @description Tracks migration execution state in the database
4
+ */
5
+ import type { MigrationRecord } from './Migration';
6
+ /**
7
+ * Migration Repository
8
+ *
9
+ * The MigrationRepository class manages the database table that tracks
10
+ * which migrations have been executed. It provides methods for logging
11
+ * migrations, retrieving the list of ran migrations, and managing batches.
12
+ */
13
+ export declare class MigrationRepository {
14
+ private tableName;
15
+ private connectionName;
16
+ constructor(connectionName?: string);
17
+ /**
18
+ * Set the table name for migrations
19
+ */
20
+ setTable(table: string): this;
21
+ /**
22
+ * Create the migration repository table if it doesn't exist
23
+ */
24
+ createRepository(): Promise<void>;
25
+ /**
26
+ * Check if the migration repository exists
27
+ */
28
+ repositoryExists(): Promise<boolean>;
29
+ /**
30
+ * Delete the migration repository table
31
+ */
32
+ deleteRepository(): Promise<void>;
33
+ /**
34
+ * Get all ran migrations
35
+ */
36
+ getRan(): Promise<string[]>;
37
+ /**
38
+ * Get migrations for a specific batch
39
+ */
40
+ getMigrations(batch: number): Promise<MigrationRecord[]>;
41
+ /**
42
+ * Get the last batch number
43
+ */
44
+ getLastBatchNumber(): Promise<number>;
45
+ /**
46
+ * Get the next batch number
47
+ */
48
+ getNextBatchNumber(): Promise<number>;
49
+ /**
50
+ * Log that a migration was run
51
+ */
52
+ log(migration: string, batch: number): Promise<void>;
53
+ /**
54
+ * Remove a migration from the log
55
+ */
56
+ delete(migration: string): Promise<void>;
57
+ /**
58
+ * Get the last migrations (for rollback)
59
+ */
60
+ getLast(): Promise<MigrationRecord[]>;
61
+ /**
62
+ * Get the database connection
63
+ */
64
+ private getConnection;
65
+ }
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Migrator
3
+ * @description Migration runner with support for running and rolling back migrations
4
+ */
5
+ /**
6
+ * Migrator Options
7
+ */
8
+ export interface MigratorOptions {
9
+ /** Path to migrations directory */
10
+ path?: string;
11
+ /** Database connection name */
12
+ connection?: string;
13
+ /** Migration table name */
14
+ table?: string;
15
+ }
16
+ /**
17
+ * Migration Result
18
+ */
19
+ export interface MigrationResult {
20
+ /** Migrations that were run */
21
+ migrations: string[];
22
+ /** Batch number */
23
+ batch?: number;
24
+ }
25
+ /**
26
+ * Migrator
27
+ *
28
+ * The Migrator class is responsible for managing the database migration lifecycle.
29
+ * It handles discovering migration files, tracking which migrations have been run
30
+ * in the database, and executing the `up` or `down` methods of migration classes.
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const migrator = new Migrator({ path: './migrations' })
35
+ *
36
+ * // Run all pending migrations
37
+ * await migrator.run()
38
+ *
39
+ * // Rollback the last batch of migrations
40
+ * await migrator.rollback()
41
+ * ```
42
+ */
43
+ export declare class Migrator {
44
+ private repository;
45
+ private migrationsPath;
46
+ private resolvedMigrations;
47
+ constructor(options?: MigratorOptions);
48
+ /**
49
+ * Set migrations path
50
+ */
51
+ setPath(path: string): this;
52
+ /**
53
+ * Set database connection
54
+ */
55
+ connection(name: string): this;
56
+ /**
57
+ * Run all pending migrations.
58
+ *
59
+ * This method will identify all migration files that have not yet been
60
+ * recorded in the migrations table and execute their `up` method.
61
+ *
62
+ * @returns A promise that resolves to the migration result.
63
+ */
64
+ run(): Promise<MigrationResult>;
65
+ /**
66
+ * Run a specific migration up
67
+ */
68
+ runUp(migrationName: string): Promise<void>;
69
+ /**
70
+ * Rollback the last batch of migrations.
71
+ *
72
+ * This method will identify the migrations that were part of the last
73
+ * execution batch and execute their `down` method.
74
+ *
75
+ * @param steps The number of batches to rollback (defaults to 1).
76
+ * @returns A promise that resolves to the migration result.
77
+ */
78
+ rollback(steps?: number): Promise<MigrationResult>;
79
+ /**
80
+ * Rollback all migrations
81
+ */
82
+ reset(): Promise<MigrationResult>;
83
+ /**
84
+ * Reset and re-run all migrations
85
+ */
86
+ fresh(): Promise<MigrationResult>;
87
+ /**
88
+ * Rollback and re-run the last batch
89
+ */
90
+ refresh(steps?: number): Promise<MigrationResult>;
91
+ /**
92
+ * Get migration status
93
+ */
94
+ status(): Promise<{
95
+ ran: string[];
96
+ pending: string[];
97
+ }>;
98
+ /**
99
+ * Get all migration files from the migrations directory
100
+ */
101
+ private getMigrationFiles;
102
+ /**
103
+ * Run a single migration
104
+ */
105
+ private runMigration;
106
+ /**
107
+ * Resolve migration class from file
108
+ */
109
+ private resolveMigration;
110
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Migration Module Index
3
+ */
4
+ export type { Migration, MigrationConstructor, MigrationFile, MigrationRecord } from './Migration';
5
+ export { MigrationRepository } from './MigrationRepository';
6
+ export { type MigrationResult, Migrator, type MigratorOptions } from './Migrator';
@@ -0,0 +1,33 @@
1
+ import { type Counter, type Histogram } from '@opentelemetry/api';
2
+ export interface AtlasMetricsConfig {
3
+ enabled: boolean;
4
+ }
5
+ export declare class AtlasMetrics {
6
+ private meter;
7
+ private config;
8
+ private poolCallbacks;
9
+ readonly operationDuration?: Histogram;
10
+ readonly operationErrors?: Counter;
11
+ readonly poolSize?: any;
12
+ readonly poolUtilization?: any;
13
+ readonly poolWaitTime?: Histogram;
14
+ readonly poolAcquisitionErrors?: Counter;
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;
33
+ }
@@ -0,0 +1,15 @@
1
+ import { AtlasMetrics, type AtlasMetricsConfig } from './AtlasMetrics';
2
+ import { AtlasTracer, type AtlasTracingConfig } from './AtlasTracer';
3
+ export declare class AtlasObservability {
4
+ private static instance;
5
+ tracer?: AtlasTracer;
6
+ metrics?: AtlasMetrics;
7
+ private constructor();
8
+ static getInstance(): AtlasObservability;
9
+ initialize(config: {
10
+ tracing?: AtlasTracingConfig;
11
+ metrics?: AtlasMetricsConfig;
12
+ }): void;
13
+ static getTracer(): AtlasTracer | undefined;
14
+ static getMetrics(): AtlasMetrics | undefined;
15
+ }
@@ -0,0 +1,12 @@
1
+ import { type Context, type Span } from '@opentelemetry/api';
2
+ export interface AtlasTracingConfig {
3
+ enabled: boolean;
4
+ serviceName?: string;
5
+ }
6
+ export declare class AtlasTracer {
7
+ private tracer;
8
+ private config;
9
+ constructor(config: AtlasTracingConfig);
10
+ startSpan(name: string, attributes?: Record<string, any>): Span | undefined;
11
+ getActiveContext(): Context;
12
+ }
@@ -0,0 +1,9 @@
1
+ export * from './AtlasMetrics';
2
+ export * from './AtlasObservability';
3
+ export * from './AtlasTracer';
4
+ export interface AtlasObservabilityConfig {
5
+ enabled: boolean;
6
+ tracing?: boolean;
7
+ metrics?: boolean;
8
+ serviceName?: string;
9
+ }
@@ -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
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * ORM Module Index
3
+ */
4
+ export * from './model';
5
+ export { ModelRepository } from './Repository';
6
+ export * from './schema';
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Dirty Tracker for monitoring attribute modifications on model instances.
3
+ *
4
+ * Maintains a snapshot of original values and tracks which keys have been
5
+ * changed. Supports optimized structural comparison and deep change detection
6
+ * for complex objects.
7
+ *
8
+ * @template T - The shape of the model attributes.
9
+ */
10
+ export declare class DirtyTracker<T extends Record<string, unknown>> {
11
+ /**
12
+ * Stores the initial values as retrieved from the database.
13
+ */
14
+ private original;
15
+ /**
16
+ * Tracks keys that differ from their original state.
17
+ */
18
+ private dirty;
19
+ /**
20
+ * When enabled, nested objects are compared recursively.
21
+ */
22
+ private useDeepComparison;
23
+ /**
24
+ * Configures the comparison strategy for nested structures.
25
+ *
26
+ * @param enabled - True to enable recursive comparison.
27
+ */
28
+ setDeepComparison(enabled: boolean): void;
29
+ /**
30
+ * Records initial state and clears the dirty set.
31
+ *
32
+ * Called typically during hydration or after a successful save.
33
+ *
34
+ * @param data - The baseline values.
35
+ */
36
+ setOriginal(data: Partial<T>): void;
37
+ /**
38
+ * Checks for changes and updates the dirty set accordingly.
39
+ *
40
+ * Compares the new value against the original. If they match, the key
41
+ * is removed from the dirty set (reversion).
42
+ *
43
+ * @param key - The attribute name.
44
+ * @param newValue - The proposed new value.
45
+ */
46
+ mark(key: keyof T, newValue: unknown): void;
47
+ /**
48
+ * Indicates if any attributes or a specific attribute has been modified.
49
+ *
50
+ * @param key - Optional specific attribute to check.
51
+ * @returns True if changes are detected.
52
+ */
53
+ isDirty(key?: keyof T): boolean;
54
+ /**
55
+ * Returns a list of all modified attribute names.
56
+ */
57
+ getDirty(): Array<keyof T>;
58
+ /**
59
+ * Extracts current values for all dirty attributes.
60
+ *
61
+ * @param current - The source object containing all current values.
62
+ * @returns An object with only the modified entries.
63
+ */
64
+ getDirtyValues(current: Partial<T>): Partial<T>;
65
+ /**
66
+ * Retrieves the original value of an attribute from the snapshot.
67
+ */
68
+ getOriginal(key: keyof T): unknown;
69
+ /**
70
+ * Retrieves the complete original snapshot.
71
+ */
72
+ getOriginals(): Partial<T>;
73
+ /**
74
+ * Synchronizes the snapshot with the current state.
75
+ *
76
+ * @param data - The new baseline data.
77
+ */
78
+ sync(data: Partial<T>): void;
79
+ /**
80
+ * Reverts the dirty flag for a specific attribute.
81
+ */
82
+ reset(key: keyof T): void;
83
+ /**
84
+ * Clears all tracking information.
85
+ */
86
+ resetAll(): void;
87
+ /**
88
+ * Compares two values for equality using optimized structural comparison.
89
+ *
90
+ * Performs shallow comparison by default. Avoids JSON.stringify overhead
91
+ * by using recursive structural comparison for arrays, maps, and sets.
92
+ *
93
+ * @param a - First value.
94
+ * @param b - Second value.
95
+ * @returns True if equal.
96
+ * @internal
97
+ */
98
+ private isEqual;
99
+ /**
100
+ * Performs deep equality comparison with cycle detection.
101
+ *
102
+ * @param a - First value.
103
+ * @param b - Second value.
104
+ * @param visited - Set tracking visited objects.
105
+ * @returns True if deeply equal.
106
+ * @internal
107
+ */
108
+ private deepEqual;
109
+ /**
110
+ * Clones a value to ensure the original snapshot remains immutable.
111
+ *
112
+ * @param value - Value to clone.
113
+ * @internal
114
+ */
115
+ private cloneValue;
116
+ /**
117
+ * Performs recursive deep cloning.
118
+ * @internal
119
+ */
120
+ private deepClone;
121
+ }