@dittolive/ditto 4.5.1-experimental.aarch64-linux.1.aarch64 → 4.5.2-rc.2

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 (152) hide show
  1. package/DittoReactNative.podspec +25 -0
  2. package/README.md +2 -2
  3. package/node/ditto.cjs.js +1 -1
  4. package/node/ditto.cjs.js.map +1 -0
  5. package/node/ditto.cjs.pretty.js +9655 -0
  6. package/node/ditto.cjs.pretty.js.map +1 -0
  7. package/node/ditto.darwin-arm64.node +0 -0
  8. package/node/ditto.darwin-x64.node +0 -0
  9. package/node/{ditto.linux-arm64.node → ditto.linux-x64.node} +0 -0
  10. package/node/transports.darwin-arm64.node +0 -0
  11. package/node/transports.darwin-x64.node +0 -0
  12. package/package.json +2 -1
  13. package/react-native/android/CMakeLists.txt +37 -0
  14. package/react-native/android/build.gradle +186 -0
  15. package/react-native/android/cpp-adapter.cpp +254 -0
  16. package/react-native/android/gradle.properties +5 -0
  17. package/react-native/android/src/main/AndroidManifest.xml +4 -0
  18. package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKModule.java +85 -0
  19. package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKPackage.java +28 -0
  20. package/react-native/cpp/include/Arc.hpp +141 -0
  21. package/react-native/cpp/include/Attachment.h +16 -0
  22. package/react-native/cpp/include/Authentication.h +23 -0
  23. package/react-native/cpp/include/Collection.h +13 -0
  24. package/react-native/cpp/include/DQL.h +21 -0
  25. package/react-native/cpp/include/Document.h +17 -0
  26. package/react-native/cpp/include/Identity.h +17 -0
  27. package/react-native/cpp/include/Lifecycle.h +17 -0
  28. package/react-native/cpp/include/LiveQuery.h +17 -0
  29. package/react-native/cpp/include/Logger.h +22 -0
  30. package/react-native/cpp/include/Misc.h +27 -0
  31. package/react-native/cpp/include/Presence.h +14 -0
  32. package/react-native/cpp/include/SmallPeerInfo.h +19 -0
  33. package/react-native/cpp/include/Transports.h +25 -0
  34. package/react-native/cpp/include/TypedArray.hpp +167 -0
  35. package/react-native/cpp/include/Utils.h +61 -0
  36. package/react-native/cpp/include/main.h +10 -0
  37. package/react-native/cpp/src/Attachment.cpp +86 -0
  38. package/react-native/cpp/src/Authentication.cpp +227 -0
  39. package/react-native/cpp/src/Collection.cpp +54 -0
  40. package/react-native/cpp/src/DQL.cpp +256 -0
  41. package/react-native/cpp/src/Document.cpp +146 -0
  42. package/react-native/cpp/src/Identity.cpp +123 -0
  43. package/react-native/cpp/src/Lifecycle.cpp +110 -0
  44. package/react-native/cpp/src/LiveQuery.cpp +63 -0
  45. package/react-native/cpp/src/Logger.cpp +200 -0
  46. package/react-native/cpp/src/Misc.cpp +283 -0
  47. package/react-native/cpp/src/Presence.cpp +79 -0
  48. package/react-native/cpp/src/SmallPeerInfo.cpp +142 -0
  49. package/react-native/cpp/src/Transports.cpp +270 -0
  50. package/react-native/cpp/src/TypedArray.cpp +303 -0
  51. package/react-native/cpp/src/Utils.cpp +138 -0
  52. package/react-native/cpp/src/main.cpp +152 -0
  53. package/react-native/dittoffi/dittoffi.h +4700 -0
  54. package/react-native/dittoffi/ifaddrs.cpp +385 -0
  55. package/react-native/dittoffi/ifaddrs.h +206 -0
  56. package/react-native/ios/DittoRNSDK.h +7 -0
  57. package/react-native/ios/DittoRNSDK.mm +107 -0
  58. package/react-native/ios/YeetJSIUtils.h +60 -0
  59. package/react-native/ios/YeetJSIUtils.mm +196 -0
  60. package/react-native/lib/commonjs/ditto.rn.js +92 -0
  61. package/react-native/lib/commonjs/ditto.rn.js.map +1 -0
  62. package/react-native/lib/commonjs/index.js +61 -0
  63. package/react-native/lib/commonjs/index.js.map +1 -0
  64. package/react-native/lib/module/ditto.rn.js +88 -0
  65. package/react-native/lib/module/ditto.rn.js.map +1 -0
  66. package/react-native/lib/module/index.js +27 -0
  67. package/react-native/lib/module/index.js.map +1 -0
  68. package/react-native/lib/typescript/ditto.rn.d.ts +15 -0
  69. package/react-native/lib/typescript/ditto.rn.d.ts.map +1 -0
  70. package/react-native/lib/typescript/index.d.ts +1 -0
  71. package/react-native/lib/typescript/index.d.ts.map +1 -0
  72. package/react-native/src/ditto.rn.ts +91 -0
  73. package/react-native/src/environment/environment.fallback.ts +4 -0
  74. package/react-native/src/index.ts +26 -0
  75. package/react-native/src/sources/@cbor-redux.ts +2 -0
  76. package/react-native/src/sources/@ditto.core.ts +1 -0
  77. package/react-native/src/sources/@environment.ts +1 -0
  78. package/react-native/src/sources/attachment-fetch-event.ts +54 -0
  79. package/react-native/src/sources/attachment-fetcher-manager.ts +144 -0
  80. package/react-native/src/sources/attachment-fetcher.ts +134 -0
  81. package/react-native/src/sources/attachment-token.ts +48 -0
  82. package/react-native/src/sources/attachment.ts +74 -0
  83. package/react-native/src/sources/augment.ts +101 -0
  84. package/react-native/src/sources/authenticator.ts +314 -0
  85. package/react-native/src/sources/base-pending-cursor-operation.ts +239 -0
  86. package/react-native/src/sources/base-pending-id-specific-operation.ts +109 -0
  87. package/react-native/src/sources/bridge.ts +553 -0
  88. package/react-native/src/sources/build-time-constants.ts +8 -0
  89. package/react-native/src/sources/cbor.ts +35 -0
  90. package/react-native/src/sources/collection-interface.ts +67 -0
  91. package/react-native/src/sources/collection.ts +212 -0
  92. package/react-native/src/sources/collections-event.ts +99 -0
  93. package/react-native/src/sources/counter.ts +82 -0
  94. package/react-native/src/sources/ditto.ts +979 -0
  95. package/react-native/src/sources/document-id.ts +159 -0
  96. package/react-native/src/sources/document-path.ts +306 -0
  97. package/react-native/src/sources/document.ts +193 -0
  98. package/react-native/src/sources/epilogue.ts +30 -0
  99. package/react-native/src/sources/error-codes.ts +52 -0
  100. package/react-native/src/sources/error.ts +208 -0
  101. package/react-native/src/sources/essentials.ts +53 -0
  102. package/react-native/src/sources/ffi-error.ts +122 -0
  103. package/react-native/src/sources/ffi.ts +2012 -0
  104. package/react-native/src/sources/identity.ts +163 -0
  105. package/react-native/src/sources/init.ts +71 -0
  106. package/react-native/src/sources/internal.ts +109 -0
  107. package/react-native/src/sources/keep-alive.ts +73 -0
  108. package/react-native/src/sources/key-path.ts +198 -0
  109. package/react-native/src/sources/live-query-event.ts +208 -0
  110. package/react-native/src/sources/live-query-manager.ts +102 -0
  111. package/react-native/src/sources/live-query.ts +166 -0
  112. package/react-native/src/sources/logger.ts +196 -0
  113. package/react-native/src/sources/main.ts +60 -0
  114. package/react-native/src/sources/observer-manager.ts +178 -0
  115. package/react-native/src/sources/observer.ts +79 -0
  116. package/react-native/src/sources/pending-collections-operation.ts +232 -0
  117. package/react-native/src/sources/pending-cursor-operation.ts +218 -0
  118. package/react-native/src/sources/pending-id-specific-operation.ts +218 -0
  119. package/react-native/src/sources/presence-manager.ts +161 -0
  120. package/react-native/src/sources/presence.ts +233 -0
  121. package/react-native/src/sources/query-result-item.ts +116 -0
  122. package/react-native/src/sources/query-result.ts +55 -0
  123. package/react-native/src/sources/register.ts +95 -0
  124. package/react-native/src/sources/small-peer-info.ts +177 -0
  125. package/react-native/src/sources/static-tcp-client.ts +6 -0
  126. package/react-native/src/sources/store-observer.ts +177 -0
  127. package/react-native/src/sources/store.ts +385 -0
  128. package/react-native/src/sources/subscription-manager.ts +99 -0
  129. package/react-native/src/sources/subscription.ts +89 -0
  130. package/react-native/src/sources/sync-subscription.ts +90 -0
  131. package/react-native/src/sources/sync.ts +559 -0
  132. package/react-native/src/sources/test-helpers.ts +24 -0
  133. package/react-native/src/sources/transport-conditions-manager.ts +104 -0
  134. package/react-native/src/sources/transport-config.ts +430 -0
  135. package/react-native/src/sources/update-result.ts +66 -0
  136. package/react-native/src/sources/update-results-map.ts +57 -0
  137. package/react-native/src/sources/websocket-client.ts +7 -0
  138. package/react-native/src/sources/write-transaction-collection.ts +122 -0
  139. package/react-native/src/sources/write-transaction-pending-cursor-operation.ts +101 -0
  140. package/react-native/src/sources/write-transaction-pending-id-specific-operation.ts +74 -0
  141. package/react-native/src/sources/write-transaction.ts +121 -0
  142. package/react-native.config.js +9 -0
  143. package/types/ditto.d.ts.map +1 -0
  144. package/web/ditto.es6.js +1 -1
  145. package/web/ditto.es6.js.map +1 -0
  146. package/web/ditto.es6.pretty.js +12600 -0
  147. package/web/ditto.es6.pretty.js.map +1 -0
  148. package/web/ditto.umd.js +1 -1
  149. package/web/ditto.umd.js.map +1 -0
  150. package/web/ditto.umd.pretty.js +12669 -0
  151. package/web/ditto.umd.pretty.js.map +1 -0
  152. package/web/ditto.wasm +0 -0
