@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,146 @@
1
+ #include "Utils.h"
2
+
3
+ #include <Document.h>
4
+ #include <dittoffi.h>
5
+ #include <unordered_map>
6
+
7
+ namespace sharedjsi
8
+ {
9
+
10
+ Function ditto_document_free(Runtime &runtime)
11
+ {
12
+ return Function::createFromHostFunction(runtime,
13
+ PropNameID::forAscii(runtime,
14
+ STRINGIFIED_FUNC_NAME()),
15
+ 0,
16
+ [](Runtime &runtime,
17
+ const Value &thisValue,
18
+ const Value *arguments,
19
+ size_t count) -> Value
20
+ {
21
+ CDocument_t *document = jsPointerObjectToCPointer<CDocument_t>(runtime, arguments[0]);
22
+ ::ditto_document_free(document);
23
+ return Value();
24
+ });
25
+ }
26
+
27
+ Function ditto_document_id(Runtime &runtime)
28
+ {
29
+ return Function::createFromHostFunction(runtime,
30
+ PropNameID::forAscii(runtime,
31
+ STRINGIFIED_FUNC_NAME()),
32
+ 0,
33
+ [](Runtime &runtime,
34
+ const Value &thisValue,
35
+ const Value *arguments,
36
+ size_t count) -> Value
37
+ {
38
+ CDocument_t const *document = jsPointerObjectToCPointer<CDocument>(runtime, arguments[0]);
39
+ slice_boxed_uint8_t res = ::ditto_document_id(document);
40
+ return cSlicedBoxToJSSlicedBox(runtime, res);
41
+ });
42
+ }
43
+
44
+ Function ditto_document_id_query_compatible(Runtime &runtime)
45
+ {
46
+ return Function::createFromHostFunction(runtime,
47
+ PropNameID::forAscii(runtime,
48
+ STRINGIFIED_FUNC_NAME()),
49
+ 0,
50
+ [](Runtime &runtime,
51
+ const Value &thisValue,
52
+ const Value *arguments,
53
+ size_t count) -> Value
54
+ {
55
+
56
+ std::vector<uint8_t> id_vec = jsTypedArrayToCVector(runtime, arguments[0]);
57
+ slice_ref_uint8_t id = borrowVecAsRefSlice(id_vec);
58
+
59
+ std::string stringPrimitiveStr = arguments[1].getString(runtime).utf8(runtime);
60
+ StringPrimitiveFormat_t stringPrimitiveFormat;
61
+ if (stringPrimitiveStr == "WithQuotes") {
62
+ stringPrimitiveFormat = STRING_PRIMITIVE_FORMAT_WITH_QUOTES;
63
+ } if (stringPrimitiveStr == "WithoutQuotes") {
64
+ stringPrimitiveFormat = STRING_PRIMITIVE_FORMAT_WITHOUT_QUOTES;
65
+ } else {
66
+ throw std::invalid_argument("Invalid string primitive format.");
67
+ }
68
+
69
+ char *res = ::ditto_document_id_query_compatible(id, stringPrimitiveFormat);
70
+ return String::createFromUtf8(runtime, res);
71
+ });
72
+ }
73
+
74
+ Function ditto_document_get_cbor_with_path_type(Runtime &runtime) {
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
+ CDocument_t const *document = jsPointerObjectToCPointer<CDocument>(runtime, arguments[0]);
85
+ std::string path_str = jsTypedArrayToCString(runtime, arguments[1]);
86
+ const char *path = path_str.c_str();
87
+ std::string pathTypeStr = arguments[2].asString(runtime).utf8(runtime);
88
+
89
+ static const std::unordered_map<std::string, PathAccessorType_t> lookup = {
90
+ {"String", PATH_ACCESSOR_TYPE_STRING},
91
+ {"Number", PATH_ACCESSOR_TYPE_NUMBER},
92
+ {"Int", PATH_ACCESSOR_TYPE_INT},
93
+ {"UInt", PATH_ACCESSOR_TYPE_U_INT},
94
+ {"Float", PATH_ACCESSOR_TYPE_FLOAT},
95
+ {"Double", PATH_ACCESSOR_TYPE_DOUBLE},
96
+ {"Bool", PATH_ACCESSOR_TYPE_BOOL},
97
+ {"Null", PATH_ACCESSOR_TYPE_NULL},
98
+ {"Object", PATH_ACCESSOR_TYPE_OBJECT},
99
+ {"Array", PATH_ACCESSOR_TYPE_ARRAY},
100
+ {"Any", PATH_ACCESSOR_TYPE_ANY},
101
+ {"Counter", PATH_ACCESSOR_TYPE_COUNTER},
102
+ {"Register", PATH_ACCESSOR_TYPE_REGISTER},
103
+ {"Attachment", PATH_ACCESSOR_TYPE_ATTACHMENT},
104
+ {"Rga", PATH_ACCESSOR_TYPE_R_W_MAP},
105
+ {"RWMap", PATH_ACCESSOR_TYPE_R_W_MAP},
106
+ };
107
+
108
+ PathAccessorType_t path_type;
109
+ auto it = lookup.find(pathTypeStr);
110
+ if (it != lookup.end()) {
111
+ path_type = it->second;
112
+ } else {
113
+ throw std::invalid_argument("Invalid path type string");
114
+ }
115
+
116
+ CBORPathResult_t res = ::ditto_document_get_cbor_with_path_type(document, path, path_type);
117
+
118
+ Object obj(runtime);
119
+ obj.setProperty(runtime, "status_code", static_cast<double>(res.status_code));
120
+ obj.setProperty(runtime, "cbor", cSlicedBoxToJSSlicedBox(runtime, res.cbor));
121
+ return obj;
122
+ });
123
+ }
124
+
125
+
126
+ Function ditto_validate_document_id(Runtime &runtime)
127
+ {
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
+
138
+ std::vector<uint8_t> doc_id_vec = jsTypedArrayToCVector(runtime, arguments[0]);
139
+ slice_ref_uint8_t doc_id = borrowVecAsRefSlice(doc_id_vec);
140
+
141
+ slice_boxed_uint8 *out_cbor = jsPointerObjectToCPointer<slice_boxed_uint8>(runtime, arguments[1]);
142
+ uint32_t res = ::ditto_validate_document_id(doc_id, out_cbor);
143
+ return static_cast<double>(res);
144
+ });
145
+ }
146
+ }
@@ -0,0 +1,123 @@
1
+ #include "Utils.h"
2
+
3
+ #include <Identity.h>
4
+
5
+ namespace sharedjsi
6
+ {
7
+
8
+ Object convertConfigResultToJSIObject(Runtime &runtime, IdentityConfigResult_t result) {
9
+ Object obj(runtime);
10
+ obj.setProperty(runtime, "status_code", (double)result.status_code);
11
+ obj.setProperty(runtime, "identity_config", cPointerToJSPointerObject(runtime, result.identity_config));
12
+ return obj;
13
+ }
14
+
15
+ Function ditto_identity_config_make_online_playground(Runtime &runtime)
16
+ {
17
+ return Function::createFromHostFunction(runtime,
18
+ PropNameID::forAscii(runtime,
19
+ STRINGIFIED_FUNC_NAME()),
20
+ 0,
21
+ [](Runtime &runtime,
22
+ const Value &thisValue,
23
+ const Value *arguments,
24
+ size_t count) -> Value
25
+ {
26
+ std::string app_id_str = jsTypedArrayToCString(runtime, arguments[0]);
27
+ std::string shared_token_str = jsTypedArrayToCString(runtime, arguments[1]);
28
+ std::string base_url_str = jsTypedArrayToCString(runtime, arguments[2]);
29
+
30
+ const char *app_id = app_id_str.c_str();
31
+ const char *shared_token = shared_token_str.c_str();
32
+ const char *base_url = base_url_str.c_str();
33
+
34
+ IdentityConfigResult_t config_result = ::ditto_identity_config_make_online_playground(app_id, shared_token, base_url);
35
+ return convertConfigResultToJSIObject(runtime, config_result);
36
+ });
37
+ }
38
+
39
+ Function ditto_identity_config_make_offline_playground(Runtime &runtime)
40
+ {
41
+ return Function::createFromHostFunction(runtime,
42
+ PropNameID::forAscii(runtime,
43
+ STRINGIFIED_FUNC_NAME()),
44
+ 0,
45
+ [](Runtime &runtime,
46
+ const Value &thisValue,
47
+ const Value *arguments,
48
+ size_t count) -> Value
49
+ {
50
+ std::string app_id_str = jsTypedArrayToCString(runtime, arguments[0]);
51
+ const char *app_id = app_id_str.c_str();
52
+ uint64_t site_id = arguments[1].asNumber();
53
+
54
+ IdentityConfigResult_t config_result = ::ditto_identity_config_make_offline_playground(app_id, site_id);
55
+ return convertConfigResultToJSIObject(runtime, config_result);
56
+ });
57
+ }
58
+
59
+ Function ditto_identity_config_make_manual_v0(Runtime &runtime)
60
+ {
61
+ return Function::createFromHostFunction(runtime,
62
+ PropNameID::forAscii(runtime,
63
+ STRINGIFIED_FUNC_NAME()),
64
+ 0,
65
+ [](Runtime &runtime,
66
+ const Value &thisValue,
67
+ const Value *arguments,
68
+ size_t count) -> Value
69
+ {
70
+ std::string config_cbor_b64_str = jsTypedArrayToCString(runtime, arguments[0]);
71
+ const char *config_cbor_b64 = config_cbor_b64_str.c_str();
72
+
73
+ IdentityConfigResult_t config_result = ::ditto_identity_config_make_manual_v0(config_cbor_b64);
74
+ return convertConfigResultToJSIObject(runtime, config_result);
75
+ });
76
+ }
77
+
78
+ Function ditto_identity_config_make_shared_key(Runtime &runtime)
79
+ {
80
+ return Function::createFromHostFunction(runtime,
81
+ PropNameID::forAscii(runtime,
82
+ STRINGIFIED_FUNC_NAME()),
83
+ 0,
84
+ [](Runtime &runtime,
85
+ const Value &thisValue,
86
+ const Value *arguments,
87
+ size_t count) -> Value
88
+ {
89
+ std::string app_id_str = jsTypedArrayToCString(runtime, arguments[0]);
90
+ const char *app_id = app_id_str.c_str();
91
+
92
+ std::string shared_key_str = jsTypedArrayToCString(runtime, arguments[1]);
93
+ const char *shared_key = shared_key_str.c_str();
94
+
95
+ uint64_t site_id = arguments[2].asNumber();
96
+
97
+ IdentityConfigResult_t config_result = ::ditto_identity_config_make_shared_key(app_id, shared_key, site_id);
98
+ return convertConfigResultToJSIObject(runtime, config_result);
99
+ });
100
+ }
101
+
102
+ Function ditto_identity_config_make_online_with_authentication(Runtime &runtime)
103
+ {
104
+ return Function::createFromHostFunction(runtime,
105
+ PropNameID::forAscii(runtime,
106
+ STRINGIFIED_FUNC_NAME()),
107
+ 0,
108
+ [](Runtime &runtime,
109
+ const Value &thisValue,
110
+ const Value *arguments,
111
+ size_t count) -> Value
112
+ {
113
+ std::string app_id_str = jsTypedArrayToCString(runtime, arguments[0]);
114
+ std::string baseURLVector = jsTypedArrayToCString(runtime, arguments[1]);
115
+
116
+ const char *app_id = app_id_str.c_str();
117
+ const char *base_url = baseURLVector.c_str();
118
+
119
+ IdentityConfigResult_t config_result = ::ditto_identity_config_make_online_with_authentication(app_id, base_url);
120
+ return convertConfigResultToJSIObject(runtime, config_result);
121
+ });
122
+ }
123
+ }
@@ -0,0 +1,110 @@
1
+ #include "Utils.h"
2
+
3
+ #include <Lifecycle.h>
4
+
5
+ namespace sharedjsi
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
+ Function ditto_shutdown(Runtime &runtime)
25
+ {
26
+ return Function::createFromHostFunction(runtime,
27
+ PropNameID::forAscii(runtime,
28
+ STRINGIFIED_FUNC_NAME()),
29
+ 0,
30
+ [](Runtime &runtime,
31
+ const Value &thisValue,
32
+ const Value *arguments,
33
+ size_t count) -> Value
34
+ {
35
+ ::ditto_shutdown(jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]));
36
+ return Value();
37
+ });
38
+ }
39
+
40
+ Function ditto_free(Runtime &runtime)
41
+ {
42
+ return Function::createFromHostFunction(runtime,
43
+ PropNameID::forAscii(runtime,
44
+ STRINGIFIED_FUNC_NAME()),
45
+ 0,
46
+ [](Runtime &runtime,
47
+ const Value &thisValue,
48
+ const Value *arguments,
49
+ size_t count) -> Value
50
+ {
51
+ ::ditto_free(jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]));
52
+ return Value();
53
+ });
54
+ }
55
+
56
+ Function ditto_make(Runtime &runtime)
57
+ {
58
+ return Function::createFromHostFunction(runtime,
59
+ PropNameID::forAscii(runtime,
60
+ STRINGIFIED_FUNC_NAME()),
61
+ 0,
62
+ [](Runtime &runtime,
63
+ const Value &thisValue,
64
+ const Value *arguments,
65
+ size_t count) -> Value
66
+ {
67
+ UninitializedDitto_t *uninit_ditto = jsPointerObjectToCPointer<UninitializedDitto_t>(runtime, arguments[0]);
68
+ CIdentityConfig_t *identity_config = jsPointerObjectToCPointer<CIdentityConfig_t>(runtime, arguments[1]);
69
+ HistoryTracking_t history_tracking = HISTORY_TRACKING_DISABLED;
70
+
71
+ CDitto_t *pointer = ::ditto_make(uninit_ditto, identity_config, history_tracking);
72
+ return cPointerToJSPointerObject(runtime, pointer);
73
+ });
74
+ }
75
+
76
+
77
+ Function ditto_init_sdk_version(Runtime &runtime)
78
+ {
79
+ return Function::createFromHostFunction(runtime,
80
+ PropNameID::forAscii(runtime,
81
+ STRINGIFIED_FUNC_NAME()),
82
+ 0,
83
+ [](Runtime &runtime,
84
+ const Value &thisValue,
85
+ const Value *arguments,
86
+ size_t count) -> Value
87
+ {
88
+ std::string platform_str = arguments[0].toString(runtime).utf8(runtime);
89
+ std::string language_str = arguments[1].toString(runtime).utf8(runtime);
90
+ std::string semver_str = arguments[2].toString(runtime).utf8(runtime);
91
+ const char *semver = semver_str.c_str();
92
+
93
+ Language_t language = LANGUAGE_UNKNOWN;
94
+ if (language_str == "JavaScript") {
95
+ language = LANGUAGE_JAVA_SCRIPT;
96
+ }
97
+
98
+ Platform_t platform = PLATFORM_UNKNOWN;
99
+ if (platform_str == "Ios") {
100
+ platform = PLATFORM_IOS;
101
+ } else if (platform_str == "Android") {
102
+ platform = PLATFORM_ANDROID;
103
+ }
104
+
105
+ ::ditto_init_sdk_version(platform, language, semver);
106
+ return Value();
107
+ });
108
+ }
109
+
110
+ }
@@ -0,0 +1,63 @@
1
+
2
+ #include "Utils.h"
3
+ #include "LiveQuery.h"
4
+
5
+ namespace sharedjsi
6
+ {
7
+
8
+ Function ditto_live_query_signal_available_next(Runtime &runtime)
9
+ {
10
+ return Function::createFromHostFunction(runtime,
11
+ PropNameID::forAscii(runtime,
12
+ STRINGIFIED_FUNC_NAME()),
13
+ 0,
14
+ [](Runtime &runtime,
15
+ const Value &thisValue,
16
+ const Value *arguments,
17
+ size_t count) -> Value
18
+ {
19
+ CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
20
+ int64_t liveQueryId = arguments[1].asNumber();
21
+
22
+ ::ditto_live_query_signal_available_next(ditto, liveQueryId);
23
+ return Value();
24
+ });
25
+ }
26
+
27
+ Function ditto_live_query_start(Runtime &runtime)
28
+ {
29
+ return Function::createFromHostFunction(runtime,
30
+ PropNameID::forAscii(runtime,
31
+ STRINGIFIED_FUNC_NAME()),
32
+ 0,
33
+ [](Runtime &runtime,
34
+ const Value &thisValue,
35
+ const Value *arguments,
36
+ size_t count) -> Value
37
+ {
38
+ CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
39
+ int64_t liveQueryId = arguments[1].asNumber();
40
+ int32_t res = ::ditto_live_query_start(ditto, liveQueryId);
41
+ return static_cast<double>(res);
42
+ });
43
+ }
44
+
45
+ Function ditto_live_query_stop(Runtime &runtime)
46
+ {
47
+ return Function::createFromHostFunction(runtime,
48
+ PropNameID::forAscii(runtime,
49
+ STRINGIFIED_FUNC_NAME()),
50
+ 0,
51
+ [](Runtime &runtime,
52
+ const Value &thisValue,
53
+ const Value *arguments,
54
+ size_t count) -> Value
55
+ {
56
+ CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
57
+ int64_t liveQueryId = arguments[1].asNumber();
58
+
59
+ ::ditto_live_query_stop(ditto, liveQueryId);
60
+ return Value();
61
+ });
62
+ }
63
+ }
@@ -0,0 +1,200 @@
1
+
2
+ #include "Logger.h"
3
+ #include "Utils.h"
4
+
5
+ #include <unordered_map>
6
+
7
+ namespace sharedjsi
8
+ {
9
+
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
+ }
50
+ };
51
+
52
+ Function ditto_log(Runtime &runtime)
53
+ {
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
+ });
72
+ }
73
+
74
+ Function ditto_logger_minimum_log_level_get(Runtime &runtime)
75
+ {
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
+ });
89
+ }
90
+
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
+ }
109
+
110
+ Function ditto_logger_set_log_file(Runtime &runtime)
111
+ {
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
+ });
124
+ }
125
+
126
+ Function ditto_logger_emoji_headings_enabled(Runtime &runtime)
127
+ {
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
+ });
140
+ }
141
+
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
+ }
156
+
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
+ }
171
+
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
+ }
187
+
188
+ std::function<void(CLogLevel_t, const char *)> global_js_callback;
189
+
190
+ extern "C"
191
+ {
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
+ }
199
+ }
200
+ }