@@ -31,7 +31,14 @@ def errors_in_this_namespace
3131 end
3232
3333 def dependencies
34- errors_in_this_namespace
34+ [
35+ RemoteCommandGenerator . new ( Manifest ::RootManifest . new ( root_manifest ) ) ,
36+ *queries_that_are_dirtied_by_this_command . keys
37+ ]
38+ end
39+
40+ def will_define
41+ ts_instance_path
3542 end
3643
3744 def command_errors_index_generator
@@ -52,6 +59,121 @@ def result_json_requires_cast?
5259 result_type && type_requires_cast? ( result_type )
5360 end
5461
62+ def queries_that_are_dirtied_by_this_command
63+ return { } if query?
64+
65+ return @queries_that_are_dirtied_by_this_command if defined? ( @queries_that_are_dirtied_by_this_command )
66+
67+ command_result_type = result_type
68+
69+ paths_to_data = nil
70+
71+ if command_result_type
72+ command_result_type = command_result_type . to_type if command_result_type . is_a? ( Manifest ::TypeDeclaration )
73+
74+ if command_result_type . detached_entity?
75+ paths_to_data = { command_result_type => [ :outcome , :result , command_result_type . primary_key_name ] }
76+ else
77+ result_type_associations = Manifest ::Model . associations ( command_result_type )
78+
79+ unless result_type_associations . empty?
80+ data_path , entity_type = result_type_associations . to_a . first
81+ paths_to_data = { entity_type => [ :outcome , :result , data_path , entity_type . primary_key_name ] }
82+ end
83+ end
84+ end
85+
86+ if paths_to_data . nil?
87+ if inputs_type
88+ inputs_associations = Manifest ::Model . associations ( inputs_type )
89+
90+ unless inputs_associations . empty?
91+ data_path , entity_type = inputs_associations . to_a . first
92+ paths_to_data = { entity_type => [ :inputs , *data_path ] }
93+ end
94+ end
95+ end
96+
97+ dirties = { }
98+
99+ unless paths_to_data . nil?
100+ all_queries = Manifest ::RootManifest . new ( root_manifest ) . queries . map do |query |
101+ generator_for ( query )
102+ end
103+
104+ paths_to_data . each_pair do |entity_type , path |
105+ all_queries . each do |query |
106+ query_inputs_type = query . inputs_type
107+
108+ if query_inputs_type
109+ query_associations = Manifest ::Model . associations ( query_inputs_type )
110+ query_associations . each_pair do |query_association_path , query_entity_class |
111+ query_entity_class = query_entity_class . to_type if query_entity_class . is_a? ( Manifest ::TypeDeclaration )
112+
113+ if query_entity_class == entity_type
114+ dirties [ query ] = [ path , query_association_path ]
115+ end
116+ end
117+
118+ next if dirties . key? ( query )
119+ end
120+
121+ query_result_type = query . result_type
122+ next unless query_result_type
123+
124+ if query_result_type . is_a? ( Manifest ::TypeDeclaration ) && query_result_type . reference?
125+ query_result_type = query_result_type . to_type
126+ end
127+
128+ if query_result_type == entity_type
129+ dirties [ query ] = true
130+ else
131+ entity_classes = Manifest ::Model . associations ( query_result_type ) . values . uniq
132+
133+ entity_classes . each do |query_entity_class |
134+ query_entity_class = query_entity_class . to_type if query_entity_class . is_a? ( Manifest ::TypeDeclaration )
135+
136+ if query_entity_class == entity_type
137+ dirties [ query ] = true
138+ break
139+ end
140+ end
141+ end
142+ end
143+ end
144+ end
145+
146+ @queries_that_are_dirtied_by_this_command = dirties
147+ end
148+
149+ def queries_dirtied_without_inputs
150+ return @queries_dirtied_without_inputs if defined? ( @queries_dirtied_without_inputs )
151+
152+ queries_dirtied = [ ]
153+
154+ queries_that_are_dirtied_by_this_command . each_pair do |query , value |
155+ if value == true
156+ queries_dirtied << query
157+ end
158+ end
159+
160+ @queries_dirtied_without_inputs = queries_dirtied
161+ end
162+
163+ def queries_dirtied_with_inputs
164+ return @queries_dirtied_with_inputs if defined? ( @queries_dirtied_with_inputs )
165+
166+ dirtied_queries = { }
167+
168+ queries_that_are_dirtied_by_this_command . each_pair do |query , value |
169+ if value != true
170+ dirtied_queries [ query ] = value
171+ end
172+ end
173+
174+ @queries_dirtied_with_inputs = dirtied_queries
175+ end
176+
55177 private
56178
57179 def type_requires_cast? ( type_declaration )
0 commit comments