@gravito/ripple 4.0.0 → 4.0.3

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 (225) 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 -2
  4. package/dist/core/src/Application.d.ts +41 -0
  5. package/dist/core/src/ConfigManager.d.ts +39 -0
  6. package/dist/core/src/Container/RequestScopeManager.d.ts +62 -0
  7. package/dist/core/src/Container/RequestScopeMetrics.d.ts +144 -0
  8. package/dist/core/src/Container.d.ts +45 -0
  9. package/dist/core/src/ErrorHandler.d.ts +3 -0
  10. package/dist/core/src/HookManager.d.ts +104 -165
  11. package/dist/core/src/PlanetCore.d.ts +114 -1
  12. package/dist/core/src/RequestContext.d.ts +97 -0
  13. package/dist/core/src/Router.d.ts +32 -46
  14. package/dist/core/src/ServiceProvider.d.ts +22 -0
  15. package/dist/core/src/adapters/bun/BunContext.d.ts +10 -1
  16. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +35 -0
  17. package/dist/core/src/adapters/bun/BunWebSocketHandler.d.ts +48 -0
  18. package/dist/core/src/adapters/bun/RadixRouter.d.ts +1 -0
  19. package/dist/core/src/adapters/bun/index.d.ts +7 -0
  20. package/dist/core/src/binary/BinaryUtils.d.ts +105 -0
  21. package/dist/core/src/binary/index.d.ts +5 -0
  22. package/dist/core/src/cli/queue-commands.d.ts +6 -0
  23. package/dist/core/src/compat/async-local-storage.d.ts +7 -0
  24. package/dist/core/src/compat/crypto.d.ts +6 -0
  25. package/dist/core/src/engine/AOTRouter.d.ts +16 -1
  26. package/dist/core/src/engine/FastContext.d.ts +42 -1
  27. package/dist/core/src/engine/Gravito.d.ts +13 -19
  28. package/dist/core/src/engine/MinimalContext.d.ts +23 -0
  29. package/dist/core/src/engine/analyzer.d.ts +92 -6
  30. package/dist/core/src/engine/types.d.ts +6 -0
  31. package/dist/core/src/error-handling/RequestScopeErrorContext.d.ts +126 -0
  32. package/dist/core/src/events/BackpressureManager.d.ts +215 -0
  33. package/dist/core/src/events/DeadLetterQueue.d.ts +75 -1
  34. package/dist/core/src/events/EventBackend.d.ts +2 -1
  35. package/dist/core/src/events/EventOptions.d.ts +99 -4
  36. package/dist/core/src/events/EventPriorityQueue.d.ts +36 -175
  37. package/dist/core/src/events/FlowControlStrategy.d.ts +109 -0
  38. package/dist/core/src/events/MessageQueueBridge.d.ts +184 -0
  39. package/dist/core/src/events/PriorityEscalationManager.d.ts +82 -0
  40. package/dist/core/src/events/RetryScheduler.d.ts +104 -0
  41. package/dist/core/src/events/WorkerPool.d.ts +98 -0
  42. package/dist/core/src/events/WorkerPoolConfig.d.ts +153 -0
  43. package/dist/core/src/events/WorkerPoolMetrics.d.ts +65 -0
  44. package/dist/core/src/events/aggregation/AggregationWindow.d.ts +77 -0
  45. package/dist/core/src/events/aggregation/DeduplicationManager.d.ts +135 -0
  46. package/dist/core/src/events/aggregation/EventAggregationManager.d.ts +108 -0
  47. package/dist/core/src/events/aggregation/EventBatcher.d.ts +99 -0
  48. package/dist/core/src/events/aggregation/types.d.ts +117 -0
  49. package/dist/core/src/events/index.d.ts +18 -6
  50. package/dist/core/src/events/observability/OTelEventMetrics.d.ts +92 -0
  51. package/dist/core/src/events/observability/StreamWorkerMetrics.d.ts +76 -0
  52. package/dist/core/src/events/observability/index.d.ts +4 -0
  53. package/dist/core/src/events/queue-core.d.ts +77 -0
  54. package/dist/core/src/events/task-executor.d.ts +51 -0
  55. package/dist/core/src/events/types.d.ts +59 -0
  56. package/dist/core/src/ffi/NativeAccelerator.d.ts +62 -0
  57. package/dist/core/src/ffi/NativeHasher.d.ts +139 -0
  58. package/dist/core/src/ffi/cbor-fallback.d.ts +96 -0
  59. package/dist/core/src/ffi/hash-fallback.d.ts +33 -0
  60. package/dist/core/src/ffi/index.d.ts +10 -0
  61. package/dist/core/src/ffi/types.d.ts +135 -0
  62. package/dist/core/src/health/HealthProvider.d.ts +67 -0
  63. package/dist/core/src/helpers/Str.d.ts +15 -0
  64. package/dist/core/src/hooks/ActionManager.d.ts +132 -0
  65. package/dist/core/src/hooks/AsyncDetector.d.ts +84 -0
  66. package/dist/core/src/hooks/FilterManager.d.ts +71 -0
  67. package/dist/core/src/hooks/MigrationWarner.d.ts +24 -0
  68. package/dist/core/src/hooks/dlq-operations.d.ts +60 -0
  69. package/dist/core/src/hooks/types.d.ts +107 -0
  70. package/dist/core/src/http/CookieJar.d.ts +2 -2
  71. package/dist/core/src/http/types.d.ts +43 -3
  72. package/dist/core/src/index.d.ts +504 -15
  73. package/dist/core/src/observability/QueueDashboard.d.ts +136 -0
  74. package/dist/core/src/observability/contracts.d.ts +137 -0
  75. package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +36 -3
  76. package/dist/core/src/runtime/adapter-bun.d.ts +12 -0
  77. package/dist/core/src/runtime/adapter-deno.d.ts +12 -0
  78. package/dist/core/src/runtime/adapter-node.d.ts +12 -0
  79. package/dist/core/src/runtime/adapter-unknown.d.ts +13 -0
  80. package/dist/core/src/runtime/archive.d.ts +17 -0
  81. package/dist/core/src/runtime/compression.d.ts +21 -0
  82. package/dist/core/src/runtime/deep-equals.d.ts +56 -0
  83. package/dist/core/src/runtime/detection.d.ts +22 -0
  84. package/dist/core/src/runtime/escape.d.ts +34 -0
  85. package/dist/core/src/runtime/index.d.ts +44 -0
  86. package/dist/core/src/runtime/markdown.d.ts +44 -0
  87. package/dist/core/src/runtime/types.d.ts +436 -0
  88. package/dist/core/src/runtime-helpers.d.ts +67 -0
  89. package/dist/core/src/runtime.d.ts +10 -118
  90. package/dist/core/src/testing/HttpTester.d.ts +1 -0
  91. package/dist/core/src/transpiler-utils.d.ts +170 -0
  92. package/dist/{ripple/src/engines → engines}/BunEngine.d.ts +11 -0
  93. package/dist/engines/UWebSocketsEngine.d.ts +97 -0
  94. package/dist/engines/WsEngine.d.ts +69 -0
  95. package/dist/{ripple/src/engines → engines}/index.d.ts +4 -0
  96. package/dist/index.js +1 -7139
  97. package/dist/index.js.map +3 -69
  98. package/dist/{ripple/src/serializers → serializers}/ISerializer.d.ts +1 -1
  99. package/dist/{ripple/src/serializers → serializers}/JsonSerializer.d.ts +1 -1
  100. package/dist/{ripple/src/serializers → serializers}/ProtobufSerializer.d.ts +6 -3
  101. package/dist/{ripple/src/types.d.ts → types.d.ts} +11 -0
  102. package/package.json +7 -2
  103. package/dist/atlas/src/DB.d.ts +0 -301
  104. package/dist/atlas/src/OrbitAtlas.d.ts +0 -9
  105. package/dist/atlas/src/config/defineConfig.d.ts +0 -14
  106. package/dist/atlas/src/config/index.d.ts +0 -7
  107. package/dist/atlas/src/config/loadConfig.d.ts +0 -48
  108. package/dist/atlas/src/connection/Connection.d.ts +0 -108
  109. package/dist/atlas/src/connection/ConnectionManager.d.ts +0 -111
  110. package/dist/atlas/src/drivers/BunSQLDriver.d.ts +0 -32
  111. package/dist/atlas/src/drivers/BunSQLPreparedStatement.d.ts +0 -118
  112. package/dist/atlas/src/drivers/MongoDBDriver.d.ts +0 -36
  113. package/dist/atlas/src/drivers/MySQLDriver.d.ts +0 -66
  114. package/dist/atlas/src/drivers/PostgresDriver.d.ts +0 -83
  115. package/dist/atlas/src/drivers/RedisDriver.d.ts +0 -43
  116. package/dist/atlas/src/drivers/SQLiteDriver.d.ts +0 -45
  117. package/dist/atlas/src/drivers/types.d.ts +0 -260
  118. package/dist/atlas/src/errors/index.d.ts +0 -45
  119. package/dist/atlas/src/grammar/Grammar.d.ts +0 -342
  120. package/dist/atlas/src/grammar/MongoGrammar.d.ts +0 -47
  121. package/dist/atlas/src/grammar/MySQLGrammar.d.ts +0 -54
  122. package/dist/atlas/src/grammar/NullGrammar.d.ts +0 -35
  123. package/dist/atlas/src/grammar/PostgresGrammar.d.ts +0 -62
  124. package/dist/atlas/src/grammar/SQLiteGrammar.d.ts +0 -32
  125. package/dist/atlas/src/index.d.ts +0 -67
  126. package/dist/atlas/src/migration/Migration.d.ts +0 -64
  127. package/dist/atlas/src/migration/MigrationRepository.d.ts +0 -65
  128. package/dist/atlas/src/migration/Migrator.d.ts +0 -110
  129. package/dist/atlas/src/migration/index.d.ts +0 -6
  130. package/dist/atlas/src/observability/AtlasMetrics.d.ts +0 -11
  131. package/dist/atlas/src/observability/AtlasObservability.d.ts +0 -15
  132. package/dist/atlas/src/observability/AtlasTracer.d.ts +0 -12
  133. package/dist/atlas/src/observability/index.d.ts +0 -9
  134. package/dist/atlas/src/orm/index.d.ts +0 -5
  135. package/dist/atlas/src/orm/model/DirtyTracker.d.ts +0 -121
  136. package/dist/atlas/src/orm/model/Model.d.ts +0 -449
  137. package/dist/atlas/src/orm/model/ModelRegistry.d.ts +0 -20
  138. package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +0 -136
  139. package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +0 -36
  140. package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +0 -87
  141. package/dist/atlas/src/orm/model/concerns/HasRelationships.d.ts +0 -117
  142. package/dist/atlas/src/orm/model/concerns/HasSerialization.d.ts +0 -64
  143. package/dist/atlas/src/orm/model/concerns/applyMixins.d.ts +0 -15
  144. package/dist/atlas/src/orm/model/concerns/index.d.ts +0 -12
  145. package/dist/atlas/src/orm/model/decorators.d.ts +0 -109
  146. package/dist/atlas/src/orm/model/errors.d.ts +0 -52
  147. package/dist/atlas/src/orm/model/index.d.ts +0 -10
  148. package/dist/atlas/src/orm/model/relationships.d.ts +0 -207
  149. package/dist/atlas/src/orm/model/types.d.ts +0 -12
  150. package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +0 -123
  151. package/dist/atlas/src/orm/schema/SchemaSniffer.d.ts +0 -54
  152. package/dist/atlas/src/orm/schema/index.d.ts +0 -6
  153. package/dist/atlas/src/orm/schema/types.d.ts +0 -85
  154. package/dist/atlas/src/query/Expression.d.ts +0 -60
  155. package/dist/atlas/src/query/NPlusOneDetector.d.ts +0 -10
  156. package/dist/atlas/src/query/QueryBuilder.d.ts +0 -573
  157. package/dist/atlas/src/query/clauses/GroupByClause.d.ts +0 -51
  158. package/dist/atlas/src/query/clauses/HavingClause.d.ts +0 -70
  159. package/dist/atlas/src/query/clauses/JoinClause.d.ts +0 -87
  160. package/dist/atlas/src/query/clauses/LimitClause.d.ts +0 -82
  161. package/dist/atlas/src/query/clauses/OrderByClause.d.ts +0 -69
  162. package/dist/atlas/src/query/clauses/SelectClause.d.ts +0 -71
  163. package/dist/atlas/src/query/clauses/WhereClause.d.ts +0 -167
  164. package/dist/atlas/src/query/clauses/index.d.ts +0 -11
  165. package/dist/atlas/src/schema/Blueprint.d.ts +0 -276
  166. package/dist/atlas/src/schema/ColumnDefinition.d.ts +0 -154
  167. package/dist/atlas/src/schema/ForeignKeyDefinition.d.ts +0 -37
  168. package/dist/atlas/src/schema/Schema.d.ts +0 -131
  169. package/dist/atlas/src/schema/grammars/MySQLSchemaGrammar.d.ts +0 -23
  170. package/dist/atlas/src/schema/grammars/PostgresSchemaGrammar.d.ts +0 -26
  171. package/dist/atlas/src/schema/grammars/SQLiteSchemaGrammar.d.ts +0 -28
  172. package/dist/atlas/src/schema/grammars/SchemaGrammar.d.ts +0 -97
  173. package/dist/atlas/src/schema/grammars/index.d.ts +0 -7
  174. package/dist/atlas/src/schema/index.d.ts +0 -8
  175. package/dist/atlas/src/seed/Factory.d.ts +0 -90
  176. package/dist/atlas/src/seed/Seeder.d.ts +0 -28
  177. package/dist/atlas/src/seed/SeederRunner.d.ts +0 -74
  178. package/dist/atlas/src/seed/index.d.ts +0 -6
  179. package/dist/atlas/src/types/index.d.ts +0 -1100
  180. package/dist/atlas/src/utils/levenshtein.d.ts +0 -9
  181. package/dist/core/src/adapters/PhotonAdapter.d.ts +0 -171
  182. package/dist/core/src/adapters/photon-types.d.ts +0 -73
  183. package/dist/core/src/http/middleware/BodySizeLimit.d.ts +0 -16
  184. package/dist/core/src/http/middleware/Cors.d.ts +0 -24
  185. package/dist/core/src/http/middleware/Csrf.d.ts +0 -23
  186. package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +0 -28
  187. package/dist/core/src/http/middleware/SecurityHeaders.d.ts +0 -29
  188. package/dist/core/src/http/middleware/ThrottleRequests.d.ts +0 -18
  189. package/dist/core/src/instrumentation/index.d.ts +0 -35
  190. package/dist/core/src/instrumentation/opentelemetry.d.ts +0 -178
  191. package/dist/core/src/instrumentation/types.d.ts +0 -182
  192. package/dist/photon/src/index.d.ts +0 -84
  193. package/dist/photon/src/middleware/binary.d.ts +0 -31
  194. package/dist/photon/src/middleware/htmx.d.ts +0 -39
  195. package/dist/photon/src/middleware/ratelimit.d.ts +0 -157
  196. package/dist/photon/src/openapi.d.ts +0 -19
  197. /package/dist/{ripple/src/channels → channels}/Channel.d.ts +0 -0
  198. /package/dist/{ripple/src/channels → channels}/ChannelManager.d.ts +0 -0
  199. /package/dist/{ripple/src/channels → channels}/index.d.ts +0 -0
  200. /package/dist/{ripple/src/drivers → drivers}/LocalDriver.d.ts +0 -0
  201. /package/dist/{ripple/src/drivers → drivers}/NATSDriver.d.ts +0 -0
  202. /package/dist/{ripple/src/drivers → drivers}/RedisDriver.d.ts +0 -0
  203. /package/dist/{ripple/src/drivers → drivers}/index.d.ts +0 -0
  204. /package/dist/{ripple/src/engines → engines}/IRippleEngine.d.ts +0 -0
  205. /package/dist/{ripple/src/errors → errors}/RippleError.d.ts +0 -0
  206. /package/dist/{ripple/src/errors → errors}/index.d.ts +0 -0
  207. /package/dist/{ripple/src/events → events}/BroadcastEvent.d.ts +0 -0
  208. /package/dist/{ripple/src/events → events}/BroadcastManager.d.ts +0 -0
  209. /package/dist/{ripple/src/events → events}/Broadcaster.d.ts +0 -0
  210. /package/dist/{ripple/src/events → events}/index.d.ts +0 -0
  211. /package/dist/{ripple/src/health → health}/HealthChecker.d.ts +0 -0
  212. /package/dist/{ripple/src/health → health}/index.d.ts +0 -0
  213. /package/dist/{ripple/src/index.d.ts → index.d.ts} +0 -0
  214. /package/dist/{ripple/src/logging → logging}/Logger.d.ts +0 -0
  215. /package/dist/{ripple/src/logging → logging}/index.d.ts +0 -0
  216. /package/dist/{ripple/src/middleware → middleware}/InterceptorManager.d.ts +0 -0
  217. /package/dist/{ripple/src/observability → observability}/RippleMetrics.d.ts +0 -0
  218. /package/dist/{ripple/src/reliability → reliability}/AckManager.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/utils → utils}/MessageSerializer.d.ts +0 -0
  224. /package/dist/{ripple/src/utils → utils}/TokenBucket.d.ts +0 -0
  225. /package/dist/{ripple/src/utils → utils}/index.d.ts +0 -0
