OverviewFilesCommitsIssuesDocsReleasesPeers

keet-cli / keet-core-4.14.4-pretty / lib / core / contract / index.js

94 lines · javascript ref:
const e = require("path"),
  r = require("rocksdb-blobs"),
  t = require("hyperblobs"),
  o = require("hyperdb"),
  s = require("../../../schema/spec"),
  {
    contract: {
      hyperdispatch: { Router: i, encode: c },
      hyperdb: n,
    },
  } = s,
  a = require("./identity"),
  b = require("./internal"),
  h = require("./members"),
  u = require("./members/labels"),
  l = require("./chat"),
  d = require("./reactions"),
  p = require("./config"),
  q = require("./labels"),
  m = require("./calls"),
  w = require("./testing"),
  E = require("./registration")
class v {
  constructor(
    e,
    r,
    {
      abi: t,
      bootstrap: o,
      router: s,
      hostcalls: i,
      writer: c,
      genesis: n,
      dryRun: a,
      trace: b,
      fork: h,
    },
  ) {
    if (
      ((this.db = e),
      (this.blobs = r),
      (this.writer = c),
      (this.genesis = !!n),
      (this.bootstrap = o),
      (this.router = s),
      (this.hostcalls = i),
      (this.dryRun = a),
      (this.trace = b),
      (this.fork = h),
      (this.abi = t),
      !i.addWriter)
    )
      throw new Error("An addWriter hostcall must be provided as context")
    if (!i.removeWriter) throw new Error("A removeWriter hostcall must be provided as context")
    if (!i.removeable) throw new Error("A removeable hostcall must be provided as context")
    if (!i.interrupt) throw new Error("An interrupt hostcall must be provided as context")
    if (!i.createAnchor) throw new Error("A createAnchor hostcall must be provided as context")
  }
}
class A {
  static OpContext = v
  static bee(e, r = {}) {
    const s = e.get(A.DB_VIEW_NAME),
      i = e.get(A.BLOB_VIEW_NAME),
      c = o.bee(s, n, r.hyperdb)
    return { blobs: new t(i), db: c, cores: { db: s, blobs: i } }
  }
  static rocks(t, s = {}) {
    const i = e.join(t, "db"),
      c = e.join(t, "blobs"),
      a = o.rocks(i, n, s.hyperdb)
    return { blobs: new r(c), db: a }
  }
  static DB_VIEW_NAME = "keet/v3/db"
  static BLOB_VIEW_NAME = "keet/v3/blobs"
}
function f() {
  const e = new i()
  return (
    a[E](e),
    b[E](e),
    h[E](e),
    u[E](e),
    l[E](e),
    d[E](e),
    p[E](e),
    q[E](e),
    m[E](e),
    w[E](e),
    e
  )
}
module.exports = { KeetContract: A, createRouter: f, encodeOperation: c, spec: s }