1 import Base 2 import ordinary_declaration.bend as Identity 3 import schema_fragments.bend as SF 4 import bundle_pack.bend as Pack 5 import bundle_requests.bend as Cmd 6 import bundle_construction.bend as CS 7 import bundle_insert_adapter.bend as AD 8 9 # Metadata only. Raw constructors and the declared factory/binding remain trusted. 10 # This plan supplies no World, storage or provider capability. 11 # Schema-indexed bundle metadata for raw input and cooked heterogeneous 12 # payload types. Contains no payload, world or provider; trusted construction 13 # and binding callbacks supply the actual operations. See docs/parity/bundles.md. 14 type Plan<-S:Data,-Raw:Type,-Cooked:Type> is Data: 15 Plan{entries:List<&2,SF.Entry>} 16 # Empty bundle plan for Unit raw/cooked tails; performs no construction. 17 def terminal(~S:Data) -> Plan:Plan{[]} 18 # Describe one component in a bundle using its schema-scoped declaration. 19 # Adds metadata only; does not allocate a column or accept a payload. 20 def component(~S:Data,~I:Type,~P:Type,+identity:Identity.Declaration) -> Plan: 21 Plan{[SF.Entry{SF.Component{},Identity.key(~S,~P,identity),Identity.key(~S,~P,identity)}]} 22 # Append head/tail component entries and derive matching nested Pack types. 23 # Preserves heterogeneous affine payload shapes without receiving live payloads; 24 # collisions are checked by request, not by this composition step. 25 def compose(~S:Data,~HR:Type,~HC:Type,~TR:Type,~TC:Type,head:Plan,tail:Plan) -> Plan,Pack.Pack>: 26 match head tail: 27 case Plan{heads} Plan{tails}:Plan{List.append(&2,SF.Entry,heads,tails)} 28 def checked(~S:Data,~Store:Type,~R:Type,~E:Data,~Packet:Type,~Context:Type,~Raw:Type,~Cooked:Type,~Error:Data,~construct:Context -> Raw -> CS.Staged,~pack:Cooked -> (Cooked -> Raw) -> Packet,~unpack:Packet -> Raw,validation:SF.Validation,owner:AD.Owner,input:Cmd.Input) -> AD.Owner & Cmd.Output: 29 match validation input: 30 case SF.Invalid{error} Cmd.Input{_,raw}:(owner,Cmd.Refused{raw,AD.DeclarationRefused{error}}) 31 case SF.Valid{} input:Cmd.request(~S,~Store,~R,~E,~Packet,~Context,~Raw,~Cooked,~Error,~construct,~pack,~unpack,owner,input) 32 # Validate bundle metadata before invoking construction/command staging. 33 # Declaration refusal returns the opaque owner and original raw input without 34 # running construct. Other results follow the bound bundle request contract. 35 # Successful staging is deferred; visibility requires an explicit barrier. 36 # Raw adapters, reversible constructors and pack/unpack remain trusted setup. 37 # Ownership/error scenarios: docs/parity/bundles.md. 38 def request(~S:Data,~Store:Type,~R:Type,~E:Data,~Packet:Type,~Context:Type,~Raw:Type,~Cooked:Type,~Error:Data,~construct:Context -> Raw -> CS.Staged,~pack:Cooked -> (Cooked -> Raw) -> Packet,~unpack:Packet -> Raw,plan:Plan,owner:AD.Owner,input:Cmd.Input) -> AD.Owner & Cmd.Output: 39 match plan: 40 case Plan{entries}:checked(~S,~Store,~R,~E,~Packet,~Context,~Raw,~Cooked,~Error,~construct,~pack,~unpack,SF.validate(~S,entries),owner,input)