@dittolive/ditto 4.10.2 → 4.11.0-preview.1

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 (44) hide show
  1. package/DittoReactNative.podspec +1 -17
  2. package/README.md +4 -80
  3. package/node/ditto.cjs.js +444 -81
  4. package/node/ditto.darwin-arm64.node +0 -0
  5. package/node/ditto.darwin-x64.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/package.json +1 -1
  10. package/react-native/android/build.gradle +29 -34
  11. package/react-native/android/cpp-adapter.cpp +10 -11
  12. package/react-native/android/dittoffi/src/ditto_transaction.cpp +1 -0
  13. package/react-native/android/dittoffi/src/ditto_transaction.h +91 -0
  14. package/react-native/android/dittoffi/src/dittoffi.h +587 -390
  15. package/react-native/android/dittoffi/src/dittoffi_java.cpp +3360 -1358
  16. package/react-native/android/dittoffi/src/dittoffi_java.h +59 -10
  17. package/react-native/android/dittoffi/src/dittoffi_java.i +2 -0
  18. package/react-native/android/dittoffi/src/dittostore_java.i +48 -0
  19. package/react-native/android/dittoffi/src/mesh_java_interfaces.h +81 -109
  20. package/react-native/android/gradle.properties +6 -5
  21. package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKModule.kt +23 -15
  22. package/react-native/cpp/include/DQL.h +1 -0
  23. package/react-native/cpp/include/Differ.h +14 -0
  24. package/react-native/cpp/include/Lifecycle.h +1 -1
  25. package/react-native/cpp/include/Transaction.h +18 -0
  26. package/react-native/cpp/include/Transports.h +1 -0
  27. package/react-native/cpp/include/Utils.h +27 -3
  28. package/react-native/cpp/include/main.h +2 -0
  29. package/react-native/cpp/src/DQL.cpp +21 -0
  30. package/react-native/cpp/src/Differ.cpp +57 -0
  31. package/react-native/cpp/src/Lifecycle.cpp +17 -7
  32. package/react-native/cpp/src/Misc.cpp +50 -32
  33. package/react-native/cpp/src/Transaction.cpp +195 -0
  34. package/react-native/cpp/src/Transports.cpp +77 -1
  35. package/react-native/cpp/src/Utils.cpp +11 -0
  36. package/react-native/cpp/src/main.cpp +18 -1
  37. package/react-native/ditto.es6.js +1 -1
  38. package/react-native/ios/DittoRNSDK.mm +2 -4
  39. package/types/ditto.d.ts +271 -33
  40. package/web/ditto.es6.js +1 -1
  41. package/web/ditto.umd.js +1 -1
  42. package/web/ditto.wasm +0 -0
  43. package/react-native/ios/YeetJSIUtils.h +0 -60
  44. package/react-native/ios/YeetJSIUtils.mm +0 -196
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dittolive/ditto",
3
- "version": "4.10.2",
3
+ "version": "4.11.0-preview.1",
4
4
  "description": "Ditto is a cross-platform SDK that allows apps to sync with and even without internet connectivity.",
5
5
  "homepage": "https://ditto.live",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
@@ -1,8 +1,9 @@
1
1
  import groovy.json.JsonSlurper
2
2
 
