@sqliteai/sqlite-sync-expo-dev 0.9.93

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/LICENSE.md +41 -0
  2. package/README.md +86 -0
  3. package/android/jniLibs/arm64-v8a/cloudsync.so +0 -0
  4. package/android/jniLibs/armeabi-v7a/cloudsync.so +0 -0
  5. package/android/jniLibs/x86_64/cloudsync.so +0 -0
  6. package/app.plugin.js +165 -0
  7. package/ios/CloudSync.xcframework/Info.plist +59 -0
  8. package/ios/CloudSync.xcframework/_CodeSignature/CodeDirectory +0 -0
  9. package/ios/CloudSync.xcframework/_CodeSignature/CodeRequirements +0 -0
  10. package/ios/CloudSync.xcframework/_CodeSignature/CodeRequirements-1 +0 -0
  11. package/ios/CloudSync.xcframework/_CodeSignature/CodeResources +323 -0
  12. package/ios/CloudSync.xcframework/_CodeSignature/CodeSignature +0 -0
  13. package/ios/CloudSync.xcframework/ios-arm64/CloudSync.framework/CloudSync +0 -0
  14. package/ios/CloudSync.xcframework/ios-arm64/CloudSync.framework/Headers/CloudSync.h +135 -0
  15. package/ios/CloudSync.xcframework/ios-arm64/CloudSync.framework/Info.plist +1 -0
  16. package/ios/CloudSync.xcframework/ios-arm64/CloudSync.framework/Modules/module.modulemap +1 -0
  17. package/ios/CloudSync.xcframework/ios-arm64/CloudSync.framework/_CodeSignature/CodeResources +124 -0
  18. package/ios/CloudSync.xcframework/ios-arm64_x86_64-simulator/CloudSync.framework/CloudSync +0 -0
  19. package/ios/CloudSync.xcframework/ios-arm64_x86_64-simulator/CloudSync.framework/Headers/CloudSync.h +135 -0
  20. package/ios/CloudSync.xcframework/ios-arm64_x86_64-simulator/CloudSync.framework/Info.plist +1 -0
  21. package/ios/CloudSync.xcframework/ios-arm64_x86_64-simulator/CloudSync.framework/Modules/module.modulemap +1 -0
  22. package/ios/CloudSync.xcframework/ios-arm64_x86_64-simulator/CloudSync.framework/_CodeSignature/CodeResources +124 -0
  23. package/ios/CloudSync.xcframework/macos-arm64_x86_64/CloudSync.framework/CloudSync +0 -0
  24. package/ios/CloudSync.xcframework/macos-arm64_x86_64/CloudSync.framework/Headers/CloudSync.h +135 -0
  25. package/ios/CloudSync.xcframework/macos-arm64_x86_64/CloudSync.framework/Info.plist +1 -0
  26. package/ios/CloudSync.xcframework/macos-arm64_x86_64/CloudSync.framework/Modules/module.modulemap +1 -0
  27. package/ios/CloudSync.xcframework/macos-arm64_x86_64/CloudSync.framework/_CodeSignature/CodeResources +124 -0
  28. package/package.json +43 -0
  29. package/src/index.d.ts +12 -0
  30. package/src/index.js +25 -0
