// The autobase spelling of the core's writer-set contract.
//
// ⛔ THIS FILE IS THE TRAP, ISOLATED SO IT CAN BE TESTED.
//
// hyper-identity-core's apply calls `host.addWriter(key, { isIndexer })` — one vocabulary, so the
// core never has to know which engine it is running on. autobase spells the same option
// `{ indexer }`. autobee spells it `{ isIndexer }` and, crucially, DEFAULTS IT TO TRUE
// (autobee 2.1.0 lib/apply-calls.js:33: `addWriter(key, { isIndexer = true, weight = isIndexer ? 2 : 1 })`).
//
// So a mechanical port in either direction fails SILENTLY and in opposite ways: autobase receives
// an option it does not know and quietly makes a plain writer where an indexer was meant; autobee
// receives an option it does not know and quietly makes an INDEXER out of every writer — the thing
// identity-registry.js warns in its own comment deadlocks a manifest migration at 2→3 indexers.
//
// Neither engine errors. Both look fine. That is why the translation is a named unit with a test
// rather than an object literal buried in a constructor.
export function adaptHost (host) {
if (!host || typeof host.addWriter !== 'function') return host
return {
...host,
addWriter: (key, opts = {}) => host.addWriter(key, { indexer: !!opts.isIndexer }),
removeWriter: (key) => host.removeWriter(key)
}
}
export default adaptHost