MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / checkSchema

Function checkSchema

javascript/selenium-webdriver/project_bidi_schema.mjs:873–992  ·  view source on GitHub ↗
(source)

Source from the content-addressed store, hash-verified

871 * @returns {string[]} One message per problem; empty when valid.
872 */
873export function checkSchema(source) {
874 const schema = withVendor(source)
875 const allTypes = schema.types
876 const errors = []
877 const has = (name) => Object.hasOwn(allTypes, name)
878 const hasUnknown = (node) =>
879 !node
880 ? false
881 : node.primitive === 'unknown'
882 ? true
883 : node.list
884 ? hasUnknown(node.list)
885 : node.map
886 ? hasUnknown(node.map)
887 : node.union
888 ? node.union.some(hasUnknown)
889 : node.record
890 ? node.record.some((f) => hasUnknown(f.type))
891 : false
892 const hasEmptyInlineRecord = (node) =>
893 !node
894 ? false
895 : Array.isArray(node.record)
896 ? node.record.length === 0 || node.record.some((f) => hasEmptyInlineRecord(f.type))
897 : node.list
898 ? hasEmptyInlineRecord(node.list)
899 : node.map
900 ? hasEmptyInlineRecord(node.map)
901 : node.union
902 ? node.union.some(hasEmptyInlineRecord)
903 : false
904 const isNumeric = (node, seen = new Set()) => {
905 if (node.primitive !== undefined) return node.primitive === 'integer' || node.primitive === 'number'
906 if (node.ref === undefined || seen.has(node.ref)) return false
907 seen.add(node.ref)
908 const target = allTypes[node.ref]
909 return target?.kind === 'alias' && isNumeric(target.type, seen)
910 }
911 const nestedTypes = (node) => [node.list, node.map, ...(node.union ?? []), ...(node.record ?? []).map((f) => f.type)]
912 const hasMisplacedBound = (node) =>
913 !!node && ((BOUND_KEYS.some((k) => k in node) && !isNumeric(node)) || nestedTypes(node).some(hasMisplacedBound))
914 const report = (where, node) => {
915 for (const r of refsInType(node)) if (!has(r)) errors.push(`${where}: unresolved type ${r}`)
916 if (hasUnknown(node)) errors.push(`${where}: projected to an unknown primitive (unhandled CDDL type)`)
917 if (hasEmptyInlineRecord(node)) errors.push(`${where}: projected an empty inline record (dropped type reference)`)
918 if (hasMisplacedBound(node)) errors.push(`${where}: carries a numeric bound on a non-numeric type`)
919 }
920
921 for (const c of [...schema.commands, ...schema.events]) {
922 report(c.method, c.params)
923 report(c.method, c.result ?? null)
924 }
925 // A command/event whose envelope record carries real params must surface them —
926 // guards the model builder's gap where an inline `params: {...}` (vs a named ref)
927 // was dropped, leaving it parameterless while its type still required them.
928 const envelopeParams = commandEnvelopeParams(schema.types)
929 for (const c of [...schema.commands, ...schema.events]) {
930 const expected = envelopeParams.get(c.method)

Callers 2

mainFunction · 0.85

Calls 14

withVendorFunction · 0.85
reportFunction · 0.85
commandEnvelopeParamsFunction · 0.85
hasFunction · 0.85
checkSelectorFunction · 0.85
envelopeResultUnionFunction · 0.85
refsInTypeFunction · 0.85
leakFunction · 0.85
entriesMethod · 0.80
filterMethod · 0.80
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected