@@ -21,9 +21,13 @@ import (
2121const WILDCARD = "*"
2222
2323// Copy copies all information from one item pointer to another
24- func (liq * BlastPropagation ) Copy (dest * BlastPropagation ) {
25- dest .In = liq .GetIn ()
26- dest .Out = liq .GetOut ()
24+ func (bp * BlastPropagation ) Copy (dest * BlastPropagation ) {
25+ dest .In = bp .GetIn ()
26+ dest .Out = bp .GetOut ()
27+ }
28+
29+ func (bp * BlastPropagation ) IsEqual (other * BlastPropagation ) bool {
30+ return bp .GetIn () == other .GetIn () && bp .GetOut () == other .GetOut ()
2731}
2832
2933// Copy copies all information from one item pointer to another
@@ -153,6 +157,12 @@ func (i *Item) Hash() string {
153157 return hashSum (([]byte (fmt .Sprint (i .GloballyUniqueName ()))))
154158}
155159
160+ func (e * Edge ) IsEqual (other * Edge ) bool {
161+ return e .GetFrom ().IsEqual (other .GetFrom ()) &&
162+ e .GetTo ().IsEqual (other .GetTo ()) &&
163+ e .GetBlastPropagation ().IsEqual (other .GetBlastPropagation ())
164+ }
165+
156166// Hash Returns a 12 character hash for the item. This is likely but not
157167// guaranteed to be unique. The hash is calculated using the GloballyUniqueName
158168func (r * Reference ) Hash () string {
@@ -168,13 +178,61 @@ func (r *Reference) Hash() string {
168178//
169179// They are concatenated with dots (.)
170180func (r * Reference ) GloballyUniqueName () string {
171- return strings .Join ([]string {
172- r .GetScope (),
173- r .GetType (),
174- r .GetUniqueAttributeValue (),
175- },
176- "." ,
177- )
181+ if r == nil {
182+ // in the llm templates nil references are processed, and after spending
183+ // half an hour on trying to figure out what was happening in the
184+ // reflect code, I decided to just return an empty string here. DS,
185+ // 2025-02-26
186+ return ""
187+ }
188+ if r .GetIsQuery () {
189+ if r .GetMethod () == QueryMethod_GET {
190+ // GET queries are single items
191+ return fmt .Sprintf ("%v.%v.%v" , r .GetScope (), r .GetType (), r .GetQuery ())
192+ }
193+ panic (fmt .Sprintf ("cannot get globally unique name for query reference: %v" , r ))
194+ }
195+ return fmt .Sprintf ("%v.%v.%v" , r .GetScope (), r .GetType (), r .GetUniqueAttributeValue ())
196+
197+ }
198+
199+ // Key returns a globally unique string for this reference, even if it is a GET query
200+ func (r * Reference ) Key () string {
201+ if r == nil {
202+ panic ("cannot get key for nil reference" )
203+ }
204+ if r .GetIsQuery () {
205+ if r .IsSingle () {
206+ // GET queries without wildcards are single items
207+ return fmt .Sprintf ("%v.%v.%v" , r .GetScope (), r .GetType (), r .GetQuery ())
208+ }
209+ return fmt .Sprintf ("%v: %v.%v.%v" , r .GetMethod (), r .GetScope (), r .GetType (), r .GetQuery ())
210+ }
211+ return r .GloballyUniqueName ()
212+ }
213+
214+ // IsSingle returns true if this references a single item, false if it is a LIST
215+ // or SEARCH query, or a GET query with scope and/or type wildcards.
216+ func (r * Reference ) IsSingle () bool {
217+ // nil reference is never good
218+ if r == nil {
219+ return false
220+ }
221+ // if it is a query, then it is only a single item if it is a GET query with no wildcards
222+ if r .GetIsQuery () {
223+ return r .GetMethod () == QueryMethod_GET && r .GetScope () != "*" && r .GetType () != "*"
224+ }
225+ // if it is not a query, then it is always single item
226+ return true
227+ }
228+
229+ func (r * Reference ) IsEqual (other * Reference ) bool {
230+ return r .GetScope () == other .GetScope () &&
231+ r .GetType () == other .GetType () &&
232+ r .GetUniqueAttributeValue () == other .GetUniqueAttributeValue () &&
233+ r .GetIsQuery () == other .GetIsQuery () &&
234+ r .GetMethod () == other .GetMethod () &&
235+ r .GetQuery () == other .GetQuery ()
178236}
179237
180238// Copy copies all information from one Reference pointer to another
@@ -184,6 +242,24 @@ func (r *Reference) Copy(dest *Reference) {
184242 dest .Scope = r .GetScope ()
185243}
186244
245+ func (r * Reference ) ToQuery () * Query {
246+ if ! r .GetIsQuery () {
247+ return & Query {
248+ Scope : r .GetScope (),
249+ Type : r .GetType (),
250+ Method : QueryMethod_GET ,
251+ Query : r .GetUniqueAttributeValue (),
252+ }
253+ }
254+
255+ return & Query {
256+ Scope : r .GetScope (),
257+ Type : r .GetType (),
258+ Method : r .GetMethod (),
259+ Query : r .GetQuery (),
260+ }
261+ }
262+
187263// Copy copies all information from one Metadata pointer to another
188264func (m * Metadata ) Copy (dest * Metadata ) {
189265 if m == nil {
@@ -353,6 +429,37 @@ func (r *Query) ParseUuid() uuid.UUID {
353429 return reqUUID
354430}
355431
432+ func (qr * QueryResponse ) ToGatewayResponse () * GatewayResponse {
433+ switch qr .GetResponseType ().(type ) {
434+ case * QueryResponse_NewItem :
435+ return & GatewayResponse {
436+ ResponseType : & GatewayResponse_NewItem {
437+ NewItem : qr .GetNewItem (),
438+ },
439+ }
440+ case * QueryResponse_Edge :
441+ return & GatewayResponse {
442+ ResponseType : & GatewayResponse_NewEdge {
443+ NewEdge : qr .GetEdge (),
444+ },
445+ }
446+ case * QueryResponse_Error :
447+ return & GatewayResponse {
448+ ResponseType : & GatewayResponse_QueryError {
449+ QueryError : qr .GetError (),
450+ },
451+ }
452+ case * QueryResponse_Response :
453+ return & GatewayResponse {
454+ ResponseType : & GatewayResponse_QueryStatus {
455+ QueryStatus : qr .GetResponse ().ToQueryStatus (),
456+ },
457+ }
458+ default :
459+ panic (fmt .Sprintf ("encountered unknown QueryResponse type: %T" , qr ))
460+ }
461+ }
462+
356463func (x * CancelQuery ) GetUUIDParsed () * uuid.UUID {
357464 u , err := uuid .FromBytes (x .GetUUID ())
358465 if err != nil {
0 commit comments