turso_sync_sdk_kit 0.4.3-pre.2

Turso sync SDK kit
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
/* automatically generated by rust-bindgen 0.71.1 */

use turso_sdk_kit::capi::c::*;

#[repr(u32)]
#[doc = " TURSO_DATABASE_SYNC_IO_REQUEST"]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum turso_sync_io_request_type_t {
    TURSO_SYNC_IO_NONE = 0,
    TURSO_SYNC_IO_HTTP = 1,
    TURSO_SYNC_IO_FULL_READ = 2,
    TURSO_SYNC_IO_FULL_WRITE = 3,
}
#[repr(C)]
pub struct turso_sync_io_http_request_t {
    pub url: turso_slice_ref_t,
    pub method: turso_slice_ref_t,
    pub path: turso_slice_ref_t,
    pub body: turso_slice_ref_t,
    pub headers: i32,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
    ["Size of turso_sync_io_http_request_t"]
        [::std::mem::size_of::<turso_sync_io_http_request_t>() - 72usize];
    ["Alignment of turso_sync_io_http_request_t"]
        [::std::mem::align_of::<turso_sync_io_http_request_t>() - 8usize];
    ["Offset of field: turso_sync_io_http_request_t::url"]
        [::std::mem::offset_of!(turso_sync_io_http_request_t, url) - 0usize];
    ["Offset of field: turso_sync_io_http_request_t::method"]
        [::std::mem::offset_of!(turso_sync_io_http_request_t, method) - 16usize];
    ["Offset of field: turso_sync_io_http_request_t::path"]
        [::std::mem::offset_of!(turso_sync_io_http_request_t, path) - 32usize];
    ["Offset of field: turso_sync_io_http_request_t::body"]
        [::std::mem::offset_of!(turso_sync_io_http_request_t, body) - 48usize];
    ["Offset of field: turso_sync_io_http_request_t::headers"]
        [::std::mem::offset_of!(turso_sync_io_http_request_t, headers) - 64usize];
};
impl Default for turso_sync_io_http_request_t {
    fn default() -> Self {
        let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
        unsafe {
            ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
            s.assume_init()
        }
    }
}
#[repr(C)]
pub struct turso_sync_io_http_header_t {
    pub key: turso_slice_ref_t,
    pub value: turso_slice_ref_t,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
    ["Size of turso_sync_io_http_header_t"]
        [::std::mem::size_of::<turso_sync_io_http_header_t>() - 32usize];
    ["Alignment of turso_sync_io_http_header_t"]
        [::std::mem::align_of::<turso_sync_io_http_header_t>() - 8usize];
    ["Offset of field: turso_sync_io_http_header_t::key"]
        [::std::mem::offset_of!(turso_sync_io_http_header_t, key) - 0usize];
    ["Offset of field: turso_sync_io_http_header_t::value"]
        [::std::mem::offset_of!(turso_sync_io_http_header_t, value) - 16usize];
};
impl Default for turso_sync_io_http_header_t {
    fn default() -> Self {
        let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
        unsafe {
            ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
            s.assume_init()
        }
    }
}
#[repr(C)]
pub struct turso_sync_io_full_read_request_t {
    pub path: turso_slice_ref_t,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
    ["Size of turso_sync_io_full_read_request_t"]
        [::std::mem::size_of::<turso_sync_io_full_read_request_t>() - 16usize];
    ["Alignment of turso_sync_io_full_read_request_t"]
        [::std::mem::align_of::<turso_sync_io_full_read_request_t>() - 8usize];
    ["Offset of field: turso_sync_io_full_read_request_t::path"]
        [::std::mem::offset_of!(turso_sync_io_full_read_request_t, path) - 0usize];
};
impl Default for turso_sync_io_full_read_request_t {
    fn default() -> Self {
        let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
        unsafe {
            ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
            s.assume_init()
        }
    }
}
#[repr(C)]
pub struct turso_sync_io_full_write_request_t {
    pub path: turso_slice_ref_t,
    pub content: turso_slice_ref_t,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
    ["Size of turso_sync_io_full_write_request_t"]
        [::std::mem::size_of::<turso_sync_io_full_write_request_t>() - 32usize];
    ["Alignment of turso_sync_io_full_write_request_t"]
        [::std::mem::align_of::<turso_sync_io_full_write_request_t>() - 8usize];
    ["Offset of field: turso_sync_io_full_write_request_t::path"]
        [::std::mem::offset_of!(turso_sync_io_full_write_request_t, path) - 0usize];
    ["Offset of field: turso_sync_io_full_write_request_t::content"]
        [::std::mem::offset_of!(turso_sync_io_full_write_request_t, content) - 16usize];
};
impl Default for turso_sync_io_full_write_request_t {
    fn default() -> Self {
        let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
        unsafe {
            ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
            s.assume_init()
        }
    }
}
#[repr(u32)]
#[doc = " TURSO_ASYNC_OPERATION_RESULT"]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum turso_sync_operation_result_type_t {
    TURSO_ASYNC_RESULT_NONE = 0,
    TURSO_ASYNC_RESULT_CONNECTION = 1,
    TURSO_ASYNC_RESULT_CHANGES = 2,
    TURSO_ASYNC_RESULT_STATS = 3,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct turso_sync_changes {
    _unused: [u8; 0],
}
#[doc = " opaque pointer to the TursoDatabaseSyncChanges instance\n SAFETY: turso_sync_changes_t have independent lifetime and must be explicitly deallocated with turso_sync_changes_deinit method OR passed to the turso_sync_database_apply_changes method which gather ownership to this object"]
pub type turso_sync_changes_t = turso_sync_changes;
#[doc = " structure holding opaque pointer to the SyncEngineStats instance\n SAFETY: revision string will be valid only during async operation lifetime (until turso_sync_operation_deinit)\n Most likely, caller will need to copy revision slice to its internal buffer for longer lifetime"]
#[repr(C)]
pub struct turso_sync_stats_t {
    pub cdc_operations: i64,
    pub main_wal_size: i64,
    pub revert_wal_size: i64,
    pub last_pull_unix_time: i64,
    pub last_push_unix_time: i64,
    pub network_sent_bytes: i64,
    pub network_received_bytes: i64,
    pub revision: turso_slice_ref_t,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
    ["Size of turso_sync_stats_t"][::std::mem::size_of::<turso_sync_stats_t>() - 72usize];
    ["Alignment of turso_sync_stats_t"][::std::mem::align_of::<turso_sync_stats_t>() - 8usize];
    ["Offset of field: turso_sync_stats_t::cdc_operations"]
        [::std::mem::offset_of!(turso_sync_stats_t, cdc_operations) - 0usize];
    ["Offset of field: turso_sync_stats_t::main_wal_size"]
        [::std::mem::offset_of!(turso_sync_stats_t, main_wal_size) - 8usize];
    ["Offset of field: turso_sync_stats_t::revert_wal_size"]
        [::std::mem::offset_of!(turso_sync_stats_t, revert_wal_size) - 16usize];
    ["Offset of field: turso_sync_stats_t::last_pull_unix_time"]
        [::std::mem::offset_of!(turso_sync_stats_t, last_pull_unix_time) - 24usize];
    ["Offset of field: turso_sync_stats_t::last_push_unix_time"]
        [::std::mem::offset_of!(turso_sync_stats_t, last_push_unix_time) - 32usize];
    ["Offset of field: turso_sync_stats_t::network_sent_bytes"]
        [::std::mem::offset_of!(turso_sync_stats_t, network_sent_bytes) - 40usize];
    ["Offset of field: turso_sync_stats_t::network_received_bytes"]
        [::std::mem::offset_of!(turso_sync_stats_t, network_received_bytes) - 48usize];
    ["Offset of field: turso_sync_stats_t::revision"]
        [::std::mem::offset_of!(turso_sync_stats_t, revision) - 56usize];
};
impl Default for turso_sync_stats_t {
    fn default() -> Self {
        let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
        unsafe {
            ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
            s.assume_init()
        }
    }
}
#[doc = " Database sync description."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct turso_sync_database_config_t {
    pub path: *const ::std::os::raw::c_char,
    pub remote_url: *const ::std::os::raw::c_char,
    pub client_name: *const ::std::os::raw::c_char,
    pub long_poll_timeout_ms: i32,
    pub bootstrap_if_empty: bool,
    pub reserved_bytes: i32,
    pub partial_bootstrap_strategy_prefix: i32,
    pub partial_bootstrap_strategy_query: *const ::std::os::raw::c_char,
    pub partial_bootstrap_segment_size: usize,
    pub partial_bootstrap_prefetch: bool,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
    ["Size of turso_sync_database_config_t"]
        [::std::mem::size_of::<turso_sync_database_config_t>() - 64usize];
    ["Alignment of turso_sync_database_config_t"]
        [::std::mem::align_of::<turso_sync_database_config_t>() - 8usize];
    ["Offset of field: turso_sync_database_config_t::path"]
        [::std::mem::offset_of!(turso_sync_database_config_t, path) - 0usize];
    ["Offset of field: turso_sync_database_config_t::remote_url"]
        [::std::mem::offset_of!(turso_sync_database_config_t, remote_url) - 8usize];
    ["Offset of field: turso_sync_database_config_t::client_name"]
        [::std::mem::offset_of!(turso_sync_database_config_t, client_name) - 16usize];
    ["Offset of field: turso_sync_database_config_t::long_poll_timeout_ms"]
        [::std::mem::offset_of!(turso_sync_database_config_t, long_poll_timeout_ms) - 24usize];
    ["Offset of field: turso_sync_database_config_t::bootstrap_if_empty"]
        [::std::mem::offset_of!(turso_sync_database_config_t, bootstrap_if_empty) - 28usize];
    ["Offset of field: turso_sync_database_config_t::reserved_bytes"]
        [::std::mem::offset_of!(turso_sync_database_config_t, reserved_bytes) - 32usize];
    ["Offset of field: turso_sync_database_config_t::partial_bootstrap_strategy_prefix"][::std::mem::offset_of!(
        turso_sync_database_config_t,
        partial_bootstrap_strategy_prefix
    )
        - 36usize];
    ["Offset of field: turso_sync_database_config_t::partial_bootstrap_strategy_query"][::std::mem::offset_of!(
        turso_sync_database_config_t,
        partial_bootstrap_strategy_query
    )
        - 40usize];
    ["Offset of field: turso_sync_database_config_t::partial_bootstrap_segment_size"][::std::mem::offset_of!(
        turso_sync_database_config_t,
        partial_bootstrap_segment_size
    ) - 48usize];
    ["Offset of field: turso_sync_database_config_t::partial_bootstrap_prefetch"][::std::mem::offset_of!(
        turso_sync_database_config_t,
        partial_bootstrap_prefetch
    ) - 56usize];
};
impl Default for turso_sync_database_config_t {
    fn default() -> Self {
        let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
        unsafe {
            ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
            s.assume_init()
        }
    }
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct turso_sync_database {
    _unused: [u8; 0],
}
#[doc = " opaque pointer to the TursoDatabaseSync instance"]
pub type turso_sync_database_t = turso_sync_database;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct turso_sync_operation {
    _unused: [u8; 0],
}
#[doc = " opaque pointer to the TursoAsyncOperation instance\n SAFETY: methods for the turso_sync_operation_t can't be called concurrently"]
pub type turso_sync_operation_t = turso_sync_operation;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct turso_sync_io_item {
    _unused: [u8; 0],
}
#[doc = " opaque pointer to the SyncEngineIoQueueItem instance"]
pub type turso_sync_io_item_t = turso_sync_io_item;
unsafe extern "C" {
    #[doc = " Create database sync holder but do not open it"]
    pub fn turso_sync_database_new(
        db_config: *const turso_database_config_t,
        sync_config: *const turso_sync_database_config_t,
        database: *mut *const turso_sync_database_t,
        error_opt_out: *mut *const ::std::os::raw::c_char,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Open prepared synced database, fail if no properly setup database exists\n AsyncOperation returns None"]
    pub fn turso_sync_database_open(
        self_: *const turso_sync_database_t,
        operation: *mut *const turso_sync_operation_t,
        error_opt_out: *mut *const ::std::os::raw::c_char,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Open or prepared synced database or create it if no properly setup database exists\n AsyncOperation returns None"]
    pub fn turso_sync_database_create(
        self_: *const turso_sync_database_t,
        operation: *mut *const turso_sync_operation_t,
        error_opt_out: *mut *const ::std::os::raw::c_char,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Create turso database connection\n SAFETY: synced database must be opened before that operation (with either turso_database_sync_create or turso_database_sync_open)\n AsyncOperation returns Connection"]
    pub fn turso_sync_database_connect(
        self_: *const turso_sync_database_t,
        operation: *mut *const turso_sync_operation_t,
        error_opt_out: *mut *const ::std::os::raw::c_char,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Collect stats about synced database\n AsyncOperation returns Stats"]
    pub fn turso_sync_database_stats(
        self_: *const turso_sync_database_t,
        operation: *mut *const turso_sync_operation_t,
        error_opt_out: *mut *const ::std::os::raw::c_char,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Checkpoint WAL of the synced database\n AsyncOperation returns None"]
    pub fn turso_sync_database_checkpoint(
        self_: *const turso_sync_database_t,
        operation: *mut *const turso_sync_operation_t,
        error_opt_out: *mut *const ::std::os::raw::c_char,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Push local changes to remote\n AsyncOperation returns None"]
    pub fn turso_sync_database_push_changes(
        self_: *const turso_sync_database_t,
        operation: *mut *const turso_sync_operation_t,
        error_opt_out: *mut *const ::std::os::raw::c_char,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Wait for remote changes\n AsyncOperation returns Changes (which must be properly deinited or used in the [turso_sync_database_apply_changes] method)"]
    pub fn turso_sync_database_wait_changes(
        self_: *const turso_sync_database_t,
        operation: *mut *const turso_sync_operation_t,
        error_opt_out: *mut *const ::std::os::raw::c_char,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Apply remote changes locally\n SAFETY: caller must guarantee that no other methods are executing concurrently (push/wait/checkpoint)\n otherwise, operation will return MISUSE error\n\n the method CONSUMES turso_sync_changes_t instance and caller no longer owns it after the call\n So, the changes MUST NOT be explicitly deallocated after the method call (either successful or not)\n\n AsyncOperation returns None"]
    pub fn turso_sync_database_apply_changes(
        self_: *const turso_sync_database_t,
        changes: *const turso_sync_changes_t,
        operation: *mut *const turso_sync_operation_t,
        error_opt_out: *mut *const ::std::os::raw::c_char,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Resume async operation\n If return TURSO_IO - caller must drive IO\n If return TURSO_DONE - caller must inspect result and clean up it or use it accordingly\n It's safe to call turso_sync_operation_resume multiple times even after operation completion (in case of repeat calls after completion - final result always will be returned)"]
    pub fn turso_sync_operation_resume(
        self_: *const turso_sync_operation_t,
        error_opt_out: *mut *const ::std::os::raw::c_char,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Extract operation result kind"]
    pub fn turso_sync_operation_result_kind(
        self_: *const turso_sync_operation_t,
    ) -> turso_sync_operation_result_type_t;
}
unsafe extern "C" {
    #[doc = " Extract Connection result from finished async operation"]
    pub fn turso_sync_operation_result_extract_connection(
        self_: *const turso_sync_operation_t,
        connection: *mut *const turso_connection_t,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Extract Changes result from finished async operation\n If no changes were fetched - return TURSO_OK and set changes to null pointer"]
    pub fn turso_sync_operation_result_extract_changes(
        self_: *const turso_sync_operation_t,
        changes: *mut *const turso_sync_changes_t,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Extract Stats result from finished async operation"]
    pub fn turso_sync_operation_result_extract_stats(
        self_: *const turso_sync_operation_t,
        stats: *mut turso_sync_stats_t,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Try to take IO request from the sync engine IO queue"]
    pub fn turso_sync_database_io_take_item(
        self_: *const turso_sync_database_t,
        item: *mut *const turso_sync_io_item_t,
        error_opt_out: *mut *const ::std::os::raw::c_char,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Run extra database callbacks after IO execution"]
    pub fn turso_sync_database_io_step_callbacks(
        self_: *const turso_sync_database_t,
        error_opt_out: *mut *const ::std::os::raw::c_char,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Get request IO kind"]
    pub fn turso_sync_database_io_request_kind(
        self_: *const turso_sync_io_item_t,
    ) -> turso_sync_io_request_type_t;
}
unsafe extern "C" {
    #[doc = " Get HTTP request header key-value pair"]
    pub fn turso_sync_database_io_request_http(
        self_: *const turso_sync_io_item_t,
        request: *mut turso_sync_io_http_request_t,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Get HTTP request fields"]
    pub fn turso_sync_database_io_request_http_header(
        self_: *const turso_sync_io_item_t,
        index: usize,
        header: *mut turso_sync_io_http_header_t,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Get HTTP request fields"]
    pub fn turso_sync_database_io_request_full_read(
        self_: *const turso_sync_io_item_t,
        request: *mut turso_sync_io_full_read_request_t,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Get HTTP request fields"]
    pub fn turso_sync_database_io_request_full_write(
        self_: *const turso_sync_io_item_t,
        request: *mut turso_sync_io_full_write_request_t,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Poison IO request completion with error"]
    pub fn turso_sync_database_io_poison(
        self_: *const turso_sync_io_item_t,
        error: *mut turso_slice_ref_t,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Set IO request completion status"]
    pub fn turso_sync_database_io_status(
        self_: *const turso_sync_io_item_t,
        status: i32,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Push bytes to the IO completion buffer"]
    pub fn turso_sync_database_io_push_buffer(
        self_: *const turso_sync_io_item_t,
        buffer: *mut turso_slice_ref_t,
    ) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Set IO request completion as done"]
    pub fn turso_sync_database_io_done(self_: *const turso_sync_io_item_t) -> turso_status_code_t;
}
unsafe extern "C" {
    #[doc = " Deallocate a TursoDatabaseSync"]
    pub fn turso_sync_database_deinit(self_: *const turso_sync_database_t);
}
unsafe extern "C" {
    #[doc = " Deallocate a TursoAsyncOperation"]
    pub fn turso_sync_operation_deinit(self_: *const turso_sync_operation_t);
}
unsafe extern "C" {
    #[doc = " Deallocate a SyncEngineIoQueueItem"]
    pub fn turso_sync_database_io_item_deinit(self_: *const turso_sync_io_item_t);
}
unsafe extern "C" {
    #[doc = " Deallocate a TursoDatabaseSyncChanges"]
    pub fn turso_sync_changes_deinit(self_: *const turso_sync_changes_t);
}