OverviewFilesCommitsIssuesDocsReleasesPeers

keet-deobfuscated / @holepunchto / keet-indexing / lib / private-profile / index.js

38 lines · javascript ref:
const e = require("./private-mailbox"),
  t = require("./private-rooms"),
  i = require("./private-devices")
module.exports = class {
  static Operations = new Set([...e.Operations, ...t.Operations, ...i.Operations])
  constructor(a) {
    ;((this.view = a),
      (this.privateMailbox = new e(this)),
      (this.privateRooms = new t(this)),
      (this.privateDevices = new i(this)))
  }
  initialize() {
    ;(this.privateMailbox.initialize(),
      this.privateRooms.initialize(),
      this.privateDevices.initialize())
  }
  async migrate() {
    const e = this.view.plugins.get("@holepunchto/private-profile")
    if (e) {
      for await (const { _id: t } of e.rooms.createReadStream())
        await this.privateRooms.rooms.update(t, { key: t }, { upsert: !0 })
      for await (const { _id: t, value: i } of e.deviceKeys.createReadStream())
        await this.privateDevices.keys.update(t, i, { upsert: !0 })
      for await (const { _id: t, value: i } of e.deviceAttestations.createReadStream())
        await this.privateDevices.attestations.update(t, i, { upsert: !0 })
    }
  }
  async autobaseApply(a, s) {
    return t.Operations.has(a.type)
      ? this.privateRooms.autobaseApply(a, s)
      : i.Operations.has(a.type)
        ? this.privateDevices.autobaseApply(a, s)
        : e.Operations.has(a.type)
          ? this.privateMailbox.autobaseApply(a, s)
          : void 0
  }
}