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
preflighthands the batch tocontext.holdDeletes. A held batch fails the run before the vendor is read, so nothing is carried. - Archives. A kind with
holdArchivescounts 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-heldorarchives-heldgives a value,<count>:<hash>, that names the whole batch. The owner sets it in the connector's setting<name>_confirm_deletesor<name>_confirm_archives, such asraindrop_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.
perMinuteis the most requests it starts in any 60 seconds. A request over the budget waits. - The vendor's count. From the
x-ratelimit-limit,-remainingand-resetheaders, 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 forRetry-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. WithoutwaitUntil,runthrowsUnreachablewith 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
thumbnailFromAddressholds a key of the address it was made from, whichthumbnailMadeFromreads back. Pass the row's thumbnail assince, and nothing is fetched while the address is the same. - Writing it. An entry that leaves
thumbnailout clears it, so send the held one (withHeldThumbnail). Write a new one withderiveand awhennaming the address, so a picture changed meanwhile never gets the old thumbnail. - Refusals kept.
rowThumbnailkeeps one for a row: until the address changes for a picture that can't be made, a week for a host's answer such as404, and 30 minutes for a failure that may pass, such as a timeout. It keeps at most 1,024. - Every row gets a turn.
thumbnailTurnswalks the rows from a cursor the connector keeps, so each run carries on where the last stopped.