@@ -21,7 +21,7 @@ export interface ISerializer {
21
21
  * @param data - The raw data received from the client
22
22
  * @returns Parsed ClientMessage object
23
23
  */
24
- deserialize(data: string | Buffer | ArrayBuffer): ClientMessage;
24
+ deserialize(data: string | Buffer | ArrayBuffer | Uint8Array): ClientMessage;
25
25
  /**
26
26
  * Serialize message for broadcasting with caching optimization.
27
27
  *
@@ -12,7 +12,7 @@ export declare class JsonSerializer implements ISerializer {
12
12
  /** Cached serialized string for the current broadcast operation */
13
13
  private broadcastCache;
14
14
  serialize(message: ServerMessage): string;
15
- deserialize(data: string | Buffer | ArrayBuffer): ClientMessage;
15
+ deserialize(data: string | Buffer | ArrayBuffer | Uint8Array): ClientMessage;
16
16
  serializeForBroadcast(message: ServerMessage): string;
17
17
  clearBroadcastCache(): void;
18
18
  getPongMessage(): string;
@@ -7,11 +7,14 @@ import type { ISerializer } from './ISerializer';
7
7
  * Requires 'protobufjs' to be installed.
8
8
  */
9
9
  export declare class ProtobufSerializer implements ISerializer {
10
- private protoPath?;
10
+ private options;
11
11
  readonly contentType = "protobuf";
12
12
  private broadcastCache;
13
13
  private initialized;
14
- constructor(protoPath?: string | undefined);
14
+ constructor(options?: {
15
+ protoPath?: string;
16
+ pure?: boolean;
17
+ });
15
18
  /**
16
19
  * Resolves the proto file path using a multi-level fallback strategy.
17
20
  *
@@ -26,7 +29,7 @@ export declare class ProtobufSerializer implements ISerializer {
26
29
  */
27
30
  init(): Promise<void>;
28
31
  serialize(message: ServerMessage): Uint8Array;
29
- deserialize(data: string | Buffer | ArrayBuffer): ClientMessage;
32
+ deserialize(data: string | Buffer | ArrayBuffer | Uint8Array): ClientMessage;
30
33
  serializeForBroadcast(message: ServerMessage): Uint8Array;
31
34
  clearBroadcastCache(): void;
32
35
  getPongMessage(): Uint8Array;
@@ -34,6 +34,8 @@ export interface ClientData {
34
34
  reconnectionToken?: string;
35
35
  /** Session expiry timestamp (v3.6+) */
36
36
  sessionExpiry?: number;
37
+ /** Remote IP address (v5.0+) */
38
+ remoteAddress?: string;
37
39
  }
38
40
  /**
39
41
  * Supported WebSocket channel types.
@@ -769,6 +771,15 @@ export interface RippleConfig {
769
771
  * Install with: npm install protobufjs
770
772
  */
771
773
  serializer?: 'json' | 'protobuf';
774
+ /**
775
+ * Configuration for the serializer (v5.0+).
776
+ */
777
+ serializerOptions?: {
778
+ /** Path to custom .proto file (Protobuf only) */
779
+ protoPath?: string;
780
+ /** Enable pure binary mode (no JSON envelope for payload) - Protobuf only (default: false) */
781
+ pure?: boolean;
782
+ };
772
783
  /**
773
784
  * Performance & Backpressure (v3.7+).
774
785
  */
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@gravito/ripple",
3
- "version": "4.0.0",
3
+ "sideEffects": false,
4
+ "version": "4.0.3",
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": "workspace:*",
49
+ "@gravito/core": "^2.0.0",
48
50
  "ioredis": "^5.0.0",
49
51
  "nats": "^2.23.0",
50
52
  "protobufjs": "^8.0.0",
@@ -65,8 +67,11 @@
65
67
  }
66
68
  },
