blind-peer-encodings
Version:
Blind-peer encodings
95 lines (82 loc) • 2.76 kB
JavaScript
// 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 }
// '@blind-peer-router/assignment' collection key
const collection0_key = new IndexEncoder([IndexEncoder.BUFFER], { prefix: 0 })
function collection0_indexify(record) {
const a = record.key
return a === undefined ? [] : [a]
}
// '@blind-peer-router/assignment' value encoding
const collection0_enc = getEncoding('@blind-peer-router/assignment/hyperdb#0')
// '@blind-peer-router/assignment' 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
}
// '@blind-peer-router/assignment' key reconstruction function
function collection0_reconstruct_key(keyBuf) {
const key = collection0_key.decode(keyBuf)
return {
key: key[0]
}
}
// '@blind-peer-router/assignment'
const collection0 = {
name: '@blind-peer-router/assignment',
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 '@blind-peer-router/assignment':
return collection0
default:
return null
}
}
function resolveIndex(name) {
switch (name) {
default:
return null
}
}