@nextlyhq/adapter-drizzle 0.0.2-alpha.6 → 0.0.2-alpha.60

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.
@@ -1,4 +1,5 @@
1
1
  import { a as SqlParam, S as SupportedDialect } from './core-CVO7WYDj.cjs';
2
+ import { SQL } from 'drizzle-orm';
2
3
 
3
4
  /**
4
5
  * Query building type definitions for database-agnostic queries.
@@ -147,6 +148,17 @@ interface SelectOptions {
147
148
  having?: WhereClause;
148
149
  /** Return distinct rows only */
149
150
  distinct?: boolean;
151
+ /**
152
+ * Take a `FOR UPDATE` row lock on the selected rows for the rest of the
153
+ * transaction, and read the latest committed values rather than the
154
+ * transaction's snapshot. Use for read-modify-write sequences that must not
155
+ * interleave (e.g. re-reading a status under the lock the write will take).
156
+ *
157
+ * Requires a transaction executor. No-ops on SQLite, which has no `FOR UPDATE`
158
+ * and needs none — its transactions open with `BEGIN IMMEDIATE`, already
159
+ * serializing writers.
160
+ */
161
+ forUpdate?: boolean;
150
162
  }
151
163
  /**
152
164
  * Options for INSERT operations.
@@ -275,6 +287,58 @@ interface TransactionContext {
275
287
  * @returns Array of result rows
276
288
  */
277
289
  execute<T = unknown>(sql: string, params?: SqlParam[]): Promise<T[]>;
290
+ /**
291
+ * Run a Drizzle-built statement within the transaction, for its effect.
292
+ *
293
+ * @remarks
294
+ * The typed CRUD methods below resolve their table through the schema
295
+ * registry and reject any name it does not declare. That leaves no way to
296
+ * write to a table addressed under a name the ORM does not know — a table
297
+ * mid-rename, most of all — other than assembling SQL by hand, which also
298
+ * means hand-picking each driver's placeholder syntax.
299
+ *
300
+ * This accepts Drizzle's `sql` template instead, so identifier quoting and
301
+ * parameter binding are generated for the dialect in use. Implemented per
302
+ * adapter because the underlying call is not uniform: node-postgres and
303
+ * mysql2 expose `execute`, while better-sqlite3 needs `run` and throws on a
304
+ * statement that returns no rows.
305
+ *
306
+ * Returns nothing: this is for statements run to change data, not to read it.
307
+ *
308
+ * @param statement - Drizzle `sql` template to run
309
+ */
310
+ runStatement(statement: SQL): Promise<void>;
311
+ /**
312
+ * Run a Drizzle-built statement within the transaction and return its rows.
313
+ *
314
+ * @remarks
315
+ * The reading half of `runStatement`, for the same reason: a table the schema
316
+ * registry does not declare cannot be reached through the typed CRUD methods,
317
+ * which reject the name outright. Implemented per adapter because the drivers
318
+ * disagree about both the call and the result — node-postgres answers
319
+ * `{ rows }`, mysql2 a `[rows, fields]` tuple, and better-sqlite3 needs `all`.
320
+ *
321
+ * @param statement - Drizzle `sql` template to run
322
+ * @returns Rows the statement produced
323
+ */
324
+ queryStatement<T = Record<string, unknown>>(statement: SQL): Promise<T[]>;
325
+ /**
326
+ * Take an exclusive lock on a single row for the rest of this transaction.
327
+ *
328
+ * @remarks
329
+ * For read-modify-write sequences that must not interleave: without a lock
330
+ * another transaction can commit between the read and the write, leaving the
331
+ * caller's view of the prior state inconsistent with what its own write
332
+ * applied on top of.
333
+ *
334
+ * No-ops on dialects without row-level locking. SQLite is the case that
335
+ * matters and needs nothing — its transactions open with `BEGIN IMMEDIATE`,
336
+ * which already serializes writers.
337
+ *
338
+ * @param table - Table name
339
+ * @param id - Primary-key value of the row to lock
340
+ */
341
+ lockRow(table: string, id: SqlParam): Promise<void>;
278
342
  /**
279
343
  * Insert a single record.
280
344
  *
@@ -365,6 +429,20 @@ interface TransactionContext {
365
429
  * @param name - Savepoint name
366
430
  */
367
431
  releaseSavepoint?(name: string): Promise<void>;
432
+ /**
433
+ * Return the Drizzle ORM instance bound to THIS transaction's connection.
434
+ *
435
+ * @remarks
436
+ * Runs Drizzle `sql` templates / fluent queries inside the caller's
437
+ * transaction (same client the delegated CRUD methods use), so services
438
+ * that drop to Drizzle raw SQL (e.g. junction-table writes) can participate
439
+ * in the transaction instead of running on the pooled connection. Required
440
+ * so callers never silently fall back to the pooled connection (which would
441
+ * run a write outside the transaction); every adapter must implement it.
442
+ * Generic return so callers narrow to the dialect Drizzle type they need
443
+ * without an `any` cast.
444
+ */
445
+ getDrizzle<T = unknown>(): T;
368
446
  }
