mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 09:07:40 +00:00
31 lines
888 B
JavaScript
31 lines
888 B
JavaScript
import { parse, stringify } from 'devalue'
|
|
|
|
const reducers = {
|
|
Error: (value) =>
|
|
value instanceof Error && {
|
|
name: value.name,
|
|
message: value.message,
|
|
stack: value.stack,
|
|
cause: value.cause
|
|
}
|
|
}
|
|
|
|
const revivers = {
|
|
Error: ({ name, message, stack, cause }) => {
|
|
const error = new Error(message, cause === undefined ? undefined : { cause })
|
|
error.name = name
|
|
error.stack = stack
|
|
return error
|
|
}
|
|
}
|
|
|
|
// Preserves RegExp filters, cyclic test results, and Errors (e.g. a failed module fetch) across Bun/Node's JSON-only IPC.
|
|
export function encodeNodeRuntimeMessage(value) {
|
|
return stringify(value, reducers)
|
|
}
|
|
|
|
// Why pass non-strings through: tests that fake a parent with process.emit('message') reach this listener too.
|
|
export function decodeNodeRuntimeMessage(text) {
|
|
return typeof text === 'string' ? parse(text, revivers) : text
|
|
}
|