ordinary_bundle.bend

bendvy-ecs-core@0.1.0.1 · 40 lines · 0 definitions

1import Base
2import ordinary_declaration.bend as Identity
3import schema_fragments.bend as SF
4import bundle_pack.bend as Pack
5import bundle_requests.bend as Cmd
6import bundle_construction.bend as CS
7import 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.
14type Plan<-S:Data,-Raw:Type,-Cooked:Type> is Data:
15  Plan{entries:List<&2,SF.Entry<S>>}
16# Empty bundle plan for Unit raw/cooked tails; performs no construction.
17def terminal(~S:Data) -> Plan<S,Unit,Unit>: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.
20def component(~S:Data,~I:Type,~P:Type,+identity:Identity.Declaration<S,P>) -> Plan<S,I,P>:
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.
25def compose(~S:Data,~HR:Type,~HC:Type,~TR:Type,~TC:Type,head:Plan<S,HR,HC>,tail:Plan<S,TR,TC>) -> Plan<S,Pack.Pack<HR,TR>,Pack.Pack<HC,TC>>:
26  match head tail:
27    case Plan{heads} Plan{tails}:Plan{List.append(&2,SF.Entry<S>,heads,tails)}
28def checked(~S:Data,~Store:Type,~R:Type,~E:Data,~Packet:Type,~Context:Type,~Raw:Type,~Cooked:Type,~Error:Data,~construct:Context -> Raw -> CS.Staged<Context,Raw,Cooked,Error>,~pack:Cooked -> (Cooked -> Raw) -> Packet,~unpack:Packet -> Raw,validation:SF.Validation,owner:AD.Owner<S,Store,R,E,Packet,Context>,input:Cmd.Input<S,Raw>) -> AD.Owner<S,Store,R,E,Packet,Context> & Cmd.Output<S,Raw,Error>:
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.
38def request(~S:Data,~Store:Type,~R:Type,~E:Data,~Packet:Type,~Context:Type,~Raw:Type,~Cooked:Type,~Error:Data,~construct:Context -> Raw -> CS.Staged<Context,Raw,Cooked,Error>,~pack:Cooked -> (Cooked -> Raw) -> Packet,~unpack:Packet -> Raw,plan:Plan<S,Raw,Cooked>,owner:AD.Owner<S,Store,R,E,Packet,Context>,input:Cmd.Input<S,Raw>) -> AD.Owner<S,Store,R,E,Packet,Context> & Cmd.Output<S,Raw,Error>:
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)