369
447
 
370
448
  /**
@@ -1,4 +1,5 @@
1
1
  import { a as SqlParam, S as SupportedDialect } from './core-CVO7WYDj.js';
2
+ import { SQL } from 'drizzle-orm';
2
3
 
3
4
  /**
4
5
  * Query building type definitions for database-agnostic queries.
@@ -147,6 +148,17 @@ interface SelectOptions {
147
148
  having?: WhereClause;
148
149
  /** Return distinct rows only */
149
150
  distinct?: boolean;
151
+ /**
152
+ * Take a `FOR UPDATE` row lock on the selected rows for the rest of the
153
+ * transaction, and read the latest committed values rather than the
154
+ * transaction's snapshot. Use for read-modify-write sequences that must not
155
+ * interleave (e.g. re-reading a status under the lock the write will take).
156
+ *
157
+ * Requires a transaction executor. No-ops on SQLite, which has no `FOR UPDATE`
158
+ * and needs none — its transactions open with `BEGIN IMMEDIATE`, already
159
+ * serializing writers.
160
+ */
161
+ forUpdate?: boolean;
150
162
  }
151
163
  /**
152
164
  * Options for INSERT operations.
@@ -275,6 +287,58 @@ interface TransactionContext {
275
287
  * @returns Array of result rows
276
288
  */
277
289
  execute<T = unknown>(sql: string, params?: SqlParam[]): Promise<T[]>;
290
+ /**
291
+ * Run a Drizzle-built statement within the transaction, for its effect.
292
+ *
293
+ * @remarks
294
+ * The typed CRUD methods below resolve their table through the schema
295
+ * registry and reject any name it does not declare. That leaves no way to
296
+ * write to a table addressed under a name the ORM does not know — a table
297
+ * mid-rename, most of all — other than assembling SQL by hand, which also
298
+ * means hand-picking each driver's placeholder syntax.
299
+ *
300
+ * This accepts Drizzle's `sql` template instead, so identifier quoting and
301
+ * parameter binding are generated for the dialect in use. Implemented per
302
+ * adapter because the underlying call is not uniform: node-postgres and
303
+ * mysql2 expose `execute`, while better-sqlite3 needs `run` and throws on a
304
+ * statement that returns no rows.
305
+ *
306
+ * Returns nothing: this is for statements run to change data, not to read it.
307
+ *
308
+ * @param statement - Drizzle `sql` template to run
309
+ */
310
+ runStatement(statement: SQL): Promise<void>;
311
+ /**
312
+ * Run a Drizzle-built statement within the transaction and return its rows.
313
+ *
314
+ * @remarks
315
+ * The reading half of `runStatement`, for the same reason: a table the schema
316
+ * registry does not declare cannot be reached through the typed CRUD methods,
317
+ * which reject the name outright. Implemented per adapter because the drivers
318
+ * disagree about both the call and the result — node-postgres answers
319
+ * `{ rows }`, mysql2 a `[rows, fields]` tuple, and better-sqlite3 needs `all`.
320
+ *
321
+ * @param statement - Drizzle `sql` template to run
322
+ * @returns Rows the statement produced
323
+ */
324
+ queryStatement<T = Record<string, unknown>>(statement: SQL): Promise<T[]>;
325
+ /**
326
+ * Take an exclusive lock on a single row for the rest of this transaction.
327
+ *
328
+ * @remarks
329
+ * For read-modify-write sequences that must not interleave: without a lock
330
+ * another transaction can commit between the read and the write, leaving the
331
+ * caller's view of the prior state inconsistent with what its own write
332
+ * applied on top of.
333
+ *
334
+ * No-ops on dialects without row-level locking. SQLite is the case that
335
+ * matters and needs nothing — its transactions open with `BEGIN IMMEDIATE`,
336
+ * which already serializes writers.
337
+ *
338
+ * @param table - Table name
339
+ * @param id - Primary-key value of the row to lock
340
+ */
341
+ lockRow(table: string, id: SqlParam): Promise<void>;
278
342
  /**
279
343
  * Insert a single record.
280
344
  *
@@ -365,6 +429,20 @@ interface TransactionContext {
365
429
  * @param name - Savepoint name
366
430
  */
367
431
  releaseSavepoint?(name: string): Promise<void>;
