@@ -21,9 +21,13 @@ import (
21
21
const WILDCARD = "*"
22
22
23
23
// 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 ()
27
31
}
28
32
29
33
// Copy copies all information from one item pointer to another
@@ -153,6 +157,12 @@ func (i *Item) Hash() string {
153
157
return hashSum (([]byte (fmt .Sprint (i .GloballyUniqueName ()))))
154
158
}
155
159
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
+
156
166
// Hash Returns a 12 character hash for the item. This is likely but not
157
167
// guaranteed to be unique. The hash is calculated using the GloballyUniqueName
158
168
func (r * Reference ) Hash () string {
@@ -168,13 +178,61 @@ func (r *Reference) Hash() string {
168
178
//
169
179
// They are concatenated with dots (.)
170
180
func (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 ()
178
236
}
179
237
180
238
// Copy copies all information from one Reference pointer to another
@@ -184,6 +242,24 @@ func (r *Reference) Copy(dest *Reference) {
184
242
dest .Scope = r .GetScope ()
185
243
}
186
244
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
+
187
263
// Copy copies all information from one Metadata pointer to another
188
264
func (m * Metadata ) Copy (dest * Metadata ) {
189
265
if m == nil {
@@ -350,6 +426,37 @@ func (r *Query) ParseUuid() uuid.UUID {
350
426
return reqUUID
351
427
}
352
428
429
+ func (qr * QueryResponse ) ToGatewayResponse () * GatewayResponse {
430
+ switch qr .GetResponseType ().(type ) {
431
+ case * QueryResponse_NewItem :
432
+ return & GatewayResponse {
433
+ ResponseType : & GatewayResponse_NewItem {
434
+ NewItem : qr .GetNewItem (),
435
+ },
436
+ }
437
+ case * QueryResponse_Edge :
438
+ return & GatewayResponse {
439
+ ResponseType : & GatewayResponse_NewEdge {
440
+ NewEdge : qr .GetEdge (),
441
+ },
442
+ }
443
+ case * QueryResponse_Error :
444
+ return & GatewayResponse {
445
+ ResponseType : & GatewayResponse_QueryError {
446
+ QueryError : qr .GetError (),
447
+ },
448
+ }
449
+ case * QueryResponse_Response :
450
+ return & GatewayResponse {
451
+ ResponseType : & GatewayResponse_QueryStatus {
452
+ QueryStatus : qr .GetResponse ().ToQueryStatus (),
453
+ },
454
+ }
455
+ default :
456
+ panic (fmt .Sprintf ("encountered unknown QueryResponse type: %T" , qr ))
457
+ }
458
+ }
459
+
353
460
func (x * CancelQuery ) GetUUIDParsed () * uuid.UUID {
354
461
u , err := uuid .FromBytes (x .GetUUID ())
355
462
if err != nil {
0 commit comments