OverviewFilesCommitsIssuesDocsReleasesPeers

keet-daemon / spec / state-base / contract / hyperdb / index.js

97 lines · javascript ref:
// This file is autogenerated by the hyperdb compiler
/* eslint-disable camelcase */

const { IndexEncoder, c, b4a } = require('hyperdb/runtime')
const { version, getEncoding, setVersion } = require('./messages.js')

const versions = { schema: version, db: 1 }

// '@state/entries' collection key
const collection0_key = new IndexEncoder([
  IndexEncoder.STRING
], { prefix: 0 })

function collection0_indexify (record) {
  const a = record.key
  return a === undefined ? [] : [a]
}

// '@state/entries' value encoding
const collection0_enc = getEncoding('@state/entry/hyperdb#0')

// '@state/entries' reconstruction function
function collection0_reconstruct (schemaVersion, keyBuf, valueBuf) {
  const key = collection0_key.decode(keyBuf)
  setVersion(schemaVersion)
  const state = { start: 0, end: valueBuf.byteLength, buffer: valueBuf }
  const type = c.uint.decode(state)
  if (type !== 0) throw new Error('Unknown collection type: ' + type)
  collection0.decodedVersion = c.uint.decode(state)
  const record = collection0_enc.decode(state)
  record.key = key[0]
  return record
}
// '@state/entries' key reconstruction function
function collection0_reconstruct_key (keyBuf) {
  const key = collection0_key.decode(keyBuf)
  return {
    key: key[0]
  }
}

// '@state/entries'
const collection0 = {
  name: '@state/entries',
  id: 0,
  version: 1,
  encodeKey (record) {
    const key = [record.key]
    return collection0_key.encode(key)
  },
  encodeKeyRange ({ gt, lt, gte, lte } = {}) {
    return collection0_key.encodeRange({
      gt: gt ? collection0_indexify(gt) : null,
      lt: lt ? collection0_indexify(lt) : null,
      gte: gte ? collection0_indexify(gte) : null,
      lte: lte ? collection0_indexify(lte) : null
    })
  },
  encodeValue (schemaVersion, collectionVersion, record) {
    setVersion(schemaVersion)
    const state = { start: 0, end: 2, buffer: null }
    collection0_enc.preencode(state, record)
    state.buffer = b4a.allocUnsafe(state.end)
    state.buffer[state.start++] = 0
    state.buffer[state.start++] = collectionVersion
    collection0_enc.encode(state, record)
    return state.buffer
  },
  trigger: null,
  reconstruct: collection0_reconstruct,
  reconstructKey: collection0_reconstruct_key,
  indexes: [],
  decodedVersion: 0
}

const collections = [
  collection0
]

const indexes = [
]

module.exports = { versions, collections, indexes, resolveCollection, resolveIndex }

function resolveCollection (name) {
  switch (name) {
    case '@state/entries': return collection0
    default: return null
  }
}

function resolveIndex (name) {
  switch (name) {
    default: return null
  }
}