@nextlyhq/adapter-drizzle 0.0.2-alpha.48 → 0.0.2-alpha.50

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.
@@ -2,7 +2,7 @@ import { AnyRelations, SQL } from 'drizzle-orm';
2
2
  import { S as SupportedDialect, a as SqlParam, T as TableResolver } from './core-CVO7WYDj.js';
3
3
  import { T as TransactionContext, e as TransactionOptions, D as DatabaseCapabilities, P as PoolStats, S as SelectOptions, I as InsertOptions, W as WhereClause, U as UpdateOptions, f as DeleteOptions, g as UpsertOptions, a as Migration, d as MigrationResult } from './migration-Bj84e15B.js';
4
4
  import { T as TableDefinition, C as CreateTableOptions, D as DropTableOptions, A as AlterTableOperation, a as AlterTableOptions } from './schema-BIQ0YQZ_.js';
5
- import { D as DatabaseErrorKind, a as DatabaseError } from './error-um1d_3Uo.js';
5
+ import { D as DatabaseErrorKind, a as DatabaseError } from './error-BrdknH2s.js';
6
6
 
7
7
  /**
8
8
  * Base database adapter abstract class.
@@ -60,11 +60,29 @@ declare abstract class DrizzleAdapter {
60
60
  * The transaction is automatically committed on success or rolled back on error.
61
61
  * Supports nested transactions via savepoints on databases that support them.
62
62
  *
63
+ * Two kinds of error leave this method, and a caller has to be able to tell
64
+ * them apart. An error carrying the Nextly application brand — see
65
+ * `isApplicationError` — arrives exactly as it was thrown, because that is
66
+ * the application refusing the write rather than the database failing to
67
+ * perform it, and rewriting it would discard the code and payload the caller
68
+ * is meant to act on.
69
+ *
70
+ * Everything else arrives as a `DatabaseError` with its kind classified, and
71
+ * that deliberately includes an unbranded error the callback itself threw:
72
+ * the brand is the only thing distinguishing a deliberate refusal from a
73
+ * driver failure that surfaced through callback code, and guessing from the
74
+ * throw site would put raw driver text on the wire under a caller's own
75
+ * error shape.
76
+ *
77
+ * The rollback is the same either way.
78
+ *
63
79
  * @param callback - Function to execute within transaction
64
80
  * @param options - Transaction options
65
81
  * @returns Result from the callback
66
82
  *
67
- * @throws {DatabaseError} If transaction fails
83
+ * @throws {DatabaseError} If the transaction itself fails, or if the callback
84
+ * threw an error that does not carry the application brand
85
+ * @throws The callback's own error, unchanged, when it carries that brand
68
86
  */
69
87
  abstract transaction<T>(callback: (ctx: TransactionContext) => Promise<T>, options?: TransactionOptions): Promise<T>;
70
88
  /**
@@ -2,7 +2,7 @@ import { AnyRelations, SQL } from 'drizzle-orm';
2
2
  import { S as SupportedDialect, a as SqlParam, T as TableResolver } from './core-CVO7WYDj.cjs';
3
3
  import { T as TransactionContext, e as TransactionOptions, D as DatabaseCapabilities, P as PoolStats, S as SelectOptions, I as InsertOptions, W as WhereClause, U as UpdateOptions, f as DeleteOptions, g as UpsertOptions, a as Migration, d as MigrationResult } from './migration-BUc56kip.cjs';
4
4
  import { T as TableDefinition, C as CreateTableOptions, D as DropTableOptions, A as AlterTableOperation, a as AlterTableOptions } from './schema-BDn8WfSL.cjs';
5
- import { D as DatabaseErrorKind, a as DatabaseError } from './error-um1d_3Uo.cjs';
5
+ import { D as DatabaseErrorKind, a as DatabaseError } from './error-BrdknH2s.cjs';
6
6
 
7
7
  /**
8
8
  * Base database adapter abstract class.
@@ -60,11 +60,29 @@ declare abstract class DrizzleAdapter {
60
60
  * The transaction is automatically committed on success or rolled back on error.
61
61
  * Supports nested transactions via savepoints on databases that support them.
62
62
  *
63
+ * Two kinds of error leave this method, and a caller has to be able to tell
64
+ * them apart. An error carrying the Nextly application brand — see
65
+ * `isApplicationError` — arrives exactly as it was thrown, because that is
66
+ * the application refusing the write rather than the database failing to
67
+ * perform it, and rewriting it would discard the code and payload the caller
68
+ * is meant to act on.
69
+ *
70
+ * Everything else arrives as a `DatabaseError` with its kind classified, and
71
+ * that deliberately includes an unbranded error the callback itself threw:
72
+ * the brand is the only thing distinguishing a deliberate refusal from a
73
+ * driver failure that surfaced through callback code, and guessing from the
74
+ * throw site would put raw driver text on the wire under a caller's own
75
+ * error shape.
76
+ *
77
+ * The rollback is the same either way.
78
+ *
63
79
  * @param callback - Function to execute within transaction
64
80
  * @param options - Transaction options
65
81
  * @returns Result from the callback
66
82
  *
67
- * @throws {DatabaseError} If transaction fails
83
+ * @throws {DatabaseError} If the transaction itself fails, or if the callback
84
+ * threw an error that does not carry the application brand
85
+ * @throws The callback's own error, unchanged, when it carries that brand
68
86
  */
