OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-identity2 / lib / adapt-host.js

25 lines · javascript ref:
// The autobee spelling of the core's writer-set contract.
//
// autobee already speaks `{ isIndexer }`, so this looks like it could be omitted. ⛔ It could not.
//
//     addWriter(key, { isIndexer = true, weight = isIndexer ? 2 : 1 } = {})
//                                 ^^^^ autobee 2.1.0 lib/apply-calls.js:33
//
// The default is TRUE. So the difference between passing the flag and forgetting it is the
// difference between a plain writer and an indexer — and forgetting it is what a "no translation
// needed, just pass through" binding does the first time the core adds a call site that omits it.
//
// Pinning it here means the absent case is decided in the file that knows autobee's defaults,
// rather than inherited from them silently.

export function adaptHost (host) {
  if (!host || typeof host.addWriter !== 'function') return host
  return {
    ...host,
    addWriter: (key, opts = {}) => host.addWriter(key, { isIndexer: !!opts.isIndexer }),
    removeWriter: (key) => host.removeWriter(key)
  }
}

export default adaptHost