Explorer

definy.handle-event-service

description
Serves /definy.v1.EventService/* on a definy host that is not the old public server (definy.node-host-script on fly.io and so on, docs.fly-io), and the other requests with otherwise. The reading methods are the same as definy.handle-rpc. SubmitEvent is checked with definy.submit-event (signature, rules, types); only the events of accept_accounts are accepted unless accept_any_account is true. UploadContent stores only the contents that an accepted SubmitEvent said were missing (definy.accept-submit-event, definy.accept-upload-content)
type
Fn(
  request: @http.request,
  accept_accounts: List<String>,
  accept_any_account: Boolean,
  otherwise: Fn() -> @definy.service-io
) -> @definy.service-io
expression
fn(request$0, accept_accounts$1, accept_any_account$9, otherwise$2) =>
  match @std.string-starts-with(value: @http.path(request: $0), prefix: "/definy.v1.EventService/") {
    false =>
      $2(),
    true =>
      let method$3 = @core.string-slice(
          value: @http.path(request: $0),
          start: 24,
          end: @core.string-length(value: @http.path(request: $0))
        );
      @definy.ensure-seeded(
        then: fn(seeded$4) =>
          @definy.rpc-respond(
            cbor: @definy.request-wants-cbor(request: $0),
            io: match @definy.rpc-request-json(request: $0) {
              #invalid(message$6) =>
                @definy.rpc-error(code: "invalid_argument", message: $6),
              #json(json$7) =>
                match $3 {
                  "SubmitEvent" =>
                    @definy.accept-submit-event(request: $7, accept_accounts: $1, accept_any_account: $9),
                  "UploadContent" =>
                    @definy.accept-upload-content(request: $7),
                  _ =>
                    match @definy.handle-rpc(method: @core.string-concat(left: "EventService/", right: $3), request: $0) {
                      #some(handler$8) =>
                        $8(request: $7),
                      #none(_) =>
                        @definy.rpc-error(
                          code: "unimplemented",
                          message: @core.string-concat(
                            left: "Endpoint ",
                            right: @core.string-concat(left: @http.path(request: $0), right: " is not implemented")
                          )
                        )
                    }
                }
            }
          )
      )
  }
visibility
public
definy.handle-event-service (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: RUq9kVozRvqKyKXKBjQvhpjdf0HYX_FLfuown_eT_Bg
content hash: SavjnEvBPLjy8EF0UPhOQRMMSA4FwK0kBuw9p-8AHSw