OverviewFilesCommitsIssuesDocsReleasesPeers

pear-git / scripts / check-user.js

37 lines · javascript ref:
#!/usr/bin/env bare

await import('bare-node-runtime/global')

import Corestore from 'corestore'
import Hyperbee from 'hyperbee'

const userId = process.argv[2]

if (!userId) {
  console.error('Usage: bare check-user.js <userId>')
  process.exit(1)
}

const storage = './pear-git-storage'
const store = new Corestore(storage)
const registryCore = store.get({ name: 'registry' })
const registry = new Hyperbee(registryCore, {
  keyEncoding: 'utf-8',
  valueEncoding: 'json'
})

await registry.ready()

const userKey = `user:${userId}`
const userEntry = await registry.get(userKey)

if (!userEntry) {
  console.error(`User not found: ${userId}`)
  process.exit(1)
}

console.log('User object:')
console.log(JSON.stringify(userEntry.value, null, 2))

process.exit(0)