aboutsummaryrefslogtreecommitdiff
path: root/clients/drafts.h
diff options
context:
space:
mode:
Diffstat (limited to 'clients/drafts.h')
-rw-r--r--clients/drafts.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/clients/drafts.h b/clients/drafts.h
new file mode 100644
index 0000000..2cc67db
--- /dev/null
+++ b/clients/drafts.h
@@ -0,0 +1,49 @@
+#ifndef BOKF_DRAFTS_H
+#define BOKF_DRAFTS_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+/* 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-<time>-<seq>", unique within the process. Caller frees. */
+char *drafts_new_id(void);
+
+#endif