UNPKG

@mastra/core

Version:
37 lines 2.01 kB
/** * Safely JSON-stringifies a value, replacing circular references with "[Circular]". * Uses a stack-based approach so shared (non-circular) references are preserved. */ export declare function safeStringify(value: unknown, space?: string | number): string; /** * Serialize a value to JSON while visiting no more than * `SERIALIZATION_NODE_BUDGET` nodes. Returns the JSON string, or `undefined` * when the value cannot be represented as JSON: it threw (a cycle or BigInt), * exhausted the budget (a shared-reference graph `JSON.stringify` would expand * exponentially), or produced no output (top-level `undefined`, a function, a * symbol, or an object whose `toJSON()` returns `undefined`). * * The value is read exactly once, so a caller that needs both a serializability * check and the serialized result can use this rather than probing and then * re-serializing — closing a TOCTOU gap where a stateful getter/`toJSON()` * returns a different (e.g. much larger) value the second time. */ export declare function boundedStringify(value: unknown): string | undefined; /** * Whether `value` can be serialized to JSON within `SERIALIZATION_NODE_BUDGET` * nodes. `false` for cycles, BigInt, over-budget shared-reference graphs, and * values that produce no JSON output (top-level undefined/function/symbol, or an * object whose `toJSON()` returns undefined). */ export declare function isBoundedSerializable(value: unknown): boolean; /** * Returns a JSON-serializable copy of a value. * * If the value already serializes within the node budget it is returned * unchanged (no cloning overhead). Otherwise — a cycle, a BigInt, or a * shared-reference graph too large for the probe — it is rebuilt through * `collapseStringify`, which dedupes repeated references to `[Circular]` and so * completes in bounded time instead of hanging on the exponential expansion. */ export declare function ensureSerializable(value: unknown): unknown; //# sourceMappingURL=safe-stringify.d.ts.map