Skip to content

Commit d3f8ef3

Browse files
committed
formatter fix
1 parent 6c26b4d commit d3f8ef3

10 files changed

Lines changed: 150 additions & 9 deletions

File tree

.formatter.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ locals_without_parens = [
2020
initial_states: 1,
2121
default_initial_state: 1,
2222
state_attribute: 1,
23-
transition: 1
23+
transition: 1,
24+
compact: 1
2425
]
2526

2627
[

lib/diffo/provider/assigner/assignable_value.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ defmodule Diffo.Provider.AssignableValue do
1212

1313
jason do
1414
pick [:first, :last, :free, :type, :algorithm]
15-
compact(true)
15+
compact true
1616
end
1717

1818
typed_struct do

lib/diffo/provider/assigner/assignment.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ defmodule Diffo.Provider.Assignment do
1212

1313
jason do
1414
pick [:id, :assignee_id, :operation]
15-
compact(true)
15+
compact true
1616
end
1717

1818
typed_struct do

lib/diffo/provider/components/base_instance.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ defmodule Diffo.Provider.BaseInstance do
5858
:type
5959
]
6060

61-
compact(true)
61+
compact true
6262

6363
customize fn result, record ->
6464
result

lib/diffo/provider/components/entity.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ defmodule Diffo.Provider.Entity do
2929

3030
jason do
3131
pick [:id, :href, :name, :referredType, :type]
32-
compact(true)
32+
compact true
3333
rename referredType: "@referredType", type: "@type"
3434
end
3535

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# SPDX-FileCopyrightText: 2025 diffo contributors <https://github.com/diffo-dev/diffo/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
defmodule Diffo.Provider.Event do
6+
@moduledoc """
7+
Diffo - TMF Service and Resource Management with a difference
8+
9+
Event - Ash Resource for a TMF Event
10+
"""
11+
use Ash.Resource,
12+
otp_app: :diffo,
13+
domain: Diffo.Provider,
14+
data_layer: AshNeo4j.DataLayer,
15+
extensions: [AshOutstanding.Resource, AshJason.Resource]
16+
17+
alias Diffo.Util, as: Util
18+
19+
resource do
20+
description "An Ash Resource for a TMF Entity Reference"
21+
plural_name :events
22+
end
23+
24+
neo4j do
25+
relate [
26+
{:instance, :FIRED, :incoming, :Instance},
27+
#{:earlier_event, :AFTER, :outgoing, :Event}
28+
]
29+
end
30+
31+
jason do
32+
rename id: :eventId, inserted_at: :eventTime, type: :eventType
33+
34+
customize fn result, record ->
35+
result
36+
|> Event.time(record)
37+
|> Util.rename(:instance, record.type)
38+
|> Util.nest([record.type], :event)
39+
end
40+
41+
order [:eventId, :eventTime, :eventType, :event]
42+
end
43+
44+
outstanding do
45+
expect [:eventType, :eventTime, :event]
46+
end
47+
48+
actions do
49+
defaults [:read, :destroy]
50+
51+
create :create do
52+
description "creates an event, fired by an instance"
53+
accept [:type]
54+
argument :instance_id, :uuid
55+
argument :earlier_event_id, :uuid
56+
57+
change manage_relationship(:instance_id, :instance, type: :append_and_remove)
58+
#change manage_relationship(:earlier_event_id, :earlier_event, type: :append_and_remove)
59+
change load [:instance_type]
60+
end
61+
62+
read :list do
63+
description "lists all events"
64+
end
65+
66+
read :list_events_by_instance_id do
67+
description "lists events by instance id"
68+
argument :instance_id, :uuid
69+
filter expr(instance_id == ^arg(:instance_id))
70+
end
71+
end
72+
73+
attributes do
74+
uuid_primary_key :id do
75+
description "a uuid4, unique to this entity ref, generated by default"
76+
public? false
77+
end
78+
79+
attribute :type, :atom do
80+
description "the type of the event"
81+
allow_nil? false
82+
public? true
83+
end
84+
85+
create_timestamp :inserted_at
86+
87+
update_timestamp :updated_at
88+
end
89+
90+
relationships do
91+
belongs_to :instance, Diffo.Provider.Instance do
92+
description "the instance which fired the event"
93+
allow_nil? false
94+
public? true
95+
end
96+
97+
#has_one :earlier_event, Diffo.Provider.Event do
98+
# description "the earlier event, if any"
99+
# allow_nil? true
100+
# public? true
101+
#end
102+
end
103+
104+
calculations do
105+
calculate :instance_type,
106+
:atom,
107+
expr(instance.type) do
108+
description "the type of the instance which fired the event"
109+
end
110+
end
111+
112+
preparations do
113+
prepare build(load: [:instance_type], sort: [inserted_at: :desc])
114+
end
115+
116+
@doc """
117+
Assists in encoding event time
118+
"""
119+
def time(result, record) do
120+
result
121+
|> Diffo.Util.set(
122+
:eventTime,
123+
Diffo.Util.to_iso8601(record.inserted_at)
124+
)
125+
end
126+
127+
@doc """
128+
Compares two event, by id
129+
## Examples
130+
iex> Diffo.Provider.Event.compare(%{id: "a"}, %{id: "a"})
131+
:eq
132+
iex> Diffo.Provider.Event.compare(%{id: "b"}, %{id: "a"})
133+
:gt
134+
iex> Diffo.Provider.Event.compare(%{id: "a"}, %{id: "b"})
135+
:lt
136+
137+
"""
138+
def compare(%{id: id0}, %{id: id1}),
139+
do: Diffo.Util.compare(id0, id1)
140+
end

lib/diffo/provider/components/party.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ defmodule Diffo.Provider.Party do
3535

3636
jason do
3737
pick [:id, :href, :name, :referredType, :type]
38-
compact(true)
38+
compact true
3939
rename referredType: "@referredType", type: "@type"
4040
end
4141

lib/diffo/provider/components/place.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ defmodule Diffo.Provider.Place do
2929

3030
jason do
3131
pick [:id, :href, :name, :referredType, :type]
32-
compact(true)
32+
compact true
3333
rename referredType: "@referredType", type: "@type"
3434
end
3535

test/support/resource/card_value.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ defmodule Diffo.Test.CardValue do
1212

1313
jason do
1414
pick [:name, :family, :model, :technology]
15-
compact(true)
15+
compact true
1616
end
1717

1818
outstanding do

test/support/resource/shelf_value.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ defmodule Diffo.Test.ShelfValue do
1212

1313
jason do
1414
pick [:name, :family, :model, :technology]
15-
compact(true)
15+
compact true
1616
end
1717

1818
outstanding do

0 commit comments

Comments
 (0)