// IdentityRegistry — the AUTOBEE binding of hyper-identity-core's registry.
//
// Sibling of `hyper-identity`, which is the autobase binding. Same class, same ops, same apply,
// same reads — the engine is a package, not an option, so nothing here can silently be the other
// one.
import Autobee from 'autobee'
import { BaseIdentityRegistry } from 'hyper-identity-core/registry'
import { Hyperbee2View } from './view-shim.js'
import { adaptHost } from './adapt-host.js'
export class IdentityRegistry extends BaseIdentityRegistry {
static engine = 'autobee'
_adaptHost () { return adaptHost }
// ⛔ autobee attributes an op to `node.key`; autobase to `node.from.key`. Without this the core's
// contract check reads an undefined `node.from` and skips — a permission gate that stops gating
// with no error.
_writerKeyOf (node) { return node && node.key ? node.key : null }
async _createBase ({ apply, rootKey }) {
// ⛔ `fastForward` is NOT the same option here. autobase takes `{ key }` — the log's key.
// autobee takes a BOOT HEAD, `{ boot: { head: { key, length } } }` naming a writer's core at a
// length, which a joiner cannot derive from a log key: it has to be conveyed or remembered.
//
// So `fastForwardTo` has no autobee meaning, and quietly ignoring it would be the same class of
// bug as the addWriter flag — an option accepted and dropped.
if (this._fastForwardTo) {
throw new Error(
'hyper-identity2: fastForwardTo is an autobase option and has no autobee equivalent — ' +
'autobee fast-forward needs an oplog BOOT HEAD ({ key, length } of a writer core), not a ' +
'log key. Omit it, or convey a head and pass fastForward directly.')
}
return new Autobee(this._store, rootKey, {
apply,
// autobee's open() receives a hyperbee2 INSTANCE, where autobase's receives a store. That
// one-line difference is why the view shim exists.
open: (bee) => new Hyperbee2View(bee),
keyPair: this._keyPair || undefined,
optimistic: true,
// ⚠ OFF, deliberately, and not a workaround. Unconfigured, autobee PROBES for candidate
// oplog heads and pays DEFAULT_OP_TIMEOUT (5s, lib/constants.js:5) per wakeup batch looking
// for something that does not exist when there are no stamped heads. Measured at 25 writers:
// 25s versus 0.2s. Declining to search is not the same as disabling a feature that works.
fastForward: false
})
}
}
export default IdentityRegistry