import Base import ./recovery_use.bend as Use import ./resource_field_binding.bend as Binding import ./world.bend as W import ./owner_product.bend as Product import ./ordinary_recovery_declaration.bend as D import ./ordinary_recoverable_array_resource.bend as F import ./recoverable_array.bend as A import ./recoverable_array_owner.bend as AO import ./recovery_journal.bend as Journal import ./world_resource_owner.bend as WR import ./ordinary_schema.bend as Schema # Canonical selected resource field with generated recovery path; no caller inverse. # Binding supplies the same identity/path pair as ordinary resource-field grants. # Advanced capability-shape projection for identity-indexed recoverable Array
# replacement and checked element swap, with opaque execution owner H.
def Ops(~S:Data,~P:Type,~identity:Schema.Resource ,(Capture & WR.Rest ,~FieldRest,~resource_target(~S,~C,~R,~E,~Capture),~fieldLens)
def empty(~Capture:Type,~R:Type,~P:Type,~FieldRest:Type,~fieldLens:Product.Lens , install it in
# the selected field and journal the displaced array in the shared recovery path.
# Commit returns displaced owners; rollback restores originals and returns displaced
# replacements through the declaration recovery result, not a duplicate live owner.
def replace(~S:Data,~C:Type,~E:Data,~Capture:Type,~R:Type,~P:Type,~FieldRest:Type,~fieldLens:Product.Lens ) -> F.Frame ,identity)],Use.known([Use.Use{Use.Resource{Schema.resource_key(~S,~Array ,identity)},Use.Write{}}])}
>,H:Type) -> Type:F.Write
# Trusted recovery lens into World resources while threading actual capture and
# all other World fields. This is setup plumbing, not a gameplay World accessor.
def resource_target(~S:Data,~C:Type,~R:Type,~E:Data,~Capture:Type) -> Product.Lens>:
Product.compose(~Product.Owner,~Capture,~R,~WR.Rest,~Product.lens(~W.World,~Capture,~Product.Left{}),~WR.lens(~S,~C,~R,~E))
# Trusted composition of World-resource and selected Array-field lenses.
# Canonical binding supplies the identity/path pair; siblings/capture stay owned.
def target(~S:Data,~C:Type,~E:Data,~Capture:Type,~R:Type,~P:Type,~FieldRest:Type,~fieldLens:Product.Lens) & FieldRest>:
Product.compose(~Product.Owner),~Array) & FieldRest),~target(~S,~C,~E,~Capture,~R,~P,~FieldRest,~fieldLens),~All,~Rest,~path,state,journal,incoming))
def swapped(~S:Data,~C:Type,~E:Data,~Capture:Type,~R:Type,~P:Type,~FieldRest:Type,~fieldLens:Product.Lens) & FieldRest),~target(~S,~C,~E,~Capture,~R,~P,~FieldRest,~fieldLens),~All,~Rest,~path,state,journal,index,incoming))
# Advanced canonical grant builder hiding resource lens and journal plumbing
# behind the identity-indexed recoverable write operations. Does not execute them.
def grant(~S:Data,~C:Type,~E:Data,~Capture:Type,~R:Type,~P:Type,~FieldRest:Type,~fieldLens:Product.Lens>,~All:Type,~Rest:Type,~path:Product.Lens,Capture>,All>>:
F.Write{replace(~S,~C,~E,~Capture,~R,~P,~FieldRest,~fieldLens,~All,~Rest,~path),swap(~S,~C,~E,~Capture,~R,~P,~FieldRest,~fieldLens,~All,~Rest,~path)}
# Derive the recoverable selected Array resource declaration from its canonical
# Binding. Initializes empty recovery records and publishes known Write-use metadata
# for this resource key. Shared recovery composition controls finish/undo order;
# there is no caller-authored inverse or automatic external-effect rollback.
# See docs/parity/recovery.md for explicit owned recovery boundaries.
def declaration(~S:Data,~C:Type,~E:Data,~Capture:Type,~R:Type,~P:Type,~FieldRest:Type,~fieldLens:Product.Lens>,~binding:Binding.Binding,FieldRest,fieldLens,identity>) -> D.Declaration,Capture>,List