@@ -9,18 +9,19 @@ defmodule AshTypescript.Test.ChannelTracker do
99 All publications use `transform: :calc_name`. Ash auto-populates the
1010 `returns` type from the calculation, which AshTypescript reads directly.
1111
12- Expression types covered (all :auto unless noted) :
12+ Expression types covered:
1313 - String concat (explicit and :auto)
14- - Map with local attribute fields
15- - Map with mixed field types (string, integer, boolean )
16- - Integer from attribute reference
17- - Boolean expression
18-
19- Note: Avoids aggregate expressions (first, count, max) because
20- Ash.DataLayer.Simple doesn't support aggregate type resolution for :auto.
14+ - Map with local fields (:auto)
15+ - Map with relationship traversal via first() (:auto )
16+ - Map with nested relationship traversal via first() with dot access (:auto)
17+ - Map mixing aggregates, booleans, strings, and relationship fields (:auto)
18+ - Count aggregate (:auto)
19+ - Max aggregate (:auto)
20+ - Boolean expression ( :auto)
2121 """
2222 use Ash.Resource ,
2323 domain: nil ,
24+ data_layer: Ash.DataLayer.Ets ,
2425 notifiers: [ Ash.Notifier.PubSub ]
2526
2627 pub_sub do
@@ -51,13 +52,13 @@ defmodule AshTypescript.Test.ChannelTracker do
5152 public?: true ,
5253 transform: :snapshot
5354
54- # Map calc with different field types (:auto typed)
55+ # Map calc with relationship traversal (:auto typed)
5556 publish :detail_snapshot , [ :id ] ,
5657 event: "tracker_detail" ,
5758 public?: true ,
5859 transform: :detail
5960
60- # Integer from attribute (:auto typed)
61+ # Count aggregate (:auto typed)
6162 publish :count_entries , [ :id ] ,
6263 event: "tracker_entry_count" ,
6364 public?: true ,
@@ -69,19 +70,19 @@ defmodule AshTypescript.Test.ChannelTracker do
6970 public?: true ,
7071 transform: :is_active
7172
72- # Integer from attribute (:auto typed)
73+ # Max aggregate (:auto typed)
7374 publish :top_score , [ :id ] ,
7475 event: "tracker_top_score" ,
7576 public?: true ,
7677 transform: :top_entry_score
7778
78- # Map with various field types (:auto typed)
79+ # Map with nested relationship traversal (:auto typed)
7980 publish :deep_snapshot , [ :id ] ,
8081 event: "tracker_deep_detail" ,
8182 public?: true ,
8283 transform: :deep_detail
8384
84- # Map mixing expressions and attributes (:auto typed)
85+ # Map mixing aggregates, booleans, and strings (:auto typed)
8586 publish :full_report , [ :id ] ,
8687 event: "tracker_report" ,
8788 public?: true ,
@@ -122,15 +123,15 @@ defmodule AshTypescript.Test.ChannelTracker do
122123 public? ( true )
123124 end
124125
125- # :auto map calc with different field types (no aggregates )
126+ # :auto map calc with relationship traversal (first aggregate )
126127 calculate :detail ,
127128 :auto ,
128- expr ( % { id: id , name: name , description: status } ) do
129+ expr ( % { id: id , name: name , latest_entry_body: first ( entries , field: :body ) } ) do
129130 public? ( true )
130131 end
131132
132- # :auto integer — type inferred from integer attribute
133- calculate :entry_count , :auto , expr ( priority ) do
133+ # :auto count aggregate — should resolve to integer
134+ calculate :entry_count , :auto , expr ( count ( entries ) ) do
134135 public? ( true )
135136 end
136137
@@ -139,19 +140,20 @@ defmodule AshTypescript.Test.ChannelTracker do
139140 public? ( true )
140141 end
141142
142- # :auto integer — type inferred from integer attribute
143- calculate :top_entry_score , :auto , expr ( priority ) do
143+ # :auto max aggregate on related field — should resolve to integer
144+ calculate :top_entry_score , :auto , expr ( max ( entries , field: :score ) ) do
144145 public? ( true )
145146 end
146147
147- # :auto map with various field types
148+ # :auto map with nested relationship traversal — entries -> author -> username
148149 calculate :deep_detail ,
149150 :auto ,
150151 expr ( % {
151152 id: id ,
152153 name: name ,
153- status: status ,
154- current_priority: priority
154+ latest_author: first ( entries , field: :channel_tracker_author_id ) ,
155+ latest_body: first ( entries , field: :body ) ,
156+ latest_score: first ( entries , field: :score )
155157 } ) do
156158 public? ( true )
157159 end
@@ -163,8 +165,9 @@ defmodule AshTypescript.Test.ChannelTracker do
163165 name: name ,
164166 status: status ,
165167 is_active: status == "active" and priority > 0 ,
166- current_priority: priority ,
167- label: name <> " tracker"
168+ entry_count: count ( entries ) ,
169+ top_score: max ( entries , field: :score ) ,
170+ latest_body: first ( entries , field: :body )
168171 } ) do
169172 public? ( true )
170173 end
0 commit comments