Connector kit helpers

Look up how the connector kit keeps a vendor's tags in step, remakes restored rows, holds a large batch, paces requests and makes thumbnails.

The connector kit gives a connector these helpers beyond reading and writing rows. The options a kind takes to use them are in Connector kit kind options. Connectors are in alpha: what alpha means.

Tags and favorites

A kind that declares tags or favorite hands the kit a vendor's tags as Marfa tags, and its favorite as the favorite tag. An owner chooses where they land.

The kit keeps tags in step tag by tag. It keeps the tags both sides last agreed on. A tag added on either side is kept. A tag removed on one side is removed from the other only where the other holds it as agreed, so a tag one side never held is never removed from it. The favorite follows the same rule.

A change of the tag or favorite choice never removes a tag. The first agreement after it is a union.

A create carries the row's tags and favorite, as change.tags.added and change.favorite, for a kind that carries them back. A create that can't set them must answer the vendor's entry, so the kit sends them after it.

A vendor tag named favorite or conflicted-copy, one Marfa refuses (blank, ., .. or over 128 characters), and any past an item's 100 tags stay at the vendor, and a condition names each. Where the kind's fields list original_values, those tags are kept there too. A tag changed in Marfa reaches the vendor as tags added and removed, never as a replacement list. A kind that is not carried back reads tags only: a tag removed in Marfa comes back.

Restored rows

remake is handed a restored row's tags and favorite, to set on a row made again at the vendor. A row that another row's trash took with it is offered too, after each row above it.

Holds on large batches

A hold keeps a mistake from becoming a large loss. A batch is held when it is more than 20 and more than a quarter of the whole it comes from. For deletes, holdDeletes takes a limit other than 20.

  • Deletes. A connector's preflight hands the batch to context.holdDeletes. A held batch fails the run before the vendor is read, so nothing is carried.
  • Archives. A kind with holdArchives counts its archives against its active rows in Marfa. A held batch archives none of that kind, and the run writes everything else. The kit keeps what it gathered, so a vendor that reports a deletion only once loses none.
  • The value. The condition deletes-held or archives-held gives a value, <count>:<hash>, that names the whole batch. The owner sets it in the connector's setting <name>_confirm_deletes or <name>_confirm_archives, such as raindrop_confirm_deletes, which the connector declares.
  • It covers each delete's operation. A value given for a batch of binned rows never releases purges of the same rows, and one for one operation releases no other.
  • A value is spent. It releases that batch once and no later or larger one. A spent value left set does nothing.
  • Until then the hold stands. For deletes, the owner restores the binned rows in Marfa or confirms the value. An archive hold also ends once the vendor sends the rows again.

Pacing requests

Pacer, from @withmarfa/connector/pacer, paces a connector's requests to one vendor account.

  • The budget. perMinute is the most requests it starts in any 60 seconds. A request over the budget waits.
  • The vendor's count. From the x-ratelimit-limit, -remaining and -reset headers, it spreads out what is left once a fifth of the limit remains (5 requests where no limit is sent), over the time to the reset or one minute if that is sooner. At none, it pauses.
  • A 429. It waits for Retry-After, else the reset, else 60 seconds, between 1 second and an hour, then sends the request again. Every request meanwhile waits too.
  • A pause is durable. It is waited out through the run's waitUntil, so a restart does not forget it. Without waitUntil, run throws Unreachable with the deadline instead.

Thumbnails

makeThumbnail, from @withmarfa/connector/thumbnails, makes the small picture a thumbnail field takes. thumbnailFromAddress fetches the picture and makes it in one step.

  • In and out. It reads JPEG, PNG, GIF and WebP, but not an animated WebP. The long side is at most 256 pixels, and the result aims for 8 KiB and never passes 16 KiB.
  • Refused, with a reason: not a picture, SVG, one pixel wide or high, HEIC or AVIF, over 25 million pixels, a CMYK JPEG over 16 million, or damaged.
  • It carries its source address. A thumbnail from thumbnailFromAddress holds a key of the address it was made from, which thumbnailMadeFrom reads back. Pass the row's thumbnail as since, and nothing is fetched while the address is the same.
  • Writing it. An entry that leaves thumbnail out clears it, so send the held one (withHeldThumbnail). Write a new one with derive and a when naming the address, so a picture changed meanwhile never gets the old thumbnail.
  • Refusals kept. rowThumbnail keeps one for a row: until the address changes for a picture that can't be made, a week for a host's answer such as 404, and 30 minutes for a failure that may pass, such as a timeout. It keeps at most 1,024.
  • Every row gets a turn. thumbnailTurns walks the rows from a cursor the connector keeps, so each run carries on where the last stopped.

On this page