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

Function aliasMapRecords

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

* Turns each field-less map record (a CDDL `{* text => V}` group the projector lifts out * as a synthetic type) into an alias of `{ map: V }`. Emitted as a record, it would have no * declared keys, so every received entry would be warned about and dropped as undeclared; * as a map, each key is de

(schema)

Source from the content-addressed store, hash-verified

316 * decisions 4, 7, 9 and 10). An alias keeps the type's exported name.
317 */
318function aliasMapRecords(schema) {
319 const sections = [schema, ...Object.values(schema.vendor ?? {})]
320 const maps = new Set()
321 for (const section of sections) {
322 for (const [name, node] of Object.entries(section.types ?? {})) {
323 if (node.kind === 'record' && node.map !== undefined && node.fields.length === 0) {
324 section.types[name] = { kind: 'alias', type: { map: node.map } }
325 maps.add(name)
326 }
327 }
328 }
329 // A union resolves its variants as records or unions, so it cannot select a map.
330 for (const section of sections) {
331 for (const [name, node] of Object.entries(section.types ?? {})) {
332 const variant = node.kind === 'union' ? node.variants.find((v) => maps.has(v)) : undefined
333 if (variant) throw new Error(`${name}: union variant ${variant} is a map, which a union cannot select`)
334 }
335 }
336}
337
338// ============================================================
339// Schema-derived domain grouping

Callers 1

generateTypeScriptFunction · 0.85

Calls 5

valuesMethod · 0.80
entriesMethod · 0.80
findMethod · 0.80
addMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected