@dittolive/ditto 4.5.4 → 4.6.0

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 (87) hide show
  1. package/README.md +2 -2
  2. package/node/ditto.cjs.js +1111 -563
  3. package/node/ditto.darwin-arm64.node +0 -0
  4. package/node/ditto.darwin-x64.node +0 -0
  5. package/node/ditto.linux-arm.node +0 -0
  6. package/node/ditto.linux-arm64.node +0 -0
  7. package/node/ditto.linux-x64.node +0 -0
  8. package/node/ditto.win32-x64.node +0 -0
  9. package/node/transports.darwin-arm64.node +0 -0
  10. package/node/transports.darwin-x64.node +0 -0
  11. package/package.json +45 -1
  12. package/react-native/android/build.gradle +1 -1
  13. package/react-native/android/cpp-adapter.cpp +68 -59
  14. package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKModule.java +35 -0
  15. package/react-native/cpp/include/Arc.hpp +1 -1
  16. package/react-native/cpp/include/Attachment.h +5 -1
  17. package/react-native/cpp/include/DQL.h +9 -9
  18. package/react-native/cpp/include/FFIUtils.h +14 -0
  19. package/react-native/cpp/include/IO.h +13 -0
  20. package/react-native/cpp/include/Lifecycle.h +0 -1
  21. package/react-native/cpp/include/Misc.h +3 -0
  22. package/react-native/cpp/include/Utils.h +0 -2
  23. package/react-native/cpp/src/Attachment.cpp +200 -13
  24. package/react-native/cpp/src/Authentication.cpp +3 -3
  25. package/react-native/cpp/src/DQL.cpp +23 -23
  26. package/react-native/cpp/src/Document.cpp +10 -10
  27. package/react-native/cpp/src/FFIUtils.cpp +64 -0
  28. package/react-native/cpp/src/IO.cpp +35 -0
  29. package/react-native/cpp/src/Identity.cpp +3 -3
  30. package/react-native/cpp/src/Lifecycle.cpp +2 -19
  31. package/react-native/cpp/src/LiveQuery.cpp +3 -5
  32. package/react-native/cpp/src/Logger.cpp +171 -172
  33. package/react-native/cpp/src/Misc.cpp +52 -4
  34. package/react-native/cpp/src/Presence.cpp +1 -1
  35. package/react-native/cpp/src/SmallPeerInfo.cpp +1 -1
  36. package/react-native/cpp/src/Transports.cpp +10 -5
  37. package/react-native/cpp/src/Utils.cpp +110 -114
  38. package/react-native/cpp/src/main.cpp +28 -15
  39. package/react-native/dittoffi/dittoffi.h +328 -280
  40. package/react-native/ios/DittoRNSDK.mm +123 -71
  41. package/react-native/src/ditto.rn.ts +30 -6
  42. package/react-native/src/index.ts +7 -4
  43. package/react-native/src/sources/@cbor-redux.ts +1 -1
  44. package/react-native/src/sources/attachment-fetch-event.ts +2 -2
  45. package/react-native/src/sources/attachment-fetcher-manager.ts +5 -4
  46. package/react-native/src/sources/attachment-fetcher.ts +152 -21
  47. package/react-native/src/sources/attachment-token.ts +94 -13
  48. package/react-native/src/sources/attachment.ts +66 -19
  49. package/react-native/src/sources/augment.ts +13 -6
  50. package/react-native/src/sources/base-pending-cursor-operation.ts +22 -6
  51. package/react-native/src/sources/base-pending-id-specific-operation.ts +3 -0
  52. package/react-native/src/sources/bridge.ts +2 -2
  53. package/react-native/src/sources/cbor.ts +0 -15
  54. package/react-native/src/sources/collection-interface.ts +12 -6
  55. package/react-native/src/sources/collection.ts +9 -2
  56. package/react-native/src/sources/ditto.ts +26 -18
  57. package/react-native/src/sources/document-id.ts +11 -7
  58. package/react-native/src/sources/document-path.ts +4 -2
  59. package/react-native/src/sources/document.ts +49 -5
  60. package/react-native/src/sources/error-codes.ts +28 -0
  61. package/react-native/src/sources/error.ts +20 -1
  62. package/react-native/src/sources/essentials.ts +25 -3
  63. package/react-native/src/sources/ffi-error.ts +2 -1
  64. package/react-native/src/sources/ffi.ts +180 -102
  65. package/react-native/src/sources/internal.ts +37 -3
  66. package/react-native/src/sources/live-query-manager.ts +10 -1
  67. package/react-native/src/sources/live-query.ts +1 -1
  68. package/react-native/src/sources/observer-manager.ts +7 -0
  69. package/react-native/src/sources/pending-id-specific-operation.ts +2 -2
  70. package/react-native/src/sources/presence-manager.ts +12 -2
  71. package/react-native/src/sources/presence.ts +5 -0
  72. package/react-native/src/sources/query-result-item.ts +15 -0
  73. package/react-native/src/sources/small-peer-info.ts +2 -2
  74. package/react-native/src/sources/static-tcp-client.ts +2 -0
  75. package/react-native/src/sources/store-observer.ts +4 -2
  76. package/react-native/src/sources/store.ts +253 -3
  77. package/react-native/src/sources/sync.ts +6 -3
  78. package/react-native/src/sources/transport-config.ts +2 -2
  79. package/react-native/src/sources/update-results-map.ts +8 -0
  80. package/react-native/src/sources/write-transaction-collection.ts +1 -1
  81. package/react-native/src/sources/write-transaction.ts +1 -1
  82. package/types/ditto.d.ts +2866 -2568
  83. package/web/ditto.es6.js +1 -1
  84. package/web/ditto.umd.js +1 -1
  85. package/web/ditto.wasm +0 -0
  86. package/react-native/.yarn/install-state.gz +0 -0
  87. package/react-native/.yarnrc.yml +0 -1
@@ -4,23 +4,6 @@
4
4
 
5
5
  namespace sharedjsi
6
6
  {
7
- Function ditto_uninitialized_ditto_make(Runtime &runtime)
8
- {
9
- return Function::createFromHostFunction(runtime,
10
- PropNameID::forAscii(runtime,
11
- STRINGIFIED_FUNC_NAME()),
12
- 0,
13
- [](Runtime &runtime,
14
- const Value &thisValue,
15
- const Value *arguments,
16
- size_t count) -> Value
17
- {
18
- std::string path = jsTypedArrayToCString(runtime, arguments[0]);
19
- UninitializedDitto_t *pointer = ::ditto_uninitialized_ditto_make(path.c_str());
20
- return cPointerToJSPointerObject(runtime, pointer);
21
- });
22
- }
23
-
24
7
  Function ditto_shutdown(Runtime &runtime)
25
8
  {
26
9
  return Function::createFromHostFunction(runtime,
@@ -64,11 +47,11 @@ Function ditto_make(Runtime &runtime)
64
47
  const Value *arguments,
65
48
  size_t count) -> Value
66
49
  {
67
- UninitializedDitto_t *uninit_ditto = jsPointerObjectToCPointer<UninitializedDitto_t>(runtime, arguments[0]);
50
+ std::string path = jsTypedArrayToCString(runtime, arguments[0]);
68
51
  CIdentityConfig_t *identity_config = jsPointerObjectToCPointer<CIdentityConfig_t>(runtime, arguments[1]);
69
52
  HistoryTracking_t history_tracking = HISTORY_TRACKING_DISABLED;
70
53
 
71
- CDitto_t *pointer = ::ditto_make(uninit_ditto, identity_config, history_tracking);
54
+ CDitto_t *pointer = ::ditto_make(path.c_str(), identity_config, history_tracking);
72
55
  return cPointerToJSPointerObject(runtime, pointer);
73
56
  });
74
57
  }
@@ -5,8 +5,6 @@
5
5
  namespace sharedjsi
