@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,1100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/atlas - Type Definitions
|
|
3
|
+
* @description Core types for the database query builder and ORM
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Supported database driver types
|
|
7
|
+
*/
|
|
8
|
+
export type DriverType = 'postgres' | 'mysql' | 'mariadb' | 'sqlite' | 'mongodb' | 'redis';
|
|
9
|
+
import type { AtlasMetrics, AtlasTracer } from '../observability';
|
|
10
|
+
/**
|
|
11
|
+
* Base connection interface
|
|
12
|
+
*/
|
|
13
|
+
export interface BaseConnectionConfig {
|
|
14
|
+
/**
|
|
15
|
+
* The database driver to use
|
|
16
|
+
*/
|
|
17
|
+
driver: DriverType;
|
|
18
|
+
/**
|
|
19
|
+
* Database host address
|
|
20
|
+
* @default 'localhost'
|
|
21
|
+
*/
|
|
22
|
+
host?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Database port number
|
|
25
|
+
*/
|
|
26
|
+
port?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Database name
|
|
29
|
+
*/
|
|
30
|
+
database?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Database username
|
|
33
|
+
*/
|
|
34
|
+
username?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Database password
|
|
37
|
+
*/
|
|
38
|
+
password?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Database character set
|
|
41
|
+
* @default 'utf8mb4'
|
|
42
|
+
*/
|
|
43
|
+
charset?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Database timezone
|
|
46
|
+
* @default 'UTC'
|
|
47
|
+
*/
|
|
48
|
+
timezone?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Connection pool configuration
|
|
51
|
+
*/
|
|
52
|
+
pool?: PoolConfig;
|
|
53
|
+
/**
|
|
54
|
+
* SSL configuration for secure connections
|
|
55
|
+
*/
|
|
56
|
+
ssl?: SSLConfig | boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Whether to use the native driver (e.g., Bun.sql) if available
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
useNativeDriver?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Pre-initialized tracer instance
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
tracer?: AtlasTracer;
|
|
67
|
+
/**
|
|
68
|
+
* Pre-initialized metrics instance
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
metrics?: AtlasMetrics;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Union type for all connection configurations
|
|
75
|
+
*/
|
|
76
|
+
export type ConnectionConfig = PostgresConfig | MySQLConfig | SQLiteConfig | MongoDBConfig | RedisConfig | BaseConnectionConfig;
|
|
77
|
+
export interface AtlasObservabilityConfig {
|
|
78
|
+
enabled: boolean;
|
|
79
|
+
tracing?: boolean;
|
|
80
|
+
metrics?: boolean;
|
|
81
|
+
serviceName?: string;
|
|
82
|
+
}
|
|
83
|
+
export interface AtlasConfig {
|
|
84
|
+
default: string;
|
|
85
|
+
connections: Record<string, ConnectionConfig>;
|
|
86
|
+
observability?: AtlasObservabilityConfig;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* PostgreSQL specific configuration
|
|
90
|
+
*/
|
|
91
|
+
export interface PostgresConfig extends BaseConnectionConfig {
|
|
92
|
+
/**
|
|
93
|
+
* Driver identifier
|
|
94
|
+
*/
|
|
95
|
+
driver: 'postgres';
|
|
96
|
+
/**
|
|
97
|
+
* Default database schema
|
|
98
|
+
* @default 'public'
|
|
99
|
+
*/
|
|
100
|
+
schema?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Application name for connection tracking
|
|
103
|
+
*/
|
|
104
|
+
applicationName?: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* MySQL/MariaDB specific configuration
|
|
108
|
+
*/
|
|
109
|
+
export interface MySQLConfig extends BaseConnectionConfig {
|
|
110
|
+
/**
|
|
111
|
+
* Driver identifier
|
|
112
|
+
*/
|
|
113
|
+
driver: 'mysql' | 'mariadb';
|
|
114
|
+
/**
|
|
115
|
+
* Path to Unix domain socket
|
|
116
|
+
*/
|
|
117
|
+
socketPath?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Whether to allow multiple SQL statements in a single query
|
|
120
|
+
* @default false
|
|
121
|
+
*/
|
|
122
|
+
multipleStatements?: boolean;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* SQLite specific configuration
|
|
126
|
+
*/
|
|
127
|
+
export interface SQLiteConfig {
|
|
128
|
+
/**
|
|
129
|
+
* Driver identifier
|
|
130
|
+
*/
|
|
131
|
+
driver: 'sqlite';
|
|
132
|
+
/**
|
|
133
|
+
* Database file path or ':memory:' for in-memory database
|
|
134
|
+
*/
|
|
135
|
+
database: string;
|
|
136
|
+
/**
|
|
137
|
+
* Whether to open the database in read-only mode
|
|
138
|
+
* @default false
|
|
139
|
+
*/
|
|
140
|
+
readonly?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Whether to use the native driver (e.g., Bun.sql) if available
|
|
143
|
+
* @default false
|
|
144
|
+
*/
|
|
145
|
+
useNativeDriver?: boolean;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* MongoDB specific configuration
|
|
149
|
+
*/
|
|
150
|
+
export interface MongoDBConfig extends BaseConnectionConfig {
|
|
151
|
+
/**
|
|
152
|
+
* Driver identifier
|
|
153
|
+
*/
|
|
154
|
+
driver: 'mongodb';
|
|
155
|
+
/**
|
|
156
|
+
* MongoDB connection URI
|
|
157
|
+
*/
|
|
158
|
+
uri: string;
|
|
159
|
+
/**
|
|
160
|
+
* Additional MongoDB driver options
|
|
161
|
+
*/
|
|
162
|
+
options?: Record<string, unknown>;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Redis specific configuration
|
|
166
|
+
*/
|
|
167
|
+
export interface RedisConfig extends BaseConnectionConfig {
|
|
168
|
+
/**
|
|
169
|
+
* Driver identifier
|
|
170
|
+
*/
|
|
171
|
+
driver: 'redis';
|
|
172
|
+
/**
|
|
173
|
+
* Redis server host
|
|
174
|
+
*/
|
|
175
|
+
host: string;
|
|
176
|
+
/**
|
|
177
|
+
* Redis server port
|
|
178
|
+
* @default 6379
|
|
179
|
+
*/
|
|
180
|
+
port?: number;
|
|
181
|
+
/**
|
|
182
|
+
* Redis server password
|
|
183
|
+
*/
|
|
184
|
+
password?: string;
|
|
185
|
+
/**
|
|
186
|
+
* Redis database index
|
|
187
|
+
* @default 0
|
|
188
|
+
*/
|
|
189
|
+
db?: number;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Connection pool configuration
|
|
193
|
+
*/
|
|
194
|
+
export interface PoolConfig {
|
|
195
|
+
/**
|
|
196
|
+
* Minimum number of connections in the pool
|
|
197
|
+
*/
|
|
198
|
+
min?: number;
|
|
199
|
+
/**
|
|
200
|
+
* Maximum number of connections in the pool
|
|
201
|
+
*/
|
|
202
|
+
max?: number;
|
|
203
|
+
/**
|
|
204
|
+
* Maximum time (ms) to wait for a connection from the pool
|
|
205
|
+
*/
|
|
206
|
+
acquireTimeout?: number;
|
|
207
|
+
/**
|
|
208
|
+
* Maximum time (ms) a connection can be idle before being released
|
|
209
|
+
*/
|
|
210
|
+
idleTimeout?: number;
|
|
211
|
+
/**
|
|
212
|
+
* Interval (ms) to check for idle connections to reap
|
|
213
|
+
*/
|
|
214
|
+
reapInterval?: number;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* SSL configuration
|
|
218
|
+
*/
|
|
219
|
+
export interface SSLConfig {
|
|
220
|
+
/**
|
|
221
|
+
* Whether to reject unauthorized connections
|
|
222
|
+
*/
|
|
223
|
+
rejectUnauthorized?: boolean;
|
|
224
|
+
/**
|
|
225
|
+
* Certificate Authority (CA) certificate
|
|
226
|
+
*/
|
|
227
|
+
ca?: string;
|
|
228
|
+
/**
|
|
229
|
+
* Client private key
|
|
230
|
+
*/
|
|
231
|
+
key?: string;
|
|
232
|
+
/**
|
|
233
|
+
* Client certificate
|
|
234
|
+
*/
|
|
235
|
+
cert?: string;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Supported comparison operators
|
|
239
|
+
*/
|
|
240
|
+
export type Operator = '=' | '!=' | '<>' | '<' | '<=' | '>' | '>=' | 'like' | 'ilike' | 'not like' | 'in' | 'not in' | 'between' | 'not between' | 'is' | 'is not';
|
|
241
|
+
/**
|
|
242
|
+
* Boolean operators for WHERE clauses
|
|
243
|
+
*/
|
|
244
|
+
export type BooleanOperator = 'and' | 'or';
|
|
245
|
+
/**
|
|
246
|
+
* Order direction
|
|
247
|
+
*/
|
|
248
|
+
export type OrderDirection = 'asc' | 'desc';
|
|
249
|
+
/**
|
|
250
|
+
* Join types
|
|
251
|
+
*/
|
|
252
|
+
export type JoinType = 'inner' | 'left' | 'right' | 'cross' | 'full';
|
|
253
|
+
/**
|
|
254
|
+
* WHERE clause structure
|
|
255
|
+
*/
|
|
256
|
+
export interface WhereClause {
|
|
257
|
+
/**
|
|
258
|
+
* Type of the where clause
|
|
259
|
+
*/
|
|
260
|
+
type: 'basic' | 'nested' | 'in' | 'null' | 'between' | 'raw' | 'exists' | 'column';
|
|
261
|
+
/**
|
|
262
|
+
* Column name
|
|
263
|
+
*/
|
|
264
|
+
column?: string;
|
|
265
|
+
/**
|
|
266
|
+
* Comparison operator
|
|
267
|
+
*/
|
|
268
|
+
operator?: Operator;
|
|
269
|
+
/**
|
|
270
|
+
* Value for basic comparison
|
|
271
|
+
*/
|
|
272
|
+
value?: unknown;
|
|
273
|
+
/**
|
|
274
|
+
* Values for IN or BETWEEN clauses
|
|
275
|
+
*/
|
|
276
|
+
values?: unknown[];
|
|
277
|
+
/**
|
|
278
|
+
* Boolean operator (AND/OR)
|
|
279
|
+
*/
|
|
280
|
+
boolean: BooleanOperator;
|
|
281
|
+
/**
|
|
282
|
+
* Whether to negate the clause (NOT)
|
|
283
|
+
*/
|
|
284
|
+
not?: boolean;
|
|
285
|
+
/**
|
|
286
|
+
* Nested query builder for subqueries
|
|
287
|
+
*/
|
|
288
|
+
query?: QueryBuilderContract;
|
|
289
|
+
/**
|
|
290
|
+
* Raw SQL for raw clauses
|
|
291
|
+
*/
|
|
292
|
+
sql?: string;
|
|
293
|
+
/**
|
|
294
|
+
* Bindings for raw clauses
|
|
295
|
+
*/
|
|
296
|
+
bindings?: unknown[];
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* ORDER BY clause structure
|
|
300
|
+
*/
|
|
301
|
+
export interface OrderClause {
|
|
302
|
+
/**
|
|
303
|
+
* Column name
|
|
304
|
+
*/
|
|
305
|
+
column: string;
|
|
306
|
+
/**
|
|
307
|
+
* Sort direction
|
|
308
|
+
*/
|
|
309
|
+
direction: OrderDirection;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* JOIN clause structure
|
|
313
|
+
*/
|
|
314
|
+
export interface JoinClause {
|
|
315
|
+
/**
|
|
316
|
+
* Type of join
|
|
317
|
+
*/
|
|
318
|
+
type: JoinType;
|
|
319
|
+
/**
|
|
320
|
+
* Table to join
|
|
321
|
+
*/
|
|
322
|
+
table: string;
|
|
323
|
+
/**
|
|
324
|
+
* First column for join condition
|
|
325
|
+
*/
|
|
326
|
+
first: string;
|
|
327
|
+
/**
|
|
328
|
+
* Operator for join condition
|
|
329
|
+
*/
|
|
330
|
+
operator: string;
|
|
331
|
+
/**
|
|
332
|
+
* Second column for join condition
|
|
333
|
+
*/
|
|
334
|
+
second: string;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* HAVING clause structure
|
|
338
|
+
*/
|
|
339
|
+
export interface HavingClause {
|
|
340
|
+
/**
|
|
341
|
+
* Type of having clause
|
|
342
|
+
*/
|
|
343
|
+
type: 'basic' | 'raw';
|
|
344
|
+
/**
|
|
345
|
+
* Column name
|
|
346
|
+
*/
|
|
347
|
+
column?: string;
|
|
348
|
+
/**
|
|
349
|
+
* Comparison operator
|
|
350
|
+
*/
|
|
351
|
+
operator?: Operator;
|
|
352
|
+
/**
|
|
353
|
+
* Value for comparison
|
|
354
|
+
*/
|
|
355
|
+
value?: unknown;
|
|
356
|
+
/**
|
|
357
|
+
* Boolean operator (AND/OR)
|
|
358
|
+
*/
|
|
359
|
+
boolean: BooleanOperator;
|
|
360
|
+
/**
|
|
361
|
+
* Raw SQL for raw clauses
|
|
362
|
+
*/
|
|
363
|
+
sql?: string;
|
|
364
|
+
/**
|
|
365
|
+
* Bindings for raw clauses
|
|
366
|
+
*/
|
|
367
|
+
bindings?: unknown[];
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Query execution result
|
|
371
|
+
*/
|
|
372
|
+
export interface QueryResult<T = Record<string, unknown>> {
|
|
373
|
+
/**
|
|
374
|
+
* Result rows
|
|
375
|
+
*/
|
|
376
|
+
rows: T[];
|
|
377
|
+
/**
|
|
378
|
+
* Number of rows returned
|
|
379
|
+
*/
|
|
380
|
+
rowCount: number;
|
|
381
|
+
/**
|
|
382
|
+
* Last inserted ID (if available)
|
|
383
|
+
*/
|
|
384
|
+
insertId?: number | bigint | string | undefined;
|
|
385
|
+
/**
|
|
386
|
+
* Field metadata
|
|
387
|
+
*/
|
|
388
|
+
fields?: FieldInfo[];
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Field information from query result
|
|
392
|
+
*/
|
|
393
|
+
export interface FieldInfo {
|
|
394
|
+
/**
|
|
395
|
+
* Field name
|
|
396
|
+
*/
|
|
397
|
+
name: string;
|
|
398
|
+
/**
|
|
399
|
+
* Data type name
|
|
400
|
+
*/
|
|
401
|
+
dataType?: string | undefined;
|
|
402
|
+
/**
|
|
403
|
+
* Table ID (if available)
|
|
404
|
+
*/
|
|
405
|
+
tableId?: number | undefined;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Execution result (INSERT/UPDATE/DELETE)
|
|
409
|
+
*/
|
|
410
|
+
export interface ExecuteResult {
|
|
411
|
+
/**
|
|
412
|
+
* Number of affected rows
|
|
413
|
+
*/
|
|
414
|
+
affectedRows: number;
|
|
415
|
+
/**
|
|
416
|
+
* Last inserted ID (for INSERT)
|
|
417
|
+
*/
|
|
418
|
+
insertId?: number | bigint | string | undefined;
|
|
419
|
+
/**
|
|
420
|
+
* Number of changed rows (for UPDATE)
|
|
421
|
+
*/
|
|
422
|
+
changedRows?: number | undefined;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Pagination result
|
|
426
|
+
*/
|
|
427
|
+
export interface PaginateResult<T> {
|
|
428
|
+
/**
|
|
429
|
+
* Paginated data
|
|
430
|
+
*/
|
|
431
|
+
data: T[];
|
|
432
|
+
/**
|
|
433
|
+
* Pagination metadata
|
|
434
|
+
*/
|
|
435
|
+
pagination: {
|
|
436
|
+
/**
|
|
437
|
+
* Current page number
|
|
438
|
+
*/
|
|
439
|
+
page: number;
|
|
440
|
+
/**
|
|
441
|
+
* Number of items per page
|
|
442
|
+
*/
|
|
443
|
+
perPage: number;
|
|
444
|
+
/**
|
|
445
|
+
* Total number of items
|
|
446
|
+
*/
|
|
447
|
+
total: number;
|
|
448
|
+
/**
|
|
449
|
+
* Total number of pages
|
|
450
|
+
*/
|
|
451
|
+
totalPages: number;
|
|
452
|
+
/**
|
|
453
|
+
* Whether there is a next page
|
|
454
|
+
*/
|
|
455
|
+
hasNext: boolean;
|
|
456
|
+
/**
|
|
457
|
+
* Whether there is a previous page
|
|
458
|
+
*/
|
|
459
|
+
hasPrev: boolean;
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Connection pool statistics
|
|
464
|
+
*/
|
|
465
|
+
export interface PoolStats {
|
|
466
|
+
/**
|
|
467
|
+
* Number of idle connections in the pool
|
|
468
|
+
*/
|
|
469
|
+
idle: number;
|
|
470
|
+
/**
|
|
471
|
+
* Number of connections waiting to be acquired
|
|
472
|
+
*/
|
|
473
|
+
pending: number;
|
|
474
|
+
/**
|
|
475
|
+
* Number of active connections currently in use
|
|
476
|
+
*/
|
|
477
|
+
active: number;
|
|
478
|
+
/**
|
|
479
|
+
* Total number of connections in the pool
|
|
480
|
+
*/
|
|
481
|
+
total: number;
|
|
482
|
+
/**
|
|
483
|
+
* Maximum number of connections allowed
|
|
484
|
+
*/
|
|
485
|
+
max: number;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Model base class (forward declaration)
|
|
489
|
+
* Actual implementation in src/orm/model/Model.ts
|
|
490
|
+
*/
|
|
491
|
+
export type Model = import('../orm/model/Model').Model;
|
|
492
|
+
/**
|
|
493
|
+
* Model constructor type (forward declaration)
|
|
494
|
+
*/
|
|
495
|
+
export type ModelConstructor<T extends Model> = import('../orm/model/Model').ModelConstructor<T>;
|
|
496
|
+
/**
|
|
497
|
+
* Database Driver Contract
|
|
498
|
+
*/
|
|
499
|
+
export interface DriverContract {
|
|
500
|
+
/**
|
|
501
|
+
* Get driver name
|
|
502
|
+
*/
|
|
503
|
+
getDriverName(): DriverType;
|
|
504
|
+
/**
|
|
505
|
+
* Connect to the database
|
|
506
|
+
*/
|
|
507
|
+
connect(): Promise<void>;
|
|
508
|
+
/**
|
|
509
|
+
* Disconnect from the database
|
|
510
|
+
*/
|
|
511
|
+
disconnect(): Promise<void>;
|
|
512
|
+
/**
|
|
513
|
+
* Check if connected
|
|
514
|
+
*/
|
|
515
|
+
isConnected(): boolean;
|
|
516
|
+
/**
|
|
517
|
+
* Execute a query and return results
|
|
518
|
+
*/
|
|
519
|
+
query<T = Record<string, unknown>>(sql: string, bindings?: unknown[]): Promise<QueryResult<T>>;
|
|
520
|
+
/**
|
|
521
|
+
* Execute a statement (INSERT/UPDATE/DELETE)
|
|
522
|
+
*/
|
|
523
|
+
execute(sql: string, bindings?: unknown[]): Promise<ExecuteResult>;
|
|
524
|
+
/**
|
|
525
|
+
* Begin a transaction
|
|
526
|
+
*/
|
|
527
|
+
beginTransaction(): Promise<void>;
|
|
528
|
+
/**
|
|
529
|
+
* Commit the current transaction
|
|
530
|
+
*/
|
|
531
|
+
commit(): Promise<void>;
|
|
532
|
+
/**
|
|
533
|
+
* Rollback the current transaction
|
|
534
|
+
*/
|
|
535
|
+
rollback(): Promise<void>;
|
|
536
|
+
/**
|
|
537
|
+
* Check if currently in a transaction
|
|
538
|
+
*/
|
|
539
|
+
inTransaction(): boolean;
|
|
540
|
+
/**
|
|
541
|
+
* Prepare a statement for repeated execution
|
|
542
|
+
* @optional Only implemented by drivers that support prepared statements
|
|
543
|
+
* @param sql - SQL query to prepare
|
|
544
|
+
* @returns Prepared statement identifier
|
|
545
|
+
*/
|
|
546
|
+
prepare?(sql: string): Promise<string>;
|
|
547
|
+
/**
|
|
548
|
+
* Execute a prepared statement
|
|
549
|
+
* @optional Only implemented by drivers that support prepared statements
|
|
550
|
+
* @param name - Prepared statement identifier
|
|
551
|
+
* @param bindings - Query parameters
|
|
552
|
+
* @returns Query result
|
|
553
|
+
*/
|
|
554
|
+
executePrepared?<T = Record<string, unknown>>(name: string, bindings?: unknown[]): Promise<QueryResult<T>>;
|
|
555
|
+
/**
|
|
556
|
+
* Clear all prepared statements from cache
|
|
557
|
+
* @optional Only implemented by drivers that support prepared statements
|
|
558
|
+
*/
|
|
559
|
+
clearPreparedStatements?(): Promise<void>;
|
|
560
|
+
/**
|
|
561
|
+
* Stream query results for processing large datasets
|
|
562
|
+
* @optional Only implemented by drivers that support streaming
|
|
563
|
+
* @param sql - SQL query
|
|
564
|
+
* @param bindings - Query parameters
|
|
565
|
+
* @returns Async iterable of result rows
|
|
566
|
+
*/
|
|
567
|
+
stream?<T = Record<string, unknown>>(sql: string, bindings?: unknown[]): AsyncIterable<T>;
|
|
568
|
+
/**
|
|
569
|
+
* Get connection pool statistics
|
|
570
|
+
* @optional Only implemented by drivers that support connection pooling
|
|
571
|
+
* @returns Pool statistics or null if not supported
|
|
572
|
+
*/
|
|
573
|
+
getPoolStats?(): PoolStats | null;
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Connection Contract
|
|
577
|
+
*/
|
|
578
|
+
export interface ConnectionContract {
|
|
579
|
+
/**
|
|
580
|
+
* Get connection name
|
|
581
|
+
*/
|
|
582
|
+
getName(): string;
|
|
583
|
+
/**
|
|
584
|
+
* Get the underlying driver
|
|
585
|
+
*/
|
|
586
|
+
getDriver(): DriverContract;
|
|
587
|
+
/**
|
|
588
|
+
* Get connection configuration
|
|
589
|
+
*/
|
|
590
|
+
getConfig(): ConnectionConfig;
|
|
591
|
+
/**
|
|
592
|
+
* Get the tracer instance for this connection
|
|
593
|
+
*/
|
|
594
|
+
getTracer(): AtlasTracer | undefined;
|
|
595
|
+
/**
|
|
596
|
+
* Create a new query builder for the given table
|
|
597
|
+
*/
|
|
598
|
+
table<T = Record<string, unknown>>(tableName: string): QueryBuilderContract<T>;
|
|
599
|
+
/**
|
|
600
|
+
* Execute raw SQL query and return results
|
|
601
|
+
*/
|
|
602
|
+
raw<T = Record<string, unknown>>(sql: string, bindings?: unknown[]): Promise<QueryResult<T>>;
|
|
603
|
+
/**
|
|
604
|
+
* Execute raw SQL statement (INSERT/UPDATE/DELETE)
|
|
605
|
+
*/
|
|
606
|
+
execute(sql: string, bindings?: unknown[]): Promise<ExecuteResult>;
|
|
607
|
+
/**
|
|
608
|
+
* Execute a callback within a database transaction
|
|
609
|
+
*/
|
|
610
|
+
transaction<T>(callback: (connection: ConnectionContract) => Promise<T>): Promise<T>;
|
|
611
|
+
/**
|
|
612
|
+
* Disconnect from the database
|
|
613
|
+
*/
|
|
614
|
+
disconnect(): Promise<void>;
|
|
615
|
+
/**
|
|
616
|
+
* Get the grammar instance for this connection
|
|
617
|
+
*/
|
|
618
|
+
getGrammar(): GrammarContract;
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Query Builder Contract
|
|
622
|
+
*/
|
|
623
|
+
export interface QueryBuilderContract<T = Record<string, unknown>> {
|
|
624
|
+
/**
|
|
625
|
+
* Set the model for hydration
|
|
626
|
+
*/
|
|
627
|
+
setModel<M extends Model = Model>(model: ModelConstructor<M>): this;
|
|
628
|
+
/**
|
|
629
|
+
* Get the current model
|
|
630
|
+
*/
|
|
631
|
+
getModel<M extends Model = Model>(): ModelConstructor<M> | undefined;
|
|
632
|
+
/**
|
|
633
|
+
* Select columns for the query
|
|
634
|
+
*/
|
|
635
|
+
select(...columns: string[]): this;
|
|
636
|
+
/**
|
|
637
|
+
* Set the table for the query
|
|
638
|
+
*/
|
|
639
|
+
from(table: string): this;
|
|
640
|
+
/**
|
|
641
|
+
* Add a raw select expression
|
|
642
|
+
*/
|
|
643
|
+
selectRaw(sql: string, bindings?: unknown[]): this;
|
|
644
|
+
/**
|
|
645
|
+
* Force the query to return distinct results
|
|
646
|
+
*/
|
|
647
|
+
distinct(): this;
|
|
648
|
+
/**
|
|
649
|
+
* Add a basic where clause
|
|
650
|
+
*/
|
|
651
|
+
where(column: string, value: unknown | QueryBuilderContract<any>): this;
|
|
652
|
+
where(column: string, operator: Operator, value: unknown | QueryBuilderContract<any>): this;
|
|
653
|
+
where(callback: (query: QueryBuilderContract<T>) => void): this;
|
|
654
|
+
where(conditions: Record<string, unknown | QueryBuilderContract<any>>): this;
|
|
655
|
+
/**
|
|
656
|
+
* Add an "or where" clause
|
|
657
|
+
*/
|
|
658
|
+
orWhere(column: string, value: unknown | QueryBuilderContract<any>): this;
|
|
659
|
+
orWhere(column: string, operator: Operator, value: unknown | QueryBuilderContract<any>): this;
|
|
660
|
+
orWhere(callback: (query: QueryBuilderContract<T>) => void): this;
|
|
661
|
+
/**
|
|
662
|
+
* Add a "where in" clause
|
|
663
|
+
*/
|
|
664
|
+
whereIn(column: string, values: unknown[] | QueryBuilderContract<any>): this;
|
|
665
|
+
/**
|
|
666
|
+
* Add a "where not in" clause
|
|
667
|
+
*/
|
|
668
|
+
whereNotIn(column: string, values: unknown[] | QueryBuilderContract<any>): this;
|
|
669
|
+
/**
|
|
670
|
+
* Add an "or where in" clause
|
|
671
|
+
*/
|
|
672
|
+
orWhereIn(column: string, values: unknown[] | QueryBuilderContract<any>): this;
|
|
673
|
+
/**
|
|
674
|
+
* Add an "or where not in" clause
|
|
675
|
+
*/
|
|
676
|
+
orWhereNotIn(column: string, values: unknown[] | QueryBuilderContract<any>): this;
|
|
677
|
+
/**
|
|
678
|
+
* Add a "where null" clause
|
|
679
|
+
*/
|
|
680
|
+
whereNull(column: string): this;
|
|
681
|
+
/**
|
|
682
|
+
* Add a "where not null" clause
|
|
683
|
+
*/
|
|
684
|
+
whereNotNull(column: string): this;
|
|
685
|
+
/**
|
|
686
|
+
* Add an "or where null" clause
|
|
687
|
+
*/
|
|
688
|
+
orWhereNull(column: string): this;
|
|
689
|
+
/**
|
|
690
|
+
* Add an "or where not null" clause
|
|
691
|
+
*/
|
|
692
|
+
orWhereNotNull(column: string): this;
|
|
693
|
+
/**
|
|
694
|
+
* Add a "where between" clause
|
|
695
|
+
*/
|
|
696
|
+
whereBetween(column: string, values: [unknown, unknown]): this;
|
|
697
|
+
/**
|
|
698
|
+
* Add a "where not between" clause
|
|
699
|
+
*/
|
|
700
|
+
whereNotBetween(column: string, values: [unknown, unknown]): this;
|
|
701
|
+
/**
|
|
702
|
+
* Add a raw where clause
|
|
703
|
+
*/
|
|
704
|
+
whereRaw(sql: string, bindings?: unknown[]): this;
|
|
705
|
+
/**
|
|
706
|
+
* Add a raw "or where" clause
|
|
707
|
+
*/
|
|
708
|
+
orWhereRaw(sql: string, bindings?: unknown[]): this;
|
|
709
|
+
/**
|
|
710
|
+
* Add a "where column" clause (comparing two columns)
|
|
711
|
+
*/
|
|
712
|
+
whereColumn(first: string, operator: Operator, second: string): this;
|
|
713
|
+
/**
|
|
714
|
+
* Add a "where exists" clause
|
|
715
|
+
*/
|
|
716
|
+
whereExists(callback: (query: QueryBuilderContract<unknown>) => void): this;
|
|
717
|
+
/**
|
|
718
|
+
* Add a "where not exists" clause
|
|
719
|
+
*/
|
|
720
|
+
whereNotExists(callback: (query: QueryBuilderContract<unknown>) => void): this;
|
|
721
|
+
/**
|
|
722
|
+
* Add a where clause for JSON fields
|
|
723
|
+
*/
|
|
724
|
+
whereJson(column: string, value: unknown): this;
|
|
725
|
+
/**
|
|
726
|
+
* Add an "or where" clause for JSON fields
|
|
727
|
+
*/
|
|
728
|
+
orWhereJson(column: string, value: unknown): this;
|
|
729
|
+
/**
|
|
730
|
+
* Add a "where json contains" clause
|
|
731
|
+
*/
|
|
732
|
+
whereJsonContains(column: string, value: unknown): this;
|
|
733
|
+
/**
|
|
734
|
+
* Add an "or where json contains" clause
|
|
735
|
+
*/
|
|
736
|
+
orWhereJsonContains(column: string, value: unknown): this;
|
|
737
|
+
/**
|
|
738
|
+
* Add an inner join clause
|
|
739
|
+
*/
|
|
740
|
+
join(table: string, first: string, operator: string, second: string): this;
|
|
741
|
+
/**
|
|
742
|
+
* Add a left join clause
|
|
743
|
+
*/
|
|
744
|
+
leftJoin(table: string, first: string, operator: string, second: string): this;
|
|
745
|
+
/**
|
|
746
|
+
* Add a right join clause
|
|
747
|
+
*/
|
|
748
|
+
rightJoin(table: string, first: string, operator: string, second: string): this;
|
|
749
|
+
/**
|
|
750
|
+
* Add a cross join clause
|
|
751
|
+
*/
|
|
752
|
+
crossJoin(table: string): this;
|
|
753
|
+
/**
|
|
754
|
+
* Add a group by clause
|
|
755
|
+
*/
|
|
756
|
+
groupBy(...columns: string[]): this;
|
|
757
|
+
/**
|
|
758
|
+
* Add a having clause
|
|
759
|
+
*/
|
|
760
|
+
having(column: string, operator: Operator, value: unknown): this;
|
|
761
|
+
/**
|
|
762
|
+
* Add a raw having clause
|
|
763
|
+
*/
|
|
764
|
+
havingRaw(sql: string, bindings?: unknown[]): this;
|
|
765
|
+
/**
|
|
766
|
+
* Add an order by clause
|
|
767
|
+
*/
|
|
768
|
+
orderBy(column: string, direction?: OrderDirection): this;
|
|
769
|
+
/**
|
|
770
|
+
* Add a descending order by clause
|
|
771
|
+
*/
|
|
772
|
+
orderByDesc(column: string): this;
|
|
773
|
+
/**
|
|
774
|
+
* Add a raw order by clause
|
|
775
|
+
*/
|
|
776
|
+
orderByRaw(sql: string, bindings?: unknown[]): this;
|
|
777
|
+
/**
|
|
778
|
+
* Order by the latest record (created_at by default)
|
|
779
|
+
*/
|
|
780
|
+
latest(column?: string): this;
|
|
781
|
+
/**
|
|
782
|
+
* Order by the oldest record (created_at by default)
|
|
783
|
+
*/
|
|
784
|
+
oldest(column?: string): this;
|
|
785
|
+
/**
|
|
786
|
+
* Set the limit for the query
|
|
787
|
+
*/
|
|
788
|
+
limit(value: number): this;
|
|
789
|
+
/**
|
|
790
|
+
* Set the offset for the query
|
|
791
|
+
*/
|
|
792
|
+
offset(value: number): this;
|
|
793
|
+
/**
|
|
794
|
+
* Alias for offset
|
|
795
|
+
*/
|
|
796
|
+
skip(value: number): this;
|
|
797
|
+
/**
|
|
798
|
+
* Alias for limit
|
|
799
|
+
*/
|
|
800
|
+
take(value: number): this;
|
|
801
|
+
/**
|
|
802
|
+
* Execute the query and get all results
|
|
803
|
+
*/
|
|
804
|
+
get(): Promise<T[]>;
|
|
805
|
+
/**
|
|
806
|
+
* Stream query results for processing large datasets
|
|
807
|
+
* Returns an async iterator that yields records one at a time
|
|
808
|
+
*
|
|
809
|
+
* @example
|
|
810
|
+
* ```typescript
|
|
811
|
+
* for await (const user of User.query().where('active', true).stream()) {
|
|
812
|
+
* await processUser(user)
|
|
813
|
+
* }
|
|
814
|
+
* ```
|
|
815
|
+
*/
|
|
816
|
+
stream(): AsyncIterable<T>;
|
|
817
|
+
/**
|
|
818
|
+
* Get the first result
|
|
819
|
+
*/
|
|
820
|
+
first(): Promise<T | null>;
|
|
821
|
+
/**
|
|
822
|
+
* Get the first result or throw an error
|
|
823
|
+
*/
|
|
824
|
+
firstOrFail(): Promise<T>;
|
|
825
|
+
/**
|
|
826
|
+
* Find a record by its primary key
|
|
827
|
+
*/
|
|
828
|
+
find(id: unknown, primaryKey?: string): Promise<T | null>;
|
|
829
|
+
/**
|
|
830
|
+
* Find a record by its primary key or throw an error
|
|
831
|
+
*/
|
|
832
|
+
findOrFail(id: unknown, primaryKey?: string): Promise<T>;
|
|
833
|
+
/**
|
|
834
|
+
* Get a single value from the first record
|
|
835
|
+
*/
|
|
836
|
+
value<V = unknown>(column: string): Promise<V | null>;
|
|
837
|
+
/**
|
|
838
|
+
* Get an array of values from a single column
|
|
839
|
+
*/
|
|
840
|
+
pluck<V = unknown>(column: string): Promise<V[]>;
|
|
841
|
+
/**
|
|
842
|
+
* Check if any records exist matching the query
|
|
843
|
+
*/
|
|
844
|
+
exists(): Promise<boolean>;
|
|
845
|
+
/**
|
|
846
|
+
* Check if no records exist matching the query
|
|
847
|
+
*/
|
|
848
|
+
doesntExist(): Promise<boolean>;
|
|
849
|
+
/**
|
|
850
|
+
* Get the count of records
|
|
851
|
+
*/
|
|
852
|
+
count(column?: string): Promise<number>;
|
|
853
|
+
/**
|
|
854
|
+
* Get the maximum value of a column
|
|
855
|
+
*/
|
|
856
|
+
max<V = number>(column: string): Promise<V | null>;
|
|
857
|
+
/**
|
|
858
|
+
* Get the minimum value of a column
|
|
859
|
+
*/
|
|
860
|
+
min<V = number>(column: string): Promise<V | null>;
|
|
861
|
+
/**
|
|
862
|
+
* Get the average value of a column
|
|
863
|
+
*/
|
|
864
|
+
avg(column: string): Promise<number | null>;
|
|
865
|
+
/**
|
|
866
|
+
* Get the sum of a column
|
|
867
|
+
*/
|
|
868
|
+
sum(column: string): Promise<number>;
|
|
869
|
+
/**
|
|
870
|
+
* Insert new records
|
|
871
|
+
*/
|
|
872
|
+
insert(data: Partial<T> | Partial<T>[]): Promise<T[]>;
|
|
873
|
+
/**
|
|
874
|
+
* Insert a record and get its ID
|
|
875
|
+
*/
|
|
876
|
+
insertGetId(data: Partial<T>, primaryKey?: string): Promise<number | bigint>;
|
|
877
|
+
/**
|
|
878
|
+
* Update existing records
|
|
879
|
+
*/
|
|
880
|
+
update(data: Partial<T>): Promise<number>;
|
|
881
|
+
/**
|
|
882
|
+
* Update a JSON field
|
|
883
|
+
*/
|
|
884
|
+
updateJson(column: string, value: unknown): Promise<number>;
|
|
885
|
+
/**
|
|
886
|
+
* Delete records
|
|
887
|
+
*/
|
|
888
|
+
delete(): Promise<number>;
|
|
889
|
+
/**
|
|
890
|
+
* Truncate the table
|
|
891
|
+
*/
|
|
892
|
+
truncate(): Promise<void>;
|
|
893
|
+
/**
|
|
894
|
+
* Increment a column's value
|
|
895
|
+
*/
|
|
896
|
+
increment(column: string, amount?: number, extra?: Partial<T>): Promise<number>;
|
|
897
|
+
/**
|
|
898
|
+
* Decrement a column's value
|
|
899
|
+
*/
|
|
900
|
+
decrement(column: string, amount?: number, extra?: Partial<T>): Promise<number>;
|
|
901
|
+
/**
|
|
902
|
+
* Insert or update records
|
|
903
|
+
*/
|
|
904
|
+
upsert(data: Partial<T> | Partial<T>[], uniqueBy: string | string[], update?: string[]): Promise<number>;
|
|
905
|
+
/**
|
|
906
|
+
* Paginate the query results
|
|
907
|
+
*/
|
|
908
|
+
paginate(perPage?: number, page?: number): Promise<PaginateResult<T>>;
|
|
909
|
+
/**
|
|
910
|
+
* Simple pagination (no total count)
|
|
911
|
+
*/
|
|
912
|
+
simplePaginate(perPage?: number, page?: number): Promise<PaginateResult<T>>;
|
|
913
|
+
/**
|
|
914
|
+
* Chunk the query results for processing large datasets
|
|
915
|
+
*/
|
|
916
|
+
chunk(size: number, callback: (results: T[]) => Promise<undefined | boolean>): Promise<void>;
|
|
917
|
+
/**
|
|
918
|
+
* Get the compiled SQL string
|
|
919
|
+
*/
|
|
920
|
+
toSql(): string;
|
|
921
|
+
/**
|
|
922
|
+
* Get the query bindings
|
|
923
|
+
*/
|
|
924
|
+
getBindings(): unknown[];
|
|
925
|
+
/**
|
|
926
|
+
* Dump the query SQL and bindings
|
|
927
|
+
*/
|
|
928
|
+
dump(): this;
|
|
929
|
+
/**
|
|
930
|
+
* Dump the query SQL and bindings and terminate execution
|
|
931
|
+
*/
|
|
932
|
+
dd(): never;
|
|
933
|
+
/**
|
|
934
|
+
* Clone the query builder instance
|
|
935
|
+
*/
|
|
936
|
+
clone(): QueryBuilderContract<T>;
|
|
937
|
+
/**
|
|
938
|
+
* Set the query to read-only mode to skip Model hydration overhead.
|
|
939
|
+
*/
|
|
940
|
+
readonly(value?: boolean): this;
|
|
941
|
+
/**
|
|
942
|
+
* Get the compiled query structure
|
|
943
|
+
*/
|
|
944
|
+
getCompiledQuery(): CompiledQuery;
|
|
945
|
+
/**
|
|
946
|
+
* Check if the query has a limit or offset
|
|
947
|
+
*/
|
|
948
|
+
hasLimitOrOffset(): boolean;
|
|
949
|
+
/**
|
|
950
|
+
* Eager load relationships
|
|
951
|
+
*/
|
|
952
|
+
with(relation: string | string[] | Record<string, (query: QueryBuilderContract<unknown>) => void>): this;
|
|
953
|
+
/**
|
|
954
|
+
* Add a WHERE HAS relationship existence clause
|
|
955
|
+
*/
|
|
956
|
+
whereHas(relation: string, callback?: (query: QueryBuilderContract<unknown>) => void): this;
|
|
957
|
+
/**
|
|
958
|
+
* Include soft-deleted records in the query
|
|
959
|
+
*/
|
|
960
|
+
withTrashed(): this;
|
|
961
|
+
/**
|
|
962
|
+
* Only include soft-deleted records in the query
|
|
963
|
+
*/
|
|
964
|
+
onlyTrashed(): this;
|
|
965
|
+
/**
|
|
966
|
+
* Restore soft-deleted records
|
|
967
|
+
*/
|
|
968
|
+
restore(): Promise<number>;
|
|
969
|
+
/**
|
|
970
|
+
* Permanently delete records (bypass soft deletes)
|
|
971
|
+
*/
|
|
972
|
+
forceDelete(): Promise<number>;
|
|
973
|
+
/**
|
|
974
|
+
* Apply a query scope
|
|
975
|
+
*/
|
|
976
|
+
applyScope(name: string, callback: (query: QueryBuilderContract<T>) => void): this;
|
|
977
|
+
/**
|
|
978
|
+
* Remove a global scope
|
|
979
|
+
*/
|
|
980
|
+
withoutGlobalScope(name: string): this;
|
|
981
|
+
/**
|
|
982
|
+
* Cache the query results
|
|
983
|
+
*/
|
|
984
|
+
cache(ttl: number, key?: string): this;
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Grammar Contract
|
|
988
|
+
*/
|
|
989
|
+
/**
|
|
990
|
+
* Cache Interface
|
|
991
|
+
*/
|
|
992
|
+
export interface CacheInterface {
|
|
993
|
+
get<T = unknown>(key: string): Promise<T | null>;
|
|
994
|
+
set(key: string, value: unknown, ttl?: number): Promise<void>;
|
|
995
|
+
delete(key: string): Promise<void>;
|
|
996
|
+
clear(): Promise<void>;
|
|
997
|
+
}
|
|
998
|
+
/**
|
|
999
|
+
* Grammar Contract
|
|
1000
|
+
*/
|
|
1001
|
+
export interface GrammarContract {
|
|
1002
|
+
/**
|
|
1003
|
+
* Compile a SELECT statement
|
|
1004
|
+
*/
|
|
1005
|
+
compileSelect(query: CompiledQuery): string;
|
|
1006
|
+
/**
|
|
1007
|
+
* Compile an INSERT statement
|
|
1008
|
+
*/
|
|
1009
|
+
compileInsert(query: CompiledQuery, values: Record<string, unknown>[]): string;
|
|
1010
|
+
/**
|
|
1011
|
+
* Compile an INSERT and get ID statement
|
|
1012
|
+
*/
|
|
1013
|
+
compileInsertGetId(query: CompiledQuery, values: Record<string, unknown>, primaryKey: string): string;
|
|
1014
|
+
/**
|
|
1015
|
+
* Compile an UPDATE statement
|
|
1016
|
+
*/
|
|
1017
|
+
compileUpdate(query: CompiledQuery, values: Record<string, unknown>): string;
|
|
1018
|
+
/**
|
|
1019
|
+
* Compile a DELETE statement
|
|
1020
|
+
*/
|
|
1021
|
+
compileDelete(query: CompiledQuery): string;
|
|
1022
|
+
/**
|
|
1023
|
+
* Compile a TRUNCATE statement
|
|
1024
|
+
*/
|
|
1025
|
+
compileTruncate(query: CompiledQuery): string;
|
|
1026
|
+
/**
|
|
1027
|
+
* Compile an aggregate query
|
|
1028
|
+
*/
|
|
1029
|
+
compileAggregate(query: CompiledQuery, aggregate: {
|
|
1030
|
+
function: string;
|
|
1031
|
+
column: string;
|
|
1032
|
+
}): string;
|
|
1033
|
+
/**
|
|
1034
|
+
* Compile an EXISTS query
|
|
1035
|
+
*/
|
|
1036
|
+
compileExists(query: CompiledQuery): string;
|
|
1037
|
+
/**
|
|
1038
|
+
* Get placeholder for binding
|
|
1039
|
+
*/
|
|
1040
|
+
getPlaceholder(index: number): string;
|
|
1041
|
+
/**
|
|
1042
|
+
* Wrap a column name
|
|
1043
|
+
*/
|
|
1044
|
+
wrapColumn(column: string): string;
|
|
1045
|
+
/**
|
|
1046
|
+
* Wrap a table name
|
|
1047
|
+
*/
|
|
1048
|
+
wrapTable(table: string): string;
|
|
1049
|
+
/**
|
|
1050
|
+
* Quote a value
|
|
1051
|
+
*/
|
|
1052
|
+
quoteValue(value: unknown): string;
|
|
1053
|
+
/**
|
|
1054
|
+
* Compile a lateral eager load query
|
|
1055
|
+
*/
|
|
1056
|
+
compileLateralEagerLoad(table: string, foreignKey: string, parentKeys: unknown[], query: CompiledQuery): {
|
|
1057
|
+
sql: string;
|
|
1058
|
+
bindings: unknown[];
|
|
1059
|
+
};
|
|
1060
|
+
getStructuralKey(query: CompiledQuery): string;
|
|
1061
|
+
/**
|
|
1062
|
+
* Compile a JSON path query
|
|
1063
|
+
*/
|
|
1064
|
+
compileJsonPath(column: string, value: unknown): string;
|
|
1065
|
+
/**
|
|
1066
|
+
* Compile a JSON contains query
|
|
1067
|
+
*/
|
|
1068
|
+
compileJsonContains(column: string, value: unknown): string;
|
|
1069
|
+
/**
|
|
1070
|
+
* Compile a JSON update statement
|
|
1071
|
+
*/
|
|
1072
|
+
compileUpdateJson(query: CompiledQuery, column: string, value: unknown): string;
|
|
1073
|
+
/**
|
|
1074
|
+
* Compile an UPSERT statement
|
|
1075
|
+
*/
|
|
1076
|
+
compileUpsert(query: CompiledQuery, values: Record<string, unknown>[], uniqueBy: string[], update: string[]): string;
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* Compiled query structure (used by Grammar)
|
|
1080
|
+
*/
|
|
1081
|
+
export interface CompiledQuery {
|
|
1082
|
+
table: string;
|
|
1083
|
+
columns: string[];
|
|
1084
|
+
distinct: boolean;
|
|
1085
|
+
wheres: WhereClause[];
|
|
1086
|
+
orders: OrderClause[];
|
|
1087
|
+
groups: string[];
|
|
1088
|
+
havings: HavingClause[];
|
|
1089
|
+
joins: JoinClause[];
|
|
1090
|
+
limit?: number | undefined;
|
|
1091
|
+
offset?: number | undefined;
|
|
1092
|
+
bindings: unknown[];
|
|
1093
|
+
bindingCounts?: {
|
|
1094
|
+
select: number;
|
|
1095
|
+
where: number;
|
|
1096
|
+
join: number;
|
|
1097
|
+
having: number;
|
|
1098
|
+
order: number;
|
|
1099
|
+
};
|
|
1100
|
+
}
|