67
69
  "devDependencies": {
70
+ "@gravito/core": "workspace:*",
71
+ "@types/ws": "^8.18.1",
68
72
  "bun-types": "latest",
69
73
  "ioredis": "^5.4.2",
74
+ "nats": "^2.23.0",
70
75
  "protobufjs": "^8.0.0",
71
76
  "tinybench": "^6.0.0",
72
77
  "typescript": "^5.9.3",
@@ -1,301 +0,0 @@
1
- import { type AtlasMetrics, type AtlasTracer } from './observability';
2
- import type { AtlasConfig, CacheInterface, ConnectionConfig, ConnectionContract, QueryBuilderContract, QueryResult } from './types';
3
- /**
4
- * DB Facade - Static entry point for database operations.
5
- *
6
- * Provides a Laravel-style static interface for managing connections,
7
- * building queries, and executing transactions. Acts as the primary
8
- * gateway for application-level database interaction.
9
- *
10
- * @example
11
- * ```typescript
12
- * // Setup
13
- * DB.configure({
14
- * default: 'main',
15
- * connections: { main: { driver: 'sqlite', database: ':memory:' } }
16
- * });
17
- *
18
- * // Fluent Querying
19
- * const users = await DB.table('users').where('id', 1).get();
20
- *
21
- * // Raw Execution
22
- * const stats = await DB.raw('SELECT count(*) FROM users');
23
- * ```
24
- */
25
- export declare class DB {
26
- private static manager;
27
- private static initialized;
28
- private static cache;
29
- private static _debug;
30
- private static _queryLog;
31
- private static readonly MAX_LOG_SIZE;
32
- private static queryListener?;
33
- /**
34
- * Sets the global cache provider for query results.
35
- *
36
- * @param cache - Implementation of CacheInterface (e.g., Redis, In-Memory).
37
- */
38
- static setCache(cache: CacheInterface): void;
39
- /**
40
- * Retrieves the active global cache provider.
41
- *
42
- * @returns The cache interface or undefined if none is configured.
43
- */
44
- static getCache(): CacheInterface | undefined;
45
- /**
46
- * Toggles debug mode for query logging.
47
- *
48
- * When enabled, executed queries are stored in an internal log with
49
- * performance metrics.
50
- *
51
- * @param enabled - Whether to enable logging.
52
- */
53
- static debug(enabled?: boolean): void;
54
- /**
55
- * Indicates if debug mode is currently active.
56
- */
57
- static isDebug(): boolean;
58
- /**
59
- * Retrieves the last executed SQL statement with interpolated values.
60
- *
61
- * Useful for debugging and integration testing.
62
- *
63
- * @returns The full SQL string or null if no queries were run.
64
- */
65
- static getLastQuery(): string | null;
66
- /**
67
- * Retrieves the complete query log for the current session.
68
- *
69
- * @returns A copy of the query log array.
70
- */
71
- static getQueryLog(): typeof this._queryLog;
72
- /**
73
- * Flushes the internal query log.
74
- */
75
- static clearQueryLog(): void;
76
- /**
77
- * Records a query execution event.
78
- *
79
- * @param sql - The SQL statement.
80
- * @param bindings - The parameter values.
81
- * @param duration - Time taken in ms.
82
- * @internal
83
- */
84
- static logQuery(sql: string, bindings: unknown[], duration: number): void;
85
- /**
86
- * Interpolates bindings into a SQL string for display purposes.
87
- *
88
- * Warning: This is only for logging/debugging and NOT for execution
89
- * to avoid SQL injection risks.
90
- *
91
- * @param sql - The SQL template with placeholders.
92
- * @param bindings - The values to inject.
93
- * @returns The readable SQL string.
94
- */
95
- private static interpolateBindings;
96
- /**
97
- * Executes a callback in "pretend" mode where queries are captured but not run.
98
- *
99
- * Ideal for verifying generated SQL without side effects.
100
- *
101
- * @param callback - Logic to simulate.
102
- * @returns Captured SQL strings and the callback result.
103
- *
104
- * @example
105
- * ```typescript
106
- * const { queries } = await DB.pretend(() => User.create({ name: 'Test' }));
107
- * ```
108
- */
109
- static pretend<T>(callback: () => Promise<T>): Promise<{
110
- queries: string[];
111
- result?: T;
112
- }>;
113
- private constructor();
114
- /**
115
- * Retrieves performance metrics from the SQL compiler cache.
116
- *
117
- * @returns Stats including hit rate and cache utilization.
118
- */
119
- static getCacheStats(): {
120
- size: number;
121
- maxSize: number;
122
- hitRate: number;
123
- };
124
- /**
125
- * Initializes the database subsystem with the provided configuration.
126
- *
127
- * Configures the connection manager and observability (Tracing/Metrics).
128
- * This method must be called before any database operations.
129
- *
130
- * @param config - The Atlas configuration object.
131
- * @throws {Error} If configuration is invalid.
132
- */
133
- static configure(config: AtlasConfig): void;
134
- /**
135
- * Retrieves the global tracer for manual span creation.
136
- */
137
- static getTracer(): AtlasTracer | undefined;
138
- /**
139
- * Retrieves the global metrics reporter.
140
- */
141
- static getMetrics(): AtlasMetrics | undefined;
142
- /**
143
- * Configures the database using environment variables.
144
- *
145
- * Looks for standard DB_* variables or DATABASE_URL.
146
- *
147
- * @param connectionName - The name to assign to the primary connection.
148
- */
149
- static configureFromEnv(connectionName?: string): void;
150
- /**
151
- * Loads configuration from a file.
152
- *
153
- * Automatically detects common patterns like config/database.ts.
154
- *
155
- * @param configPath - Explicit path to the config file.
156
- */
157
- static configureFromFile(configPath?: string): Promise<void>;
158
- /**
159
- * Best-effort configuration using file detection then environment variables.
160
- *
161
- * @param configPath - Optional path to try first.
162
- */
163
- static autoConfigure(configPath?: string): Promise<void>;
164
- /**
165
- * Manually adds a connection to the manager.
166
- *
167
- * @param name - Unique connection name.
168
- * @param config - Connection settings.
169
- */
170
- static addConnection(name: string, config: ConnectionConfig): void;
171
- /**
172
- * Adds a connection configured via prefixed environment variables.
173
- *
174
- * @param name - Connection name.
175
- * @param prefix - Env variable prefix (e.g. "READ_ONLY").
176
- */
177
- static addConnectionFromEnv(name: string, prefix?: string): void;
178
- /**
179
- * Sets the global default connection.
180
- *
181
- * @param name - The connection identifier.
182
- */
183
- static setDefaultConnection(name: string): void;
184
- /**
185
- * Returns the name of the current default connection.
186
- */
187
- static getDefaultConnection(): string;
188
- /**
189
- * Retrieves a connection instance.
190
- *
191
- * @param name - Name of the connection (defaults to the global default).
192
- * @returns The active connection instance.
193
- * @throws {Error} If DB is not configured or connection name is unknown.
194
- */
195
- static connection(name?: string): ConnectionContract;
196
- /**
197
- * Checks if a specific connection has been configured.
198
- */
199
- static hasConnection(name: string): boolean;
200
- /**
201
- * Lists all configured connection identifiers.
202
- */
203
- static getConnectionNames(): string[];
204
- /**
205
- * Retrieves the raw configuration for a connection.
206
- */
207
- static getConnectionConfig(name?: string): ConnectionConfig | undefined;
208
- /**
209
- * Initializes a fluent query builder for a specific table.
210
- *
211
- * @template T - The row type.
212
- * @param tableName - The database table name.
213
- * @returns A QueryBuilder instance.
214
- */
215
- static table<T = Record<string, unknown>>(tableName: string): QueryBuilderContract<T>;
216
- /**
217
- * Executes a raw SQL statement with telemetry tracking.
218
- *
219
- * @template T - The expected row type.
220
- * @param sql - The SQL string with placeholders.
221
- * @param bindings - Array of values.
222
- * @returns The raw query result.
223
- *
224
- * @example
225
- * ```typescript
226
- * const users = await DB.raw('SELECT * FROM users WHERE active = ?', [true]);
227
- * ```
228
- */
229
- static raw<T = Record<string, unknown>>(sql: string, bindings?: unknown[]): Promise<QueryResult<T>>;
230
- /**
231
- * Alias for {@link raw}.
232
- */
233
- static rawQuery<T = Record<string, unknown>>(sql: string, bindings?: unknown[]): Promise<QueryResult<T>>;
234
- /**
235
- * Executes logic within a managed database transaction.
236
- *
237
- * Automatically commits on success and rolls back on error.
238
- * Receives a connection instance scoped to the transaction.
239
- *
240
- * @template T - Logic result type.
241
- * @param callback - The transactional logic.
242
- * @param connectionName - Optional specific connection.
243
- * @returns The callback's return value.
244
- */
245
- static transaction<T>(callback: (connection: ConnectionContract) => Promise<T>, connectionName?: string): Promise<T>;
246
- /**
247
- * Manually starts a database transaction.
248
- *
249
- * Caller is responsible for calling commit() or rollback().
250
- *
251
- * @param connectionName - Connection to use.
252
- * @returns A transaction-scoped connection.
253
- * @throws {Error} If the driver does not support transactions.
254
- */
255
- static beginTransaction(connectionName?: string): Promise<ConnectionContract>;
256
- /**
257
- * Closes the specified connection.
258
- */
259
- static disconnect(name?: string): Promise<void>;
260
- /**
261
- * Closes all managed connections.
262
- */
263
- static disconnectAll(): Promise<void>;
264
- /**
265
- * Safely shuts down the database subsystem.
266
- */
267
- static shutdown(): Promise<void>;
268
- /**
269
- * Closes and re-opens a connection.
270
- */
271
- static reconnect(name?: string): Promise<ConnectionContract>;
272
- /**
273
- * Removes a connection from the internal cache without closing it.
274
- */
275
- static purge(name?: string): void;
276
- /**
277
- * Shortcut for starting a query with specific columns.
278
- */
279
- static select<T = Record<string, unknown>>(tableName: string, columns?: string[]): QueryBuilderContract<T>;
280
- /**
281
- * Shortcut for inserting records.
282
- */
283
- static insert<T = Record<string, unknown>>(tableName: string, data: Partial<T> | Partial<T>[]): Promise<T[]>;
284
- /**
285
- * Shortcut for updating records based on key-value filters.
286
- */
287
- static update<T = Record<string, unknown>>(tableName: string, where: Record<string, unknown>, data: Partial<T>): Promise<number>;
288
- /**
289
- * Shortcut for deleting records based on key-value filters.
290
- */
291
- static delete(tableName: string, where: Record<string, unknown>): Promise<number>;
292
- /**
293
- * Ensures the DB facade is ready for use.
294
- */
295
- private static ensureConfigured;
296
- /**
297
- * Internal reset for testing.
298
- * @internal
299
- */
300
- static _reset(): Promise<void>;
301
- }
@@ -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 { autoConfigure, loadConfig, loadConfigFile } from './loadConfig';
@@ -1,48 +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>;
42
- /**
43
- * Auto-configure database from config file or environment
44
- * This is a convenience function that tries config file first, then environment
45
- *
46
- * @param configPath - Optional path to config file
47
- */
48
- export declare function autoConfigure(configPath?: string): Promise<void>;
@@ -1,108 +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
- * Create a new query builder for a table
57
- */
58
- table<T = Record<string, unknown>>(tableName: string): QueryBuilderContract<T>;
59
- /**
60
- * Alias for table() for NoSQL connections
61
- */
62
- collection<T = Record<string, unknown>>(name: string): QueryBuilderContract<T>;
63
- /**
64
- * Execute raw SQL
65
- */
66
- raw<T = Record<string, unknown>>(sql: string, bindings?: unknown[]): Promise<QueryResult<T>>;
67
- /**
68
- * Execute raw SQL statement (INSERT/UPDATE/DELETE)
69
- */
70
- execute(sql: string, bindings?: unknown[]): Promise<ExecuteResult>;
71
- /**
72
- * Run a callback within a transaction
73
- */
74
- transaction<T>(callback: (connection: ConnectionContract) => Promise<T>): Promise<T>;
75
- /**
76
- * Stream query results for processing large datasets
77
- * @param sql - SQL query
78
- * @param bindings - Query parameters
79
- * @returns Async iterable of result rows
80
- */
81
- stream<T = Record<string, unknown>>(sql: string, bindings?: unknown[]): AsyncIterable<T>;
82
- /**
83
- * Get connection pool statistics (if supported by driver)
84
- * @returns Pool statistics or null if not supported
85
- */
86
- getPoolStats(): PoolStats | null;
87
- /**
88
- * Disconnect from the database
89
- */
90
- disconnect(): Promise<void>;
91
- /**
92
- * Connect to the database
93
- */
94
- connect(): Promise<void>;
95
- /**
96
- * Ensure connection is established
97
- */
98
- protected ensureConnected(): Promise<void>;
99
- /**
100
- * Create the driver instance based on config
101
- * Automatically prefers Bun.sql native driver when available (unless explicitly disabled)
102
- */
103
- protected createDriver(): DriverContract;
104
- /**
105
- * Create the grammar instance based on config
106
- */
107
- protected createGrammar(): GrammarContract;
108
- }