Skip to content

Commit 6229234

Browse files
committed
fix: fix test JSON repr issues
1 parent 9d980ce commit 6229234

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

libs/driver-adapters/executor/src/qc-test-worker/worker-query.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
type QueryInterpreterTransactionManager,
1313
QueryPlanNode,
1414
RawResponse,
15-
safeJsonStringify,
1615
type TransactionManager,
1716
UserFacingError,
1817
} from '@prisma/client-engine-runtime'
@@ -302,3 +301,32 @@ function getFullOperationName(query: JsonProtocolQuery): string {
302301
}
303302
}
304303
}
304+
305+
/**
306+
* `JSON.stringify` wrapper with custom replacer function that handles nested
307+
* BigInt and Buffer values.
308+
*/
309+
export function safeJsonStringify(obj: unknown): string {
310+
// Recursively convert any values that we cannot pass
311+
// to JSON.stringify to a serializable format.
312+
// We cannot use the JSON.serialize(obj, transform), because it calls
313+
// `toJSON` methods on objects, which we want to avoid.
314+
function transformValue(value: unknown): unknown {
315+
if (typeof value === 'bigint') {
316+
return value.toString()
317+
} else if (Buffer.isBuffer(value)) {
318+
return value.toString('base64')
319+
} else if (Array.isArray(value)) {
320+
return value.map(transformValue)
321+
} else if (value !== null && typeof value === 'object') {
322+
const result: Record<string, unknown> = {}
323+
for (const [key, val] of Object.entries(value)) {
324+
result[key] = transformValue(val)
325+
}
326+
return result
327+
}
328+
return value
329+
}
330+
331+
return JSON.stringify(transformValue(obj))
332+
}

query-engine/connector-test-kit-rs/query-engine-tests/tests/raw/sql/typed_output.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ mod typed_output {
8989
42,
9090
"9223372036854775807",
9191
1.5432,
92-
"AQID",
92+
[
93+
1,
94+
2,
95+
3
96+
]
9397
true,
9498
"1900-10-10T01:10:10.001+00:00",
9599
"123.4567891",

0 commit comments

Comments
 (0)