import Base import ./change_tick.bend as Tick import ./world.bend as W import ./system.bend as Sys import ./transaction.bend as Tx import ./commands.bend as Cmd import ./capabilities.bend as Cap import ./reader_parameter.bend as RP import ./event_notice_runtime.bend as Mixed import ./event_family_routing.bend as Route import ./relation_commands.bend as Notice import ./internal/relation_failures/domains.bend as D import ./ordinary_reader_system.bend as Ordinary import ./ordinary_app_reader_parameter.bend as Parameter import ./ordinary_app_registration_fields.bend as Fields import ./ordinary_app_composer.bend as Build import ./ordinary_app_records.bend as Pair import ./ordinary_app_recipe.bend as Tree import ./ordinary_app_observation_data.bend as DTO # Retained declaration facts belong to the provider's existing Declaration owner. # The ordinary definition receives the same generated parameter and facts together. def define_mixed(~S:Data,~C:Type,~R:Type,~P:Data,~F:Type,~H:Type, ~Reader:Type,~View:Data,~Delta:Type,~Args:Type,~Failure:Data,~Output:Type, ~validateFn:Route.Runtime,Mixed.State> -> Reader -> Route.Runtime,Mixed.State> & (Reader & Bool), ~prepareFn:Route.Runtime,Mixed.State> -> @+cursor:Maybe<&2,Tick.Tick> -> Reader -> Route.Runtime,Mixed.State> & (Reader & (View & Delta)), ~commitFn:Route.Runtime,Mixed.State> -> Reader -> Delta -> @+cursor:Tick.Tick -> Route.Runtime,Mixed.State> & Reader,~releaseFn:Route.Runtime,Mixed.State> -> Reader -> Route.Runtime,Mixed.State>, ~Ops:Type -> Type, ~body:@-K:Type -> @-caps:Ops(K) -> (View & Args) -> K -> K & (Tx.Outcome & Output), ~grant:Ops(Tx.Tx>,Notice.Notice>), ~sync:F -> Nat -> List<&2,P> -> F, ~classify:Notice.Notice -> Maybe>, ~initialize:Route.Runtime,Mixed.State> -> RP.RegistrationFacts -> Route.Runtime,Mixed.State> & (Reader & RP.Param,Mixed.State>,Reader,View,Delta,validateFn,prepareFn,commitFn,releaseFn>), descriptor:Parameter.Declared,Mixed.State>,Reader,View,Delta,validateFn,prepareFn,commitFn,releaseFn>>, context:Route.Runtime,Mixed.State>,name:String) -> Ordinary.Definition,Mixed.State>,Ordinary.Provider,Ordinary.Invocation<(Mixed.State & Nat),Reader,RP.Param,Mixed.State>,Reader,View,Delta,validateFn,prepareFn,commitFn,releaseFn>,List<&2,Fields.DeclaredUse>,Args>,Empty,Ordinary.Envelope<(Mixed.State & Nat),Reader,RP.Param,Mixed.State>,Reader,View,Delta,validateFn,prepareFn,commitFn,releaseFn>,List<&2,Fields.DeclaredUse>,Failure,Output>,Ordinary.shared_runner(~S,~C,~R,~P,~F,~H,~Reader,~View,~Delta,~Args,~List<&2,Fields.DeclaredUse>,~Failure,~Output,~validateFn,~prepareFn,~commitFn,~releaseFn,~Ops,~body,~grant,~sync,~classify)>,Reader,RP.Param,Mixed.State>,Reader,View,Delta,validateFn,prepareFn,commitFn,releaseFn>,List<&2,Fields.DeclaredUse>>,RP.Param,Mixed.State>,Reader,View,Delta,validateFn,prepareFn,commitFn,releaseFn>,List<&2,Fields.DeclaredUse>>: match descriptor: case Parameter.Declared{parameter,uses}:Ordinary.define_mixed(~S,~C,~R,~P,~F,~H,~Reader,~View,~Delta,~Args,~List<&2,Fields.DeclaredUse>,~Failure,~Output,~validateFn,~prepareFn,~commitFn,~releaseFn,~Ops,~body,~grant,~sync,~classify,~initialize,parameter,uses,context,name) # One registration produces one Binding, even when its parameters span categories. def fold(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Type,~Error:Data,~Output:Type,~runner:W.World -> Args -> Sys.Outcome,Error,Output>,~Reader:Type,~Param:Type,value:Ordinary.Provider,Reader,Param,List<&2,Fields.DeclaredUse>>) -> Ordinary.Provider,Reader,Param,List<&2,Fields.DeclaredUse>> & List<&2,Fields.Fields>: match value: case Ordinary.Provider{Sys.Registry{+namespace,+id,+name,+access,+cursor},reader,parameter,+uses}:(Ordinary.Provider{Sys.Registry{namespace,id,name,access,cursor},reader,parameter,uses},[Fields.Fields{namespace,id,name,access,cursor,name,[],Fields.MixedKind{uses}}]) def sources(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Type,~Error:Data,~Output:Type,~runner:W.World -> Args -> Sys.Outcome,Error,Output>,~Reader:Type,~Param:Type,value:Ordinary.Provider,Reader,Param,List<&2,Fields.DeclaredUse>>) -> Ordinary.Provider,Reader,Param,List<&2,Fields.DeclaredUse>> & List<&2,Fields.DeclaredUse>: match value: case Ordinary.Provider{registry,reader,parameter,+uses}:(Ordinary.Provider{registry,reader,parameter,uses},uses) def fold_meta_returned(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Type,~Error:Data,~Output:Type,~runner:W.World -> Args -> Sys.Outcome,Error,Output>,~Reader:Type,~Param:Type,~Meta:Type,meta:Meta,result:Ordinary.Provider,Reader,Param,List<&2,Fields.DeclaredUse>> & List<&2,Fields.Fields>) -> (Meta & Ordinary.Provider,Reader,Param,List<&2,Fields.DeclaredUse>>) & List<&2,Fields.Fields>: match result: case (provider,fields):((meta,provider),fields) def fold_meta(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Type,~Error:Data,~Output:Type,~runner:W.World -> Args -> Sys.Outcome,Error,Output>,~Reader:Type,~Param:Type,~Meta:Type,value:Meta & Ordinary.Provider,Reader,Param,List<&2,Fields.DeclaredUse>>) -> (Meta & Ordinary.Provider,Reader,Param,List<&2,Fields.DeclaredUse>>) & List<&2,Fields.Fields>: match value: case (meta,provider):fold_meta_returned(~S,~C,~R,~E,~Args,~Error,~Output,~runner,~Reader,~Param,~Meta,meta,fold(~S,~C,~R,~E,~Args,~Error,~Output,~runner,~Reader,~Param,provider)) # Operational runtime metadata remains affine in H, beside the actual provider. # The library composes the fold; application setup supplies no debug adapter. def attach(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Type,~Error:Data,~Output:Type,~runner:W.World -> Args -> Sys.Outcome,Error,Output>,~Reader:Type,~Param:Type,~Meta:Type,~Previous:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~previousFold:Previous -> Previous & List<&2,Fields.Fields>,world:W.World,previous:Previous,meta:Meta,provider:Ordinary.Provider,Reader,Param,List<&2,Fields.DeclaredUse>>,recipe:Tree.Recipe,Rows,observe>,debug:Bool) -> Build.Registered,Previous & (Meta & Ordinary.Provider,Reader,Param,List<&2,Fields.DeclaredUse>>),Rows,observe,Pair.fold_pair(~S,~Previous,~(Meta & Ordinary.Provider,Reader,Param,List<&2,Fields.DeclaredUse>>),~previousFold,~fold_meta(~S,~C,~R,~E,~Args,~Error,~Output,~runner,~Reader,~Param,~Meta))>: Build.Registered{world,(previous,(meta,provider)),recipe,debug} # Registration refusal recovers the generated descriptor. If disposal itself # refuses, its sole provider still owns the initialized readers and declaration. type Recovered<-S:Data,-Context:Type,-Provider:Type,-Param:Data> is Type: Registered{context:Context,provider:Provider} Rejected{context:Context,descriptor:Parameter.Declared} DisposalRejected{context:Context,provider:Provider,descriptor:Parameter.Declared} def disposal_recovered(~S:Data,~Context:Type,~Registry:Type,~Reader:Type,~Param:Data,context:Context,parameter:Param,provider:Ordinary.Provider>) -> Recovered>,Param>: match provider: case Ordinary.Provider{registry,reader,initialized,+uses}:DisposalRejected{context,Ordinary.Provider{registry,reader,initialized,uses},Parameter.Declared{parameter,uses}} def recover(~S:Data,~Context:Type,~Registry:Type,~Reader:Type,~Param:Data,result:Ordinary.Definition>,Param,List<&2,Fields.DeclaredUse>>) -> Recovered>,Param>: match result: case Ordinary.DefinitionRegistered{context,provider}:Registered{context,provider} case Ordinary.DefinitionRejected{context,parameter,uses}:Rejected{context,Parameter.Declared{parameter,uses}} case Ordinary.DefinitionDisposalRejected{context,provider,parameter}:disposal_recovered(~S,~Context,~Registry,~Reader,~Param,context,parameter,provider) # A routed application already owns its sole World inside Context. def attach_context(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Type,~Error:Data,~Output:Type,~runner:W.World -> Args -> Sys.Outcome,Error,Output>,~Reader:Type,~Param:Type,~Context:Type,~Previous:Type,~Rows:Data,~observe:Context -> Context & DTO.Observation,~previousFold:Previous -> Previous & List<&2,Fields.Fields>,context:Context,previous:Previous,provider:Ordinary.Provider,Reader,Param,List<&2,Fields.DeclaredUse>>,recipe:Tree.Recipe,debug:Bool) -> Build.Registered,Reader,Param,List<&2,Fields.DeclaredUse>>,Rows,observe,Pair.fold_pair(~S,~Previous,~Ordinary.Provider,Reader,Param,List<&2,Fields.DeclaredUse>>,~previousFold,~fold(~S,~C,~R,~E,~Args,~Error,~Output,~runner,~Reader,~Param))>: Build.Registered{context,(previous,provider),recipe,debug}