hakodb 0.8.21

Embedded & Cloud-native Document Engine
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
/* Auto-generated by cbindgen. Do not edit manually. */

#ifndef HAKO_H
#define HAKO_H

#pragma once

#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#define INSERT 1

#define DELETE 2

typedef struct HK_Array HK_Array;

typedef struct HK_Batch HK_Batch;

typedef struct HK_CloudSync HK_CloudSync;

typedef struct HK_Config HK_Config;

typedef struct HK_Doc HK_Doc;

typedef struct HK_Engine HK_Engine;

typedef struct HK_NetSyncer HK_NetSyncer;

typedef struct HK_Query HK_Query;

/**
 * Raw (undecoded) document handle. `bytes` pins the storage-encoded
 * buffer (zero copies for inlined docs); decode on demand with
 * `hk_rawdoc_to_doc`. Bytes are opaque storage encoding — do not persist
 * or compare across versions.
 */
typedef struct HK_RawDoc HK_RawDoc;

/**
 * Slab of raw docs. Borrowed-handle contract mirrors HK_ResultSet:
 * `hk_rawresult_get` pointers die with `hk_rawresult_free`.
 */
typedef struct HK_RawResultSet HK_RawResultSet;

typedef struct HK_ResultSet HK_ResultSet;

typedef struct HK_Transaction HK_Transaction;

typedef struct HK_ViewDoc HK_ViewDoc;

typedef struct HK_Watch HK_Watch;

typedef void (*HK_OnSnapshotCallback)(const char *collection,
                                      const char *path,
                                      int32_t kind,
                                      void *user_data);

typedef bool (*HkWalkCallback)(const char *id,
                               uintptr_t id_len,
                               const uint8_t *bytes,
                               uintptr_t bytes_len,
                               void *userdata);

/**
 * View-walk callback: borrowed id + a borrowed view handle (valid for the
 * call only — do not free, do not retain). Return true to continue.
 */
typedef bool (*HkViewWalkCallback)(const char *id,
                                   uintptr_t id_len,
                                   const struct HK_ViewDoc *view,
                                   void *userdata);

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

struct HK_Engine *hk_engine_open(const char *path);

bool hk_engine_is_indexes_ready(struct HK_Engine *engine);

/**
 * Block until background work settles (index recovery + async index
 * updates + blob persistence + maintenance) or `timeout_ms` lapses.
 * Requires two consecutive clear samples, so use it before measuring.
 * Returns true when settled. See `Hako::await_quiescent`.
 */
bool hk_engine_await_quiescent(struct HK_Engine *engine, uint64_t timeout_ms);

/**
 * Point-sample diagnostic as JSON (free with hk_string_free):
 * {"indexes_ready":b,"pending_index_ops":n,"index_backfills":n,
 *  "pending_blob_bytes":n,"queued_blob_items":n,
 *  "maintenance_running":b,"quiescent":b}.
 * Tells you WHAT is outstanding instead of guessing.
 */
char *hk_engine_quiescence_status(struct HK_Engine *engine);

struct HK_Config *hk_config_new(void);

void hk_config_free(struct HK_Config *config);

void hk_config_set_durability(struct HK_Config *config, int32_t mode);

void hk_config_set_encryption_key(struct HK_Config *config, const char *key);

/**
 * Set which collections should be encrypted.
 * collections_json: A JSON array of strings, e.g., '["secrets", "private_messages"]'
 */
int32_t hk_config_set_encrypted_collections(struct HK_Config *config, const char *collections_json);

void hk_config_set_audit_log(struct HK_Config *config, bool enabled, const char *path);

void hk_config_set_query_workers(struct HK_Config *config, uintptr_t count);

void hk_config_set_memory_limits(struct HK_Config *config,
                                 uintptr_t mmap_size,
                                 uintptr_t max_inlined_bytes);

void hk_config_set_storage_tuning(struct HK_Config *config,
                                  uintptr_t page_size,
                                  uintptr_t compaction_threshold,
                                  uintptr_t group_commit_max_ops);

