@dxos/echo
    Preparing search index...

    Function createRefReplacer

    • 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:..." }.

      Parameters

      Returns JsonReplacer

      O(k) per object value (isEncodedRef counts its keys), plus a URI parse and an O(target size) toJSON for each ref resolved within depth.