@@ -0,0 +1,141 @@
1
+ #ifndef _ARC_
2
+ #define _ARC_
3
+
4
+ #include <atomic>
5
+ #include <cassert>
6
+ #include <utility>
7
+
8
+ namespace sharedjsi {
9
+
10
+ template <typename T> struct ArcPointee {
11
+ T value;
12
+ mutable std::atomic<size_t> strong_count;
13
+
14
+ ArcPointee(T &&value, size_t strong_count)
15
+ : value /* = */ (std::move(value)), strong_count /* = */ (strong_count) {}
16
+ };
17
+
18
+ template <typename T> class Arc {
19
+ public:
20
+ // Post-condition: refcount = 1.
21
+ Arc(T value) noexcept
22
+ : ptr /* = */ (new ArcPointee<T>(std::move(value), 1)) {}
23
+
24
+ // Post-condition: refcount ±= 0; schedules dtor glue to `-= 1`.
25
+ // There has to be a 1-to-1 relation between `into_raw()` and `from_raw()`.
26
+ static Arc<T> from_raw(void *ptr) noexcept {
27
+ return Arc(static_cast<ArcPointee<T> *>(ptr));
28
+ }
29
+
30
+ // The equivalent of boost's `detach()`.
31
+ // Post-condition: refcount ±= 0; disables the `-= 1` eventual dtor glue.
32
+ // There has to be a 1-to-1 relation between `into_raw()` and `from_raw()`.
33
+ static void *into_raw(ArcPointee<T> &&self) noexcept {
34
+ auto ptr = self.ptr;
35
+ self.ptr = nullptr;
36
+ return static_cast<void *>(ptr);
37
+ }
38
+
39
+ // The equivalent of boost's `get()`.
40
+ // Post-condition: refcount ±= 0; dtor untouched.
41
+ static void *as_raw(Arc<T> const &arc) noexcept { return arc.ptr; }
42
+
43
+ // Borrow a `void *` as a `Arc<T>`, *temporarily*.
44
+ // (i.e., without touching the refcount nor setting up any ownership).
45
+ // - You could then use the copy (clone) ctor to get back an owned `Arc<T>`,
46
+ // via the retain therein.
47
+ // Post-condition: refcount ±= 0; dtor not enabled.
48
+ static Arc<T> &borrow_from_raw(void *&ptr) noexcept {
49
+ return *reinterpret_cast<Arc<T> *>(&ptr);
50
+ }
51
+
52
+ // Copy (clone) constructor
53
+ // Post-condition: refcount += 1; schedules new `-= 1` dtor glue.
54
+ Arc(Arc<T> const &other) noexcept : ptr /* = */ (other.ptr) {
55
+ ++(ptr->strong_count);
56
+ }
57
+
58
+ // Destructor / dtor.
59
+ // Post-condition: refcount = -1.
60
+ ~Arc() {
61
+ if (ptr != nullptr) { // <- if not moved from.
62
+ size_t count = --(ptr->strong_count);
63
+ if (count == 0) {
64
+ delete ptr;
65
+ }
66
+ }
67
+ }
68
+
69
+ // Move constructor
70
+ // Post-condition: refcount ±= 0 (and `rhs.ptr == nullptr`); moves dtor glue
71
+ // from `rhs` to `this`.
72
+ Arc(Arc<T> &&rhs) noexcept : ptr /* = */ (rhs.ptr) { rhs.ptr = nullptr; }
73
+
74
+ // Using `swap()`, we can use temporaries to derive the tricky assignments
75
+ // semantics off the above constructor & destructor operations, thanks to the
76
+ // C++ RAII semantics of the temporary. Post-condition: refcount ±= 0.
77
+ void swap(Arc<T> &rhs) noexcept {
78
+ ArcPointee<T> *rhs_ptr = rhs.ptr;
79
+ rhs.ptr = this->ptr;
80
+ this->ptr = rhs_ptr;
81
+ }
82
+
83
+ // Copy (clone) assignment.
84
+ // Post-condition: rhs refcount += 1; orig `*this` destroyed; schedules new
85
+ // `-= 1` dtor glue.
86
+ Arc<T> &operator=(Arc<T> const &rhs) noexcept {
87
+ {
88
+ Arc temporary{rhs}; // copy ctor: +1 of rhs
89
+ temporary.swap(*this);
90
+ } // dtor: -1 on what used to be `*this`.
91
+ return *this;
92
+ }
93
+
94
+ // Move assignment
95
+ // Post-condition: rhs refcount ±= 0; `rhs.ptr == nullptr`; orig `*this`
96
+ // destroyed. Moved dtor.
97
+ Arc<T> &operator=(Arc<T> &&rhs) noexcept {
98
+ {
99
+ Arc<T> temporary{
100
+ std::move(rhs)}; // move ctor: +0 of rhs; `rhs` is now `nullptr`.
101
+ temporary.swap(*this);
102
+ } // dtor: -1 on what used to be `*this`.
103
+ return *this;
104
+ }
105
+
106
+ // Deref
107
+ // Post-condition: rhs refcount ±= 0; dtor untouched.
108
+ T &operator*() const noexcept {
109
+ assert(ptr != nullptr);
110
+ return ptr->value;
111
+ }
112
+
113
+ // Post-condition: rhs refcount ±= 0; dtor untouched.
114
+ T *operator->() const noexcept {
115
+ assert(ptr != nullptr);
116
+ return &ptr->value;
117
+ }
118
+
119
+ private:
120
+ ArcPointee<T> *ptr;
121
+
122
+ // from raw
123
+ Arc<T>(ArcPointee<T> *ptr) : ptr(ptr) {}
124
+ };
125
+
126
+ #define DEFINE_RETAIN_RELEASE_FOR(T, retain, release) \
127
+ extern "C" { \
128
+ /* Post-condition: refcount += 1; dtor untouched. */ \
129
+ static void retain(void *ptr) { \
130
+ ++(static_cast<ArcPointee<T> *>(ptr)->strong_count); \
131
+ } \
132
+ \
133
+ /* Post-condition: refcount -= 1; dtor untouched. */ \
134
+ static void release(void *ptr) { Arc<T>::from_raw(ptr); } \
135
+ } \
136
+ static_assert(true, \
137
+ "") // <- to require a semi-colon when the macro is invoked.
138
+
139
+ } // namespace sharedjsi
140
+
141
+ #endif // _ARC_
@@ -0,0 +1,16 @@
1
+ #ifndef Attachment_H
2
+ #define Attachment_H
3
+
4
+ #include <jsi/jsi.h>
5
+
6
+ using namespace facebook::jsi;
7
+
8
+ namespace sharedjsi
9
+ {
10
+ Function ditto_cancel_resolve_attachment(Runtime &runtime);
11
+ Function ditto_free_attachment_handle(Runtime &runtime);
12
+ Function ditto_get_complete_attachment_path(Runtime &runtime);
13
+ Function ditto_new_attachment_from_bytes(Runtime &runtime);
14
+ }
15
+
16
+ #endif /* Attachment_H */
@@ -0,0 +1,23 @@
1
+ #ifndef Authentication_H
2
+ #define Authentication_H
3
+
4
+ #include <jsi/jsi.h>
5
+
6
+ using namespace facebook::jsi;
7
+
8
+ namespace sharedjsi
9
+ {
10
+ Function ditto_auth_client_set_validity_listener(Runtime &runtime);
11
+ Function ditto_auth_client_is_web_valid(Runtime &runtime);
12
+ Function ditto_auth_client_is_x509_valid(Runtime &runtime);
13
+ Function ditto_auth_client_get_app_id(Runtime &runtime);
14
+ Function ditto_auth_client_get_site_id(Runtime &runtime);
15
+ Function ditto_auth_client_make_login_provider(Runtime &runtime);
16
+ Function ditto_auth_set_login_provider(Runtime &runtime);
17
+ Function ditto_auth_client_login_with_token(Runtime &runtime);
18
+ Function ditto_auth_client_login_with_credentials(Runtime &runtime);
19
+ Function ditto_auth_client_logout(Runtime &runtime);
20
+ Function ditto_auth_client_user_id(Runtime &runtime);
21
+ }
22
+
23
+ #endif /* Authentication_H */
@@ -0,0 +1,13 @@
1
+ #ifndef Collection_H
2
+ #define Collection_H
3
+
4
+ #include <jsi/jsi.h>
5
+
6
+ using namespace facebook::jsi;
7
+
8
+ namespace sharedjsi
9
+ {
10
+ Function ditto_collection_insert_value(Runtime &runtime);
11
+ }
12
+
13
+ #endif /* Collection_H */
@@ -0,0 +1,21 @@
1
+ #ifndef DQL_H
2
+ #define DQL_H
3
+
4
+ #include <jsi/jsi.h>
5
+
6
+ using namespace facebook::jsi;
7
+
8
+ namespace sharedjsi {
9
+ Function dittoffi_try_experimental_register_change_observer_str_detached(Runtime &runtime);
10
+ Function dittoffi_try_experimental_add_dql_subscription(Runtime &runtime);
11
+ Function dittoffi_try_experimental_remove_dql_subscription(Runtime &runtime);
12
+ Function dittoffi_try_experimental_exec_statement_str(Runtime &runtime);
13
+ Function ditto_dql_response_result_count(Runtime &runtime);
14
+ Function ditto_dql_response_result_at(Runtime &runtime);
15
+ Function ditto_dql_response_affected_document_id_count(Runtime &runtime);
16
+ Function ditto_dql_response_affected_document_id_at(Runtime &runtime);
17
+ Function ditto_result_cbor(Runtime &runtime);
18
+ Function ditto_result_json(Runtime &runtime);
19
+ }
20
+
21
+ #endif /* DQL_H */
@@ -0,0 +1,17 @@
1
+ #ifndef Document_H
2
+ #define Document_H
3
+
4
+ #include <jsi/jsi.h>
5
+
6
+ using namespace facebook::jsi;
7
+
8
+ namespace sharedjsi
9
+ {
10
+ Function ditto_document_id_query_compatible(Runtime &runtime);
11
+ Function ditto_document_id(Runtime &runtime);
12
+ Function ditto_document_free(Runtime &runtime);
13
+ Function ditto_document_get_cbor_with_path_type(Runtime &runtime);
14
+ Function ditto_validate_document_id(Runtime &runtime);
15
+ }
16
+
17
+ #endif /* Document_H */
@@ -0,0 +1,17 @@
1
+ #ifndef Identity_H
2
+ #define Identity_H
3
+
4
+ #include <jsi/jsi.h>
5
+
6
+ using namespace facebook::jsi;
7
+
8
+ namespace sharedjsi
9
+ {
10
+ Function ditto_identity_config_make_online_playground(Runtime &runtime);
11
+ Function ditto_identity_config_make_offline_playground(Runtime &runtime);
12
+ Function ditto_identity_config_make_manual_v0(Runtime &runtime);
13
+ Function ditto_identity_config_make_shared_key(Runtime &runtime);
14
+ Function ditto_identity_config_make_online_with_authentication(Runtime &runtime);
15
+ }
16
+
17
+ #endif /* Identity_H */
@@ -0,0 +1,17 @@
1
+ #ifndef Lifecycle_H
2
+ #define Lifecycle_H
3
+
4
+ #include <jsi/jsi.h>
5
+
6
+ using namespace facebook::jsi;
7
+
8
+ namespace sharedjsi
9
+ {
10
+ Function ditto_init_sdk_version(Runtime &runtime);
11
+ Function ditto_uninitialized_ditto_make(Runtime &runtime);
12
+ Function ditto_shutdown(Runtime &runtime);
13
+ Function ditto_free(Runtime &runtime);
14
+ Function ditto_make(Runtime &runtime);
15
+ }
16
+
17
+ #endif /* Document_H */
@@ -0,0 +1,17 @@
1
+ #ifndef LiveQuery_H
2
+ #define LiveQuery_H
3
+
4
+ #include <jsi/jsi.h>
5
+
6
+ using namespace facebook::jsi;
7
+
8
+ namespace sharedjsi
9
+ {
10
+ Function ditto_live_query_signal_available_next(Runtime &runtime);
11
+ Function ditto_live_query_start(Runtime &runtime);
12
+ Function ditto_live_query_stop(Runtime &runtime);
13
+ Function ditto_live_query_register_str_detached(Runtime &runtime);
14
+ void v_live_query_update(void *ctx, c_cb_params_t params);
15
+ }
16
+
17
+ #endif /* LiveQuery_H */
@@ -0,0 +1,22 @@
1
+
2
+
3
+ #ifndef Logger_H
4
+ #define Logger_H
5
+
6
+ #include <jsi/jsi.h>
7
+
8
+ using namespace facebook::jsi;
9
+
10
+ namespace sharedjsi
11
+ {
12
+ Function ditto_log(Runtime &runtime);
13
+ Function ditto_logger_set_log_file(Runtime &runtime);
14
+ Function ditto_logger_minimum_log_level_get(Runtime &runtime);
15
+ Function ditto_logger_minimum_log_level(Runtime &runtime);
16
+ Function ditto_logger_emoji_headings_enabled_get(Runtime &runtime);
17
+ Function ditto_logger_emoji_headings_enabled(Runtime &runtime);
18
+ Function ditto_logger_enabled_get(Runtime &runtime);
19
+ Function ditto_logger_enabled(Runtime &runtime);
20
+
21
+ }
22
+ #endif /* Logger_H */
@@ -0,0 +1,27 @@
1
+ #ifndef Misc_H
2
+ #define Misc_H
3
+
4
+ #include <jsi/jsi.h>
5
+
6
+ using namespace facebook::jsi;
7
+
8
+ namespace sharedjsi
9
+ {
10
+ Function ditto_tick(Runtime &runtime);
11
+ Function ditto_set_device_name(Runtime &runtime);
12
+ Function ditto_error_message(Runtime &runtime);
13
+ Function dittoffi_error_code(Runtime &runtime);
14
+ Function dittoffi_error_description(Runtime &runtime);
15
+ Function dittoffi_error_free(Runtime &runtime);
16
+ Function ditto_set_connect_retry_interval(Runtime &runtime);
17
+ Function ditto_get_sdk_version(Runtime &runtime);
18
+ Function dittoffi_get_sdk_semver(Runtime &runtime);
19
+ Function ditto_small_peer_info_set_transport_config_data(Runtime &runtime);
20
+ Function ditto_verify_license(Runtime &runtime);
21
+ Function ditto_run_garbage_collection(Runtime &runtime);
22
+ Function ditto_set_static_websocket_clients(Runtime &runtime);
23
+ Function ditto_set_sync_group(Runtime &runtime);
24
+ Function refCStringToString(Runtime &runtime);
25
+ }
26
+
27
+ #endif /* Misc_H */
@@ -0,0 +1,14 @@
1
+ #ifndef Presence_H
2
+ #define Presence_H
3
+
4
+ #include <jsi/jsi.h>
5
+
6
+ using namespace facebook::jsi;
7
+
8
+ namespace sharedjsi
9
+ {
10
+ Function ditto_presence_v3(Runtime &runtime);
11
+ Function ditto_register_presence_v3_callback(Runtime &runtime);
12
+ Function ditto_clear_presence_v3_callback(Runtime &runtime);
13
+ }
14
+ #endif /* Presence_H */
@@ -0,0 +1,19 @@
1
+ #ifndef SmallPeerInfo_H
2
+ #define SmallPeerInfo_H
3
+
4
+ #include <jsi/jsi.h>
5
+
6
+ using namespace facebook::jsi;
7
+
8
+ namespace sharedjsi
9
+ {
10
+ Function ditto_small_peer_info_set_transport_config_data(Runtime &runtime);
11
+ Function ditto_small_peer_info_get_is_enabled(Runtime &runtime);
12
+ Function ditto_small_peer_info_set_enabled(Runtime &runtime);
13
+ Function ditto_small_peer_info_get_sync_scope(Runtime &runtime);
14
+ Function ditto_small_peer_info_set_sync_scope(Runtime &runtime);
15
+ Function ditto_small_peer_info_get_metadata(Runtime &runtime);
16
+ Function ditto_small_peer_info_set_metadata(Runtime &runtime);
17
+ }
18
+
19
+ #endif /* SmallPeerInfo_H */
@@ -0,0 +1,25 @@
1
+ #ifndef Transports_h
2
+ #define Transports_h
3
+
4
+ #include <jsi/jsi.h>
5
+
6
+ using namespace facebook::jsi;
7
+
8
+ namespace sharedjsi {
9
+ Function ditto_sdk_transports_error_new(Runtime &runtime);
10
+ Function ditto_sdk_transports_init(Runtime &runtime);
11
+ Function ditto_sdk_transports_error_value(Runtime &runtime);
12
+ Function ditto_sdk_transports_error_free(Runtime &runtime);
13
+ Function ditto_sdk_transports_ble_is_available(Runtime &runtime);
14
+ Function ditto_sdk_transports_ble_create(Runtime &runtime);
15
+ Function ditto_sdk_transports_ble_destroy(Runtime &runtime);
16
+ Function ditto_sdk_transports_lan_is_available(Runtime &runtime);
17
+ Function ditto_sdk_transports_lan_create(Runtime &runtime);
18
+ Function ditto_sdk_transports_lan_destroy(Runtime &runtime);
19
+ Function ditto_sdk_transports_awdl_is_available(Runtime &runtime);
20
+ Function ditto_sdk_transports_awdl_create(Runtime &runtime);
21
+ Function ditto_sdk_transports_awdl_destroy(Runtime &runtime);
22
+ Function ditto_add_multicast_transport(Runtime &runtime);
23
+ Function ditto_remove_multicast_transport(Runtime &runtime);
24
+ }
25
+ #endif /* Transports_h */
@@ -0,0 +1,167 @@
1
+
2
+ #pragma once
3
+
4
+ #include <jsi/jsi.h>
5
+
6
+ namespace jsi = facebook::jsi;
7
+
8
+ enum class TypedArrayKind {
9
+ Int8Array,
10
+ Int16Array,
11
+ Int32Array,
12
+ Uint8Array,
13
+ Uint8ClampedArray,
14
+ Uint16Array,
15
+ Uint32Array,
16
+ Float32Array,
17
+ Float64Array,
18
+ };
19
+
20
+ template <TypedArrayKind T>
21
+ class TypedArray;
22
+
23
+ template <TypedArrayKind T>
24
+ struct typedArrayTypeMap;
25
+ template <>
26
+ struct typedArrayTypeMap<TypedArrayKind::Int8Array> {
27
+ typedef int8_t type;
28
+ };
29
+ template <>
30
+ struct typedArrayTypeMap<TypedArrayKind::Int16Array> {
31
+ typedef int16_t type;
32
+ };
33
+ template <>
34
+ struct typedArrayTypeMap<TypedArrayKind::Int32Array> {
35
+ typedef int32_t type;
36
+ };
37
+ template <>
38
+ struct typedArrayTypeMap<TypedArrayKind::Uint8Array> {
39
+ typedef uint8_t type;
40
+ };
41
+ template <>
42
+ struct typedArrayTypeMap<TypedArrayKind::Uint8ClampedArray> {
43
+ typedef uint8_t type;
44
+ };
45
+ template <>
46
+ struct typedArrayTypeMap<TypedArrayKind::Uint16Array> {
47
+ typedef uint16_t type;
48
+ };
49
+ template <>
50
+ struct typedArrayTypeMap<TypedArrayKind::Uint32Array> {
51
+ typedef uint32_t type;
52
+ };
53
+ template <>
54
+ struct typedArrayTypeMap<TypedArrayKind::Float32Array> {
55
+ typedef float type;
56
+ };
57
+ template <>
58
+ struct typedArrayTypeMap<TypedArrayKind::Float64Array> {
59
+ typedef double type;
60
+ };
61
+
62
+ // Instance of this class will invalidate PropNameIDCache when destructor is called.
63
+ // Attach this object to global in specific jsi::Runtime to make sure lifecycle of
64
+ // the cache object is connected to the lifecycle of the js runtime
65
+ class InvalidateCacheOnDestroy : public jsi::HostObject {
66
+ public:
67
+ InvalidateCacheOnDestroy(jsi::Runtime &runtime);
68
+ virtual ~InvalidateCacheOnDestroy();
69
+ virtual jsi::Value get(jsi::Runtime &, const jsi::PropNameID &name) {
70
+ return jsi::Value::null();
71
+ }
72
+ virtual void set(jsi::Runtime &, const jsi::PropNameID &name, const jsi::Value &value) {}
73
+ virtual std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) {
74
+ return {};
75
+ }
76
+
77
+ private:
78
+ uintptr_t key;
79
+ };
80
+
81
+ class TypedArrayBase : public jsi::Object {
82
+ public:
83
+ template <TypedArrayKind T>
84
+ using ContentType = typename typedArrayTypeMap<T>::type;
85
+
86
+ TypedArrayBase(jsi::Runtime &, size_t, TypedArrayKind);
87
+ TypedArrayBase(jsi::Runtime &, const jsi::Object &);
88
+ TypedArrayBase(TypedArrayBase &&) = default;
89
+ TypedArrayBase &operator=(TypedArrayBase &&) = default;
90
+
91
+ TypedArrayKind getKind(jsi::Runtime &runtime) const;
92
+
93
+ template <TypedArrayKind T>
94
+ TypedArray<T> get(jsi::Runtime &runtime) const &;
95
+ template <TypedArrayKind T>
96
+ TypedArray<T> get(jsi::Runtime &runtime) &&;
97
+ template <TypedArrayKind T>
98
+ TypedArray<T> as(jsi::Runtime &runtime) const &;
99
+ template <TypedArrayKind T>
100
+ TypedArray<T> as(jsi::Runtime &runtime) &&;
101
+
102
+ size_t size(jsi::Runtime &runtime) const;
103
+ size_t length(jsi::Runtime &runtime) const;
104
+ size_t byteLength(jsi::Runtime &runtime) const;
105
+ size_t byteOffset(jsi::Runtime &runtime) const;
106
+ bool hasBuffer(jsi::Runtime &runtime) const;
107
+
108
+ std::vector<uint8_t> toVector(jsi::Runtime &runtime);
109
+ jsi::ArrayBuffer getBuffer(jsi::Runtime &runtime) const;
110
+
111
+ private:
112
+ template <TypedArrayKind>
113
+ friend class TypedArray;
114
+ };
115
+
116
+ bool isTypedArray(jsi::Runtime &runtime, const jsi::Object &jsObj);
117
+ TypedArrayBase getTypedArray(jsi::Runtime &runtime, const jsi::Object &jsObj);
118
+
119
+ std::vector<uint8_t> arrayBufferToVector(jsi::Runtime &runtime, jsi::Object &jsObj);
120
+ void arrayBufferUpdate(
121
+ jsi::Runtime &runtime,
122
+ jsi::ArrayBuffer &buffer,
123
+ std::vector<uint8_t> data,
124
+ size_t offset);
125
+
126
+ template <TypedArrayKind T>
127
+ class TypedArray : public TypedArrayBase {
128
+ public:
129
+ TypedArray(jsi::Runtime &runtime, size_t size);
130
+ TypedArray(jsi::Runtime &runtime, std::vector<ContentType<T>> data);
131
+ TypedArray(TypedArrayBase &&base);
132
+ TypedArray(TypedArray &&) = default;
133
+ TypedArray &operator=(TypedArray &&) = default;
134
+
135
+ std::vector<ContentType<T>> toVector(jsi::Runtime &runtime);
136
+ void update(jsi::Runtime &runtime, const std::vector<ContentType<T>> &data);
137
+ };
138
+
139
+ template <TypedArrayKind T>
140
+ TypedArray<T> TypedArrayBase::get(jsi::Runtime &runtime) const & {
141
+ assert(getKind(runtime) == T);
142
+ (void)runtime; // when assert is disabled we need to mark this as used
143
+ return TypedArray<T>(jsi::Value(runtime, jsi::Value(runtime, *this).asObject(runtime)));
144
+ }
145
+
146
+ template <TypedArrayKind T>
147
+ TypedArray<T> TypedArrayBase::get(jsi::Runtime &runtime) && {
148
+ assert(getKind(runtime) == T);
149
+ (void)runtime; // when assert is disabled we need to mark this as used
150
+ return TypedArray<T>(std::move(*this));
151
+ }
152
+
153
+ template <TypedArrayKind T>
154
+ TypedArray<T> TypedArrayBase::as(jsi::Runtime &runtime) const & {
155
+ if (getKind(runtime) != T) {
156
+ throw jsi::JSError(runtime, "Object is not a TypedArray");
157
+ }
158
+ return get<T>(runtime);
159
+ }
160
+
161
+ template <TypedArrayKind T>
162
+ TypedArray<T> TypedArrayBase::as(jsi::Runtime &runtime) && {
163
+ if (getKind(runtime) != T) {
164
+ throw jsi::JSError(runtime, "Object is not a TypedArray");
165
+ }
166
+ return std::move(*this).get<T>(runtime);
167
+ }
@@ -0,0 +1,61 @@
1
+ #ifndef UTILS_H
2
+ #define UTILS_H
3
+
4
+ #include <vector>
5
+ #include <jsi/jsi.h>
6
+ #include "TypedArray.hpp"
7
+ #include <dittoffi.h>
8
+
9
+ #define STRINGIFY(it) #it
10
+
11
+ #define STRINGIFIED_FUNC_NAME() STRINGIFY(__function)
12
+ #define STRINGIFY_TYPE(T) #T
13
+
14
+ using namespace facebook::jsi;
15
+
16
+ namespace sharedjsi
17
+ {
18
+
19
+ std::string pointerToHexString(void const *ptr);
20
+
21
+ template <typename T>
22
+ Value cPointerToJSPointerObject(Runtime &runtime, const T *pointer) {
23
+ if (pointer == nullptr) {
24
+ return Value::null();
25
+ }
26
+
27
+ Object obj(runtime);
28
+ obj.setProperty(runtime, "type", STRINGIFY_TYPE(T));
29
+ obj.setProperty(runtime, "addr", pointerToHexString(pointer));
30
+ return obj;
31
+ }
32
+
33
+ template <typename T>
34
+ T *jsPointerObjectToCPointer(Runtime &runtime, const Value &arg)
35
+ {
36
+ if (arg.isNull() || arg.isUndefined()) {
37
+ return nullptr;
38
+ }
39
+ Object obj = arg.getObject(runtime);
40
+ std::string str = obj.getProperty(runtime, "addr").toString(runtime).utf8(runtime);
41
+ T *ptr;
42
+ sscanf(str.c_str(), "%p", &ptr);
43
+ return ptr;
44
+ }
45
+
46
+ std::vector<uint8_t> jsTypedArrayToCVector(Runtime &runtime, const Value &arg);
47
+ std::string jsTypedArrayToCString(Runtime &runtime, const Value &arg);
48
+
49
+ slice_ref_uint8_t borrowVecAsOptRefSlice(std::vector<uint8_t> const& v);
50
+ slice_ref_uint8_t borrowVecAsRefSlice(std::vector<uint8_t> const& v);
51
+
52
+ Value cSlicedBoxToJSSlicedBox(Runtime &runtime, slice_boxed_uint8 box_c_bytes);
53
+ Function sliceBoxedToUInt8Array(Runtime &runtime);
54
+
55
+ Function withOutBoxCBytes(Runtime &runtime);
56
+
57
+ void ditto_tick(Runtime* jsi);
58
+ void ditto_enqueue_call(std::function<void(Runtime *)> && task);
59
+ }
60
+
61
+ #endif /* UTILS_H */
@@ -0,0 +1,10 @@
1
+ #ifndef EXAMPLE_H
2
+ #define EXAMPLE_H
3
+
4
+ namespace sharedjsi
5
+ {
6
+ void install(facebook::jsi::Runtime &jsiRuntime);
7
+ }
8
+
9
+
10
+ #endif /* EXAMPLE_H */