Explorer

definy.mirror-receive

description
Makes this store a mirror of remote, a little per run: creates the tables if missing, then stores the events of remote (the seed events too) that this store does not have, oldest first, with definy.mirror-events-loop (at most limit events, and at most content_limit contents). definy-html runs it from its Cron trigger (docs/html-ui.md)
type
Fn(remote: String, limit: Number, content_limit: Number) -> @definy.service-io
expression
fn(remote$0, limit$1, content_limit$2) =>
  @definy.ensure-seeded(
    then: fn(seeded$3) =>
      @definy.mirror-remote-events(
        remote: $0,
        offset: 0,
        acc: [],
        then: fn(result$4) =>
          match $4 {
            #error(message$5) =>
              @definy.mcp-text-error(text: $5),
            #ok(remote_events$6) =>
              @definy.mirror-local-hashes(
                offset: 0,
                acc: [],
                then: fn(hashes$7) =>
                  let missing$8 = @definy.mirror-missing(events: $6, known: $7);
                  @definy.mirror-events-loop(
                    remote: $0,
                    content_limit: $2,
                    events: $8,
                    index: 0,
                    limit: $1,
                    count: 0,
                    errors: [],
                    then: fn(summary$9) =>
                      @definy.sync-summary-result(
                        text: @definy.sync-summary-text(verb: "Mirrored", remote: $0, total: @core.list-length(value: $8), summary: $9),
                        summary: $9
                      )
                  )
              )
          }
      )
  )
visibility
public
definy.mirror-receive (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: edrAQA0lUlGOvO_gb-x1GS5_3DteU6NmCR41AqonBrc
content hash: HHk8YBgaXR5XLhXhDc6MzrTwWNHCGh_zN9bNlWkEa7g