Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class Collection extends DBType {
if (!external) return { external: false, fqn: getFQN(schema.namespace, schema.name) }
this.builder.schema.register({
derived: true,
framed: schema.framed,
namespace: schema.namespace,
name: schema.name + type,
versions
Expand Down
52 changes: 52 additions & 0 deletions test/versions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { test } = require('./helpers')
const tmp = require('test-tmp')
const path = require('path')
const fs = require('fs')

test.bee('define versionField on collection', async function ({ build }, t) {
const dir = await tmp(t, { dir: path.join(__dirname, 'fixtures/tmp') })
Expand Down Expand Up @@ -35,6 +36,26 @@ test.bee('define versionField on collection', async function ({ build }, t) {
await dbVersions.close()
})

test.bee(
'a versioned collection value inherits the framed flag of its schema',
async function ({ build }, t) {
const framedDir = await tmp(t, { dir: path.join(__dirname, 'fixtures/tmp') })
const framedDb = await build(createVersionedDB, { dir: framedDir })
const framed = fs.readFileSync(path.join(framedDir, 'hyperdb', 'messages.js'), 'utf8')
t.ok(framed.includes('// framed version'), 'a versioned value is framed by default')
await framedDb.close()

const unframedDir = await tmp(t, { dir: path.join(__dirname, 'fixtures/tmp') })
const unframedDb = await build(createUnframedVersionedDB, { dir: unframedDir })
const unframed = fs.readFileSync(path.join(unframedDir, 'hyperdb', 'messages.js'), 'utf8')
t.absent(
unframed.includes('// framed version'),
'framed: false carries through to the derived value'
)
await unframedDb.close()
}
)

test.bee('versioned collection schema maps old rows on read', async function ({ build }, t) {
const dir = await tmp(t, { dir: path.join(__dirname, 'fixtures/tmp') })

Expand Down Expand Up @@ -220,6 +241,37 @@ function createVersionedDB(HyperDB, Hyperschema, paths) {
HyperDB.toDisk(db)
}

function createUnframedVersionedDB(HyperDB, Hyperschema, paths) {
const schema = Hyperschema.from(paths.schema)
const example = schema.namespace('example')

registerThingV1(example)

example.register({
name: 'thing',
framed: false,
versions: [
{
version: 1,
type: '@example/thing-v1'
}
]
})

Hyperschema.toDisk(schema)

const db = HyperDB.from(paths.schema, paths.db)
const exampleDB = db.namespace('example')

exampleDB.collections.register({
name: 'things',
schema: '@example/thing',
key: ['id']
})

HyperDB.toDisk(db)
}

function createVersionedDBWithV2(HyperDB, Hyperschema, paths) {
const schema = Hyperschema.from(paths.schema)
const example = schema.namespace('example')
Expand Down
Loading