@nextlyhq/adapter-drizzle 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +9 -0
  3. package/dist/adapter-BxJVtttb.d.ts +592 -0
  4. package/dist/adapter-nvlxFkF-.d.cts +592 -0
  5. package/dist/core-CVO7WYDj.d.cts +74 -0
  6. package/dist/core-CVO7WYDj.d.ts +74 -0
  7. package/dist/error-um1d_3Uo.d.cts +105 -0
  8. package/dist/error-um1d_3Uo.d.ts +105 -0
  9. package/dist/index.cjs +1137 -0
  10. package/dist/index.cjs.map +1 -0
  11. package/dist/index.d.cts +57 -0
  12. package/dist/index.d.ts +57 -0
  13. package/dist/index.mjs +1134 -0
  14. package/dist/index.mjs.map +1 -0
  15. package/dist/migration-BbO5meEV.d.cts +622 -0
  16. package/dist/migration-Qe70wDOC.d.ts +622 -0
  17. package/dist/migrations.cjs +195 -0
  18. package/dist/migrations.cjs.map +1 -0
  19. package/dist/migrations.d.cts +351 -0
  20. package/dist/migrations.d.ts +351 -0
  21. package/dist/migrations.mjs +185 -0
  22. package/dist/migrations.mjs.map +1 -0
  23. package/dist/schema/index.cjs +10 -0
  24. package/dist/schema/index.cjs.map +1 -0
  25. package/dist/schema/index.d.cts +133 -0
  26. package/dist/schema/index.d.ts +133 -0
  27. package/dist/schema/index.mjs +7 -0
  28. package/dist/schema/index.mjs.map +1 -0
  29. package/dist/schema-BDn8WfSL.d.cts +200 -0
  30. package/dist/schema-BIQ0YQZ_.d.ts +200 -0
  31. package/dist/types/index.cjs +24 -0
  32. package/dist/types/index.cjs.map +1 -0
  33. package/dist/types/index.d.cts +210 -0
  34. package/dist/types/index.d.ts +210 -0
  35. package/dist/types/index.mjs +21 -0
  36. package/dist/types/index.mjs.map +1 -0
  37. package/dist/version-check.cjs +154 -0
  38. package/dist/version-check.cjs.map +1 -0
  39. package/dist/version-check.d.cts +43 -0
  40. package/dist/version-check.d.ts +43 -0
  41. package/dist/version-check.mjs +150 -0
  42. package/dist/version-check.mjs.map +1 -0
  43. package/package.json +94 -0
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ // src/types/error.ts
4
+ function isDatabaseError(error) {
5
+ return typeof error === "object" && error !== null && "kind" in error && typeof error.kind === "string";
6
+ }
7
+ function createDatabaseError(options) {
8
+ const error = new Error(options.message);
9
+ error.name = "DatabaseError";
10
+ error.kind = options.kind;
11
+ if (options.code !== void 0) error.code = options.code;
12
+ if (options.constraint !== void 0) error.constraint = options.constraint;
13
+ if (options.table !== void 0) error.table = options.table;
14
+ if (options.column !== void 0) error.column = options.column;
15
+ if (options.detail !== void 0) error.detail = options.detail;
16
+ if (options.hint !== void 0) error.hint = options.hint;
17
+ if (options.cause !== void 0) error.cause = options.cause;
18
+ return error;
19
+ }
20
+
21
+ exports.createDatabaseError = createDatabaseError;
22
+ exports.isDatabaseError = isDatabaseError;
23
+ //# sourceMappingURL=index.cjs.map
24
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/error.ts"],"names":[],"mappings":";;;AAuFO,SAAS,gBAAgB,KAAA,EAAwC;AACtE,EAAA,OACE,OAAO,UAAU,QAAA,IACjB,KAAA,KAAU,QACV,MAAA,IAAU,KAAA,IACV,OAAQ,KAAA,CAAwB,IAAA,KAAS,QAAA;AAE7C;AA+CO,SAAS,oBACd,OAAA,EACe;AACf,EAAA,MAAM,KAAA,GAAQ,IAAI,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA;AACvC,EAAA,KAAA,CAAM,IAAA,GAAO,eAAA;AACb,EAAA,KAAA,CAAM,OAAO,OAAA,CAAQ,IAAA;AAErB,EAAA,IAAI,OAAA,CAAQ,IAAA,KAAS,MAAA,EAAW,KAAA,CAAM,OAAO,OAAA,CAAQ,IAAA;AACrD,EAAA,IAAI,OAAA,CAAQ,UAAA,KAAe,MAAA,EAAW,KAAA,CAAM,aAAa,OAAA,CAAQ,UAAA;AACjE,EAAA,IAAI,OAAA,CAAQ,KAAA,KAAU,MAAA,EAAW,KAAA,CAAM,QAAQ,OAAA,CAAQ,KAAA;AACvD,EAAA,IAAI,OAAA,CAAQ,MAAA,KAAW,MAAA,EAAW,KAAA,CAAM,SAAS,OAAA,CAAQ,MAAA;AACzD,EAAA,IAAI,OAAA,CAAQ,MAAA,KAAW,MAAA,EAAW,KAAA,CAAM,SAAS,OAAA,CAAQ,MAAA;AACzD,EAAA,IAAI,OAAA,CAAQ,IAAA,KAAS,MAAA,EAAW,KAAA,CAAM,OAAO,OAAA,CAAQ,IAAA;AACrD,EAAA,IAAI,OAAA,CAAQ,KAAA,KAAU,MAAA,EAAW,KAAA,CAAM,QAAQ,OAAA,CAAQ,KAAA;AAEvD,EAAA,OAAO,KAAA;AACT","file":"index.cjs","sourcesContent":["/**\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 * 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"]}
@@ -0,0 +1,210 @@
1
+ import { a as SqlParam } from '../core-CVO7WYDj.cjs';
2
+ export { J as JsonArray, b as JsonObject, c as JsonValue, S as SupportedDialect, T as TableResolver } from '../core-CVO7WYDj.cjs';
3
+ export { D as DatabaseCapabilities, f as DeleteOptions, I as InsertOptions, J as JoinSpec, a as Migration, c as MigrationOptions, M as MigrationRecord, d as MigrationResult, b as MigrationStatus, O as OrderBySpec, P as PoolStats, S as SelectOptions, T as TransactionContext, h as TransactionIsolationLevel, e as TransactionOptions, U as UpdateOptions, g as UpsertOptions, W as WhereClause, i as WhereCondition, j as WhereOperator } from '../migration-BbO5meEV.cjs';
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 };
@@ -0,0 +1,210 @@
1
+ import { a as SqlParam } from '../core-CVO7WYDj.js';
2
+ export { J as JsonArray, b as JsonObject, c as JsonValue, S as SupportedDialect, T as TableResolver } from '../core-CVO7WYDj.js';
3
+ export { D as DatabaseCapabilities, f as DeleteOptions, I as InsertOptions, J as JoinSpec, a as Migration, c as MigrationOptions, M as MigrationRecord, d as MigrationResult, b as MigrationStatus, O as OrderBySpec, P as PoolStats, S as SelectOptions, T as TransactionContext, h as TransactionIsolationLevel, e as TransactionOptions, U as UpdateOptions, g as UpsertOptions, W as WhereClause, i as WhereCondition, j as WhereOperator } from '../migration-Qe70wDOC.js';
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 };
@@ -0,0 +1,21 @@
1
+ // src/types/error.ts
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
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/error.ts"],"names":[],"mappings":";AAuFO,SAAS,gBAAgB,KAAA,EAAwC;AACtE,EAAA,OACE,OAAO,UAAU,QAAA,IACjB,KAAA,KAAU,QACV,MAAA,IAAU,KAAA,IACV,OAAQ,KAAA,CAAwB,IAAA,KAAS,QAAA;AAE7C;AA+CO,SAAS,oBACd,OAAA,EACe;AACf,EAAA,MAAM,KAAA,GAAQ,IAAI,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA;AACvC,EAAA,KAAA,CAAM,IAAA,GAAO,eAAA;AACb,EAAA,KAAA,CAAM,OAAO,OAAA,CAAQ,IAAA;AAErB,EAAA,IAAI,OAAA,CAAQ,IAAA,KAAS,MAAA,EAAW,KAAA,CAAM,OAAO,OAAA,CAAQ,IAAA;AACrD,EAAA,IAAI,OAAA,CAAQ,UAAA,KAAe,MAAA,EAAW,KAAA,CAAM,aAAa,OAAA,CAAQ,UAAA;AACjE,EAAA,IAAI,OAAA,CAAQ,KAAA,KAAU,MAAA,EAAW,KAAA,CAAM,QAAQ,OAAA,CAAQ,KAAA;AACvD,EAAA,IAAI,OAAA,CAAQ,MAAA,KAAW,MAAA,EAAW,KAAA,CAAM,SAAS,OAAA,CAAQ,MAAA;AACzD,EAAA,IAAI,OAAA,CAAQ,MAAA,KAAW,MAAA,EAAW,KAAA,CAAM,SAAS,OAAA,CAAQ,MAAA;AACzD,EAAA,IAAI,OAAA,CAAQ,IAAA,KAAS,MAAA,EAAW,KAAA,CAAM,OAAO,OAAA,CAAQ,IAAA;AACrD,EAAA,IAAI,OAAA,CAAQ,KAAA,KAAU,MAAA,EAAW,KAAA,CAAM,QAAQ,OAAA,CAAQ,KAAA;AAEvD,EAAA,OAAO,KAAA;AACT","file":"index.mjs","sourcesContent":["/**\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 * 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"]}
@@ -0,0 +1,154 @@
1
+ 'use strict';
2
+
3
+ // src/version-check.ts
4
+ var NEXTLY_MIN_DB_VERSIONS = {
5
+ postgresql: { major: 15, minor: 0 },
6
+ mysql: { major: 8, minor: 0 },
7
+ sqlite: { major: 3, minor: 38 }
8
+ };
9
+ var UnsupportedDialectVersionError = class extends Error {
10
+ kind = "unsupported_version";
11
+ dialect;
12
+ detectedVersion;
13
+ requiredVersion;
14
+ cause;
15
+ constructor(args) {
16
+ super(args.message);
17
+ this.name = "UnsupportedDialectVersionError";
18
+ this.dialect = args.dialect;
19
+ this.detectedVersion = args.detectedVersion;
20
+ this.requiredVersion = args.requiredVersion;
21
+ this.cause = args.cause;
22
+ }
23
+ };
24
+ var DOCS_URL = "https://nextlyhq.com/docs/database/support";
25
+ var VARIANT_TOKENS = [
26
+ "mariadb",
27
+ "tidb",
28
+ "aurora",
29
+ "planetscale",
30
+ "vitess"
31
+ ];
32
+ var POSTGRES_REGEX = /^PostgreSQL (\d+)\.(\d+)/;
33
+ var MYSQL_REGEX = /^(\d+)\.(\d+)\.(\d+)/;
34
+ var SQLITE_REGEX = /^(\d+)\.(\d+)\.(\d+)/;
35
+ function parsePostgres(raw) {
36
+ const match = POSTGRES_REGEX.exec(raw);
37
+ if (!match) return null;
38
+ return { major: Number(match[1]), minor: Number(match[2]) };
39
+ }
40
+ function parseMySQL(raw) {
41
+ const match = MYSQL_REGEX.exec(raw);
42
+ if (!match) return null;
43
+ return { major: Number(match[1]), minor: Number(match[2]) };
44
+ }
45
+ function parseSQLite(raw) {
46
+ const match = SQLITE_REGEX.exec(raw);
47
+ if (!match) return null;
48
+ return { major: Number(match[1]), minor: Number(match[2]) };
49
+ }
50
+ function detectVariant(raw) {
51
+ const lower = raw.toLowerCase();
52
+ for (const token of VARIANT_TOKENS) {
53
+ if (lower.includes(token)) return token;
54
+ }
55
+ return null;
56
+ }
57
+ function meetsMinimum(detected, required) {
58
+ if (detected.major > required.major) return true;
59
+ if (detected.major < required.major) return false;
60
+ return detected.minor >= required.minor;
61
+ }
62
+ async function checkDialectVersion(client, dialect, options) {
63
+ const required = NEXTLY_MIN_DB_VERSIONS[dialect];
64
+ const requiredStr = `${required.major}.${required.minor}+`;
65
+ let raw;
66
+ if (dialect === "sqlite") {
67
+ raw = await querySqliteVersion(client);
68
+ } else if (dialect === "postgresql") {
69
+ raw = await queryPostgresVersion(client);
70
+ } else {
71
+ raw = await queryMysqlVersion(client);
72
+ }
73
+ const variant = dialect === "mysql" ? detectVariant(raw) : null;
74
+ if (variant) {
75
+ const warning = `Detected ${variant} ('${raw}'). Nextly is regression-tested against real MySQL 8.0+ only; this MySQL-compatible variant is not officially supported in v1 but most operations should work. See ${DOCS_URL}.`;
76
+ if (options?.onWarning) options.onWarning(warning);
77
+ return;
78
+ }
79
+ let parsed;
80
+ if (dialect === "postgresql") parsed = parsePostgres(raw);
81
+ else if (dialect === "mysql") parsed = parseMySQL(raw);
82
+ else parsed = parseSQLite(raw);
83
+ if (!parsed) {
84
+ throw new UnsupportedDialectVersionError({
85
+ dialect,
86
+ detectedVersion: raw,
87
+ requiredVersion: requiredStr,
88
+ message: `Could not parse ${dialect} version from '${raw}'. Nextly requires ${dialect} ${requiredStr}. If you are on a known MySQL-compatible variant we did not detect, please file an issue. See ${DOCS_URL}.`
89
+ });
90
+ }
91
+ if (!meetsMinimum(parsed, required)) {
92
+ const labels = {
93
+ postgresql: "PostgreSQL",
94
+ mysql: "MySQL",
95
+ sqlite: "SQLite"
96
+ };
97
+ throw new UnsupportedDialectVersionError({
98
+ dialect,
99
+ detectedVersion: `${parsed.major}.${parsed.minor}`,
100
+ requiredVersion: requiredStr,
101
+ message: `${labels[dialect]} ${requiredStr} required; detected ${parsed.major}.${parsed.minor}. See ${DOCS_URL}.`
102
+ });
103
+ }
104
+ }
105
+ async function queryPostgresVersion(client) {
106
+ if (!client.query) {
107
+ throw new Error("PostgreSQL client missing query() method");
108
+ }
109
+ const result = await client.query("SELECT version()");
110
+ const row = result.rows?.[0];
111
+ const version = row?.version;
112
+ if (typeof version !== "string") {
113
+ throw new Error(
114
+ `Unexpected response shape from SELECT version(): ${JSON.stringify(result)}`
115
+ );
116
+ }
117
+ return version;
118
+ }
119
+ async function queryMysqlVersion(client) {
120
+ if (!client.query) {
121
+ throw new Error("MySQL client missing query() method");
122
+ }
123
+ const result = await client.query("SELECT VERSION() AS version");
124
+ const row = result?.[0]?.[0];
125
+ const version = row?.version;
126
+ if (typeof version !== "string") {
127
+ throw new Error(
128
+ `Unexpected response shape from SELECT VERSION(): ${JSON.stringify(result)}`
129
+ );
130
+ }
131
+ return version;
132
+ }
133
+ function querySqliteVersion(client) {
134
+ if (!client.prepare) {
135
+ return Promise.reject(new Error("SQLite client missing prepare() method"));
136
+ }
137
+ const stmt = client.prepare("SELECT sqlite_version() AS version");
138
+ const row = stmt.get();
139
+ const version = row?.version;
140
+ if (typeof version !== "string") {
141
+ return Promise.reject(
142
+ new Error(
143
+ `Unexpected response shape from SELECT sqlite_version(): ${JSON.stringify(row)}`
144
+ )
145
+ );
146
+ }
147
+ return Promise.resolve(version);
148
+ }
149
+
150
+ exports.NEXTLY_MIN_DB_VERSIONS = NEXTLY_MIN_DB_VERSIONS;
151
+ exports.UnsupportedDialectVersionError = UnsupportedDialectVersionError;
152
+ exports.checkDialectVersion = checkDialectVersion;
153
+ //# sourceMappingURL=version-check.cjs.map
154
+ //# sourceMappingURL=version-check.cjs.map