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

Function foldVendorExtensions

javascript/selenium-webdriver/generate_bidi.mjs:735–758  ·  view source on GitHub ↗

* Folds each vendor's fields into the spec types it extends. ADR 17786 counts a supported vendor's * extensions as the spec, so they are declared fields: typed and validated, never a reason to make * the type extensible (#18184). Fields on a spec command's params go only to that command's vendor

(schema)

Source from the content-addressed store, hash-verified

733 * than left to its extension map, which keeps carrying other browsers' fields.
734 */
735function foldVendorExtensions(schema) {
736 const vendorTypes = Object.assign({}, ...Object.values(schema.vendor ?? {}).map((s) => s.types ?? {}))
737 for (const [namespace, section] of Object.entries(schema.vendor ?? {})) {
738 for (const [typeName, entry] of Object.entries(section.extends ?? {})) {
739 const base = schema.types[typeName]
740 if (base?.kind !== 'record') {
741 throw new Error(`vendor ${namespace} extends ${typeName}, which is not a record`)
742 }
743 const wires = new Set(base.fields.map((f) => f.wire))
744 const redeclared = entry.fields.find((f) => wires.has(f.wire))
745 if (redeclared) throw new Error(`vendor ${namespace} redeclares ${redeclared.wire} on ${typeName}`)
746 if (schema.commands.some((c) => c.params?.ref === typeName)) continue
747
748 const taken = new Set(base.fields.map((f) => f.name))
749 const fields = entry.fields.map((f) => {
750 const name = `${namespace}${pascalCase(f.name.replace(`${namespace}:`, ''))}`
751 if (taken.has(name)) throw new Error(`vendor field ${f.wire} on ${typeName} collides with ${name}`)
752 return { ...f, name, required: false }
753 })
754 schema.types[typeName] = { ...base, fields: [...base.fields, ...fields] }
755 for (const ref of fields.flatMap((f) => refsIn(f.type))) collectVendorTypes(ref, vendorTypes, schema.types)
756 }
757 }
758}
759
760/** Adds `name` and every vendor type it transitively references to `into`; spec types are left to their own domain. */
761function collectVendorTypes(name, vendorTypes, into) {

Callers 1

generateTypeScriptFunction · 0.85

Calls 8

pascalCaseFunction · 0.85
refsInFunction · 0.85
collectVendorTypesFunction · 0.85
valuesMethod · 0.80
entriesMethod · 0.80
findMethod · 0.80
mapMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected