OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-social / hyper-board / lib / board.js

86 lines · javascript ref:
import Corestore from 'corestore'
import Hyperbee from 'hyperbee'
import { BoardStore } from './board-store.js'

class Board {
  constructor (storage, opts = {}) {
    this.store = new Corestore(storage)
    this.bee = new Hyperbee(this.store.get({ name: 'board' }), {
      keyEncoding: 'utf-8',
      valueEncoding: 'json'
    })
    this.boardStore = new BoardStore(this.bee)
    this.name = opts.name || 'Board'
  }

  async ready () {
    await this.store.ready()
    await this.boardStore.ready()
  }

  // Card CRUD
  async createCard (opts) {
    return this.boardStore.createCard(opts)
  }

  async getCard (id) {
    return this.boardStore.getCard(id)
  }

  async updateCard (id, updates) {
    return this.boardStore.updateCard(id, updates)
  }

  async deleteCard (id) {
    return this.boardStore.deleteCard(id)
  }

  async moveCard (id, lane) {
    return this.boardStore.moveCard(id, lane)
  }

  // Lane management
  async addLane (name, order) {
    return this.boardStore.addLane(name, order)
  }

  async removeLane (name) {
    return this.boardStore.removeLane(name)
  }

  async listLanes () {
    return this.boardStore.listLanes()
  }

  // Queries
  async listCards (opts) {
    return this.boardStore.listCards(opts)
  }

  async search (query) {
    return this.boardStore.search(query)
  }

  async stats () {
    return this.boardStore.stats()
  }

  // Get board view — all lanes with their cards
  async view () {
    const lanes = await this.listLanes()
    const allCards = await this.listCards()

    return lanes.map(lane => ({
      name: lane.name,
      order: lane.order,
      cards: allCards.filter(c => c.lane === lane.name)
    }))
  }

  async close () {
    await this.store.close()
  }
}

export { Board }