1 import Base 2 import ./recovery_use.bend as Use 3 import ./resource_field_binding.bend as Binding 4 import ./world.bend as W 5 import ./owner_product.bend as Product 6 import ./ordinary_recovery_declaration.bend as D 7 import ./ordinary_recoverable_array_resource.bend as F 8 import ./recoverable_array.bend as A 9 import ./recoverable_array_owner.bend as AO 10 import ./recovery_journal.bend as Journal 11 import ./world_resource_owner.bend as WR 12 import ./ordinary_schema.bend as Schema 13 # Canonical selected resource field with generated recovery path; no caller inverse. 14 # Binding supplies the same identity/path pair as ordinary resource-field grants. 15 # Advanced capability-shape projection for identity-indexed recoverable Array
16 # replacement and checked element swap, with opaque execution owner H.
17 def Ops(~S:Data,~P:Type,~identity:Schema.Resource ,(Capture & WR.Rest ,~FieldRest,~resource_target(~S,~C,~R,~E,~Capture),~fieldLens)
26 def empty(~Capture:Type,~R:Type,~P:Type,~FieldRest:Type,~fieldLens:Product.Lens , install it in
31 # the selected field and journal the displaced array in the shared recovery path.
32 # Commit returns displaced owners; rollback restores originals and returns displaced
33 # replacements through the declaration recovery result, not a duplicate live owner.
34 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
18 # Trusted recovery lens into World resources while threading actual capture and
19 # all other World fields. This is setup plumbing, not a gameplay World accessor.
20 def resource_target(~S:Data,~C:Type,~R:Type,~E:Data,~Capture:Type) -> Product.Lens>:
21 Product.compose(~Product.Owner,~Capture,~R,~WR.Rest,~Product.lens(~W.World,~Capture,~Product.Left{}),~WR.lens(~S,~C,~R,~E))
22 # Trusted composition of World-resource and selected Array-field lenses.
23 # Canonical binding supplies the identity/path pair; siblings/capture stay owned.
24 def target(~S:Data,~C:Type,~E:Data,~Capture:Type,~R:Type,~P:Type,~FieldRest:Type,~fieldLens:Product.Lens) & FieldRest>:
25 Product.compose(~Product.Owner),~Array) & FieldRest),~target(~S,~C,~E,~Capture,~R,~P,~FieldRest,~fieldLens),~All,~Rest,~path,state,journal,incoming))
37 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))
48 # Advanced canonical grant builder hiding resource lens and journal plumbing
49 # behind the identity-indexed recoverable write operations. Does not execute them.
50 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>>:
51 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)}
52 # Derive the recoverable selected Array resource declaration from its canonical
53 # Binding. Initializes empty recovery records and publishes known Write-use metadata
54 # for this resource key. Shared recovery composition controls finish/undo order;
55 # there is no caller-authored inverse or automatic external-effect rollback.
56 # See docs/parity/recovery.md for explicit owned recovery boundaries.
57 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