Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion libs/driver-adapters/executor/src/qc-test-worker/worker-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
type QueryInterpreterTransactionManager,
QueryPlanNode,
RawResponse,
safeJsonStringify,
type TransactionManager,
UserFacingError,
} from '@prisma/client-engine-runtime'
Expand Down Expand Up @@ -302,3 +301,36 @@ function getFullOperationName(query: JsonProtocolQuery): string {
}
}
}

/**
* `JSON.stringify` wrapper with custom replacer function that handles nested
* BigInt and Buffer values.
*/
export function safeJsonStringify(obj: unknown): string {
// Recursively convert any values that we cannot pass
// to JSON.stringify to a serializable format.
// We cannot use the JSON.serialize(obj, transform), because it calls
// `toJSON` methods on objects, which we want to avoid.
function transformValue(value: unknown): unknown {
if (typeof value === 'bigint') {
return value.toString()
} else if (ArrayBuffer.isView(value)) {
return Buffer.from(
value.buffer,
value.byteOffset,
value.byteLength,
).toString('base64')
} else if (Array.isArray(value)) {
return value.map(transformValue)
} else if (value !== null && typeof value === 'object') {
const result: Record<string, unknown> = {}
for (const [key, val] of Object.entries(value)) {
result[key] = transformValue(val)
}
return result
}
return value
}

return JSON.stringify(transformValue(obj))
}
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,11 @@ mod typed_output {
42,
92233720368,
1.5432,
"AQID",
[
1,
2,
3
],
1,
"1900-10-10T01:10:10.001+00:00",
123.4567891
Expand Down
Loading