fix(autobase-todo): correct Autobase constructor, open/apply signatures, bootstrap addWriter logic, remove crashing view log

docs: update hyperdrive-fileshare index.js (reader key arg)
This commit is contained in:
Hermes Agent
2026-04-20 02:02:32 -04:00
parent 023afa2f22
commit a312017dc0
2 changed files with 22 additions and 16 deletions
+19 -13
View File
@@ -25,33 +25,39 @@ async function main() {
console.log('w1 key:', w1.key.toString('hex')) console.log('w1 key:', w1.key.toString('hex'))
console.log('w2 key:', w2.key.toString('hex')) // random per storage, replicate to share console.log('w2 key:', w2.key.toString('hex')) // random per storage, replicate to share
async function open (store) { async function open (store, host) {
return store.get({ name: 'merged-todos', valueEncoding: 'json' }) return store.get({ name: 'merged-todos', valueEncoding: 'json' })
} }
async function apply (nodes, view) { async function apply (nodes, view, host) {
for (const { value } of nodes) { for (const node of nodes) {
const { value } = node
if (value === null) continue // skip acks if (value === null) continue // skip acks
if (value.addWriter) {
await host.addWriter(value.addWriter, { indexer: true })
continue
}
await view.append(value) await view.append(value)
} }
} }
let localInput = null const base = new Autobase(corestore, null, {
if (mode === 'writer1') {
localInput = w1
} else if (mode === 'writer2') {
localInput = w2
}
const base = new Autobase([w1, w2], {
localInput,
open, open,
apply apply
}) })
await base.ready() await base.ready()
console.log('Autobase view key:', base.view.key.toString('hex')) // console.log('Autobase view key:', base.view?.key?.toString('hex') || 'not ready')
console.log('Autobase ready, length:', base.length) console.log('Autobase ready, length:', base.length)
// Bootstrap writers
if (mode === 'writer1') {
await base.append({ addWriter: w2.key })
console.log('Bootstrapped writer2')
} else if (mode === 'writer2') {
await base.append({ addWriter: w1.key })
console.log('Bootstrapped writer1')
}
// Fixed swarm topic // Fixed swarm topic
const topic = crypto.createHash('sha256').update('autobase-todo-test').digest() const topic = crypto.createHash('sha256').update('autobase-todo-test').digest()
console.log('Topic:', topic.toString('hex').slice(0, 16) + '...') console.log('Topic:', topic.toString('hex').slice(0, 16) + '...')
+3 -3
View File
@@ -22,8 +22,8 @@ async function main() {
if (isWriter) { if (isWriter) {
const content = 'Test P2P file share content\n' const content = 'Test P2P file share content\n'
await drive.put('test.txt', Buffer.from(content)) await drive.put('/test.txt', Buffer.from(content))
console.log('✅ File written: test.txt') console.log('✅ File written: /test.txt')
console.log('📤 Share this drive key with readers: ' + drive.key.toString('hex')) console.log('📤 Share this drive key with readers: ' + drive.key.toString('hex'))
} else { } else {
console.log('🔍 Connecting to drive key: ' + process.argv[2]) console.log('🔍 Connecting to drive key: ' + process.argv[2])
@@ -41,7 +41,7 @@ async function main() {
if (!isWriter) { if (!isWriter) {
const checkFile = async () => { const checkFile = async () => {
try { try {
const content = await drive.get('test.txt') const content = await drive.get('/test.txt')
if (content) { if (content) {
console.log('📥 File received successfully:') console.log('📥 File received successfully:')
console.log(content.toString()) console.log(content.toString())