Skip to contents

Validates and summarizes a plan for execution by zotExecute(). A row has action "patch", "create", "attach", or "trash"; a user or group library; an item key for patch and Trash rows; and a payload list.

Usage

zotPreview(plan, describe)

Arguments

plan

A data.table with columns action, library, itemKey, payload (list column).

describe

Text identifying the batch.

Value

A zotPreview: the plan, its canonical SHA-256 digest, counts by action and library (N rows and the bytes attach rows upload, 0 for other actions) and creation time.

Details

zotPreview() validates the plan, rejects unknown actions and recognized source labels, copies the rows, and calculates a digest from a canonical JSON representation. It does not contact Zotero.

Three rules protect the ledger and the write itself. A create row leaves itemKey as NA, because zotExecute() identifies a create by its position and a keyed create would make a resumed batch create the item again. An identified item appears once per library, because the ledger holds one entry per library and key and a repeated pair would drop the second row. A payload carries no key or version field: zotPatch() sends the version as a conditional header, and a payload version is read back changed, which reports a successful write as failed.

An attach row creates an attachment item and uploads a local file; it leaves itemKey as NA, like a create row. Its payload carries parentItem (NULL for a standalone attachment), the local path, the stored filename, contentType, an optional charset, the file's md5 (32 lowercase hexadecimal digits) and filesize (a whole number of bytes above zero); ztAttachPlan() builds such rows. Source labels are refused in filename only, because the local path is never stored in Zotero. The digest covers the whole payload, so an approval binds the exact bytes through their MD5.

Examples

Plan <- data.table::data.table(
  action = "patch", library = "user", itemKey = "ABCD1234",
  payload = list(list(title = "A reviewed title"))
)
Preview <- zotPreview(Plan, describe = "Correct one title")
Preview
#> <zotPreview> Correct one title 
#>   digest: 34f12497d5349ed6e1397c32f5bedfa29625bb9006ad73c5258cb4aa38f0a9b3 
#>    action library     N bytes
#>    <char>  <char> <int> <num>
#> 1:  patch    user     1     0