fix(typedb): improve concept serialization for frontend compatibility
- Add 'type' alias alongside '_type' for frontend compatibility - Handle both bytes and string IID formats from driver - Add 'id' alias alongside '_iid' for consistency
This commit is contained in:
parent
271545fa8b
commit
35066eb5eb
1 changed files with 24 additions and 3 deletions
|
|
@ -108,10 +108,21 @@ def serialize_concept(concept) -> Dict[str, Any]:
|
|||
if hasattr(concept_type, 'get_label'):
|
||||
label = concept_type.get_label()
|
||||
result['_type'] = label.name if hasattr(label, 'name') else str(label)
|
||||
result['type'] = result['_type'] # Alias for frontend compatibility
|
||||
|
||||
if hasattr(concept, 'get_iid'):
|
||||
iid = concept.get_iid()
|
||||
result['_iid'] = iid.hex() if iid else None
|
||||
# Handle both old (bytes with .hex()) and new (string) driver formats
|
||||
if iid is None:
|
||||
result['_iid'] = None
|
||||
result['id'] = None
|
||||
elif hasattr(iid, 'hex'):
|
||||
result['_iid'] = iid.hex()
|
||||
result['id'] = iid.hex()
|
||||
else:
|
||||
# iid is already a string
|
||||
result['_iid'] = str(iid)
|
||||
result['id'] = str(iid)
|
||||
|
||||
if hasattr(concept, 'get_value'):
|
||||
result['value'] = concept.get_value()
|
||||
|
|
@ -127,8 +138,18 @@ def serialize_concept_map(concept_map) -> Dict[str, Any]:
|
|||
concept = concept_map.get(var)
|
||||
if concept:
|
||||
if hasattr(concept, 'get_value'):
|
||||
# It's an attribute value
|
||||
result[var] = concept.get_value()
|
||||
# It's an attribute value - include type info for frontend
|
||||
attr_type = None
|
||||
if hasattr(concept, 'get_type'):
|
||||
concept_type = concept.get_type()
|
||||
if hasattr(concept_type, 'get_label'):
|
||||
label = concept_type.get_label()
|
||||
attr_type = label.name if hasattr(label, 'name') else str(label)
|
||||
|
||||
result[var] = {
|
||||
'value': concept.get_value(),
|
||||
'type': attr_type,
|
||||
}
|
||||
elif hasattr(concept, 'get_iid'):
|
||||
# It's an entity or relation
|
||||
result[var] = serialize_concept(concept)
|
||||
|
|
|
|||
Loading…
Reference in a new issue