69
87
  abstract transaction<T>(callback: (ctx: TransactionContext) => Promise<T>, options?: TransactionOptions): Promise<T>;
70
88
  /**
@@ -64,6 +64,23 @@ interface DatabaseError extends Error {
64
64
  * @public
65
65
  */
66
66
  declare function isDatabaseError(error: unknown): error is DatabaseError;
67
+ /**
68
+ * Whether an error is the application's verdict rather than the database's
69
+ * failure.
70
+ *
71
+ * Work running inside a transaction may throw to roll the write back — a
72
+ * refused value, a permission denial — and such an error is not something the
73
+ * driver produced. Classifying it as a database error replaces its code and its
74
+ * payload with a generic one, so a caller that asked for a refusal is handed an
75
+ * unexplained failure instead, and per-field validation detail is lost on the
76
+ * way out.
77
+ *
78
+ * @param error - Error to check
79
+ * @returns True if the error was raised by application code
80
+ *
81
+ * @public
82
+ */
83
+ declare function isApplicationError(error: unknown): boolean;
67
84
  /**
68
85
  * Database error constructor options.
69
86
  *
@@ -102,4 +119,4 @@ interface DatabaseErrorOptions {
102
119
  */
103
120
  declare function createDatabaseError(options: DatabaseErrorOptions): DatabaseError;
104
121
 
105
- export { type DatabaseErrorKind as D, type DatabaseError as a, type DatabaseErrorOptions as b, createDatabaseError as c, isDatabaseError as i };
122
+ export { type DatabaseErrorKind as D, type DatabaseError as a, type DatabaseErrorOptions as b, createDatabaseError as c, isDatabaseError as d, isApplicationError as i };
@@ -64,6 +64,23 @@ interface DatabaseError extends Error {
64
64
  * @public
65
65
  */
66
66
  declare function isDatabaseError(error: unknown): error is DatabaseError;
67
+ /**
68
+ * Whether an error is the application's verdict rather than the database's
69
+ * failure.
70
+ *
71
+ * Work running inside a transaction may throw to roll the write back — a
72
+ * refused value, a permission denial — and such an error is not something the
73
+ * driver produced. Classifying it as a database error replaces its code and its
74
+ * payload with a generic one, so a caller that asked for a refusal is handed an
75
+ * unexplained failure instead, and per-field validation detail is lost on the
76
+ * way out.
77
+ *
78
+ * @param error - Error to check
79
+ * @returns True if the error was raised by application code
80
+ *
81
+ * @public
82
+ */
83
+ declare function isApplicationError(error: unknown): boolean;
67
84
  /**
68
85
  * Database error constructor options.
69
86
  *
@@ -102,4 +119,4 @@ interface DatabaseErrorOptions {
102
119
  */
103
120
  declare function createDatabaseError(options: DatabaseErrorOptions): DatabaseError;
104
121
 
105
- export { type DatabaseErrorKind as D, type DatabaseError as a, type DatabaseErrorOptions as b, createDatabaseError as c, isDatabaseError as i };
122
+ export { type DatabaseErrorKind as D, type DatabaseError as a, type DatabaseErrorOptions as b, createDatabaseError as c, isDatabaseError as d, isApplicationError as i };