Skip to content

Commit 5291253

Browse files
committed
initial version
1 parent 583c2a0 commit 5291253

40 files changed

Lines changed: 2745 additions & 1 deletion

.formatter.exs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
# Used by "mix format"
6+
locals_without_parens = [
7+
id: 1,
8+
category: 1,
9+
is_enabled?: 1,
10+
characteristic: 2,
11+
pick: 1,
12+
rename: 1,
13+
field: 3,
14+
expect: 1,
15+
relate: 1,
16+
translate: 1,
17+
guard: 1,
18+
customize: 1,
19+
order: 1,
20+
initial_states: 1,
21+
default_initial_state: 1,
22+
state_attribute: 1,
23+
transition: 1
24+
]
25+
26+
[
27+
plugins: [Spark.Formatter],
28+
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
29+
import_deps: [:ash],
30+
locals_without_parens: locals_without_parens,
31+
export: [
32+
locals_without_parens: locals_without_parens
33+
]
34+
]

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
3+
4+
SPDX-License-Identifier: MIT
5+
-->
6+
7+
# Change Log
8+
9+
All notable changes to this project will be documented in this file.
10+
See [Conventional Commits](Https://conventionalcommits.org) for commit guidelines.
11+
12+
<!-- changelog -->
13+
14+
## [v0.0.1](https://github.com/diffo-dev/diffo/compare/v0.0.1..v0.0.1) (2025-10-20)
15+
16+
### Features:
17+
* initial version

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo/graphs.contributors>
2+
SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
33
44
SPDX-License-Identifier: MIT
55
-->

config/config.exs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import Config
6+
7+
config :spark,
8+
formatter: [
9+
remove_parens?: true,
10+
"Ash.Resource": [
11+
section_order: [
12+
:resource,
13+
:code_interface,
14+
:specification,
15+
:features,
16+
:characteristics,
17+
:neo4j,
18+
:jason,
19+
:outstanding,
20+
:actions,
21+
:state_machine,
22+
:attributes,
23+
:relationships,
24+
:identities,
25+
:aggregates,
26+
:calculations,
27+
:preparations
28+
]
29+
],
30+
"Ash.TypedStruct": [
31+
section_order: [
32+
:jason,
33+
:outstanding,
34+
:fields
35+
]
36+
]
37+
]
38+
39+
config :diffo, ash_domains: [Diffo.Provider, Diffo.Access]
40+
config :diffo_example, ash_domains: [DiffoExample.Access]
41+
import_config "#{config_env()}.exs"

config/dev.exs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import Config
6+
7+
config :boltx, Bolt,
8+
uri: "bolt://localhost:7687",
9+
auth: [username: "neo4j", password: "password"],
10+
user_agent: "DiffoExampleDev/1",
11+
pool_size: 15,
12+
max_overflow: 3,
13+
prefix: :default,
14+
name: Bolt,
15+
log: true,
16+
log_hex: true
17+
18+
level =
19+
if System.get_env("DEBUG") do
20+
:debug
21+
else
22+
:info
23+
end
24+
25+
config :logger, :console,
26+
level: level,
27+
format: "$date $time [$level] $metadata$message\n"

config/prod.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import Config

config/runtime.exs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import Config
6+
7+
if config_env() == :prod do
8+
database_url =
9+
System.get_env("DATABASE_URL") ||
10+
raise """
11+
environment variable DATABASE_URL is missing.
12+
For example: ecto://USER:PASS@HOST/DATABASE
13+
"""
14+
15+
config :diffo_example, DiffoExample.Repo,
16+
url: database_url,
17+
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")
18+
end

config/test.exs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import Config
6+
7+
config :logger, level: :warning
8+
config :ash, disable_async?: true
9+
config :ash, :missed_notifications, :ignore
10+
11+
config :boltx, Bolt,
12+
uri: "bolt://localhost:7687",
13+
auth: [username: "neo4j", password: "password"],
14+
user_agent: "DiffoExampleTest/1",
15+
pool_size: 15,
16+
max_overflow: 3,
17+
prefix: :default,
18+
name: Bolt,
19+
log: true,
20+
log_hex: true
21+
22+
level =
23+
if System.get_env("DEBUG") do
24+
:debug
25+
else
26+
:info
27+
end
28+
29+
config :logger, :console,
30+
level: level,
31+
format: "$date $time [$level] $metadata$message\n"

lib/access/access.ex

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
defmodule DiffoExample.Access do
6+
@moduledoc """
7+
Diffo - TMF Service and Resource Management with a difference
8+
9+
Access - example Access domain
10+
"""
11+
use Ash.Domain,
12+
otp_app: :diffo
13+
14+
alias DiffoExample.Access.DslAccess
15+
alias DiffoExample.Access.Shelf
16+
alias DiffoExample.Access.Card
17+
alias DiffoExample.Access.Cable
18+
alias DiffoExample.Access.Path
19+
20+
domain do
21+
description "An example showing how TMF Services and Resources for a fictional Access domain can be extended from the Provider domain"
22+
end
23+
24+
resources do
25+
resource DslAccess do
26+
define :get_dsl_by_id, action: :read, get_by: :id
27+
define :qualify_dsl, action: :qualify
28+
define :qualify_dsl_result, action: :qualify_result
29+
define :design_dsl_result, action: :design_result
30+
end
31+
32+
resource Shelf do
33+
define :get_shelf_by_id, action: :read, get_by: :id
34+
define :build_shelf, action: :build
35+
define :define_shelf, action: :define
36+
define :relate_shelf, action: :relate
37+
define :assign_slot, action: :assign_slot
38+
end
39+
40+
resource Card do
41+
define :get_card_by_id, action: :read, get_by: :id
42+
define :build_card, action: :build
43+
define :define_card, action: :define
44+
define :relate_card, action: :relate
45+
define :assign_port, action: :assign_port
46+
end
47+
48+
resource Cable do
49+
define :get_cable_by_id, action: :read, get_by: :id
50+
define :build_cable, action: :build
51+
define :define_cable, action: :define
52+
define :relate_cable, action: :relate
53+
define :assign_pair, action: :assign_pair
54+
end
55+
56+
resource Path do
57+
define :get_path_by_id, action: :read, get_by: :id
58+
define :build_path, action: :build
59+
define :define_path, action: :define
60+
define :relate_path, action: :relate
61+
end
62+
end
63+
end

lib/access/resources/cable.ex

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
defmodule DiffoExample.Access.Cable do
6+
@moduledoc """
7+
Diffo - TMF Service and Resource Management with a difference
8+
9+
Cable - Cable Resource Instance
10+
"""
11+
12+
alias Diffo.Provider.BaseInstance
13+
alias Diffo.Provider.Instance.Specification
14+
alias Diffo.Provider.Instance.Relationship
15+
alias Diffo.Provider.Instance.Feature
16+
alias Diffo.Provider.Instance.Characteristic
17+
alias Diffo.Provider.Instance.Place
18+
alias Diffo.Provider.Instance.Party
19+
alias Diffo.Provider.Assigner
20+
alias Diffo.Provider.Assignment
21+
22+
alias DiffoExample.Access
23+
24+
use Ash.Resource,
25+
fragments: [BaseInstance],
26+
domain: Access
27+
28+
resource do
29+
description "An Ash Resource representing a Cable"
30+
plural_name :Cables
31+
end
32+
33+
specification do
34+
id "ce0a567a-6abb-4862-9e33-851fd79fa595"
35+
name "cable"
36+
type :resourceSpecification
37+
description "A Cable Resource Instance"
38+
category "Network Resource"
39+
end
40+
41+
characteristics do
42+
characteristic :cable, DiffoExample.Access.CableValue
43+
characteristic :pairs, Diffo.Provider.AssignableValue
44+
end
45+
46+
actions do
47+
create :build do
48+
description "creates a new Cable resource instance for build"
49+
accept [:id, :name, :type, :which]
50+
argument :specified_by, :uuid, public?: false
51+
argument :relationships, {:array, :struct}
52+
argument :features, {:array, :uuid}, public?: false
53+
argument :characteristics, {:array, :uuid}, public?: false
54+
argument :places, {:array, :struct}
55+
argument :parties, {:array, :struct}
56+
57+
change set_attribute(:type, :resource)
58+
59+
change before_action(fn changeset, _context ->
60+
changeset
61+
|> Specification.set_specified_by_argument()
62+
|> Feature.set_features_argument()
63+
|> Characteristic.set_characteristics_argument()
64+
end)
65+
66+
change after_action(fn changeset, result, _context ->
67+
with {:ok, with_specification} <- Specification.relate_instance(result, changeset),
68+
{:ok, with_relationships} <-
69+
Relationship.relate_instance(with_specification, changeset),
70+
{:ok, with_features} <-
71+
Feature.relate_instance(with_relationships, changeset),
72+
{:ok, with_characteristics} <-
73+
Characteristic.relate_instance(with_features, changeset),
74+
{:ok, with_places} <- Place.relate_instance(with_characteristics, changeset),
75+
{:ok, _with_parties} <- Party.relate_instance(with_places, changeset),
76+
{:ok, cable} <- Access.get_cable_by_id(result.id),
77+
do: {:ok, cable}
78+
end)
79+
80+
change load [:href]
81+
upsert? false
82+
end
83+
84+
update :define do
85+
description "defines the cable"
86+
argument :characteristic_value_updates, {:array, :term}
87+
88+
change after_action(fn changeset, result, _context ->
89+
with {:ok, _result} <- Characteristic.update_values(result, changeset),
90+
{:ok, cable} <- Access.get_cable_by_id(result.id),
91+
do: {:ok, cable}
92+
end)
93+
end
94+
95+
update :relate do
96+
description "relates the cable with other instances"
97+
argument :relationships, {:array, :struct}
98+
99+
change after_action(fn changeset, result, _context ->
100+
with {:ok, _cable} <- Relationship.relate_instance(result, changeset),
101+
{:ok, cable} <- Access.get_cable_by_id(result.id),
102+
do: {:ok, cable}
103+
end)
104+
end
105+
106+
update :assign_pair do
107+
description "relates the cable with an instance by assigning a pair"
108+
argument :assignment, :struct, constraints: [instance_of: Assignment]
109+
110+
change after_action(fn changeset, result, _context ->
111+
with {:ok, _cable} <- Assigner.assign(result, changeset, :pairs, :pair),
112+
{:ok, cable} <- Access.get_cable_by_id(result.id),
113+
do: {:ok, cable}
114+
end)
115+
end
116+
end
117+
end

0 commit comments

Comments
 (0)