#ifndef BOKF_DRAFTS_H #define BOKF_DRAFTS_H #include #include /* Client-local edit drafts: every non-committed edit is mirrored to $XDG_CACHE_HOME/bokf/drafts.json (mode 0600, atomic replace) so a reload, a crash or Ctrl+C never loses work. A record is keyed by (org, entity, id); a new entity uses a temporary id from drafts_new_id(). See docs/TUI-GUIDELINES.md "Interaction model". */ struct draft { int64_t org; char *entity; char *id; char *fields; /* JSON object text */ }; struct drafts { struct draft *v; size_t n, cap; char path[600]; }; void drafts_init(struct drafts *d); /* Explicit path, for tests. */ void drafts_init_path(struct drafts *d, const char *path); void drafts_free(struct drafts *d); /* The draft's fields JSON, or NULL; the store owns the string. */ const char *drafts_get(const struct drafts *d, int64_t org, const char *entity, const char *id); int drafts_have(const struct drafts *d, int64_t org, const char *entity, const char *id); /* Inserts or replaces the draft and persists the file. */ void drafts_put(struct drafts *d, int64_t org, const char *entity, const char *id, const char *fields); void drafts_del(struct drafts *d, int64_t org, const char *entity, const char *id); size_t drafts_count(const struct drafts *d, int64_t org, const char *entity); void drafts_foreach(const struct drafts *d, int64_t org, const char *entity, void (*cb)(void *ud, const char *id, const char *fields), void *ud); /* "ny-