@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.
- package/README.md +211 -0
- package/dist/atlas/src/DB.d.ts +301 -0
- package/dist/atlas/src/OrbitAtlas.d.ts +9 -0
- package/dist/atlas/src/config/defineConfig.d.ts +14 -0
- package/dist/atlas/src/config/index.d.ts +7 -0
- package/dist/atlas/src/config/loadConfig.d.ts +48 -0
- package/dist/atlas/src/connection/Connection.d.ts +108 -0
- package/dist/atlas/src/connection/ConnectionManager.d.ts +111 -0
- package/dist/atlas/src/drivers/BunSQLDriver.d.ts +32 -0
- package/dist/atlas/src/drivers/BunSQLPreparedStatement.d.ts +118 -0
- package/dist/atlas/src/drivers/MongoDBDriver.d.ts +36 -0
- package/dist/atlas/src/drivers/MySQLDriver.d.ts +66 -0
- package/dist/atlas/src/drivers/PostgresDriver.d.ts +83 -0
- package/dist/atlas/src/drivers/RedisDriver.d.ts +43 -0
- package/dist/atlas/src/drivers/SQLiteDriver.d.ts +45 -0
- package/dist/atlas/src/drivers/types.d.ts +260 -0
- package/dist/atlas/src/errors/index.d.ts +45 -0
- package/dist/atlas/src/grammar/Grammar.d.ts +342 -0
- package/dist/atlas/src/grammar/MongoGrammar.d.ts +47 -0
- package/dist/atlas/src/grammar/MySQLGrammar.d.ts +54 -0
- package/dist/atlas/src/grammar/NullGrammar.d.ts +35 -0
- package/dist/atlas/src/grammar/PostgresGrammar.d.ts +62 -0
- package/dist/atlas/src/grammar/SQLiteGrammar.d.ts +32 -0
- package/dist/atlas/src/index.d.ts +67 -0
- package/dist/atlas/src/migration/Migration.d.ts +64 -0
- package/dist/atlas/src/migration/MigrationRepository.d.ts +65 -0
- package/dist/atlas/src/migration/Migrator.d.ts +110 -0
- package/dist/atlas/src/migration/index.d.ts +6 -0
- package/dist/atlas/src/observability/AtlasMetrics.d.ts +11 -0
- package/dist/atlas/src/observability/AtlasObservability.d.ts +15 -0
- package/dist/atlas/src/observability/AtlasTracer.d.ts +12 -0
- package/dist/atlas/src/observability/index.d.ts +9 -0
- package/dist/atlas/src/orm/index.d.ts +5 -0
- package/dist/atlas/src/orm/model/DirtyTracker.d.ts +121 -0
- package/dist/atlas/src/orm/model/Model.d.ts +449 -0
- package/dist/atlas/src/orm/model/ModelRegistry.d.ts +20 -0
- package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +136 -0
- package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +36 -0
- package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +87 -0
- package/dist/atlas/src/orm/model/concerns/HasRelationships.d.ts +117 -0
- package/dist/atlas/src/orm/model/concerns/HasSerialization.d.ts +64 -0
- package/dist/atlas/src/orm/model/concerns/applyMixins.d.ts +15 -0
- package/dist/atlas/src/orm/model/concerns/index.d.ts +12 -0
- package/dist/atlas/src/orm/model/decorators.d.ts +109 -0
- package/dist/atlas/src/orm/model/errors.d.ts +52 -0
- package/dist/atlas/src/orm/model/index.d.ts +10 -0
- package/dist/atlas/src/orm/model/relationships.d.ts +207 -0
- package/dist/atlas/src/orm/model/types.d.ts +12 -0
- package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +123 -0
- package/dist/atlas/src/orm/schema/SchemaSniffer.d.ts +54 -0
- package/dist/atlas/src/orm/schema/index.d.ts +6 -0
- package/dist/atlas/src/orm/schema/types.d.ts +85 -0
- package/dist/atlas/src/query/Expression.d.ts +60 -0
- package/dist/atlas/src/query/NPlusOneDetector.d.ts +10 -0
- package/dist/atlas/src/query/QueryBuilder.d.ts +573 -0
- package/dist/atlas/src/query/clauses/GroupByClause.d.ts +51 -0
- package/dist/atlas/src/query/clauses/HavingClause.d.ts +70 -0
- package/dist/atlas/src/query/clauses/JoinClause.d.ts +87 -0
- package/dist/atlas/src/query/clauses/LimitClause.d.ts +82 -0
- package/dist/atlas/src/query/clauses/OrderByClause.d.ts +69 -0
- package/dist/atlas/src/query/clauses/SelectClause.d.ts +71 -0
- package/dist/atlas/src/query/clauses/WhereClause.d.ts +167 -0
- package/dist/atlas/src/query/clauses/index.d.ts +11 -0
- package/dist/atlas/src/schema/Blueprint.d.ts +276 -0
- package/dist/atlas/src/schema/ColumnDefinition.d.ts +154 -0
- package/dist/atlas/src/schema/ForeignKeyDefinition.d.ts +37 -0
- package/dist/atlas/src/schema/Schema.d.ts +131 -0
- package/dist/atlas/src/schema/grammars/MySQLSchemaGrammar.d.ts +23 -0
- package/dist/atlas/src/schema/grammars/PostgresSchemaGrammar.d.ts +26 -0
- package/dist/atlas/src/schema/grammars/SQLiteSchemaGrammar.d.ts +28 -0
- package/dist/atlas/src/schema/grammars/SchemaGrammar.d.ts +97 -0
- package/dist/atlas/src/schema/grammars/index.d.ts +7 -0
- package/dist/atlas/src/schema/index.d.ts +8 -0
- package/dist/atlas/src/seed/Factory.d.ts +90 -0
- package/dist/atlas/src/seed/Seeder.d.ts +28 -0
- package/dist/atlas/src/seed/SeederRunner.d.ts +74 -0
- package/dist/atlas/src/seed/index.d.ts +6 -0
- package/dist/atlas/src/types/index.d.ts +1100 -0
- package/dist/atlas/src/utils/levenshtein.d.ts +9 -0
- package/dist/core/src/Application.d.ts +215 -0
- package/dist/core/src/CommandKernel.d.ts +33 -0
- package/dist/core/src/ConfigManager.d.ts +26 -0
- package/dist/core/src/Container.d.ts +108 -0
- package/dist/core/src/ErrorHandler.d.ts +63 -0
- package/dist/core/src/Event.d.ts +5 -0
- package/dist/core/src/EventManager.d.ts +123 -0
- package/dist/core/src/GlobalErrorHandlers.d.ts +47 -0
- package/dist/core/src/GravitoServer.d.ts +28 -0
- package/dist/core/src/HookManager.d.ts +496 -0
- package/dist/core/src/Listener.d.ts +4 -0
- package/dist/core/src/Logger.d.ts +20 -0
- package/dist/core/src/PlanetCore.d.ts +289 -0
- package/dist/core/src/Route.d.ts +36 -0
- package/dist/core/src/Router.d.ts +284 -0
- package/dist/core/src/ServiceProvider.d.ts +156 -0
- package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +27 -0
- package/dist/core/src/adapters/PhotonAdapter.d.ts +171 -0
- package/dist/core/src/adapters/bun/BunContext.d.ts +45 -0
- package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +31 -0
- package/dist/core/src/adapters/bun/BunRequest.d.ts +31 -0
- package/dist/core/src/adapters/bun/RadixNode.d.ts +19 -0
- package/dist/core/src/adapters/bun/RadixRouter.d.ts +31 -0
- package/dist/core/src/adapters/bun/types.d.ts +20 -0
- package/dist/core/src/adapters/photon-types.d.ts +73 -0
- package/dist/core/src/adapters/types.d.ts +235 -0
- package/dist/core/src/engine/AOTRouter.d.ts +124 -0
- package/dist/core/src/engine/FastContext.d.ts +100 -0
- package/dist/core/src/engine/Gravito.d.ts +137 -0
- package/dist/core/src/engine/MinimalContext.d.ts +79 -0
- package/dist/core/src/engine/analyzer.d.ts +27 -0
- package/dist/core/src/engine/constants.d.ts +23 -0
- package/dist/core/src/engine/index.d.ts +26 -0
- package/dist/core/src/engine/path.d.ts +26 -0
- package/dist/core/src/engine/pool.d.ts +83 -0
- package/dist/core/src/engine/types.d.ts +143 -0
- package/dist/core/src/events/CircuitBreaker.d.ts +229 -0
- package/dist/core/src/events/DeadLetterQueue.d.ts +145 -0
- package/dist/core/src/events/EventBackend.d.ts +11 -0
- package/dist/core/src/events/EventOptions.d.ts +109 -0
- package/dist/core/src/events/EventPriorityQueue.d.ts +202 -0
- package/dist/core/src/events/IdempotencyCache.d.ts +60 -0
- package/dist/core/src/events/index.d.ts +14 -0
- package/dist/core/src/events/observability/EventMetrics.d.ts +132 -0
- package/dist/core/src/events/observability/EventTracer.d.ts +68 -0
- package/dist/core/src/events/observability/EventTracing.d.ts +161 -0
- package/dist/core/src/events/observability/OTelEventMetrics.d.ts +240 -0
- package/dist/core/src/events/observability/ObservableHookManager.d.ts +108 -0
- package/dist/core/src/events/observability/index.d.ts +20 -0
- package/dist/core/src/events/observability/metrics-types.d.ts +16 -0
- package/dist/core/src/events/types.d.ts +75 -0
- package/dist/core/src/exceptions/AuthenticationException.d.ts +8 -0
- package/dist/core/src/exceptions/AuthorizationException.d.ts +8 -0
- package/dist/core/src/exceptions/CircularDependencyException.d.ts +9 -0
- package/dist/core/src/exceptions/GravitoException.d.ts +23 -0
- package/dist/core/src/exceptions/HttpException.d.ts +9 -0
- package/dist/core/src/exceptions/ModelNotFoundException.d.ts +10 -0
- package/dist/core/src/exceptions/ValidationException.d.ts +22 -0
- package/dist/core/src/exceptions/index.d.ts +7 -0
- package/dist/core/src/helpers/Arr.d.ts +19 -0
- package/dist/core/src/helpers/Str.d.ts +23 -0
- package/dist/core/src/helpers/data.d.ts +25 -0
- package/dist/core/src/helpers/errors.d.ts +34 -0
- package/dist/core/src/helpers/response.d.ts +41 -0
- package/dist/core/src/helpers.d.ts +338 -0
- package/dist/core/src/http/CookieJar.d.ts +51 -0
- package/dist/core/src/http/cookie.d.ts +29 -0
- package/dist/core/src/http/middleware/BodySizeLimit.d.ts +16 -0
- package/dist/core/src/http/middleware/Cors.d.ts +24 -0
- package/dist/core/src/http/middleware/Csrf.d.ts +23 -0
- package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +28 -0
- package/dist/core/src/http/middleware/SecurityHeaders.d.ts +29 -0
- package/dist/core/src/http/middleware/ThrottleRequests.d.ts +18 -0
- package/dist/core/src/http/types.d.ts +355 -0
- package/dist/core/src/index.d.ts +76 -0
- package/dist/core/src/instrumentation/index.d.ts +35 -0
- package/dist/core/src/instrumentation/opentelemetry.d.ts +178 -0
- package/dist/core/src/instrumentation/types.d.ts +182 -0
- package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +316 -0
- package/dist/core/src/reliability/RetryPolicy.d.ts +217 -0
- package/dist/core/src/reliability/index.d.ts +6 -0
- package/dist/core/src/router/ControllerDispatcher.d.ts +12 -0
- package/dist/core/src/router/RequestValidator.d.ts +20 -0
- package/dist/core/src/runtime.d.ts +119 -0
- package/dist/core/src/security/Encrypter.d.ts +33 -0
- package/dist/core/src/security/Hasher.d.ts +29 -0
- package/dist/core/src/testing/HttpTester.d.ts +39 -0
- package/dist/core/src/testing/TestResponse.d.ts +78 -0
- package/dist/core/src/testing/index.d.ts +2 -0
- package/dist/core/src/types/events.d.ts +94 -0
- package/dist/echo/src/OrbitEcho.d.ts +115 -0
- package/dist/echo/src/dlq/DeadLetterQueue.d.ts +94 -0
- package/dist/echo/src/dlq/MemoryDeadLetterQueue.d.ts +36 -0
- package/dist/echo/src/dlq/index.d.ts +2 -0
- package/dist/echo/src/index.d.ts +64 -0
- package/dist/echo/src/middleware/RequestBufferMiddleware.d.ts +62 -0
- package/dist/echo/src/middleware/index.d.ts +8 -0
- package/dist/echo/src/observability/index.d.ts +3 -0
- package/dist/echo/src/observability/logging/ConsoleEchoLogger.d.ts +37 -0
- package/dist/echo/src/observability/logging/EchoLogger.d.ts +38 -0
- package/dist/echo/src/observability/logging/index.d.ts +2 -0
- package/dist/echo/src/observability/metrics/MetricsProvider.d.ts +69 -0
- package/dist/echo/src/observability/metrics/NoopMetricsProvider.d.ts +17 -0
- package/dist/echo/src/observability/metrics/PrometheusMetricsProvider.d.ts +39 -0
- package/dist/echo/src/observability/metrics/index.d.ts +3 -0
- package/dist/echo/src/observability/tracing/NoopTracer.d.ts +33 -0
- package/dist/echo/src/observability/tracing/Tracer.d.ts +75 -0
- package/dist/echo/src/observability/tracing/index.d.ts +2 -0
- package/dist/echo/src/providers/GenericProvider.d.ts +53 -0
- package/dist/echo/src/providers/GitHubProvider.d.ts +35 -0
- package/dist/echo/src/providers/LinearProvider.d.ts +27 -0
- package/dist/echo/src/providers/PaddleProvider.d.ts +31 -0
- package/dist/echo/src/providers/ShopifyProvider.d.ts +27 -0
- package/dist/echo/src/providers/SlackProvider.d.ts +27 -0
- package/dist/echo/src/providers/StripeProvider.d.ts +38 -0
- package/dist/echo/src/providers/TwilioProvider.d.ts +31 -0
- package/dist/echo/src/providers/base/BaseProvider.d.ts +87 -0
- package/dist/echo/src/providers/base/HeaderUtils.d.ts +34 -0
- package/dist/echo/src/providers/index.d.ts +14 -0
- package/dist/echo/src/receive/SignatureValidator.d.ts +67 -0
- package/dist/echo/src/receive/WebhookReceiver.d.ts +185 -0
- package/dist/echo/src/receive/index.d.ts +2 -0
- package/dist/echo/src/replay/WebhookReplayService.d.ts +35 -0
- package/dist/echo/src/replay/index.d.ts +1 -0
- package/dist/echo/src/resilience/CircuitBreaker.d.ts +117 -0
- package/dist/echo/src/resilience/index.d.ts +10 -0
- package/dist/echo/src/rotation/KeyRotationManager.d.ts +127 -0
- package/dist/echo/src/rotation/index.d.ts +10 -0
- package/dist/echo/src/send/WebhookDispatcher.d.ts +198 -0
- package/dist/echo/src/send/index.d.ts +1 -0
- package/dist/echo/src/storage/MemoryWebhookStore.d.ts +14 -0
- package/dist/echo/src/storage/WebhookStore.d.ts +236 -0
- package/dist/echo/src/storage/index.d.ts +2 -0
- package/dist/echo/src/types.d.ts +756 -0
- package/dist/index.js +1332 -190
- package/dist/index.js.map +28 -10
- package/dist/photon/src/index.d.ts +84 -0
- package/dist/photon/src/middleware/binary.d.ts +31 -0
- package/dist/photon/src/middleware/htmx.d.ts +39 -0
- package/dist/photon/src/middleware/ratelimit.d.ts +157 -0
- package/dist/photon/src/openapi.d.ts +19 -0
- package/package.json +7 -5
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connection Manager
|
|
3
|
+
* @description Manages multiple database connections
|
|
4
|
+
*/
|
|
5
|
+
import type { ConnectionConfig, ConnectionContract } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Connection Manager
|
|
8
|
+
*
|
|
9
|
+
* Responsible for managing the lifecycle of database connections.
|
|
10
|
+
* It handles connection pooling (via drivers), lazy initialization,
|
|
11
|
+
* and automatic cleanup of idle connections.
|
|
12
|
+
*
|
|
13
|
+
* Connections are stored in a Map and retrieved by name. If a connection
|
|
14
|
+
* hasn't been initialized, the manager creates it using the provided configuration.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ConnectionManager {
|
|
17
|
+
private readonly configs;
|
|
18
|
+
private connections;
|
|
19
|
+
private defaultConnectionName;
|
|
20
|
+
private lastUsed;
|
|
21
|
+
private cleanupInterval?;
|
|
22
|
+
private readonly MAX_IDLE_TIME;
|
|
23
|
+
private readonly CLEANUP_INTERVAL;
|
|
24
|
+
constructor(configs?: Record<string, ConnectionConfig>);
|
|
25
|
+
/**
|
|
26
|
+
* Get a connection instance by name.
|
|
27
|
+
* If the connection is not already initialized, it will be created.
|
|
28
|
+
*
|
|
29
|
+
* @param name - Optional connection name (defaults to 'default').
|
|
30
|
+
* @returns The connection instance.
|
|
31
|
+
* @throws Error if the connection is not configured.
|
|
32
|
+
*/
|
|
33
|
+
connection(name?: string): ConnectionContract;
|
|
34
|
+
/**
|
|
35
|
+
* Add a connection configuration.
|
|
36
|
+
*
|
|
37
|
+
* @param name - Unique name for the connection.
|
|
38
|
+
* @param config - Connection configuration settings.
|
|
39
|
+
*/
|
|
40
|
+
addConnection(name: string, config: ConnectionConfig): void;
|
|
41
|
+
/**
|
|
42
|
+
* Set the default connection name.
|
|
43
|
+
*
|
|
44
|
+
* @param name - The name of the default connection.
|
|
45
|
+
*/
|
|
46
|
+
setDefaultConnection(name: string): void;
|
|
47
|
+
/**
|
|
48
|
+
* Get the default connection name.
|
|
49
|
+
*
|
|
50
|
+
* @returns The default connection name.
|
|
51
|
+
*/
|
|
52
|
+
getDefaultConnection(): string;
|
|
53
|
+
/**
|
|
54
|
+
* Check if a connection configuration exists.
|
|
55
|
+
*
|
|
56
|
+
* @param name - The connection name to check.
|
|
57
|
+
* @returns True if the connection is configured.
|
|
58
|
+
*/
|
|
59
|
+
hasConnection(name: string): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Get all configured connection names.
|
|
62
|
+
*
|
|
63
|
+
* @returns Array of connection names.
|
|
64
|
+
*/
|
|
65
|
+
getConnectionNames(): string[];
|
|
66
|
+
/**
|
|
67
|
+
* Get the configuration for a specific connection.
|
|
68
|
+
*
|
|
69
|
+
* @param name - The connection name.
|
|
70
|
+
* @returns The connection configuration or undefined if not found.
|
|
71
|
+
*/
|
|
72
|
+
getConfig(name: string): ConnectionConfig | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Disconnect all active connections.
|
|
75
|
+
*
|
|
76
|
+
* @returns A promise that resolves when all connections are closed.
|
|
77
|
+
*/
|
|
78
|
+
disconnectAll(): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Disconnect a specific connection by name.
|
|
81
|
+
*
|
|
82
|
+
* @param name - Optional connection name (defaults to default).
|
|
83
|
+
* @returns A promise that resolves when the connection is closed.
|
|
84
|
+
*/
|
|
85
|
+
disconnect(name?: string): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Purge a connection from the manager's cache.
|
|
88
|
+
* This will NOT disconnect the connection if it's already active.
|
|
89
|
+
*
|
|
90
|
+
* @param name - Optional connection name.
|
|
91
|
+
*/
|
|
92
|
+
purge(name?: string): void;
|
|
93
|
+
/**
|
|
94
|
+
* Reconnect to a connection.
|
|
95
|
+
* This will disconnect the existing connection and create a new one.
|
|
96
|
+
*
|
|
97
|
+
* @param name - Optional connection name.
|
|
98
|
+
* @returns The new connection instance.
|
|
99
|
+
*/
|
|
100
|
+
reconnect(name?: string): Promise<ConnectionContract>;
|
|
101
|
+
private cleanupIdleConnections;
|
|
102
|
+
private startCleanup;
|
|
103
|
+
stopCleanup(): void;
|
|
104
|
+
/**
|
|
105
|
+
* Shutdown the connection manager.
|
|
106
|
+
* Stops the idle cleanup interval and disconnects all connections.
|
|
107
|
+
*
|
|
108
|
+
* @returns A promise that resolves when shutdown is complete.
|
|
109
|
+
*/
|
|
110
|
+
shutdown(): Promise<void>;
|
|
111
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bun Native SQL Driver
|
|
3
|
+
*/
|
|
4
|
+
import type { ConnectionConfig, DriverContract, DriverType, ExecuteResult, PoolStats, QueryResult } from '../types';
|
|
5
|
+
export declare class BunSQLDriver implements DriverContract {
|
|
6
|
+
private readonly config;
|
|
7
|
+
private client;
|
|
8
|
+
private sqliteClient;
|
|
9
|
+
private connected;
|
|
10
|
+
private transactionActive;
|
|
11
|
+
private preparedManager?;
|
|
12
|
+
constructor(config: ConnectionConfig);
|
|
13
|
+
getDriverName(): DriverType;
|
|
14
|
+
connect(): Promise<void>;
|
|
15
|
+
disconnect(): Promise<void>;
|
|
16
|
+
isConnected(): boolean;
|
|
17
|
+
query<T = Record<string, unknown>>(sql: string, bindings?: unknown[]): Promise<QueryResult<T>>;
|
|
18
|
+
execute(sql: string, bindings?: unknown[]): Promise<ExecuteResult>;
|
|
19
|
+
private normalizeBindings;
|
|
20
|
+
beginTransaction(): Promise<void>;
|
|
21
|
+
commit(): Promise<void>;
|
|
22
|
+
rollback(): Promise<void>;
|
|
23
|
+
inTransaction(): boolean;
|
|
24
|
+
private ensureConnection;
|
|
25
|
+
private getConnectionUrl;
|
|
26
|
+
prepare(sql: string): Promise<string>;
|
|
27
|
+
executePrepared<T = Record<string, unknown>>(name: string, bindings?: unknown[]): Promise<QueryResult<T>>;
|
|
28
|
+
clearPreparedStatements(): Promise<void>;
|
|
29
|
+
stream<T = Record<string, unknown>>(sql: string, bindings?: unknown[]): AsyncIterable<T>;
|
|
30
|
+
getPoolStats(): PoolStats | null;
|
|
31
|
+
private normalizeError;
|
|
32
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bun SQL Prepared Statement Manager
|
|
3
|
+
* @description Manages prepared statement caching, lifecycle, and optimization
|
|
4
|
+
*/
|
|
5
|
+
import type { BunSQLClient } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for prepared statement manager
|
|
8
|
+
*/
|
|
9
|
+
export interface PreparedStatementManagerConfig {
|
|
10
|
+
/**
|
|
11
|
+
* Maximum number of prepared statements to cache
|
|
12
|
+
* @default 100
|
|
13
|
+
*/
|
|
14
|
+
maxStatements?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Idle timeout in milliseconds before a statement is removed
|
|
17
|
+
* @default 60000 (1 minute)
|
|
18
|
+
*/
|
|
19
|
+
idleTimeout?: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Prepared Statement Manager for BunSQL
|
|
23
|
+
*
|
|
24
|
+
* Manages statement caching and lifecycle to optimize query performance.
|
|
25
|
+
* Features:
|
|
26
|
+
* - LRU (Least Recently Used) cache eviction
|
|
27
|
+
* - Idle timeout cleanup
|
|
28
|
+
* - Usage statistics tracking
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const manager = new BunSQLPreparedStatementManager(client)
|
|
33
|
+
*
|
|
34
|
+
* // Prepare a statement
|
|
35
|
+
* const stmtId = await manager.prepare('SELECT * FROM users WHERE id = ?')
|
|
36
|
+
*
|
|
37
|
+
* // Execute multiple times
|
|
38
|
+
* const users1 = await manager.execute(stmtId, [1])
|
|
39
|
+
* const users2 = await manager.execute(stmtId, [2])
|
|
40
|
+
*
|
|
41
|
+
* // Clean up
|
|
42
|
+
* await manager.clear()
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare class BunSQLPreparedStatementManager {
|
|
46
|
+
private readonly client;
|
|
47
|
+
private statements;
|
|
48
|
+
private sqlToName;
|
|
49
|
+
private readonly config;
|
|
50
|
+
private cleanupTimer?;
|
|
51
|
+
constructor(client: BunSQLClient, config?: PreparedStatementManagerConfig);
|
|
52
|
+
/**
|
|
53
|
+
* Prepare a SQL statement for repeated execution
|
|
54
|
+
*
|
|
55
|
+
* @param sql - SQL query to prepare
|
|
56
|
+
* @returns Prepared statement identifier
|
|
57
|
+
*/
|
|
58
|
+
prepare(sql: string): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Execute a prepared statement
|
|
61
|
+
*
|
|
62
|
+
* @param name - Prepared statement identifier
|
|
63
|
+
* @param bindings - Query parameters
|
|
64
|
+
* @returns Query result rows
|
|
65
|
+
*/
|
|
66
|
+
execute<T = Record<string, unknown>>(name: string, bindings?: unknown[]): Promise<T[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Clear all prepared statements
|
|
69
|
+
*/
|
|
70
|
+
clear(): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Clean up idle statements
|
|
73
|
+
*/
|
|
74
|
+
cleanup(): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Get statement usage statistics
|
|
77
|
+
*
|
|
78
|
+
* @param name - Prepared statement identifier
|
|
79
|
+
* @returns Usage statistics or null if not found
|
|
80
|
+
*/
|
|
81
|
+
getStats(name: string): {
|
|
82
|
+
useCount: number;
|
|
83
|
+
lastUsed: number;
|
|
84
|
+
} | null;
|
|
85
|
+
/**
|
|
86
|
+
* Get the number of cached statements
|
|
87
|
+
*/
|
|
88
|
+
getSize(): number;
|
|
89
|
+
/**
|
|
90
|
+
* Destroy the manager and clean up resources
|
|
91
|
+
*/
|
|
92
|
+
destroy(): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Evict the least recently used statement
|
|
95
|
+
* @private
|
|
96
|
+
*/
|
|
97
|
+
private evictLeastRecentlyUsed;
|
|
98
|
+
/**
|
|
99
|
+
* Generate a unique statement name
|
|
100
|
+
* @private
|
|
101
|
+
*/
|
|
102
|
+
private generateStatementName;
|
|
103
|
+
/**
|
|
104
|
+
* Simple hash function for SQL strings
|
|
105
|
+
* @private
|
|
106
|
+
*/
|
|
107
|
+
private simpleHash;
|
|
108
|
+
/**
|
|
109
|
+
* Start periodic cleanup timer
|
|
110
|
+
* @private
|
|
111
|
+
*/
|
|
112
|
+
private startCleanupTimer;
|
|
113
|
+
/**
|
|
114
|
+
* Stop cleanup timer
|
|
115
|
+
* @private
|
|
116
|
+
*/
|
|
117
|
+
private stopCleanupTimer;
|
|
118
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ConnectionConfig, DriverContract, DriverType, ExecuteResult, QueryResult } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* MongoDB Driver
|
|
4
|
+
* Provides a document interface via DB.connection('mongodb')
|
|
5
|
+
*/
|
|
6
|
+
import type { MongoClient } from './types';
|
|
7
|
+
export declare class MongoDBDriver implements DriverContract {
|
|
8
|
+
private config;
|
|
9
|
+
private client;
|
|
10
|
+
private db;
|
|
11
|
+
private MongoClientCtor?;
|
|
12
|
+
constructor(config: ConnectionConfig, deps?: {
|
|
13
|
+
MongoClient?: new (url: string, options?: Record<string, unknown>) => MongoClient;
|
|
14
|
+
});
|
|
15
|
+
getDriverName(): DriverType;
|
|
16
|
+
connect(): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Dynamically load mongodb module
|
|
19
|
+
*/
|
|
20
|
+
private loadMongoModule;
|
|
21
|
+
disconnect(): Promise<void>;
|
|
22
|
+
isConnected(): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Execute a query (Protocol: JSON String)
|
|
25
|
+
*/
|
|
26
|
+
query<T = Record<string, unknown>>(protocolJson: string, _bindings?: unknown[]): Promise<QueryResult<T>>;
|
|
27
|
+
/**
|
|
28
|
+
* Execute a write operation (Protocol: JSON String)
|
|
29
|
+
*/
|
|
30
|
+
execute(protocolJson: string, _bindings?: unknown[]): Promise<ExecuteResult>;
|
|
31
|
+
beginTransaction(): Promise<void>;
|
|
32
|
+
commit(): Promise<void>;
|
|
33
|
+
rollback(): Promise<void>;
|
|
34
|
+
inTransaction(): boolean;
|
|
35
|
+
private mapDocument;
|
|
36
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MySQL/MariaDB Driver
|
|
3
|
+
* @description Database driver for MySQL and MariaDB using mysql2 package
|
|
4
|
+
*/
|
|
5
|
+
import type { ConnectionConfig, DriverContract, DriverType, ExecuteResult, QueryResult } from '../types';
|
|
6
|
+
export declare class MySQLDriver implements DriverContract {
|
|
7
|
+
private readonly config;
|
|
8
|
+
private readonly driverType;
|
|
9
|
+
private pool;
|
|
10
|
+
private transactionConnection;
|
|
11
|
+
private connected;
|
|
12
|
+
private mysql;
|
|
13
|
+
constructor(config: ConnectionConfig, driverType?: 'mysql' | 'mariadb');
|
|
14
|
+
/**
|
|
15
|
+
* Get the driver name
|
|
16
|
+
*/
|
|
17
|
+
getDriverName(): DriverType;
|
|
18
|
+
/**
|
|
19
|
+
* Connect to MySQL/MariaDB
|
|
20
|
+
*/
|
|
21
|
+
connect(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Dynamically load mysql2 module
|
|
24
|
+
*/
|
|
25
|
+
private loadMySQLModule;
|
|
26
|
+
/**
|
|
27
|
+
* Disconnect from MySQL
|
|
28
|
+
*/
|
|
29
|
+
disconnect(): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Check if connected
|
|
32
|
+
*/
|
|
33
|
+
isConnected(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Execute a query
|
|
36
|
+
*/
|
|
37
|
+
query<T = Record<string, unknown>>(sql: string, bindings?: unknown[]): Promise<QueryResult<T>>;
|
|
38
|
+
/**
|
|
39
|
+
* Execute a statement (INSERT/UPDATE/DELETE)
|
|
40
|
+
*/
|
|
41
|
+
execute(sql: string, bindings?: unknown[]): Promise<ExecuteResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Begin a transaction
|
|
44
|
+
*/
|
|
45
|
+
beginTransaction(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Commit the current transaction
|
|
48
|
+
*/
|
|
49
|
+
commit(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Rollback the current transaction
|
|
52
|
+
*/
|
|
53
|
+
rollback(): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Check if in transaction
|
|
56
|
+
*/
|
|
57
|
+
inTransaction(): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Get a connection from the pool
|
|
60
|
+
*/
|
|
61
|
+
private getConnection;
|
|
62
|
+
/**
|
|
63
|
+
* Normalize MySQL/MariaDB errors
|
|
64
|
+
*/
|
|
65
|
+
private normalizeError;
|
|
66
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostgreSQL Driver
|
|
3
|
+
* @description Database driver implementation for PostgreSQL using node-pg
|
|
4
|
+
*/
|
|
5
|
+
import type { DriverContract, DriverType, ExecuteResult, PostgresConfig, QueryResult } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* PostgreSQL Driver
|
|
8
|
+
* Connects and executes queries against PostgreSQL databases
|
|
9
|
+
*/
|
|
10
|
+
export declare class PostgresDriver implements DriverContract {
|
|
11
|
+
private readonly config;
|
|
12
|
+
private pool;
|
|
13
|
+
private connected;
|
|
14
|
+
private transactionActive;
|
|
15
|
+
private transactionClient;
|
|
16
|
+
private preparedStatements;
|
|
17
|
+
private statementCounter;
|
|
18
|
+
constructor(config: PostgresConfig);
|
|
19
|
+
/**
|
|
20
|
+
* Get driver name
|
|
21
|
+
*/
|
|
22
|
+
getDriverName(): DriverType;
|
|
23
|
+
/**
|
|
24
|
+
* Connect to the database
|
|
25
|
+
*/
|
|
26
|
+
connect(): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Disconnect from the database
|
|
29
|
+
*/
|
|
30
|
+
disconnect(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Check if connected
|
|
33
|
+
*/
|
|
34
|
+
isConnected(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Execute a query and return results
|
|
37
|
+
*/
|
|
38
|
+
query<T = Record<string, unknown>>(sql: string, bindings?: unknown[]): Promise<QueryResult<T>>;
|
|
39
|
+
/**
|
|
40
|
+
* Execute a statement (INSERT/UPDATE/DELETE)
|
|
41
|
+
*/
|
|
42
|
+
execute(sql: string, bindings?: unknown[]): Promise<ExecuteResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Prepare a statement for repeated execution
|
|
45
|
+
*/
|
|
46
|
+
prepare(sql: string): Promise<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Execute a prepared statement
|
|
49
|
+
*/
|
|
50
|
+
executePrepared<T>(name: string, bindings?: unknown[]): Promise<QueryResult<T>>;
|
|
51
|
+
/**
|
|
52
|
+
* Clear all prepared statements
|
|
53
|
+
*/
|
|
54
|
+
clearPreparedStatements(): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Begin a transaction
|
|
57
|
+
*/
|
|
58
|
+
beginTransaction(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Commit the current transaction
|
|
61
|
+
*/
|
|
62
|
+
commit(): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Rollback the current transaction
|
|
65
|
+
*/
|
|
66
|
+
rollback(): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Check if currently in a transaction
|
|
69
|
+
*/
|
|
70
|
+
inTransaction(): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Get a client for executing queries
|
|
73
|
+
*/
|
|
74
|
+
private getClient;
|
|
75
|
+
/**
|
|
76
|
+
* Normalize PostgreSQL errors
|
|
77
|
+
*/
|
|
78
|
+
private normalizeError;
|
|
79
|
+
/**
|
|
80
|
+
* Dynamically load the pg module
|
|
81
|
+
*/
|
|
82
|
+
private loadPgModule;
|
|
83
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redis Driver
|
|
3
|
+
* @description Driver implementation for Redis using ioredis
|
|
4
|
+
*/
|
|
5
|
+
import type { ConnectionConfig, DriverContract, DriverType, ExecuteResult, QueryResult } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Redis Driver
|
|
8
|
+
* Provides a key-value interface via DB.connection('redis')
|
|
9
|
+
*/
|
|
10
|
+
import type { RedisClient } from './types';
|
|
11
|
+
export declare class RedisDriver implements DriverContract {
|
|
12
|
+
private config;
|
|
13
|
+
private client;
|
|
14
|
+
private RedisCtor?;
|
|
15
|
+
constructor(config: ConnectionConfig, deps?: {
|
|
16
|
+
Redis?: new (config: Record<string, unknown>) => RedisClient;
|
|
17
|
+
});
|
|
18
|
+
getDriverName(): DriverType;
|
|
19
|
+
connect(): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Dynamically load ioredis module
|
|
22
|
+
*/
|
|
23
|
+
private loadRedisModule;
|
|
24
|
+
disconnect(): Promise<void>;
|
|
25
|
+
isConnected(): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Raw Redis command execution via pseudo-SQL or direct mapping
|
|
28
|
+
*/
|
|
29
|
+
query<T = any>(_sql: string, _bindings?: unknown[]): Promise<QueryResult<T>>;
|
|
30
|
+
execute(_sql: string, _bindings?: unknown[]): Promise<ExecuteResult>;
|
|
31
|
+
get(key: string): Promise<string | null>;
|
|
32
|
+
set(key: string, value: string | number): Promise<'OK'>;
|
|
33
|
+
setex(key: string, seconds: number, value: string | number): Promise<'OK'>;
|
|
34
|
+
del(key: string): Promise<number>;
|
|
35
|
+
/**
|
|
36
|
+
* Get the raw ioredis client for advanced operations
|
|
37
|
+
*/
|
|
38
|
+
getRawClient(): RedisClient | null;
|
|
39
|
+
beginTransaction(): Promise<void>;
|
|
40
|
+
commit(): Promise<void>;
|
|
41
|
+
rollback(): Promise<void>;
|
|
42
|
+
inTransaction(): boolean;
|
|
43
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite Driver
|
|
3
|
+
* @description Database driver implementation for SQLite using better-sqlite3
|
|
4
|
+
*/
|
|
5
|
+
import type { ConnectionConfig, DriverContract, DriverType, ExecuteResult, QueryResult } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
|
|
8
|
+
* SQLite Driver
|
|
9
|
+
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* SQLite driver implementation for Atlas ORM.
|
|
13
|
+
*
|
|
14
|
+
* Automatically detects and uses `bun:sqlite` if running in Bun,
|
|
15
|
+
* otherwise falls back to `better-sqlite3`.
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
* @since 3.0.0
|
|
19
|
+
*/
|
|
20
|
+
export declare class SQLiteDriver implements DriverContract {
|
|
21
|
+
private config;
|
|
22
|
+
private client;
|
|
23
|
+
private inTransactionState;
|
|
24
|
+
constructor(config: ConnectionConfig);
|
|
25
|
+
getDriverName(): DriverType;
|
|
26
|
+
connect(): Promise<void>;
|
|
27
|
+
disconnect(): Promise<void>;
|
|
28
|
+
isConnected(): boolean;
|
|
29
|
+
query<T = Record<string, unknown>>(sql: string, bindings?: unknown[]): Promise<QueryResult<T>>;
|
|
30
|
+
execute(sql: string, bindings?: unknown[]): Promise<ExecuteResult>;
|
|
31
|
+
beginTransaction(): Promise<void>;
|
|
32
|
+
commit(): Promise<void>;
|
|
33
|
+
rollback(): Promise<void>;
|
|
34
|
+
inTransaction(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
* Normalize SQLite errors
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
*/
|
|
44
|
+
private normalizeError;
|
|
45
|
+
}
|