@@ -0,0 +1,135 @@
1
+ //
2
+ // cloudsync.h
3
+ // cloudsync
4
+ //
5
+ // Created by Marco Bambini on 16/05/24.
6
+ //
7
+
8
+ #ifndef __CLOUDSYNC__
9
+ #define __CLOUDSYNC__
10
+
11
+ #include <stdint.h>
12
+ #include <stddef.h>
13
+ #include <stdbool.h>
14
+ #include "database.h"
15
+
16
+ #ifdef __cplusplus
17
+ extern "C" {
18
+ #endif
19
+
20
+ #define CLOUDSYNC_VERSION "0.9.93"
21
+ #define CLOUDSYNC_MAX_TABLENAME_LEN 512
22
+
23
+ #define CLOUDSYNC_VALUE_NOTSET -1
24
+ #define CLOUDSYNC_TOMBSTONE_VALUE "__[RIP]__"
25
+ #define CLOUDSYNC_RLS_RESTRICTED_VALUE "__[RLS]__"
26
+ #define CLOUDSYNC_DISABLE_ROWIDONLY_TABLES 1
27
+ #define CLOUDSYNC_DEFAULT_ALGO "cls"
28
+
29
+ #define CLOUDSYNC_CHANGES_NCOLS 9
30
+
31
+ typedef enum {
32
+ CLOUDSYNC_PAYLOAD_APPLY_WILL_APPLY = 1,
33
+ CLOUDSYNC_PAYLOAD_APPLY_DID_APPLY = 2,
34
+ CLOUDSYNC_PAYLOAD_APPLY_CLEANUP = 3
35
+ } CLOUDSYNC_PAYLOAD_APPLY_STEPS;
36
+
37
+ // CRDT Algos
38
+ table_algo cloudsync_algo_from_name (const char *algo_name);
39
+ const char *cloudsync_algo_name (table_algo algo);
40
+
41
+ // Opaque structures
42
+ typedef struct cloudsync_payload_context cloudsync_payload_context;
43
+ typedef struct cloudsync_table_context cloudsync_table_context;
44
+
45
+ // CloudSync context
46
+ cloudsync_context *cloudsync_context_create (void *db);
47
+ const char *cloudsync_context_init (cloudsync_context *data);
48
+ void cloudsync_context_free (void *ctx);
49
+
50
+ // CloudSync global
51
+ int cloudsync_init_table (cloudsync_context *data, const char *table_name, const char *algo_name, bool skip_int_pk_check);
52
+ int cloudsync_cleanup (cloudsync_context *data, const char *table_name);
53
+ int cloudsync_cleanup_all (cloudsync_context *data);
54
+ int cloudsync_terminate (cloudsync_context *data);
55
+ int cloudsync_insync (cloudsync_context *data);
56
+ int cloudsync_bumpseq (cloudsync_context *data);
57
+ void *cloudsync_siteid (cloudsync_context *data);
58
+ void cloudsync_reset_siteid (cloudsync_context *data);
59
+ void cloudsync_sync_key (cloudsync_context *data, const char *key, const char *value);
60
+ int64_t cloudsync_dbversion_next (cloudsync_context *data, int64_t merging_version);
61
+ int64_t cloudsync_dbversion (cloudsync_context *data);
62
+ void cloudsync_update_schema_hash (cloudsync_context *data);
63
+ int cloudsync_dbversion_check_uptodate (cloudsync_context *data);
64
+ bool cloudsync_config_exists (cloudsync_context *data);
65
+ dbvm_t *cloudsync_colvalue_stmt (cloudsync_context *data, const char *tbl_name, bool *persistent);
66
+
67
+ // CloudSync alter table
68
+ int cloudsync_begin_alter (cloudsync_context *data, const char *table_name);
69
+ int cloudsync_commit_alter (cloudsync_context *data, const char *table_name);
70
+
71
+ // CloudSync getter/setter
72
+ void *cloudsync_db (cloudsync_context *data);
73
+ void *cloudsync_auxdata (cloudsync_context *data);
74
+ void cloudsync_set_auxdata (cloudsync_context *data, void *xdata);
75
+ int cloudsync_set_error (cloudsync_context *data, const char *err_user, int err_code);
76
+ int cloudsync_set_dberror (cloudsync_context *data);
77
+ const char *cloudsync_errmsg (cloudsync_context *data);
78
+ int cloudsync_errcode (cloudsync_context *data);
79
+ void cloudsync_reset_error (cloudsync_context *data);
80
+ int cloudsync_commit_hook (void *ctx);
81
+ void cloudsync_rollback_hook (void *ctx);
82
+ void cloudsync_set_schema (cloudsync_context *data, const char *schema);
83
+ const char *cloudsync_schema (cloudsync_context *data);
84
+ const char *cloudsync_table_schema (cloudsync_context *data, const char *table_name);
85
+
86
+ // Payload
87
+ int cloudsync_payload_apply (cloudsync_context *data, const char *payload, int blen, int *nrows);
88
+ int cloudsync_payload_encode_step (cloudsync_payload_context *payload, cloudsync_context *data, int argc, dbvalue_t **argv);
89
+ int cloudsync_payload_encode_final (cloudsync_payload_context *payload, cloudsync_context *data);
90
+ char *cloudsync_payload_blob (cloudsync_payload_context *payload, int64_t *blob_size, int64_t *nrows);
91
+ size_t cloudsync_payload_context_size (size_t *header_size);
92
+ int cloudsync_payload_get (cloudsync_context *data, char **blob, int *blob_size, int *db_version, int *seq, int64_t *new_db_version, int64_t *new_seq);
93
+ int cloudsync_payload_save (cloudsync_context *data, const char *payload_path, int *blob_size); // available only on Desktop OS (no WASM, no mobile)
94
+
95
+ // CloudSync table context
96
+ cloudsync_table_context *table_lookup (cloudsync_context *data, const char *table_name);
97
+ void *table_column_lookup (cloudsync_table_context *table, const char *col_name, bool is_merge, int *index);
98
+ bool table_enabled (cloudsync_table_context *table);
99
+ void table_set_enabled (cloudsync_table_context *table, bool value);
100
+ bool table_add_to_context (cloudsync_context *data, table_algo algo, const char *table_name);
101
+ bool table_pk_exists (cloudsync_table_context *table, const char *value, size_t len);
102
+ int table_count_cols (cloudsync_table_context *table);
103
+ int table_count_pks (cloudsync_table_context *table);
104
+ const char *table_colname (cloudsync_table_context *table, int index);
105
+ char **table_pknames (cloudsync_table_context *table);
106
+ void table_set_pknames (cloudsync_table_context *table, char **pknames);
107
+ bool table_algo_isgos (cloudsync_table_context *table);
108
+ const char *table_schema (cloudsync_table_context *table);
109
+ int table_remove (cloudsync_context *data, cloudsync_table_context *table);
110
+ void table_free (cloudsync_table_context *table);
111
+
112
+ // local merge/apply
113
+ int local_mark_insert_sentinel_meta (cloudsync_table_context *table, const char *pk, size_t pklen, int64_t db_version, int seq);
114
+ int local_update_sentinel (cloudsync_table_context *table, const char *pk, size_t pklen, int64_t db_version, int seq);
115
+ int local_mark_insert_or_update_meta (cloudsync_table_context *table, const char *pk, size_t pklen, const char *col_name, int64_t db_version, int seq);
116
+ int local_mark_delete_meta (cloudsync_table_context *table, const char *pk, size_t pklen, int64_t db_version, int seq);
117
+ int local_drop_meta (cloudsync_table_context *table, const char *pk, size_t pklen);
118
+ int local_update_move_meta (cloudsync_table_context *table, const char *pk, size_t pklen, const char *pk2, size_t pklen2, int64_t db_version);
119
+
120
+ // used by changes virtual table
121
+ int merge_insert_col (cloudsync_context *data, cloudsync_table_context *table, const char *pk, int pklen, const char *col_name, dbvalue_t *col_value, int64_t col_version, int64_t db_version, const char *site_id, int site_len, int64_t seq, int64_t *rowid);
122
+ int merge_insert (cloudsync_context *data, cloudsync_table_context *table, const char *insert_pk, int insert_pk_len, int64_t insert_cl, const char *insert_name, dbvalue_t *insert_value, int64_t insert_col_version, int64_t insert_db_version, const char *insert_site_id, int insert_site_id_len, int64_t insert_seq, int64_t *rowid);
123
+
124
+ // decode bind context
125
+ char *cloudsync_pk_context_tbl (cloudsync_pk_decode_bind_context *ctx, int64_t *tbl_len);
126
+ void *cloudsync_pk_context_pk (cloudsync_pk_decode_bind_context *ctx, int64_t *pk_len);
127
+ char *cloudsync_pk_context_colname (cloudsync_pk_decode_bind_context *ctx, int64_t *colname_len);
128
+ int64_t cloudsync_pk_context_cl (cloudsync_pk_decode_bind_context *ctx);
129
+ int64_t cloudsync_pk_context_dbversion (cloudsync_pk_decode_bind_context *ctx);
130
+
131
+ #ifdef __cplusplus
132
+ }
133
+ #endif
134
+
135
+ #endif
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> <string>en</string> <key>CFBundleExecutable</key> <string>CloudSync</string> <key>CFBundleIdentifier</key> <string>ai.sqlite.cloudsync</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundlePackageType</key> <string>FMWK</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleVersion</key> <string>0.9.93</string> <key>CFBundleShortVersionString</key> <string>0.9.93</string> <key>MinimumOSVersion</key> <string>11.0</string> </dict> </plist>
@@ -0,0 +1 @@
1
+ framework module CloudSync { umbrella header "CloudSync.h" export * }
@@ -0,0 +1,124 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>files</key>
6
+ <dict>
7
+ <key>Headers/CloudSync.h</key>
8
+ <data>
9
+ Nc+kIC+twZGH06Dw5dVhXMtyOHM=
10
+ </data>
11
+ <key>Info.plist</key>
12
+ <data>
13
+ yTqWzbysWYKSmsWB65CHpxOJbb4=
14
+ </data>
15
+ <key>Modules/module.modulemap</key>
16
+ <data>
17
+ ro9xghwl6x7oHnWfH0PiOV6up+o=
18
+ </data>
19
+ </dict>
20
+ <key>files2</key>
21
+ <dict>
22
+ <key>Headers/CloudSync.h</key>
23
+ <dict>
24
+ <key>hash2</key>
25
+ <data>
26
+ QiEl0xVP3oqIip09seRY0BkDjiPE+xlccwEZ2GAMjdI=
27
+ </data>
28
+ </dict>
29
+ <key>Modules/module.modulemap</key>
30
+ <dict>
31
+ <key>hash2</key>
32
+ <data>
33
+ bIwPn3WW18gPsoCQuL+cYaEBTMqTFCR6Y8FSln2GcXQ=
34
+ </data>
35
+ </dict>
36
+ </dict>
37
+ <key>rules</key>
38
+ <dict>
39
+ <key>^.*</key>
40
+ <true/>
41
+ <key>^.*\.lproj/</key>
42
+ <dict>
43
+ <key>optional</key>
44
+ <true/>
45
+ <key>weight</key>
46
+ <real>1000</real>
47
+ </dict>
48
+ <key>^.*\.lproj/locversion.plist$</key>
49
+ <dict>
50
+ <key>omit</key>
51
+ <true/>
52
+ <key>weight</key>
53
+ <real>1100</real>
54
+ </dict>
55
+ <key>^Base\.lproj/</key>
56
+ <dict>
57
+ <key>weight</key>
58
+ <real>1010</real>
59
+ </dict>
60
+ <key>^version.plist$</key>
61
+ <true/>
62
+ </dict>
63
+ <key>rules2</key>
64
+ <dict>
65
+ <key>.*\.dSYM($|/)</key>
66
+ <dict>
67
+ <key>weight</key>
68
+ <real>11</real>
69
+ </dict>
70
+ <key>^(.*/)?\.DS_Store$</key>
71
+ <dict>
72
+ <key>omit</key>
73
+ <true/>
74
+ <key>weight</key>
75
+ <real>2000</real>
76
+ </dict>
77
+ <key>^.*</key>
78
+ <true/>
79
+ <key>^.*\.lproj/</key>
80
+ <dict>
81
+ <key>optional</key>
82
+ <true/>
83
+ <key>weight</key>
84
+ <real>1000</real>
85
+ </dict>
86
+ <key>^.*\.lproj/locversion.plist$</key>
87
+ <dict>
88
+ <key>omit</key>
89
+ <true/>
90
+ <key>weight</key>
91
+ <real>1100</real>
92
+ </dict>
93
+ <key>^Base\.lproj/</key>
94
+ <dict>
95
+ <key>weight</key>
96
+ <real>1010</real>
97
+ </dict>
98
+ <key>^Info\.plist$</key>
99
+ <dict>
100
+ <key>omit</key>
101
+ <true/>
102
+ <key>weight</key>
103
+ <real>20</real>
104
+ </dict>
105
+ <key>^PkgInfo$</key>
106
+ <dict>
107
+ <key>omit</key>
108
+ <true/>
109
+ <key>weight</key>
110
+ <real>20</real>
111
+ </dict>
112
+ <key>^embedded\.provisionprofile$</key>
113
+ <dict>
114
+ <key>weight</key>
115
+ <real>20</real>
116
+ </dict>
117
+ <key>^version\.plist$</key>
118
+ <dict>
119
+ <key>weight</key>
120
+ <real>20</real>
121
+ </dict>
122
+ </dict>
123
+ </dict>
124
+ </plist>
@@ -0,0 +1,135 @@
1
+ //
2
+ // cloudsync.h
3
+ // cloudsync
4
+ //
5
+ // Created by Marco Bambini on 16/05/24.
6
+ //
7
+
8
+ #ifndef __CLOUDSYNC__
9
+ #define __CLOUDSYNC__
10
+
11
+ #include <stdint.h>
12
+ #include <stddef.h>
13
+ #include <stdbool.h>
14
+ #include "database.h"
15
+
16
+ #ifdef __cplusplus
17
+ extern "C" {
18
+ #endif
19
+
20
+ #define CLOUDSYNC_VERSION "0.9.93"
21
+ #define CLOUDSYNC_MAX_TABLENAME_LEN 512
22
+
23
+ #define CLOUDSYNC_VALUE_NOTSET -1
24
+ #define CLOUDSYNC_TOMBSTONE_VALUE "__[RIP]__"
25
+ #define CLOUDSYNC_RLS_RESTRICTED_VALUE "__[RLS]__"
26
+ #define CLOUDSYNC_DISABLE_ROWIDONLY_TABLES 1
27
+ #define CLOUDSYNC_DEFAULT_ALGO "cls"
28
+
29
+ #define CLOUDSYNC_CHANGES_NCOLS 9
30
+
31
+ typedef enum {
32
+ CLOUDSYNC_PAYLOAD_APPLY_WILL_APPLY = 1,
33
+ CLOUDSYNC_PAYLOAD_APPLY_DID_APPLY = 2,
34
+ CLOUDSYNC_PAYLOAD_APPLY_CLEANUP = 3
35
+ } CLOUDSYNC_PAYLOAD_APPLY_STEPS;
36
+
37
+ // CRDT Algos
38
+ table_algo cloudsync_algo_from_name (const char *algo_name);
39
+ const char *cloudsync_algo_name (table_algo algo);
40
+
41
+ // Opaque structures
42
+ typedef struct cloudsync_payload_context cloudsync_payload_context;
43
+ typedef struct cloudsync_table_context cloudsync_table_context;
44
+
45
+ // CloudSync context
46
+ cloudsync_context *cloudsync_context_create (void *db);
47
+ const char *cloudsync_context_init (cloudsync_context *data);
48
+ void cloudsync_context_free (void *ctx);
49
+
50
+ // CloudSync global
51
+ int cloudsync_init_table (cloudsync_context *data, const char *table_name, const char *algo_name, bool skip_int_pk_check);
52
+ int cloudsync_cleanup (cloudsync_context *data, const char *table_name);
53
+ int cloudsync_cleanup_all (cloudsync_context *data);
54
+ int cloudsync_terminate (cloudsync_context *data);
55
+ int cloudsync_insync (cloudsync_context *data);
56
+ int cloudsync_bumpseq (cloudsync_context *data);
57
+ void *cloudsync_siteid (cloudsync_context *data);
58
+ void cloudsync_reset_siteid (cloudsync_context *data);
59
+ void cloudsync_sync_key (cloudsync_context *data, const char *key, const char *value);
60
+ int64_t cloudsync_dbversion_next (cloudsync_context *data, int64_t merging_version);
61
+ int64_t cloudsync_dbversion (cloudsync_context *data);
62
+ void cloudsync_update_schema_hash (cloudsync_context *data);
63
+ int cloudsync_dbversion_check_uptodate (cloudsync_context *data);
64
+ bool cloudsync_config_exists (cloudsync_context *data);
65
+ dbvm_t *cloudsync_colvalue_stmt (cloudsync_context *data, const char *tbl_name, bool *persistent);
66
+
67
+ // CloudSync alter table
68
+ int cloudsync_begin_alter (cloudsync_context *data, const char *table_name);
69
+ int cloudsync_commit_alter (cloudsync_context *data, const char *table_name);
70
+
71
+ // CloudSync getter/setter
72
+ void *cloudsync_db (cloudsync_context *data);
73
+ void *cloudsync_auxdata (cloudsync_context *data);
74
+ void cloudsync_set_auxdata (cloudsync_context *data, void *xdata);
75
+ int cloudsync_set_error (cloudsync_context *data, const char *err_user, int err_code);
76
+ int cloudsync_set_dberror (cloudsync_context *data);
77
+ const char *cloudsync_errmsg (cloudsync_context *data);
78
+ int cloudsync_errcode (cloudsync_context *data);
79
+ void cloudsync_reset_error (cloudsync_context *data);
80
+ int cloudsync_commit_hook (void *ctx);
81
+ void cloudsync_rollback_hook (void *ctx);
82
+ void cloudsync_set_schema (cloudsync_context *data, const char *schema);
83
+ const char *cloudsync_schema (cloudsync_context *data);
84
+ const char *cloudsync_table_schema (cloudsync_context *data, const char *table_name);
85
+
86
+ // Payload
87
+ int cloudsync_payload_apply (cloudsync_context *data, const char *payload, int blen, int *nrows);
88
+ int cloudsync_payload_encode_step (cloudsync_payload_context *payload, cloudsync_context *data, int argc, dbvalue_t **argv);
89
+ int cloudsync_payload_encode_final (cloudsync_payload_context *payload, cloudsync_context *data);
90
+ char *cloudsync_payload_blob (cloudsync_payload_context *payload, int64_t *blob_size, int64_t *nrows);
91
+ size_t cloudsync_payload_context_size (size_t *header_size);
92
+ int cloudsync_payload_get (cloudsync_context *data, char **blob, int *blob_size, int *db_version, int *seq, int64_t *new_db_version, int64_t *new_seq);
93
+ int cloudsync_payload_save (cloudsync_context *data, const char *payload_path, int *blob_size); // available only on Desktop OS (no WASM, no mobile)
94
+
95
+ // CloudSync table context
96
+ cloudsync_table_context *table_lookup (cloudsync_context *data, const char *table_name);
97
+ void *table_column_lookup (cloudsync_table_context *table, const char *col_name, bool is_merge, int *index);
98
+ bool table_enabled (cloudsync_table_context *table);
99
+ void table_set_enabled (cloudsync_table_context *table, bool value);
100
+ bool table_add_to_context (cloudsync_context *data, table_algo algo, const char *table_name);
101
+ bool table_pk_exists (cloudsync_table_context *table, const char *value, size_t len);
102
+ int table_count_cols (cloudsync_table_context *table);
103
+ int table_count_pks (cloudsync_table_context *table);
104
+ const char *table_colname (cloudsync_table_context *table, int index);
105
+ char **table_pknames (cloudsync_table_context *table);
106
+ void table_set_pknames (cloudsync_table_context *table, char **pknames);
107
+ bool table_algo_isgos (cloudsync_table_context *table);
108
+ const char *table_schema (cloudsync_table_context *table);
109
+ int table_remove (cloudsync_context *data, cloudsync_table_context *table);
110
+ void table_free (cloudsync_table_context *table);
111
+
112
+ // local merge/apply
113
+ int local_mark_insert_sentinel_meta (cloudsync_table_context *table, const char *pk, size_t pklen, int64_t db_version, int seq);
114
+ int local_update_sentinel (cloudsync_table_context *table, const char *pk, size_t pklen, int64_t db_version, int seq);
115
+ int local_mark_insert_or_update_meta (cloudsync_table_context *table, const char *pk, size_t pklen, const char *col_name, int64_t db_version, int seq);
116
+ int local_mark_delete_meta (cloudsync_table_context *table, const char *pk, size_t pklen, int64_t db_version, int seq);
117
+ int local_drop_meta (cloudsync_table_context *table, const char *pk, size_t pklen);
118
+ int local_update_move_meta (cloudsync_table_context *table, const char *pk, size_t pklen, const char *pk2, size_t pklen2, int64_t db_version);
119
+
120
+ // used by changes virtual table
121
+ int merge_insert_col (cloudsync_context *data, cloudsync_table_context *table, const char *pk, int pklen, const char *col_name, dbvalue_t *col_value, int64_t col_version, int64_t db_version, const char *site_id, int site_len, int64_t seq, int64_t *rowid);
122
+ int merge_insert (cloudsync_context *data, cloudsync_table_context *table, const char *insert_pk, int insert_pk_len, int64_t insert_cl, const char *insert_name, dbvalue_t *insert_value, int64_t insert_col_version, int64_t insert_db_version, const char *insert_site_id, int insert_site_id_len, int64_t insert_seq, int64_t *rowid);
123
+
124
+ // decode bind context
125
+ char *cloudsync_pk_context_tbl (cloudsync_pk_decode_bind_context *ctx, int64_t *tbl_len);
126
+ void *cloudsync_pk_context_pk (cloudsync_pk_decode_bind_context *ctx, int64_t *pk_len);
127
+ char *cloudsync_pk_context_colname (cloudsync_pk_decode_bind_context *ctx, int64_t *colname_len);
128
+ int64_t cloudsync_pk_context_cl (cloudsync_pk_decode_bind_context *ctx);
129
+ int64_t cloudsync_pk_context_dbversion (cloudsync_pk_decode_bind_context *ctx);
130
+
131
+ #ifdef __cplusplus
132
+ }
133
+ #endif
134
+
135
+ #endif
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> <string>en</string> <key>CFBundleExecutable</key> <string>CloudSync</string> <key>CFBundleIdentifier</key> <string>ai.sqlite.cloudsync</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundlePackageType</key> <string>FMWK</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleVersion</key> <string>0.9.93</string> <key>CFBundleShortVersionString</key> <string>0.9.93</string> <key>MinimumOSVersion</key> <string>11.0</string> </dict> </plist>
@@ -0,0 +1 @@
1
+ framework module CloudSync { umbrella header "CloudSync.h" export * }
@@ -0,0 +1,124 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>files</key>
6
+ <dict>
7
+ <key>Headers/CloudSync.h</key>
8
+ <data>
9
+ Nc+kIC+twZGH06Dw5dVhXMtyOHM=
10
+ </data>
11
+ <key>Info.plist</key>
12
+ <data>
13
+ yTqWzbysWYKSmsWB65CHpxOJbb4=
14
+ </data>
15
+ <key>Modules/module.modulemap</key>
16
+ <data>
17
+ ro9xghwl6x7oHnWfH0PiOV6up+o=
18
+ </data>
19
+ </dict>
20
+ <key>files2</key>
21
+ <dict>
22
+ <key>Headers/CloudSync.h</key>
23
+ <dict>
24
+ <key>hash2</key>
25
+ <data>
26
+ QiEl0xVP3oqIip09seRY0BkDjiPE+xlccwEZ2GAMjdI=
27
+ </data>
28
+ </dict>
29
+ <key>Modules/module.modulemap</key>
30
+ <dict>
31
+ <key>hash2</key>
32
+ <data>
33
+ bIwPn3WW18gPsoCQuL+cYaEBTMqTFCR6Y8FSln2GcXQ=
34
+ </data>
35
+ </dict>
36
+ </dict>
37
+ <key>rules</key>
38
+ <dict>
39
+ <key>^.*</key>
40
+ <true/>
41
+ <key>^.*\.lproj/</key>
42
+ <dict>
43
+ <key>optional</key>
44
+ <true/>
45
+ <key>weight</key>
46
+ <real>1000</real>
47
+ </dict>
48
+ <key>^.*\.lproj/locversion.plist$</key>
49
+ <dict>
50
+ <key>omit</key>
51
+ <true/>
52
+ <key>weight</key>
53
+ <real>1100</real>
54
+ </dict>
55
+ <key>^Base\.lproj/</key>
56
+ <dict>
57
+ <key>weight</key>
58
+ <real>1010</real>
59
+ </dict>
60
+ <key>^version.plist$</key>
61
+ <true/>
62
+ </dict>
63
+ <key>rules2</key>
64
+ <dict>
65
+ <key>.*\.dSYM($|/)</key>
66
+ <dict>
67
+ <key>weight</key>
68
+ <real>11</real>
69
+ </dict>
70
+ <key>^(.*/)?\.DS_Store$</key>
71
+ <dict>
72
+ <key>omit</key>
73
+ <true/>
74
+ <key>weight</key>
75
+ <real>2000</real>
76
+ </dict>
77
+ <key>^.*</key>
78
+ <true/>
79
+ <key>^.*\.lproj/</key>
80
+ <dict>
81
+ <key>optional</key>
82
+ <true/>
83
+ <key>weight</key>
84
+ <real>1000</real>
85
+ </dict>
86
+ <key>^.*\.lproj/locversion.plist$</key>
87
+ <dict>
88
+ <key>omit</key>
89
+ <true/>
90
+ <key>weight</key>
91
+ <real>1100</real>
92
+ </dict>
93
+ <key>^Base\.lproj/</key>
94
+ <dict>
95
+ <key>weight</key>
96
+ <real>1010</real>
97
+ </dict>
98
+ <key>^Info\.plist$</key>
99
+ <dict>
100
+ <key>omit</key>
101
+ <true/>
102
+ <key>weight</key>
103
+ <real>20</real>
104
+ </dict>
105
+ <key>^PkgInfo$</key>
106
+ <dict>
107
+ <key>omit</key>
108
+ <true/>
109
+ <key>weight</key>
110
+ <real>20</real>
111
+ </dict>
112
+ <key>^embedded\.provisionprofile$</key>
113
+ <dict>
114
+ <key>weight</key>
115
+ <real>20</real>
116
+ </dict>
117
+ <key>^version\.plist$</key>
118
+ <dict>
119
+ <key>weight</key>
120
+ <real>20</real>
121
+ </dict>
122
+ </dict>
123
+ </dict>
124
+ </plist>
@@ -0,0 +1,135 @@
1
+ //
2
+ // cloudsync.h
3
+ // cloudsync
4
+ //
5
+ // Created by Marco Bambini on 16/05/24.
6
+ //
7
+
8
+ #ifndef __CLOUDSYNC__
9
+ #define __CLOUDSYNC__
10
+
11
+ #include <stdint.h>
12
+ #include <stddef.h>
13
+ #include <stdbool.h>
14
+ #include "database.h"
15
+
16
+ #ifdef __cplusplus
17
+ extern "C" {
18
+ #endif
19
+
20
+ #define CLOUDSYNC_VERSION "0.9.93"
21
+ #define CLOUDSYNC_MAX_TABLENAME_LEN 512
22
+
23
+ #define CLOUDSYNC_VALUE_NOTSET -1
24
+ #define CLOUDSYNC_TOMBSTONE_VALUE "__[RIP]__"
25
+ #define CLOUDSYNC_RLS_RESTRICTED_VALUE "__[RLS]__"
26
+ #define CLOUDSYNC_DISABLE_ROWIDONLY_TABLES 1
27
+ #define CLOUDSYNC_DEFAULT_ALGO "cls"
28
+
29
+ #define CLOUDSYNC_CHANGES_NCOLS 9
30
+
31
+ typedef enum {
32
+ CLOUDSYNC_PAYLOAD_APPLY_WILL_APPLY = 1,
33
+ CLOUDSYNC_PAYLOAD_APPLY_DID_APPLY = 2,
34
+ CLOUDSYNC_PAYLOAD_APPLY_CLEANUP = 3
35
+ } CLOUDSYNC_PAYLOAD_APPLY_STEPS;
36
+
37
+ // CRDT Algos
38
+ table_algo cloudsync_algo_from_name (const char *algo_name);
39
+ const char *cloudsync_algo_name (table_algo algo);
40
+
41
+ // Opaque structures
42
+ typedef struct cloudsync_payload_context cloudsync_payload_context;
43
+ typedef struct cloudsync_table_context cloudsync_table_context;
44
+
45
+ // CloudSync context
46
+ cloudsync_context *cloudsync_context_create (void *db);
47
+ const char *cloudsync_context_init (cloudsync_context *data);
48
+ void cloudsync_context_free (void *ctx);
49
+
50
+ // CloudSync global
51
+ int cloudsync_init_table (cloudsync_context *data, const char *table_name, const char *algo_name, bool skip_int_pk_check);
52
+ int cloudsync_cleanup (cloudsync_context *data, const char *table_name);
53
+ int cloudsync_cleanup_all (cloudsync_context *data);
54
+ int cloudsync_terminate (cloudsync_context *data);
55
+ int cloudsync_insync (cloudsync_context *data);
56
+ int cloudsync_bumpseq (cloudsync_context *data);
57
+ void *cloudsync_siteid (cloudsync_context *data);
58
+ void cloudsync_reset_siteid (cloudsync_context *data);
59
+ void cloudsync_sync_key (cloudsync_context *data, const char *key, const char *value);
60
+ int64_t cloudsync_dbversion_next (cloudsync_context *data, int64_t merging_version);
61
+ int64_t cloudsync_dbversion (cloudsync_context *data);
62
+ void cloudsync_update_schema_hash (cloudsync_context *data);
63
+ int cloudsync_dbversion_check_uptodate (cloudsync_context *data);
64
+ bool cloudsync_config_exists (cloudsync_context *data);
65
+ dbvm_t *cloudsync_colvalue_stmt (cloudsync_context *data, const char *tbl_name, bool *persistent);
66
+
67
+ // CloudSync alter table
68
+ int cloudsync_begin_alter (cloudsync_context *data, const char *table_name);
69
+ int cloudsync_commit_alter (cloudsync_context *data, const char *table_name);
70
+
71
+ // CloudSync getter/setter
72
+ void *cloudsync_db (cloudsync_context *data);
73
+ void *cloudsync_auxdata (cloudsync_context *data);
74
+ void cloudsync_set_auxdata (cloudsync_context *data, void *xdata);
75
+ int cloudsync_set_error (cloudsync_context *data, const char *err_user, int err_code);
76
+ int cloudsync_set_dberror (cloudsync_context *data);
77
+ const char *cloudsync_errmsg (cloudsync_context *data);
78
+ int cloudsync_errcode (cloudsync_context *data);
79
+ void cloudsync_reset_error (cloudsync_context *data);
80
+ int cloudsync_commit_hook (void *ctx);
81
+ void cloudsync_rollback_hook (void *ctx);
82
+ void cloudsync_set_schema (cloudsync_context *data, const char *schema);
83
+ const char *cloudsync_schema (cloudsync_context *data);
84
+ const char *cloudsync_table_schema (cloudsync_context *data, const char *table_name);
85
+
86
+ // Payload
87
+ int cloudsync_payload_apply (cloudsync_context *data, const char *payload, int blen, int *nrows);
88
+ int cloudsync_payload_encode_step (cloudsync_payload_context *payload, cloudsync_context *data, int argc, dbvalue_t **argv);
89
+ int cloudsync_payload_encode_final (cloudsync_payload_context *payload, cloudsync_context *data);
90
+ char *cloudsync_payload_blob (cloudsync_payload_context *payload, int64_t *blob_size, int64_t *nrows);
91
+ size_t cloudsync_payload_context_size (size_t *header_size);
92
+ int cloudsync_payload_get (cloudsync_context *data, char **blob, int *blob_size, int *db_version, int *seq, int64_t *new_db_version, int64_t *new_seq);
93
+ int cloudsync_payload_save (cloudsync_context *data, const char *payload_path, int *blob_size); // available only on Desktop OS (no WASM, no mobile)
94
+
95
+ // CloudSync table context
96
+ cloudsync_table_context *table_lookup (cloudsync_context *data, const char *table_name);
97
+ void *table_column_lookup (cloudsync_table_context *table, const char *col_name, bool is_merge, int *index);
98
+ bool table_enabled (cloudsync_table_context *table);
99
+ void table_set_enabled (cloudsync_table_context *table, bool value);
100
+ bool table_add_to_context (cloudsync_context *data, table_algo algo, const char *table_name);
101
+ bool table_pk_exists (cloudsync_table_context *table, const char *value, size_t len);
102
+ int table_count_cols (cloudsync_table_context *table);
103
+ int table_count_pks (cloudsync_table_context *table);
104
+ const char *table_colname (cloudsync_table_context *table, int index);
105
+ char **table_pknames (cloudsync_table_context *table);
106
+ void table_set_pknames (cloudsync_table_context *table, char **pknames);
107
+ bool table_algo_isgos (cloudsync_table_context *table);
108
+ const char *table_schema (cloudsync_table_context *table);
109
+ int table_remove (cloudsync_context *data, cloudsync_table_context *table);
110
+ void table_free (cloudsync_table_context *table);
111
+
112
+ // local merge/apply
113
+ int local_mark_insert_sentinel_meta (cloudsync_table_context *table, const char *pk, size_t pklen, int64_t db_version, int seq);
114
+ int local_update_sentinel (cloudsync_table_context *table, const char *pk, size_t pklen, int64_t db_version, int seq);
115
+ int local_mark_insert_or_update_meta (cloudsync_table_context *table, const char *pk, size_t pklen, const char *col_name, int64_t db_version, int seq);
116
+ int local_mark_delete_meta (cloudsync_table_context *table, const char *pk, size_t pklen, int64_t db_version, int seq);
117
+ int local_drop_meta (cloudsync_table_context *table, const char *pk, size_t pklen);
118
+ int local_update_move_meta (cloudsync_table_context *table, const char *pk, size_t pklen, const char *pk2, size_t pklen2, int64_t db_version);
119
+
120
+ // used by changes virtual table
121
+ int merge_insert_col (cloudsync_context *data, cloudsync_table_context *table, const char *pk, int pklen, const char *col_name, dbvalue_t *col_value, int64_t col_version, int64_t db_version, const char *site_id, int site_len, int64_t seq, int64_t *rowid);
122
+ int merge_insert (cloudsync_context *data, cloudsync_table_context *table, const char *insert_pk, int insert_pk_len, int64_t insert_cl, const char *insert_name, dbvalue_t *insert_value, int64_t insert_col_version, int64_t insert_db_version, const char *insert_site_id, int insert_site_id_len, int64_t insert_seq, int64_t *rowid);
123
+
124
+ // decode bind context
125
+ char *cloudsync_pk_context_tbl (cloudsync_pk_decode_bind_context *ctx, int64_t *tbl_len);
126
+ void *cloudsync_pk_context_pk (cloudsync_pk_decode_bind_context *ctx, int64_t *pk_len);
127
+ char *cloudsync_pk_context_colname (cloudsync_pk_decode_bind_context *ctx, int64_t *colname_len);
128
+ int64_t cloudsync_pk_context_cl (cloudsync_pk_decode_bind_context *ctx);
129
+ int64_t cloudsync_pk_context_dbversion (cloudsync_pk_decode_bind_context *ctx);
130
+
131
+ #ifdef __cplusplus
132
+ }
133
+ #endif
134
+
135
+ #endif