166 lines
4.7 KiB
JavaScript
166 lines
4.7 KiB
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 }
|
|
|
|
// '@bridgeswarm/records' collection key
|
|
const collection0_key = new IndexEncoder([
|
|
IndexEncoder.STRING
|
|
], { prefix: 0 })
|
|
|
|
function collection0_indexify (record) {
|
|
const a = record.id
|
|
return a === undefined ? [] : [a]
|
|
}
|
|
|
|
// '@bridgeswarm/records' value encoding
|
|
const collection0_enc = getEncoding('@bridgeswarm/record/hyperdb#0')
|
|
|
|
// '@bridgeswarm/records' 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.id = key[0]
|
|
return record
|
|
}
|
|
// '@bridgeswarm/records' key reconstruction function
|
|
function collection0_reconstruct_key (keyBuf) {
|
|
const key = collection0_key.decode(keyBuf)
|
|
return {
|
|
id: key[0]
|
|
}
|
|
}
|
|
|
|
// '@bridgeswarm/records'
|
|
const collection0 = {
|
|
name: '@bridgeswarm/records',
|
|
id: 0,
|
|
version: 1,
|
|
encodeKey (record) {
|
|
const key = [record.id]
|
|
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
|
|
}
|
|
|
|
// '@bridgeswarm/notes' collection key
|
|
const collection1_key = new IndexEncoder([
|
|
IndexEncoder.STRING
|
|
], { prefix: 1 })
|
|
|
|
function collection1_indexify (record) {
|
|
const a = record.id
|
|
return a === undefined ? [] : [a]
|
|
}
|
|
|
|
// '@bridgeswarm/notes' value encoding
|
|
const collection1_enc = getEncoding('@bridgeswarm/note/hyperdb#1')
|
|
|
|
// '@bridgeswarm/notes' reconstruction function
|
|
function collection1_reconstruct (schemaVersion, keyBuf, valueBuf) {
|
|
const key = collection1_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)
|
|
collection1.decodedVersion = c.uint.decode(state)
|
|
const record = collection1_enc.decode(state)
|
|
record.id = key[0]
|
|
return record
|
|
}
|
|
// '@bridgeswarm/notes' key reconstruction function
|
|
function collection1_reconstruct_key (keyBuf) {
|
|
const key = collection1_key.decode(keyBuf)
|
|
return {
|
|
id: key[0]
|
|
}
|
|
}
|
|
|
|
// '@bridgeswarm/notes'
|
|
const collection1 = {
|
|
name: '@bridgeswarm/notes',
|
|
id: 1,
|
|
version: 1,
|
|
encodeKey (record) {
|
|
const key = [record.id]
|
|
return collection1_key.encode(key)
|
|
},
|
|
encodeKeyRange ({ gt, lt, gte, lte } = {}) {
|
|
return collection1_key.encodeRange({
|
|
gt: gt ? collection1_indexify(gt) : null,
|
|
lt: lt ? collection1_indexify(lt) : null,
|
|
gte: gte ? collection1_indexify(gte) : null,
|
|
lte: lte ? collection1_indexify(lte) : null
|
|
})
|
|
},
|
|
encodeValue (schemaVersion, collectionVersion, record) {
|
|
setVersion(schemaVersion)
|
|
const state = { start: 0, end: 2, buffer: null }
|
|
collection1_enc.preencode(state, record)
|
|
state.buffer = b4a.allocUnsafe(state.end)
|
|
state.buffer[state.start++] = 0
|
|
state.buffer[state.start++] = collectionVersion
|
|
collection1_enc.encode(state, record)
|
|
return state.buffer
|
|
},
|
|
trigger: null,
|
|
reconstruct: collection1_reconstruct,
|
|
reconstructKey: collection1_reconstruct_key,
|
|
indexes: [],
|
|
decodedVersion: 0
|
|
}
|
|
|
|
const collections = [
|
|
collection0,
|
|
collection1
|
|
]
|
|
|
|
const indexes = [
|
|
]
|
|
|
|
module.exports = { versions, collections, indexes, resolveCollection, resolveIndex }
|
|
|
|
function resolveCollection (name) {
|
|
switch (name) {
|
|
case '@bridgeswarm/records': return collection0
|
|
case '@bridgeswarm/notes': return collection1
|
|
default: return null
|
|
}
|
|
}
|
|
|
|
function resolveIndex (name) {
|
|
switch (name) {
|
|
default: return null
|
|
}
|
|
}
|