void hk_config_set_blob_threshold(struct HK_Config *config, uintptr_t threshold_bytes);

/**
 * WAL headroom reservation in bytes (0 = off, default 4MB). Preallocated
 * ahead of the write position so steady-state appends never extend the
 * file. Sparse: consumes no disk until written. Ignored for Manual.
 */
void hk_config_set_wal_reserve_bytes(struct HK_Config *config, uint64_t bytes);

/**
 * Write-path phase breakdown (see engine::write_stats_report). Returns a
 * fresh C string the caller frees with hk_string_free. Counters reset.
 */
char *hk_debug_write_stats(void);

/**
 * Opens the engine using a custom config.
 * Note: This function takes ownership of the config and will free it automatically.
 */
struct HK_Engine *hk_engine_open_with_config(const char *path, struct HK_Config *config);

struct HK_Watch *hk_engine_watch(struct HK_Engine *engine,
                                 const char *collection,
                                 HK_OnSnapshotCallback callback,
                                 void *user_data_ptr);

void hk_watch_free(struct HK_Watch *watch);

void hk_engine_free(struct HK_Engine *engine);

struct HK_Doc *hk_doc_new(void);

void hk_doc_free(struct HK_Doc *doc);

int32_t hk_doc_insert_str(struct HK_Doc *doc, const char *key, const char *value);

int32_t hk_doc_insert_int(struct HK_Doc *doc, const char *key, int64_t value);

int32_t hk_doc_insert_float(struct HK_Doc *doc, const char *key, double value);

int32_t hk_doc_insert_bool(struct HK_Doc *doc, const char *key, bool value);

int32_t hk_doc_insert_null(struct HK_Doc *doc, const char *key);

int32_t hk_doc_insert_bin(struct HK_Doc *doc, const char *key, const uint8_t *data, uintptr_t len);

int32_t hk_engine_insert(struct HK_Engine *engine,
                         const char *collection,
                         const char *doc_id,
                         const struct HK_Doc *doc);

/**
 * Owned-doc insert: takes over the HK_Doc handle (no deep clone).
 * The handle is ALWAYS consumed — success or failure — do not use or free
 * `doc` after the call.
 */
int32_t hk_engine_insert_take(struct HK_Engine *engine,
                              const char *collection,
                              const char *doc_id,
                              struct HK_Doc *doc);

struct HK_Doc *hk_engine_get(struct HK_Engine *engine, const char *collection, const char *doc_id);

int32_t hk_engine_delete(struct HK_Engine *engine, const char *collection, const char *doc_id);

/**
 * Local-only delete: marks the key so no sync tailer or handshake
 * catch-up ever transmits it, then deletes normally (fresh tombstone
 * timestamp keeps the version clock advanced — handshake-stable).
 */
int32_t hk_engine_delete_local(struct HK_Engine *engine,
                               const char *collection,
                               const char *doc_id);

/**
 * Marks a collection local-only (`local != 0`) or rejoins it to sync.
 * A local-only collection never emits nor is caught up from the network.
 */
int32_t hk_engine_set_collection_local(struct HK_Engine *engine,
                                       const char *collection,
                                       int32_t local);

/**
 * Opts a key back into replication (future ops only).
 */
int32_t hk_engine_replicate_key(struct HK_Engine *engine,
                                const char *collection,
                                const char *doc_id);

/**
 * Opts a whole collection back into replication (clears flag + key marks).
 */
int32_t hk_engine_replicate_collection(struct HK_Engine *engine, const char *collection);

/**
 * Vacuum: purge a collection's tombstones. Emits no WAL op (never
 * replicates); drops the version so the next handshake pulls peer state.
 * Returns tombstones purged, or -1 on error.
 */
int32_t hk_engine_vacuum_collection(struct HK_Engine *engine, const char *collection);

struct HK_Batch *hk_batch_new(void);

void hk_batch_free(struct HK_Batch *batch);

