@gravito/ripple 4.0.1 → 5.0.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 (226) hide show
  1. package/README.md +26 -10
  2. package/dist/{ripple/src/OrbitRipple.d.ts → OrbitRipple.d.ts} +1 -0
  3. package/dist/{ripple/src/RippleServer.d.ts → RippleServer.d.ts} +32 -1
  4. package/dist/core/src/Application.d.ts +41 -0
  5. package/dist/core/src/HookManager.d.ts +33 -189
  6. package/dist/core/src/PlanetCore.d.ts +31 -1
  7. package/dist/core/src/Router.d.ts +32 -46
  8. package/dist/core/src/adapters/bun/BunContext.d.ts +6 -1
  9. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +35 -0
  10. package/dist/core/src/adapters/bun/BunWebSocketHandler.d.ts +48 -0
  11. package/dist/core/src/adapters/bun/RadixRouter.d.ts +1 -0
  12. package/dist/core/src/adapters/bun/index.d.ts +7 -0
  13. package/dist/core/src/binary/BinaryUtils.d.ts +105 -0
  14. package/dist/core/src/binary/index.d.ts +5 -0
  15. package/dist/core/src/compat/async-local-storage.d.ts +7 -0
  16. package/dist/core/src/compat/crypto.d.ts +6 -0
  17. package/dist/core/src/engine/AOTRouter.d.ts +10 -0
  18. package/dist/core/src/engine/FastContext.d.ts +19 -1
  19. package/dist/core/src/engine/Gravito.d.ts +13 -18
  20. package/dist/core/src/engine/MinimalContext.d.ts +2 -0
  21. package/dist/core/src/engine/analyzer.d.ts +92 -6
  22. package/dist/core/src/engine/types.d.ts +3 -0
  23. package/dist/core/src/events/CircuitBreaker.d.ts +12 -0
  24. package/dist/core/src/events/EventPriorityQueue.d.ts +18 -256
  25. package/dist/core/src/events/index.d.ts +12 -11
  26. package/dist/core/src/events/queue-core.d.ts +77 -0
  27. package/dist/core/src/events/task-executor.d.ts +51 -0
  28. package/dist/core/src/exceptions/AuthException.d.ts +10 -0
  29. package/dist/core/src/exceptions/AuthenticationException.d.ts +2 -2
  30. package/dist/core/src/exceptions/AuthorizationException.d.ts +2 -2
  31. package/dist/core/src/exceptions/CacheException.d.ts +9 -0
  32. package/dist/core/src/exceptions/CircularDependencyException.d.ts +2 -1
  33. package/dist/core/src/exceptions/ConfigurationException.d.ts +9 -0
  34. package/dist/core/src/exceptions/DatabaseException.d.ts +9 -0
  35. package/dist/core/src/exceptions/DomainException.d.ts +9 -0
  36. package/dist/core/src/exceptions/InfrastructureException.d.ts +17 -0
  37. package/dist/core/src/exceptions/QueueException.d.ts +9 -0
  38. package/dist/core/src/exceptions/StorageException.d.ts +9 -0
  39. package/dist/core/src/exceptions/StreamException.d.ts +9 -0
  40. package/dist/core/src/exceptions/SystemException.d.ts +9 -0
  41. package/dist/core/src/exceptions/ValidationException.d.ts +2 -2
  42. package/dist/core/src/exceptions/index.d.ts +10 -0
  43. package/dist/core/src/ffi/NativeAccelerator.d.ts +62 -0
  44. package/dist/core/src/ffi/NativeHasher.d.ts +139 -0
  45. package/dist/core/src/ffi/cbor-fallback.d.ts +96 -0
  46. package/dist/core/src/ffi/hash-fallback.d.ts +33 -0
  47. package/dist/core/src/ffi/index.d.ts +10 -0
  48. package/dist/core/src/ffi/types.d.ts +135 -0
  49. package/dist/core/src/helpers/Str.d.ts +15 -0
  50. package/dist/core/src/hooks/ActionManager.d.ts +132 -0
  51. package/dist/core/src/hooks/AsyncDetector.d.ts +84 -0
  52. package/dist/core/src/hooks/FilterManager.d.ts +71 -0
  53. package/dist/core/src/hooks/MigrationWarner.d.ts +24 -0
  54. package/dist/core/src/hooks/dlq-operations.d.ts +60 -0
  55. package/dist/core/src/hooks/types.d.ts +107 -0
  56. package/dist/core/src/http/CookieJar.d.ts +2 -2
  57. package/dist/core/src/http/types.d.ts +24 -3
  58. package/dist/core/src/index.d.ts +491 -14
  59. package/dist/core/src/observability/contracts.d.ts +137 -0
  60. package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +2 -3
  61. package/dist/core/src/runtime/adapter-bun.d.ts +12 -0
  62. package/dist/core/src/runtime/adapter-deno.d.ts +12 -0
  63. package/dist/core/src/runtime/adapter-node.d.ts +12 -0
  64. package/dist/core/src/runtime/adapter-unknown.d.ts +13 -0
  65. package/dist/core/src/runtime/archive.d.ts +17 -0
  66. package/dist/core/src/runtime/compression.d.ts +21 -0
  67. package/dist/core/src/runtime/deep-equals.d.ts +56 -0
  68. package/dist/core/src/runtime/detection.d.ts +22 -0
  69. package/dist/core/src/runtime/escape.d.ts +34 -0
  70. package/dist/core/src/runtime/index.d.ts +44 -0
  71. package/dist/core/src/runtime/markdown.d.ts +44 -0
  72. package/dist/core/src/runtime/types.d.ts +436 -0
  73. package/dist/core/src/runtime-helpers.d.ts +67 -0
  74. package/dist/core/src/runtime.d.ts +10 -118
  75. package/dist/core/src/testing/HttpTester.d.ts +1 -0
  76. package/dist/core/src/transpiler-utils.d.ts +170 -0
  77. package/dist/{ripple/src/engines → engines}/BunEngine.d.ts +11 -0
  78. package/dist/errors/RippleError.d.ts +66 -0
  79. package/dist/index.js +1 -7502
  80. package/dist/index.js.map +3 -71
  81. package/package.json +6 -2
  82. package/dist/atlas/src/DB.d.ts +0 -348
  83. package/dist/atlas/src/OrbitAtlas.d.ts +0 -9
  84. package/dist/atlas/src/config/defineConfig.d.ts +0 -14
  85. package/dist/atlas/src/config/index.d.ts +0 -7
  86. package/dist/atlas/src/config/loadConfig.d.ts +0 -41
  87. package/dist/atlas/src/connection/Connection.d.ts +0 -112
  88. package/dist/atlas/src/connection/ConnectionManager.d.ts +0 -180
  89. package/dist/atlas/src/connection/ReplicaConnectionPool.d.ts +0 -54
  90. package/dist/atlas/src/drivers/BunSQLDriver.d.ts +0 -32
  91. package/dist/atlas/src/drivers/BunSQLPreparedStatement.d.ts +0 -118
  92. package/dist/atlas/src/drivers/MongoDBDriver.d.ts +0 -36
  93. package/dist/atlas/src/drivers/MySQLDriver.d.ts +0 -79
  94. package/dist/atlas/src/drivers/PostgresDriver.d.ts +0 -96
  95. package/dist/atlas/src/drivers/RedisDriver.d.ts +0 -43
  96. package/dist/atlas/src/drivers/SQLiteDriver.d.ts +0 -45
  97. package/dist/atlas/src/drivers/types.d.ts +0 -260
  98. package/dist/atlas/src/errors/index.d.ts +0 -45
  99. package/dist/atlas/src/grammar/Grammar.d.ts +0 -342
  100. package/dist/atlas/src/grammar/MongoGrammar.d.ts +0 -47
  101. package/dist/atlas/src/grammar/MySQLGrammar.d.ts +0 -54
  102. package/dist/atlas/src/grammar/NullGrammar.d.ts +0 -35
  103. package/dist/atlas/src/grammar/PostgresGrammar.d.ts +0 -62
  104. package/dist/atlas/src/grammar/SQLiteGrammar.d.ts +0 -32
  105. package/dist/atlas/src/index.d.ts +0 -79
  106. package/dist/atlas/src/migration/Migration.d.ts +0 -64
  107. package/dist/atlas/src/migration/MigrationRepository.d.ts +0 -65
  108. package/dist/atlas/src/migration/Migrator.d.ts +0 -110
  109. package/dist/atlas/src/migration/index.d.ts +0 -6
  110. package/dist/atlas/src/observability/AtlasMetrics.d.ts +0 -33
  111. package/dist/atlas/src/observability/AtlasObservability.d.ts +0 -15
  112. package/dist/atlas/src/observability/AtlasTracer.d.ts +0 -12
  113. package/dist/atlas/src/observability/index.d.ts +0 -9
  114. package/dist/atlas/src/orm/Repository.d.ts +0 -247
  115. package/dist/atlas/src/orm/index.d.ts +0 -6
  116. package/dist/atlas/src/orm/model/DirtyTracker.d.ts +0 -121
  117. package/dist/atlas/src/orm/model/Model.d.ts +0 -458
  118. package/dist/atlas/src/orm/model/ModelRegistry.d.ts +0 -20
  119. package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +0 -150
  120. package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +0 -36
  121. package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +0 -92
  122. package/dist/atlas/src/orm/model/concerns/HasRelationships.d.ts +0 -117
  123. package/dist/atlas/src/orm/model/concerns/HasSerialization.d.ts +0 -64
  124. package/dist/atlas/src/orm/model/concerns/applyMixins.d.ts +0 -15
  125. package/dist/atlas/src/orm/model/concerns/index.d.ts +0 -12
  126. package/dist/atlas/src/orm/model/decorators.d.ts +0 -138
  127. package/dist/atlas/src/orm/model/errors.d.ts +0 -52
  128. package/dist/atlas/src/orm/model/index.d.ts +0 -10
  129. package/dist/atlas/src/orm/model/relationships.d.ts +0 -207
  130. package/dist/atlas/src/orm/model/types.d.ts +0 -12
  131. package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +0 -124
  132. package/dist/atlas/src/orm/schema/SchemaSniffer.d.ts +0 -54
  133. package/dist/atlas/src/orm/schema/index.d.ts +0 -6
  134. package/dist/atlas/src/orm/schema/types.d.ts +0 -85
  135. package/dist/atlas/src/pool/AdaptivePoolManager.d.ts +0 -98
  136. package/dist/atlas/src/pool/PoolHealthChecker.d.ts +0 -91
  137. package/dist/atlas/src/pool/PoolStrategy.d.ts +0 -129
  138. package/dist/atlas/src/pool/PoolWarmer.d.ts +0 -92
  139. package/dist/atlas/src/query/Expression.d.ts +0 -60
  140. package/dist/atlas/src/query/NPlusOneDetector.d.ts +0 -10
  141. package/dist/atlas/src/query/QueryBuilder.d.ts +0 -643
  142. package/dist/atlas/src/query/RelationshipResolver.d.ts +0 -23
  143. package/dist/atlas/src/query/clauses/GroupByClause.d.ts +0 -51
  144. package/dist/atlas/src/query/clauses/HavingClause.d.ts +0 -70
  145. package/dist/atlas/src/query/clauses/JoinClause.d.ts +0 -87
  146. package/dist/atlas/src/query/clauses/LimitClause.d.ts +0 -82
  147. package/dist/atlas/src/query/clauses/OrderByClause.d.ts +0 -69
  148. package/dist/atlas/src/query/clauses/SelectClause.d.ts +0 -71
  149. package/dist/atlas/src/query/clauses/WhereClause.d.ts +0 -167
  150. package/dist/atlas/src/query/clauses/index.d.ts +0 -11
  151. package/dist/atlas/src/schema/Blueprint.d.ts +0 -276
  152. package/dist/atlas/src/schema/ColumnDefinition.d.ts +0 -154
  153. package/dist/atlas/src/schema/ForeignKeyDefinition.d.ts +0 -37
  154. package/dist/atlas/src/schema/MigrationGenerator.d.ts +0 -45
  155. package/dist/atlas/src/schema/Schema.d.ts +0 -131
  156. package/dist/atlas/src/schema/SchemaDiff.d.ts +0 -73
  157. package/dist/atlas/src/schema/TypeGenerator.d.ts +0 -57
  158. package/dist/atlas/src/schema/TypeWriter.d.ts +0 -42
  159. package/dist/atlas/src/schema/grammars/MySQLSchemaGrammar.d.ts +0 -23
  160. package/dist/atlas/src/schema/grammars/PostgresSchemaGrammar.d.ts +0 -26
  161. package/dist/atlas/src/schema/grammars/SQLiteSchemaGrammar.d.ts +0 -28
  162. package/dist/atlas/src/schema/grammars/SchemaGrammar.d.ts +0 -97
  163. package/dist/atlas/src/schema/grammars/index.d.ts +0 -7
  164. package/dist/atlas/src/schema/index.d.ts +0 -8
  165. package/dist/atlas/src/seed/Factory.d.ts +0 -90
  166. package/dist/atlas/src/seed/Seeder.d.ts +0 -28
  167. package/dist/atlas/src/seed/SeederRunner.d.ts +0 -74
  168. package/dist/atlas/src/seed/index.d.ts +0 -6
  169. package/dist/atlas/src/sharding/ShardingManager.d.ts +0 -59
  170. package/dist/atlas/src/types/index.d.ts +0 -1182
  171. package/dist/atlas/src/utils/CursorEncoding.d.ts +0 -63
  172. package/dist/atlas/src/utils/levenshtein.d.ts +0 -9
  173. package/dist/core/src/adapters/PhotonAdapter.d.ts +0 -175
  174. package/dist/core/src/adapters/photon-types.d.ts +0 -73
  175. package/dist/core/src/http/middleware/BodySizeLimit.d.ts +0 -16
  176. package/dist/core/src/http/middleware/Cors.d.ts +0 -24
  177. package/dist/core/src/http/middleware/Csrf.d.ts +0 -23
  178. package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +0 -28
  179. package/dist/core/src/http/middleware/SecurityHeaders.d.ts +0 -29
  180. package/dist/core/src/http/middleware/ThrottleRequests.d.ts +0 -18
  181. package/dist/core/src/instrumentation/index.d.ts +0 -35
  182. package/dist/core/src/instrumentation/opentelemetry.d.ts +0 -178
  183. package/dist/core/src/instrumentation/types.d.ts +0 -182
  184. package/dist/core/src/observability/Metrics.d.ts +0 -244
  185. package/dist/photon/src/index.d.ts +0 -89
  186. package/dist/photon/src/middleware/binary.d.ts +0 -31
  187. package/dist/photon/src/middleware/htmx.d.ts +0 -39
  188. package/dist/photon/src/middleware/ratelimit-redis.d.ts +0 -50
  189. package/dist/photon/src/middleware/ratelimit.d.ts +0 -161
  190. package/dist/photon/src/openapi.d.ts +0 -19
  191. package/dist/ripple/src/errors/RippleError.d.ts +0 -48
  192. /package/dist/{ripple/src/channels → channels}/Channel.d.ts +0 -0
  193. /package/dist/{ripple/src/channels → channels}/ChannelManager.d.ts +0 -0
  194. /package/dist/{ripple/src/channels → channels}/index.d.ts +0 -0
  195. /package/dist/{ripple/src/drivers → drivers}/LocalDriver.d.ts +0 -0
  196. /package/dist/{ripple/src/drivers → drivers}/NATSDriver.d.ts +0 -0
  197. /package/dist/{ripple/src/drivers → drivers}/RedisDriver.d.ts +0 -0
  198. /package/dist/{ripple/src/drivers → drivers}/index.d.ts +0 -0
  199. /package/dist/{ripple/src/engines → engines}/IRippleEngine.d.ts +0 -0
  200. /package/dist/{ripple/src/engines → engines}/UWebSocketsEngine.d.ts +0 -0
  201. /package/dist/{ripple/src/engines → engines}/WsEngine.d.ts +0 -0
  202. /package/dist/{ripple/src/engines → engines}/index.d.ts +0 -0
  203. /package/dist/{ripple/src/errors → errors}/index.d.ts +0 -0
  204. /package/dist/{ripple/src/events → events}/BroadcastEvent.d.ts +0 -0
  205. /package/dist/{ripple/src/events → events}/BroadcastManager.d.ts +0 -0
  206. /package/dist/{ripple/src/events → events}/Broadcaster.d.ts +0 -0
  207. /package/dist/{ripple/src/events → events}/index.d.ts +0 -0
  208. /package/dist/{ripple/src/health → health}/HealthChecker.d.ts +0 -0
  209. /package/dist/{ripple/src/health → health}/index.d.ts +0 -0
  210. /package/dist/{ripple/src/index.d.ts → index.d.ts} +0 -0
  211. /package/dist/{ripple/src/logging → logging}/Logger.d.ts +0 -0
  212. /package/dist/{ripple/src/logging → logging}/index.d.ts +0 -0
  213. /package/dist/{ripple/src/middleware → middleware}/InterceptorManager.d.ts +0 -0
  214. /package/dist/{ripple/src/observability → observability}/RippleMetrics.d.ts +0 -0
  215. /package/dist/{ripple/src/reliability → reliability}/AckManager.d.ts +0 -0
  216. /package/dist/{ripple/src/serializers → serializers}/ISerializer.d.ts +0 -0
  217. /package/dist/{ripple/src/serializers → serializers}/JsonSerializer.d.ts +0 -0
  218. /package/dist/{ripple/src/serializers → serializers}/ProtobufSerializer.d.ts +0 -0
  219. /package/dist/{ripple/src/serializers → serializers}/index.d.ts +0 -0
  220. /package/dist/{ripple/src/tracking → tracking}/ConnectionTracker.d.ts +0 -0
  221. /package/dist/{ripple/src/tracking → tracking}/SessionManager.d.ts +0 -0
  222. /package/dist/{ripple/src/tracking → tracking}/index.d.ts +0 -0
  223. /package/dist/{ripple/src/types.d.ts → types.d.ts} +0 -0
  224. /package/dist/{ripple/src/utils → utils}/MessageSerializer.d.ts +0 -0
  225. /package/dist/{ripple/src/utils → utils}/TokenBucket.d.ts +0 -0
  226. /package/dist/{ripple/src/utils → utils}/index.d.ts +0 -0
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@gravito/ripple",
3
- "version": "4.0.1",
3
+ "sideEffects": false,
4
+ "version": "5.0.0",
4
5
  "description": "Bun-native WebSocket broadcasting for Gravito. Channel-based real-time communication.",
