Returns a JsonReplacer that inlines ECHO ref objects ({ "/": "echo:..." }) up to
depth ref hops. Beyond that depth refs are left in their encoded form.
Implemented as a per-call JSON.stringify replacer (not a one-shot tree walk at root) so it
composes with wrappers like safeStringify that intercept the root call. JSON.stringify
already drives the recursion; we only need to (a) detect a ref at the current callback,
(b) resolve and return the target if hop budget remains, and (c) tag the returned object
with its hop count so children know how far in they are.
The hop count is tracked per-object via a WeakMap: a ref-resolved target's children inherit
parentHops + 1; a regular intermediate object's children inherit parentHops. This makes the
budget count ref hops, not tree depth — a ref deep in a tree still resolves once when
depth >= 1.
Note: ECHO objects' toJSON runs before the replacer is invoked, so by the time we see a
value refs are already encoded as { "/": "dxn:..." }.
Returns a JsonReplacer that inlines ECHO ref objects (
{ "/": "echo:..." }) up todepthref hops. Beyond that depth refs are left in their encoded form.Implemented as a per-call
JSON.stringifyreplacer (not a one-shot tree walk at root) so it composes with wrappers likesafeStringifythat intercept the root call. JSON.stringify already drives the recursion; we only need to (a) detect a ref at the current callback, (b) resolve and return the target if hop budget remains, and (c) tag the returned object with its hop count so children know how far in they are.The hop count is tracked per-object via a
WeakMap: a ref-resolved target's children inheritparentHops + 1; a regular intermediate object's children inheritparentHops. This makes the budget count ref hops, not tree depth — a ref deep in a tree still resolves once whendepth >= 1.Note: ECHO objects'
toJSONruns before the replacer is invoked, so by the time we see a value refs are already encoded as{ "/": "dxn:..." }.