@prisma/client-engine-runtime 6.9.0-dev.21 → 6.9.0-dev.22
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 +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.js +91 -38
- package/dist/index.mjs +89 -37
- package/dist/tracing.d.ts +10 -2
- package/dist/transactionManager/TransactionManager.d.ts +3 -1
- package/dist/utils.d.ts +5 -0
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Context } from '@opentelemetry/api';
|
|
2
2
|
import type { IsolationLevel } from '@prisma/driver-adapter-utils';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import { Span } from '@opentelemetry/api';
|
|
4
|
+
import { SpanOptions } from '@opentelemetry/api';
|
|
5
5
|
import { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
|
|
6
6
|
import { SqlQueryable } from '@prisma/driver-adapter-utils';
|
|
7
7
|
import { SqlResultSet } from '@prisma/driver-adapter-utils';
|
|
@@ -292,6 +292,12 @@ export declare type ResultNode = {
|
|
|
292
292
|
resultType: PrismaValueType;
|
|
293
293
|
};
|
|
294
294
|
|
|
295
|
+
/**
|
|
296
|
+
* `JSON.stringify` wrapper with custom replacer function that handles nested
|
|
297
|
+
* BigInt and Uint8Array values.
|
|
298
|
+
*/
|
|
299
|
+
export declare function safeJsonStringify(obj: unknown): string;
|
|
300
|
+
|
|
295
301
|
declare type SpanCallback<R> = (span?: Span, context?: Context) => R;
|
|
296
302
|
|
|
297
303
|
export declare interface TracingHelper {
|
|
@@ -309,10 +315,11 @@ export declare class TransactionManager {
|
|
|
309
315
|
private readonly driverAdapter;
|
|
310
316
|
private readonly transactionOptions;
|
|
311
317
|
private readonly tracingHelper;
|
|
312
|
-
constructor({ driverAdapter, transactionOptions, tracingHelper, }: {
|
|
318
|
+
constructor({ driverAdapter, transactionOptions, tracingHelper, onQuery, }: {
|
|
313
319
|
driverAdapter: SqlDriverAdapter;
|
|
314
320
|
transactionOptions: TransactionOptions;
|
|
315
321
|
tracingHelper: TracingHelper;
|
|
322
|
+
onQuery?: (event: QueryEvent) => void;
|
|
316
323
|
});
|
|
317
324
|
startTransaction(options?: TransactionOptions): Promise<TransactionInfo>;
|
|
318
325
|
commitTransaction(transactionId: string): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Context } from '@opentelemetry/api';
|
|
2
2
|
import type { IsolationLevel } from '@prisma/driver-adapter-utils';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import { Span } from '@opentelemetry/api';
|
|
4
|
+
import { SpanOptions } from '@opentelemetry/api';
|
|
5
5
|
import { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
|
|
6
6
|
import { SqlQueryable } from '@prisma/driver-adapter-utils';
|
|
7
7
|
import { SqlResultSet } from '@prisma/driver-adapter-utils';
|
|
@@ -292,6 +292,12 @@ export declare type ResultNode = {
|
|
|
292
292
|
resultType: PrismaValueType;
|
|
293
293
|
};
|
|
294
294
|
|
|
295
|
+
/**
|
|
296
|
+
* `JSON.stringify` wrapper with custom replacer function that handles nested
|
|
297
|
+
* BigInt and Uint8Array values.
|
|
298
|
+
*/
|
|
299
|
+
export declare function safeJsonStringify(obj: unknown): string;
|
|
300
|
+
|
|
295
301
|
declare type SpanCallback<R> = (span?: Span, context?: Context) => R;
|
|
296
302
|
|
|
297
303
|
export declare interface TracingHelper {
|
|
@@ -309,10 +315,11 @@ export declare class TransactionManager {
|
|
|
309
315
|
private readonly driverAdapter;
|
|
310
316
|
private readonly transactionOptions;
|
|
311
317
|
private readonly tracingHelper;
|
|
312
|
-
constructor({ driverAdapter, transactionOptions, tracingHelper, }: {
|
|
318
|
+
constructor({ driverAdapter, transactionOptions, tracingHelper, onQuery, }: {
|
|
313
319
|
driverAdapter: SqlDriverAdapter;
|
|
314
320
|
transactionOptions: TransactionOptions;
|
|
315
321
|
tracingHelper: TracingHelper;
|
|
322
|
+
onQuery?: (event: QueryEvent) => void;
|
|
316
323
|
});
|
|
317
324
|
startTransaction(options?: TransactionOptions): Promise<TransactionInfo>;
|
|
318
325
|
commitTransaction(transactionId: string): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -41,7 +41,8 @@ __export(index_exports, {
|
|
|
41
41
|
isPrismaValueBytes: () => isPrismaValueBytes,
|
|
42
42
|
isPrismaValueGenerator: () => isPrismaValueGenerator,
|
|
43
43
|
isPrismaValuePlaceholder: () => isPrismaValuePlaceholder,
|
|
44
|
-
noopTracingHelper: () => noopTracingHelper
|
|
44
|
+
noopTracingHelper: () => noopTracingHelper,
|
|
45
|
+
safeJsonStringify: () => safeJsonStringify
|
|
45
46
|
});
|
|
46
47
|
module.exports = __toCommonJS(index_exports);
|
|
47
48
|
|
|
@@ -75,6 +76,16 @@ function doKeysMatch(lhs, rhs) {
|
|
|
75
76
|
return isDeepStrictEqual(lhs[key], rhs[key]);
|
|
76
77
|
});
|
|
77
78
|
}
|
|
79
|
+
function safeJsonStringify(obj) {
|
|
80
|
+
return JSON.stringify(obj, (_key, val) => {
|
|
81
|
+
if (typeof val === "bigint") {
|
|
82
|
+
return val.toString();
|
|
83
|
+
} else if (val instanceof Uint8Array) {
|
|
84
|
+
return Buffer.from(val).toString("base64");
|
|
85
|
+
}
|
|
86
|
+
return val;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
78
89
|
|
|
79
90
|
// src/interpreter/DataMapper.ts
|
|
80
91
|
var DataMapperError = class extends Error {
|
|
@@ -184,10 +195,8 @@ function mapValue(value, resultType) {
|
|
|
184
195
|
}
|
|
185
196
|
}
|
|
186
197
|
|
|
187
|
-
// src/interpreter/QueryInterpreter.ts
|
|
188
|
-
var import_api = require("@opentelemetry/api");
|
|
189
|
-
|
|
190
198
|
// src/tracing.ts
|
|
199
|
+
var import_api = require("@opentelemetry/api");
|
|
191
200
|
var noopTracingHelper = {
|
|
192
201
|
runInChildSpan(_, callback) {
|
|
193
202
|
return callback();
|
|
@@ -205,6 +214,37 @@ function providerToOtelSystem(provider) {
|
|
|
205
214
|
assertNever(provider, `Unknown provider: ${provider}`);
|
|
206
215
|
}
|
|
207
216
|
}
|
|
217
|
+
async function withQuerySpanAndEvent({
|
|
218
|
+
query,
|
|
219
|
+
queryable,
|
|
220
|
+
tracingHelper,
|
|
221
|
+
onQuery,
|
|
222
|
+
execute
|
|
223
|
+
}) {
|
|
224
|
+
return await tracingHelper.runInChildSpan(
|
|
225
|
+
{
|
|
226
|
+
name: "db_query",
|
|
227
|
+
kind: import_api.SpanKind.CLIENT,
|
|
228
|
+
attributes: {
|
|
229
|
+
"db.query.text": query.sql,
|
|
230
|
+
"db.system.name": providerToOtelSystem(queryable.provider)
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
async () => {
|
|
234
|
+
const timestamp = /* @__PURE__ */ new Date();
|
|
235
|
+
const startInstant = performance.now();
|
|
236
|
+
const result = await execute();
|
|
237
|
+
const endInstant = performance.now();
|
|
238
|
+
onQuery?.({
|
|
239
|
+
timestamp,
|
|
240
|
+
duration: endInstant - startInstant,
|
|
241
|
+
query: query.sql,
|
|
242
|
+
params: query.args
|
|
243
|
+
});
|
|
244
|
+
return result;
|
|
245
|
+
}
|
|
246
|
+
);
|
|
247
|
+
}
|
|
208
248
|
|
|
209
249
|
// src/UserFacingError.ts
|
|
210
250
|
var import_driver_adapter_utils = require("@prisma/driver-adapter-utils");
|
|
@@ -844,13 +884,13 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
844
884
|
}
|
|
845
885
|
case "execute": {
|
|
846
886
|
const query = renderQuery(node.args, scope, generators);
|
|
847
|
-
return this.#
|
|
887
|
+
return this.#withQuerySpanAndEvent(query, queryable, async () => {
|
|
848
888
|
return await queryable.executeRaw(query);
|
|
849
889
|
});
|
|
850
890
|
}
|
|
851
891
|
case "query": {
|
|
852
892
|
const query = renderQuery(node.args, scope, generators);
|
|
853
|
-
return this.#
|
|
893
|
+
return this.#withQuerySpanAndEvent(query, queryable, async () => {
|
|
854
894
|
if (node.args.type === "rawSql") {
|
|
855
895
|
return this.#rawSerializer(await queryable.queryRaw(query));
|
|
856
896
|
} else {
|
|
@@ -980,30 +1020,14 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
980
1020
|
assertNever(node, `Unexpected node type: ${node.type}`);
|
|
981
1021
|
}
|
|
982
1022
|
}
|
|
983
|
-
#
|
|
984
|
-
return
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
}
|
|
992
|
-
},
|
|
993
|
-
async () => {
|
|
994
|
-
const timestamp = /* @__PURE__ */ new Date();
|
|
995
|
-
const startInstant = performance.now();
|
|
996
|
-
const result = await execute();
|
|
997
|
-
const endInstant = performance.now();
|
|
998
|
-
this.#onQuery?.({
|
|
999
|
-
timestamp,
|
|
1000
|
-
duration: endInstant - startInstant,
|
|
1001
|
-
query: query.sql,
|
|
1002
|
-
params: query.args
|
|
1003
|
-
});
|
|
1004
|
-
return result;
|
|
1005
|
-
}
|
|
1006
|
-
);
|
|
1023
|
+
#withQuerySpanAndEvent(query, queryable, execute) {
|
|
1024
|
+
return withQuerySpanAndEvent({
|
|
1025
|
+
query,
|
|
1026
|
+
queryable,
|
|
1027
|
+
execute,
|
|
1028
|
+
tracingHelper: this.#tracingHelper,
|
|
1029
|
+
onQuery: this.#onQuery
|
|
1030
|
+
});
|
|
1007
1031
|
}
|
|
1008
1032
|
};
|
|
1009
1033
|
function isEmpty(value) {
|
|
@@ -1146,6 +1170,16 @@ var MAX_CLOSED_TRANSACTIONS = 100;
|
|
|
1146
1170
|
var debug = (0, import_debug.Debug)("prisma:client:transactionManager");
|
|
1147
1171
|
var COMMIT_QUERY = () => ({ sql: "COMMIT", args: [], argTypes: [] });
|
|
1148
1172
|
var ROLLBACK_QUERY = () => ({ sql: "ROLLBACK", args: [], argTypes: [] });
|
|
1173
|
+
var PHANTOM_COMMIT_QUERY = () => ({
|
|
1174
|
+
sql: '-- Implicit "COMMIT" query via underlying driver',
|
|
1175
|
+
args: [],
|
|
1176
|
+
argTypes: []
|
|
1177
|
+
});
|
|
1178
|
+
var PHANTOM_ROLLBACK_QUERY = () => ({
|
|
1179
|
+
sql: '-- Implicit "ROLLBACK" query via underlying driver',
|
|
1180
|
+
args: [],
|
|
1181
|
+
argTypes: []
|
|
1182
|
+
});
|
|
1149
1183
|
var TransactionManager = class {
|
|
1150
1184
|
// The map of active transactions.
|
|
1151
1185
|
transactions = /* @__PURE__ */ new Map();
|
|
@@ -1155,14 +1189,17 @@ var TransactionManager = class {
|
|
|
1155
1189
|
driverAdapter;
|
|
1156
1190
|
transactionOptions;
|
|
1157
1191
|
tracingHelper;
|
|
1192
|
+
#onQuery;
|
|
1158
1193
|
constructor({
|
|
1159
1194
|
driverAdapter,
|
|
1160
1195
|
transactionOptions,
|
|
1161
|
-
tracingHelper
|
|
1196
|
+
tracingHelper,
|
|
1197
|
+
onQuery
|
|
1162
1198
|
}) {
|
|
1163
1199
|
this.driverAdapter = driverAdapter;
|
|
1164
1200
|
this.transactionOptions = transactionOptions;
|
|
1165
1201
|
this.tracingHelper = tracingHelper;
|
|
1202
|
+
this.#onQuery = onQuery;
|
|
1166
1203
|
}
|
|
1167
1204
|
async startTransaction(options) {
|
|
1168
1205
|
return await this.tracingHelper.runInChildSpan("start_transaction", () => this.#startTransactionImpl(options));
|
|
@@ -1266,14 +1303,20 @@ var TransactionManager = class {
|
|
|
1266
1303
|
debug("Closing transaction.", { transactionId: tx.id, status });
|
|
1267
1304
|
tx.status = status;
|
|
1268
1305
|
if (tx.transaction && status === "committed") {
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1306
|
+
if (tx.transaction.options.usePhantomQuery) {
|
|
1307
|
+
await this.#withQuerySpanAndEvent(PHANTOM_COMMIT_QUERY(), tx.transaction, () => tx.transaction.commit());
|
|
1308
|
+
} else {
|
|
1309
|
+
await tx.transaction.commit();
|
|
1310
|
+
const query = COMMIT_QUERY();
|
|
1311
|
+
await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
|
|
1272
1312
|
}
|
|
1273
1313
|
} else if (tx.transaction) {
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1314
|
+
if (tx.transaction.options.usePhantomQuery) {
|
|
1315
|
+
await this.#withQuerySpanAndEvent(PHANTOM_ROLLBACK_QUERY(), tx.transaction, () => tx.transaction.rollback());
|
|
1316
|
+
} else {
|
|
1317
|
+
await tx.transaction.rollback();
|
|
1318
|
+
const query = ROLLBACK_QUERY();
|
|
1319
|
+
await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
|
|
1277
1320
|
}
|
|
1278
1321
|
}
|
|
1279
1322
|
clearTimeout(tx.timer);
|
|
@@ -1294,6 +1337,15 @@ var TransactionManager = class {
|
|
|
1294
1337
|
maxWait: options.maxWait
|
|
1295
1338
|
};
|
|
1296
1339
|
}
|
|
1340
|
+
#withQuerySpanAndEvent(query, queryable, execute) {
|
|
1341
|
+
return withQuerySpanAndEvent({
|
|
1342
|
+
query,
|
|
1343
|
+
queryable,
|
|
1344
|
+
execute,
|
|
1345
|
+
tracingHelper: this.tracingHelper,
|
|
1346
|
+
onQuery: this.#onQuery
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1297
1349
|
};
|
|
1298
1350
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1299
1351
|
0 && (module.exports = {
|
|
@@ -1308,5 +1360,6 @@ var TransactionManager = class {
|
|
|
1308
1360
|
isPrismaValueBytes,
|
|
1309
1361
|
isPrismaValueGenerator,
|
|
1310
1362
|
isPrismaValuePlaceholder,
|
|
1311
|
-
noopTracingHelper
|
|
1363
|
+
noopTracingHelper,
|
|
1364
|
+
safeJsonStringify
|
|
1312
1365
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -28,6 +28,16 @@ function doKeysMatch(lhs, rhs) {
|
|
|
28
28
|
return isDeepStrictEqual(lhs[key], rhs[key]);
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
+
function safeJsonStringify(obj) {
|
|
32
|
+
return JSON.stringify(obj, (_key, val) => {
|
|
33
|
+
if (typeof val === "bigint") {
|
|
34
|
+
return val.toString();
|
|
35
|
+
} else if (val instanceof Uint8Array) {
|
|
36
|
+
return Buffer.from(val).toString("base64");
|
|
37
|
+
}
|
|
38
|
+
return val;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
31
41
|
|
|
32
42
|
// src/interpreter/DataMapper.ts
|
|
33
43
|
var DataMapperError = class extends Error {
|
|
@@ -137,10 +147,8 @@ function mapValue(value, resultType) {
|
|
|
137
147
|
}
|
|
138
148
|
}
|
|
139
149
|
|
|
140
|
-
// src/interpreter/QueryInterpreter.ts
|
|
141
|
-
import { SpanKind } from "@opentelemetry/api";
|
|
142
|
-
|
|
143
150
|
// src/tracing.ts
|
|
151
|
+
import { SpanKind } from "@opentelemetry/api";
|
|
144
152
|
var noopTracingHelper = {
|
|
145
153
|
runInChildSpan(_, callback) {
|
|
146
154
|
return callback();
|
|
@@ -158,6 +166,37 @@ function providerToOtelSystem(provider) {
|
|
|
158
166
|
assertNever(provider, `Unknown provider: ${provider}`);
|
|
159
167
|
}
|
|
160
168
|
}
|
|
169
|
+
async function withQuerySpanAndEvent({
|
|
170
|
+
query,
|
|
171
|
+
queryable,
|
|
172
|
+
tracingHelper,
|
|
173
|
+
onQuery,
|
|
174
|
+
execute
|
|
175
|
+
}) {
|
|
176
|
+
return await tracingHelper.runInChildSpan(
|
|
177
|
+
{
|
|
178
|
+
name: "db_query",
|
|
179
|
+
kind: SpanKind.CLIENT,
|
|
180
|
+
attributes: {
|
|
181
|
+
"db.query.text": query.sql,
|
|
182
|
+
"db.system.name": providerToOtelSystem(queryable.provider)
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
async () => {
|
|
186
|
+
const timestamp = /* @__PURE__ */ new Date();
|
|
187
|
+
const startInstant = performance.now();
|
|
188
|
+
const result = await execute();
|
|
189
|
+
const endInstant = performance.now();
|
|
190
|
+
onQuery?.({
|
|
191
|
+
timestamp,
|
|
192
|
+
duration: endInstant - startInstant,
|
|
193
|
+
query: query.sql,
|
|
194
|
+
params: query.args
|
|
195
|
+
});
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
);
|
|
199
|
+
}
|
|
161
200
|
|
|
162
201
|
// src/UserFacingError.ts
|
|
163
202
|
import { isDriverAdapterError } from "@prisma/driver-adapter-utils";
|
|
@@ -797,13 +836,13 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
797
836
|
}
|
|
798
837
|
case "execute": {
|
|
799
838
|
const query = renderQuery(node.args, scope, generators);
|
|
800
|
-
return this.#
|
|
839
|
+
return this.#withQuerySpanAndEvent(query, queryable, async () => {
|
|
801
840
|
return await queryable.executeRaw(query);
|
|
802
841
|
});
|
|
803
842
|
}
|
|
804
843
|
case "query": {
|
|
805
844
|
const query = renderQuery(node.args, scope, generators);
|
|
806
|
-
return this.#
|
|
845
|
+
return this.#withQuerySpanAndEvent(query, queryable, async () => {
|
|
807
846
|
if (node.args.type === "rawSql") {
|
|
808
847
|
return this.#rawSerializer(await queryable.queryRaw(query));
|
|
809
848
|
} else {
|
|
@@ -933,30 +972,14 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
933
972
|
assertNever(node, `Unexpected node type: ${node.type}`);
|
|
934
973
|
}
|
|
935
974
|
}
|
|
936
|
-
#
|
|
937
|
-
return
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
}
|
|
945
|
-
},
|
|
946
|
-
async () => {
|
|
947
|
-
const timestamp = /* @__PURE__ */ new Date();
|
|
948
|
-
const startInstant = performance.now();
|
|
949
|
-
const result = await execute();
|
|
950
|
-
const endInstant = performance.now();
|
|
951
|
-
this.#onQuery?.({
|
|
952
|
-
timestamp,
|
|
953
|
-
duration: endInstant - startInstant,
|
|
954
|
-
query: query.sql,
|
|
955
|
-
params: query.args
|
|
956
|
-
});
|
|
957
|
-
return result;
|
|
958
|
-
}
|
|
959
|
-
);
|
|
975
|
+
#withQuerySpanAndEvent(query, queryable, execute) {
|
|
976
|
+
return withQuerySpanAndEvent({
|
|
977
|
+
query,
|
|
978
|
+
queryable,
|
|
979
|
+
execute,
|
|
980
|
+
tracingHelper: this.#tracingHelper,
|
|
981
|
+
onQuery: this.#onQuery
|
|
982
|
+
});
|
|
960
983
|
}
|
|
961
984
|
};
|
|
962
985
|
function isEmpty(value) {
|
|
@@ -1099,6 +1122,16 @@ var MAX_CLOSED_TRANSACTIONS = 100;
|
|
|
1099
1122
|
var debug = Debug("prisma:client:transactionManager");
|
|
1100
1123
|
var COMMIT_QUERY = () => ({ sql: "COMMIT", args: [], argTypes: [] });
|
|
1101
1124
|
var ROLLBACK_QUERY = () => ({ sql: "ROLLBACK", args: [], argTypes: [] });
|
|
1125
|
+
var PHANTOM_COMMIT_QUERY = () => ({
|
|
1126
|
+
sql: '-- Implicit "COMMIT" query via underlying driver',
|
|
1127
|
+
args: [],
|
|
1128
|
+
argTypes: []
|
|
1129
|
+
});
|
|
1130
|
+
var PHANTOM_ROLLBACK_QUERY = () => ({
|
|
1131
|
+
sql: '-- Implicit "ROLLBACK" query via underlying driver',
|
|
1132
|
+
args: [],
|
|
1133
|
+
argTypes: []
|
|
1134
|
+
});
|
|
1102
1135
|
var TransactionManager = class {
|
|
1103
1136
|
// The map of active transactions.
|
|
1104
1137
|
transactions = /* @__PURE__ */ new Map();
|
|
@@ -1108,14 +1141,17 @@ var TransactionManager = class {
|
|
|
1108
1141
|
driverAdapter;
|
|
1109
1142
|
transactionOptions;
|
|
1110
1143
|
tracingHelper;
|
|
1144
|
+
#onQuery;
|
|
1111
1145
|
constructor({
|
|
1112
1146
|
driverAdapter,
|
|
1113
1147
|
transactionOptions,
|
|
1114
|
-
tracingHelper
|
|
1148
|
+
tracingHelper,
|
|
1149
|
+
onQuery
|
|
1115
1150
|
}) {
|
|
1116
1151
|
this.driverAdapter = driverAdapter;
|
|
1117
1152
|
this.transactionOptions = transactionOptions;
|
|
1118
1153
|
this.tracingHelper = tracingHelper;
|
|
1154
|
+
this.#onQuery = onQuery;
|
|
1119
1155
|
}
|
|
1120
1156
|
async startTransaction(options) {
|
|
1121
1157
|
return await this.tracingHelper.runInChildSpan("start_transaction", () => this.#startTransactionImpl(options));
|
|
@@ -1219,14 +1255,20 @@ var TransactionManager = class {
|
|
|
1219
1255
|
debug("Closing transaction.", { transactionId: tx.id, status });
|
|
1220
1256
|
tx.status = status;
|
|
1221
1257
|
if (tx.transaction && status === "committed") {
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1258
|
+
if (tx.transaction.options.usePhantomQuery) {
|
|
1259
|
+
await this.#withQuerySpanAndEvent(PHANTOM_COMMIT_QUERY(), tx.transaction, () => tx.transaction.commit());
|
|
1260
|
+
} else {
|
|
1261
|
+
await tx.transaction.commit();
|
|
1262
|
+
const query = COMMIT_QUERY();
|
|
1263
|
+
await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
|
|
1225
1264
|
}
|
|
1226
1265
|
} else if (tx.transaction) {
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1266
|
+
if (tx.transaction.options.usePhantomQuery) {
|
|
1267
|
+
await this.#withQuerySpanAndEvent(PHANTOM_ROLLBACK_QUERY(), tx.transaction, () => tx.transaction.rollback());
|
|
1268
|
+
} else {
|
|
1269
|
+
await tx.transaction.rollback();
|
|
1270
|
+
const query = ROLLBACK_QUERY();
|
|
1271
|
+
await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
|
|
1230
1272
|
}
|
|
1231
1273
|
}
|
|
1232
1274
|
clearTimeout(tx.timer);
|
|
@@ -1247,6 +1289,15 @@ var TransactionManager = class {
|
|
|
1247
1289
|
maxWait: options.maxWait
|
|
1248
1290
|
};
|
|
1249
1291
|
}
|
|
1292
|
+
#withQuerySpanAndEvent(query, queryable, execute) {
|
|
1293
|
+
return withQuerySpanAndEvent({
|
|
1294
|
+
query,
|
|
1295
|
+
queryable,
|
|
1296
|
+
execute,
|
|
1297
|
+
tracingHelper: this.tracingHelper,
|
|
1298
|
+
onQuery: this.#onQuery
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
1250
1301
|
};
|
|
1251
1302
|
export {
|
|
1252
1303
|
DataMapperError,
|
|
@@ -1260,5 +1311,6 @@ export {
|
|
|
1260
1311
|
isPrismaValueBytes,
|
|
1261
1312
|
isPrismaValueGenerator,
|
|
1262
1313
|
isPrismaValuePlaceholder,
|
|
1263
|
-
noopTracingHelper
|
|
1314
|
+
noopTracingHelper,
|
|
1315
|
+
safeJsonStringify
|
|
1264
1316
|
};
|
package/dist/tracing.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { Provider } from '@prisma/driver-adapter-utils';
|
|
1
|
+
import { type Context, type Span, type SpanOptions } from '@opentelemetry/api';
|
|
2
|
+
import type { Provider, SqlQuery, SqlQueryable } from '@prisma/driver-adapter-utils';
|
|
3
|
+
import { QueryEvent } from './events';
|
|
3
4
|
export type SpanCallback<R> = (span?: Span, context?: Context) => R;
|
|
4
5
|
export type ExtendedSpanOptions = SpanOptions & {
|
|
5
6
|
name: string;
|
|
@@ -9,3 +10,10 @@ export interface TracingHelper {
|
|
|
9
10
|
}
|
|
10
11
|
export declare const noopTracingHelper: TracingHelper;
|
|
11
12
|
export declare function providerToOtelSystem(provider: Provider): string;
|
|
13
|
+
export declare function withQuerySpanAndEvent<T>({ query, queryable, tracingHelper, onQuery, execute, }: {
|
|
14
|
+
query: SqlQuery;
|
|
15
|
+
queryable: SqlQueryable;
|
|
16
|
+
tracingHelper: TracingHelper;
|
|
17
|
+
onQuery?: (event: QueryEvent) => void;
|
|
18
|
+
execute: () => Promise<T>;
|
|
19
|
+
}): Promise<T>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SqlDriverAdapter, Transaction } from '@prisma/driver-adapter-utils';
|
|
2
|
+
import { QueryEvent } from '../events';
|
|
2
3
|
import { TracingHelper } from '../tracing';
|
|
3
4
|
import { Options, TransactionInfo } from './Transaction';
|
|
4
5
|
export declare class TransactionManager {
|
|
@@ -8,10 +9,11 @@ export declare class TransactionManager {
|
|
|
8
9
|
private readonly driverAdapter;
|
|
9
10
|
private readonly transactionOptions;
|
|
10
11
|
private readonly tracingHelper;
|
|
11
|
-
constructor({ driverAdapter, transactionOptions, tracingHelper, }: {
|
|
12
|
+
constructor({ driverAdapter, transactionOptions, tracingHelper, onQuery, }: {
|
|
12
13
|
driverAdapter: SqlDriverAdapter;
|
|
13
14
|
transactionOptions: Options;
|
|
14
15
|
tracingHelper: TracingHelper;
|
|
16
|
+
onQuery?: (event: QueryEvent) => void;
|
|
15
17
|
});
|
|
16
18
|
startTransaction(options?: Options): Promise<TransactionInfo>;
|
|
17
19
|
commitTransaction(transactionId: string): Promise<void>;
|
package/dist/utils.d.ts
CHANGED
|
@@ -9,3 +9,8 @@ export declare function isDeepStrictEqual(a: unknown, b: unknown): boolean;
|
|
|
9
9
|
* converts arguments to the types used by driver adapters if necessary.
|
|
10
10
|
*/
|
|
11
11
|
export declare function doKeysMatch(lhs: {}, rhs: {}): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* `JSON.stringify` wrapper with custom replacer function that handles nested
|
|
14
|
+
* BigInt and Uint8Array values.
|
|
15
|
+
*/
|
|
16
|
+
export declare function safeJsonStringify(obj: unknown): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/client-engine-runtime",
|
|
3
|
-
"version": "6.9.0-dev.
|
|
3
|
+
"version": "6.9.0-dev.22",
|
|
4
4
|
"description": "This package is intended for Prisma's internal use",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"nanoid": "5.1.5",
|
|
32
32
|
"ulid": "3.0.0",
|
|
33
33
|
"uuid": "11.1.0",
|
|
34
|
-
"@prisma/
|
|
35
|
-
"@prisma/
|
|
34
|
+
"@prisma/driver-adapter-utils": "6.9.0-dev.22",
|
|
35
|
+
"@prisma/debug": "6.9.0-dev.22"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/jest": "29.5.14",
|