1 import Base 2 import ./decode_data.bend as D 3 import ./snapshot_data.bend as Snapshot 4 import ./restore_raw.bend as Raw 5 6 # ParseRejected returns actual unchanged owner/runtime with original Raw/error. 7 # Delivered retains original Raw beside the restore callback's actual Output; 8 # its inner outcome/recovery determines semantic restore success or refusal. 9 type Returned is Type: 10 ParseRejected{owner:Owner,runtime:Runtime,original:D.Raw,error:Raw.Error} 11 Delivered{original:D.Raw,output:Output} 12 def parsed(~Owner:Type,~Runtime:Type,~Output:Type,~run:Owner -> Runtime -> Snapshot.Snapshot -> Output,+original:D.Raw,owner:Owner,runtime:Runtime,result:Raw.Parsed) -> Returned: 13 match result: 14 case Raw.Rejected{input,error}:ParseRejected{owner,runtime,input,error} 15 case Raw.Accepted{snapshot}:Delivered{original,run(owner,runtime,snapshot)} 16 # Parse before invoking the closed typed restore callback. Parse failure does not 17 # call restore or consume its actual owners; success transfers owner/runtime and 18 # Snapshot exactly once. Callback Output must retain whatever owners/results its 19 # contract requires; this generic wrapper adds no rollback or recovery guarantee. 20 # See docs/parity/restore-basic.md and its RawOwner.run consumer. 21 def run(~Owner:Type,~Runtime:Type,~Output:Type,~restore:Owner -> Runtime -> Snapshot.Snapshot -> Output,owner:Owner,runtime:Runtime,+input:D.Raw) -> Returned: 22 parsed(~Owner,~Runtime,~Output,~restore,input,owner,runtime,Raw.parse(input))