Skip to content

Send files directly between devices over the internet - no cloud storage, no size limits.

2.7 KB
Raw Blame
// This file is autogenerated by the hyperdb compiler
/* eslint-disable camelcase */

import { IndexEncoder, c, b4a } from 'hyperdb/runtime'
import { version, getEncoding, setVersion } from './messages.js'

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

// '@altersend/remembered-peers' collection key
const collection0_key = new IndexEncoder([IndexEncoder.STRING], { prefix: 0 })

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

// '@altersend/remembered-peers' value encoding
const collection0_enc = getEncoding('@altersend/remembered-peer/hyperdb#0')

// '@altersend/remembered-peers' 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.remoteDevicePubkey = key[0]
  return record
}
// '@altersend/remembered-peers' key reconstruction function
function collection0_reconstruct_key(keyBuf) {
  const key = collection0_key.decode(keyBuf)
  return {
    remoteDevicePubkey: key[0]
  }
}

// '@altersend/remembered-peers'
const collection0 = {
  name: '@altersend/remembered-peers',
  id: 0,
  version: 1,
  encodeKey(record) {
    const key = [record.remoteDevicePubkey]
    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 = []

export default { versions, collections, indexes, resolveCollection, resolveIndex }

function resolveCollection(name) {
  switch (name) {
    case '@altersend/remembered-peers':
      return collection0
    default:
      return null
  }
}

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