@gravito/echo 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/README.md +211 -0
  2. package/dist/atlas/src/DB.d.ts +301 -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 +48 -0
  7. package/dist/atlas/src/connection/Connection.d.ts +108 -0
  8. package/dist/atlas/src/connection/ConnectionManager.d.ts +111 -0
  9. package/dist/atlas/src/drivers/BunSQLDriver.d.ts +32 -0
  10. package/dist/atlas/src/drivers/BunSQLPreparedStatement.d.ts +118 -0
  11. package/dist/atlas/src/drivers/MongoDBDriver.d.ts +36 -0
  12. package/dist/atlas/src/drivers/MySQLDriver.d.ts +66 -0
  13. package/dist/atlas/src/drivers/PostgresDriver.d.ts +83 -0
  14. package/dist/atlas/src/drivers/RedisDriver.d.ts +43 -0
  15. package/dist/atlas/src/drivers/SQLiteDriver.d.ts +45 -0
  16. package/dist/atlas/src/drivers/types.d.ts +260 -0
  17. package/dist/atlas/src/errors/index.d.ts +45 -0
  18. package/dist/atlas/src/grammar/Grammar.d.ts +342 -0
  19. package/dist/atlas/src/grammar/MongoGrammar.d.ts +47 -0
  20. package/dist/atlas/src/grammar/MySQLGrammar.d.ts +54 -0
  21. package/dist/atlas/src/grammar/NullGrammar.d.ts +35 -0
  22. package/dist/atlas/src/grammar/PostgresGrammar.d.ts +62 -0
  23. package/dist/atlas/src/grammar/SQLiteGrammar.d.ts +32 -0
  24. package/dist/atlas/src/index.d.ts +67 -0
  25. package/dist/atlas/src/migration/Migration.d.ts +64 -0
  26. package/dist/atlas/src/migration/MigrationRepository.d.ts +65 -0
  27. package/dist/atlas/src/migration/Migrator.d.ts +110 -0
  28. package/dist/atlas/src/migration/index.d.ts +6 -0
  29. package/dist/atlas/src/observability/AtlasMetrics.d.ts +11 -0
  30. package/dist/atlas/src/observability/AtlasObservability.d.ts +15 -0
  31. package/dist/atlas/src/observability/AtlasTracer.d.ts +12 -0
  32. package/dist/atlas/src/observability/index.d.ts +9 -0
  33. package/dist/atlas/src/orm/index.d.ts +5 -0
  34. package/dist/atlas/src/orm/model/DirtyTracker.d.ts +121 -0
  35. package/dist/atlas/src/orm/model/Model.d.ts +449 -0
  36. package/dist/atlas/src/orm/model/ModelRegistry.d.ts +20 -0
  37. package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +136 -0
  38. package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +36 -0
  39. package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +87 -0
  40. package/dist/atlas/src/orm/model/concerns/HasRelationships.d.ts +117 -0
  41. package/dist/atlas/src/orm/model/concerns/HasSerialization.d.ts +64 -0
  42. package/dist/atlas/src/orm/model/concerns/applyMixins.d.ts +15 -0
  43. package/dist/atlas/src/orm/model/concerns/index.d.ts +12 -0
  44. package/dist/atlas/src/orm/model/decorators.d.ts +109 -0
  45. package/dist/atlas/src/orm/model/errors.d.ts +52 -0
  46. package/dist/atlas/src/orm/model/index.d.ts +10 -0
  47. package/dist/atlas/src/orm/model/relationships.d.ts +207 -0
  48. package/dist/atlas/src/orm/model/types.d.ts +12 -0
  49. package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +123 -0
  50. package/dist/atlas/src/orm/schema/SchemaSniffer.d.ts +54 -0
  51. package/dist/atlas/src/orm/schema/index.d.ts +6 -0
  52. package/dist/atlas/src/orm/schema/types.d.ts +85 -0
  53. package/dist/atlas/src/query/Expression.d.ts +60 -0
  54. package/dist/atlas/src/query/NPlusOneDetector.d.ts +10 -0
  55. package/dist/atlas/src/query/QueryBuilder.d.ts +573 -0
  56. package/dist/atlas/src/query/clauses/GroupByClause.d.ts +51 -0
  57. package/dist/atlas/src/query/clauses/HavingClause.d.ts +70 -0
  58. package/dist/atlas/src/query/clauses/JoinClause.d.ts +87 -0
  59. package/dist/atlas/src/query/clauses/LimitClause.d.ts +82 -0
  60. package/dist/atlas/src/query/clauses/OrderByClause.d.ts +69 -0
  61. package/dist/atlas/src/query/clauses/SelectClause.d.ts +71 -0
  62. package/dist/atlas/src/query/clauses/WhereClause.d.ts +167 -0
  63. package/dist/atlas/src/query/clauses/index.d.ts +11 -0
  64. package/dist/atlas/src/schema/Blueprint.d.ts +276 -0
  65. package/dist/atlas/src/schema/ColumnDefinition.d.ts +154 -0
  66. package/dist/atlas/src/schema/ForeignKeyDefinition.d.ts +37 -0
  67. package/dist/atlas/src/schema/Schema.d.ts +131 -0
  68. package/dist/atlas/src/schema/grammars/MySQLSchemaGrammar.d.ts +23 -0
  69. package/dist/atlas/src/schema/grammars/PostgresSchemaGrammar.d.ts +26 -0
  70. package/dist/atlas/src/schema/grammars/SQLiteSchemaGrammar.d.ts +28 -0
  71. package/dist/atlas/src/schema/grammars/SchemaGrammar.d.ts +97 -0
  72. package/dist/atlas/src/schema/grammars/index.d.ts +7 -0
  73. package/dist/atlas/src/schema/index.d.ts +8 -0
  74. package/dist/atlas/src/seed/Factory.d.ts +90 -0
  75. package/dist/atlas/src/seed/Seeder.d.ts +28 -0
  76. package/dist/atlas/src/seed/SeederRunner.d.ts +74 -0
  77. package/dist/atlas/src/seed/index.d.ts +6 -0
  78. package/dist/atlas/src/types/index.d.ts +1100 -0
  79. package/dist/atlas/src/utils/levenshtein.d.ts +9 -0
  80. package/dist/core/src/Application.d.ts +215 -0
  81. package/dist/core/src/CommandKernel.d.ts +33 -0
  82. package/dist/core/src/ConfigManager.d.ts +26 -0
  83. package/dist/core/src/Container.d.ts +108 -0
  84. package/dist/core/src/ErrorHandler.d.ts +63 -0
  85. package/dist/core/src/Event.d.ts +5 -0
  86. package/dist/core/src/EventManager.d.ts +123 -0
  87. package/dist/core/src/GlobalErrorHandlers.d.ts +47 -0
  88. package/dist/core/src/GravitoServer.d.ts +28 -0
  89. package/dist/core/src/HookManager.d.ts +496 -0
  90. package/dist/core/src/Listener.d.ts +4 -0
  91. package/dist/core/src/Logger.d.ts +20 -0
  92. package/dist/core/src/PlanetCore.d.ts +289 -0
  93. package/dist/core/src/Route.d.ts +36 -0
  94. package/dist/core/src/Router.d.ts +284 -0
  95. package/dist/core/src/ServiceProvider.d.ts +156 -0
  96. package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +27 -0
  97. package/dist/core/src/adapters/PhotonAdapter.d.ts +171 -0
  98. package/dist/core/src/adapters/bun/BunContext.d.ts +45 -0
  99. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +31 -0
  100. package/dist/core/src/adapters/bun/BunRequest.d.ts +31 -0
  101. package/dist/core/src/adapters/bun/RadixNode.d.ts +19 -0
  102. package/dist/core/src/adapters/bun/RadixRouter.d.ts +31 -0
  103. package/dist/core/src/adapters/bun/types.d.ts +20 -0
  104. package/dist/core/src/adapters/photon-types.d.ts +73 -0
  105. package/dist/core/src/adapters/types.d.ts +235 -0
  106. package/dist/core/src/engine/AOTRouter.d.ts +124 -0
  107. package/dist/core/src/engine/FastContext.d.ts +100 -0
  108. package/dist/core/src/engine/Gravito.d.ts +137 -0
  109. package/dist/core/src/engine/MinimalContext.d.ts +79 -0
  110. package/dist/core/src/engine/analyzer.d.ts +27 -0
  111. package/dist/core/src/engine/constants.d.ts +23 -0
  112. package/dist/core/src/engine/index.d.ts +26 -0
  113. package/dist/core/src/engine/path.d.ts +26 -0
  114. package/dist/core/src/engine/pool.d.ts +83 -0
  115. package/dist/core/src/engine/types.d.ts +143 -0
  116. package/dist/core/src/events/CircuitBreaker.d.ts +229 -0
  117. package/dist/core/src/events/DeadLetterQueue.d.ts +145 -0
  118. package/dist/core/src/events/EventBackend.d.ts +11 -0
  119. package/dist/core/src/events/EventOptions.d.ts +109 -0
  120. package/dist/core/src/events/EventPriorityQueue.d.ts +202 -0
  121. package/dist/core/src/events/IdempotencyCache.d.ts +60 -0
  122. package/dist/core/src/events/index.d.ts +14 -0
  123. package/dist/core/src/events/observability/EventMetrics.d.ts +132 -0
  124. package/dist/core/src/events/observability/EventTracer.d.ts +68 -0
  125. package/dist/core/src/events/observability/EventTracing.d.ts +161 -0
  126. package/dist/core/src/events/observability/OTelEventMetrics.d.ts +240 -0
  127. package/dist/core/src/events/observability/ObservableHookManager.d.ts +108 -0
  128. package/dist/core/src/events/observability/index.d.ts +20 -0
  129. package/dist/core/src/events/observability/metrics-types.d.ts +16 -0
  130. package/dist/core/src/events/types.d.ts +75 -0
  131. package/dist/core/src/exceptions/AuthenticationException.d.ts +8 -0
  132. package/dist/core/src/exceptions/AuthorizationException.d.ts +8 -0
  133. package/dist/core/src/exceptions/CircularDependencyException.d.ts +9 -0
  134. package/dist/core/src/exceptions/GravitoException.d.ts +23 -0
  135. package/dist/core/src/exceptions/HttpException.d.ts +9 -0
  136. package/dist/core/src/exceptions/ModelNotFoundException.d.ts +10 -0
  137. package/dist/core/src/exceptions/ValidationException.d.ts +22 -0
  138. package/dist/core/src/exceptions/index.d.ts +7 -0
  139. package/dist/core/src/helpers/Arr.d.ts +19 -0
  140. package/dist/core/src/helpers/Str.d.ts +23 -0
  141. package/dist/core/src/helpers/data.d.ts +25 -0
  142. package/dist/core/src/helpers/errors.d.ts +34 -0
  143. package/dist/core/src/helpers/response.d.ts +41 -0
  144. package/dist/core/src/helpers.d.ts +338 -0
  145. package/dist/core/src/http/CookieJar.d.ts +51 -0
  146. package/dist/core/src/http/cookie.d.ts +29 -0
  147. package/dist/core/src/http/middleware/BodySizeLimit.d.ts +16 -0
  148. package/dist/core/src/http/middleware/Cors.d.ts +24 -0
  149. package/dist/core/src/http/middleware/Csrf.d.ts +23 -0
  150. package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +28 -0
  151. package/dist/core/src/http/middleware/SecurityHeaders.d.ts +29 -0
  152. package/dist/core/src/http/middleware/ThrottleRequests.d.ts +18 -0
  153. package/dist/core/src/http/types.d.ts +355 -0
  154. package/dist/core/src/index.d.ts +76 -0
  155. package/dist/core/src/instrumentation/index.d.ts +35 -0
  156. package/dist/core/src/instrumentation/opentelemetry.d.ts +178 -0
  157. package/dist/core/src/instrumentation/types.d.ts +182 -0
  158. package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +316 -0
  159. package/dist/core/src/reliability/RetryPolicy.d.ts +217 -0
  160. package/dist/core/src/reliability/index.d.ts +6 -0
  161. package/dist/core/src/router/ControllerDispatcher.d.ts +12 -0
  162. package/dist/core/src/router/RequestValidator.d.ts +20 -0
  163. package/dist/core/src/runtime.d.ts +119 -0
  164. package/dist/core/src/security/Encrypter.d.ts +33 -0
  165. package/dist/core/src/security/Hasher.d.ts +29 -0
  166. package/dist/core/src/testing/HttpTester.d.ts +39 -0
  167. package/dist/core/src/testing/TestResponse.d.ts +78 -0
  168. package/dist/core/src/testing/index.d.ts +2 -0
  169. package/dist/core/src/types/events.d.ts +94 -0
  170. package/dist/echo/src/OrbitEcho.d.ts +115 -0
  171. package/dist/echo/src/dlq/DeadLetterQueue.d.ts +94 -0
  172. package/dist/echo/src/dlq/MemoryDeadLetterQueue.d.ts +36 -0
  173. package/dist/echo/src/dlq/index.d.ts +2 -0
  174. package/dist/echo/src/index.d.ts +64 -0
  175. package/dist/echo/src/middleware/RequestBufferMiddleware.d.ts +62 -0
  176. package/dist/echo/src/middleware/index.d.ts +8 -0
  177. package/dist/echo/src/observability/index.d.ts +3 -0
  178. package/dist/echo/src/observability/logging/ConsoleEchoLogger.d.ts +37 -0
  179. package/dist/echo/src/observability/logging/EchoLogger.d.ts +38 -0
  180. package/dist/echo/src/observability/logging/index.d.ts +2 -0
  181. package/dist/echo/src/observability/metrics/MetricsProvider.d.ts +69 -0
  182. package/dist/echo/src/observability/metrics/NoopMetricsProvider.d.ts +17 -0
  183. package/dist/echo/src/observability/metrics/PrometheusMetricsProvider.d.ts +39 -0
  184. package/dist/echo/src/observability/metrics/index.d.ts +3 -0
  185. package/dist/echo/src/observability/tracing/NoopTracer.d.ts +33 -0
  186. package/dist/echo/src/observability/tracing/Tracer.d.ts +75 -0
  187. package/dist/echo/src/observability/tracing/index.d.ts +2 -0
  188. package/dist/echo/src/providers/GenericProvider.d.ts +53 -0
  189. package/dist/echo/src/providers/GitHubProvider.d.ts +35 -0
  190. package/dist/echo/src/providers/LinearProvider.d.ts +27 -0
  191. package/dist/echo/src/providers/PaddleProvider.d.ts +31 -0
  192. package/dist/echo/src/providers/ShopifyProvider.d.ts +27 -0
  193. package/dist/echo/src/providers/SlackProvider.d.ts +27 -0
  194. package/dist/echo/src/providers/StripeProvider.d.ts +38 -0
  195. package/dist/echo/src/providers/TwilioProvider.d.ts +31 -0
  196. package/dist/echo/src/providers/base/BaseProvider.d.ts +87 -0
  197. package/dist/echo/src/providers/base/HeaderUtils.d.ts +34 -0
  198. package/dist/echo/src/providers/index.d.ts +14 -0
  199. package/dist/echo/src/receive/SignatureValidator.d.ts +67 -0
  200. package/dist/echo/src/receive/WebhookReceiver.d.ts +185 -0
  201. package/dist/echo/src/receive/index.d.ts +2 -0
  202. package/dist/echo/src/replay/WebhookReplayService.d.ts +35 -0
  203. package/dist/echo/src/replay/index.d.ts +1 -0
  204. package/dist/echo/src/resilience/CircuitBreaker.d.ts +117 -0
  205. package/dist/echo/src/resilience/index.d.ts +10 -0
  206. package/dist/echo/src/rotation/KeyRotationManager.d.ts +127 -0
  207. package/dist/echo/src/rotation/index.d.ts +10 -0
  208. package/dist/echo/src/send/WebhookDispatcher.d.ts +198 -0
  209. package/dist/echo/src/send/index.d.ts +1 -0
  210. package/dist/echo/src/storage/MemoryWebhookStore.d.ts +14 -0
  211. package/dist/echo/src/storage/WebhookStore.d.ts +236 -0
  212. package/dist/echo/src/storage/index.d.ts +2 -0
  213. package/dist/echo/src/types.d.ts +756 -0
  214. package/dist/index.js +1332 -190
  215. package/dist/index.js.map +28 -10
  216. package/dist/photon/src/index.d.ts +84 -0
  217. package/dist/photon/src/middleware/binary.d.ts +31 -0
  218. package/dist/photon/src/middleware/htmx.d.ts +39 -0
  219. package/dist/photon/src/middleware/ratelimit.d.ts +157 -0
  220. package/dist/photon/src/openapi.d.ts +19 -0
  221. package/package.json +7 -5
