@prisma/client-engine-runtime 6.9.0-dev.25 → 6.9.0-dev.27
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.js +96 -24
- package/dist/index.mjs +96 -24
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -96,7 +96,7 @@ function applyDataMap(data, structure) {
|
|
|
96
96
|
case "Object":
|
|
97
97
|
return mapArrayOrObject(data, structure.fields);
|
|
98
98
|
case "Value":
|
|
99
|
-
return mapValue(data, structure.resultType);
|
|
99
|
+
return mapValue(data, "<result>", structure.resultType);
|
|
100
100
|
default:
|
|
101
101
|
assertNever(structure, `Invalid data mapping type: '${structure.type}'`);
|
|
102
102
|
}
|
|
@@ -145,7 +145,7 @@ function mapObject(data, fields) {
|
|
|
145
145
|
{
|
|
146
146
|
const dbName = node.dbName;
|
|
147
147
|
if (Object.hasOwn(data, dbName)) {
|
|
148
|
-
result[name] = mapValue(data[dbName], node.resultType);
|
|
148
|
+
result[name] = mapValue(data[dbName], dbName, node.resultType);
|
|
149
149
|
} else {
|
|
150
150
|
throw new DataMapperError(
|
|
151
151
|
`Missing data field (Value): '${dbName}'; node: ${JSON.stringify(node)}; data: ${JSON.stringify(data)}`
|
|
@@ -159,41 +159,113 @@ function mapObject(data, fields) {
|
|
|
159
159
|
}
|
|
160
160
|
return result;
|
|
161
161
|
}
|
|
162
|
-
function mapValue(value, resultType) {
|
|
162
|
+
function mapValue(value, columnName, resultType) {
|
|
163
163
|
if (value === null) return null;
|
|
164
164
|
switch (resultType.type) {
|
|
165
165
|
case "Any":
|
|
166
166
|
return value;
|
|
167
|
-
case "String":
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
case "
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
167
|
+
case "String": {
|
|
168
|
+
if (typeof value !== "string") {
|
|
169
|
+
throw new DataMapperError(`Expected a string in column '${columnName}', got ${typeof value}: ${value}`);
|
|
170
|
+
}
|
|
171
|
+
return value;
|
|
172
|
+
}
|
|
173
|
+
case "Int": {
|
|
174
|
+
switch (typeof value) {
|
|
175
|
+
case "number": {
|
|
176
|
+
if (Number.isInteger(value)) {
|
|
177
|
+
return value;
|
|
178
|
+
}
|
|
179
|
+
throw new DataMapperError(`Expected an integer in column '${columnName}', got float: ${value}`);
|
|
180
|
+
}
|
|
181
|
+
case "string": {
|
|
182
|
+
const numberValue = Number(value);
|
|
183
|
+
if (Number.isInteger(numberValue)) {
|
|
184
|
+
return numberValue;
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
BigInt(value);
|
|
188
|
+
} catch {
|
|
189
|
+
throw new DataMapperError(`Expected an integer in column '${columnName}', got string: ${value}`);
|
|
190
|
+
}
|
|
191
|
+
throw new DataMapperError(
|
|
192
|
+
`Integer value in column '${columnName}' is too large to represent as a JavaScript number without loss of precision, got: ${value}. Consider using BigInt type.`
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
default:
|
|
196
|
+
throw new DataMapperError(`Expected an integer in column '${columnName}', got ${typeof value}: ${value}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
case "BigInt": {
|
|
200
|
+
if (typeof value !== "number" && typeof value !== "string") {
|
|
201
|
+
throw new DataMapperError(`Expected a bigint in column '${columnName}', got ${typeof value}: ${value}`);
|
|
202
|
+
}
|
|
203
|
+
return { $type: "BigInt", value };
|
|
204
|
+
}
|
|
205
|
+
case "Float": {
|
|
206
|
+
if (typeof value === "number") return value;
|
|
207
|
+
if (typeof value === "string") {
|
|
208
|
+
const parsedValue = Number(value);
|
|
209
|
+
if (Number.isNaN(parsedValue) && !/^[-+]?nan$/.test(value.toLowerCase())) {
|
|
210
|
+
throw new DataMapperError(`Expected a float in column '${columnName}', got string: ${value}`);
|
|
211
|
+
}
|
|
212
|
+
return parsedValue;
|
|
213
|
+
}
|
|
214
|
+
throw new DataMapperError(`Expected a float in column '${columnName}', got ${typeof value}: ${value}`);
|
|
215
|
+
}
|
|
216
|
+
case "Boolean": {
|
|
217
|
+
if (typeof value === "boolean") return value;
|
|
218
|
+
if (typeof value === "number") return value === 1;
|
|
219
|
+
if (typeof value === "string") {
|
|
220
|
+
if (value === "true" || value === "TRUE" || value === "1") {
|
|
221
|
+
return true;
|
|
222
|
+
} else if (value === "false" || value === "FALSE" || value === "0") {
|
|
223
|
+
return false;
|
|
224
|
+
} else {
|
|
225
|
+
throw new DataMapperError(`Expected a boolean in column '${columnName}', got ${typeof value}: ${value}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
throw new DataMapperError(`Expected a boolean in column '${columnName}', got ${typeof value}: ${value}`);
|
|
229
|
+
}
|
|
177
230
|
case "Decimal":
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
231
|
+
if (typeof value !== "number" && typeof value !== "string" && !import_decimal2.default.isDecimal(value)) {
|
|
232
|
+
throw new DataMapperError(`Expected a decimal in column '${columnName}', got ${typeof value}: ${value}`);
|
|
233
|
+
}
|
|
234
|
+
return { $type: "Decimal", value };
|
|
235
|
+
case "Date": {
|
|
236
|
+
if (typeof value === "string") {
|
|
237
|
+
return { $type: "DateTime", value: ensureTimezoneInIsoString(value) };
|
|
238
|
+
}
|
|
239
|
+
if (typeof value === "number" || value instanceof Date) {
|
|
240
|
+
return { $type: "DateTime", value };
|
|
241
|
+
}
|
|
242
|
+
throw new DataMapperError(`Expected a date in column '${columnName}', got ${typeof value}: ${value}`);
|
|
243
|
+
}
|
|
181
244
|
case "Array": {
|
|
182
245
|
const values = value;
|
|
183
|
-
return values.map((v) => mapValue(v, resultType.inner));
|
|
246
|
+
return values.map((v, i) => mapValue(v, `${columnName}[${i}]`, resultType.inner));
|
|
247
|
+
}
|
|
248
|
+
case "Object": {
|
|
249
|
+
const jsonValue = typeof value === "string" ? value : safeJsonStringify(value);
|
|
250
|
+
return { $type: "Json", value: jsonValue };
|
|
184
251
|
}
|
|
185
|
-
case "Object":
|
|
186
|
-
return typeof value === "string" ? value : JSON.stringify(value);
|
|
187
252
|
case "Bytes": {
|
|
188
|
-
if (
|
|
189
|
-
|
|
253
|
+
if (typeof value === "string" && value.startsWith("\\x")) {
|
|
254
|
+
return { $type: "Bytes", value: Buffer.from(value.slice(2), "hex").toString("base64") };
|
|
255
|
+
}
|
|
256
|
+
if (Array.isArray(value)) {
|
|
257
|
+
return { $type: "Bytes", value: Buffer.from(value).toString("base64") };
|
|
190
258
|
}
|
|
191
|
-
|
|
259
|
+
throw new DataMapperError(`Expected a byte array in column '${columnName}', got ${typeof value}: ${value}`);
|
|
192
260
|
}
|
|
193
261
|
default:
|
|
194
262
|
assertNever(resultType, `DataMapper: Unknown result type: ${resultType.type}`);
|
|
195
263
|
}
|
|
196
264
|
}
|
|
265
|
+
var TIMEZONE_PATTERN = /Z$|[+-]\d{2}(:?\d{2})?$/;
|
|
266
|
+
function ensureTimezoneInIsoString(dt) {
|
|
267
|
+
return TIMEZONE_PATTERN.test(dt) ? dt : `${dt}Z`;
|
|
268
|
+
}
|
|
197
269
|
|
|
198
270
|
// src/tracing.ts
|
|
199
271
|
var import_api = require("@opentelemetry/api");
|
|
@@ -661,9 +733,9 @@ function serializeRawSql(resultSet) {
|
|
|
661
733
|
const mappers = types.map((type) => {
|
|
662
734
|
switch (type) {
|
|
663
735
|
case "int":
|
|
664
|
-
return (value) => typeof value === "number" ? value : parseInt(`${value}`, 10);
|
|
736
|
+
return (value) => value === null ? null : typeof value === "number" ? value : parseInt(`${value}`, 10);
|
|
665
737
|
case "bigint":
|
|
666
|
-
return (value) => typeof value === "bigint" ? value : BigInt(`${value}`);
|
|
738
|
+
return (value) => value === null ? null : typeof value === "bigint" ? value : BigInt(`${value}`);
|
|
667
739
|
default:
|
|
668
740
|
return (value) => value;
|
|
669
741
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -48,7 +48,7 @@ function applyDataMap(data, structure) {
|
|
|
48
48
|
case "Object":
|
|
49
49
|
return mapArrayOrObject(data, structure.fields);
|
|
50
50
|
case "Value":
|
|
51
|
-
return mapValue(data, structure.resultType);
|
|
51
|
+
return mapValue(data, "<result>", structure.resultType);
|
|
52
52
|
default:
|
|
53
53
|
assertNever(structure, `Invalid data mapping type: '${structure.type}'`);
|
|
54
54
|
}
|
|
@@ -97,7 +97,7 @@ function mapObject(data, fields) {
|
|
|
97
97
|
{
|
|
98
98
|
const dbName = node.dbName;
|
|
99
99
|
if (Object.hasOwn(data, dbName)) {
|
|
100
|
-
result[name] = mapValue(data[dbName], node.resultType);
|
|
100
|
+
result[name] = mapValue(data[dbName], dbName, node.resultType);
|
|
101
101
|
} else {
|
|
102
102
|
throw new DataMapperError(
|
|
103
103
|
`Missing data field (Value): '${dbName}'; node: ${JSON.stringify(node)}; data: ${JSON.stringify(data)}`
|
|
@@ -111,41 +111,113 @@ function mapObject(data, fields) {
|
|
|
111
111
|
}
|
|
112
112
|
return result;
|
|
113
113
|
}
|
|
114
|
-
function mapValue(value, resultType) {
|
|
114
|
+
function mapValue(value, columnName, resultType) {
|
|
115
115
|
if (value === null) return null;
|
|
116
116
|
switch (resultType.type) {
|
|
117
117
|
case "Any":
|
|
118
118
|
return value;
|
|
119
|
-
case "String":
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
case "
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
119
|
+
case "String": {
|
|
120
|
+
if (typeof value !== "string") {
|
|
121
|
+
throw new DataMapperError(`Expected a string in column '${columnName}', got ${typeof value}: ${value}`);
|
|
122
|
+
}
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
case "Int": {
|
|
126
|
+
switch (typeof value) {
|
|
127
|
+
case "number": {
|
|
128
|
+
if (Number.isInteger(value)) {
|
|
129
|
+
return value;
|
|
130
|
+
}
|
|
131
|
+
throw new DataMapperError(`Expected an integer in column '${columnName}', got float: ${value}`);
|
|
132
|
+
}
|
|
133
|
+
case "string": {
|
|
134
|
+
const numberValue = Number(value);
|
|
135
|
+
if (Number.isInteger(numberValue)) {
|
|
136
|
+
return numberValue;
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
BigInt(value);
|
|
140
|
+
} catch {
|
|
141
|
+
throw new DataMapperError(`Expected an integer in column '${columnName}', got string: ${value}`);
|
|
142
|
+
}
|
|
143
|
+
throw new DataMapperError(
|
|
144
|
+
`Integer value in column '${columnName}' is too large to represent as a JavaScript number without loss of precision, got: ${value}. Consider using BigInt type.`
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
default:
|
|
148
|
+
throw new DataMapperError(`Expected an integer in column '${columnName}', got ${typeof value}: ${value}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
case "BigInt": {
|
|
152
|
+
if (typeof value !== "number" && typeof value !== "string") {
|
|
153
|
+
throw new DataMapperError(`Expected a bigint in column '${columnName}', got ${typeof value}: ${value}`);
|
|
154
|
+
}
|
|
155
|
+
return { $type: "BigInt", value };
|
|
156
|
+
}
|
|
157
|
+
case "Float": {
|
|
158
|
+
if (typeof value === "number") return value;
|
|
159
|
+
if (typeof value === "string") {
|
|
160
|
+
const parsedValue = Number(value);
|
|
161
|
+
if (Number.isNaN(parsedValue) && !/^[-+]?nan$/.test(value.toLowerCase())) {
|
|
162
|
+
throw new DataMapperError(`Expected a float in column '${columnName}', got string: ${value}`);
|
|
163
|
+
}
|
|
164
|
+
return parsedValue;
|
|
165
|
+
}
|
|
166
|
+
throw new DataMapperError(`Expected a float in column '${columnName}', got ${typeof value}: ${value}`);
|
|
167
|
+
}
|
|
168
|
+
case "Boolean": {
|
|
169
|
+
if (typeof value === "boolean") return value;
|
|
170
|
+
if (typeof value === "number") return value === 1;
|
|
171
|
+
if (typeof value === "string") {
|
|
172
|
+
if (value === "true" || value === "TRUE" || value === "1") {
|
|
173
|
+
return true;
|
|
174
|
+
} else if (value === "false" || value === "FALSE" || value === "0") {
|
|
175
|
+
return false;
|
|
176
|
+
} else {
|
|
177
|
+
throw new DataMapperError(`Expected a boolean in column '${columnName}', got ${typeof value}: ${value}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
throw new DataMapperError(`Expected a boolean in column '${columnName}', got ${typeof value}: ${value}`);
|
|
181
|
+
}
|
|
129
182
|
case "Decimal":
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
183
|
+
if (typeof value !== "number" && typeof value !== "string" && !Decimal2.isDecimal(value)) {
|
|
184
|
+
throw new DataMapperError(`Expected a decimal in column '${columnName}', got ${typeof value}: ${value}`);
|
|
185
|
+
}
|
|
186
|
+
return { $type: "Decimal", value };
|
|
187
|
+
case "Date": {
|
|
188
|
+
if (typeof value === "string") {
|
|
189
|
+
return { $type: "DateTime", value: ensureTimezoneInIsoString(value) };
|
|
190
|
+
}
|
|
191
|
+
if (typeof value === "number" || value instanceof Date) {
|
|
192
|
+
return { $type: "DateTime", value };
|
|
193
|
+
}
|
|
194
|
+
throw new DataMapperError(`Expected a date in column '${columnName}', got ${typeof value}: ${value}`);
|
|
195
|
+
}
|
|
133
196
|
case "Array": {
|
|
134
197
|
const values = value;
|
|
135
|
-
return values.map((v) => mapValue(v, resultType.inner));
|
|
198
|
+
return values.map((v, i) => mapValue(v, `${columnName}[${i}]`, resultType.inner));
|
|
199
|
+
}
|
|
200
|
+
case "Object": {
|
|
201
|
+
const jsonValue = typeof value === "string" ? value : safeJsonStringify(value);
|
|
202
|
+
return { $type: "Json", value: jsonValue };
|
|
136
203
|
}
|
|
137
|
-
case "Object":
|
|
138
|
-
return typeof value === "string" ? value : JSON.stringify(value);
|
|
139
204
|
case "Bytes": {
|
|
140
|
-
if (
|
|
141
|
-
|
|
205
|
+
if (typeof value === "string" && value.startsWith("\\x")) {
|
|
206
|
+
return { $type: "Bytes", value: Buffer.from(value.slice(2), "hex").toString("base64") };
|
|
207
|
+
}
|
|
208
|
+
if (Array.isArray(value)) {
|
|
209
|
+
return { $type: "Bytes", value: Buffer.from(value).toString("base64") };
|
|
142
210
|
}
|
|
143
|
-
|
|
211
|
+
throw new DataMapperError(`Expected a byte array in column '${columnName}', got ${typeof value}: ${value}`);
|
|
144
212
|
}
|
|
145
213
|
default:
|
|
146
214
|
assertNever(resultType, `DataMapper: Unknown result type: ${resultType.type}`);
|
|
147
215
|
}
|
|
148
216
|
}
|
|
217
|
+
var TIMEZONE_PATTERN = /Z$|[+-]\d{2}(:?\d{2})?$/;
|
|
218
|
+
function ensureTimezoneInIsoString(dt) {
|
|
219
|
+
return TIMEZONE_PATTERN.test(dt) ? dt : `${dt}Z`;
|
|
220
|
+
}
|
|
149
221
|
|
|
150
222
|
// src/tracing.ts
|
|
151
223
|
import { SpanKind } from "@opentelemetry/api";
|
|
@@ -613,9 +685,9 @@ function serializeRawSql(resultSet) {
|
|
|
613
685
|
const mappers = types.map((type) => {
|
|
614
686
|
switch (type) {
|
|
615
687
|
case "int":
|
|
616
|
-
return (value) => typeof value === "number" ? value : parseInt(`${value}`, 10);
|
|
688
|
+
return (value) => value === null ? null : typeof value === "number" ? value : parseInt(`${value}`, 10);
|
|
617
689
|
case "bigint":
|
|
618
|
-
return (value) => typeof value === "bigint" ? value : BigInt(`${value}`);
|
|
690
|
+
return (value) => value === null ? null : typeof value === "bigint" ? value : BigInt(`${value}`);
|
|
619
691
|
default:
|
|
620
692
|
return (value) => value;
|
|
621
693
|
}
|
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.27",
|
|
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/debug": "6.9.0-dev.
|
|
35
|
-
"@prisma/driver-adapter-utils": "6.9.0-dev.
|
|
34
|
+
"@prisma/debug": "6.9.0-dev.27",
|
|
35
|
+
"@prisma/driver-adapter-utils": "6.9.0-dev.27"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/jest": "29.5.14",
|