import Base import ./decode_data.bend as D import ./persistence_declaration.bend as Persist import ./owner_product.bend as Product import ./ordinary_declaration.bend as Component import ./column.bend as Col import ./schema_fragments.bend as Fragment # One normal declaration drives schema entries and physical Store/Resources types. # Names default to the one ordinary key. No user metadata or lens input. # Detached schema description indexed by the component and resource owner # types. It contains no world or payloads; product derives matching owner # products. Raw Schema construction is trusted metadata setup. type Schema<-S:Data,-Store:Type,-Resources:Type> is Data: Schema{entries:List<&2,Fragment.Entry>} # Schema-scoped resource key and payload type, without a resource instance. # Convert with resource_schema before composition and collision validation. type Resource<-S:Data,-P:Type> is Data: Resource{key:String} # Declare a resource key for schema S and payload P. No payload is allocated # or provisioned and duplicate keys are not checked until schema validation. def resource(~S:Data,~P:Type,key:String) -> Resource: Resource{key} # Return the authored resource key; does not read a runtime resource. def resource_key(~S:Data,~P:Type,value:Resource) -> String: match value: case Resource{key}:key # Describe a component declaration and derive its column owner type. # Does not allocate storage or validate collisions. Compose with product and # validate before App attachment; examples/scheduled-health/registration.bend. def component(~S:Data,~P:Type,declaration:Component.Declaration) -> Schema,Unit>: +key=Component.key(~S,~P,declaration) Schema{[Fragment.Entry{Fragment.Component{},key,key}]} # Describe a resource and derive its resource owner type without constructing # its payload. This declaration supplies metadata, not a live resource value. def resource_schema(~S:Data,~P:Type,declaration:Resource) -> Schema: +key=resource_key(~S,~P,declaration) Schema{[Fragment.Entry{Fragment.Resource{},key,key}]} # Return schema entries in composition order, detached from all world owners. def entries(~S:Data,~C:Type,~R:Type,value:Schema) -> List<&2,Fragment.Entry>: match value: case Schema{entries}:entries # Compose two same-schema declarations, appending entries left then right # and deriving matching component/resource Product.Owner types. Supports # arbitrary affine payload types; does not copy payloads or reject collisions. def product(~S:Data,~LC:Type,~LR:Type,~RC:Type,~RR:Type,left:Schema,right:Schema) -> Schema,Product.Owner>: Schema{List.append(&2,Fragment.Entry,entries(~S,~LC,~LR,left),entries(~S,~RC,~RR,right))} # Check composed declaration entries for schema conflicts, returning the # structured Fragment.Validation result. No World exists in this operation; # validation neither constructs payloads nor proves trusted storage lens laws. def validate(~S:Data,~C:Type,~R:Type,value:Schema) -> Fragment.Validation: Fragment.validate_loop(~S,entries(~S,~C,~R,value),[]) # Declare a component with plain persistence classification from its bound # extension. Records the classification and derives the owner type; does not # execute codecs, validate input, allocate payloads or export a snapshot. # Use the matching persistence declaration and identity when composing a schema. def component_plain(~S:Data,~P:Type,~identity:Component.Declaration,extension:Persist.Plain) -> Schema,Unit>: +key=Component.key(~S,~P,identity) Schema{[Fragment.Classified{Fragment.Component{},key,key,Fragment.Plain{}}]} # Declare a component with transient persistence classification from its bound # extension. Records the classification and derives the owner type; does not # execute codecs, validate input, allocate payloads or export a snapshot. # Use the matching persistence declaration and identity when composing a schema. def component_transient(~S:Data,~P:Type,~identity:Component.Declaration,extension:Persist.Transient) -> Schema,Unit>: +key=Component.key(~S,~P,identity) Schema{[Fragment.Classified{Fragment.Component{},key,key,Fragment.Transient{}}]} # Declare a component with constructed persistence classification from its bound # extension. Records the classification and derives the owner type; does not # execute codecs, validate input, allocate payloads or export a snapshot. # Use the matching persistence declaration and identity when composing a schema. def component_constructed(~S:Data,~P:Type,~identity:Component.Declaration,~project:P -> P & D.Raw,extension:Persist.Constructed) -> Schema,Unit>: +key=Component.key(~S,~P,identity) Schema{[Fragment.Classified{Fragment.Component{},key,key,Fragment.Constructed{}}]} # Declare a resource with plain persistence classification from its bound # extension. Records the classification and derives the owner type; does not # execute codecs, validate input, allocate payloads or export a snapshot. # Use the matching persistence declaration and identity when composing a schema. def resource_plain(~S:Data,~P:Type,~identity:Component.Declaration,extension:Persist.Plain) -> Schema: +key=Component.key(~S,~P,identity) Schema{[Fragment.Classified{Fragment.Resource{},key,key,Fragment.Plain{}}]} # Declare a resource with transient persistence classification from its bound # extension. Records the classification and derives the owner type; does not # execute codecs, validate input, allocate payloads or export a snapshot. # Use the matching persistence declaration and identity when composing a schema. def resource_transient(~S:Data,~P:Type,~identity:Component.Declaration,extension:Persist.Transient) -> Schema: +key=Component.key(~S,~P,identity) Schema{[Fragment.Classified{Fragment.Resource{},key,key,Fragment.Transient{}}]} # Declare a resource with constructed persistence classification from its bound # extension. Records the classification and derives the owner type; does not # execute codecs, validate input, allocate payloads or export a snapshot. # Use the matching persistence declaration and identity when composing a schema. def resource_constructed(~S:Data,~P:Type,~identity:Component.Declaration,~project:P -> P & D.Raw,extension:Persist.Constructed) -> Schema: +key=Component.key(~S,~P,identity) Schema{[Fragment.Classified{Fragment.Resource{},key,key,Fragment.Constructed{}}]}