6
6
  {
7
7
 
8
- // TODO: Bridge int64_t! When we'll actually reach a number as big as int64, it will crash.
9
-
10
8
  Function ditto_live_query_signal_available_next(Runtime &runtime)
11
9
  {
12
10
  return Function::createFromHostFunction(runtime,
@@ -19,7 +17,7 @@ Function ditto_live_query_signal_available_next(Runtime &runtime)
19
17
  size_t count) -> Value
20
18
  {
21
19
  CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
22
- int64_t liveQueryId = arguments[1].asNumber();
20
+ int64_t liveQueryId = arguments[1].asBigInt(runtime).asInt64(runtime);
23
21
 
24
22
  ::ditto_live_query_signal_available_next(ditto, liveQueryId);
25
23
  return Value();
@@ -38,7 +36,7 @@ Function ditto_live_query_start(Runtime &runtime)
38
36
  size_t count) -> Value
39
37
  {
40
38
  CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
41
- int64_t liveQueryId = arguments[1].asNumber();
39
+ int64_t liveQueryId = arguments[1].asBigInt(runtime).asInt64(runtime);
42
40
  int32_t res = ::ditto_live_query_start(ditto, liveQueryId);
43
41
  return static_cast<double>(res);
44
42
  });
@@ -56,7 +54,7 @@ Function ditto_live_query_stop(Runtime &runtime)
56
54
  size_t count) -> Value
