Diffo.Provider.BaseCharacteristic (Diffo v0.4.0)

Copy Markdown View Source

Ash Resource Fragment which is the point of extension for typed TMF Characteristics.

BaseCharacteristic is the foundation for domain-specific Characteristic kinds. Include it as a fragment on an Ash.Resource to get a typed characteristic node in Neo4j with real Ash attributes — no Ash.Type.Dynamic required.

Diffo.Provider.Characteristic remains available as the generic dynamic option (storing values via Diffo.Type.Value); it includes Characteristic.Extension so the DSL verifier accepts it alongside typed resources.

Usage

defmodule MyApp.CircuitCharacteristic do
  use Ash.Resource, fragments: [BaseCharacteristic], domain: MyApp.Domain

  attributes do
    attribute :bandwidth_mbps, :integer, public?: true
    attribute :technology, :atom, public?: true
  end

  actions do
    create :create do
      accept [:name, :bandwidth_mbps, :technology]
      argument :instance_id, :uuid
      argument :feature_id, :uuid
    end

    update :update do
      accept [:bandwidth_mbps, :technology]
    end
  end

  calculations do
    calculate :value, Diffo.Type.CharacteristicValue, Diffo.Provider.Calculations.CharacteristicValue do
      public? true
    end
  end

  preparations do
    prepare build(load: [:value])
  end

  jason do
    pick [:name, :value]
    compact true
  end
end

DSL declaration

provider do
  characteristics do
    characteristic :circuit, MyApp.CircuitCharacteristic
  end
end

At build time a CircuitCharacteristic node is created and connected to the instance via an :HAS edge. The name attribute (e.g. :circuit) identifies the characteristic's role on the instance.

Typed vs dynamic

StyleDSL targetNeo4j nodeValue storage
TypedBaseCharacteristic-derivedper-type label (e.g. :CircuitCharacteristic)direct Ash attributes
DynamicDiffo.Provider.Characteristic:CharacteristicDiffo.Type.Value dynamic

Summary

Functions

extensions()

opts()

persisted()

spark_dsl_config()

validate_sections()