432
+ /**
433
+ * Return the Drizzle ORM instance bound to THIS transaction's connection.
434
+ *
435
+ * @remarks
436
+ * Runs Drizzle `sql` templates / fluent queries inside the caller's
437
+ * transaction (same client the delegated CRUD methods use), so services
438
+ * that drop to Drizzle raw SQL (e.g. junction-table writes) can participate
439
+ * in the transaction instead of running on the pooled connection. Required
440
+ * so callers never silently fall back to the pooled connection (which would
441
+ * run a write outside the transaction); every adapter must implement it.
442
+ * Generic return so callers narrow to the dialect Drizzle type they need
443
+ * without an `any` cast.
444
+ */
445
+ getDrizzle<T = unknown>(): T;
368
446
  }
369
447
 
370
448
  /**
@@ -1,9 +1,10 @@
1
- import { D as DrizzleAdapter } from './adapter-nvlxFkF-.cjs';
2
- import { M as MigrationRecord, a as Migration, b as MigrationStatus, c as MigrationOptions } from './migration-BbO5meEV.cjs';
3
- export { d as MigrationResult } from './migration-BbO5meEV.cjs';
1
+ import { D as DrizzleAdapter } from './adapter-BG7MnOUw.cjs';
2
+ import { M as MigrationRecord, a as Migration, b as MigrationStatus, c as MigrationOptions } from './migration-BUc56kip.cjs';
3
+ export { d as MigrationResult } from './migration-BUc56kip.cjs';
4
+ import 'drizzle-orm';
4
5
  import './core-CVO7WYDj.cjs';
5
6
  import './schema-BDn8WfSL.cjs';
6
- import './error-um1d_3Uo.cjs';
7
+ import './error-BrdknH2s.cjs';
7
8
 
8
9
  /**
9
10
  * Database migration utilities.
@@ -1,9 +1,10 @@
1
- import { D as DrizzleAdapter } from './adapter-BxJVtttb.js';
2
- import { M as MigrationRecord, a as Migration, b as MigrationStatus, c as MigrationOptions } from './migration-Qe70wDOC.js';
3
- export { d as MigrationResult } from './migration-Qe70wDOC.js';
1
+ import { D as DrizzleAdapter } from './adapter-DjPoLjBK.js';
2
+ import { M as MigrationRecord, a as Migration, b as MigrationStatus, c as MigrationOptions } from './migration-Bj84e15B.js';
3
+ export { d as MigrationResult } from './migration-Bj84e15B.js';
4
+ import 'drizzle-orm';
4
5
  import './core-CVO7WYDj.js';
5
6
  import './schema-BIQ0YQZ_.js';
6
- import './error-um1d_3Uo.js';
7
+ import './error-BrdknH2s.js';
7
8
 
8
9
  /**
9
10
  * Database migration utilities.
@@ -4,6 +4,13 @@
4
4
  function isDatabaseError(error) {
5
5
  return typeof error === "object" && error !== null && "kind" in error && typeof error.kind === "string";
6
6
  }
7
+ var APPLICATION_ERROR_BRAND = Symbol.for("nextly/NextlyError");
8
+ function isApplicationError(error) {
9
+ if (error === null || typeof error !== "object" && typeof error !== "function") {
10
+ return false;
11
+ }
12
+ return error[APPLICATION_ERROR_BRAND] === true;
13
+ }
7
14
  function createDatabaseError(options) {
8
15
  const error = new Error(options.message);
9
16
  error.name = "DatabaseError";
@@ -19,6 +26,7 @@ function createDatabaseError(options) {
19
26
  }
20
27
 
21
28
  exports.createDatabaseError = createDatabaseError;
29
+ exports.isApplicationError = isApplicationError;
22
30
  exports.isDatabaseError = isDatabaseError;
23
31
  //# sourceMappingURL=index.cjs.map
24
32
  //# sourceMappingURL=index.cjs.map
@@ -1 +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"]}
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;AAYA,IAAM,uBAAA,GAAyC,MAAA,CAAO,GAAA,CAAI,oBAAoB,CAAA;AAkBvE,SAAS,mBAAmB,KAAA,EAAyB;AAC1D,EAAA,IACE,UAAU,IAAA,IACT,OAAO,UAAU,QAAA,IAAY,OAAO,UAAU,UAAA,EAC/C;AACA,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAQ,KAAA,CAAkC,uBAAuB,CAAA,KAAM,IAAA;AACzE;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 * 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"]}
@@ -1,8 +1,9 @@
1
1
  import { a as SqlParam } from '../core-CVO7WYDj.cjs';
2
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';
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-BUc56kip.cjs';
4
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';
5
+ export { a as DatabaseError, D as DatabaseErrorKind, b as DatabaseErrorOptions, c as createDatabaseError, i as isApplicationError, d as isDatabaseError } from '../error-BrdknH2s.cjs';
6
+ import 'drizzle-orm';
6
7
 
7
8
  /**
8
9
  * Database adapter configuration type definitions.
@@ -1,8 +1,9 @@
1
1
  import { a as SqlParam } from '../core-CVO7WYDj.js';
2
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';
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-Bj84e15B.js';
4
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';
5
+ export { a as DatabaseError, D as DatabaseErrorKind, b as DatabaseErrorOptions, c as createDatabaseError, i as isApplicationError, d as isDatabaseError } from '../error-BrdknH2s.js';
6
+ import 'drizzle-orm';
6
7
 
7
8
  /**
8
9
  * Database adapter configuration type definitions.
@@ -2,6 +2,13 @@
2
2
  function isDatabaseError(error) {
3
3
  return typeof error === "object" && error !== null && "kind" in error && typeof error.kind === "string";
4
4
  }
5
+ var APPLICATION_ERROR_BRAND = Symbol.for("nextly/NextlyError");
6
+ function isApplicationError(error) {
7
+ if (error === null || typeof error !== "object" && typeof error !== "function") {
8
+ return false;
9
+ }
10
+ return error[APPLICATION_ERROR_BRAND] === true;
11
+ }
5
12
  function createDatabaseError(options) {
6
13
  const error = new Error(options.message);
7
14
  error.name = "DatabaseError";
@@ -16,6 +23,6 @@ function createDatabaseError(options) {
16
23
  return error;
17
24
  }
18
25
 
19
- export { createDatabaseError, isDatabaseError };
26
+ export { createDatabaseError, isApplicationError, isDatabaseError };
20
27
  //# sourceMappingURL=index.mjs.map
21
28
  //# sourceMappingURL=index.mjs.map
@@ -1 +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"]}
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;AAYA,IAAM,uBAAA,GAAyC,MAAA,CAAO,GAAA,CAAI,oBAAoB,CAAA;AAkBvE,SAAS,mBAAmB,KAAA,EAAyB;AAC1D,EAAA,IACE,UAAU,IAAA,IACT,OAAO,UAAU,QAAA,IAAY,OAAO,UAAU,UAAA,EAC/C;AACA,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAQ,KAAA,CAAkC,uBAAuB,CAAA,KAAM,IAAA;AACzE;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 * 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"]}
@@ -1,5 +1,5 @@
1
1
  import { S as SupportedDialect } from './core-CVO7WYDj.cjs';
2
- import { a as DatabaseError } from './error-um1d_3Uo.cjs';
2
+ import { a as DatabaseError } from './error-BrdknH2s.cjs';
3
3
 
4
4
  declare const NEXTLY_MIN_DB_VERSIONS: {
5
5
  readonly postgresql: {
@@ -1,5 +1,5 @@
1
1
  import { S as SupportedDialect } from './core-CVO7WYDj.js';
2
- import { a as DatabaseError } from './error-um1d_3Uo.js';
2
+ import { a as DatabaseError } from './error-BrdknH2s.js';
3
3
 
4
4
  declare const NEXTLY_MIN_DB_VERSIONS: {
5
5
  readonly postgresql: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextlyhq/adapter-drizzle",
3
- "version": "0.0.2-alpha.6",
3
+ "version": "0.0.2-alpha.60",
4
4
  "description": "Shared Drizzle ORM adapter logic for Nextly database adapters",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -38,22 +38,22 @@
38
38
  "dist"
39
39
  ],
40
40
  "engines": {
41
- "node": ">=20.0.0"
41
+ "node": "^20.19.0 || ^22.12.0 || >=24.0.0"
42
42
  },
43
43
  "dependencies": {
44
- "drizzle-orm": "^0.45.2"
44
+ "drizzle-orm": "1.0.0-rc.4"
45
45
  },
46
46
  "devDependencies": {
47
- "@types/node": "^20.0.0",
48
- "@vitest/coverage-v8": "^4.0.8",
49
- "@vitest/ui": "^4.0.8",
50
- "eslint": "^9.34.0",
47
+ "@types/node": "^20.19.17",
48
+ "@vitest/coverage-v8": "^4.1.0",
49
+ "@vitest/ui": "^4.1.0",
50
+ "eslint": "^9.39.1",
51
51
  "tsup": "^8.5.0",
52
52
  "typescript": "^5.9.3",
53
53
  "vite-tsconfig-paths": "^5.1.4",
54
- "vitest": "^4.0.8",
55
- "@nextlyhq/eslint-config": "0.0.2-alpha.5",
56
- "@nextlyhq/tsconfig": "0.0.2-alpha.5"
54
+ "vitest": "^4.1.0",
55
+ "@nextlyhq/eslint-config": "0.0.2-alpha.60",
56
+ "@nextlyhq/tsconfig": "0.0.2-alpha.60"
57
57
  },
58
58
  "repository": {
59
59
  "type": "git",