Module: Textus::Protocol::Manifest::Schema

Defined in:
lib/textus/protocol/manifest/schema.rb,
lib/textus/protocol/manifest/schema/contract.rb,
lib/textus/protocol/manifest/schema/validator.rb

Defined Under Namespace

Modules: Validator

Constant Summary collapse

LANES =

The closed coordination vocabulary (ADR 0028; five in 0033; unified in 0034; the quarantine + derived ZONE-KINDS folded into one machine kind in ADR 0091). Each kind pairs with the capability that authorizes originating bytes in it.

{
  "canon" => "author",
  "workspace" => "keep",
  "machine" => "converge",
  "queue" => "propose",
  "raw" => "ingest",
}.freeze
LANE_KINDS =
LANES.keys.freeze
CAPABILITIES =
LANES.values.uniq.freeze
KIND_REQUIRES_VERB =
LANES
ROOT_KEYS =

Key whitelists and rule-field registry (ADR 0109).

%w[version roles owner lanes entries data audit worker].freeze
LANE_KEYS =
%w[name kind owner desc].freeze
ENTRY_KEYS =
%w[key schema format naming tracked].freeze
AUDIT_KEYS =
%w[max_size keep].freeze
OWNER_SUBJECT_PATTERN =
/\A[a-z][a-z0-9_-]*\z/
Contract =

rubocop:disable Metrics/BlockLength

Dry::Schema.JSON do
  optional(:lanes).value(:array).each do
    hash do
      required(:name).value(:string)
      required(:kind).value(included_in?: LANE_KINDS)
      optional(:owner).value(:string)
      optional(:desc).value(:string)
    end
  end

  optional(:roles).value(:array).each do
    hash do
      required(:name).value(:string)
      optional(:can).value(:array).each(:string)
    end
  end

  optional(:entries).value(:array).each do
    hash do
      required(:key).value(:string)
      optional(:format).value(:string)
      optional(:schema).maybe(:string)
      optional(:tracked).value(:bool)
      optional(:naming).value(:string)
    end
  end

  optional(:data).value(:hash)

  optional(:audit).hash do
    optional(:max_size).value(:integer)
    optional(:keep).value(:integer)
  end
  optional(:worker).hash do
    optional(:pool).value(:integer)
    optional(:poll).value(:integer)
    optional(:lease_ttl).value(:integer)
    optional(:max_attempts).value(:integer)
  end
  optional(:version).value(:string)
end

Class Method Summary collapse

Class Method Details

.validate!(raw) ⇒ Object

Public entry point — structural validation then semantic checks.



30
# File 'lib/textus/protocol/manifest/schema.rb', line 30

def self.validate!(raw) = Validator.validate!(raw)

.walk(raw, allowed, path) ⇒ Object



32
33
34
35
36
# File 'lib/textus/protocol/manifest/schema.rb', line 32

def self.walk(raw, allowed, path)
  raw.each_key do |k|
    raise BadManifest.new("unknown key '#{k}' at '#{path}'") unless allowed.include?(k)
  end
end