Diffo.Provider.Instance.Extension

Copy Markdown View Source

DSL Extension customising an Instance.

Provides two top-level sections:

structure

Describes the static shape of the Instance kind — what it is, what values it carries, and what parties it relates to. All structure declarations are baked into the resource module at compile time via persisters and are introspectable at runtime via Diffo.Provider.Instance.Info or directly as generated functions on the resource module.

  • specification do — the TMF Specification (id, name, type, version, description, category). The id is a stable UUID4 that is the same across all environments for this Instance kind.
  • characteristics do — typed value slots carried by instances of this kind, each backed by an Ash.TypedStruct.
  • features do — optional capabilities of this kind, each with its own typed characteristic payload and an enabled/disabled default.
  • parties do — the party roles that instances of this kind relate to, with multiplicity, reference, and calculation options.
  • places do — the place roles that instances of this kind relate to, mirroring parties do in structure and options.

behaviour

Declares which Ash actions should be wired for instance build lifecycle management. Currently supports create declarations; future sections will cover triggers and other lifecycle concerns.

Declaring create :name in behaviour do actions do causes the TransformBehaviour transformer to inject :specified_by, :features, and :characteristics arguments onto the named Ash create action. These arguments carry the UUIDs of the TMF entities created by build_before/1 and consumed by the Ash relationship management in the action.

See the DSL cheat sheet for the full DSL reference. See Diffo.Provider.BaseInstance for full usage documentation including generated functions.

structure

Defines the structural shape of the Instance — its specification, characteristics, features, parties, and places

Nested DSLs

Examples

structure do
  specification do
    id "da9b207a-26c3-451d-8abd-0640c6349979"
    name "DSL Access Service"
    type :serviceSpecification
  end

  characteristics do
    characteristic :circuit, Diffo.Access.Circuit
  end

  parties do
    party :provider, MyApp.Provider
  end

  places do
    place :installation_site, MyApp.GeographicSite
  end
end

structure.specification

Defines the Instance Specification

Examples

specification do
  id "da9b207a-26c3-451d-8abd-0640c6349979"
  name "DSL Access Service"
  type :serviceSpecification
  major_version 1
  description "An access network service connecting a subscriber premises to an access NNI via DSL"
  category "Network Service"
end

Options

NameTypeDefaultDocs
idString.tThe id of the specification, a uuid4 the same in all environments, unique for name and major_version.
nameString.tThe name of the specification, unique to a service but common for all versions.
typeatom:serviceSpecificationThe type of the specification.
major_versioninteger1The major_version of the specification.
minor_versionintegerThe minor_version of the specification.
patch_versionintegerThe patch_version of the specification.
tmf_versionintegerThe TMF API version of the specification, e.g. 4.
descriptionString.tA generic description of the specified service or resource.
categoryString.tThe category the specified service or resource belongs to.

structure.characteristics

List of Instance Characteristics

Nested DSLs

Examples

characteristics do
  characteristic :dslam, Diffo.Access.Dslam
  characteristic :aggregate_interface, Diffo.Access.AggregateInterface
  characteristic :circuit, Diffo.Access.Circuit
  characteristic :line, Diffo.Access.Line
end

structure.characteristics.characteristic

characteristic name, value_type

Adds a Characteristic

Arguments

NameTypeDefaultDocs
nameatomThe name of the characteristic, an atom
value_typeanyThe type of the characteristic's value. An atom module name such as an Ash.TypedStruct for a scalar value, or {:array, module} for an array of values of that type.

structure.features

Configuration for Instance Features

Nested DSLs

Examples

features do
  feature :dynamic_line_management do
    is_enabled? true
    characteristics do
      characteristic :constraints, Diffo.Access.Constraints
    end
  end
end

structure.features.feature

feature name

Adds a Feature

Nested DSLs

Arguments

NameTypeDefaultDocs
nameatomThe name of the feature, an atom

Options

NameTypeDefaultDocs
is_enabled?booleanWhether the feature is enabled by default, defaults true