57
55
  {
58
56
  CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
59
- int64_t liveQueryId = arguments[1].asNumber();
57
+ int64_t liveQueryId = arguments[1].asBigInt(runtime).asInt64(runtime);
60
58
 
61
59
  ::ditto_live_query_stop(ditto, liveQueryId);
62
60
  return Value();
@@ -1,4 +1,3 @@
1
-
2
1
  #include "Logger.h"
3
2
  #include "Utils.h"
4
3
 
@@ -7,194 +6,194 @@
7
6
  namespace sharedjsi
8
7
  {
9
8
 
10
- CLogLevel_t jsLogLevelStringToCLogLevel(std::string log_level)
11
- {
12
- static const std::unordered_map<std::string, CLogLevel_t> lookup = {
13
- {"Error", C_LOG_LEVEL_ERROR},
14
- {"Warning", C_LOG_LEVEL_WARNING},
15
- {"Info", C_LOG_LEVEL_INFO},
16
- {"Debug", C_LOG_LEVEL_DEBUG},
17
- {"Verbose", C_LOG_LEVEL_VERBOSE},
18
- };
19
-
20
- auto it = lookup.find(log_level.c_str());
21
- if (it != lookup.end())
22
- {
23
- return it->second;
24
- }
25
- else
26
- {
27
- throw std::invalid_argument("Invalid log level");
28
- }
29
- };
30
-
31
- std::string cLogLevelToJSLogLevelString(CLogLevel_t log_level)
32
- {
33
- static const std::unordered_map<CLogLevel_t, std::string> lookup = {
34
- {C_LOG_LEVEL_ERROR, "Error"},
35
- {C_LOG_LEVEL_WARNING, "Warning"},
36
- {C_LOG_LEVEL_INFO, "Info"},
37
- {C_LOG_LEVEL_DEBUG, "Debug"},
38
- {C_LOG_LEVEL_VERBOSE, "Verbose"},
39
- };
40
-
41
- auto it = lookup.find(log_level);
42
- if (it != lookup.end())
43
- {
44
- return it->second;
45
- }
46
- else
47
- {
48
- throw std::invalid_argument("Invalid log level");
49
- }
9
+ CLogLevel_t jsLogLevelStringToCLogLevel(std::string log_level)
10
+ {
11
+ static const std::unordered_map<std::string, CLogLevel_t> lookup = {
12
+ {"Error", C_LOG_LEVEL_ERROR},
13
+ {"Warning", C_LOG_LEVEL_WARNING},
14
+ {"Info", C_LOG_LEVEL_INFO},
15
+ {"Debug", C_LOG_LEVEL_DEBUG},
16
+ {"Verbose", C_LOG_LEVEL_VERBOSE},
50
17
  };
51
18
 
52
- Function ditto_log(Runtime &runtime)
19
+ auto it = lookup.find(log_level.c_str());
20
+ if (it != lookup.end())
53
21
  {
54
- return Function::createFromHostFunction(runtime,
55
- PropNameID::forAscii(runtime,
56
- STRINGIFIED_FUNC_NAME()),
57
- 0,
58
- [](Runtime &runtime,
59
- const Value &thisValue,
60
- const Value *arguments,
61
- size_t count) -> Value
62
- {
63
- std::string log_level_str = arguments[0].toString(runtime).utf8(runtime);
64
- CLogLevel_t log_level = jsLogLevelStringToCLogLevel(log_level_str);
65
-
66
- std::string message_str = jsTypedArrayToCString(runtime, arguments[1]);
67
- const char *message = message_str.c_str();
68
-
69
- ::ditto_log(log_level, message);
70
- return Value();
71
- });
22
+ return it->second;
72
23
  }
73
-
74
- Function ditto_logger_minimum_log_level_get(Runtime &runtime)
24
+ else
75
25
  {
76
- return Function::createFromHostFunction(runtime,
77
- PropNameID::forAscii(runtime,
78
- STRINGIFIED_FUNC_NAME()),
79
- 0,
80
- [](Runtime &runtime,
81
- const Value &thisValue,
82
- const Value *arguments,
83
- size_t count) -> Value
84
- {
85
- CLogLevel_t res = ::ditto_logger_minimum_log_level_get();
86
- std::string log_level = cLogLevelToJSLogLevelString(res);
87
- return String::createFromUtf8(runtime, log_level);
88
- });
26
+ throw std::invalid_argument("Invalid log level");
89
27
  }
28
+ };
90
29
 
91
- Function ditto_logger_minimum_log_level(Runtime &runtime)
92
- {
93
- return Function::createFromHostFunction(runtime,
94
- PropNameID::forAscii(runtime,
95
- STRINGIFIED_FUNC_NAME()),
96
- 0,
97
- [](Runtime &runtime,
98
- const Value &thisValue,
99
- const Value *arguments,
100
- size_t count) -> Value
101
- {
102
- std::string log_level_str = arguments[0].toString(runtime).utf8(runtime);
103
- CLogLevel_t log_level = jsLogLevelStringToCLogLevel(log_level_str);
104
-
105
- ::ditto_logger_minimum_log_level(log_level);
106
- return Value();
107
- });
108
- }
30
+ std::string cLogLevelToJSLogLevelString(CLogLevel_t log_level)
31
+ {
32
+ static const std::unordered_map<CLogLevel_t, std::string> lookup = {
33
+ {C_LOG_LEVEL_ERROR, "Error"},
34
+ {C_LOG_LEVEL_WARNING, "Warning"},
35
+ {C_LOG_LEVEL_INFO, "Info"},
36
+ {C_LOG_LEVEL_DEBUG, "Debug"},
37
+ {C_LOG_LEVEL_VERBOSE, "Verbose"},
38
+ };
109
39
 
110
- Function ditto_logger_set_log_file(Runtime &runtime)
40
+ auto it = lookup.find(log_level);
41
+ if (it != lookup.end())
111
42
  {
112
- return Function::createFromHostFunction(runtime,
113
- PropNameID::forAscii(runtime,
114
- STRINGIFIED_FUNC_NAME()),
115
- 0,
116
- [](Runtime &runtime,
117
- const Value &thisValue,
118
- const Value *arguments,
119
- size_t count) -> Value
120
- {
121
- ::ditto_logger_set_log_file(arguments[0].toString(runtime).utf8(runtime).c_str());
122
- return Value();
123
- });
43
+ return it->second;
124
44
  }
125
-
126
- Function ditto_logger_emoji_headings_enabled(Runtime &runtime)
45
+ else
127
46
  {
128
- return Function::createFromHostFunction(runtime,
129
- PropNameID::forAscii(runtime,
130
- STRINGIFIED_FUNC_NAME()),
131
- 0,
132
- [](Runtime &runtime,
133
- const Value &thisValue,
134
- const Value *arguments,
135
- size_t count) -> Value
136
- {
137
- ::ditto_logger_emoji_headings_enabled(arguments[0].asBool());
138
- return Value();
139
- });
47
+ throw std::invalid_argument("Invalid log level");
140
48
  }
49
+ };
141
50
 
142
- Function ditto_logger_emoji_headings_enabled_get(Runtime &runtime)
143
- {
144
- return Function::createFromHostFunction(runtime,
145
- PropNameID::forAscii(runtime,
146
- STRINGIFIED_FUNC_NAME()),
147
- 0,
148
- [](Runtime &runtime,
149
- const Value &thisValue,
150
- const Value *arguments,
151
- size_t count) -> Value
152
- {
153
- return ::ditto_logger_emoji_headings_enabled_get();
154
- });
155
- }
51
+ Function ditto_log(Runtime &runtime)
52
+ {
53
+ return Function::createFromHostFunction(runtime,
54
+ PropNameID::forAscii(runtime,
55
+ STRINGIFIED_FUNC_NAME()),
56
+ 0,
57
+ [](Runtime &runtime,
58
+ const Value &thisValue,
59
+ const Value *arguments,
60
+ size_t count) -> Value
61
+ {
62
+ std::string log_level_str = arguments[0].toString(runtime).utf8(runtime);
63
+ CLogLevel_t log_level = jsLogLevelStringToCLogLevel(log_level_str);
64
+
65
+ std::string message_str = jsTypedArrayToCString(runtime, arguments[1]);
66
+ const char *message = message_str.c_str();
67
+
68
+ ::ditto_log(log_level, message);
69
+ return Value();
70
+ });
71
+ }
156
72
 
157
- Function ditto_logger_enabled_get(Runtime &runtime)
158
- {
159
- return Function::createFromHostFunction(runtime,
160
- PropNameID::forAscii(runtime,
161
- STRINGIFIED_FUNC_NAME()),
162
- 0,
163
- [](Runtime &runtime,
164
- const Value &thisValue,
165
- const Value *arguments,
166
- size_t count) -> Value
167
- {
168
- return ::ditto_logger_enabled_get();
169
- });
170
- }
73
+ Function ditto_logger_minimum_log_level_get(Runtime &runtime)
74
+ {
75
+ return Function::createFromHostFunction(runtime,
76
+ PropNameID::forAscii(runtime,
77
+ STRINGIFIED_FUNC_NAME()),
78
+ 0,
79
+ [](Runtime &runtime,
80
+ const Value &thisValue,
81
+ const Value *arguments,
82
+ size_t count) -> Value
83
+ {
84
+ CLogLevel_t res = ::ditto_logger_minimum_log_level_get();
85
+ std::string log_level = cLogLevelToJSLogLevelString(res);
86
+ return String::createFromUtf8(runtime, log_level);
87
+ });
88
+ }
171
89
 
172
- Function ditto_logger_enabled(Runtime &runtime)
173
- {
174
- return Function::createFromHostFunction(runtime,
175
- PropNameID::forAscii(runtime,
176
- STRINGIFIED_FUNC_NAME()),
177
- 0,
178
- [](Runtime &runtime,
179
- const Value &thisValue,
180
- const Value *arguments,
181
- size_t count) -> Value
182
- {
183
- ::ditto_logger_enabled(arguments[0].asBool());
184
- return Value();
185
- });
186
- }
90
+ Function ditto_logger_minimum_log_level(Runtime &runtime)
91
+ {
92
+ return Function::createFromHostFunction(runtime,
93
+ PropNameID::forAscii(runtime,
94
+ STRINGIFIED_FUNC_NAME()),
95
+ 0,
96
+ [](Runtime &runtime,
97
+ const Value &thisValue,
98
+ const Value *arguments,
99
+ size_t count) -> Value
100
+ {
101
+ std::string log_level_str = arguments[0].toString(runtime).utf8(runtime);
102
+ CLogLevel_t log_level = jsLogLevelStringToCLogLevel(log_level_str);
103
+
104
+ ::ditto_logger_minimum_log_level(log_level);
105
+ return Value();
106
+ });
107
+ }
187
108
 
188
- std::function<void(CLogLevel_t, const char *)> global_js_callback;
109
+ Function ditto_logger_set_log_file(Runtime &runtime)
110
+ {
111
+ return Function::createFromHostFunction(runtime,
112
+ PropNameID::forAscii(runtime,
113
+ STRINGIFIED_FUNC_NAME()),
114
+ 0,
115
+ [](Runtime &runtime,
116
+ const Value &thisValue,
117
+ const Value *arguments,
118
+ size_t count) -> Value
119
+ {
120
+ ::ditto_logger_set_log_file(arguments[0].toString(runtime).utf8(runtime).c_str());
121
+ return Value();
122
+ });
123
+ }
189
124
 
190
- extern "C"
125
+ Function ditto_logger_emoji_headings_enabled(Runtime &runtime)
126
+ {
127
+ return Function::createFromHostFunction(runtime,
128
+ PropNameID::forAscii(runtime,
129
+ STRINGIFIED_FUNC_NAME()),
130
+ 0,
131
+ [](Runtime &runtime,
132
+ const Value &thisValue,
133
+ const Value *arguments,
134
+ size_t count) -> Value
135
+ {
136
+ ::ditto_logger_emoji_headings_enabled(arguments[0].asBool());
137
+ return Value();
138
+ });
139
+ }
140
+
141
+ Function ditto_logger_emoji_headings_enabled_get(Runtime &runtime)
142
+ {
143
+ return Function::createFromHostFunction(runtime,
144
+ PropNameID::forAscii(runtime,
145
+ STRINGIFIED_FUNC_NAME()),
146
+ 0,
147
+ [](Runtime &runtime,
148
+ const Value &thisValue,
149
+ const Value *arguments,
150
+ size_t count) -> Value
151
+ {
152
+ return ::ditto_logger_emoji_headings_enabled_get();
153
+ });
154
+ }
155
+
156
+ Function ditto_logger_enabled_get(Runtime &runtime)
157
+ {
158
+ return Function::createFromHostFunction(runtime,
159
+ PropNameID::forAscii(runtime,
160
+ STRINGIFIED_FUNC_NAME()),
161
+ 0,
162
+ [](Runtime &runtime,
163
+ const Value &thisValue,
164
+ const Value *arguments,
165
+ size_t count) -> Value
166
+ {
167
+ return ::ditto_logger_enabled_get();
168
+ });
169
+ }
170
+
171
+ Function ditto_logger_enabled(Runtime &runtime)
172
+ {
173
+ return Function::createFromHostFunction(runtime,
174
+ PropNameID::forAscii(runtime,
175
+ STRINGIFIED_FUNC_NAME()),
176
+ 0,
177
+ [](Runtime &runtime,
178
+ const Value &thisValue,
179
+ const Value *arguments,
180
+ size_t count) -> Value
181
+ {
182
+ ::ditto_logger_enabled(arguments[0].asBool());
183
+ return Value();
184
+ });
185
+ }
186
+
187
+ std::function<void(CLogLevel_t, const char *)> global_js_callback;
188
+
189
+ extern "C"
190
+ {
191
+ void custom_log_callback(CLogLevel_t log_level, const char *message)
192
+ {
193
+ if (global_js_callback)
191
194
  {
192
- void custom_log_callback(CLogLevel_t log_level, const char *message)
193
- {
194
- if (global_js_callback)
195
- {
196
- global_js_callback(log_level, message);
197
- }
198
- }
195
+ global_js_callback(log_level, message);
199
196
  }
200
197
  }
198
+ }
199
+ }
@@ -47,7 +47,7 @@ Function ditto_error_message(Runtime &runtime) {
47
47
  size_t count) -> Value
48
48
  {
49
49
  char *str = ::ditto_error_message();
50
- return String::createFromUtf8(runtime, str ? str : "");
50
+ return cPointerToJSPointerObject<char>(runtime, str);
51
51
  });
52
52
  }