3
3
  buildscript {
4
- // Buildscript is evaluated before everything else so we can't use getExtOrDefault
5
- def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["rnsdk_kotlinVersion"]
4
+ ext.getExtOrDefault = {name ->
5
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["rnsdk_" + name]
6
+ }
6
7
 
7
8
  repositories {
8
9
  google()
@@ -10,9 +11,9 @@ buildscript {
10
11
  }
11
12
 
12
13
  dependencies {
13
- classpath "com.android.tools.build:gradle:7.2.1"
14
- // noinspection DifferentKotlinGradleVersion
15
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14
+ classpath "com.android.tools.build:gradle:8.7.2"
15
+ // noinspection DifferentKotlinGradleVersion
16
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
16
17
  }
17
18
  }
18
19
 
@@ -21,20 +22,9 @@ def reactNativeArchitectures() {
21
22
  return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
22
23
  }
23
24
 
24
- def isNewArchitectureEnabled() {
25
- return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
26
- }
27
-
28
25
  apply plugin: "com.android.library"
29
26
  apply plugin: "kotlin-android"
30
27
 
31
- if (isNewArchitectureEnabled()) {
32
- apply plugin: "com.facebook.react"
33
- }
34
-
35
- def getExtOrDefault(name) {
36
- return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["rnsdk_" + name]
37
- }
38
28
 
39
29
  def getExtOrIntegerDefault(name) {
40
30
  return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["rnsdk_" + name]).toInteger()
@@ -74,10 +64,18 @@ android {
74
64
 
75
65
  externalNativeBuild {
76
66
  cmake {
77
- cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all"
78
- // ESSENTIAL for adding JSI
67
+ cppFlags "-frtti -fexceptions -Wall -fstack-protector-all"
79
68
  arguments "-DANDROID_STL=c++_shared"
80
69
  abiFilters (*reactNativeArchitectures())
70
+
71
+ buildTypes {
72
+ debug {
73
+ cppFlags "-O1 -g"
74
+ }
75
+ release {
76
+ cppFlags "-O2"
77
+ }
78
+ }
81
79
  }
82
80
  }
83
81
  }
@@ -111,23 +109,8 @@ repositories {
111
109
 
112
110
  def kotlin_version = getExtOrDefault("kotlinVersion")
113
111
 
114
- def getVersionFromPackageJson() {
115
- def packageJsonPath = file('../../package.json')
116
- if (packageJsonPath.exists()) {
117
- def packageJson = new JsonSlurper().parse(packageJsonPath)
118
- return packageJson.version
119
- } else {
120
- throw new FileNotFoundException("package.json not found at: ${packageJsonPath}")
121
- }
122
- }
123
-
124
- project.version = getVersionFromPackageJson()
125
-
126
112
  dependencies {
127
- // For < 0.71, this will be from the local maven repo
128
- // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
129
- //noinspection GradleDynamicVersion
130
- implementation "com.facebook.react:react-native:+"
113
+ implementation "com.facebook.react:react-android"
131
114
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
132
115
 
133
116
  def aarFile = file('dittoffi/aar/ditto.aar')
@@ -141,6 +124,18 @@ dependencies {
141
124
  }
142
125
  }
143
126
 
127
+ def getVersionFromPackageJson() {
128
+ def packageJsonPath = file('../../package.json')
129
+ if (packageJsonPath.exists()) {
130
+ def packageJson = new JsonSlurper().parse(packageJsonPath)
131
+ return packageJson.version
132
+ } else {
133
+ throw new FileNotFoundException("package.json not found at: ${packageJsonPath}")
134
+ }
135
+ }
136
+
137
+ project.version = getVersionFromPackageJson()
138
+
144
139
  tasks.register('downloadBinaries') {
145
140
  doLast {
146
141
  def defaultArchitectures = ['arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64']
@@ -129,12 +129,11 @@ void install(Runtime &jsiRuntime) {
129
129
  std::move(ditto_sdk_transports_android_missing_permissions));
130
130
  }
131
131
 
132
-
133
- extern "C"
132
+ extern "C"
134
133
  JNIEXPORT void JNICALL
135
- Java_com_dittolive_rnsdk_DittoRNSDKModule_nativeInstall(JNIEnv *env, jobject thiz, jobject context, jobject callInvokerHolderObj,
136
- jlong jsi_ptr, jstring default_dir)
137
- {
134
+ Java_com_dittolive_rnsdk_DittoRNSDKModule_nativeInstall(JNIEnv *env, jobject thiz, jobject context,
135
+ jobject call_invoker, jlong jsi_ptr,
136
+ jstring default_dir) {
138
137
  // Save context, module, java_vm objects globally (thread-safe, as opposed to JNIEnv)
139
138
  java_context = env->NewGlobalRef(context);
140
139
  java_object = env->NewGlobalRef(thiz);
@@ -147,13 +146,13 @@ Java_com_dittolive_rnsdk_DittoRNSDKModule_nativeInstall(JNIEnv *env, jobject thi
147
146
  // in the video: https://youtu.be/oLmGInjKU2U?feature=shared&t=1220
148
147
  // The details on how to do this were not documented, though.
149
148
  // We have to figure a way to get the actual CallInvoker object using the fbjni library.
150
- //
151
- // jni::alias_ref<> is a wrapper provided by the React Native JNI layer.
152
- // It creates an “alias” reference type which helps in managing the
153
- // lifecycle of JNI references more safely. The alias_ref ensures that the
154
- // reference is valid within the current scope and automatically deletes
149
+ //
150
+ // jni::alias_ref<> is a wrapper provided by the React Native JNI layer.
151
+ // It creates an “alias” reference type which helps in managing the
152
+ // lifecycle of JNI references more safely. The alias_ref ensures that the
153
+ // reference is valid within the current scope and automatically deletes
155
154
  // the local reference when going out of scope to prevent memory leaks.
156
- auto callInvokerHolderObjRef = reinterpret_cast<react::CallInvokerHolder::javaobject>(callInvokerHolderObj);
155
+ auto callInvokerHolderObjRef = reinterpret_cast<react::CallInvokerHolder::javaobject>(call_invoker);
157
156
  auto jsCallInvokerHolder = jni::alias_ref<react::CallInvokerHolder::javaobject>(callInvokerHolderObjRef)->cthis();
158
157
  auto jsCallInvoker = jsCallInvokerHolder->getCallInvoker();
159
158
 
@@ -0,0 +1 @@
1
+ #include "ditto_transaction.h"
@@ -0,0 +1,91 @@
1
+ extern "C" {
2
+ #include "dittoffi.h"
3
+ }
4
+ #include "retainable.h"
5
+
6
+ #ifdef SWIG
7
+ %feature("director", assumeoverride=1) TransactionCompletionContinuation;
8
+ %feature("director", assumeoverride=1) TransactionExecuteContinuation;
9
+ %feature("director", assumeoverride=1) BeginTransactionContinuation;
10
+ #endif
11
+
12
+ /** \brief
13
+ * Context object for Kotlin DittoTransaction.InternalTransactionCompletionContinuation which handles wiring up the
14
+ * callback from Rust across the FFI boundary.
15
+ */
16
+ class TransactionCompletionContinuation : public Retainable {
17
+ public:
18
+ virtual ~TransactionCompletionContinuation() {}
19
+
20
+ // To be overridden by Kotlin/Java
21
+ virtual void invoke(dittoffi_result_dittoffi_transaction_completion_action_t result) = 0;
22
+
23
+ static void invokeContinuationCompletion(void *const context,
24
+ dittoffi_result_dittoffi_transaction_completion_action_t result) {
25
+ auto instance = static_cast<TransactionCompletionContinuation *>(context);
26
+ instance->invoke(result);
27
+ }
28
+
29
+ BoxDynFnMut1_void_dittoffi_result_dittoffi_transaction_completion_action_t intoFfi() {
30
+ this->java_retain();
31
+ BoxDynFnMut1_void_dittoffi_result_dittoffi_transaction_completion_action_t ffiCompletion = {};
32
+ ffiCompletion.env_ptr = this;
33
+ ffiCompletion.call = TransactionCompletionContinuation::invokeContinuationCompletion;
34
+ ffiCompletion.free = TransactionCompletionContinuation::invokeRelease;
35
+ return ffiCompletion;
36
+ }
37
+ };
38
+
39
+ /** \brief
40
+ * Context object for Kotlin DittoTransaction.InternalTransactionExecuteContinuation which handles wiring up the
41
+ * callback from Rust across the FFI boundary.
42
+ */
43
+ class TransactionExecuteContinuation : public Retainable {
44
+ public:
45
+ virtual ~TransactionExecuteContinuation() {}
46
+
47
+ // To be overridden by Kotlin/Java
48
+ virtual void invoke(dittoffi_result_dittoffi_query_result_ptr_t result) = 0;
49
+
50
+ static void invokeContinuationExecute(void *const context,
51
+ dittoffi_result_dittoffi_query_result_ptr_t result) {
52
+ auto instance = static_cast<TransactionExecuteContinuation *>(context);
53
+ instance->invoke(result);
54
+ }
55
+
56
+ BoxDynFnMut1_void_dittoffi_result_dittoffi_query_result_ptr_t intoFfi() {
57
+ this->java_retain();
58
+ BoxDynFnMut1_void_dittoffi_result_dittoffi_query_result_ptr_t ffiExecute = {};
59
+ ffiExecute.env_ptr = this;
60
+ ffiExecute.call = TransactionExecuteContinuation::invokeContinuationExecute;
61
+ ffiExecute.free = TransactionExecuteContinuation::invokeRelease;
62
+ return ffiExecute;
63
+ }
64
+ };
65
+
66
+ /** \brief
67
+ * Context object for Kotlin DittoStore.InternalDittoBeginTransactionContinuation which handles wiring up the
68
+ * callback from Rust across the FFI boundary.
69
+ */
70
+ class BeginTransactionContinuation : public Retainable {
71
+ public:
72
+ virtual ~BeginTransactionContinuation() {}
73
+
74
+ // To be overridden by Kotlin
75
+ virtual void invoke(dittoffi_result_dittoffi_transaction_ptr_t result) = 0;
76
+
77
+ static void invokeContinuation(void *const context,
78
+ dittoffi_result_dittoffi_transaction_ptr_t result) {
79
+ auto instance = static_cast<BeginTransactionContinuation *>(context);
80
+ instance->invoke(result);
81
+ }
82
+
83
+ BoxDynFnMut1_void_dittoffi_result_dittoffi_transaction_ptr_t intoFfi() {
84
+ this->java_retain();
85
+ BoxDynFnMut1_void_dittoffi_result_dittoffi_transaction_ptr_t ffiBeginTransaction = {};
86
+ ffiBeginTransaction.env_ptr = this;
87
+ ffiBeginTransaction.call = BeginTransactionContinuation::invokeContinuation;
88
+ ffiBeginTransaction.free = BeginTransactionContinuation::invokeRelease;
89
+ return ffiBeginTransaction;
90
+ }
91
+ };