int32_t hk_batch_set(struct HK_Batch *batch,
                     const char *collection,
                     const char *doc_id,
                     struct HK_Doc *doc);

int32_t hk_batch_delete(struct HK_Batch *batch, const char *collection, const char *doc_id);

int32_t hk_batch_commit(struct HK_Engine *engine, struct HK_Batch *batch);

struct HK_Query *hk_query_new(const char *collection);

void hk_query_free(struct HK_Query *query);

int32_t hk_query_where_eq_str(struct HK_Query *query, const char *field, const char *value);

int32_t hk_query_where_eq_bool(struct HK_Query *query, const char *field, bool value);

/**
 * Executes the query and deletes all matching documents.
 * Returns the number of deleted documents, or -1 on error.
 */
int32_t hk_query_delete(struct HK_Engine *engine, struct HK_Query *query);

/**
 * Local-only mass delete: marks every match so the wipe never leaves
 * this device, then deletes. See `hk_engine_delete_local`.
 */
int32_t hk_query_delete_local(struct HK_Engine *engine, struct HK_Query *query);

/**
 * Executes the query and applies the updates from 'patch_doc' to all matches.
 * Returns the number of updated documents, or -1 on error.
 */
int32_t hk_query_patch(struct HK_Engine *engine,
                       struct HK_Query *query,
                       const struct HK_Doc *patch_doc);

int32_t hk_query_where_eq_int(struct HK_Query *query, const char *field, int64_t value);

int32_t hk_query_where_ne_str(struct HK_Query *query, const char *field, const char *value);

int32_t hk_query_where_ne_int(struct HK_Query *query, const char *field, int64_t value);

int32_t hk_query_where_gt_str(struct HK_Query *query, const char *field, const char *value);

int32_t hk_query_where_gt_int(struct HK_Query *query, const char *field, int64_t value);

int32_t hk_query_where_gte_str(struct HK_Query *query, const char *field, const char *value);

int32_t hk_query_where_gte_int(struct HK_Query *query, const char *field, int64_t value);

int32_t hk_query_where_lt_str(struct HK_Query *query, const char *field, const char *value);

int32_t hk_query_where_lt_int(struct HK_Query *query, const char *field, int64_t value);

int32_t hk_query_where_lte_str(struct HK_Query *query, const char *field, const char *value);

int32_t hk_query_where_lte_int(struct HK_Query *query, const char *field, int64_t value);

int32_t hk_query_where_array_contains(struct HK_Query *query, const char *field, const char *value);

int32_t hk_query_where_array_contains_any(struct HK_Query *query,
                                          const char *field,
                                          struct HK_Array *array);

int32_t hk_query_where_not_in(struct HK_Query *query, const char *field, struct HK_Array *array);

int32_t hk_query_order_by(struct HK_Query *query, const char *field, bool ascending);

int32_t hk_query_limit(struct HK_Query *query, uintptr_t limit);

/**
 * Opt in to deferred blobs: matching docs come back with blob-backed
 * fields as `Value::BlobLink` placeholders (no blob-file reads).
 * Resolve later with `hk_doc_resolve_blobs`. Default off (eager).
 */
int32_t hk_query_defer_blobs(struct HK_Query *query, int defer);

/**
 * Resolve deferred blob fields of a query-returned doc in place.
 * No-op for docs without BlobLinks. Needs the owning collection (blob
 * addresses are per-shard).
 */
int32_t hk_doc_resolve_blobs(struct HK_Engine *engine, const char *collection, struct HK_Doc *doc);

int32_t hk_query_offset(struct HK_Query *query, uintptr_t offset);

int32_t hk_query_select_field(struct HK_Query *query, const char *field);

char *hk_query_execute(struct HK_Engine *engine, const struct HK_Query *query);

struct HK_ResultSet *hk_query_execute_to_handles(struct HK_Engine *engine,
                                                 const struct HK_Query *query);

uintptr_t hk_result_set_count(struct HK_ResultSet *results);

struct HK_Doc *hk_result_set_get_doc(struct HK_ResultSet *results, uintptr_t index);

