MCPcopy Create free account
hub / github.com/github/docs / validateRecords

Function validateRecords

script/search/validate-records.js:13–37  ·  view source on GitHub ↗
(name, records)

Source from the content-addressed store, hash-verified

11}
12
13export default function validateRecords(name, records) {
14 assert(isString(name) && name.length, '`name` is required')
15 assert(isArray(records) && records.length, '`records` must be a non-empty array')
16
17 // each ID is unique
18 const objectIDs = records.map((record) => record.objectID)
19 const dupes = countArrayValues(objectIDs)
20 .filter(({ count }) => count > 1)
21 .map(({ value }) => value)
22 assert(!dupes.length, `every objectID must be unique. dupes: ${dupes.join('; ')}`)
23
24 records.forEach((record) => {
25 assert(
26 isString(record.objectID) && record.objectID.length,
27 `objectID must be a string. received: ${record.objectID}, ${JSON.stringify(record)}`
28 )
29
30 assert(
31 isString(record.title) && record.title.length,
32 `title must be a string. received: ${record.title}, ${JSON.stringify(record)}`
33 )
34 })
35
36 return true
37}

Callers 1

writeIndexRecordsFunction · 0.85

Calls 1

countArrayValuesFunction · 0.85

Tested by

no test coverage detected