structure.features.feature.characteristic

characteristic name, value_type

Adds a Characteristic

Arguments

NameTypeDefaultDocs
nameatomThe name of the characteristic, an atom
value_typeanyThe type of the characteristic's value. An atom module name such as an Ash.TypedStruct for a scalar value, or {:array, module} for an array of values of that type.

structure.parties

List of Instance Party roles

Nested DSLs

Examples

parties do
  party :provider, MyApp.Provider, calculate: :provider_calculation
  parties :technician, MyApp.Technician, constraints: [min: 1, max: 3]
  party :owner, MyApp.InfrastructureCo, reference: true
end

structure.parties.party

party role, party_type

Declares a singular party role on this Instance

Arguments

NameTypeDefaultDocs
roleatomThe role name, an atom
party_typeanyThe module of the Party kind. An atom module name such as a BaseParty-derived resource.

Options

NameTypeDefaultDocs
referencebooleanfalseIf true, no direct PartyRef edge is created; the party is reachable by graph traversal.
calculateatomName of an Ash calculation on this resource that produces the party at build time.

Introspection

Target: Diffo.Provider.Instance.Extension.PartyDeclaration

structure.parties.parties

parties role, party_type

Declares a plural party role on this Instance

Arguments

NameTypeDefaultDocs
roleatomThe role name, an atom
party_typeanyThe module of the Party kind. An atom module name such as a BaseParty-derived resource.

Options

NameTypeDefaultDocs
referencebooleanfalseIf true, no direct PartyRef edge is created; the party is reachable by graph traversal.
calculateatomName of an Ash calculation on this resource that produces the party at build time.
constraintskeywordMultiplicity constraints on the number of parties in this role, e.g. [min: 1, max: 3]

Introspection

Target: Diffo.Provider.Instance.Extension.PartyDeclaration

structure.places

List of Instance Place roles

Nested DSLs

Examples

places do
  place :installation_site, MyApp.GeographicSite
  places :coverage_areas, MyApp.GeographicLocation, constraints: [min: 1]
  place :billing_address, MyApp.GeographicAddress, reference: true
end

structure.places.place

place role, place_type

Declares a singular place role on this Instance

Arguments

NameTypeDefaultDocs
roleatomThe role name, an atom
place_typeanyThe module of the Place kind. A BasePlace-derived resource.

Options

NameTypeDefaultDocs
referencebooleanfalseIf true, no direct PlaceRef edge is created; the place is reachable by graph traversal.
calculateatomName of an Ash calculation on this resource that produces the place at build time.

Introspection

Target: Diffo.Provider.Instance.Extension.PlaceDeclaration

structure.places.places

places role, place_type

Declares a plural place role on this Instance

Arguments

NameTypeDefaultDocs
roleatomThe role name, an atom
place_typeanyThe module of the Place kind. A BasePlace-derived resource.

Options

NameTypeDefaultDocs
referencebooleanfalseIf true, no direct PlaceRef edge is created; the place is reachable by graph traversal.
calculateatomName of an Ash calculation on this resource that produces the place at build time.
constraintskeywordMultiplicity constraints on the number of places in this role, e.g. [min: 1, max: 3]

Introspection

Target: Diffo.Provider.Instance.Extension.PlaceDeclaration

behaviour

Defines the behavioural wiring for the Instance — actions, and in future triggers and tasks

Nested DSLs

Examples

behaviour do
  actions do
    create :build
    update :define
  end
end

behaviour.actions

Declares which actions to wire for instance behaviour

Nested DSLs

Examples

actions do
  create :build
  update :define
end

behaviour.actions.create

create name

Marks a create action for instance build wiring, injecting :specified_by, :features, and :characteristics arguments

Arguments

NameTypeDefaultDocs
nameatomThe name of the create action to wire

behaviour.actions.update

update name

Marks an update action for instance behaviour wiring

Arguments

NameTypeDefaultDocs
nameatomThe name of the update action to wire