void hk_result_set_free(struct HK_ResultSet *results);

struct HK_RawResultSet *hk_query_execute_raw(struct HK_Engine *engine,
                                             const struct HK_Query *query);

uintptr_t hk_rawresult_count(struct HK_RawResultSet *results);

struct HK_RawDoc *hk_rawresult_get(struct HK_RawResultSet *results, uintptr_t index);

void hk_rawresult_free(struct HK_RawResultSet *results);

/**
 * Borrowed byte view of a raw doc. Returns null on null handle; `*len_out`
 * (when non-null) receives the length. Valid until hk_rawresult_free —
 * zero copies for inlined docs.
 */
const uint8_t *hk_rawdoc_bytes(const struct HK_RawDoc *doc, uintptr_t *len_out);

/**
 * Borrowed id view of a raw doc (for keyset paging without decoding).
 * Rust Strings are NOT NUL-terminated, so the length goes through
 * `*len_out` (when non-null) — read `(ptr, len)`, do NOT treat as CStr.
 * Valid until hk_rawresult_free.
 */
const char *hk_rawdoc_id(const struct HK_RawDoc *doc, uintptr_t *len_out);

/**
 * Keyset anchor from a raw row. `id`-ordered queries bind the id with no
 * decode; other order fields decode the row ONCE per page (not per row).
 */
int32_t hk_query_start_after_raw(struct HK_Query *query, const struct HK_RawDoc *anchor_doc);

/**
 * The pointer resolver: decode a raw row into an owned HK_Doc (blob
 * fields inflated via the engine, same as a decoded query row).
 */
struct HK_Doc *hk_rawdoc_to_doc(struct HK_Engine *engine,
                                const struct HK_RawDoc *raw_doc,
                                const char *collection);

int64_t hk_cursor_walk(struct HK_Engine *engine,
                       const struct HK_Query *query,
                       HkWalkCallback callback,
                       void *userdata);

struct HK_ViewDoc *hk_view_get(struct HK_Engine *engine,
                               const char *collection,
                               const char *doc_id);

void hk_view_free(struct HK_ViewDoc *view);

uintptr_t hk_view_field_count(const struct HK_ViewDoc *view);

bool hk_view_has_field(const struct HK_ViewDoc *view, const char *key);

bool hk_view_get_int(const struct HK_ViewDoc *view, const char *key, int64_t *out);

bool hk_view_get_float(const struct HK_ViewDoc *view, const char *key, double *out);

int32_t hk_view_get_bool(const struct HK_ViewDoc *view, const char *key);

/**
 * Borrowed UTF-8 view of a String field. Returns null when missing or not
 * a String; `*len_out` (when non-null) receives the byte length. Valid
 * until hk_view_free — same borrowed contract as hk_rawdoc_bytes.
 */
const char *hk_view_get_str(const struct HK_ViewDoc *view, const char *key, uintptr_t *len_out);

/**
 * Borrowed view of a Binary field. Same lifetime contract as above.
 */
const uint8_t *hk_view_get_bytes(const struct HK_ViewDoc *view,
                                 const char *key,
                                 uintptr_t *len_out);

/**
 * Escape hatch: full owned decode of the pinned bytes (links unresolved —
 * follow with hk_doc_resolve_blobs when needed).
 */
struct HK_Doc *hk_view_to_doc(const struct HK_ViewDoc *view, const char *doc_id);

/**
 * One-call lazy scan: lends each row as a view (no decode, no owned
 * construction). Returns rows visited, -1 on error. Same no-reentry
 * contract as hk_cursor_walk.
 */
int64_t hk_cursor_walk_view(struct HK_Engine *engine,
                            const struct HK_Query *query,
                            HkViewWalkCallback callback,
                            void *userdata);

/**
 * Bulk result-set to JSON: one call, one JSON array string, no per-doc
 * DOM and no per-doc FFI round trips. Byte-identical to joining
 * `hk_doc_to_json` per row. Caller frees with `hk_string_free`.
 */
