@nextlyhq/adapter-drizzle 0.0.2-alpha.7 → 0.0.2-alpha.71
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 +25 -1
- package/dist/adapter-BypoOEEN.d.cts +1166 -0
- package/dist/adapter-CSP-Ek-L.d.ts +1166 -0
- package/dist/index-BYb6cDli.d.ts +1168 -0
- package/dist/index-C4HJsfwA.d.cts +1168 -0
- package/dist/index.cjs +2302 -1085
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -9
- package/dist/index.d.ts +5 -9
- package/dist/index.mjs +2301 -1083
- package/dist/index.mjs.map +1 -1
- package/dist/migrations.cjs +345 -146
- package/dist/migrations.cjs.map +1 -1
- package/dist/migrations.d.cts +93 -109
- package/dist/migrations.d.ts +93 -109
- package/dist/migrations.mjs +344 -144
- package/dist/migrations.mjs.map +1 -1
- package/dist/schema/index.cjs +21 -6
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +5 -116
- package/dist/schema/index.d.ts +5 -116
- package/dist/schema/index.mjs +20 -4
- package/dist/schema/index.mjs.map +1 -1
- package/dist/schema-Bkkr3JMC.d.cts +264 -0
- package/dist/schema-Bkkr3JMC.d.ts +264 -0
- package/dist/schema-name.cjs +42 -0
- package/dist/schema-name.cjs.map +1 -0
- package/dist/schema-name.d.cts +12 -0
- package/dist/schema-name.d.ts +12 -0
- package/dist/schema-name.mjs +40 -0
- package/dist/schema-name.mjs.map +1 -0
- package/dist/text-match.cjs +50 -0
- package/dist/text-match.cjs.map +1 -0
- package/dist/text-match.d.cts +32 -0
- package/dist/text-match.d.ts +32 -0
- package/dist/text-match.mjs +48 -0
- package/dist/text-match.mjs.map +1 -0
- package/dist/types/index.cjs +8 -24
- package/dist/types/index.d.cts +3 -210
- package/dist/types/index.d.ts +3 -210
- package/dist/types/index.mjs +1 -21
- package/dist/types-CNyA1oIm.cjs +185 -0
- package/dist/types-CNyA1oIm.cjs.map +1 -0
- package/dist/types-CaF_5jNk.mjs +150 -0
- package/dist/types-CaF_5jNk.mjs.map +1 -0
- package/dist/version-check.cjs +119 -127
- package/dist/version-check.cjs.map +1 -1
- package/dist/version-check.d.cts +54 -39
- package/dist/version-check.d.ts +54 -39
- package/dist/version-check.mjs +117 -125
- package/dist/version-check.mjs.map +1 -1
- package/package.json +23 -17
- package/dist/adapter-BxJVtttb.d.ts +0 -592
- package/dist/adapter-nvlxFkF-.d.cts +0 -592
- package/dist/core-CVO7WYDj.d.cts +0 -74
- package/dist/core-CVO7WYDj.d.ts +0 -74
- package/dist/error-um1d_3Uo.d.cts +0 -105
- package/dist/error-um1d_3Uo.d.ts +0 -105
- package/dist/migration-BbO5meEV.d.cts +0 -622
- package/dist/migration-Qe70wDOC.d.ts +0 -622
- package/dist/schema-BDn8WfSL.d.cts +0 -200
- package/dist/schema-BIQ0YQZ_.d.ts +0 -200
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.mjs.map +0 -1
package/dist/types/index.d.cts
CHANGED
|
@@ -1,210 +1,3 @@
|
|
|
1
|
-
import { a as SqlParam } from
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
export { A as AlterTableOperation, a as AlterTableOptions, b as ColumnDefinition, C as CreateTableOptions, D as DropTableOptions, I as IndexDefinition, c as TableConstraint, T as TableDefinition } from '../schema-BDn8WfSL.cjs';
|
|
5
|
-
export { a as DatabaseError, D as DatabaseErrorKind, b as DatabaseErrorOptions, c as createDatabaseError, i as isDatabaseError } from '../error-um1d_3Uo.cjs';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Database adapter configuration type definitions.
|
|
9
|
-
*
|
|
10
|
-
* @packageDocumentation
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Logger interface for adapter operations.
|
|
15
|
-
*
|
|
16
|
-
* @remarks
|
|
17
|
-
* Adapters use this interface to log queries, errors, and performance metrics.
|
|
18
|
-
*
|
|
19
|
-
* @public
|
|
20
|
-
*/
|
|
21
|
-
interface AdapterLogger {
|
|
22
|
-
/**
|
|
23
|
-
* Log a query execution.
|
|
24
|
-
*
|
|
25
|
-
* @param sql - SQL statement
|
|
26
|
-
* @param params - Query parameters
|
|
27
|
-
* @param durationMs - Query execution time in milliseconds
|
|
28
|
-
*/
|
|
29
|
-
query?: (sql: string, params?: SqlParam[], durationMs?: number) => void;
|
|
30
|
-
/**
|
|
31
|
-
* Log an error.
|
|
32
|
-
*
|
|
33
|
-
* @param error - Error object
|
|
34
|
-
* @param context - Additional context about the error
|
|
35
|
-
*/
|
|
36
|
-
error?: (error: Error, context?: Record<string, unknown>) => void;
|
|
37
|
-
/**
|
|
38
|
-
* Log a debug message.
|
|
39
|
-
*
|
|
40
|
-
* @param message - Debug message
|
|
41
|
-
* @param context - Additional context
|
|
42
|
-
*/
|
|
43
|
-
debug?: (message: string, context?: Record<string, unknown>) => void;
|
|
44
|
-
/**
|
|
45
|
-
* Log a warning.
|
|
46
|
-
*
|
|
47
|
-
* @param message - Warning message
|
|
48
|
-
* @param context - Additional context
|
|
49
|
-
*/
|
|
50
|
-
warn?: (message: string, context?: Record<string, unknown>) => void;
|
|
51
|
-
/**
|
|
52
|
-
* Log an info message.
|
|
53
|
-
*
|
|
54
|
-
* @param message - Info message
|
|
55
|
-
* @param context - Additional context
|
|
56
|
-
*/
|
|
57
|
-
info?: (message: string, context?: Record<string, unknown>) => void;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Connection pool configuration.
|
|
61
|
-
*
|
|
62
|
-
* @remarks
|
|
63
|
-
* Controls connection pooling behavior. SQLite adapters ignore these
|
|
64
|
-
* settings as SQLite uses a single connection.
|
|
65
|
-
*
|
|
66
|
-
* @public
|
|
67
|
-
*/
|
|
68
|
-
interface PoolConfig {
|
|
69
|
-
/** Minimum number of connections in the pool */
|
|
70
|
-
min?: number;
|
|
71
|
-
/** Maximum number of connections in the pool */
|
|
72
|
-
max?: number;
|
|
73
|
-
/** Time (ms) before an idle connection is closed */
|
|
74
|
-
idleTimeoutMs?: number;
|
|
75
|
-
/** Time (ms) to wait for a connection before timing out */
|
|
76
|
-
connectionTimeoutMs?: number;
|
|
77
|
-
/** Time (ms) before considering an unused connection stale */
|
|
78
|
-
maxLifetimeMs?: number;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* SSL/TLS configuration for database connections.
|
|
82
|
-
*
|
|
83
|
-
* @remarks
|
|
84
|
-
* Relevant for PostgreSQL and MySQL. SQLite doesn't use network connections.
|
|
85
|
-
*
|
|
86
|
-
* @public
|
|
87
|
-
*/
|
|
88
|
-
interface SslConfig {
|
|
89
|
-
/** Reject unauthorized certificates (default: true for production) */
|
|
90
|
-
rejectUnauthorized?: boolean;
|
|
91
|
-
/** Path to CA certificate file */
|
|
92
|
-
ca?: string;
|
|
93
|
-
/** Path to client certificate file */
|
|
94
|
-
cert?: string;
|
|
95
|
-
/** Path to client private key file */
|
|
96
|
-
key?: string;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Base adapter configuration.
|
|
100
|
-
*
|
|
101
|
-
* @remarks
|
|
102
|
-
* Common configuration options for all database adapters. Dialect-specific
|
|
103
|
-
* adapters may extend this interface with additional options.
|
|
104
|
-
*
|
|
105
|
-
* @public
|
|
106
|
-
*/
|
|
107
|
-
interface BaseAdapterConfig {
|
|
108
|
-
/**
|
|
109
|
-
* Database connection URL.
|
|
110
|
-
*
|
|
111
|
-
* @remarks
|
|
112
|
-
* Examples:
|
|
113
|
-
* - PostgreSQL: `postgres://user:pass@localhost:5432/dbname`
|
|
114
|
-
* - MySQL: `mysql://user:pass@localhost:3306/dbname`
|
|
115
|
-
* - SQLite: `file:./data/app.db` or `file::memory:`
|
|
116
|
-
*/
|
|
117
|
-
url?: string;
|
|
118
|
-
/** Database host (alternative to URL) */
|
|
119
|
-
host?: string;
|
|
120
|
-
/** Database port (alternative to URL) */
|
|
121
|
-
port?: number;
|
|
122
|
-
/** Database name (alternative to URL) */
|
|
123
|
-
database?: string;
|
|
124
|
-
/** Database user (alternative to URL) */
|
|
125
|
-
user?: string;
|
|
126
|
-
/** Database password (alternative to URL) */
|
|
127
|
-
password?: string;
|
|
128
|
-
/** Connection pool configuration */
|
|
129
|
-
pool?: PoolConfig;
|
|
130
|
-
/** Logger instance for queries and errors */
|
|
131
|
-
logger?: AdapterLogger;
|
|
132
|
-
/** Schema name (PostgreSQL) */
|
|
133
|
-
schema?: string;
|
|
134
|
-
/** SSL/TLS configuration */
|
|
135
|
-
ssl?: SslConfig | boolean;
|
|
136
|
-
/**
|
|
137
|
-
* Default query timeout in milliseconds.
|
|
138
|
-
*
|
|
139
|
-
* @remarks
|
|
140
|
-
* Queries exceeding this limit will be aborted and throw a DatabaseError
|
|
141
|
-
* with kind 'timeout'. This prevents runaway queries from blocking the
|
|
142
|
-
* system indefinitely.
|
|
143
|
-
*
|
|
144
|
-
* Can be overridden per-transaction via TransactionOptions.timeoutMs.
|
|
145
|
-
*
|
|
146
|
-
* Set to 0 or undefined to disable timeout (not recommended for production).
|
|
147
|
-
*
|
|
148
|
-
* @default 15000 (15 seconds)
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ```typescript
|
|
152
|
-
* const adapter = createPostgresAdapter({
|
|
153
|
-
* url: 'postgres://localhost/mydb',
|
|
154
|
-
* queryTimeoutMs: 30000, // 30 seconds
|
|
155
|
-
* });
|
|
156
|
-
* ```
|
|
157
|
-
*/
|
|
158
|
-
queryTimeoutMs?: number;
|
|
159
|
-
/** Additional connection options (driver-specific) */
|
|
160
|
-
options?: Record<string, unknown>;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* PostgreSQL-specific adapter configuration.
|
|
164
|
-
*
|
|
165
|
-
* @public
|
|
166
|
-
*/
|
|
167
|
-
interface PostgresAdapterConfig extends BaseAdapterConfig {
|
|
168
|
-
/** Application name for connection tracking */
|
|
169
|
-
applicationName?: string;
|
|
170
|
-
/** Statement timeout in milliseconds */
|
|
171
|
-
statementTimeout?: number;
|
|
172
|
-
/** Query timeout in milliseconds */
|
|
173
|
-
queryTimeout?: number;
|
|
174
|
-
/** Enable prepared statements (default: true) */
|
|
175
|
-
preparedStatements?: boolean;
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* MySQL-specific adapter configuration.
|
|
179
|
-
*
|
|
180
|
-
* @public
|
|
181
|
-
*/
|
|
182
|
-
interface MySqlAdapterConfig extends BaseAdapterConfig {
|
|
183
|
-
/** Character set (default: utf8mb4) */
|
|
184
|
-
charset?: string;
|
|
185
|
-
/** Timezone (default: 'local') */
|
|
186
|
-
timezone?: string;
|
|
187
|
-
/** Enable multiple statements per query (default: false, security risk) */
|
|
188
|
-
multipleStatements?: boolean;
|
|
189
|
-
/** Date strings instead of Date objects (default: false) */
|
|
190
|
-
dateStrings?: boolean;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* SQLite-specific adapter configuration.
|
|
194
|
-
*
|
|
195
|
-
* @public
|
|
196
|
-
*/
|
|
197
|
-
interface SqliteAdapterConfig extends BaseAdapterConfig {
|
|
198
|
-
/** Enable WAL mode (default: true) */
|
|
199
|
-
wal?: boolean;
|
|
200
|
-
/** Busy timeout in milliseconds (default: 5000) */
|
|
201
|
-
busyTimeout?: number;
|
|
202
|
-
/** Enable foreign keys (default: true) */
|
|
203
|
-
foreignKeys?: boolean;
|
|
204
|
-
/** Memory-only database (overrides url) */
|
|
205
|
-
memory?: boolean;
|
|
206
|
-
/** Read-only mode (default: false) */
|
|
207
|
-
readonly?: boolean;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export { type AdapterLogger, type BaseAdapterConfig, type MySqlAdapterConfig, type PoolConfig, type PostgresAdapterConfig, SqlParam, type SqliteAdapterConfig, type SslConfig };
|
|
1
|
+
import { a as DropTableOptions, c as TableDefinition, d as JsonValue, f as SqlParam, i as CreateTableOptions, l as JsonArray, m as TableResolver, n as AlterTableOptions, o as IndexDefinition, p as SupportedDialect, r as ColumnDefinition, s as TableConstraint, t as AlterTableOperation, u as JsonObject } from "../schema-Bkkr3JMC.cjs";
|
|
2
|
+
import { A as UpdateOptions, C as TransactionContext, D as DeleteOptions, E as CountOptions, F as WhereClause, I as WhereCondition, L as WhereOperator, M as JoinSpec, N as OrderBySpec, O as InsertOptions, P as WHERE_OPERATORS, S as PoolStats, T as TransactionOptions, _ as MigrationOptions, a as PostgresAdapterConfig, b as MigrationStatus, c as DatabaseError, d as POOL_WAIT_TIMEOUT_CODE, f as createDatabaseError, g as Migration, h as poolWaitTimeoutError, i as PoolConfig, j as UpsertOptions, k as SelectOptions, l as DatabaseErrorKind, m as isDatabaseError, n as BaseAdapterConfig, o as SqliteAdapterConfig, p as isApplicationError, r as MySqlAdapterConfig, s as SslConfig, t as AdapterLogger, u as DatabaseErrorOptions, v as MigrationRecord, w as TransactionIsolationLevel, x as DatabaseCapabilities, y as MigrationResult } from "../index-C4HJsfwA.cjs";
|
|
3
|
+
export { type AdapterLogger, type AlterTableOperation, type AlterTableOptions, type BaseAdapterConfig, type ColumnDefinition, type CountOptions, type CreateTableOptions, type DatabaseCapabilities, type DatabaseError, type DatabaseErrorKind, type DatabaseErrorOptions, type DeleteOptions, type DropTableOptions, type IndexDefinition, type InsertOptions, type JoinSpec, type JsonArray, type JsonObject, type JsonValue, type Migration, type MigrationOptions, type MigrationRecord, type MigrationResult, type MigrationStatus, type MySqlAdapterConfig, type OrderBySpec, POOL_WAIT_TIMEOUT_CODE, type PoolConfig, type PoolStats, type PostgresAdapterConfig, type SelectOptions, type SqlParam, type SqliteAdapterConfig, type SslConfig, type SupportedDialect, type TableConstraint, type TableDefinition, type TableResolver, type TransactionContext, type TransactionIsolationLevel, type TransactionOptions, type UpdateOptions, type UpsertOptions, WHERE_OPERATORS, type WhereClause, type WhereCondition, type WhereOperator, createDatabaseError, isApplicationError, isDatabaseError, poolWaitTimeoutError };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,210 +1,3 @@
|
|
|
1
|
-
import { a as SqlParam } from
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
export { A as AlterTableOperation, a as AlterTableOptions, b as ColumnDefinition, C as CreateTableOptions, D as DropTableOptions, I as IndexDefinition, c as TableConstraint, T as TableDefinition } from '../schema-BIQ0YQZ_.js';
|
|
5
|
-
export { a as DatabaseError, D as DatabaseErrorKind, b as DatabaseErrorOptions, c as createDatabaseError, i as isDatabaseError } from '../error-um1d_3Uo.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Database adapter configuration type definitions.
|
|
9
|
-
*
|
|
10
|
-
* @packageDocumentation
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Logger interface for adapter operations.
|
|
15
|
-
*
|
|
16
|
-
* @remarks
|
|
17
|
-
* Adapters use this interface to log queries, errors, and performance metrics.
|
|
18
|
-
*
|
|
19
|
-
* @public
|
|
20
|
-
*/
|
|
21
|
-
interface AdapterLogger {
|
|
22
|
-
/**
|
|
23
|
-
* Log a query execution.
|
|
24
|
-
*
|
|
25
|
-
* @param sql - SQL statement
|
|
26
|
-
* @param params - Query parameters
|
|
27
|
-
* @param durationMs - Query execution time in milliseconds
|
|
28
|
-
*/
|
|
29
|
-
query?: (sql: string, params?: SqlParam[], durationMs?: number) => void;
|
|
30
|
-
/**
|
|
31
|
-
* Log an error.
|
|
32
|
-
*
|
|
33
|
-
* @param error - Error object
|
|
34
|
-
* @param context - Additional context about the error
|
|
35
|
-
*/
|
|
36
|
-
error?: (error: Error, context?: Record<string, unknown>) => void;
|
|
37
|
-
/**
|
|
38
|
-
* Log a debug message.
|
|
39
|
-
*
|
|
40
|
-
* @param message - Debug message
|
|
41
|
-
* @param context - Additional context
|
|
42
|
-
*/
|
|
43
|
-
debug?: (message: string, context?: Record<string, unknown>) => void;
|
|
44
|
-
/**
|
|
45
|
-
* Log a warning.
|
|
46
|
-
*
|
|
47
|
-
* @param message - Warning message
|
|
48
|
-
* @param context - Additional context
|
|
49
|
-
*/
|
|
50
|
-
warn?: (message: string, context?: Record<string, unknown>) => void;
|
|
51
|
-
/**
|
|
52
|
-
* Log an info message.
|
|
53
|
-
*
|
|
54
|
-
* @param message - Info message
|
|
55
|
-
* @param context - Additional context
|
|
56
|
-
*/
|
|
57
|
-
info?: (message: string, context?: Record<string, unknown>) => void;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Connection pool configuration.
|
|
61
|
-
*
|
|
62
|
-
* @remarks
|
|
63
|
-
* Controls connection pooling behavior. SQLite adapters ignore these
|
|
64
|
-
* settings as SQLite uses a single connection.
|
|
65
|
-
*
|
|
66
|
-
* @public
|
|
67
|
-
*/
|
|
68
|
-
interface PoolConfig {
|
|
69
|
-
/** Minimum number of connections in the pool */
|
|
70
|
-
min?: number;
|
|
71
|
-
/** Maximum number of connections in the pool */
|
|
72
|
-
max?: number;
|
|
73
|
-
/** Time (ms) before an idle connection is closed */
|
|
74
|
-
idleTimeoutMs?: number;
|
|
75
|
-
/** Time (ms) to wait for a connection before timing out */
|
|
76
|
-
connectionTimeoutMs?: number;
|
|
77
|
-
/** Time (ms) before considering an unused connection stale */
|
|
78
|
-
maxLifetimeMs?: number;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* SSL/TLS configuration for database connections.
|
|
82
|
-
*
|
|
83
|
-
* @remarks
|
|
84
|
-
* Relevant for PostgreSQL and MySQL. SQLite doesn't use network connections.
|
|
85
|
-
*
|
|
86
|
-
* @public
|
|
87
|
-
*/
|
|
88
|
-
interface SslConfig {
|
|
89
|
-
/** Reject unauthorized certificates (default: true for production) */
|
|
90
|
-
rejectUnauthorized?: boolean;
|
|
91
|
-
/** Path to CA certificate file */
|
|
92
|
-
ca?: string;
|
|
93
|
-
/** Path to client certificate file */
|
|
94
|
-
cert?: string;
|
|
95
|
-
/** Path to client private key file */
|
|
96
|
-
key?: string;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Base adapter configuration.
|
|
100
|
-
*
|
|
101
|
-
* @remarks
|
|
102
|
-
* Common configuration options for all database adapters. Dialect-specific
|
|
103
|
-
* adapters may extend this interface with additional options.
|
|
104
|
-
*
|
|
105
|
-
* @public
|
|
106
|
-
*/
|
|
107
|
-
interface BaseAdapterConfig {
|
|
108
|
-
/**
|
|
109
|
-
* Database connection URL.
|
|
110
|
-
*
|
|
111
|
-
* @remarks
|
|
112
|
-
* Examples:
|
|
113
|
-
* - PostgreSQL: `postgres://user:pass@localhost:5432/dbname`
|
|
114
|
-
* - MySQL: `mysql://user:pass@localhost:3306/dbname`
|
|
115
|
-
* - SQLite: `file:./data/app.db` or `file::memory:`
|
|
116
|
-
*/
|
|
117
|
-
url?: string;
|
|
118
|
-
/** Database host (alternative to URL) */
|
|
119
|
-
host?: string;
|
|
120
|
-
/** Database port (alternative to URL) */
|
|
121
|
-
port?: number;
|
|
122
|
-
/** Database name (alternative to URL) */
|
|
123
|
-
database?: string;
|
|
124
|
-
/** Database user (alternative to URL) */
|
|
125
|
-
user?: string;
|
|
126
|
-
/** Database password (alternative to URL) */
|
|
127
|
-
password?: string;
|
|
128
|
-
/** Connection pool configuration */
|
|
129
|
-
pool?: PoolConfig;
|
|
130
|
-
/** Logger instance for queries and errors */
|
|
131
|
-
logger?: AdapterLogger;
|
|
132
|
-
/** Schema name (PostgreSQL) */
|
|
133
|
-
schema?: string;
|
|
134
|
-
/** SSL/TLS configuration */
|
|
135
|
-
ssl?: SslConfig | boolean;
|
|
136
|
-
/**
|
|
137
|
-
* Default query timeout in milliseconds.
|
|
138
|
-
*
|
|
139
|
-
* @remarks
|
|
140
|
-
* Queries exceeding this limit will be aborted and throw a DatabaseError
|
|
141
|
-
* with kind 'timeout'. This prevents runaway queries from blocking the
|
|
142
|
-
* system indefinitely.
|
|
143
|
-
*
|
|
144
|
-
* Can be overridden per-transaction via TransactionOptions.timeoutMs.
|
|
145
|
-
*
|
|
146
|
-
* Set to 0 or undefined to disable timeout (not recommended for production).
|
|
147
|
-
*
|
|
148
|
-
* @default 15000 (15 seconds)
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ```typescript
|
|
152
|
-
* const adapter = createPostgresAdapter({
|
|
153
|
-
* url: 'postgres://localhost/mydb',
|
|
154
|
-
* queryTimeoutMs: 30000, // 30 seconds
|
|
155
|
-
* });
|
|
156
|
-
* ```
|
|
157
|
-
*/
|
|
158
|
-
queryTimeoutMs?: number;
|
|
159
|
-
/** Additional connection options (driver-specific) */
|
|
160
|
-
options?: Record<string, unknown>;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* PostgreSQL-specific adapter configuration.
|
|
164
|
-
*
|
|
165
|
-
* @public
|
|
166
|
-
*/
|
|
167
|
-
interface PostgresAdapterConfig extends BaseAdapterConfig {
|
|
168
|
-
/** Application name for connection tracking */
|
|
169
|
-
applicationName?: string;
|
|
170
|
-
/** Statement timeout in milliseconds */
|
|
171
|
-
statementTimeout?: number;
|
|
172
|
-
/** Query timeout in milliseconds */
|
|
173
|
-
queryTimeout?: number;
|
|
174
|
-
/** Enable prepared statements (default: true) */
|
|
175
|
-
preparedStatements?: boolean;
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* MySQL-specific adapter configuration.
|
|
179
|
-
*
|
|
180
|
-
* @public
|
|
181
|
-
*/
|
|
182
|
-
interface MySqlAdapterConfig extends BaseAdapterConfig {
|
|
183
|
-
/** Character set (default: utf8mb4) */
|
|
184
|
-
charset?: string;
|
|
185
|
-
/** Timezone (default: 'local') */
|
|
186
|
-
timezone?: string;
|
|
187
|
-
/** Enable multiple statements per query (default: false, security risk) */
|
|
188
|
-
multipleStatements?: boolean;
|
|
189
|
-
/** Date strings instead of Date objects (default: false) */
|
|
190
|
-
dateStrings?: boolean;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* SQLite-specific adapter configuration.
|
|
194
|
-
*
|
|
195
|
-
* @public
|
|
196
|
-
*/
|
|
197
|
-
interface SqliteAdapterConfig extends BaseAdapterConfig {
|
|
198
|
-
/** Enable WAL mode (default: true) */
|
|
199
|
-
wal?: boolean;
|
|
200
|
-
/** Busy timeout in milliseconds (default: 5000) */
|
|
201
|
-
busyTimeout?: number;
|
|
202
|
-
/** Enable foreign keys (default: true) */
|
|
203
|
-
foreignKeys?: boolean;
|
|
204
|
-
/** Memory-only database (overrides url) */
|
|
205
|
-
memory?: boolean;
|
|
206
|
-
/** Read-only mode (default: false) */
|
|
207
|
-
readonly?: boolean;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export { type AdapterLogger, type BaseAdapterConfig, type MySqlAdapterConfig, type PoolConfig, type PostgresAdapterConfig, SqlParam, type SqliteAdapterConfig, type SslConfig };
|
|
1
|
+
import { a as DropTableOptions, c as TableDefinition, d as JsonValue, f as SqlParam, i as CreateTableOptions, l as JsonArray, m as TableResolver, n as AlterTableOptions, o as IndexDefinition, p as SupportedDialect, r as ColumnDefinition, s as TableConstraint, t as AlterTableOperation, u as JsonObject } from "../schema-Bkkr3JMC.js";
|
|
2
|
+
import { A as UpdateOptions, C as TransactionContext, D as DeleteOptions, E as CountOptions, F as WhereClause, I as WhereCondition, L as WhereOperator, M as JoinSpec, N as OrderBySpec, O as InsertOptions, P as WHERE_OPERATORS, S as PoolStats, T as TransactionOptions, _ as MigrationOptions, a as PostgresAdapterConfig, b as MigrationStatus, c as DatabaseError, d as POOL_WAIT_TIMEOUT_CODE, f as createDatabaseError, g as Migration, h as poolWaitTimeoutError, i as PoolConfig, j as UpsertOptions, k as SelectOptions, l as DatabaseErrorKind, m as isDatabaseError, n as BaseAdapterConfig, o as SqliteAdapterConfig, p as isApplicationError, r as MySqlAdapterConfig, s as SslConfig, t as AdapterLogger, u as DatabaseErrorOptions, v as MigrationRecord, w as TransactionIsolationLevel, x as DatabaseCapabilities, y as MigrationResult } from "../index-BYb6cDli.js";
|
|
3
|
+
export { type AdapterLogger, type AlterTableOperation, type AlterTableOptions, type BaseAdapterConfig, type ColumnDefinition, type CountOptions, type CreateTableOptions, type DatabaseCapabilities, type DatabaseError, type DatabaseErrorKind, type DatabaseErrorOptions, type DeleteOptions, type DropTableOptions, type IndexDefinition, type InsertOptions, type JoinSpec, type JsonArray, type JsonObject, type JsonValue, type Migration, type MigrationOptions, type MigrationRecord, type MigrationResult, type MigrationStatus, type MySqlAdapterConfig, type OrderBySpec, POOL_WAIT_TIMEOUT_CODE, type PoolConfig, type PoolStats, type PostgresAdapterConfig, type SelectOptions, type SqlParam, type SqliteAdapterConfig, type SslConfig, type SupportedDialect, type TableConstraint, type TableDefinition, type TableResolver, type TransactionContext, type TransactionIsolationLevel, type TransactionOptions, type UpdateOptions, type UpsertOptions, WHERE_OPERATORS, type WhereClause, type WhereCondition, type WhereOperator, createDatabaseError, isApplicationError, isDatabaseError, poolWaitTimeoutError };
|
package/dist/types/index.mjs
CHANGED
|
@@ -1,21 +1 @@
|
|
|
1
|
-
|
|
2
|
-
function isDatabaseError(error) {
|
|
3
|
-
return typeof error === "object" && error !== null && "kind" in error && typeof error.kind === "string";
|
|
4
|
-
}
|
|
5
|
-
function createDatabaseError(options) {
|
|
6
|
-
const error = new Error(options.message);
|
|
7
|
-
error.name = "DatabaseError";
|
|
8
|
-
error.kind = options.kind;
|
|
9
|
-
if (options.code !== void 0) error.code = options.code;
|
|
10
|
-
if (options.constraint !== void 0) error.constraint = options.constraint;
|
|
11
|
-
if (options.table !== void 0) error.table = options.table;
|
|
12
|
-
if (options.column !== void 0) error.column = options.column;
|
|
13
|
-
if (options.detail !== void 0) error.detail = options.detail;
|
|
14
|
-
if (options.hint !== void 0) error.hint = options.hint;
|
|
15
|
-
if (options.cause !== void 0) error.cause = options.cause;
|
|
16
|
-
return error;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export { createDatabaseError, isDatabaseError };
|
|
20
|
-
//# sourceMappingURL=index.mjs.map
|
|
21
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
export { t as POOL_WAIT_TIMEOUT_CODE, o as WHERE_OPERATORS, n as createDatabaseError, r as isApplicationError, i as isDatabaseError, a as poolWaitTimeoutError } from "../types-CaF_5jNk.mjs";
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// src/types/query.ts
|
|
2
|
+
/**
|
|
3
|
+
* Every WHERE clause operator this package DECLARES, as a value.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Declared, not guaranteed executable. Membership here means a `WhereCondition`
|
|
7
|
+
* carrying the operator type-checks — it does NOT mean the adapter can run it.
|
|
8
|
+
* `OVERLAPS` is declared and unimplemented, and throws at build time, so a
|
|
9
|
+
* validator written against this list will admit input the query layer then
|
|
10
|
+
* rejects. Validate against it to catch a misspelled operator; do not read
|
|
11
|
+
* acceptance here as a capability.
|
|
12
|
+
*
|
|
13
|
+
* - Standard comparison: =, !=, <, >, <=, >=
|
|
14
|
+
* - Set operations: IN, NOT IN
|
|
15
|
+
* - Pattern matching: LIKE, ILIKE (case-insensitive, PostgreSQL/emulated)
|
|
16
|
+
* - NULL checks: IS NULL, IS NOT NULL
|
|
17
|
+
* - Range: BETWEEN, NOT BETWEEN
|
|
18
|
+
* - Substring: CONTAINS — a LITERAL match on a TEXT column; see below
|
|
19
|
+
* - Declared but NOT implemented: OVERLAPS, which throws
|
|
20
|
+
*
|
|
21
|
+
* This list is the source of truth and {@link WhereOperator} is derived from it,
|
|
22
|
+
* rather than the two being written out separately. A guard that has to enumerate
|
|
23
|
+
* the operators — a validator over caller input, or a test asserting the builder
|
|
24
|
+
* handles or refuses each one — can only do that from a runtime value, and a
|
|
25
|
+
* hand-kept copy of the union would agree with it on the day it was written and
|
|
26
|
+
* silently stop agreeing the next time a member is added.
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
const WHERE_OPERATORS = [
|
|
31
|
+
"=",
|
|
32
|
+
"!=",
|
|
33
|
+
"<",
|
|
34
|
+
">",
|
|
35
|
+
"<=",
|
|
36
|
+
">=",
|
|
37
|
+
"IN",
|
|
38
|
+
"NOT IN",
|
|
39
|
+
"LIKE",
|
|
40
|
+
"ILIKE",
|
|
41
|
+
"IS NULL",
|
|
42
|
+
"IS NOT NULL",
|
|
43
|
+
"BETWEEN",
|
|
44
|
+
"NOT BETWEEN",
|
|
45
|
+
"CONTAINS",
|
|
46
|
+
"ICONTAINS",
|
|
47
|
+
"OVERLAPS"
|
|
48
|
+
];
|
|
49
|
+
// src/types/error.ts
|
|
50
|
+
/**
|
|
51
|
+
* Type guard for DatabaseError.
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* Checks if an error is a DatabaseError with proper typing.
|
|
55
|
+
*
|
|
56
|
+
* @param error - Error to check
|
|
57
|
+
* @returns True if error is a DatabaseError
|
|
58
|
+
*
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
function isDatabaseError(error) {
|
|
62
|
+
return typeof error === "object" && error !== null && "kind" in error && typeof error.kind === "string";
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The brand every Nextly application error carries.
|
|
66
|
+
*
|
|
67
|
+
* Read through the global symbol registry rather than imported, because the
|
|
68
|
+
* adapters must not depend on the package that defines the error: `Symbol.for`
|
|
69
|
+
* resolves to the same symbol in every module instance, which is why the brand
|
|
70
|
+
* exists in that form to begin with.
|
|
71
|
+
*
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
const APPLICATION_ERROR_BRAND = Symbol.for("nextly/NextlyError");
|
|
75
|
+
/**
|
|
76
|
+
* Whether an error is the application's verdict rather than the database's
|
|
77
|
+
* failure.
|
|
78
|
+
*
|
|
79
|
+
* Work running inside a transaction may throw to roll the write back — a
|
|
80
|
+
* refused value, a permission denial — and such an error is not something the
|
|
81
|
+
* driver produced. Classifying it as a database error replaces its code and its
|
|
82
|
+
* payload with a generic one, so a caller that asked for a refusal is handed an
|
|
83
|
+
* unexplained failure instead, and per-field validation detail is lost on the
|
|
84
|
+
* way out.
|
|
85
|
+
*
|
|
86
|
+
* @param error - Error to check
|
|
87
|
+
* @returns True if the error was raised by application code
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
function isApplicationError(error) {
|
|
92
|
+
if (error === null || typeof error !== "object" && typeof error !== "function") return false;
|
|
93
|
+
return error[APPLICATION_ERROR_BRAND] === true;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Create a DatabaseError instance.
|
|
97
|
+
*
|
|
98
|
+
* @remarks
|
|
99
|
+
* Helper function to create properly structured DatabaseError objects.
|
|
100
|
+
*
|
|
101
|
+
* @param options - Error options
|
|
102
|
+
* @returns DatabaseError instance
|
|
103
|
+
*
|
|
104
|
+
* @public
|
|
105
|
+
*/
|
|
106
|
+
function createDatabaseError(options) {
|
|
107
|
+
const error = new Error(options.message);
|
|
108
|
+
error.name = "DatabaseError";
|
|
109
|
+
error.kind = options.kind;
|
|
110
|
+
if (options.code !== void 0) error.code = options.code;
|
|
111
|
+
if (options.constraint !== void 0) error.constraint = options.constraint;
|
|
112
|
+
if (options.table !== void 0) error.table = options.table;
|
|
113
|
+
if (options.column !== void 0) error.column = options.column;
|
|
114
|
+
if (options.detail !== void 0) error.detail = options.detail;
|
|
115
|
+
if (options.hint !== void 0) error.hint = options.hint;
|
|
116
|
+
if (options.cause !== void 0) error.cause = options.cause;
|
|
117
|
+
return error;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The code an adapter gives the error it raises when a request has waited
|
|
121
|
+
* longer than `pool.connectionTimeoutMs` for a database connection.
|
|
122
|
+
*
|
|
123
|
+
* A code of the adapters' own rather than the driver's wording, because the
|
|
124
|
+
* drivers disagree: pg-pool raises a plain `Error` with no code, mysql2 has no
|
|
125
|
+
* such wait to time out, and better-sqlite3 has no pool. Core reads this one
|
|
126
|
+
* code to answer with its retryable "database busy" error.
|
|
127
|
+
*
|
|
128
|
+
* @public
|
|
129
|
+
*/
|
|
130
|
+
const POOL_WAIT_TIMEOUT_CODE = "NEXTLY_POOL_WAIT_TIMEOUT";
|
|
131
|
+
/**
|
|
132
|
+
* The error for a request that waited `boundMs` for a database connection and
|
|
133
|
+
* was given none.
|
|
134
|
+
*
|
|
135
|
+
* @param boundMs - The bound it waited, `pool.connectionTimeoutMs`
|
|
136
|
+
* @param cause - The driver's own error, when the driver raised one
|
|
137
|
+
*
|
|
138
|
+
* @public
|
|
139
|
+
*/
|
|
140
|
+
function poolWaitTimeoutError(boundMs, cause) {
|
|
141
|
+
return createDatabaseError({
|
|
142
|
+
kind: "timeout",
|
|
143
|
+
code: POOL_WAIT_TIMEOUT_CODE,
|
|
144
|
+
message: `Waited ${boundMs} ms for a database connection, and none was free`,
|
|
145
|
+
cause
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
Object.defineProperty(exports, "POOL_WAIT_TIMEOUT_CODE", {
|
|
149
|
+
enumerable: true,
|
|
150
|
+
get: function() {
|
|
151
|
+
return POOL_WAIT_TIMEOUT_CODE;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
Object.defineProperty(exports, "WHERE_OPERATORS", {
|
|
155
|
+
enumerable: true,
|
|
156
|
+
get: function() {
|
|
157
|
+
return WHERE_OPERATORS;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
Object.defineProperty(exports, "createDatabaseError", {
|
|
161
|
+
enumerable: true,
|
|
162
|
+
get: function() {
|
|
163
|
+
return createDatabaseError;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
Object.defineProperty(exports, "isApplicationError", {
|
|
167
|
+
enumerable: true,
|
|
168
|
+
get: function() {
|
|
169
|
+
return isApplicationError;
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
Object.defineProperty(exports, "isDatabaseError", {
|
|
173
|
+
enumerable: true,
|
|
174
|
+
get: function() {
|
|
175
|
+
return isDatabaseError;
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
Object.defineProperty(exports, "poolWaitTimeoutError", {
|
|
179
|
+
enumerable: true,
|
|
180
|
+
get: function() {
|
|
181
|
+
return poolWaitTimeoutError;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
//# sourceMappingURL=types-CNyA1oIm.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-CNyA1oIm.cjs","names":[],"sources":["../src/types/query.ts","../src/types/error.ts"],"sourcesContent":["/**\n * Query building type definitions for database-agnostic queries.\n *\n * @packageDocumentation\n */\n\nimport type { SqlParam } from \"./core\";\n\n/**\n * Every WHERE clause operator this package DECLARES, as a value.\n *\n * @remarks\n * Declared, not guaranteed executable. Membership here means a `WhereCondition`\n * carrying the operator type-checks — it does NOT mean the adapter can run it.\n * `OVERLAPS` is declared and unimplemented, and throws at build time, so a\n * validator written against this list will admit input the query layer then\n * rejects. Validate against it to catch a misspelled operator; do not read\n * acceptance here as a capability.\n *\n * - Standard comparison: =, !=, <, >, <=, >=\n * - Set operations: IN, NOT IN\n * - Pattern matching: LIKE, ILIKE (case-insensitive, PostgreSQL/emulated)\n * - NULL checks: IS NULL, IS NOT NULL\n * - Range: BETWEEN, NOT BETWEEN\n * - Substring: CONTAINS — a LITERAL match on a TEXT column; see below\n * - Declared but NOT implemented: OVERLAPS, which throws\n *\n * This list is the source of truth and {@link WhereOperator} is derived from it,\n * rather than the two being written out separately. A guard that has to enumerate\n * the operators — a validator over caller input, or a test asserting the builder\n * handles or refuses each one — can only do that from a runtime value, and a\n * hand-kept copy of the union would agree with it on the day it was written and\n * silently stop agreeing the next time a member is added.\n *\n * @public\n */\nexport const WHERE_OPERATORS = [\n \"=\",\n \"!=\",\n \"<\",\n \">\",\n \"<=\",\n \">=\",\n \"IN\",\n \"NOT IN\",\n \"LIKE\",\n \"ILIKE\",\n \"IS NULL\",\n \"IS NOT NULL\",\n \"BETWEEN\",\n \"NOT BETWEEN\",\n // Substring match on a TEXT column, with the value taken literally. Despite the name it is\n // not JSON containment, and it is not safe to point at a JSON column: the builder emits a\n // bare `LIKE` with no cast, so on PostgreSQL a `json`/`jsonb` column has no matching operator\n // and the statement ERRORS (`operator does not exist: jsonb ~~ text`). MySQL and SQLite\n // coerce, and there it searches the serialized text — which hits a key name as readily as a\n // value. Text columns only, and a search rather than a containment check.\n \"CONTAINS\",\n // CONTAINS without regard to case: a substring match on a TEXT column with the value taken\n // literally (`%` and `_` are characters to find, not wildcards), ignoring case on every\n // dialect even where the column's collation is case-sensitive. Which letters fold is the\n // database's `lower()` under the column's collation: the collation's Unicode version on\n // MySQL; non-ASCII too under a linguistic PostgreSQL collation; ASCII letters only on\n // SQLite and under PostgreSQL's `C` or `POSIX`.\n \"ICONTAINS\",\n // Declared, never implemented — the builder throws `Unsupported operator: OVERLAPS`. Kept in\n // the union because removing it would be a breaking change to a published type; the refusal\n // is pinned by a test so implementing it has to come through here.\n \"OVERLAPS\",\n] as const;\n\n/**\n * Every WHERE clause operator this package declares. Derived from\n * {@link WHERE_OPERATORS}, and carrying the same caveat: a value of this type\n * type-checks, which is not the same as the adapter being able to execute it.\n *\n * @public\n */\nexport type WhereOperator = (typeof WHERE_OPERATORS)[number];\n\n/**\n * Individual WHERE condition.\n *\n * @remarks\n * Represents a single condition in a WHERE clause. For IS NULL and IS NOT NULL\n * operators, the value field is optional.\n *\n * @public\n */\nexport interface WhereCondition {\n /** Column name to filter on */\n column: string;\n\n /** Comparison operator */\n op: WhereOperator;\n\n /** Value(s) to compare against (optional for IS NULL/IS NOT NULL) */\n value?: SqlParam | SqlParam[];\n\n /** Second value for BETWEEN operator */\n valueTo?: SqlParam;\n}\n\n/**\n * Complex WHERE clause with logical operators.\n *\n * @remarks\n * Supports nested conditions with AND, OR, and NOT logical operators.\n * Can be recursively nested for complex queries.\n *\n * @example\n * ```typescript\n * const where: WhereClause = {\n * and: [\n * { column: \"status\", op: \"=\", value: \"published\" },\n * {\n * or: [\n * { column: \"author\", op: \"=\", value: \"john\" },\n * { column: \"author\", op: \"=\", value: \"jane\" }\n * ]\n * }\n * ]\n * };\n * ```\n *\n * @public\n */\nexport interface WhereClause {\n /** All conditions must be true (AND) */\n and?: (WhereCondition | WhereClause)[];\n\n /** At least one condition must be true (OR) */\n or?: (WhereCondition | WhereClause)[];\n\n /** Negate a condition (NOT) */\n not?: WhereCondition | WhereClause;\n}\n\n/**\n * ORDER BY specification for query results.\n *\n * @remarks\n * Controls the sorting of query results. NULL handling varies by database\n * but can be explicitly controlled with the nulls field.\n *\n * @public\n */\nexport interface OrderBySpec {\n /** Column name to sort by */\n column: string;\n\n /** Sort direction (default: asc) */\n direction?: \"asc\" | \"desc\";\n\n /** NULL value ordering (database-specific defaults vary) */\n nulls?: \"first\" | \"last\";\n}\n\n/**\n * JOIN specification for table joins.\n *\n * @remarks\n * Supports different types of JOINs. Note that complex joins may require\n * dialect-specific handling.\n *\n * @public\n */\nexport interface JoinSpec {\n /** Type of join */\n type: \"inner\" | \"left\" | \"right\" | \"full\";\n\n /** Table name to join */\n table: string;\n\n /** Join condition */\n on: {\n /** Column from the left table */\n leftColumn: string;\n /** Column from the right table */\n rightColumn: string;\n };\n\n /** Optional alias for the joined table */\n alias?: string;\n}\n","/**\n * Database error type definitions.\n *\n * @packageDocumentation\n */\n\n/**\n * Database error classification.\n *\n * @remarks\n * Categorizes database errors for consistent error handling across adapters.\n * Each adapter translates database-specific error codes to these kinds.\n *\n * @public\n */\nexport type DatabaseErrorKind =\n | \"connection\" // Connection/network errors\n | \"query\" // Syntax or execution errors\n | \"constraint\" // Generic constraint violation\n | \"unique_violation\" // Unique constraint violation\n | \"foreign_key_violation\" // Foreign key constraint violation\n | \"check_violation\" // Check constraint violation\n | \"not_null_violation\" // NOT NULL constraint violation\n | \"deadlock\" // Transaction deadlock\n | \"timeout\" // Query or connection timeout\n | \"serialization_failure\" // Serializable transaction conflict\n | \"unsupported_version\" // F17: DB version below minimum or unparseable at connect\n | \"unknown\"; // Unclassified error\n\n/**\n * Enhanced database error interface.\n *\n * @remarks\n * Extends the standard Error interface with database-specific context.\n * Adapters should throw errors implementing this interface for consistent\n * error handling.\n *\n * @example\n * ```typescript\n * try {\n * await adapter.insert('users', { email: 'duplicate@example.com' });\n * } catch (error) {\n * if (isDatabaseError(error) && error.kind === 'unique_violation') {\n * console.log(`Duplicate ${error.column} in ${error.table}`);\n * }\n * }\n * ```\n *\n * @public\n */\nexport interface DatabaseError extends Error {\n /** Error classification */\n kind: DatabaseErrorKind;\n\n /** Database-specific error code (e.g., \"23505\" for PostgreSQL unique violation) */\n code?: string;\n\n /** Constraint name that was violated (if applicable) */\n constraint?: string;\n\n /** Table name involved in the error */\n table?: string;\n\n /** Column name involved in the error */\n column?: string;\n\n /** Detailed error description from the database */\n detail?: string;\n\n /** Hint for resolving the error */\n hint?: string;\n\n /** Original error from the database driver */\n cause?: Error;\n}\n\n/**\n * Type guard for DatabaseError.\n *\n * @remarks\n * Checks if an error is a DatabaseError with proper typing.\n *\n * @param error - Error to check\n * @returns True if error is a DatabaseError\n *\n * @public\n */\nexport function isDatabaseError(error: unknown): error is DatabaseError {\n return (\n typeof error === \"object\" &&\n error !== null &&\n \"kind\" in error &&\n typeof (error as DatabaseError).kind === \"string\"\n );\n}\n\n/**\n * The brand every Nextly application error carries.\n *\n * Read through the global symbol registry rather than imported, because the\n * adapters must not depend on the package that defines the error: `Symbol.for`\n * resolves to the same symbol in every module instance, which is why the brand\n * exists in that form to begin with.\n *\n * @internal\n */\nconst APPLICATION_ERROR_BRAND: unique symbol = Symbol.for(\"nextly/NextlyError\");\n\n/**\n * Whether an error is the application's verdict rather than the database's\n * failure.\n *\n * Work running inside a transaction may throw to roll the write back — a\n * refused value, a permission denial — and such an error is not something the\n * driver produced. Classifying it as a database error replaces its code and its\n * payload with a generic one, so a caller that asked for a refusal is handed an\n * unexplained failure instead, and per-field validation detail is lost on the\n * way out.\n *\n * @param error - Error to check\n * @returns True if the error was raised by application code\n *\n * @public\n */\nexport function isApplicationError(error: unknown): boolean {\n if (\n error === null ||\n (typeof error !== \"object\" && typeof error !== \"function\")\n ) {\n return false;\n }\n return (error as Record<symbol, unknown>)[APPLICATION_ERROR_BRAND] === true;\n}\n\n/**\n * Database error constructor options.\n *\n * @public\n */\nexport interface DatabaseErrorOptions {\n /** Error classification */\n kind: DatabaseErrorKind;\n\n /** Error message */\n message: string;\n\n /** Database-specific error code */\n code?: string;\n\n /** Constraint name */\n constraint?: string;\n\n /** Table name */\n table?: string;\n\n /** Column name */\n column?: string;\n\n /** Detailed description */\n detail?: string;\n\n /** Resolution hint */\n hint?: string;\n\n /** Original error */\n cause?: Error;\n}\n\n/**\n * Create a DatabaseError instance.\n *\n * @remarks\n * Helper function to create properly structured DatabaseError objects.\n *\n * @param options - Error options\n * @returns DatabaseError instance\n *\n * @public\n */\nexport function createDatabaseError(\n options: DatabaseErrorOptions\n): DatabaseError {\n const error = new Error(options.message) as DatabaseError;\n error.name = \"DatabaseError\";\n error.kind = options.kind;\n\n if (options.code !== undefined) error.code = options.code;\n if (options.constraint !== undefined) error.constraint = options.constraint;\n if (options.table !== undefined) error.table = options.table;\n if (options.column !== undefined) error.column = options.column;\n if (options.detail !== undefined) error.detail = options.detail;\n if (options.hint !== undefined) error.hint = options.hint;\n if (options.cause !== undefined) error.cause = options.cause;\n\n return error;\n}\n\n/**\n * The code an adapter gives the error it raises when a request has waited\n * longer than `pool.connectionTimeoutMs` for a database connection.\n *\n * A code of the adapters' own rather than the driver's wording, because the\n * drivers disagree: pg-pool raises a plain `Error` with no code, mysql2 has no\n * such wait to time out, and better-sqlite3 has no pool. Core reads this one\n * code to answer with its retryable \"database busy\" error.\n *\n * @public\n */\nexport const POOL_WAIT_TIMEOUT_CODE = \"NEXTLY_POOL_WAIT_TIMEOUT\";\n\n/**\n * The error for a request that waited `boundMs` for a database connection and\n * was given none.\n *\n * @param boundMs - The bound it waited, `pool.connectionTimeoutMs`\n * @param cause - The driver's own error, when the driver raised one\n *\n * @public\n */\nexport function poolWaitTimeoutError(\n boundMs: number,\n cause?: Error\n): DatabaseError {\n return createDatabaseError({\n kind: \"timeout\",\n code: POOL_WAIT_TIMEOUT_CODE,\n message: `Waited ${boundMs} ms for a database connection, and none was free`,\n cause,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAOA;CAOA;CAIA;AACF;;;;;;;;;;;;;ACkBA,SAAgB,gBAAgB,OAAwC;CACtE,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,OAAQ,MAAwB,SAAS;AAE7C;;;;;;;;;;;AAYA,MAAM,0BAAyC,OAAO,IAAI,oBAAoB;;;;;;;;;;;;;;;;;AAkB9E,SAAgB,mBAAmB,OAAyB;CAC1D,IACE,UAAU,QACT,OAAO,UAAU,YAAY,OAAO,UAAU,YAE/C,OAAO;CAET,OAAQ,MAAkC,6BAA6B;AACzE;;;;;;;;;;;;AA+CA,SAAgB,oBACd,SACe;CACf,MAAM,QAAQ,IAAI,MAAM,QAAQ,OAAO;CACvC,MAAM,OAAO;CACb,MAAM,OAAO,QAAQ;CAErB,IAAI,QAAQ,SAAS,KAAA,GAAW,MAAM,OAAO,QAAQ;CACrD,IAAI,QAAQ,eAAe,KAAA,GAAW,MAAM,aAAa,QAAQ;CACjE,IAAI,QAAQ,UAAU,KAAA,GAAW,MAAM,QAAQ,QAAQ;CACvD,IAAI,QAAQ,WAAW,KAAA,GAAW,MAAM,SAAS,QAAQ;CACzD,IAAI,QAAQ,WAAW,KAAA,GAAW,MAAM,SAAS,QAAQ;CACzD,IAAI,QAAQ,SAAS,KAAA,GAAW,MAAM,OAAO,QAAQ;CACrD,IAAI,QAAQ,UAAU,KAAA,GAAW,MAAM,QAAQ,QAAQ;CAEvD,OAAO;AACT;;;;;;;;;;;;AAaA,MAAa,yBAAyB;;;;;;;;;;AAWtC,SAAgB,qBACd,SACA,OACe;CACf,OAAO,oBAAoB;EACzB,MAAM;EACN,MAAM;EACN,SAAS,UAAU,QAAQ;EAC3B;CACF,CAAC;AACH"}
|