1 import Base 2 import ./ordinary_app_registration_fields.bend as Records 3 import ./ordinary_query_declaration.bend as Query 4 import ./ordinary_app_observation_data.bend as DTO 5 # Called only from enabled snapshot. Ordinary fields are not a cached description. 6 def resource_clauses(~S:Data,+mode:Query.Mode,access:List<&2,String>) -> List<&2,Query.Clause>: 7 match access: 8 case []:[] 9 case name <> rest:Query.Clause{name,mode} <> resource_clauses(~S,mode,rest) 10 def mixed_clauses(~S:Data,uses:List<&2,Records.DeclaredUse>) -> List<&2,Query.Clause>: 11 match uses: 12 case []:[] 13 case Records.DeclaredUse{_,_,key,mode} <> rest:Query.Clause{key,mode} <> mixed_clauses(~S,rest) 14 def clauses(~S:Data,kind:Records.RegistrationKind,access:List<&2,String>,retained:List<&2,Query.Clause>) -> List<&2,Query.Clause>: 15 match kind: 16 case Records.ComponentKind{}:retained 17 case Records.FieldKind{}:retained 18 case Records.ServiceKind{}:[] 19 case Records.EventKind{}:retained 20 case Records.MixedKind{uses}:mixed_clauses(~S,uses) 21 case Records.ResourceKind{mode}:resource_clauses(~S,mode,access) 22 def binding(~S:Data,fields:Records.Fields) -> DTO.Binding: 23 match fields: 24 case Records.Fields{+namespace,+id,+name,+access,+cursor,+slot,retained,kind}:DTO.Binding{namespace,id,name,access,cursor,slot,clauses(~S,kind,access,retained)} 25 def bindings(~S:Data,records:List<&2,Records.Fields>) -> List<&2,DTO.Binding>: 26 match records: 27 case []:[] 28 case record <> rest:binding(~S,record) <> bindings(~S,rest)