char *hk_result_set_to_json(struct HK_ResultSet *results);

char *hk_doc_to_json(const struct HK_Doc *doc);

const char *hk_last_error(void);

/**
 * Enable library diagnostic logging to stderr. Default OFF. Idempotent.
 */
void hk_log_enable_stderr(void);

/**
 * Disable library diagnostic logging to stderr. Default OFF. Idempotent.
 */
void hk_log_disable_stderr(void);

void hk_string_free(char *value);

int32_t hk_query_aggregate_count(struct HK_Query *query);

int32_t hk_query_aggregate_sum(struct HK_Query *query, const char *field);

int32_t hk_query_aggregate_avg(struct HK_Query *query, const char *field);

char *hk_query_execute_aggregation(struct HK_Engine *engine, const struct HK_Query *query);

int32_t hk_doc_insert_timestamp(struct HK_Doc *doc, const char *key, int64_t micros);

int32_t hk_doc_insert_server_timestamp(struct HK_Doc *doc, const char *key);

int32_t hk_engine_backup(struct HK_Engine *engine, const char *path);

int32_t hk_query_where_match(struct HK_Query *query, const char *field, const char *value);

int32_t hk_query_where_match_prefix(struct HK_Query *query, const char *field, const char *value);

int32_t hk_query_where_contains(struct HK_Query *query, const char *field, const char *value);

int32_t hk_query_where_starts_with(struct HK_Query *query, const char *field, const char *value);

char *hk_engine_list_collections(struct HK_Engine *engine);

struct HK_Array *hk_array_new(void);

void hk_array_free(struct HK_Array *array);

int32_t hk_array_append_str(struct HK_Array *array, const char *value);

int32_t hk_array_append_int(struct HK_Array *array, int64_t value);

int32_t hk_array_append_doc(struct HK_Array *array, const struct HK_Doc *doc);

/**
 * Takes the contents of 'child' and inserts it as a Map into 'parent'
 */
int32_t hk_doc_insert_doc(struct HK_Doc *parent, const char *key, const struct HK_Doc *child);

/**
 * Takes the contents of 'array' and inserts it into the document
 */
int32_t hk_doc_insert_array(struct HK_Doc *doc, const char *key, struct HK_Array *array);

int32_t hk_engine_patch(struct HK_Engine *engine,
                        const char *collection,
                        const char *doc_id,
                        const struct HK_Doc *updates);

/**
 * Creates a composite index from C++.
 * fields_json should be like: [{"field": "age", "desc": false}]
 */
uint32_t hk_engine_create_index(struct HK_Engine *engine,
                                const char *collection,
                                const char *fields_json);

/**
 * Simplified indexer: Create an index for a single field.
 */
int32_t hk_engine_create_simple_index(struct HK_Engine *engine,
                                      const char *collection,
                                      const char *field);

int32_t hk_engine_create_fts_index(struct HK_Engine *engine,
                                   const char *collection,
                                   const char *field);

char *hk_engine_list_indexes(struct HK_Engine *engine, const char *collection);

struct HK_Transaction *hk_transaction_begin(struct HK_Engine *engine);

struct HK_Doc *hk_transaction_get(struct HK_Engine *engine,
                                  struct HK_Transaction *tx,
                                  const char *collection,
                                  const char *doc_id);

int32_t hk_transaction_set(struct HK_Transaction *tx,
                           const char *collection,
                           const char *doc_id,
                           const struct HK_Doc *doc);

int32_t hk_transaction_commit(struct HK_Engine *engine, struct HK_Transaction *tx);

void hk_transaction_free(struct HK_Transaction *tx);

int32_t hk_engine_insert_subdoc(struct HK_Engine *engine,
                                const char *col,
                                const char *id,
                                const char *sub_col,
                                const char *sub_id,
                                const struct HK_Doc *doc);

int32_t hk_engine_compact(struct HK_Engine *engine);

char *hk_engine_get_stats(struct HK_Engine *engine);

