@prisma/driver-adapter-utils 5.20.0-dev.2 → 5.20.0-dev.21

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/dist/index.d.mts CHANGED
@@ -9,6 +9,13 @@ export declare type ArgType = 'Int32' | 'Int64' | 'Float' | 'Double' | 'Text' |
9
9
 
10
10
  export declare const bindAdapter: (adapter: DriverAdapter) => ErrorCapturingDriverAdapter;
11
11
 
12
+ export declare interface BoundDriverAdapter extends Queryable, WithTransaction {
13
+ /**
14
+ * Optional method that returns extra connection info
15
+ */
16
+ getConnectionInfo?(): Result<ConnectionInfo>;
17
+ }
18
+
12
19
  export declare type ColumnType = (typeof ColumnTypeEnum)[keyof typeof ColumnTypeEnum];
13
20
 
14
21
  export declare const ColumnTypeEnum: {
@@ -53,11 +60,7 @@ export declare type ConnectionInfo = {
53
60
 
54
61
  export { Debug }
55
62
 
56
- export declare interface DriverAdapter extends Queryable {
57
- /**
58
- * Starts new transaction.
59
- */
60
- startTransaction(): Promise<Result<Transaction>>;
63
+ export declare interface DriverAdapter extends Queryable, WithTransactionDeprecated, WithTransaction {
61
64
  /**
62
65
  * Optional method that returns extra connection info
63
66
  */
@@ -95,7 +98,7 @@ declare type Error_2 = {
95
98
  };
96
99
  export { Error_2 as Error }
97
100
 
98
- export declare interface ErrorCapturingDriverAdapter extends DriverAdapter {
101
+ export declare interface ErrorCapturingDriverAdapter extends BoundDriverAdapter {
99
102
  readonly errorRegistry: ErrorRegistry;
100
103
  }
101
104
 
@@ -185,8 +188,31 @@ export declare interface Transaction extends Queryable {
185
188
  rollback(): Promise<Result<void>>;
186
189
  }
187
190
 
191
+ export declare interface TransactionContext extends Queryable {
192
+ /**
193
+ * Starts new transaction.
194
+ */
195
+ startTransaction(): Promise<Result<Transaction>>;
196
+ }
197
+
188
198
  export declare type TransactionOptions = {
189
199
  usePhantomQuery: boolean;
190
200
  };
191
201
 
202
+ declare interface WithTransaction extends Queryable {
203
+ /**
204
+ * Starts new transaction.
205
+ * If `startTransaction` is not defined, `transactionContext` must be defined.
206
+ */
207
+ transactionContext?(): Promise<Result<TransactionContext>>;
208
+ }
209
+
210
+ declare interface WithTransactionDeprecated extends Queryable {
211
+ /**
212
+ * Starts new transaction.
213
+ * @deprecated Use `transactionContext` instead.
214
+ */
215
+ startTransaction?(): Promise<Result<Transaction>>;
216
+ }
217
+
192
218
  export { }
package/dist/index.d.ts CHANGED
@@ -9,6 +9,13 @@ export declare type ArgType = 'Int32' | 'Int64' | 'Float' | 'Double' | 'Text' |
9
9
 
10
10
  export declare const bindAdapter: (adapter: DriverAdapter) => ErrorCapturingDriverAdapter;
11
11
 
12
+ export declare interface BoundDriverAdapter extends Queryable, WithTransaction {
13
+ /**
14
+ * Optional method that returns extra connection info
15
+ */
16
+ getConnectionInfo?(): Result<ConnectionInfo>;
17
+ }
18
+
12
19
  export declare type ColumnType = (typeof ColumnTypeEnum)[keyof typeof ColumnTypeEnum];
13
20
 
14
21
  export declare const ColumnTypeEnum: {
@@ -53,11 +60,7 @@ export declare type ConnectionInfo = {
53
60
 
54
61
  export { Debug }
55
62
 
56
- export declare interface DriverAdapter extends Queryable {
57
- /**
58
- * Starts new transaction.
59
- */
60
- startTransaction(): Promise<Result<Transaction>>;
63
+ export declare interface DriverAdapter extends Queryable, WithTransactionDeprecated, WithTransaction {
61
64
  /**
62
65
  * Optional method that returns extra connection info
63
66
  */
@@ -95,7 +98,7 @@ declare type Error_2 = {
95
98
  };
96
99
  export { Error_2 as Error }
97
100
 
98
- export declare interface ErrorCapturingDriverAdapter extends DriverAdapter {
101
+ export declare interface ErrorCapturingDriverAdapter extends BoundDriverAdapter {
99
102
  readonly errorRegistry: ErrorRegistry;
100
103
  }
101
104
 
@@ -185,8 +188,31 @@ export declare interface Transaction extends Queryable {
185
188
  rollback(): Promise<Result<void>>;
186
189
  }
187
190
 
191
+ export declare interface TransactionContext extends Queryable {
192
+ /**
193
+ * Starts new transaction.
194
+ */
195
+ startTransaction(): Promise<Result<Transaction>>;
196
+ }
197
+
188
198
  export declare type TransactionOptions = {
189
199
  usePhantomQuery: boolean;
190
200
  };
191
201
 
202
+ declare interface WithTransaction extends Queryable {
203
+ /**
204
+ * Starts new transaction.
205
+ * If `startTransaction` is not defined, `transactionContext` must be defined.
206
+ */
207
+ transactionContext?(): Promise<Result<TransactionContext>>;
208
+ }
209
+
210
+ declare interface WithTransactionDeprecated extends Queryable {
211
+ /**
212
+ * Starts new transaction.
213
+ * @deprecated Use `transactionContext` instead.
214
+ */
215
+ startTransaction?(): Promise<Result<Transaction>>;
216
+ }
217
+
192
218
  export { }
package/dist/index.js CHANGED
@@ -73,16 +73,23 @@ var ErrorRegistryInternal = class {
73
73
  };
74
74
  var bindAdapter = (adapter) => {
75
75
  const errorRegistry = new ErrorRegistryInternal();
76
- const startTransaction = wrapAsync(errorRegistry, adapter.startTransaction.bind(adapter));
76
+ if (adapter.transactionContext === void 0 && adapter.startTransaction === void 0) {
77
+ throw new Error(
78
+ "[prisma:driverAdapters] Either `adapter.transactionContext` or `adapter.startTransaction` must be defined."
79
+ );
80
+ }
81
+ const createTransactionContext = adapter.transactionContext === void 0 ? wrapAsync(errorRegistry, () => {
82
+ return Promise.resolve(ok(adapter));
83
+ }) : wrapAsync(errorRegistry, adapter.transactionContext.bind(adapter));
77
84
  const boundAdapter = {
78
85
  adapterName: adapter.adapterName,
79
86
  errorRegistry,
80
87
  queryRaw: wrapAsync(errorRegistry, adapter.queryRaw.bind(adapter)),
81
88
  executeRaw: wrapAsync(errorRegistry, adapter.executeRaw.bind(adapter)),
82
89
  provider: adapter.provider,
83
- startTransaction: async (...args) => {
84
- const result = await startTransaction(...args);
85
- return result.map((tx) => bindTransaction(errorRegistry, tx));
90
+ transactionContext: async (...args) => {
91
+ const ctx = await createTransactionContext(...args);
92
+ return ctx.map((tx) => bindTransactionContext(errorRegistry, tx));
86
93
  }
87
94
  };
88
95
  if (adapter.getConnectionInfo) {
@@ -90,6 +97,19 @@ var bindAdapter = (adapter) => {
90
97
  }
91
98
  return boundAdapter;
92
99
  };
100
+ var bindTransactionContext = (errorRegistry, ctx) => {
101
+ const startTransaction = wrapAsync(errorRegistry, ctx.startTransaction.bind(ctx));
102
+ return {
103
+ adapterName: ctx.adapterName,
104
+ provider: ctx.provider,
105
+ queryRaw: wrapAsync(errorRegistry, ctx.queryRaw.bind(ctx)),
106
+ executeRaw: wrapAsync(errorRegistry, ctx.executeRaw.bind(ctx)),
107
+ startTransaction: async (...args) => {
108
+ const result = await startTransaction(...args);
109
+ return result.map((tx) => bindTransaction(errorRegistry, tx));
110
+ }
111
+ };
112
+ };
93
113
  var bindTransaction = (errorRegistry, transaction) => {
94
114
  return {
95
115
  adapterName: transaction.adapterName,
package/dist/index.mjs CHANGED
@@ -43,16 +43,23 @@ var ErrorRegistryInternal = class {
43
43
  };
44
44
  var bindAdapter = (adapter) => {
45
45
  const errorRegistry = new ErrorRegistryInternal();
46
- const startTransaction = wrapAsync(errorRegistry, adapter.startTransaction.bind(adapter));
46
+ if (adapter.transactionContext === void 0 && adapter.startTransaction === void 0) {
47
+ throw new Error(
48
+ "[prisma:driverAdapters] Either `adapter.transactionContext` or `adapter.startTransaction` must be defined."
49
+ );
50
+ }
51
+ const createTransactionContext = adapter.transactionContext === void 0 ? wrapAsync(errorRegistry, () => {
52
+ return Promise.resolve(ok(adapter));
53
+ }) : wrapAsync(errorRegistry, adapter.transactionContext.bind(adapter));
47
54
  const boundAdapter = {
48
55
  adapterName: adapter.adapterName,
49
56
  errorRegistry,
50
57
  queryRaw: wrapAsync(errorRegistry, adapter.queryRaw.bind(adapter)),
51
58
  executeRaw: wrapAsync(errorRegistry, adapter.executeRaw.bind(adapter)),
52
59
  provider: adapter.provider,
53
- startTransaction: async (...args) => {
54
- const result = await startTransaction(...args);
55
- return result.map((tx) => bindTransaction(errorRegistry, tx));
60
+ transactionContext: async (...args) => {
61
+ const ctx = await createTransactionContext(...args);
62
+ return ctx.map((tx) => bindTransactionContext(errorRegistry, tx));
56
63
  }
57
64
  };
58
65
  if (adapter.getConnectionInfo) {
@@ -60,6 +67,19 @@ var bindAdapter = (adapter) => {
60
67
  }
61
68
  return boundAdapter;
62
69
  };
70
+ var bindTransactionContext = (errorRegistry, ctx) => {
71
+ const startTransaction = wrapAsync(errorRegistry, ctx.startTransaction.bind(ctx));
72
+ return {
73
+ adapterName: ctx.adapterName,
74
+ provider: ctx.provider,
75
+ queryRaw: wrapAsync(errorRegistry, ctx.queryRaw.bind(ctx)),
76
+ executeRaw: wrapAsync(errorRegistry, ctx.executeRaw.bind(ctx)),
77
+ startTransaction: async (...args) => {
78
+ const result = await startTransaction(...args);
79
+ return result.map((tx) => bindTransaction(errorRegistry, tx));
80
+ }
81
+ };
82
+ };
63
83
  var bindTransaction = (errorRegistry, transaction) => {
64
84
  return {
65
85
  adapterName: transaction.adapterName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/driver-adapter-utils",
3
- "version": "5.20.0-dev.2",
3
+ "version": "5.20.0-dev.21",
4
4
  "description": "Internal set of utilities and types for Prisma's driver adapters.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -31,7 +31,7 @@
31
31
  "license": "Apache-2.0",
32
32
  "sideEffects": false,
33
33
  "dependencies": {
34
- "@prisma/debug": "5.20.0-dev.2"
34
+ "@prisma/debug": "5.20.0-dev.21"
35
35
  },
36
36
  "scripts": {
37
37
  "dev": "DEV=true tsx helpers/build.ts",