hyf

Context-aware query service for Radroots
git clone https://radroots.dev/git/hyf.git
Log | Files | Refs | README | LICENSE

request_context_contract.mojo (784B)


      1 from std.collections import List
      2 
      3 from json import Value, loads
      4 
      5 from hyf_core.request_context import (
      6     accepted_request_context_feature_names,
      7     effective_request_context_feature_names,
      8 )
      9 
     10 
     11 def _string_array(values: List[String]) raises -> Value:
     12     var array = loads("[]")
     13     for value in values:
     14         array.append(Value(String(value)))
     15     return array^
     16 
     17 
     18 def build_request_context_contract_value() raises -> Value:
     19     var contract = loads("{}")
     20     contract.set(
     21         "accepted_features",
     22         _string_array(accepted_request_context_feature_names()),
     23     )
     24     contract.set(
     25         "effective_features",
     26         _string_array(effective_request_context_feature_names()),
     27     )
     28     contract.set("unsupported_field_behavior", Value("reject"))
     29     return contract^