@prisma/client-engine-runtime 6.7.0-integration-push-qwtnrmswnvqm.1 → 6.8.0-dev.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/QueryPlan.d.ts +38 -0
- package/dist/index.d.mts +54 -1
- package/dist/index.d.ts +54 -1
- package/dist/index.js +116 -7
- package/dist/index.mjs +116 -7
- package/dist/interpreter/DataMapper.d.ts +3 -0
- package/dist/interpreter/QueryInterpreter.d.ts +10 -2
- package/dist/interpreter/serializeSql.d.ts +2 -0
- package/package.json +3 -3
- package/dist/interpreter/serialize.d.ts +0 -2
- /package/dist/interpreter/{serialize.test.d.ts → serializeSql.test.d.ts} +0 -0
package/dist/QueryPlan.d.ts
CHANGED
|
@@ -15,6 +15,38 @@ export type PrismaValueGenerator = {
|
|
|
15
15
|
};
|
|
16
16
|
export declare function isPrismaValueGenerator(value: unknown): value is PrismaValueGenerator;
|
|
17
17
|
export type PrismaValue = string | boolean | number | PrismaValue[] | null | Record<string, unknown> | PrismaValuePlaceholder | PrismaValueGenerator;
|
|
18
|
+
export type PrismaValueType = {
|
|
19
|
+
type: 'Any';
|
|
20
|
+
} | {
|
|
21
|
+
type: 'String';
|
|
22
|
+
} | {
|
|
23
|
+
type: 'Int';
|
|
24
|
+
} | {
|
|
25
|
+
type: 'BigInt';
|
|
26
|
+
} | {
|
|
27
|
+
type: 'Float';
|
|
28
|
+
} | {
|
|
29
|
+
type: 'Boolean';
|
|
30
|
+
} | {
|
|
31
|
+
type: 'Decimal';
|
|
32
|
+
} | {
|
|
33
|
+
type: 'Date';
|
|
34
|
+
} | {
|
|
35
|
+
type: 'Array';
|
|
36
|
+
inner: PrismaValueType;
|
|
37
|
+
} | {
|
|
38
|
+
type: 'Object';
|
|
39
|
+
} | {
|
|
40
|
+
type: 'Bytes';
|
|
41
|
+
};
|
|
42
|
+
export type ResultNode = {
|
|
43
|
+
type: 'Object';
|
|
44
|
+
fields: Record<string, ResultNode>;
|
|
45
|
+
} | {
|
|
46
|
+
type: 'Value';
|
|
47
|
+
dbName: string;
|
|
48
|
+
resultType: PrismaValueType;
|
|
49
|
+
};
|
|
18
50
|
export type QueryPlanBinding = {
|
|
19
51
|
name: string;
|
|
20
52
|
expr: QueryPlanNode;
|
|
@@ -103,4 +135,10 @@ export type QueryPlanNode = {
|
|
|
103
135
|
} | {
|
|
104
136
|
type: 'transaction';
|
|
105
137
|
args: QueryPlanNode;
|
|
138
|
+
} | {
|
|
139
|
+
type: 'dataMap';
|
|
140
|
+
args: {
|
|
141
|
+
expr: QueryPlanNode;
|
|
142
|
+
structure: ResultNode;
|
|
143
|
+
};
|
|
106
144
|
};
|
package/dist/index.d.mts
CHANGED
|
@@ -4,6 +4,7 @@ import type { Span } from '@opentelemetry/api';
|
|
|
4
4
|
import type { SpanOptions } from '@opentelemetry/api';
|
|
5
5
|
import { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
|
|
6
6
|
import { SqlQueryable } from '@prisma/driver-adapter-utils';
|
|
7
|
+
import { SqlResultSet } from '@prisma/driver-adapter-utils';
|
|
7
8
|
import { Transaction } from '@prisma/driver-adapter-utils';
|
|
8
9
|
|
|
9
10
|
declare type ExtendedSpanOptions = SpanOptions & {
|
|
@@ -56,6 +57,31 @@ export declare type PrismaValuePlaceholder = {
|
|
|
56
57
|
};
|
|
57
58
|
};
|
|
58
59
|
|
|
60
|
+
export declare type PrismaValueType = {
|
|
61
|
+
type: 'Any';
|
|
62
|
+
} | {
|
|
63
|
+
type: 'String';
|
|
64
|
+
} | {
|
|
65
|
+
type: 'Int';
|
|
66
|
+
} | {
|
|
67
|
+
type: 'BigInt';
|
|
68
|
+
} | {
|
|
69
|
+
type: 'Float';
|
|
70
|
+
} | {
|
|
71
|
+
type: 'Boolean';
|
|
72
|
+
} | {
|
|
73
|
+
type: 'Decimal';
|
|
74
|
+
} | {
|
|
75
|
+
type: 'Date';
|
|
76
|
+
} | {
|
|
77
|
+
type: 'Array';
|
|
78
|
+
inner: PrismaValueType;
|
|
79
|
+
} | {
|
|
80
|
+
type: 'Object';
|
|
81
|
+
} | {
|
|
82
|
+
type: 'Bytes';
|
|
83
|
+
};
|
|
84
|
+
|
|
59
85
|
export declare type QueryEvent = {
|
|
60
86
|
timestamp: Date;
|
|
61
87
|
query: string;
|
|
@@ -65,7 +91,13 @@ export declare type QueryEvent = {
|
|
|
65
91
|
|
|
66
92
|
export declare class QueryInterpreter {
|
|
67
93
|
#private;
|
|
68
|
-
constructor({ transactionManager, placeholderValues, onQuery, tracingHelper }: QueryInterpreterOptions);
|
|
94
|
+
constructor({ transactionManager, placeholderValues, onQuery, tracingHelper, serializer }: QueryInterpreterOptions);
|
|
95
|
+
static forSql(options: {
|
|
96
|
+
transactionManager: QueryInterpreterTransactionManager;
|
|
97
|
+
placeholderValues: Record<string, unknown>;
|
|
98
|
+
onQuery?: (event: QueryEvent) => void;
|
|
99
|
+
tracingHelper: TracingHelper;
|
|
100
|
+
}): QueryInterpreter;
|
|
69
101
|
run(queryPlan: QueryPlanNode, queryable: SqlQueryable): Promise<unknown>;
|
|
70
102
|
private interpretNode;
|
|
71
103
|
}
|
|
@@ -75,6 +107,7 @@ export declare type QueryInterpreterOptions = {
|
|
|
75
107
|
placeholderValues: Record<string, unknown>;
|
|
76
108
|
onQuery?: (event: QueryEvent) => void;
|
|
77
109
|
tracingHelper: TracingHelper;
|
|
110
|
+
serializer: (results: SqlResultSet) => Value;
|
|
78
111
|
};
|
|
79
112
|
|
|
80
113
|
export declare type QueryInterpreterTransactionManager = {
|
|
@@ -155,6 +188,21 @@ export declare type QueryPlanNode = {
|
|
|
155
188
|
} | {
|
|
156
189
|
type: 'transaction';
|
|
157
190
|
args: QueryPlanNode;
|
|
191
|
+
} | {
|
|
192
|
+
type: 'dataMap';
|
|
193
|
+
args: {
|
|
194
|
+
expr: QueryPlanNode;
|
|
195
|
+
structure: ResultNode;
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
export declare type ResultNode = {
|
|
200
|
+
type: 'Object';
|
|
201
|
+
fields: Record<string, ResultNode>;
|
|
202
|
+
} | {
|
|
203
|
+
type: 'Value';
|
|
204
|
+
dbName: string;
|
|
205
|
+
resultType: PrismaValueType;
|
|
158
206
|
};
|
|
159
207
|
|
|
160
208
|
declare type SpanCallback<R> = (span?: Span, context?: Context) => R;
|
|
@@ -218,4 +266,9 @@ export declare class UserFacingError extends Error {
|
|
|
218
266
|
};
|
|
219
267
|
}
|
|
220
268
|
|
|
269
|
+
/**
|
|
270
|
+
* The general type of values each node can evaluate to.
|
|
271
|
+
*/
|
|
272
|
+
declare type Value = unknown;
|
|
273
|
+
|
|
221
274
|
export { }
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { Span } from '@opentelemetry/api';
|
|
|
4
4
|
import type { SpanOptions } from '@opentelemetry/api';
|
|
5
5
|
import { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
|
|
6
6
|
import { SqlQueryable } from '@prisma/driver-adapter-utils';
|
|
7
|
+
import { SqlResultSet } from '@prisma/driver-adapter-utils';
|
|
7
8
|
import { Transaction } from '@prisma/driver-adapter-utils';
|
|
8
9
|
|
|
9
10
|
declare type ExtendedSpanOptions = SpanOptions & {
|
|
@@ -56,6 +57,31 @@ export declare type PrismaValuePlaceholder = {
|
|
|
56
57
|
};
|
|
57
58
|
};
|
|
58
59
|
|
|
60
|
+
export declare type PrismaValueType = {
|
|
61
|
+
type: 'Any';
|
|
62
|
+
} | {
|
|
63
|
+
type: 'String';
|
|
64
|
+
} | {
|
|
65
|
+
type: 'Int';
|
|
66
|
+
} | {
|
|
67
|
+
type: 'BigInt';
|
|
68
|
+
} | {
|
|
69
|
+
type: 'Float';
|
|
70
|
+
} | {
|
|
71
|
+
type: 'Boolean';
|
|
72
|
+
} | {
|
|
73
|
+
type: 'Decimal';
|
|
74
|
+
} | {
|
|
75
|
+
type: 'Date';
|
|
76
|
+
} | {
|
|
77
|
+
type: 'Array';
|
|
78
|
+
inner: PrismaValueType;
|
|
79
|
+
} | {
|
|
80
|
+
type: 'Object';
|
|
81
|
+
} | {
|
|
82
|
+
type: 'Bytes';
|
|
83
|
+
};
|
|
84
|
+
|
|
59
85
|
export declare type QueryEvent = {
|
|
60
86
|
timestamp: Date;
|
|
61
87
|
query: string;
|
|
@@ -65,7 +91,13 @@ export declare type QueryEvent = {
|
|
|
65
91
|
|
|
66
92
|
export declare class QueryInterpreter {
|
|
67
93
|
#private;
|
|
68
|
-
constructor({ transactionManager, placeholderValues, onQuery, tracingHelper }: QueryInterpreterOptions);
|
|
94
|
+
constructor({ transactionManager, placeholderValues, onQuery, tracingHelper, serializer }: QueryInterpreterOptions);
|
|
95
|
+
static forSql(options: {
|
|
96
|
+
transactionManager: QueryInterpreterTransactionManager;
|
|
97
|
+
placeholderValues: Record<string, unknown>;
|
|
98
|
+
onQuery?: (event: QueryEvent) => void;
|
|
99
|
+
tracingHelper: TracingHelper;
|
|
100
|
+
}): QueryInterpreter;
|
|
69
101
|
run(queryPlan: QueryPlanNode, queryable: SqlQueryable): Promise<unknown>;
|
|
70
102
|
private interpretNode;
|
|
71
103
|
}
|
|
@@ -75,6 +107,7 @@ export declare type QueryInterpreterOptions = {
|
|
|
75
107
|
placeholderValues: Record<string, unknown>;
|
|
76
108
|
onQuery?: (event: QueryEvent) => void;
|
|
77
109
|
tracingHelper: TracingHelper;
|
|
110
|
+
serializer: (results: SqlResultSet) => Value;
|
|
78
111
|
};
|
|
79
112
|
|
|
80
113
|
export declare type QueryInterpreterTransactionManager = {
|
|
@@ -155,6 +188,21 @@ export declare type QueryPlanNode = {
|
|
|
155
188
|
} | {
|
|
156
189
|
type: 'transaction';
|
|
157
190
|
args: QueryPlanNode;
|
|
191
|
+
} | {
|
|
192
|
+
type: 'dataMap';
|
|
193
|
+
args: {
|
|
194
|
+
expr: QueryPlanNode;
|
|
195
|
+
structure: ResultNode;
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
export declare type ResultNode = {
|
|
200
|
+
type: 'Object';
|
|
201
|
+
fields: Record<string, ResultNode>;
|
|
202
|
+
} | {
|
|
203
|
+
type: 'Value';
|
|
204
|
+
dbName: string;
|
|
205
|
+
resultType: PrismaValueType;
|
|
158
206
|
};
|
|
159
207
|
|
|
160
208
|
declare type SpanCallback<R> = (span?: Span, context?: Context) => R;
|
|
@@ -218,4 +266,9 @@ export declare class UserFacingError extends Error {
|
|
|
218
266
|
};
|
|
219
267
|
}
|
|
220
268
|
|
|
269
|
+
/**
|
|
270
|
+
* The general type of values each node can evaluate to.
|
|
271
|
+
*/
|
|
272
|
+
declare type Value = unknown;
|
|
273
|
+
|
|
221
274
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -210,6 +210,100 @@ function renderConstraint(constraint) {
|
|
|
210
210
|
return "(not available)";
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
// src/interpreter/DataMapper.ts
|
|
214
|
+
function applyDataMap(data, structure) {
|
|
215
|
+
switch (structure.type) {
|
|
216
|
+
case "Object":
|
|
217
|
+
return mapArrayOrObject(data, structure.fields);
|
|
218
|
+
case "Value":
|
|
219
|
+
return mapValue(data, structure.resultType);
|
|
220
|
+
default:
|
|
221
|
+
assertNever(structure, `Invalid data mapping type: '${structure.type}'`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function mapArrayOrObject(data, fields) {
|
|
225
|
+
if (data === null) return null;
|
|
226
|
+
if (Array.isArray(data)) {
|
|
227
|
+
const rows = data;
|
|
228
|
+
return rows.map((row) => mapObject(row, fields));
|
|
229
|
+
}
|
|
230
|
+
if (typeof data === "object") {
|
|
231
|
+
const row = data;
|
|
232
|
+
return mapObject(row, fields);
|
|
233
|
+
}
|
|
234
|
+
throw new Error(`DataMapper: Expected an array or an object, got: ${typeof data}`);
|
|
235
|
+
}
|
|
236
|
+
function mapObject(data, fields) {
|
|
237
|
+
if (typeof data !== "object") {
|
|
238
|
+
throw new Error(`DataMapper: Expected an object, but got '${typeof data}'`);
|
|
239
|
+
}
|
|
240
|
+
const result = {};
|
|
241
|
+
for (const [name, node] of Object.entries(fields)) {
|
|
242
|
+
switch (node.type) {
|
|
243
|
+
case "Object":
|
|
244
|
+
if (Object.hasOwn(data, name)) {
|
|
245
|
+
result[name] = mapArrayOrObject(data[name], node.fields);
|
|
246
|
+
} else {
|
|
247
|
+
throw new Error(
|
|
248
|
+
`DataMapper: Missing data field (Object): '${name}'; node: ${JSON.stringify(node)}; data: ${JSON.stringify(data)}`
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
break;
|
|
252
|
+
case "Value":
|
|
253
|
+
{
|
|
254
|
+
const dbName = node.dbName;
|
|
255
|
+
if (Object.hasOwn(data, dbName)) {
|
|
256
|
+
result[name] = mapValue(data[dbName], node.resultType);
|
|
257
|
+
} else {
|
|
258
|
+
throw new Error(
|
|
259
|
+
`DataMapper: Missing data field (Value): '${dbName}'; node: ${JSON.stringify(node)}; data: ${JSON.stringify(data)}`
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
break;
|
|
264
|
+
default:
|
|
265
|
+
assertNever(node, `DataMapper: Invalid data mapping node type: '${node.type}'`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return result;
|
|
269
|
+
}
|
|
270
|
+
function mapValue(value, resultType) {
|
|
271
|
+
if (value === null) return null;
|
|
272
|
+
switch (resultType.type) {
|
|
273
|
+
case "Any":
|
|
274
|
+
return value;
|
|
275
|
+
case "String":
|
|
276
|
+
return typeof value === "string" ? value : `${value}`;
|
|
277
|
+
case "Int":
|
|
278
|
+
return typeof value === "number" ? value : parseInt(`${value}`, 10);
|
|
279
|
+
case "BigInt":
|
|
280
|
+
return typeof value === "bigint" ? value : BigInt(`${value}`);
|
|
281
|
+
case "Float":
|
|
282
|
+
return typeof value === "number" ? value : parseFloat(`${value}`);
|
|
283
|
+
case "Boolean":
|
|
284
|
+
return typeof value === "boolean" ? value : value !== "0";
|
|
285
|
+
case "Decimal":
|
|
286
|
+
return typeof value === "number" ? value : parseFloat(`${value}`);
|
|
287
|
+
case "Date":
|
|
288
|
+
return value instanceof Date ? value : /* @__PURE__ */ new Date(`${value}`);
|
|
289
|
+
case "Array": {
|
|
290
|
+
const values = value;
|
|
291
|
+
return values.map((v) => {
|
|
292
|
+
mapValue(v, resultType.inner);
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
case "Object":
|
|
296
|
+
return typeof value === "object" ? value : { value };
|
|
297
|
+
case "Bytes":
|
|
298
|
+
if (typeof value !== "string") {
|
|
299
|
+
throw new Error(`DataMapper: Bytes data is not a string, got: ${typeof value}`);
|
|
300
|
+
}
|
|
301
|
+
return value;
|
|
302
|
+
default:
|
|
303
|
+
assertNever(resultType, `DataMapper: Unknown result type: ${resultType.type}`);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
213
307
|
// src/interpreter/generators.ts
|
|
214
308
|
var import_cuid = __toESM(require("@bugsnag/cuid"));
|
|
215
309
|
var import_cuid2 = require("@paralleldrive/cuid2");
|
|
@@ -468,8 +562,8 @@ function doesRequireEvaluation(param) {
|
|
|
468
562
|
return isPrismaValuePlaceholder(param) || isPrismaValueGenerator(param);
|
|
469
563
|
}
|
|
470
564
|
|
|
471
|
-
// src/interpreter/
|
|
472
|
-
function
|
|
565
|
+
// src/interpreter/serializeSql.ts
|
|
566
|
+
function serializeSql(resultSet) {
|
|
473
567
|
return resultSet.rows.map(
|
|
474
568
|
(row) => row.reduce((acc, value, index) => {
|
|
475
569
|
const splitByDot = resultSet.columnNames[index].split(".");
|
|
@@ -491,17 +585,28 @@ function serialize(resultSet) {
|
|
|
491
585
|
}
|
|
492
586
|
|
|
493
587
|
// src/interpreter/QueryInterpreter.ts
|
|
494
|
-
var QueryInterpreter = class {
|
|
588
|
+
var QueryInterpreter = class _QueryInterpreter {
|
|
495
589
|
#transactionManager;
|
|
496
590
|
#placeholderValues;
|
|
497
591
|
#onQuery;
|
|
498
592
|
#generators = new GeneratorRegistry();
|
|
499
593
|
#tracingHelper;
|
|
500
|
-
|
|
594
|
+
#serializer;
|
|
595
|
+
constructor({ transactionManager, placeholderValues, onQuery, tracingHelper, serializer }) {
|
|
501
596
|
this.#transactionManager = transactionManager;
|
|
502
597
|
this.#placeholderValues = placeholderValues;
|
|
503
598
|
this.#onQuery = onQuery;
|
|
504
599
|
this.#tracingHelper = tracingHelper;
|
|
600
|
+
this.#serializer = serializer;
|
|
601
|
+
}
|
|
602
|
+
static forSql(options) {
|
|
603
|
+
return new _QueryInterpreter({
|
|
604
|
+
transactionManager: options.transactionManager,
|
|
605
|
+
placeholderValues: options.placeholderValues,
|
|
606
|
+
onQuery: options.onQuery,
|
|
607
|
+
tracingHelper: options.tracingHelper,
|
|
608
|
+
serializer: serializeSql
|
|
609
|
+
});
|
|
505
610
|
}
|
|
506
611
|
async run(queryPlan, queryable) {
|
|
507
612
|
return this.interpretNode(queryPlan, queryable, this.#placeholderValues, this.#generators.snapshot()).catch(
|
|
@@ -552,7 +657,7 @@ var QueryInterpreter = class {
|
|
|
552
657
|
case "query": {
|
|
553
658
|
const query = renderQuery(node.args, scope, generators);
|
|
554
659
|
return this.#withQueryEvent(query, queryable, async () => {
|
|
555
|
-
return
|
|
660
|
+
return this.#serializer(await queryable.queryRaw(query));
|
|
556
661
|
});
|
|
557
662
|
}
|
|
558
663
|
case "reverse": {
|
|
@@ -602,7 +707,7 @@ var QueryInterpreter = class {
|
|
|
602
707
|
}
|
|
603
708
|
const transactionManager = this.#transactionManager.manager;
|
|
604
709
|
const transactionInfo = await transactionManager.startTransaction();
|
|
605
|
-
const transaction = transactionManager.getTransaction(transactionInfo, "
|
|
710
|
+
const transaction = transactionManager.getTransaction(transactionInfo, "query");
|
|
606
711
|
try {
|
|
607
712
|
const value = await this.interpretNode(node.args, transaction, scope, generators);
|
|
608
713
|
await transactionManager.commitTransaction(transactionInfo.id);
|
|
@@ -612,6 +717,10 @@ var QueryInterpreter = class {
|
|
|
612
717
|
throw e;
|
|
613
718
|
}
|
|
614
719
|
}
|
|
720
|
+
case "dataMap": {
|
|
721
|
+
const data = await this.interpretNode(node.args.expr, queryable, scope, generators);
|
|
722
|
+
return applyDataMap(data, node.args.structure);
|
|
723
|
+
}
|
|
615
724
|
default:
|
|
616
725
|
assertNever(node, `Unexpected node type: ${node.type}`);
|
|
617
726
|
}
|
|
@@ -734,7 +843,7 @@ var TransactionClosedError = class extends TransactionManagerError {
|
|
|
734
843
|
};
|
|
735
844
|
var TransactionRolledBackError = class extends TransactionManagerError {
|
|
736
845
|
constructor(operation) {
|
|
737
|
-
super(`Transaction already closed: A ${operation} cannot be executed on a
|
|
846
|
+
super(`Transaction already closed: A ${operation} cannot be executed on a transaction that was rolled back`);
|
|
738
847
|
}
|
|
739
848
|
};
|
|
740
849
|
var TransactionStartTimeoutError = class extends TransactionManagerError {
|
package/dist/index.mjs
CHANGED
|
@@ -168,6 +168,100 @@ function renderConstraint(constraint) {
|
|
|
168
168
|
return "(not available)";
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
// src/interpreter/DataMapper.ts
|
|
172
|
+
function applyDataMap(data, structure) {
|
|
173
|
+
switch (structure.type) {
|
|
174
|
+
case "Object":
|
|
175
|
+
return mapArrayOrObject(data, structure.fields);
|
|
176
|
+
case "Value":
|
|
177
|
+
return mapValue(data, structure.resultType);
|
|
178
|
+
default:
|
|
179
|
+
assertNever(structure, `Invalid data mapping type: '${structure.type}'`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function mapArrayOrObject(data, fields) {
|
|
183
|
+
if (data === null) return null;
|
|
184
|
+
if (Array.isArray(data)) {
|
|
185
|
+
const rows = data;
|
|
186
|
+
return rows.map((row) => mapObject(row, fields));
|
|
187
|
+
}
|
|
188
|
+
if (typeof data === "object") {
|
|
189
|
+
const row = data;
|
|
190
|
+
return mapObject(row, fields);
|
|
191
|
+
}
|
|
192
|
+
throw new Error(`DataMapper: Expected an array or an object, got: ${typeof data}`);
|
|
193
|
+
}
|
|
194
|
+
function mapObject(data, fields) {
|
|
195
|
+
if (typeof data !== "object") {
|
|
196
|
+
throw new Error(`DataMapper: Expected an object, but got '${typeof data}'`);
|
|
197
|
+
}
|
|
198
|
+
const result = {};
|
|
199
|
+
for (const [name, node] of Object.entries(fields)) {
|
|
200
|
+
switch (node.type) {
|
|
201
|
+
case "Object":
|
|
202
|
+
if (Object.hasOwn(data, name)) {
|
|
203
|
+
result[name] = mapArrayOrObject(data[name], node.fields);
|
|
204
|
+
} else {
|
|
205
|
+
throw new Error(
|
|
206
|
+
`DataMapper: Missing data field (Object): '${name}'; node: ${JSON.stringify(node)}; data: ${JSON.stringify(data)}`
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
break;
|
|
210
|
+
case "Value":
|
|
211
|
+
{
|
|
212
|
+
const dbName = node.dbName;
|
|
213
|
+
if (Object.hasOwn(data, dbName)) {
|
|
214
|
+
result[name] = mapValue(data[dbName], node.resultType);
|
|
215
|
+
} else {
|
|
216
|
+
throw new Error(
|
|
217
|
+
`DataMapper: Missing data field (Value): '${dbName}'; node: ${JSON.stringify(node)}; data: ${JSON.stringify(data)}`
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
break;
|
|
222
|
+
default:
|
|
223
|
+
assertNever(node, `DataMapper: Invalid data mapping node type: '${node.type}'`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return result;
|
|
227
|
+
}
|
|
228
|
+
function mapValue(value, resultType) {
|
|
229
|
+
if (value === null) return null;
|
|
230
|
+
switch (resultType.type) {
|
|
231
|
+
case "Any":
|
|
232
|
+
return value;
|
|
233
|
+
case "String":
|
|
234
|
+
return typeof value === "string" ? value : `${value}`;
|
|
235
|
+
case "Int":
|
|
236
|
+
return typeof value === "number" ? value : parseInt(`${value}`, 10);
|
|
237
|
+
case "BigInt":
|
|
238
|
+
return typeof value === "bigint" ? value : BigInt(`${value}`);
|
|
239
|
+
case "Float":
|
|
240
|
+
return typeof value === "number" ? value : parseFloat(`${value}`);
|
|
241
|
+
case "Boolean":
|
|
242
|
+
return typeof value === "boolean" ? value : value !== "0";
|
|
243
|
+
case "Decimal":
|
|
244
|
+
return typeof value === "number" ? value : parseFloat(`${value}`);
|
|
245
|
+
case "Date":
|
|
246
|
+
return value instanceof Date ? value : /* @__PURE__ */ new Date(`${value}`);
|
|
247
|
+
case "Array": {
|
|
248
|
+
const values = value;
|
|
249
|
+
return values.map((v) => {
|
|
250
|
+
mapValue(v, resultType.inner);
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
case "Object":
|
|
254
|
+
return typeof value === "object" ? value : { value };
|
|
255
|
+
case "Bytes":
|
|
256
|
+
if (typeof value !== "string") {
|
|
257
|
+
throw new Error(`DataMapper: Bytes data is not a string, got: ${typeof value}`);
|
|
258
|
+
}
|
|
259
|
+
return value;
|
|
260
|
+
default:
|
|
261
|
+
assertNever(resultType, `DataMapper: Unknown result type: ${resultType.type}`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
171
265
|
// src/interpreter/generators.ts
|
|
172
266
|
import cuid1 from "@bugsnag/cuid";
|
|
173
267
|
import { createId as cuid2 } from "@paralleldrive/cuid2";
|
|
@@ -426,8 +520,8 @@ function doesRequireEvaluation(param) {
|
|
|
426
520
|
return isPrismaValuePlaceholder(param) || isPrismaValueGenerator(param);
|
|
427
521
|
}
|
|
428
522
|
|
|
429
|
-
// src/interpreter/
|
|
430
|
-
function
|
|
523
|
+
// src/interpreter/serializeSql.ts
|
|
524
|
+
function serializeSql(resultSet) {
|
|
431
525
|
return resultSet.rows.map(
|
|
432
526
|
(row) => row.reduce((acc, value, index) => {
|
|
433
527
|
const splitByDot = resultSet.columnNames[index].split(".");
|
|
@@ -449,17 +543,28 @@ function serialize(resultSet) {
|
|
|
449
543
|
}
|
|
450
544
|
|
|
451
545
|
// src/interpreter/QueryInterpreter.ts
|
|
452
|
-
var QueryInterpreter = class {
|
|
546
|
+
var QueryInterpreter = class _QueryInterpreter {
|
|
453
547
|
#transactionManager;
|
|
454
548
|
#placeholderValues;
|
|
455
549
|
#onQuery;
|
|
456
550
|
#generators = new GeneratorRegistry();
|
|
457
551
|
#tracingHelper;
|
|
458
|
-
|
|
552
|
+
#serializer;
|
|
553
|
+
constructor({ transactionManager, placeholderValues, onQuery, tracingHelper, serializer }) {
|
|
459
554
|
this.#transactionManager = transactionManager;
|
|
460
555
|
this.#placeholderValues = placeholderValues;
|
|
461
556
|
this.#onQuery = onQuery;
|
|
462
557
|
this.#tracingHelper = tracingHelper;
|
|
558
|
+
this.#serializer = serializer;
|
|
559
|
+
}
|
|
560
|
+
static forSql(options) {
|
|
561
|
+
return new _QueryInterpreter({
|
|
562
|
+
transactionManager: options.transactionManager,
|
|
563
|
+
placeholderValues: options.placeholderValues,
|
|
564
|
+
onQuery: options.onQuery,
|
|
565
|
+
tracingHelper: options.tracingHelper,
|
|
566
|
+
serializer: serializeSql
|
|
567
|
+
});
|
|
463
568
|
}
|
|
464
569
|
async run(queryPlan, queryable) {
|
|
465
570
|
return this.interpretNode(queryPlan, queryable, this.#placeholderValues, this.#generators.snapshot()).catch(
|
|
@@ -510,7 +615,7 @@ var QueryInterpreter = class {
|
|
|
510
615
|
case "query": {
|
|
511
616
|
const query = renderQuery(node.args, scope, generators);
|
|
512
617
|
return this.#withQueryEvent(query, queryable, async () => {
|
|
513
|
-
return
|
|
618
|
+
return this.#serializer(await queryable.queryRaw(query));
|
|
514
619
|
});
|
|
515
620
|
}
|
|
516
621
|
case "reverse": {
|
|
@@ -560,7 +665,7 @@ var QueryInterpreter = class {
|
|
|
560
665
|
}
|
|
561
666
|
const transactionManager = this.#transactionManager.manager;
|
|
562
667
|
const transactionInfo = await transactionManager.startTransaction();
|
|
563
|
-
const transaction = transactionManager.getTransaction(transactionInfo, "
|
|
668
|
+
const transaction = transactionManager.getTransaction(transactionInfo, "query");
|
|
564
669
|
try {
|
|
565
670
|
const value = await this.interpretNode(node.args, transaction, scope, generators);
|
|
566
671
|
await transactionManager.commitTransaction(transactionInfo.id);
|
|
@@ -570,6 +675,10 @@ var QueryInterpreter = class {
|
|
|
570
675
|
throw e;
|
|
571
676
|
}
|
|
572
677
|
}
|
|
678
|
+
case "dataMap": {
|
|
679
|
+
const data = await this.interpretNode(node.args.expr, queryable, scope, generators);
|
|
680
|
+
return applyDataMap(data, node.args.structure);
|
|
681
|
+
}
|
|
573
682
|
default:
|
|
574
683
|
assertNever(node, `Unexpected node type: ${node.type}`);
|
|
575
684
|
}
|
|
@@ -692,7 +801,7 @@ var TransactionClosedError = class extends TransactionManagerError {
|
|
|
692
801
|
};
|
|
693
802
|
var TransactionRolledBackError = class extends TransactionManagerError {
|
|
694
803
|
constructor(operation) {
|
|
695
|
-
super(`Transaction already closed: A ${operation} cannot be executed on a
|
|
804
|
+
super(`Transaction already closed: A ${operation} cannot be executed on a transaction that was rolled back`);
|
|
696
805
|
}
|
|
697
806
|
};
|
|
698
807
|
var TransactionStartTimeoutError = class extends TransactionManagerError {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { SqlQueryable } from '@prisma/driver-adapter-utils';
|
|
1
|
+
import { SqlQueryable, SqlResultSet } from '@prisma/driver-adapter-utils';
|
|
2
2
|
import { QueryEvent } from '../events';
|
|
3
3
|
import { QueryPlanNode } from '../QueryPlan';
|
|
4
4
|
import { type TracingHelper } from '../tracing';
|
|
5
5
|
import { type TransactionManager } from '../transactionManager/TransactionManager';
|
|
6
|
+
import { Value } from './scope';
|
|
6
7
|
export type QueryInterpreterTransactionManager = {
|
|
7
8
|
enabled: true;
|
|
8
9
|
manager: TransactionManager;
|
|
@@ -14,10 +15,17 @@ export type QueryInterpreterOptions = {
|
|
|
14
15
|
placeholderValues: Record<string, unknown>;
|
|
15
16
|
onQuery?: (event: QueryEvent) => void;
|
|
16
17
|
tracingHelper: TracingHelper;
|
|
18
|
+
serializer: (results: SqlResultSet) => Value;
|
|
17
19
|
};
|
|
18
20
|
export declare class QueryInterpreter {
|
|
19
21
|
#private;
|
|
20
|
-
constructor({ transactionManager, placeholderValues, onQuery, tracingHelper }: QueryInterpreterOptions);
|
|
22
|
+
constructor({ transactionManager, placeholderValues, onQuery, tracingHelper, serializer }: QueryInterpreterOptions);
|
|
23
|
+
static forSql(options: {
|
|
24
|
+
transactionManager: QueryInterpreterTransactionManager;
|
|
25
|
+
placeholderValues: Record<string, unknown>;
|
|
26
|
+
onQuery?: (event: QueryEvent) => void;
|
|
27
|
+
tracingHelper: TracingHelper;
|
|
28
|
+
}): QueryInterpreter;
|
|
21
29
|
run(queryPlan: QueryPlanNode, queryable: SqlQueryable): Promise<unknown>;
|
|
22
30
|
private interpretNode;
|
|
23
31
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/client-engine-runtime",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.8.0-dev.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",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"nanoid": "5.1.5",
|
|
31
31
|
"ulid": "3.0.0",
|
|
32
32
|
"uuid": "11.1.0",
|
|
33
|
-
"@prisma/debug": "6.
|
|
34
|
-
"@prisma/driver-adapter-utils": "6.
|
|
33
|
+
"@prisma/debug": "6.8.0-dev.1",
|
|
34
|
+
"@prisma/driver-adapter-utils": "6.8.0-dev.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/jest": "29.5.14",
|
|
File without changes
|