Class: BiDiGenerate::Schema Private

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium/webdriver/bidi/support/bidi_generate.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ Schema

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Schema.



372
373
374
375
376
377
# File 'lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 372

def initialize(schema)
  @types = schema['types']
  @commands = schema['commands']
  @events = schema['events']
  promote_command_params_records!
end

Instance Method Details

#commands_for(domain) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



411
412
413
# File 'lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 411

def commands_for(domain)
  @commands.select { |c| c['domain'] == domain }
end

#domainsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Domains that carry a command or event each become one generated module.



407
408
409
# File 'lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 407

def domains
  (@commands + @events).map { |entry| entry['domain'] }.uniq
end

#enums_for(domain) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Enum types declared under "." become nested constant modules.



440
441
442
443
444
445
446
447
448
# File 'lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 440

def enums_for(domain)
  @types.filter_map do |name, type|
    next unless type['kind'] == 'enum'
    next unless name.start_with?("#{domain}.")

    pairs = type['values'].map { |v| [BiDiGenerate.enum_key(v), v.to_s] }
    Enum.new(constant_name: BiDiGenerate.screaming_snake(name.sub("#{domain}.", '')), pairs: pairs)
  end
end

#envelope_synthetic?(type) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A synthetic record lifted out as an envelope's params (its owner is an envelope).

Returns:

  • (Boolean)


483
484
485
486
487
488
# File 'lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 483

def envelope_synthetic?(type)
  return false unless type['synthetic']

  owner = @types[type['owner']]
  owner && owner['kind'] == 'record' && message_envelope?(owner)
end

#events_for(domain) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



419
420
421
# File 'lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 419

def events_for(domain)
  @events.select { |e| e['domain'] == domain }
end

#message_envelope?(type) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A protocol message envelope is a record with a baked method discriminator ({method: <const>, params: …}) — the wire shape of a command/event message. No value type carries a const method field, so this is unambiguous.

Returns:

  • (Boolean)


478
479
480
# File 'lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 478

def message_envelope?(type)
  type['fields'].any? { |f| f['wire'] == 'method' && f['type'].key?('const') }
end

#params_for(params_ref) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Flat params for a command: the record's fields, or — for a union of records — the merged superset of variant fields. Returns [] for commands with no params, or nil when params can't be flattened (alias, or a union whose variants aren't all records) so the caller forwards verbatim.



427
428
429
430
431
432
433
434
435
436
437
# File 'lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 427

def params_for(params_ref)
  return [] unless params_ref

  type = @types[params_ref['ref']]
  return nil unless type

  case type['kind']
  when 'record' then record_params(type['fields'])
  when 'union' then union_params(type, params_ref['ref'])
  end
end

#promote_command_params_records!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A command written in CDDL map form carries its params as an inline object (rather than the usual group form referencing a named params type). The projector links the command to those params, but hoists them into a synthetic record owned by the command's message envelope. That envelope is suppressed (Transport forms it), so the synthetic params record would never be emitted even though the command's params ref points straight at it. Promote it to a top-level domain record so the generator emits and references it like any other params type. Today this is exactly userAgentClientHints.setClientHintsOverride.



387
388
389
390
391
392
393
394
395
# File 'lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 387

def promote_command_params_records!
  @commands.each do |cmd|
    ref = cmd.dig('params', 'ref')
    next unless ref

    type = @types[ref]
    promote_to_domain_type!(ref) if type && envelope_synthetic?(type)
  end
end

#promote_to_domain_type!(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Strip the synthetic/owner/label tags so a lifted-out type emits as a top-level domain record instead of nesting under its (suppressed) envelope.



399
400
401
402
403
404
# File 'lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 399

def promote_to_domain_type!(name)
  type = @types[name]
  type&.delete('synthetic')
  type&.delete('owner')
  type&.delete('label')
end

#structured_ref(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The Protocol-relative class path a command result parses into, or nil when it is non-structured (or a bare list, returned raw).



492
493
494
495
# File 'lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 492

def structured_ref(name)
  resolved = resolve_named(name)
  resolved[:list] ? nil : resolved[:ref]
end

#suppressed_record?(type) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Records the generator deliberately does not emit: a message envelope, or a synthetic params record lifted out of one. Both are reachable only through the envelope, which Transport replaces — so nothing else references them.

Returns:

  • (Boolean)


471
472
473
# File 'lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 471

def suppressed_record?(type)
  message_envelope?(type) || envelope_synthetic?(type)
end

#type_kind(ref) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



415
416
417
# File 'lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 415

def type_kind(ref)
  @types[ref]&.fetch('kind', nil)
end

#types_for(domain) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Structured value classes (records + discriminated unions) declared under "." Empty records are projector artifacts with nothing to carry, so they stay opaque hashes; only non-empty records and unions become classes. Command/event message envelopes (the {method, params} wire wrapper) are skipped — Transport forms that envelope, so nothing references them.



455
456
457
458
459
460
461
462
463
464
465
466
# File 'lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 455

def types_for(domain)
  prefix = "#{domain}."
  @types.filter_map do |name, type|
    next unless name.start_with?(prefix)

    case type['kind']
    when 'record' then record_class(name, type) unless type['fields'].empty? || suppressed_record?(type)
    when 'union' then union_class(name)
    when 'alias' then union_class(name) if type['type'].key?('union')
    end
  end
end