53
53
 
@@ -95,7 +95,7 @@ Function dittoffi_error_description(Runtime &runtime) {
95
95
  size_t count) -> Value
96
96
  {
97
97
  char *res = ::dittoffi_error_description(jsPointerObjectToCPointer<dittoffi_error_t>(runtime, arguments[0]));
98
- return String::createFromUtf8(runtime, res);
98
+ return cPointerToJSPointerObject<char>(runtime, res);
99
99
  });
100
100
  }
101
101
 
@@ -264,7 +264,7 @@ Function ditto_set_sync_group(Runtime &runtime) {
264
264
  });
265
265
  }
266
266
 
267
- Function refCStringToString(Runtime &runtime)
267
+ Function ditto_disable_sync_with_v3(Runtime &runtime)
268
268
  {
269
269
  return Function::createFromHostFunction(runtime,
270
270
  PropNameID::forAscii(runtime,
@@ -275,9 +275,57 @@ Function refCStringToString(Runtime &runtime)
275
275
  const Value *arguments,
276
276
  size_t count) -> Value
277
277
  {
278
- return String::createFromUtf8(runtime, jsPointerObjectToCPointer<char>(runtime, arguments[0]));
278
+ CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
279
+ return ::ditto_disable_sync_with_v3(ditto);
279
280
  });
280
281
  }
