UNPKG

@sanity/import

Version:

Import documents to a Sanity dataset

21 lines (20 loc) 852 B
export function validateDocument(doc) { const document = doc; if (document._id !== undefined && typeof document._id !== 'string') { return `Document contained an invalid "_id" property - must be a string`; } if (document._id !== undefined && !/^[a-z0-9_.-]+$/i.test(document._id)) { return `Document ID "${document._id}" is not valid: Please use alphanumeric document IDs. Dashes (-) and underscores (_) are also allowed.`; } if (typeof document._type !== 'string') { return `Document did not contain required "_type" property of type string`; } return null; } export function documentHasError(doc, index) { const err = validateDocument(doc); if (err) { throw new Error(`Failed to parse document at index #${index}: ${err}`); } } //# sourceMappingURL=documentHasErrors.js.map