UNPKG

mock-cloud-firestore

Version:
13 lines (10 loc) 635 B
import { buildPathFromReference } from '../path'; export default function validateReference(ref, type) { const path = buildPathFromReference(ref).substr(8); const pathNodes = path.split('/'); if (type === 'collection' && pathNodes.length % 2 !== 1) { throw new Error(`Invalid collection reference. Collection references must have an odd number of segments, but ${path} has ${pathNodes.length}.`); } else if (type === 'doc' && pathNodes.length % 2 !== 0) { throw new Error(`Invalid document reference. Document references must have an even number of segments, but ${path} has ${pathNodes.length}.`); } }