281
282
 
282
283
 
284
+ Function dittoffi_base64_encode(Runtime &runtime)
285
+ {
286
+ return Function::createFromHostFunction(runtime,
287
+ PropNameID::forAscii(runtime,
288
+ STRINGIFIED_FUNC_NAME()),
289
+ 0,
290
+ [](Runtime &runtime,
291
+ const Value &thisValue,
292
+ const Value *arguments,
293
+ size_t count) -> Value
294
+ {
295
+ std::vector<uint8_t> bytes_vec = jsTypedArrayToCVector(runtime, arguments[0]);
296
+ slice_ref_uint8_t bytes = borrowVecAsRefSlice(bytes_vec);
297
+
298
+ std::string padding_mode_str = arguments[1].toString(runtime).utf8(runtime);
299
+ Base64PaddingMode_t padding_mode = padding_mode_str == "Padded" ? BASE64_PADDING_MODE_PADDED : BASE64_PADDING_MODE_UNPADDED;
300
+
301
+ char *res = ::dittoffi_base64_encode(bytes, padding_mode);
302
+ return cPointerToJSPointerObject<char>(runtime, res);
303
+ });
304
+ }
305
+
306
+ Function dittoffi_try_base64_decode(Runtime &runtime)
307
+ {
308
+ return Function::createFromHostFunction(runtime,
309
+ PropNameID::forAscii(runtime,
310
+ STRINGIFIED_FUNC_NAME()),
311
+ 0,
312
+ [](Runtime &runtime,
313
+ const Value &thisValue,
314
+ const Value *arguments,
315
+ size_t count) -> Value
316
+ {
317
+ std::string base64_str = jsTypedArrayToCString(runtime, arguments[0]);
318
+ const char *base64 = base64_str.c_str();
319
+
320
+ std::string padding_mode_str = arguments[1].toString(runtime).utf8(runtime);
321
+ Base64PaddingMode_t padding_mode = padding_mode_str == "Padded" ? BASE64_PADDING_MODE_PADDED : BASE64_PADDING_MODE_UNPADDED;
322
+
323
+ dittoffi_result_slice_boxed_uint8_t res = ::dittoffi_try_base64_decode(base64, padding_mode);
324
+
325
+ Object obj(runtime);
326
+ obj.setProperty(runtime, "success", cSlicedBoxToJSSlicedBox(runtime, res.success));
327
+ obj.setProperty(runtime, "error", cPointerToJSPointerObject(runtime, res.error));
328
+ return obj;
329
+ });
330
+ }
283
331
  }
