@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,342 @@
1
+ /**
2
+ * Abstract SQL Grammar providing base logic for SQL generation.
3
+ *
4
+ * Handles the structural assembly of SELECT, INSERT, UPDATE, and DELETE
5
+ * statements. Includes a sophisticated compilation cache to minimize
6
+ * string manipulation overhead for repetitive query structures.
7
+ */
8
+ import { LRUCache } from 'lru-cache';
9
+ import type { CompiledQuery, GrammarContract, HavingClause, JoinClause, OrderClause, WhereClause } from '../types';
10
+ export declare abstract class Grammar implements GrammarContract {
11
+ /**
12
+ * Optional prefix for all table names.
13
+ */
14
+ protected tablePrefix: string;
15
+ /**
16
+ * Database-specific character for wrapping identifiers (e.g., " or `).
17
+ */
18
+ protected abstract wrapChar: string;
19
+ /**
20
+ * Internal cache for compiled SQL templates.
21
+ * Keyed by structural hash to allow reuse across different parameter values.
22
+ */
23
+ private static compilationCache;
24
+ /**
25
+ * Metrics for cache performance monitoring.
26
+ */
27
+ private static cacheStats;
28
+ /**
29
+ * Global toggle for SQL compilation caching.
30
+ */
31
+ static useCache: boolean;
32
+ /**
33
+ * Determines if the cache is shared globally or isolated per grammar instance.
34
+ */
35
+ static cacheScope: 'global' | 'instance';
36
+ private _instanceCache?;
37
+ private _instanceCacheStats;
38
+ /**
39
+ * Retrieves performance metrics for the compilation cache.
40
+ *
41
+ * @returns Stats including hit rate and utilization.
42
+ */
43
+ static getCacheStats(): {
44
+ size: number;
45
+ maxSize: number;
46
+ hits: number;
47
+ misses: number;
48
+ sets: number;
49
+ hitRate: number;
50
+ missRate: number;
51
+ totalRequests: number;
52
+ utilization: number;
53
+ };
54
+ /**
55
+ * Retrieves metrics for the instance-level cache.
56
+ *
57
+ * @returns Stats object or null if instance caching is disabled.
58
+ */
59
+ getInstanceCacheStats(): {
60
+ size: number;
61
+ maxSize: number;
62
+ hits: number;
63
+ misses: number;
64
+ sets: number;
65
+ hitRate: number;
66
+ missRate: number;
67
+ totalRequests: number;
68
+ utilization: number;
69
+ } | null;
70
+ /**
71
+ * Flushes all performance counters.
72
+ */
73
+ static resetCacheStats(): void;
74
+ /**
75
+ * Wipes the compilation cache.
76
+ */
77
+ static clearCache(): void;
78
+ /**
79
+ * Resizes the global compilation cache.
80
+ *
81
+ * @param max - Maximum number of templates to store.
82
+ */
83
+ static setCacheSize(max: number): void;
84
+ /**
85
+ * Resolves the active cache instance based on scope configuration.
86
+ * @internal
87
+ */
88
+ protected getCompilationCache(): LRUCache<string, string>;
89
+ /**
90
+ * Returns the database-specific placeholder (e.g., ?, $1, :name).
91
+ *
92
+ * @param index - The zero-based binding index.
93
+ */
94
+ abstract getPlaceholder(index: number): string;
95
+ /**
96
+ * Compiles an INSERT statement that returns the primary key.
97
+ */
98
+ abstract compileInsertGetId(query: CompiledQuery, values: Record<string, unknown>, primaryKey: string): string;
99
+ /**
100
+ * Transforms a query structure into a SELECT SQL string.
101
+ *
102
+ * Leverages caching by generating a structural key that ignores binding values.
103
+ *
104
+ * @param query - The structural definition of the query.
105
+ * @returns The compiled SQL string.
106
+ */
107
+ compileSelect(query: CompiledQuery): string;
108
+ /**
109
+ * Generates a unique hash representing the SQL structure.
110
+ *
111
+ * Ignores specific binding values to allow cache hits for similar queries.
112
+ * Uses efficient array joining for performance.
113
+ *
114
+ * @param query - The query structure.
115
+ * @returns A deterministic string key.
116
+ */
117
+ getStructuralKey(query: CompiledQuery): string;
118
+ /**
119
+ * Compiles the SELECT list.
120
+ * @internal
121
+ */
122
+ protected compileColumns(query: CompiledQuery): string;
123
+ /**
124
+ * Compiles the FROM clause.
125
+ * @internal
126
+ */
127
+ protected compileFrom(query: CompiledQuery): string;
128
+ /**
129
+ * Compiles all WHERE constraints.
130
+ *
131
+ * @param query - The query definition.
132
+ * @param bindingOffset - Initial parameter index.
133
+ * @returns Compiled SQL snippet.
134
+ * @internal
135
+ */
136
+ protected compileWheres(query: CompiledQuery, bindingOffset?: number): string;
137
+ /**
138
+ * @deprecated Use compileWhereWithOffset.
139
+ */
140
+ protected compileWhere(where: WhereClause, _query: CompiledQuery): string;
141
+ /**
142
+ * Compiles a single WHERE clause with offset awareness.
143
+ * @internal
144
+ */
145
+ protected compileWhereWithOffset(where: WhereClause, offset: number): {
146
+ sql: string;
147
+ bindingsUsed: number;
148
+ };
149
+ /**
150
+ * Compiles a standard equality or comparison clause.
151
+ * @internal
152
+ */
153
+ protected compileWhereBasicWithOffset(where: WhereClause, offset: number): string;
154
+ /**
155
+ * Compiles an IN clause.
156
+ * @internal
157
+ */
158
+ protected compileWhereInWithOffset(where: WhereClause, offset: number): string;
159
+ /**
160
+ * Wraps nested SQL in parentheses.
161
+ * @internal
162
+ */
163
+ protected compileWhereNested(where: WhereClause): string;
164
+ /**
165
+ * Compiles IS NULL constraints.
166
+ * @internal
167
+ */
168
+ protected compileWhereNull(where: WhereClause): string;
169
+ /**
170
+ * Compiles BETWEEN constraints.
171
+ * @internal
172
+ */
173
+ protected compileWhereBetweenWithOffset(where: WhereClause, offset: number): string;
174
+ /**
175
+ * Compiles column-to-column comparisons.
176
+ * @internal
177
+ */
178
+ protected compileWhereColumn(where: WhereClause): string;
179
+ /**
180
+ * Compiles all JOIN clauses.
181
+ * @internal
182
+ */
183
+ protected compileJoins(query: CompiledQuery): string;
184
+ /**
185
+ * Compiles a single JOIN relationship.
186
+ * @internal
187
+ */
188
+ protected compileJoin(join: JoinClause): string;
189
+ /**
190
+ * Compiles the GROUP BY clause.
191
+ * @internal
192
+ */
193
+ protected compileGroups(query: CompiledQuery): string;
194
+ /**
195
+ * Compiles all HAVING constraints.
196
+ * @internal
197
+ */
198
+ protected compileHavings(query: CompiledQuery, bindingOffset?: number): string;
199
+ /**
200
+ * Sums bindings across all WHERE clauses.
201
+ * @internal
202
+ */
203
+ protected countAllWhereBindings(wheres: WhereClause[]): number;
204
+ /**
205
+ * Counts bindings for a specific WHERE type.
206
+ * @internal
207
+ */
208
+ protected countWhereBindings(where: WhereClause): number;
209
+ /**
210
+ * Compiles a single HAVING clause.
211
+ * @internal
212
+ */
213
+ protected compileHavingWithOffset(having: HavingClause, offset: number): {
214
+ sql: string;
215
+ bindingsUsed: number;
216
+ };
217
+ /**
218
+ * @deprecated
219
+ */
220
+ protected compileHaving(having: HavingClause, _query: CompiledQuery): string;
221
+ /**
222
+ * Compiles the full ORDER BY clause.
223
+ * @internal
224
+ */
225
+ protected compileOrders(query: CompiledQuery): string;
226
+ /**
227
+ * Compiles a single sorting rule.
228
+ * @internal
229
+ */
230
+ protected compileOrder(order: OrderClause): string;
231
+ /**
232
+ * Compiles the LIMIT clause.
233
+ * @internal
234
+ */
235
+ protected compileLimit(query: CompiledQuery): string;
236
+ /**
237
+ * Compiles the OFFSET clause.
238
+ * @internal
239
+ */
240
+ protected compileOffset(query: CompiledQuery): string;
241
+ /**
242
+ * Compiles a multi-row INSERT statement.
243
+ *
244
+ * @param query - The query definition.
245
+ * @param values - Records to insert.
246
+ * @returns The SQL string.
247
+ */
248
+ compileInsert(query: CompiledQuery, values: Record<string, unknown>[]): string;
249
+ /**
250
+ * Compiles an UPDATE statement with WHERE constraints.
251
+ *
252
+ * @param query - The query definition.
253
+ * @param values - Fields and values to update.
254
+ * @returns The SQL string.
255
+ */
256
+ compileUpdate(query: CompiledQuery, values: Record<string, unknown>): string;
257
+ /**
258
+ * Adjusts placeholders in a pre-compiled snippet.
259
+ * @internal
260
+ */
261
+ protected offsetPlaceholders(sql: string, _offset: number): string;
262
+ /**
263
+ * Compiles a DELETE statement.
264
+ */
265
+ compileDelete(query: CompiledQuery): string;
266
+ /**
267
+ * Compiles a TRUNCATE statement to wipe a table.
268
+ */
269
+ compileTruncate(query: CompiledQuery): string;
270
+ /**
271
+ * Compiles an aggregate function selection (COUNT, MAX, etc.).
272
+ */
273
+ compileAggregate(query: CompiledQuery, aggregate: {
274
+ function: string;
275
+ column: string;
276
+ }): string;
277
+ /**
278
+ * Compiles an EXISTS check.
279
+ */
280
+ compileExists(query: CompiledQuery): string;
281
+ /**
282
+ * Escapes a column name for SQL safety.
283
+ *
284
+ * Handles table aliases, raw expressions, and wildcards.
285
+ *
286
+ * @param column - The column identifier.
287
+ */
288
+ wrapColumn(column: string): string;
289
+ /**
290
+ * Escapes a table name.
291
+ */
292
+ wrapTable(table: string): string;
293
+ /**
294
+ * Internal string escaping.
295
+ * @internal
296
+ */
297
+ protected wrapValue(value: string): string;
298
+ /**
299
+ * Manually quotes a value for literal injection.
300
+ *
301
+ * Warning: Prefer bindings over manual quoting for security.
302
+ *
303
+ * @param value - The value to quote.
304
+ */
305
+ quoteValue(value: unknown): string;
306
+ /**
307
+ * Configures a prefix for all table references.
308
+ */
309
+ setTablePrefix(prefix: string): void;
310
+ /**
311
+ * Retrieves the current table prefix.
312
+ */
313
+ getTablePrefix(): string;
314
+ /**
315
+ * Compiles a query for relationship lateral loading.
316
+ * @throws {Error} If unsupported by driver.
317
+ */
318
+ compileLateralEagerLoad(_table: string, _foreignKey: string, _parentKeys: unknown[], _query: CompiledQuery): {
319
+ sql: string;
320
+ bindings: unknown[];
321
+ };
322
+ /**
323
+ * Compiles a JSON path selector.
324
+ * @throws {Error} If unsupported.
325
+ */
326
+ compileJsonPath(_column: string, _value: unknown): string;
327
+ /**
328
+ * Compiles a JSON containment check.
329
+ * @throws {Error} If unsupported.
330
+ */
331
+ compileJsonContains(_column: string, _value: unknown): string;
332
+ /**
333
+ * Compiles a partial JSON update.
334
+ * @throws {Error} If unsupported.
335
+ */
336
+ compileUpdateJson(_query: CompiledQuery, _column: string, _value: unknown): string;
337
+ /**
338
+ * Compiles an UPSERT statement.
339
+ * @throws {Error} If unsupported.
340
+ */
341
+ compileUpsert(_query: CompiledQuery, _values: Record<string, unknown>[], _uniqueBy: string[], _update: string[]): string;
342
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * MongoDB Grammar
3
+ * @description Translates generic CompiledQuery into a MongoDB Query Protocol (JSON)
4
+ */
5
+ import type { CompiledQuery } from '../types';
6
+ import { Grammar } from './Grammar';
7
+ /**
8
+ * MongoDB Query Protocol
9
+ * Represents the structure passed from Grammar to Driver
10
+ */
11
+ export interface MongoQueryProtocol {
12
+ collection: string;
13
+ operation: 'find' | 'insert' | 'update' | 'delete' | 'aggregate' | 'count';
14
+ filter?: Record<string, unknown>;
15
+ options?: Record<string, unknown>;
16
+ document?: Record<string, unknown> | Record<string, unknown>[];
17
+ update?: Record<string, unknown>;
18
+ pipeline?: Record<string, unknown>[];
19
+ }
20
+ /**
21
+ * Mongo Grammar
22
+ * Transforms QueryBuilder state into MongoDB commands
23
+ */
24
+ export declare class MongoGrammar extends Grammar {
25
+ protected wrapChar: string;
26
+ getPlaceholder(_index: number): string;
27
+ compileInsertGetId(query: CompiledQuery, values: Record<string, unknown>, _primaryKey: string): string;
28
+ compileSelect(query: CompiledQuery): string;
29
+ compileInsert(query: CompiledQuery, values: Record<string, unknown>[]): string;
30
+ compileUpdate(query: CompiledQuery, values: Record<string, unknown>): string;
31
+ compileDelete(query: CompiledQuery): string;
32
+ compileAggregate(query: CompiledQuery, aggregate: {
33
+ function: string;
34
+ column: string;
35
+ }): string;
36
+ compileTruncate(query: CompiledQuery): string;
37
+ /**
38
+ * Translate generic WhereClause[] to MongoDB Filter
39
+ */
40
+ private compileMongoWheres;
41
+ private normalizeValue;
42
+ private compileBasicWhere;
43
+ private compileInWhere;
44
+ private compileNullWhere;
45
+ private normalizeColumn;
46
+ compileJsonPath(column: string, value: unknown): string;
47
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * MySQL Grammar
3
+ * @description SQL grammar implementation for MySQL/MariaDB
4
+ */
5
+ import type { CompiledQuery } from '../types';
6
+ import { Grammar } from './Grammar';
7
+ /**
8
+ * MySQL Grammar
9
+ * Implements MySQL/MariaDB-specific SQL syntax
10
+ */
11
+ export declare class MySQLGrammar extends Grammar {
12
+ /**
13
+ * MySQL uses backticks for identifiers
14
+ */
15
+ protected wrapChar: string;
16
+ /**
17
+ * Get placeholder for MySQL (?)
18
+ */
19
+ getPlaceholder(_index: number): string;
20
+ /**
21
+ * Compile INSERT and return ID using LAST_INSERT_ID()
22
+ */
23
+ compileInsertGetId(query: CompiledQuery, values: Record<string, unknown>, _primaryKey: string): string;
24
+ /**
25
+ * Compile TRUNCATE for MySQL
26
+ */
27
+ compileTruncate(query: CompiledQuery): string;
28
+ /**
29
+ * MySQL-specific: Compile UPSERT using ON DUPLICATE KEY UPDATE
30
+ */
31
+ compileUpsert(query: CompiledQuery, values: Record<string, unknown>[], _uniqueBy: string[], update: string[]): string;
32
+ /**
33
+ * MySQL-specific: Compile locking clause
34
+ */
35
+ compileLock(mode: 'update' | 'share'): string;
36
+ /**
37
+ * Override offset placeholders - MySQL uses ? for all
38
+ */
39
+ protected offsetPlaceholders(sql: string, _offset: number): string;
40
+ /**
41
+ * Compile EXISTS with MySQL syntax
42
+ */
43
+ compileExists(query: CompiledQuery): string;
44
+ /**
45
+ * Override aggregate to use backticks
46
+ */
47
+ compileAggregate(query: CompiledQuery, aggregate: {
48
+ function: string;
49
+ column: string;
50
+ }): string;
51
+ compileJsonPath(column: string, _value: unknown): string;
52
+ compileJsonContains(column: string, _value: unknown): string;
53
+ compileUpdateJson(query: CompiledQuery, column: string, _value: unknown): string;
54
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Null Grammar
3
+ * @description A fallback grammar for non-SQL drivers
4
+ */
5
+ import type { CompiledQuery, GrammarContract } from '../types';
6
+ /**
7
+ * Null Grammar
8
+ * Used for MongoDB, Redis, etc. where SQL compilation is not needed.
9
+ */
10
+ export declare class NullGrammar implements GrammarContract {
11
+ compileSelect(_query: CompiledQuery): string;
12
+ compileInsert(_query: CompiledQuery, _values: Record<string, unknown>[]): string;
13
+ compileInsertGetId(_query: CompiledQuery, _values: Record<string, unknown>, _primaryKey: string): string;
14
+ compileUpdate(_query: CompiledQuery, _values: Record<string, unknown>): string;
15
+ compileDelete(_query: CompiledQuery): string;
16
+ compileTruncate(_query: CompiledQuery): string;
17
+ compileAggregate(_query: CompiledQuery, _aggregate: {
18
+ function: string;
19
+ column: string;
20
+ }): string;
21
+ compileExists(_query: CompiledQuery): string;
22
+ getPlaceholder(_index: number): string;
23
+ wrapColumn(column: string): string;
24
+ wrapTable(table: string): string;
25
+ quoteValue(value: unknown): string;
26
+ compileLateralEagerLoad(_table: string, _foreignKey: string, _parentKeys: unknown[], _query: CompiledQuery): {
27
+ sql: string;
28
+ bindings: unknown[];
29
+ };
30
+ getStructuralKey(_query: CompiledQuery): string;
31
+ compileJsonPath(column: string, _value: unknown): string;
32
+ compileJsonContains(column: string, _value: unknown): string;
33
+ compileUpdateJson(_query: CompiledQuery, column: string, _value: unknown): string;
34
+ compileUpsert(_query: CompiledQuery, _values: Record<string, unknown>[], _uniqueBy: string[], _update: string[]): string;
35
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * PostgreSQL Grammar
3
+ * @description SQL grammar implementation for PostgreSQL
4
+ */
5
+ import type { CompiledQuery } from '../types';
6
+ import { Grammar } from './Grammar';
7
+ /**
8
+ * PostgreSQL Grammar
9
+ * Implements PostgreSQL-specific SQL syntax
10
+ */
11
+ export declare class PostgresGrammar extends Grammar {
12
+ /**
13
+ * PostgreSQL uses double quotes for identifiers
14
+ */
15
+ protected wrapChar: string;
16
+ /**
17
+ * Get placeholder for PostgreSQL ($1, $2, $3...)
18
+ */
19
+ getPlaceholder(index: number): string;
20
+ /**
21
+ * Compile INSERT and return ID using RETURNING clause
22
+ */
23
+ compileInsertGetId(query: CompiledQuery, values: Record<string, unknown>, primaryKey: string): string;
24
+ /**
25
+ * Compile INSERT with RETURNING clause for PostgreSQL
26
+ */
27
+ compileInsert(query: CompiledQuery, values: Record<string, unknown>[]): string;
28
+ /**
29
+ * Compile UPDATE with RETURNING clause for PostgreSQL
30
+ */
31
+ compileUpdate(query: CompiledQuery, values: Record<string, unknown>): string;
32
+ /**
33
+ * Compile TRUNCATE with CASCADE option for PostgreSQL
34
+ */
35
+ compileTruncate(query: CompiledQuery): string;
36
+ /**
37
+ * PostgreSQL-specific: Compile UPSERT using ON CONFLICT
38
+ */
39
+ compileUpsert(query: CompiledQuery, values: Record<string, unknown>[], uniqueBy: string[], update: string[]): string;
40
+ /**
41
+ * PostgreSQL-specific: Compile locking clause
42
+ */
43
+ compileLock(mode: 'update' | 'share'): string;
44
+ /**
45
+ * Override offset placeholders for PostgreSQL
46
+ */
47
+ protected offsetPlaceholders(sql: string, offset: number): string;
48
+ /**
49
+ * Compile a lateral eager load query for PostgreSQL
50
+ */
51
+ compileLateralEagerLoad(_table: string, foreignKey: string, parentKeys: unknown[], query: CompiledQuery): {
52
+ sql: string;
53
+ bindings: unknown[];
54
+ };
55
+ /**
56
+ * Guess the PostgreSQL type for an array of values
57
+ */
58
+ protected guessType(values: unknown[]): string;
59
+ compileJsonPath(column: string, path: string[]): string;
60
+ compileJsonContains(column: string, _value: unknown): string;
61
+ compileUpdateJson(query: CompiledQuery, column: string, _value: unknown): string;
62
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * SQLite Grammar
3
+ * @description SQL grammar implementation for SQLite
4
+ */
5
+ import type { CompiledQuery } from '../types';
6
+ import { Grammar } from './Grammar';
7
+ /**
8
+ * SQLite Grammar
9
+ * Implements SQLite-specific SQL syntax
10
+ */
11
+ export declare class SQLiteGrammar extends Grammar {
12
+ /**
13
+ * SQLite uses double quotes for identifiers
14
+ */
15
+ protected wrapChar: string;
16
+ /**
17
+ * Get placeholder for SQLite (?)
18
+ */
19
+ getPlaceholder(_index: number): string;
20
+ /**
21
+ * Compile INSERT statement with RETURNING *
22
+ */
23
+ compileInsert(query: CompiledQuery, values: Record<string, unknown>[]): string;
24
+ compileInsertGetId(query: CompiledQuery, values: Record<string, unknown>, primaryKey: string): string;
25
+ /**
26
+ * Compile TRUNCATE statement
27
+ * SQLite doesn't have TRUNCATE, use DELETE FROM
28
+ */
29
+ compileTruncate(query: CompiledQuery): string;
30
+ compileJsonPath(column: string, _value: unknown): string;
31
+ compileJsonContains(_column: string, _value: unknown): string;
32
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @gravito/atlas
3
+ * @description The Standard Database Orbit - Custom Query Builder & ORM for Gravito
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * import { DB } from '@gravito/atlas'
8
+ *
9
+ * // Configure
10
+ * DB.addConnection('default', {
11
+ * driver: 'postgres',
12
+ * host: 'localhost',
13
+ * port: 5432,
14
+ * database: 'myapp',
15
+ * username: 'postgres',
16
+ * password: 'secret'
17
+ * })
18
+ *
19
+ * // Query
20
+ * const users = await DB.table('users')
21
+ * .where('status', 'active')
22
+ * .orderBy('created_at', 'desc')
23
+ * .limit(10)
24
+ * .get()
25
+ *
26
+ * // Insert
27
+ * const newUser = await DB.table('users').insert({
28
+ * name: 'John Doe',
29
+ * email: 'john@example.com'
30
+ * })
31
+ *
32
+ * // Update
33
+ * await DB.table('users')
34
+ * .where('id', 1)
35
+ * .update({ name: 'Jane Doe' })
36
+ *
37
+ * // Transaction
38
+ * await DB.transaction(async (db) => {
39
+ * await db.table('accounts').where('id', 1).decrement('balance', 100)
40
+ * await db.table('accounts').where('id', 2).increment('balance', 100)
41
+ * })
42
+ * ```
43
+ */
44
+ export type { AtlasConfig } from './config';
45
+ export { defineConfig, fromEnv, loadConfig, loadConfigFile } from './config';
46
+ export { Connection } from './connection/Connection';
47
+ export { ConnectionManager } from './connection/ConnectionManager';
48
+ export { ReplicaConnectionPool } from './connection/ReplicaConnectionPool';
49
+ export { DB } from './DB';
50
+ import { DB } from './DB';
51
+ export declare const autoConfigure: typeof DB.autoConfigure;
52
+ export { BunSQLDriver } from './drivers/BunSQLDriver';
53
+ export { PostgresDriver } from './drivers/PostgresDriver';
54
+ export { SQLiteDriver } from './drivers/SQLiteDriver';
55
+ export { ConnectionError, ConstraintViolationError, DatabaseError, ForeignKeyConstraintError, NotNullConstraintError, TableNotFoundError, UniqueConstraintError, } from './errors';
56
+ export { Grammar } from './grammar/Grammar';
57
+ export { PostgresGrammar } from './grammar/PostgresGrammar';
58
+ export type { Migration, MigrationFile, MigrationRecord, MigrationResult, MigratorOptions, } from './migration';
59
+ export { MigrationRepository, Migrator } from './migration';
60
+ export { OrbitAtlas } from './OrbitAtlas';
61
+ export type { ColumnSchema as OrmColumnSchema, ModelAttributes, ModelConstructor, ModelStatic, RelationshipMeta, RelationType, SchemaLock, SchemaMode, SchemaRegistryOptions, TableSchema, } 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';
63
+ export { Expression, raw } from './query/Expression';
64
+ export { QueryBuilder, QueryBuilderError, RecordNotFoundError } from './query/QueryBuilder';
65
+ export type { ColumnType, ForeignKeyAction, ForeignKeyDefinition, IndexDefinition } from './schema';
66
+ export { Blueprint, ColumnDefinition, Schema } from './schema';
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';
74
+ export type { FactoryDefinition, Seeder, SeederFile, SeederRunnerOptions } from './seed';
75
+ export { Factory, factory, SeederRunner } from './seed';
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';