5
6
  "type": "module",
6
7
  "main": "./dist/index.cjs",
@@ -19,6 +20,7 @@
19
20
  ],
20
21
  "scripts": {
21
22
  "build": "bun run build.ts",
23
+ "build:dts": "bun run build.ts --dts-only",
22
24
  "test": "bun test --timeout=10000",
23
25
  "typecheck": "bun tsc -p tsconfig.json --noEmit --skipLibCheck",
24
26
  "test:coverage": "bun test --timeout=10000 --coverage --coverage-reporter=lcov --coverage-dir coverage && bun run --bun scripts/check-coverage.ts",
@@ -44,7 +46,7 @@
44
46
  },
45
47
  "homepage": "https://github.com/gravito-framework/gravito#readme",
46
48
  "peerDependencies": {
47
- "@gravito/core": "^1.6.1",
49
+ "@gravito/core": "^3.0.0",
48
50
  "ioredis": "^5.0.0",
49
51
  "nats": "^2.23.0",
50
52
  "protobufjs": "^8.0.0",
@@ -65,9 +67,11 @@
65
67
  }
66
68
  },
67
69
  "devDependencies": {
70
+ "@gravito/core": "workspace:*",
68
71
  "@types/ws": "^8.18.1",
69
72
  "bun-types": "latest",
70
73
  "ioredis": "^5.4.2",
74
+ "nats": "^2.23.0",
71
75
  "protobufjs": "^8.0.0",
72
76
  "tinybench": "^6.0.0",
73
77
  "typescript": "^5.9.3",
@@ -1,348 +0,0 @@
1
- import { type AtlasMetrics, type AtlasTracer } from './observability';
2
- import type { ShardingManager } from './sharding/ShardingManager';
3
- import type { AtlasConfig, AtlasConnectionEntry, CacheInterface, ConnectionContract, QueryBuilderContract, QueryResult } from './types';
4
- /**
5
- * DB Facade - Static entry point for database operations.
6
- *
7
- * Provides a Laravel-style static interface for managing connections,
8
- * building queries, and executing transactions. Acts as the primary
9
- * gateway for application-level database interaction.
10
- *
11
- * @example
12
- * ```typescript
13
- * // Setup
14
- * DB.configure({
15
- * default: 'main',
16
- * connections: { main: { driver: 'sqlite', database: ':memory:' } }
17
- * });
18
- *
19
- * // Fluent Querying
20
- * const users = await DB.table('users').where('id', 1).get();
21
- *
22
- * // Raw Execution
23
- * const stats = await DB.raw('SELECT count(*) FROM users');
24
- * ```
25
- */
26
- export declare class DB {
27
- private static manager;
28
- private static shardingManagers;
29
- private static initialized;
30
- private static cache;
31
- private static _debug;
32
- private static _queryLog;
33
- private static readonly MAX_LOG_SIZE;
34
- private static queryListener?;
35
- /**
36
- * Registers a ShardingManager for distributed database architectures.
37
- *
38
- * @param name - Unique identifier for the sharding cluster
39
- * @param manager - The initialized ShardingManager instance
40
- */
41
- static addShardingManager(name: string, manager: ShardingManager): void;
42
- /**
43
- * Retrieves a registered ShardingManager.
44
- *
45
- * @param name - Name of the sharding cluster (defaults to 'default')
46
- * @throws Error if the manager is not found
47
- */
48
- static getShardingManager(name?: string): ShardingManager;
49
- /**
50
- * Sets the global cache provider for query results.
51
- *
52
- * @param cache - Implementation of CacheInterface (e.g., Redis, In-Memory).
53
- */
54
- static setCache(cache: CacheInterface): void;
55
- /**
56
- * Retrieves the active global cache provider.
57
- *
58
- * @returns The cache interface or undefined if none is configured.
59
- */
60
- static getCache(): CacheInterface | undefined;
61
- /**
62
- * Toggles debug mode for query logging.
63
- *
64
- * When enabled, executed queries are stored in an internal log with
65
- * performance metrics.
66
- *
67
- * @param enabled - Whether to enable logging.
68
- */
69
- static debug(enabled?: boolean): void;
70
- /**
71
- * Indicates if debug mode is currently active.
72
- */
73
- static isDebug(): boolean;
74
- /**
75
- * Retrieves the last executed SQL statement with interpolated values.
76
- *
77
- * Useful for debugging and integration testing.
78
- *
79
- * @returns The full SQL string or null if no queries were run.
80
- */
81
- static getLastQuery(): string | null;
82
- /**
83
- * Retrieves the complete query log for the current session.
84
- *
85
- * @returns A copy of the query log array.
86
- */
87
- static getQueryLog(): typeof this._queryLog;
88
- /**
89
- * Flushes the internal query log.
90
- */
91
- static clearQueryLog(): void;
92
- /**
93
- * Records a query execution event.
94
- *
95
- * @param sql - The SQL statement.
96
- * @param bindings - The parameter values.
97
- * @param duration - Time taken in ms.
98
- * @internal
99
- */
100
- static logQuery(sql: string, bindings: unknown[], duration: number): void;
101
- /**
102
- * Interpolates bindings into a SQL string for display purposes.
103
- *
104
- * Warning: This is only for logging/debugging and NOT for execution
105
- * to avoid SQL injection risks.
106
- *
107
- * @param sql - The SQL template with placeholders.
108
- * @param bindings - The values to inject.
109
- * @returns The readable SQL string.
110
- */
111
- private static interpolateBindings;
112
- /**
113
- * Executes a callback in "pretend" mode where queries are captured but not run.
114
- *
115
- * Ideal for verifying generated SQL without side effects.
116
- *
117
- * @param callback - Logic to simulate.
118
- * @returns Captured SQL strings and the callback result.
119
- *
120
- * @example
121
- * ```typescript
122
- * const { queries } = await DB.pretend(() => User.create({ name: 'Test' }));
123
- * ```
124
- */
125
- static pretend<T>(callback: () => Promise<T>): Promise<{
126
- queries: string[];
127
- result?: T;
128
- }>;
129
- private constructor();
130
- /**
131
- * Retrieves performance metrics from the SQL compiler cache.
132
- *
133
- * @returns Stats including hit rate and cache utilization.
134
- */
135
- static getCacheStats(): {
136
- size: number;
137
- maxSize: number;
138
- hitRate: number;
139
- };
140
- /**
141
- * Initializes the database subsystem with the provided configuration.
142
- *
143
- * Configures the connection manager and observability (Tracing/Metrics).
144
- * This method must be called before any database operations.
145
- *
146
- * @param config - The Atlas configuration object.
147
- * @throws {Error} If configuration is invalid.
148
- */
149
- static configure(config: AtlasConfig): void;
150
- /**
151
- * Retrieves the global tracer for manual span creation.
152
- */
153
- static getTracer(): AtlasTracer | undefined;
154
- /**
155
- * Retrieves the global metrics reporter.
156
- */
157
- static getMetrics(): AtlasMetrics | undefined;
158
- /**
159
- * Configures the database using environment variables.
160
- *
161
- * Looks for standard DB_* variables or DATABASE_URL.
162
- *
163
- * @param connectionName - The name to assign to the primary connection.
164
- */
165
- static configureFromEnv(connectionName?: string): void;
166
- /**
167
- * Loads configuration from a file.
168
- *
169
- * Automatically detects common patterns like config/database.ts.
170
- *
171
- * @param configPath - Explicit path to the config file.
172
- */
173
- static configureFromFile(configPath?: string): Promise<void>;
174
- /**
175
- * Best-effort configuration using file detection then environment variables.
176
- *
177
- * @param configPath - Optional path to try first.
178
- */
179
- static autoConfigure(configPath?: string): Promise<void>;
180
- /**
181
- * Manually adds a connection to the manager.
182
- *
183
- * @param name - Unique connection name.
184
- * @param config - Connection settings (standard or read/write replica).
185
- */
186
- static addConnection(name: string, config: AtlasConnectionEntry): void;
187
- /**
188
- * Adds a connection configured via prefixed environment variables.
189
- *
190
- * @param name - Connection name.
191
- * @param prefix - Env variable prefix (e.g. "READ_ONLY").
192
- */
193
- static addConnectionFromEnv(name: string, prefix?: string): void;
194
- /**
195
- * Sets the global default connection.
196
- *
197
- * @param name - The connection identifier.
198
- */
199
- static setDefaultConnection(name: string): void;
200
- /**
201
- * Returns the name of the current default connection.
202
- */
203
- static getDefaultConnection(): string;
204
- /**
205
- * Retrieves a connection instance.
206
- *
207
- * @param name - Name of the connection (defaults to the global default).
208
- * @returns The active connection instance.
209
- * @throws {Error} If DB is not configured or connection name is unknown.
210
- */
211
- static connection(name?: string): ConnectionContract;
212
- /**
213
- * Retrieves the read replica connection for the given connection name.
214
- *
215
- * Uses round-robin selection across configured read replicas.
216
- * Falls back to the primary connection if no replicas are configured.
217
- *
218
- * @param name - Connection name (defaults to global default)
219
- */
220
- static readConnection(name?: string): ConnectionContract;
221
- /**
222
- * Retrieves the write (primary) connection for the given connection name.
223
- *
224
- * Use this to force a query to run on the primary even inside a read context.
225
- *
226
- * @param name - Connection name (defaults to global default)
227
- */
228
- static writeConnection(name?: string): ConnectionContract;
229
- /**
230
- * Checks if a specific connection has been configured.
231
- */
232
- static hasConnection(name: string): boolean;
233
- /**
234
- * Lists all configured connection identifiers.
235
- */
236
- static getConnectionNames(): string[];
237
- /**
238
- * Retrieves the raw configuration for a connection.
239
- */
240
- static getConnectionConfig(name?: string): AtlasConnectionEntry | undefined;
241
- /**
242
- * Initializes a fluent query builder for a specific table.
243
- *
244
- * @template T - The row type.
245
- * @param tableName - The database table name.
246
- * @returns A QueryBuilder instance.
247
- */
248
- static table<T = Record<string, unknown>>(tableName: string): QueryBuilderContract<T>;
249
- /**
250
- * Executes a raw SQL statement with telemetry tracking.
251
- *
252
- * @template T - The expected row type.
253
- * @param sql - The SQL string with placeholders.
254
- * @param bindings - Array of values.
255
- * @returns The raw query result.
256
- *
257
- * @example
258
- * ```typescript
259
- * const users = await DB.raw('SELECT * FROM users WHERE active = ?', [true]);
260
- * ```
261
- */
262
- static raw<T = Record<string, unknown>>(sql: string, bindings?: unknown[]): Promise<QueryResult<T>>;
263
- /**
264
- * Alias for {@link raw}.
265
- */
266
- static rawQuery<T = Record<string, unknown>>(sql: string, bindings?: unknown[]): Promise<QueryResult<T>>;
267
- /**
268
- * Executes logic within a managed database transaction.
269
- *
270
- * Automatically commits on success and rolls back on error.
271
- * Receives a connection instance scoped to the transaction.
272
- *
273
- * @template T - Logic result type.
274
- * @param callback - The transactional logic.
275
- * @param connectionName - Optional specific connection.
276
- * @returns The callback's return value.
277
- */
278
- static transaction<T>(callback: (connection: ConnectionContract) => Promise<T>, connectionName?: string): Promise<T>;
279
- /**
280
- * Executes logic within a managed database transaction with automatic retry on serialization/stale data failures.
281
- *
282
- * Particularly useful for high-concurrency environments utilizing optimistic locking,
283
- * where `StaleModelError` is thrown due to concurrent writes.
284
- *
285
- * @template T - Logic result type.
286
- * @param callback - The transactional logic.
287
- * @param connectionName - Optional specific connection.
288
- * @param maxRetries - Maximum number of retries (default: 5).
289
- * @returns The callback's return value.
290
- * @throws Rethrows the error if max retries are exceeded.
291
- */
292
- static transactionWithRetry<T>(callback: (connection: ConnectionContract, attempt: number) => Promise<T>, connectionName?: string, maxRetries?: number): Promise<T>;
293
- /**
294
- * Manually starts a database transaction.
295
- *
296
- * Caller is responsible for calling commit() or rollback().
297
- *
298
- * @param connectionName - Connection to use.
299
- * @returns A transaction-scoped connection.
300
- * @throws {Error} If the driver does not support transactions.
301
- */
302
- static beginTransaction(connectionName?: string): Promise<ConnectionContract>;
303
- /**
304
- * Closes the specified connection.
305
- */
306
- static disconnect(name?: string): Promise<void>;
307
- /**
308
- * Closes all managed connections.
309
- */
310
- static disconnectAll(): Promise<void>;
311
- /**
312
- * Safely shuts down the database subsystem.
313
- */
314
- static shutdown(): Promise<void>;
315
- /**
316
- * Closes and re-opens a connection.
317
- */
318
- static reconnect(name?: string): Promise<ConnectionContract>;
319
- /**
320
- * Removes a connection from the internal cache without closing it.
321
- */
322
- static purge(name?: string): void;
323
- /**
324
- * Shortcut for starting a query with specific columns.
325
- */
326
- static select<T = Record<string, unknown>>(tableName: string, columns?: string[]): QueryBuilderContract<T>;
327
- /**
328
- * Shortcut for inserting records.
329
- */
330
- static insert<T = Record<string, unknown>>(tableName: string, data: Partial<T> | Partial<T>[]): Promise<T[]>;
331
- /**
332
- * Shortcut for updating records based on key-value filters.
333
- */
334
- static update<T = Record<string, unknown>>(tableName: string, where: Record<string, unknown>, data: Partial<T>): Promise<number>;
335
- /**
336
- * Shortcut for deleting records based on key-value filters.
337
- */
338
- static delete(tableName: string, where: Record<string, unknown>): Promise<number>;
339
- /**
340
- * Ensures the DB facade is ready for use.
341
- */
342
- private static ensureConfigured;
343
- /**
344
- * Internal reset for testing.
345
- * @internal
346
- */
347
- static _reset(): Promise<void>;
348
- }
@@ -1,9 +0,0 @@
1
- import type { GravitoOrbit, PlanetCore } from '@gravito/core';
2
- /**
3
- * Atlas Orbit - Database & ORM Integration
4
- * Integrates the Atlas ORM engine into the Gravito Core ecosystem.
5
- * @public
6
- */
7
- export declare class OrbitAtlas implements GravitoOrbit {
8
- install(core: PlanetCore): Promise<void>;
9
- }
@@ -1,14 +0,0 @@
1
- import type { AtlasConfig, AtlasObservabilityConfig, ConnectionConfig, PostgresConfig } from '../types';
2
- export type { AtlasConfig, AtlasObservabilityConfig, ConnectionConfig, PostgresConfig };
3
- /**
4
- * Define configuration with type checking
5
- */
6
- export declare function defineConfig(config: AtlasConfig): AtlasConfig;
7
- /**
8
- * Load configuration from environment variables with optional prefix
9
- * Supports both DATABASE_URL and individual DB_* variables
10
- *
11
- * @param connectionName - Name for the connection
12
- * @param prefix - Optional prefix for environment variables (e.g., 'READ' for DB_READ_*)
13
- */
14
- export declare function fromEnv(connectionName?: string, prefix?: string): AtlasConfig;
@@ -1,7 +0,0 @@
1
- /**
2
- * Configuration Module
3
- * @description Database configuration utilities
4
- */
5
- export type { AtlasConfig, ConnectionConfig } from '../types';
6
- export { defineConfig, fromEnv } from './defineConfig';
7
- export { loadConfig, loadConfigFile } from './loadConfig';
@@ -1,41 +0,0 @@
1
- /**
2
- * Configuration Loader
3
- * @description Load database configuration from various sources
4
- */
5
- import type { AtlasConfig } from '../types';
6
- /**
7
- * Load configuration from a TypeScript/JavaScript config file
8
- *
9
- * @param configPath - Path to the config file (default: 'config/database.ts' or 'config/database.js')
10
- * @returns Atlas configuration
11
- *
12
- * @example
13
- * ```typescript
14
- * // config/database.ts
15
- * import { defineConfig } from '@gravito/atlas'
16
- *
17
- * export default defineConfig({
18
- * default: 'default',
19
- * connections: {
20
- * default: {
21
- * driver: 'postgres',
22
- * host: 'localhost',
23
- * database: 'myapp'
24
- * }
25
- * }
26
- * })
27
- * ```
28
- */
29
- export declare function loadConfigFile(configPath?: string): Promise<AtlasConfig>;
30
- /**
31
- * Load configuration from multiple sources with priority
32
- * Priority: 1. Config file, 2. Environment variables, 3. Default
33
- *
34
- * @param options - Loading options
35
- * @returns Atlas configuration
36
- */
37
- export declare function loadConfig(options?: {
38
- configPath?: string;
39
- useEnv?: boolean;
40
- envPrefix?: string;
41
- }): Promise<AtlasConfig>;
@@ -1,112 +0,0 @@
1
- /**
2
- * Connection
3
- * @description Represents a database connection
4
- */
5
- import type { AtlasMetrics, AtlasTracer } from '../observability';
6
- import type { ConnectionConfig, ConnectionContract, DriverContract, ExecuteResult, GrammarContract, PoolStats, QueryBuilderContract, QueryResult } from '../types';
7
- /**
8
- * Database Connection
9
- * Wraps a driver and grammar for query building and execution
10
- */
11
- export declare class Connection implements ConnectionContract {
12
- protected readonly name: string;
13
- protected readonly config: ConnectionConfig;
14
- protected driver: DriverContract;
15
- protected grammar: GrammarContract;
16
- protected connected: boolean;
17
- protected proxy?: ConnectionContract;
18
- protected tracer: AtlasTracer | undefined;
19
- protected metrics: AtlasMetrics | undefined;
20
- /**
21
- * Static query listeners for global observation (e.g. debugging)
22
- */
23
- static queryListeners: Array<(query: {
24
- connection: string;
25
- sql: string;
26
- bindings: unknown[];
27
- duration: number;
28
- timestamp: number;
29
- }) => void>;
30
- constructor(name: string, config: ConnectionConfig);
31
- /**
32
- * Set the proxy instance for this connection
33
- */
34
- setProxy(proxy: ConnectionContract): void;
35
- /**
36
- * Get connection name
37
- */
38
- getName(): string;
39
- /**
40
- * Get the underlying driver
41
- */
42
- getDriver(): DriverContract;
43
- /**
44
- * Get connection configuration
45
- */
46
- getConfig(): ConnectionConfig;
47
- /**
48
- * Get the grammar
49
- */
50
- getGrammar(): GrammarContract;
51
- /**
52
- * Get the tracer
53
- */
54
- getTracer(): AtlasTracer | undefined;
55
- /**
56
- * Get the metrics
57
- */
58
- getMetrics(): AtlasMetrics | undefined;
59
- /**
60
- * Create a new query builder for a table
61
- */
62
- table<T = Record<string, unknown>>(tableName: string): QueryBuilderContract<T>;
63
- /**
64
- * Alias for table() for NoSQL connections
65
- */
66
- collection<T = Record<string, unknown>>(name: string): QueryBuilderContract<T>;
67
- /**
68
- * Execute raw SQL
69
- */
70
- raw<T = Record<string, unknown>>(sql: string, bindings?: unknown[]): Promise<QueryResult<T>>;
71
- /**
72
- * Execute raw SQL statement (INSERT/UPDATE/DELETE)
73
- */
74
- execute(sql: string, bindings?: unknown[]): Promise<ExecuteResult>;
75
- /**
76
- * Run a callback within a transaction
77
- */
78
- transaction<T>(callback: (connection: ConnectionContract) => Promise<T>): Promise<T>;
79
- /**
80
- * Stream query results for processing large datasets
81
- * @param sql - SQL query
82
- * @param bindings - Query parameters
83
- * @returns Async iterable of result rows
84
- */
85
- stream<T = Record<string, unknown>>(sql: string, bindings?: unknown[]): AsyncIterable<T>;
86
- /**
87
- * Get connection pool statistics (if supported by driver)
88
- * @returns Pool statistics or null if not supported
89
- */
90
- getPoolStats(): PoolStats | null;
91
- /**
92
- * Disconnect from the database
93
- */
94
- disconnect(): Promise<void>;
95
- /**
96
- * Connect to the database
97
- */
98
- connect(): Promise<void>;
99
- /**
100
- * Ensure connection is established
101
- */
102
- protected ensureConnected(): Promise<void>;
103
- /**
104
- * Create the driver instance based on config
105
- * Automatically prefers Bun.sql native driver when available (unless explicitly disabled)
106
- */
107
- protected createDriver(): DriverContract;
108
- /**
109
- * Create the grammar instance based on config
110
- */
111
- protected createGrammar(): GrammarContract;
112
- }