Explorer

definy.sync-submit

description
Submit an event, and when its contents are missing, upload them and submit it again
type
Fn(
  submit: Fn(
    request: @definy.json,
    then: Fn(result: Union{#ok(@definy.json), #error(String)}) -> @definy.service-io
  ) -> @definy.service-io,
  fetch_contents: Fn(
    hashes: List<String>,
    then: Fn(result: Union{#ok(List<@definy.json>), #error(String)}) -> @definy.service-io
  ) -> @definy.service-io,
  upload: Fn(
    items: List<@definy.json>,
    then: Fn(result: Union{#ok(@definy.json), #error(String)}) -> @definy.service-io
  ) -> @definy.service-io,
  event: @definy.stored-event,
  then: Fn(error: Union{#none, #some(String)}) -> @definy.service-io
) -> @definy.service-io
expression
fn(submit$0, fetch_contents$1, upload$2, event$3, then$4) =>
  let request$5 = #object<@definy.json>([{key: "signedEventBytes", value: #string<@definy.json>($3.signed_event_bytes)}]);
  $0(
    request: $5,
    then: fn(result$6) =>
      match $6 {
        #error(message$7) =>
          $4(error: #some($7)),
        #ok(json$8) =>
          match @definy.json-get-string(value: $8, key: "status") {
            #some("missing_content") =>
              $1(
                hashes: match @definy.json-get-strings(value: $8, key: "missingContentHashes") {
                  #some(hashes$9) =>
                    $9,
                  #none(_) =>
                    []
                },
                then: fn(result$10) =>
                  match $10 {
                    #error(message$11) =>
                      $4(error: #some($11)),
                    #ok(items$12) =>
                      $2(
                        items: $12,
                        then: fn(result$13) =>
                          match $13 {
                            #error(message$14) =>
                              $4(error: #some($14)),
                            #ok(_) =>
                              $0(
                                request: $5,
                                then: fn(result$15) =>
                                  match $15 {
                                    #error(message$16) =>
                                      $4(error: #some($16)),
                                    #ok(json$17) =>
                                      match @definy.json-get-string(value: $17, key: "status") {
                                        #some("missing_content") =>
                                          $4(error: #some("the contents of the event are still missing")),
                                        _ =>
                                          $4(error: #none)
                                      }
                                  }
                              )
                          }
                      )
                  }
              ),
            _ =>
              $4(error: #none)
          }
      }
  )
visibility
public
definy.sync-submit (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: R-IbQaz-HEn6akeyrlsmwE3IApS-wMkqv7KPChs_ZBo
content hash: 400vPDt_e0Qxk--yqAxQJe8JEve-KFVXVGbOlzC583k