@@ -32,7 +32,7 @@ Function ditto_presence_v3(Runtime &runtime)
32
32
  size_t count) -> Value
33
33
  {
34
34
  char *res = ::ditto_presence_v3(jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]));
35
- return String::createFromUtf8(runtime, res);
35
+ return cPointerToJSPointerObject<char>(runtime, res);
36
36
  });
37
37
  }
38
38
 
@@ -117,7 +117,7 @@ Function ditto_small_peer_info_get_metadata(Runtime &runtime) {
117
117
  size_t count) -> Value
118
118
  {
119
119
  char *metadata = ::ditto_small_peer_info_get_metadata(jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]));
120
- return String::createFromUtf8(runtime, metadata);
120
+ return cPointerToJSPointerObject<char>(runtime, metadata);
121
121
  });
122
122
 
123
123
  }
@@ -52,17 +52,22 @@ Function ditto_sdk_transports_error_value(Runtime &runtime)
52
52
  DittoSdkTransportsError_t *outError = jsPointerObjectToCPointer<DittoSdkTransportsError_t>(runtime, arguments[0]);
53
53
  DittoSdkTransportsError_t error = ::ditto_sdk_transports_error_value(outError);
54
54
 
55
- switch (error)
56
- {
55
+ std::string error_string;
56
+ switch (error) {
57
57
  case DITTO_SDK_TRANSPORTS_ERROR_NONE:
58
- return String::createFromUtf8(runtime, "None");
58
+ error_string = "None";
59
+ break;
59
60
  case DITTO_SDK_TRANSPORTS_ERROR_GENERIC:
60
- return String::createFromUtf8(runtime, "Generic");
61
+ error_string = "Generic";
62
+ break;
61
63
  case DITTO_SDK_TRANSPORTS_ERROR_UNAVAILABLE:
62
- return String::createFromUtf8(runtime, "Unavailable");
64
+ error_string = "Unavailable";
65
+ break;
63
66
  default:
64
67
  throw "Unimplemented error value";
65
68
  }
69
+ return String::createFromUtf8(runtime, error_string);
70
+
66
71
  });
67
72
  }
68
73