1 import Base 2 import ./change_tick.bend as Tick 3 import ./world.bend as W 4 import ./system.bend as Sys 5 import ./ordinary_system.bend as System 6 import ./ordinary_resource_system.bend as Resource 7 import ./ordinary_query_declaration.bend as Query 8 # Sole ordinary registration fields; no detached debug Binding or cached description. 9 # The private trusted token holds the actual registration's erased runner authority. 10 # Mixed readers retain each operational source rather than inferring modes from access strings. 11 # Detached classification of declared component, resource or event usage. 12 type UseCategory is Data: 13 ComponentUse{} 14 ResourceUse{} 15 EventUse{} 16 # Detached origin of a read declaration, including distinct notice streams. 17 type ReaderSource is Data: 18 QuerySource{} 19 MessageSource{} 20 RemovalSource{} 21 RelationFailureSource{} 22 # Detached key/mode and source of one declared access; not runtime authority. 23 type DeclaredUse is Data: 24 DeclaredUse{category:UseCategory,source:ReaderSource,key:String,mode:Query.Mode} 25 # Detached registration category; mixed registrations retain each declared use. 26 type RegistrationKind is Data: 27 ComponentKind{} 28 ResourceKind{mode:Query.Mode} 29 FieldKind{} 30 ServiceKind{} 31 EventKind{} 32 MixedKind{uses:List<&2,DeclaredUse>} 33 # Detached advanced registration description: namespace/ID/name/access, 34 # cursor, authored slot/query clauses and operation kind. This Data record 35 # is observation metadata; it does not independently prove a live registration 36 # or authorize execution without its matching typed token and World checks. 37 type Fields is Data: 38 Fields{namespace:U32,id:U32,name:String,access:List<&2,String>,cursor:Maybe<&2,Tick.Tick>,slot:String,clauses:List<&2,Query.Clause>,kind:RegistrationKind} 39 type Token<-Registry:Type> is Type: 40 Token{} 41 def component_registry(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Type,~Error:Data,~Out:Type,~runner:W.World -> Args -> Sys.Outcome,Error,Out>,slot:String,clauses:List<&2,Query.Clause>,registry:Sys.Registry) -> Token> & Fields: 42 match registry: 43 case Sys.Registry{namespace,id,name,access,cursor}:(Token{},Fields{namespace,id,name,access,cursor,slot,clauses,ComponentKind{}}) 44 def component(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Type,~Error:Data,~Out:Type,~runner:W.World -> Args -> Sys.Outcome,Error,Out>,owner:System.Owner>) -> Token> & Fields: 45 match owner: 46 case System.Owner{registry,slot,clauses}:component_registry(~S,~C,~R,~E,~Args,~Error,~Out,~runner,slot,clauses,registry) 47 def restored_registry(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Type,~Error:Data,~Out:Type,~runner:W.World -> Args -> Sys.Outcome,Error,Out>,fields:Fields) -> System.Owner>: 48 match fields: 49 case Fields{namespace,id,name,access,cursor,slot,clauses,_}:System.Owner{Sys.Registry{namespace,id,name,access,cursor},slot,clauses} 50 def restore_component(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Type,~Error:Data,~Out:Type,~runner:W.World -> Args -> Sys.Outcome,Error,Out>,token:Token>,fields:Fields) -> System.Owner>: 51 match token: 52 case Token{}:restored_registry(~S,~C,~R,~E,~Args,~Error,~Out,~runner,fields) 53 def resource_registry(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Type,~Error:Data,~Out:Type,~runner:W.World -> Args -> Sys.Outcome,Error,Out>,~mode:Query.Mode,slot:String,registry:Sys.Registry) -> Token> & Fields: 54 match registry: 55 case Sys.Registry{namespace,id,name,access,cursor}:(Token{},Fields{namespace,id,name,access,cursor,slot,[],ResourceKind{mode}}) 56 def resource(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Type,~Error:Data,~Out:Type,~runner:W.World -> Args -> Sys.Outcome,Error,Out>,~mode:Query.Mode,owner:Resource.Owner,mode>) -> Token> & Fields: 57 match owner: 58 case Resource.Owner{registry,slot}:resource_registry(~S,~C,~R,~E,~Args,~Error,~Out,~runner,~mode,slot,registry) 59 def restored_resource(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Type,~Error:Data,~Out:Type,~runner:W.World -> Args -> Sys.Outcome,Error,Out>,~mode:Query.Mode,fields:Fields) -> Resource.Owner,mode>: 60 match fields: 61 case Fields{namespace,id,name,access,cursor,slot,_,_}:Resource.Owner{Sys.Registry{namespace,id,name,access,cursor},slot} 62 def restore_resource(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Type,~Error:Data,~Out:Type,~runner:W.World -> Args -> Sys.Outcome,Error,Out>,~mode:Query.Mode,token:Token>,fields:Fields) -> Resource.Owner,mode>: 63 match token: 64 case Token{}:restored_resource(~S,~C,~R,~E,~Args,~Error,~Out,~runner,~mode,fields) 65 66 # Field declarations retain each canonical clause, including mixed read/write packs. 67 def field_registry(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Type,~Error:Data,~Out:Type,~runner:W.World -> Args -> Sys.Outcome,Error,Out>,slot:String,clauses:List<&2,Query.Clause>,registry:Sys.Registry) -> Token> & Fields: 68 match registry: 69 case Sys.Registry{namespace,id,name,access,cursor}:(Token{},Fields{namespace,id,name,access,cursor,slot,clauses,FieldKind{}})