@prisma/client-engine-runtime 7.3.0-integration-prisma6-fix-cloudflare-engine.2 → 7.3.0-integration-engines-7-3-0-10-fix-fix-mapped-enum-issue-0b7e6564db7dc3dac7f9312aa84e9ed81d805521.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.
- package/dist/index.d.mts +25 -3
- package/dist/index.d.ts +25 -3
- package/dist/index.js +121 -44
- package/dist/index.mjs +113 -37
- package/dist/interpreter/data-mapper.d.ts +5 -1
- package/dist/interpreter/query-interpreter.d.ts +8 -1
- package/dist/json-protocol.d.ts +1 -1
- package/dist/sql-commenter.d.ts +31 -0
- package/dist/sql-commenter.test.d.ts +1 -0
- package/dist/web-platform.d.ts +9 -0
- package/package.json +10 -5
package/dist/index.d.mts
CHANGED
|
@@ -2,15 +2,27 @@ import { ArgType } from '@prisma/driver-adapter-utils';
|
|
|
2
2
|
import { Arity } from '@prisma/driver-adapter-utils';
|
|
3
3
|
import { ConnectionInfo } from '@prisma/driver-adapter-utils';
|
|
4
4
|
import { Context } from '@opentelemetry/api';
|
|
5
|
-
import { Decimal } from '
|
|
5
|
+
import { Decimal } from '@prisma/client-runtime-utils';
|
|
6
6
|
import type { IsolationLevel } from '@prisma/driver-adapter-utils';
|
|
7
7
|
import { Span } from '@opentelemetry/api';
|
|
8
8
|
import { SpanOptions } from '@opentelemetry/api';
|
|
9
|
+
import type { SqlCommenterContext } from '@prisma/sqlcommenter';
|
|
10
|
+
import type { SqlCommenterPlugin } from '@prisma/sqlcommenter';
|
|
11
|
+
import type { SqlCommenterQueryInfo } from '@prisma/sqlcommenter';
|
|
9
12
|
import { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
|
|
10
13
|
import { SqlQueryable } from '@prisma/driver-adapter-utils';
|
|
11
14
|
import { SqlResultSet } from '@prisma/driver-adapter-utils';
|
|
12
15
|
import { Transaction } from '@prisma/driver-adapter-utils';
|
|
13
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Applies SQL commenter plugins and returns the merged key-value pairs.
|
|
19
|
+
* Keys with undefined values are filtered out.
|
|
20
|
+
*
|
|
21
|
+
* Each plugin receives a deep clone of the context to prevent mutations
|
|
22
|
+
* that could affect other plugins.
|
|
23
|
+
*/
|
|
24
|
+
export declare function applySqlCommenters(plugins: SqlCommenterPlugin[], context: SqlCommenterContext): Record<string, string>;
|
|
25
|
+
|
|
14
26
|
export declare type BatchResponse = MultiBatchResponse | CompactedBatchResponse;
|
|
15
27
|
|
|
16
28
|
export declare type BigIntTaggedValue = {
|
|
@@ -38,8 +50,11 @@ export declare type CompactedBatchResponse = {
|
|
|
38
50
|
*/
|
|
39
51
|
export declare function convertCompactedRows(rows: {}[], compiledBatch: CompactedBatchResponse): unknown[];
|
|
40
52
|
|
|
41
|
-
export declare class DataMapperError extends
|
|
53
|
+
export declare class DataMapperError extends UserFacingError {
|
|
42
54
|
name: string;
|
|
55
|
+
constructor(message: string, options?: {
|
|
56
|
+
cause?: unknown;
|
|
57
|
+
});
|
|
43
58
|
}
|
|
44
59
|
|
|
45
60
|
export declare type DataRule = {
|
|
@@ -234,7 +249,7 @@ export declare type QueryEvent = {
|
|
|
234
249
|
|
|
235
250
|
export declare class QueryInterpreter {
|
|
236
251
|
#private;
|
|
237
|
-
constructor({ transactionManager, placeholderValues, onQuery, tracingHelper, serializer, rawSerializer, provider, connectionInfo, }: QueryInterpreterOptions);
|
|
252
|
+
constructor({ transactionManager, placeholderValues, onQuery, tracingHelper, serializer, rawSerializer, provider, connectionInfo, sqlCommenter, }: QueryInterpreterOptions);
|
|
238
253
|
static forSql(options: {
|
|
239
254
|
transactionManager: QueryInterpreterTransactionManager;
|
|
240
255
|
placeholderValues: Record<string, unknown>;
|
|
@@ -242,6 +257,7 @@ export declare class QueryInterpreter {
|
|
|
242
257
|
tracingHelper: TracingHelper;
|
|
243
258
|
provider?: SchemaProvider;
|
|
244
259
|
connectionInfo?: ConnectionInfo;
|
|
260
|
+
sqlCommenter?: QueryInterpreterSqlCommenter;
|
|
245
261
|
}): QueryInterpreter;
|
|
246
262
|
run(queryPlan: QueryPlanNode, queryable: SqlQueryable): Promise<unknown>;
|
|
247
263
|
private interpretNode;
|
|
@@ -256,6 +272,12 @@ export declare type QueryInterpreterOptions = {
|
|
|
256
272
|
rawSerializer?: (results: SqlResultSet) => Value;
|
|
257
273
|
provider?: SchemaProvider;
|
|
258
274
|
connectionInfo?: ConnectionInfo;
|
|
275
|
+
sqlCommenter?: QueryInterpreterSqlCommenter;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
export declare type QueryInterpreterSqlCommenter = {
|
|
279
|
+
plugins: SqlCommenterPlugin[];
|
|
280
|
+
queryInfo: SqlCommenterQueryInfo;
|
|
259
281
|
};
|
|
260
282
|
|
|
261
283
|
export declare type QueryInterpreterTransactionManager = {
|
package/dist/index.d.ts
CHANGED
|
@@ -2,15 +2,27 @@ import { ArgType } from '@prisma/driver-adapter-utils';
|
|
|
2
2
|
import { Arity } from '@prisma/driver-adapter-utils';
|
|
3
3
|
import { ConnectionInfo } from '@prisma/driver-adapter-utils';
|
|
4
4
|
import { Context } from '@opentelemetry/api';
|
|
5
|
-
import { Decimal } from '
|
|
5
|
+
import { Decimal } from '@prisma/client-runtime-utils';
|
|
6
6
|
import type { IsolationLevel } from '@prisma/driver-adapter-utils';
|
|
7
7
|
import { Span } from '@opentelemetry/api';
|
|
8
8
|
import { SpanOptions } from '@opentelemetry/api';
|
|
9
|
+
import type { SqlCommenterContext } from '@prisma/sqlcommenter';
|
|
10
|
+
import type { SqlCommenterPlugin } from '@prisma/sqlcommenter';
|
|
11
|
+
import type { SqlCommenterQueryInfo } from '@prisma/sqlcommenter';
|
|
9
12
|
import { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
|
|
10
13
|
import { SqlQueryable } from '@prisma/driver-adapter-utils';
|
|
11
14
|
import { SqlResultSet } from '@prisma/driver-adapter-utils';
|
|
12
15
|
import { Transaction } from '@prisma/driver-adapter-utils';
|
|
13
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Applies SQL commenter plugins and returns the merged key-value pairs.
|
|
19
|
+
* Keys with undefined values are filtered out.
|
|
20
|
+
*
|
|
21
|
+
* Each plugin receives a deep clone of the context to prevent mutations
|
|
22
|
+
* that could affect other plugins.
|
|
23
|
+
*/
|
|
24
|
+
export declare function applySqlCommenters(plugins: SqlCommenterPlugin[], context: SqlCommenterContext): Record<string, string>;
|
|
25
|
+
|
|
14
26
|
export declare type BatchResponse = MultiBatchResponse | CompactedBatchResponse;
|
|
15
27
|
|
|
16
28
|
export declare type BigIntTaggedValue = {
|
|
@@ -38,8 +50,11 @@ export declare type CompactedBatchResponse = {
|
|
|
38
50
|
*/
|
|
39
51
|
export declare function convertCompactedRows(rows: {}[], compiledBatch: CompactedBatchResponse): unknown[];
|
|
40
52
|
|
|
41
|
-
export declare class DataMapperError extends
|
|
53
|
+
export declare class DataMapperError extends UserFacingError {
|
|
42
54
|
name: string;
|
|
55
|
+
constructor(message: string, options?: {
|
|
56
|
+
cause?: unknown;
|
|
57
|
+
});
|
|
43
58
|
}
|
|
44
59
|
|
|
45
60
|
export declare type DataRule = {
|
|
@@ -234,7 +249,7 @@ export declare type QueryEvent = {
|
|
|
234
249
|
|
|
235
250
|
export declare class QueryInterpreter {
|
|
236
251
|
#private;
|
|
237
|
-
constructor({ transactionManager, placeholderValues, onQuery, tracingHelper, serializer, rawSerializer, provider, connectionInfo, }: QueryInterpreterOptions);
|
|
252
|
+
constructor({ transactionManager, placeholderValues, onQuery, tracingHelper, serializer, rawSerializer, provider, connectionInfo, sqlCommenter, }: QueryInterpreterOptions);
|
|
238
253
|
static forSql(options: {
|
|
239
254
|
transactionManager: QueryInterpreterTransactionManager;
|
|
240
255
|
placeholderValues: Record<string, unknown>;
|
|
@@ -242,6 +257,7 @@ export declare class QueryInterpreter {
|
|
|
242
257
|
tracingHelper: TracingHelper;
|
|
243
258
|
provider?: SchemaProvider;
|
|
244
259
|
connectionInfo?: ConnectionInfo;
|
|
260
|
+
sqlCommenter?: QueryInterpreterSqlCommenter;
|
|
245
261
|
}): QueryInterpreter;
|
|
246
262
|
run(queryPlan: QueryPlanNode, queryable: SqlQueryable): Promise<unknown>;
|
|
247
263
|
private interpretNode;
|
|
@@ -256,6 +272,12 @@ export declare type QueryInterpreterOptions = {
|
|
|
256
272
|
rawSerializer?: (results: SqlResultSet) => Value;
|
|
257
273
|
provider?: SchemaProvider;
|
|
258
274
|
connectionInfo?: ConnectionInfo;
|
|
275
|
+
sqlCommenter?: QueryInterpreterSqlCommenter;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
export declare type QueryInterpreterSqlCommenter = {
|
|
279
|
+
plugins: SqlCommenterPlugin[];
|
|
280
|
+
queryInfo: SqlCommenterQueryInfo;
|
|
259
281
|
};
|
|
260
282
|
|
|
261
283
|
export declare type QueryInterpreterTransactionManager = {
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,7 @@ __export(index_exports, {
|
|
|
35
35
|
TransactionManager: () => TransactionManager,
|
|
36
36
|
TransactionManagerError: () => TransactionManagerError,
|
|
37
37
|
UserFacingError: () => UserFacingError,
|
|
38
|
+
applySqlCommenters: () => applySqlCommenters,
|
|
38
39
|
convertCompactedRows: () => convertCompactedRows,
|
|
39
40
|
deserializeJsonResponse: () => deserializeJsonResponse,
|
|
40
41
|
doKeysMatch: () => doKeysMatch,
|
|
@@ -49,10 +50,10 @@ __export(index_exports, {
|
|
|
49
50
|
module.exports = __toCommonJS(index_exports);
|
|
50
51
|
|
|
51
52
|
// src/json-protocol.ts
|
|
52
|
-
var
|
|
53
|
+
var import_client_runtime_utils2 = require("@prisma/client-runtime-utils");
|
|
53
54
|
|
|
54
55
|
// src/utils.ts
|
|
55
|
-
var
|
|
56
|
+
var import_client_runtime_utils = require("@prisma/client-runtime-utils");
|
|
56
57
|
function assertNever(_, message) {
|
|
57
58
|
throw new Error(message);
|
|
58
59
|
}
|
|
@@ -67,7 +68,7 @@ function doKeysMatch(lhs, rhs) {
|
|
|
67
68
|
if (typeof lhs[key] === typeof rhs[key] && typeof lhs[key] !== "object") {
|
|
68
69
|
return lhs[key] === rhs[key];
|
|
69
70
|
}
|
|
70
|
-
if (
|
|
71
|
+
if (import_client_runtime_utils.Decimal.isDecimal(lhs[key]) || import_client_runtime_utils.Decimal.isDecimal(rhs[key])) {
|
|
71
72
|
const lhsDecimal = asDecimal(lhs[key]);
|
|
72
73
|
const rhsDecimal = asDecimal(rhs[key]);
|
|
73
74
|
return lhsDecimal && rhsDecimal && lhsDecimal.equals(rhsDecimal);
|
|
@@ -86,10 +87,10 @@ function doKeysMatch(lhs, rhs) {
|
|
|
86
87
|
});
|
|
87
88
|
}
|
|
88
89
|
function asDecimal(value) {
|
|
89
|
-
if (
|
|
90
|
+
if (import_client_runtime_utils.Decimal.isDecimal(value)) {
|
|
90
91
|
return value;
|
|
91
92
|
} else if (typeof value === "number" || typeof value === "string") {
|
|
92
|
-
return new
|
|
93
|
+
return new import_client_runtime_utils.Decimal(value);
|
|
93
94
|
} else {
|
|
94
95
|
return;
|
|
95
96
|
}
|
|
@@ -178,7 +179,7 @@ function normalizeTaggedValue({ $type, value }) {
|
|
|
178
179
|
case "DateTime":
|
|
179
180
|
return { $type, value: new Date(value).toISOString() };
|
|
180
181
|
case "Decimal":
|
|
181
|
-
return { $type, value: String(new
|
|
182
|
+
return { $type, value: String(new import_client_runtime_utils2.Decimal(value)) };
|
|
182
183
|
case "Json":
|
|
183
184
|
return { $type, value: JSON.stringify(JSON.parse(value)) };
|
|
184
185
|
default:
|
|
@@ -221,7 +222,7 @@ function deserializeTaggedValue({ $type, value }) {
|
|
|
221
222
|
case "DateTime":
|
|
222
223
|
return new Date(value);
|
|
223
224
|
case "Decimal":
|
|
224
|
-
return new
|
|
225
|
+
return new import_client_runtime_utils2.Decimal(value);
|
|
225
226
|
case "Json":
|
|
226
227
|
return JSON.parse(value);
|
|
227
228
|
default:
|
|
@@ -299,6 +300,8 @@ function getErrorCode(err) {
|
|
|
299
300
|
return "P2002";
|
|
300
301
|
case "ForeignKeyConstraintViolation":
|
|
301
302
|
return "P2003";
|
|
303
|
+
case "InvalidInputValue":
|
|
304
|
+
return "P2007";
|
|
302
305
|
case "UnsupportedNativeDataType":
|
|
303
306
|
return "P2010";
|
|
304
307
|
case "NullConstraintViolation":
|
|
@@ -395,6 +398,8 @@ function renderErrorMessage(err) {
|
|
|
395
398
|
return `Error in external connector (id ${err.cause.id})`;
|
|
396
399
|
case "TooManyConnections":
|
|
397
400
|
return `Too many database connections opened: ${err.cause.cause}`;
|
|
401
|
+
case "InvalidInputValue":
|
|
402
|
+
return `Invalid input value: ${err.cause.message}`;
|
|
398
403
|
case "sqlite":
|
|
399
404
|
case "postgres":
|
|
400
405
|
case "mysql":
|
|
@@ -443,9 +448,12 @@ function convertCompactedRows(rows, compiledBatch) {
|
|
|
443
448
|
}
|
|
444
449
|
|
|
445
450
|
// src/interpreter/data-mapper.ts
|
|
446
|
-
var
|
|
447
|
-
var DataMapperError = class extends
|
|
451
|
+
var import_client_runtime_utils3 = require("@prisma/client-runtime-utils");
|
|
452
|
+
var DataMapperError = class extends UserFacingError {
|
|
448
453
|
name = "DataMapperError";
|
|
454
|
+
constructor(message, options) {
|
|
455
|
+
super(message, "P2023", options);
|
|
456
|
+
}
|
|
449
457
|
};
|
|
450
458
|
function applyDataMap(data, structure, enums) {
|
|
451
459
|
switch (structure.type) {
|
|
@@ -596,7 +604,7 @@ function mapValue(value, columnName, scalarType, enums) {
|
|
|
596
604
|
throw new DataMapperError(`Expected a boolean in column '${columnName}', got ${typeof value}: ${value}`);
|
|
597
605
|
}
|
|
598
606
|
}
|
|
599
|
-
if (Array.isArray(value)) {
|
|
607
|
+
if (Array.isArray(value) || value instanceof Uint8Array) {
|
|
600
608
|
for (const byte of value) {
|
|
601
609
|
if (byte !== 0) return true;
|
|
602
610
|
}
|
|
@@ -605,7 +613,7 @@ function mapValue(value, columnName, scalarType, enums) {
|
|
|
605
613
|
throw new DataMapperError(`Expected a boolean in column '${columnName}', got ${typeof value}: ${value}`);
|
|
606
614
|
}
|
|
607
615
|
case "decimal":
|
|
608
|
-
if (typeof value !== "number" && typeof value !== "string" && !
|
|
616
|
+
if (typeof value !== "number" && typeof value !== "string" && !import_client_runtime_utils3.Decimal.isDecimal(value)) {
|
|
609
617
|
throw new DataMapperError(`Expected a decimal in column '${columnName}', got ${typeof value}: ${value}`);
|
|
610
618
|
}
|
|
611
619
|
return { $type: "Decimal", value };
|
|
@@ -691,6 +699,44 @@ function normalizeDateTime(dt) {
|
|
|
691
699
|
return dtWithTz;
|
|
692
700
|
}
|
|
693
701
|
|
|
702
|
+
// src/sql-commenter.ts
|
|
703
|
+
var import_klona = require("klona");
|
|
704
|
+
function formatSqlComment(tags) {
|
|
705
|
+
const entries = Object.entries(tags);
|
|
706
|
+
if (entries.length === 0) {
|
|
707
|
+
return "";
|
|
708
|
+
}
|
|
709
|
+
entries.sort(([a], [b]) => a.localeCompare(b));
|
|
710
|
+
const parts = entries.map(([key, value]) => {
|
|
711
|
+
const encodedKey = encodeURIComponent(key);
|
|
712
|
+
const encodedValue = encodeURIComponent(value).replace(/'/g, "\\'");
|
|
713
|
+
return `${encodedKey}='${encodedValue}'`;
|
|
714
|
+
});
|
|
715
|
+
return `/*${parts.join(",")}*/`;
|
|
716
|
+
}
|
|
717
|
+
function applySqlCommenters(plugins, context) {
|
|
718
|
+
const merged = {};
|
|
719
|
+
for (const plugin of plugins) {
|
|
720
|
+
const tags = plugin((0, import_klona.klona)(context));
|
|
721
|
+
for (const [key, value] of Object.entries(tags)) {
|
|
722
|
+
if (value !== void 0) {
|
|
723
|
+
merged[key] = value;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
return merged;
|
|
728
|
+
}
|
|
729
|
+
function buildSqlComment(plugins, context) {
|
|
730
|
+
const tags = applySqlCommenters(plugins, context);
|
|
731
|
+
return formatSqlComment(tags);
|
|
732
|
+
}
|
|
733
|
+
function appendSqlComment(sql, comment) {
|
|
734
|
+
if (!comment) {
|
|
735
|
+
return sql;
|
|
736
|
+
}
|
|
737
|
+
return `${sql} ${comment}`;
|
|
738
|
+
}
|
|
739
|
+
|
|
694
740
|
// src/tracing.ts
|
|
695
741
|
var import_api = require("@opentelemetry/api");
|
|
696
742
|
var noopTracingHelper = {
|
|
@@ -1256,17 +1302,6 @@ function serializeRawValue(value, type) {
|
|
|
1256
1302
|
throw new Error(`Cannot serialize value of type ${typeof value} as JsonArray`);
|
|
1257
1303
|
}
|
|
1258
1304
|
return value.map((v) => serializeRawValue(v, import_driver_adapter_utils2.ColumnTypeEnum.Json));
|
|
1259
|
-
case import_driver_adapter_utils2.ColumnTypeEnum.Bytes:
|
|
1260
|
-
if (Array.isArray(value)) {
|
|
1261
|
-
return new Uint8Array(value);
|
|
1262
|
-
} else {
|
|
1263
|
-
throw new Error(`Cannot serialize value of type ${typeof value} as Bytes`);
|
|
1264
|
-
}
|
|
1265
|
-
case import_driver_adapter_utils2.ColumnTypeEnum.BytesArray:
|
|
1266
|
-
if (!Array.isArray(value)) {
|
|
1267
|
-
throw new Error(`Cannot serialize value of type ${typeof value} as BytesArray`);
|
|
1268
|
-
}
|
|
1269
|
-
return value.map((v) => serializeRawValue(v, import_driver_adapter_utils2.ColumnTypeEnum.Bytes));
|
|
1270
1305
|
case import_driver_adapter_utils2.ColumnTypeEnum.Boolean:
|
|
1271
1306
|
switch (typeof value) {
|
|
1272
1307
|
case "boolean":
|
|
@@ -1441,7 +1476,8 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1441
1476
|
#serializer;
|
|
1442
1477
|
#rawSerializer;
|
|
1443
1478
|
#provider;
|
|
1444
|
-
#
|
|
1479
|
+
#connectionInfo;
|
|
1480
|
+
#sqlCommenter;
|
|
1445
1481
|
constructor({
|
|
1446
1482
|
transactionManager,
|
|
1447
1483
|
placeholderValues,
|
|
@@ -1450,7 +1486,8 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1450
1486
|
serializer,
|
|
1451
1487
|
rawSerializer,
|
|
1452
1488
|
provider,
|
|
1453
|
-
connectionInfo
|
|
1489
|
+
connectionInfo,
|
|
1490
|
+
sqlCommenter
|
|
1454
1491
|
}) {
|
|
1455
1492
|
this.#transactionManager = transactionManager;
|
|
1456
1493
|
this.#placeholderValues = placeholderValues;
|
|
@@ -1459,7 +1496,8 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1459
1496
|
this.#serializer = serializer;
|
|
1460
1497
|
this.#rawSerializer = rawSerializer ?? serializer;
|
|
1461
1498
|
this.#provider = provider;
|
|
1462
|
-
this.#
|
|
1499
|
+
this.#connectionInfo = connectionInfo;
|
|
1500
|
+
this.#sqlCommenter = sqlCommenter;
|
|
1463
1501
|
}
|
|
1464
1502
|
static forSql(options) {
|
|
1465
1503
|
return new _QueryInterpreter({
|
|
@@ -1470,7 +1508,8 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1470
1508
|
serializer: serializeSql,
|
|
1471
1509
|
rawSerializer: serializeRawSql,
|
|
1472
1510
|
provider: options.provider,
|
|
1473
|
-
connectionInfo: options.connectionInfo
|
|
1511
|
+
connectionInfo: options.connectionInfo,
|
|
1512
|
+
sqlCommenter: options.sqlCommenter
|
|
1474
1513
|
});
|
|
1475
1514
|
}
|
|
1476
1515
|
async run(queryPlan, queryable) {
|
|
@@ -1534,10 +1573,11 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1534
1573
|
const queries = renderQuery(node.args, scope, generators, this.#maxChunkSize());
|
|
1535
1574
|
let sum = 0;
|
|
1536
1575
|
for (const query of queries) {
|
|
1576
|
+
const commentedQuery = this.#applyComments(query);
|
|
1537
1577
|
sum += await this.#withQuerySpanAndEvent(
|
|
1538
|
-
|
|
1578
|
+
commentedQuery,
|
|
1539
1579
|
queryable,
|
|
1540
|
-
() => queryable.executeRaw(
|
|
1580
|
+
() => queryable.executeRaw(commentedQuery).catch(
|
|
1541
1581
|
(err) => node.args.type === "rawSql" ? rethrowAsUserFacingRawError(err) : rethrowAsUserFacing(err)
|
|
1542
1582
|
)
|
|
1543
1583
|
);
|
|
@@ -1548,10 +1588,11 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1548
1588
|
const queries = renderQuery(node.args, scope, generators, this.#maxChunkSize());
|
|
1549
1589
|
let results;
|
|
1550
1590
|
for (const query of queries) {
|
|
1591
|
+
const commentedQuery = this.#applyComments(query);
|
|
1551
1592
|
const result = await this.#withQuerySpanAndEvent(
|
|
1552
|
-
|
|
1593
|
+
commentedQuery,
|
|
1553
1594
|
queryable,
|
|
1554
|
-
() => queryable.queryRaw(
|
|
1595
|
+
() => queryable.queryRaw(commentedQuery).catch(
|
|
1555
1596
|
(err) => node.args.type === "rawSql" ? rethrowAsUserFacingRawError(err) : rethrowAsUserFacing(err)
|
|
1556
1597
|
)
|
|
1557
1598
|
);
|
|
@@ -1673,8 +1714,8 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1673
1714
|
}
|
|
1674
1715
|
}
|
|
1675
1716
|
#maxChunkSize() {
|
|
1676
|
-
if (this.#
|
|
1677
|
-
return this.#
|
|
1717
|
+
if (this.#connectionInfo?.maxBindValues !== void 0) {
|
|
1718
|
+
return this.#connectionInfo.maxBindValues;
|
|
1678
1719
|
}
|
|
1679
1720
|
return this.#providerMaxChunkSize();
|
|
1680
1721
|
}
|
|
@@ -1709,6 +1750,22 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1709
1750
|
onQuery: this.#onQuery
|
|
1710
1751
|
});
|
|
1711
1752
|
}
|
|
1753
|
+
#applyComments(query) {
|
|
1754
|
+
if (!this.#sqlCommenter || this.#sqlCommenter.plugins.length === 0) {
|
|
1755
|
+
return query;
|
|
1756
|
+
}
|
|
1757
|
+
const comment = buildSqlComment(this.#sqlCommenter.plugins, {
|
|
1758
|
+
query: this.#sqlCommenter.queryInfo,
|
|
1759
|
+
sql: query.sql
|
|
1760
|
+
});
|
|
1761
|
+
if (!comment) {
|
|
1762
|
+
return query;
|
|
1763
|
+
}
|
|
1764
|
+
return {
|
|
1765
|
+
...query,
|
|
1766
|
+
sql: appendSqlComment(query.sql, comment)
|
|
1767
|
+
};
|
|
1768
|
+
}
|
|
1712
1769
|
};
|
|
1713
1770
|
function isEmpty(value) {
|
|
1714
1771
|
if (Array.isArray(value)) {
|
|
@@ -1811,7 +1868,7 @@ function evalFieldOperation(op, value, scope, generators) {
|
|
|
1811
1868
|
}
|
|
1812
1869
|
|
|
1813
1870
|
// src/raw-json-protocol.ts
|
|
1814
|
-
var
|
|
1871
|
+
var import_client_runtime_utils4 = require("@prisma/client-runtime-utils");
|
|
1815
1872
|
function normalizeRawJsonProtocolResponse(response) {
|
|
1816
1873
|
for (let i = 0; i < response.rows.length; i++) {
|
|
1817
1874
|
const row = response.rows[i];
|
|
@@ -1829,7 +1886,7 @@ function normalizeValue(type, value) {
|
|
|
1829
1886
|
case "bigint":
|
|
1830
1887
|
return String(BigInt(value));
|
|
1831
1888
|
case "decimal":
|
|
1832
|
-
return String(new
|
|
1889
|
+
return String(new import_client_runtime_utils4.Decimal(value));
|
|
1833
1890
|
case "bigint-array":
|
|
1834
1891
|
return value.map((v) => normalizeValue("bigint", v));
|
|
1835
1892
|
case "decimal-array":
|
|
@@ -1851,6 +1908,13 @@ async function randomUUID() {
|
|
|
1851
1908
|
return crypto.randomUUID();
|
|
1852
1909
|
}
|
|
1853
1910
|
|
|
1911
|
+
// src/web-platform.ts
|
|
1912
|
+
async function once(target, event) {
|
|
1913
|
+
return new Promise((resolve) => {
|
|
1914
|
+
target.addEventListener(event, resolve, { once: true });
|
|
1915
|
+
});
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1854
1918
|
// src/transaction-manager/transaction-manager-error.ts
|
|
1855
1919
|
var TransactionManagerError = class extends UserFacingError {
|
|
1856
1920
|
name = "TransactionManagerError";
|
|
@@ -1966,15 +2030,19 @@ var TransactionManager = class {
|
|
|
1966
2030
|
startedAt: Date.now(),
|
|
1967
2031
|
transaction: void 0
|
|
1968
2032
|
};
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
const startTimer = createTimeoutIfDefined(() => hasTimedOut = true, options.maxWait);
|
|
2033
|
+
const abortController = new AbortController();
|
|
2034
|
+
const startTimer = createTimeoutIfDefined(() => abortController.abort(), options.maxWait);
|
|
1972
2035
|
startTimer?.unref?.();
|
|
1973
|
-
|
|
1974
|
-
|
|
2036
|
+
const startTransactionPromise = this.driverAdapter.startTransaction(options.isolationLevel).catch(rethrowAsUserFacing);
|
|
2037
|
+
transaction.transaction = await Promise.race([
|
|
2038
|
+
startTransactionPromise.finally(() => clearTimeout(startTimer)),
|
|
2039
|
+
once(abortController.signal, "abort").then(() => void 0)
|
|
2040
|
+
]);
|
|
2041
|
+
this.transactions.set(transaction.id, transaction);
|
|
1975
2042
|
switch (transaction.status) {
|
|
1976
2043
|
case "waiting":
|
|
1977
|
-
if (
|
|
2044
|
+
if (abortController.signal.aborted) {
|
|
2045
|
+
void startTransactionPromise.then((tx) => tx.rollback()).catch((e) => debug("error in discarded transaction:", e));
|
|
1978
2046
|
await this.#closeTransaction(transaction, "timed_out");
|
|
1979
2047
|
throw new TransactionStartTimeoutError();
|
|
1980
2048
|
}
|
|
@@ -2070,8 +2138,13 @@ var TransactionManager = class {
|
|
|
2070
2138
|
await this.#withQuerySpanAndEvent(PHANTOM_COMMIT_QUERY(), tx.transaction, () => tx.transaction.commit());
|
|
2071
2139
|
} else {
|
|
2072
2140
|
const query = COMMIT_QUERY();
|
|
2073
|
-
await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query))
|
|
2074
|
-
|
|
2141
|
+
await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query)).then(
|
|
2142
|
+
() => tx.transaction.commit(),
|
|
2143
|
+
(err) => {
|
|
2144
|
+
const fail = () => Promise.reject(err);
|
|
2145
|
+
return tx.transaction.rollback().then(fail, fail);
|
|
2146
|
+
}
|
|
2147
|
+
);
|
|
2075
2148
|
}
|
|
2076
2149
|
} else if (tx.transaction) {
|
|
2077
2150
|
if (tx.transaction.options.usePhantomQuery) {
|
|
@@ -2082,8 +2155,11 @@ var TransactionManager = class {
|
|
|
2082
2155
|
);
|
|
2083
2156
|
} else {
|
|
2084
2157
|
const query = ROLLBACK_QUERY();
|
|
2085
|
-
|
|
2086
|
-
|
|
2158
|
+
try {
|
|
2159
|
+
await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
|
|
2160
|
+
} finally {
|
|
2161
|
+
await tx.transaction.rollback();
|
|
2162
|
+
}
|
|
2087
2163
|
}
|
|
2088
2164
|
}
|
|
2089
2165
|
} finally {
|
|
@@ -2138,6 +2214,7 @@ function createTimeoutIfDefined(cb, ms) {
|
|
|
2138
2214
|
TransactionManager,
|
|
2139
2215
|
TransactionManagerError,
|
|
2140
2216
|
UserFacingError,
|
|
2217
|
+
applySqlCommenters,
|
|
2141
2218
|
convertCompactedRows,
|
|
2142
2219
|
deserializeJsonResponse,
|
|
2143
2220
|
doKeysMatch,
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/json-protocol.ts
|
|
2
|
-
import { Decimal as Decimal2 } from "
|
|
2
|
+
import { Decimal as Decimal2 } from "@prisma/client-runtime-utils";
|
|
3
3
|
|
|
4
4
|
// src/utils.ts
|
|
5
|
-
import Decimal from "
|
|
5
|
+
import { Decimal } from "@prisma/client-runtime-utils";
|
|
6
6
|
function assertNever(_, message) {
|
|
7
7
|
throw new Error(message);
|
|
8
8
|
}
|
|
@@ -249,6 +249,8 @@ function getErrorCode(err) {
|
|
|
249
249
|
return "P2002";
|
|
250
250
|
case "ForeignKeyConstraintViolation":
|
|
251
251
|
return "P2003";
|
|
252
|
+
case "InvalidInputValue":
|
|
253
|
+
return "P2007";
|
|
252
254
|
case "UnsupportedNativeDataType":
|
|
253
255
|
return "P2010";
|
|
254
256
|
case "NullConstraintViolation":
|
|
@@ -345,6 +347,8 @@ function renderErrorMessage(err) {
|
|
|
345
347
|
return `Error in external connector (id ${err.cause.id})`;
|
|
346
348
|
case "TooManyConnections":
|
|
347
349
|
return `Too many database connections opened: ${err.cause.cause}`;
|
|
350
|
+
case "InvalidInputValue":
|
|
351
|
+
return `Invalid input value: ${err.cause.message}`;
|
|
348
352
|
case "sqlite":
|
|
349
353
|
case "postgres":
|
|
350
354
|
case "mysql":
|
|
@@ -393,9 +397,12 @@ function convertCompactedRows(rows, compiledBatch) {
|
|
|
393
397
|
}
|
|
394
398
|
|
|
395
399
|
// src/interpreter/data-mapper.ts
|
|
396
|
-
import Decimal3 from "
|
|
397
|
-
var DataMapperError = class extends
|
|
400
|
+
import { Decimal as Decimal3 } from "@prisma/client-runtime-utils";
|
|
401
|
+
var DataMapperError = class extends UserFacingError {
|
|
398
402
|
name = "DataMapperError";
|
|
403
|
+
constructor(message, options) {
|
|
404
|
+
super(message, "P2023", options);
|
|
405
|
+
}
|
|
399
406
|
};
|
|
400
407
|
function applyDataMap(data, structure, enums) {
|
|
401
408
|
switch (structure.type) {
|
|
@@ -546,7 +553,7 @@ function mapValue(value, columnName, scalarType, enums) {
|
|
|
546
553
|
throw new DataMapperError(`Expected a boolean in column '${columnName}', got ${typeof value}: ${value}`);
|
|
547
554
|
}
|
|
548
555
|
}
|
|
549
|
-
if (Array.isArray(value)) {
|
|
556
|
+
if (Array.isArray(value) || value instanceof Uint8Array) {
|
|
550
557
|
for (const byte of value) {
|
|
551
558
|
if (byte !== 0) return true;
|
|
552
559
|
}
|
|
@@ -641,6 +648,44 @@ function normalizeDateTime(dt) {
|
|
|
641
648
|
return dtWithTz;
|
|
642
649
|
}
|
|
643
650
|
|
|
651
|
+
// src/sql-commenter.ts
|
|
652
|
+
import { klona } from "klona";
|
|
653
|
+
function formatSqlComment(tags) {
|
|
654
|
+
const entries = Object.entries(tags);
|
|
655
|
+
if (entries.length === 0) {
|
|
656
|
+
return "";
|
|
657
|
+
}
|
|
658
|
+
entries.sort(([a], [b]) => a.localeCompare(b));
|
|
659
|
+
const parts = entries.map(([key, value]) => {
|
|
660
|
+
const encodedKey = encodeURIComponent(key);
|
|
661
|
+
const encodedValue = encodeURIComponent(value).replace(/'/g, "\\'");
|
|
662
|
+
return `${encodedKey}='${encodedValue}'`;
|
|
663
|
+
});
|
|
664
|
+
return `/*${parts.join(",")}*/`;
|
|
665
|
+
}
|
|
666
|
+
function applySqlCommenters(plugins, context) {
|
|
667
|
+
const merged = {};
|
|
668
|
+
for (const plugin of plugins) {
|
|
669
|
+
const tags = plugin(klona(context));
|
|
670
|
+
for (const [key, value] of Object.entries(tags)) {
|
|
671
|
+
if (value !== void 0) {
|
|
672
|
+
merged[key] = value;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
return merged;
|
|
677
|
+
}
|
|
678
|
+
function buildSqlComment(plugins, context) {
|
|
679
|
+
const tags = applySqlCommenters(plugins, context);
|
|
680
|
+
return formatSqlComment(tags);
|
|
681
|
+
}
|
|
682
|
+
function appendSqlComment(sql, comment) {
|
|
683
|
+
if (!comment) {
|
|
684
|
+
return sql;
|
|
685
|
+
}
|
|
686
|
+
return `${sql} ${comment}`;
|
|
687
|
+
}
|
|
688
|
+
|
|
644
689
|
// src/tracing.ts
|
|
645
690
|
import { SpanKind } from "@opentelemetry/api";
|
|
646
691
|
var noopTracingHelper = {
|
|
@@ -1206,17 +1251,6 @@ function serializeRawValue(value, type) {
|
|
|
1206
1251
|
throw new Error(`Cannot serialize value of type ${typeof value} as JsonArray`);
|
|
1207
1252
|
}
|
|
1208
1253
|
return value.map((v) => serializeRawValue(v, ColumnTypeEnum.Json));
|
|
1209
|
-
case ColumnTypeEnum.Bytes:
|
|
1210
|
-
if (Array.isArray(value)) {
|
|
1211
|
-
return new Uint8Array(value);
|
|
1212
|
-
} else {
|
|
1213
|
-
throw new Error(`Cannot serialize value of type ${typeof value} as Bytes`);
|
|
1214
|
-
}
|
|
1215
|
-
case ColumnTypeEnum.BytesArray:
|
|
1216
|
-
if (!Array.isArray(value)) {
|
|
1217
|
-
throw new Error(`Cannot serialize value of type ${typeof value} as BytesArray`);
|
|
1218
|
-
}
|
|
1219
|
-
return value.map((v) => serializeRawValue(v, ColumnTypeEnum.Bytes));
|
|
1220
1254
|
case ColumnTypeEnum.Boolean:
|
|
1221
1255
|
switch (typeof value) {
|
|
1222
1256
|
case "boolean":
|
|
@@ -1391,7 +1425,8 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1391
1425
|
#serializer;
|
|
1392
1426
|
#rawSerializer;
|
|
1393
1427
|
#provider;
|
|
1394
|
-
#
|
|
1428
|
+
#connectionInfo;
|
|
1429
|
+
#sqlCommenter;
|
|
1395
1430
|
constructor({
|
|
1396
1431
|
transactionManager,
|
|
1397
1432
|
placeholderValues,
|
|
@@ -1400,7 +1435,8 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1400
1435
|
serializer,
|
|
1401
1436
|
rawSerializer,
|
|
1402
1437
|
provider,
|
|
1403
|
-
connectionInfo
|
|
1438
|
+
connectionInfo,
|
|
1439
|
+
sqlCommenter
|
|
1404
1440
|
}) {
|
|
1405
1441
|
this.#transactionManager = transactionManager;
|
|
1406
1442
|
this.#placeholderValues = placeholderValues;
|
|
@@ -1409,7 +1445,8 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1409
1445
|
this.#serializer = serializer;
|
|
1410
1446
|
this.#rawSerializer = rawSerializer ?? serializer;
|
|
1411
1447
|
this.#provider = provider;
|
|
1412
|
-
this.#
|
|
1448
|
+
this.#connectionInfo = connectionInfo;
|
|
1449
|
+
this.#sqlCommenter = sqlCommenter;
|
|
1413
1450
|
}
|
|
1414
1451
|
static forSql(options) {
|
|
1415
1452
|
return new _QueryInterpreter({
|
|
@@ -1420,7 +1457,8 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1420
1457
|
serializer: serializeSql,
|
|
1421
1458
|
rawSerializer: serializeRawSql,
|
|
1422
1459
|
provider: options.provider,
|
|
1423
|
-
connectionInfo: options.connectionInfo
|
|
1460
|
+
connectionInfo: options.connectionInfo,
|
|
1461
|
+
sqlCommenter: options.sqlCommenter
|
|
1424
1462
|
});
|
|
1425
1463
|
}
|
|
1426
1464
|
async run(queryPlan, queryable) {
|
|
@@ -1484,10 +1522,11 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1484
1522
|
const queries = renderQuery(node.args, scope, generators, this.#maxChunkSize());
|
|
1485
1523
|
let sum = 0;
|
|
1486
1524
|
for (const query of queries) {
|
|
1525
|
+
const commentedQuery = this.#applyComments(query);
|
|
1487
1526
|
sum += await this.#withQuerySpanAndEvent(
|
|
1488
|
-
|
|
1527
|
+
commentedQuery,
|
|
1489
1528
|
queryable,
|
|
1490
|
-
() => queryable.executeRaw(
|
|
1529
|
+
() => queryable.executeRaw(commentedQuery).catch(
|
|
1491
1530
|
(err) => node.args.type === "rawSql" ? rethrowAsUserFacingRawError(err) : rethrowAsUserFacing(err)
|
|
1492
1531
|
)
|
|
1493
1532
|
);
|
|
@@ -1498,10 +1537,11 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1498
1537
|
const queries = renderQuery(node.args, scope, generators, this.#maxChunkSize());
|
|
1499
1538
|
let results;
|
|
1500
1539
|
for (const query of queries) {
|
|
1540
|
+
const commentedQuery = this.#applyComments(query);
|
|
1501
1541
|
const result = await this.#withQuerySpanAndEvent(
|
|
1502
|
-
|
|
1542
|
+
commentedQuery,
|
|
1503
1543
|
queryable,
|
|
1504
|
-
() => queryable.queryRaw(
|
|
1544
|
+
() => queryable.queryRaw(commentedQuery).catch(
|
|
1505
1545
|
(err) => node.args.type === "rawSql" ? rethrowAsUserFacingRawError(err) : rethrowAsUserFacing(err)
|
|
1506
1546
|
)
|
|
1507
1547
|
);
|
|
@@ -1623,8 +1663,8 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1623
1663
|
}
|
|
1624
1664
|
}
|
|
1625
1665
|
#maxChunkSize() {
|
|
1626
|
-
if (this.#
|
|
1627
|
-
return this.#
|
|
1666
|
+
if (this.#connectionInfo?.maxBindValues !== void 0) {
|
|
1667
|
+
return this.#connectionInfo.maxBindValues;
|
|
1628
1668
|
}
|
|
1629
1669
|
return this.#providerMaxChunkSize();
|
|
1630
1670
|
}
|
|
@@ -1659,6 +1699,22 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1659
1699
|
onQuery: this.#onQuery
|
|
1660
1700
|
});
|
|
1661
1701
|
}
|
|
1702
|
+
#applyComments(query) {
|
|
1703
|
+
if (!this.#sqlCommenter || this.#sqlCommenter.plugins.length === 0) {
|
|
1704
|
+
return query;
|
|
1705
|
+
}
|
|
1706
|
+
const comment = buildSqlComment(this.#sqlCommenter.plugins, {
|
|
1707
|
+
query: this.#sqlCommenter.queryInfo,
|
|
1708
|
+
sql: query.sql
|
|
1709
|
+
});
|
|
1710
|
+
if (!comment) {
|
|
1711
|
+
return query;
|
|
1712
|
+
}
|
|
1713
|
+
return {
|
|
1714
|
+
...query,
|
|
1715
|
+
sql: appendSqlComment(query.sql, comment)
|
|
1716
|
+
};
|
|
1717
|
+
}
|
|
1662
1718
|
};
|
|
1663
1719
|
function isEmpty(value) {
|
|
1664
1720
|
if (Array.isArray(value)) {
|
|
@@ -1761,7 +1817,7 @@ function evalFieldOperation(op, value, scope, generators) {
|
|
|
1761
1817
|
}
|
|
1762
1818
|
|
|
1763
1819
|
// src/raw-json-protocol.ts
|
|
1764
|
-
import Decimal4 from "
|
|
1820
|
+
import { Decimal as Decimal4 } from "@prisma/client-runtime-utils";
|
|
1765
1821
|
function normalizeRawJsonProtocolResponse(response) {
|
|
1766
1822
|
for (let i = 0; i < response.rows.length; i++) {
|
|
1767
1823
|
const row = response.rows[i];
|
|
@@ -1801,6 +1857,13 @@ async function randomUUID() {
|
|
|
1801
1857
|
return crypto.randomUUID();
|
|
1802
1858
|
}
|
|
1803
1859
|
|
|
1860
|
+
// src/web-platform.ts
|
|
1861
|
+
async function once(target, event) {
|
|
1862
|
+
return new Promise((resolve) => {
|
|
1863
|
+
target.addEventListener(event, resolve, { once: true });
|
|
1864
|
+
});
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1804
1867
|
// src/transaction-manager/transaction-manager-error.ts
|
|
1805
1868
|
var TransactionManagerError = class extends UserFacingError {
|
|
1806
1869
|
name = "TransactionManagerError";
|
|
@@ -1916,15 +1979,19 @@ var TransactionManager = class {
|
|
|
1916
1979
|
startedAt: Date.now(),
|
|
1917
1980
|
transaction: void 0
|
|
1918
1981
|
};
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
const startTimer = createTimeoutIfDefined(() => hasTimedOut = true, options.maxWait);
|
|
1982
|
+
const abortController = new AbortController();
|
|
1983
|
+
const startTimer = createTimeoutIfDefined(() => abortController.abort(), options.maxWait);
|
|
1922
1984
|
startTimer?.unref?.();
|
|
1923
|
-
|
|
1924
|
-
|
|
1985
|
+
const startTransactionPromise = this.driverAdapter.startTransaction(options.isolationLevel).catch(rethrowAsUserFacing);
|
|
1986
|
+
transaction.transaction = await Promise.race([
|
|
1987
|
+
startTransactionPromise.finally(() => clearTimeout(startTimer)),
|
|
1988
|
+
once(abortController.signal, "abort").then(() => void 0)
|
|
1989
|
+
]);
|
|
1990
|
+
this.transactions.set(transaction.id, transaction);
|
|
1925
1991
|
switch (transaction.status) {
|
|
1926
1992
|
case "waiting":
|
|
1927
|
-
if (
|
|
1993
|
+
if (abortController.signal.aborted) {
|
|
1994
|
+
void startTransactionPromise.then((tx) => tx.rollback()).catch((e) => debug("error in discarded transaction:", e));
|
|
1928
1995
|
await this.#closeTransaction(transaction, "timed_out");
|
|
1929
1996
|
throw new TransactionStartTimeoutError();
|
|
1930
1997
|
}
|
|
@@ -2020,8 +2087,13 @@ var TransactionManager = class {
|
|
|
2020
2087
|
await this.#withQuerySpanAndEvent(PHANTOM_COMMIT_QUERY(), tx.transaction, () => tx.transaction.commit());
|
|
2021
2088
|
} else {
|
|
2022
2089
|
const query = COMMIT_QUERY();
|
|
2023
|
-
await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query))
|
|
2024
|
-
|
|
2090
|
+
await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query)).then(
|
|
2091
|
+
() => tx.transaction.commit(),
|
|
2092
|
+
(err) => {
|
|
2093
|
+
const fail = () => Promise.reject(err);
|
|
2094
|
+
return tx.transaction.rollback().then(fail, fail);
|
|
2095
|
+
}
|
|
2096
|
+
);
|
|
2025
2097
|
}
|
|
2026
2098
|
} else if (tx.transaction) {
|
|
2027
2099
|
if (tx.transaction.options.usePhantomQuery) {
|
|
@@ -2032,8 +2104,11 @@ var TransactionManager = class {
|
|
|
2032
2104
|
);
|
|
2033
2105
|
} else {
|
|
2034
2106
|
const query = ROLLBACK_QUERY();
|
|
2035
|
-
|
|
2036
|
-
|
|
2107
|
+
try {
|
|
2108
|
+
await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
|
|
2109
|
+
} finally {
|
|
2110
|
+
await tx.transaction.rollback();
|
|
2111
|
+
}
|
|
2037
2112
|
}
|
|
2038
2113
|
}
|
|
2039
2114
|
} finally {
|
|
@@ -2087,6 +2162,7 @@ export {
|
|
|
2087
2162
|
TransactionManager,
|
|
2088
2163
|
TransactionManagerError,
|
|
2089
2164
|
UserFacingError,
|
|
2165
|
+
applySqlCommenters,
|
|
2090
2166
|
convertCompactedRows,
|
|
2091
2167
|
deserializeJsonResponse,
|
|
2092
2168
|
doKeysMatch,
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { ResultNode } from '../query-plan';
|
|
2
|
+
import { UserFacingError } from '../user-facing-error';
|
|
2
3
|
import { Value } from './scope';
|
|
3
|
-
export declare class DataMapperError extends
|
|
4
|
+
export declare class DataMapperError extends UserFacingError {
|
|
4
5
|
name: string;
|
|
6
|
+
constructor(message: string, options?: {
|
|
7
|
+
cause?: unknown;
|
|
8
|
+
});
|
|
5
9
|
}
|
|
6
10
|
export declare function applyDataMap(data: Value, structure: ResultNode, enums: Record<string, Record<string, string>>): Value;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ConnectionInfo, SqlQueryable, SqlResultSet } from '@prisma/driver-adapter-utils';
|
|
2
|
+
import type { SqlCommenterPlugin, SqlCommenterQueryInfo } from '@prisma/sqlcommenter';
|
|
2
3
|
import { QueryEvent } from '../events';
|
|
3
4
|
import { QueryPlanNode } from '../query-plan';
|
|
4
5
|
import { type SchemaProvider } from '../schema';
|
|
@@ -20,10 +21,15 @@ export type QueryInterpreterOptions = {
|
|
|
20
21
|
rawSerializer?: (results: SqlResultSet) => Value;
|
|
21
22
|
provider?: SchemaProvider;
|
|
22
23
|
connectionInfo?: ConnectionInfo;
|
|
24
|
+
sqlCommenter?: QueryInterpreterSqlCommenter;
|
|
25
|
+
};
|
|
26
|
+
export type QueryInterpreterSqlCommenter = {
|
|
27
|
+
plugins: SqlCommenterPlugin[];
|
|
28
|
+
queryInfo: SqlCommenterQueryInfo;
|
|
23
29
|
};
|
|
24
30
|
export declare class QueryInterpreter {
|
|
25
31
|
#private;
|
|
26
|
-
constructor({ transactionManager, placeholderValues, onQuery, tracingHelper, serializer, rawSerializer, provider, connectionInfo, }: QueryInterpreterOptions);
|
|
32
|
+
constructor({ transactionManager, placeholderValues, onQuery, tracingHelper, serializer, rawSerializer, provider, connectionInfo, sqlCommenter, }: QueryInterpreterOptions);
|
|
27
33
|
static forSql(options: {
|
|
28
34
|
transactionManager: QueryInterpreterTransactionManager;
|
|
29
35
|
placeholderValues: Record<string, unknown>;
|
|
@@ -31,6 +37,7 @@ export declare class QueryInterpreter {
|
|
|
31
37
|
tracingHelper: TracingHelper;
|
|
32
38
|
provider?: SchemaProvider;
|
|
33
39
|
connectionInfo?: ConnectionInfo;
|
|
40
|
+
sqlCommenter?: QueryInterpreterSqlCommenter;
|
|
34
41
|
}): QueryInterpreter;
|
|
35
42
|
run(queryPlan: QueryPlanNode, queryable: SqlQueryable): Promise<unknown>;
|
|
36
43
|
private interpretNode;
|
package/dist/json-protocol.d.ts
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { SqlCommenterContext, SqlCommenterPlugin } from '@prisma/sqlcommenter';
|
|
2
|
+
/**
|
|
3
|
+
* Formats key-value pairs into a sqlcommenter-compatible comment string.
|
|
4
|
+
*
|
|
5
|
+
* Algorithm per https://google.github.io/sqlcommenter/spec/:
|
|
6
|
+
* 1. If the map is empty, return empty string
|
|
7
|
+
* 2. Sort keys lexicographically
|
|
8
|
+
* 3. URL-encode keys
|
|
9
|
+
* 4. URL-encode values
|
|
10
|
+
* 5. Replace ' with \' in values (after URL encoding)
|
|
11
|
+
* 6. Wrap values in single quotes
|
|
12
|
+
* 7. Join key='value' pairs with commas
|
|
13
|
+
* 8. Wrap in a SQL comment
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatSqlComment(tags: Record<string, string>): string;
|
|
16
|
+
/**
|
|
17
|
+
* Applies SQL commenter plugins and returns the merged key-value pairs.
|
|
18
|
+
* Keys with undefined values are filtered out.
|
|
19
|
+
*
|
|
20
|
+
* Each plugin receives a deep clone of the context to prevent mutations
|
|
21
|
+
* that could affect other plugins.
|
|
22
|
+
*/
|
|
23
|
+
export declare function applySqlCommenters(plugins: SqlCommenterPlugin[], context: SqlCommenterContext): Record<string, string>;
|
|
24
|
+
/**
|
|
25
|
+
* Applies SQL commenter plugins and returns the formatted comment.
|
|
26
|
+
*/
|
|
27
|
+
export declare function buildSqlComment(plugins: SqlCommenterPlugin[], context: SqlCommenterContext): string;
|
|
28
|
+
/**
|
|
29
|
+
* Appends a sqlcommenter comment to a SQL query.
|
|
30
|
+
*/
|
|
31
|
+
export declare function appendSqlComment(sql: string, comment: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Equivalent to `once` from `node:events` for DOM {@link EventTarget}.
|
|
3
|
+
*
|
|
4
|
+
* It is useful, e.g., to wait for an `abort` event on {@link AbortSignal}.
|
|
5
|
+
* While in Node.js `AbortSignal` does implement `EventEmitter` interface
|
|
6
|
+
* and is compatible with the `once` utility in `node:events`, it is not
|
|
7
|
+
* necessarily the case in other JS runtimes.
|
|
8
|
+
*/
|
|
9
|
+
export declare function once(target: EventTarget, event: string): Promise<Event>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/client-engine-runtime",
|
|
3
|
-
"version": "7.3.0-integration-
|
|
3
|
+
"version": "7.3.0-integration-engines-7-3-0-10-fix-fix-mapped-enum-issue-0b7e6564db7dc3dac7f9312aa84e9ed81d805521.1",
|
|
4
4
|
"description": "This package is intended for Prisma's internal use",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -27,16 +27,21 @@
|
|
|
27
27
|
"@bugsnag/cuid": "3.2.1",
|
|
28
28
|
"@opentelemetry/api": "1.9.0",
|
|
29
29
|
"@paralleldrive/cuid2": "2.2.2",
|
|
30
|
-
"
|
|
30
|
+
"klona": "2.0.6",
|
|
31
31
|
"nanoid": "5.1.5",
|
|
32
32
|
"ulid": "3.0.0",
|
|
33
33
|
"uuid": "11.1.0",
|
|
34
|
-
"@prisma/
|
|
35
|
-
"@prisma/
|
|
34
|
+
"@prisma/client-runtime-utils": "7.3.0-integration-engines-7-3-0-10-fix-fix-mapped-enum-issue-0b7e6564db7dc3dac7f9312aa84e9ed81d805521.1",
|
|
35
|
+
"@prisma/debug": "7.3.0-integration-engines-7-3-0-10-fix-fix-mapped-enum-issue-0b7e6564db7dc3dac7f9312aa84e9ed81d805521.1",
|
|
36
|
+
"@prisma/sqlcommenter": "7.3.0-integration-engines-7-3-0-10-fix-fix-mapped-enum-issue-0b7e6564db7dc3dac7f9312aa84e9ed81d805521.1",
|
|
37
|
+
"@prisma/driver-adapter-utils": "7.3.0-integration-engines-7-3-0-10-fix-fix-mapped-enum-issue-0b7e6564db7dc3dac7f9312aa84e9ed81d805521.1"
|
|
36
38
|
},
|
|
37
39
|
"devDependencies": {
|
|
40
|
+
"@codspeed/benchmark.js-plugin": "4.0.0",
|
|
41
|
+
"@types/benchmark": "2.1.5",
|
|
38
42
|
"@types/jest": "29.5.14",
|
|
39
|
-
"@types/node": "
|
|
43
|
+
"@types/node": "~20.19.24",
|
|
44
|
+
"benchmark": "2.1.4",
|
|
40
45
|
"jest": "29.7.0",
|
|
41
46
|
"jest-junit": "16.0.0"
|
|
42
47
|
},
|