23 lines
618 B
JavaScript
23 lines
618 B
JavaScript
const semver = require('semver')
|
|
|
|
const { IncorrectTypeError, IncorrectPropertyError, MismatchedVersionError } = require('./errors.js')
|
|
|
|
function readSpecimens(collection, v) {
|
|
if (v.type !== 'hord-specimens') {
|
|
throw new IncorrectTypeError('hord-specimens', v.type)
|
|
}
|
|
if (!Array.isArray(v.specimens)) {
|
|
throw new IncorrectPropertyError('specimens', typeof [], typeof v.specimens)
|
|
}
|
|
if (!v.version || !semver.satisfies(v.version, '1.x')) {
|
|
throw new MismatchedVersionError('1.x', v.version)
|
|
}
|
|
for (let s of v.specimens) {
|
|
collection.insert(s)
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
readSpecimens,
|
|
}
|