int32_t hk_doc_insert_reference(struct HK_Doc *doc,
                                const char *key,
                                const char *target_collection,
                                const char *target_id);

/**
 * Given a document and a field name containing a Reference, fetch the target document.
 * Returns a new HK_Doc handle, or null if the field is not a reference or target not found.
 */
struct HK_Doc *hk_engine_get_by_ref(struct HK_Engine *engine,
                                    const struct HK_Doc *doc,
                                    const char *field_key);

int32_t hk_query_start_after(struct HK_Query *query, const struct HK_Doc *anchor_doc);

int32_t hk_query_start_at(struct HK_Query *query, const struct HK_Doc *anchor_doc);

int32_t hk_query_end_at(struct HK_Query *query, const struct HK_Doc *anchor_doc);

int32_t hk_query_end_before(struct HK_Query *query, const struct HK_Doc *anchor_doc);

char *hk_engine_get_audit_log(struct HK_Engine *engine);

int32_t hk_query_where_or_str(struct HK_Query *query, const char *field, const char *value);

int32_t hk_query_where_or_int(struct HK_Query *query, const char *field, int64_t value);

/**
 * Adds an IN filter: field IN [array_items]
 * This takes ownership of the HK_Array and frees it.
 */
int32_t hk_query_where_in(struct HK_Query *query, const char *field, struct HK_Array *array);

int32_t hk_engine_snapshot_indices(struct HK_Engine *engine);

void hk_config_set_compression(struct HK_Config *config, bool enabled, int32_t level);

/**
 * Hold background maintenance (checkpoint/compaction/purge/snapshots) for
 * deterministic benchmarks or hard latency bounds. Engine stays correct;
 * files grow until re-enabled. Default on.
 */
void hk_config_set_background_maintenance(struct HK_Config *config, bool enabled);

struct HK_NetSyncer *hk_net_syncer_new(struct HK_Engine *engine,
                                       const char *name,
                                       const char *room_key);

/**
 * Select discovery transports: 0 = mDNS (desktop default), 1 = UDP
 * broadcast (mobile default, no multicast), 2 = both (mixed groups — a
 * desktop joining mobile peers must opt into both or broadcast).
 * Takes effect at the next start().
 */
int32_t hk_net_syncer_set_discovery(struct HK_NetSyncer *syncer, int32_t mode);

int32_t hk_net_syncer_start(struct HK_NetSyncer *syncer, uint16_t port);

char *hk_net_syncer_status(struct HK_NetSyncer *syncer);

void hk_net_syncer_free(struct HK_NetSyncer *syncer);

struct HK_CloudSync *hk_cloud_sync_new(struct HK_Engine *engine,
                                       int32_t mode,
                                       const char *client_id,
                                       const char *room_name,
                                       const char *room_key,
                                       const char *auth_token);

/**
 * Creates a room-agnostic cloud SERVER. Not bound to any room: the server
 * accepts and persists any (room_name, room_key) pair its clients ask for and
 * routes sync to the matching room group.
 */
struct HK_CloudSync *hk_cloud_sync_server_new(struct HK_Engine *engine,
                                              const char *server_id,
                                              const char *auth_token);

/**
 * Creates an offline-first cloud CLIENT bound to a room of the caller's
 * choosing. The client picks the room (room_name + room_key) and later picks
 * the server via `hk_cloud_sync_start`.
 */
struct HK_CloudSync *hk_cloud_sync_client_new(struct HK_Engine *engine,
                                              const char *client_id,
                                              const char *room_name,
                                              const char *room_key,
                                              const char *auth_token);

int32_t hk_cloud_sync_start(struct HK_CloudSync *cloud_sync, const char *address);

char *hk_cloud_sync_status(struct HK_CloudSync *cloud_sync);

void hk_cloud_sync_stop(struct HK_CloudSync *cloud_sync);

void hk_cloud_sync_free(struct HK_CloudSync *cloud_sync);

#ifdef __cplusplus
}  // extern "C"
#endif  // __cplusplus

#endif  /* HAKO_H */