@@ -0,0 +1,260 @@
1
+ /**
2
+ * Driver Type Definitions
3
+ * @description Type definitions for third-party database driver libraries
4
+ */
5
+ /**
6
+ * MySQL/MariaDB Pool Connection
7
+ */
8
+ export interface MySQLPool {
9
+ query(sql: string, values?: unknown[]): Promise<unknown>;
10
+ execute(sql: string, values?: unknown[]): Promise<unknown>;
11
+ getConnection(): Promise<MySQLConnection>;
12
+ end(): Promise<void>;
13
+ }
14
+ /**
15
+ * MySQL/MariaDB Connection
16
+ */
17
+ export interface MySQLConnection {
18
+ query(sql: string, values?: unknown[]): Promise<unknown>;
19
+ execute(sql: string, values?: unknown[]): Promise<unknown>;
20
+ beginTransaction(): Promise<void>;
21
+ commit(): Promise<void>;
22
+ rollback(): Promise<void>;
23
+ release(): void;
24
+ }
25
+ /**
26
+ * MySQL/MariaDB Module
27
+ */
28
+ export interface MySQLModule {
29
+ createPool(config: Record<string, unknown>): MySQLPool;
30
+ createConnection(config: Record<string, unknown>): Promise<MySQLConnection>;
31
+ }
32
+ /**
33
+ * PostgreSQL Pool Client
34
+ */
35
+ export interface PostgresPoolClient {
36
+ query(sql: string, values?: unknown[]): Promise<{
37
+ rows: unknown[];
38
+ rowCount: number;
39
+ }>;
40
+ release(): void;
41
+ }
42
+ /**
43
+ * PostgreSQL Pool
44
+ */
45
+ export interface PostgresPool {
46
+ connect(): Promise<PostgresPoolClient>;
47
+ query(sql: string, values?: unknown[]): Promise<{
48
+ rows: unknown[];
49
+ rowCount: number;
50
+ }>;
51
+ end(): Promise<void>;
52
+ }
53
+ /**
54
+ * SQLite Database Client (Bun)
55
+ */
56
+ export interface SQLiteClient {
57
+ prepare(sql: string): SQLiteStatement;
58
+ query(sql: string, ...params: unknown[]): unknown[];
59
+ run(sql: string, ...params: unknown[]): {
60
+ changes: number;
61
+ lastInsertRowid: number;
62
+ };
63
+ exec?(sql: string): void;
64
+ pragma?(name: string, value?: unknown): unknown;
65
+ open?: boolean;
66
+ inTransaction?: boolean;
67
+ close(): void;
68
+ }
69
+ /**
70
+ * SQLite Statement
71
+ */
72
+ export interface SQLiteStatement {
73
+ run(...params: unknown[]): {
74
+ changes: number;
75
+ lastInsertRowid: number;
76
+ };
77
+ all(...params: unknown[]): unknown[];
78
+ get(...params: unknown[]): unknown;
79
+ }
80
+ /**
81
+ * Redis Client
82
+ */
83
+ export interface RedisClient {
84
+ connect(): Promise<void>;
85
+ get(key: string): Promise<string | null>;
86
+ set(key: string, value: string | number): Promise<'OK'>;
87
+ setex(key: string, seconds: number, value: string | number): Promise<'OK'>;
88
+ del(key: string): Promise<number>;
89
+ keys(pattern: string): Promise<string[]>;
90
+ exists(key: string): Promise<number>;
91
+ expire(key: string, seconds: number): Promise<number>;
92
+ quit(): Promise<void>;
93
+ status?: string;
94
+ }
95
+ /**
96
+ * MongoDB Client
97
+ */
98
+ export interface MongoClient {
99
+ connect(): Promise<void>;
100
+ db(name?: string): MongoDatabase;
101
+ close(): Promise<void>;
102
+ }
103
+ /**
104
+ * MongoDB Database
105
+ */
106
+ export interface MongoDatabase {
107
+ collection(name: string): MongoCollection;
108
+ }
109
+ /**
110
+ * MongoDB Collection
111
+ */
112
+ export interface MongoCollection {
113
+ find(filter?: Record<string, unknown>, options?: Record<string, unknown>): MongoCursor;
114
+ findOne(filter?: Record<string, unknown>): Promise<Record<string, unknown> | null>;
115
+ insertOne(doc: Record<string, unknown>): Promise<{
116
+ insertedId: unknown;
117
+ }>;
118
+ insertMany(docs: Record<string, unknown>[]): Promise<{
119
+ insertedIds: unknown[];
120
+ insertedCount: number;
121
+ }>;
122
+ countDocuments(filter?: Record<string, unknown>): Promise<number>;
123
+ updateOne(filter: Record<string, unknown>, update: Record<string, unknown>): Promise<{
124
+ modifiedCount: number;
125
+ }>;
126
+ updateMany(filter: Record<string, unknown>, update: Record<string, unknown>): Promise<{
127
+ modifiedCount: number;
128
+ }>;
129
+ deleteOne(filter: Record<string, unknown>): Promise<{
130
+ deletedCount: number;
131
+ }>;
132
+ deleteMany(filter: Record<string, unknown>): Promise<{
133
+ deletedCount: number;
134
+ }>;
135
+ }
136
+ /**
137
+ * MongoDB Cursor
138
+ */
139
+ export interface MongoCursor {
140
+ toArray(): Promise<Record<string, unknown>[]>;
141
+ limit(n: number): MongoCursor;
142
+ skip(n: number): MongoCursor;
143
+ sort(sort: Record<string, 1 | -1>): MongoCursor;
144
+ }
145
+ /**
146
+ * Bun SQL Client (Enhanced for Bun 1.3+)
147
+ * @description Comprehensive type definitions for Bun.sql native driver
148
+ */
149
+ export interface BunSQLClient {
150
+ (strings: TemplateStringsArray, ...values: unknown[]): Promise<BunSQLResult>;
151
+ unsafe?(sql: string, bindings?: unknown[]): Promise<BunSQLResult>;
152
+ query?(sql: string, bindings?: unknown[]): Promise<BunSQLResult>;
153
+ all?(sql: string, bindings?: unknown[]): Promise<unknown[]>;
154
+ run?(sql: string, bindings?: unknown[]): Promise<BunSQLResult>;
155
+ simple?(strings: TemplateStringsArray, ...values: unknown[]): Promise<BunSQLResult>;
156
+ prepare?(sql: string): BunSQLPreparedStatement;
157
+ transaction?<T>(callback: (sql: BunSQLClient) => Promise<T>): Promise<T>;
158
+ begin?(): Promise<BunSQLTransaction>;
159
+ close?(): Promise<void>;
160
+ end?(): Promise<void>;
161
+ readonly connections?: {
162
+ idle: number;
163
+ pending: number;
164
+ active: number;
165
+ total: number;
166
+ };
167
+ }
168
+ /**
169
+ * Bun SQL Query Result
170
+ * @description Result structure returned by Bun.sql queries
171
+ */
172
+ export interface BunSQLResult {
173
+ /**
174
+ * Result rows (iterable)
175
+ */
176
+ rows?: unknown[];
177
+ /**
178
+ * Number of rows affected/returned
179
+ */
180
+ rowCount?: number;
181
+ count?: number;
182
+ /**
183
+ * Last inserted ID (for INSERT operations)
184
+ */
185
+ lastInsertRowid?: number | bigint;
186
+ /**
187
+ * Number of changed rows (for UPDATE operations)
188
+ */
189
+ changes?: number;
190
+ /**
191
+ * Iterator support for streaming
192
+ */
193
+ [Symbol.iterator](): Iterator<unknown>;
194
+ }
195
+ /**
196
+ * Bun SQL Prepared Statement
197
+ * @description Prepared statement interface for query optimization
198
+ */
199
+ export interface BunSQLPreparedStatement {
200
+ /**
201
+ * Execute prepared statement and return result
202
+ */
203
+ run(...params: unknown[]): Promise<BunSQLResult>;
204
+ /**
205
+ * Execute and return all rows
206
+ */
207
+ all(...params: unknown[]): Promise<unknown[]>;
208
+ /**
209
+ * Execute and return first row
210
+ */
211
+ get(...params: unknown[]): Promise<unknown | undefined>;
212
+ /**
213
+ * Finalize and release the prepared statement
214
+ */
215
+ finalize(): void;
216
+ }
217
+ /**
218
+ * Bun SQL Transaction
219
+ * @description Transaction handle for advanced transaction control
220
+ */
221
+ export interface BunSQLTransaction {
222
+ /**
223
+ * Commit the transaction
224
+ */
225
+ commit(): Promise<void>;
226
+ /**
227
+ * Rollback the transaction
228
+ */
229
+ rollback(): Promise<void>;
230
+ /**
231
+ * Create a savepoint
232
+ */
233
+ savepoint?(name: string): Promise<void>;
234
+ /**
235
+ * Rollback to a savepoint
236
+ */
237
+ rollbackTo?(name: string): Promise<void>;
238
+ /**
239
+ * Release a savepoint
240
+ */
241
+ release?(name: string): Promise<void>;
242
+ }
243
+ /**
244
+ * Bun SQL Pool Configuration
245
+ * @description Configuration options for connection pool
246
+ */
247
+ export interface BunSQLPoolConfig {
248
+ /**
249
+ * Maximum number of connections in the pool
250
+ */
251
+ max?: number;
252
+ /**
253
+ * Maximum time (ms) a connection can be idle before being released
254
+ */
255
+ idleTimeout?: number;
256
+ /**
257
+ * Maximum time (ms) to wait for a connection from the pool
258
+ */
259
+ connectionTimeout?: number;
260
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Base Database Error
3
+ */
4
+ export declare class DatabaseError extends Error {
5
+ readonly originalError: unknown;
6
+ readonly query?: string;
7
+ readonly bindings?: unknown[];
8
+ constructor(message: string, originalError?: unknown, query?: string, bindings?: unknown[]);
9
+ }
10
+ /**
11
+ * Constraint Violation Error (Base)
12
+ */
13
+ export declare class ConstraintViolationError extends DatabaseError {
14
+ constructor(message: string, originalError?: unknown, query?: string, bindings?: unknown[]);
15
+ }
16
+ /**
17
+ * Unique Constraint Violation
18
+ */
19
+ export declare class UniqueConstraintError extends ConstraintViolationError {
20
+ constructor(message: string, originalError?: unknown, query?: string, bindings?: unknown[]);
21
+ }
22
+ /**
23
+ * Foreign Key Constraint Violation
24
+ */
25
+ export declare class ForeignKeyConstraintError extends ConstraintViolationError {
26
+ constructor(message: string, originalError?: unknown, query?: string, bindings?: unknown[]);
27
+ }
28
+ /**
29
+ * Not Null Constraint Violation
30
+ */
31
+ export declare class NotNullConstraintError extends ConstraintViolationError {
32
+ constructor(message: string, originalError?: unknown, query?: string, bindings?: unknown[]);
33
+ }
34
+ /**
35
+ * Table Not Found Error
36
+ */
37
+ export declare class TableNotFoundError extends DatabaseError {
38
+ constructor(message: string, originalError?: unknown, query?: string, bindings?: unknown[]);
39
+ }
40
+ /**
41
+ * Connection Error
42
+ */
43
+ export declare class ConnectionError extends DatabaseError {
44
+ constructor(message: string, originalError?: unknown);
45
+ }
@@ -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
+ }