@dittolive/ditto 4.7.4-rc.2 → 4.7.4
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.
- package/DittoReactNative.podspec +27 -0
- package/README.md +2 -2
- package/node/ditto.cjs.js +1 -1
- package/node/ditto.darwin-arm64.node +0 -0
- package/node/ditto.darwin-x64.node +0 -0
- package/node/ditto.linux-arm.node +0 -0
- package/node/ditto.linux-arm64.node +0 -0
- package/node/ditto.linux-x64.node +0 -0
- package/node/ditto.win32-x64.node +0 -0
- package/node/transports.darwin-arm64.node +0 -0
- package/node/transports.darwin-x64.node +0 -0
- package/package.json +5 -2
- package/react-native/android/.gradle/8.9/checksums/checksums.lock +0 -0
- package/react-native/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
- package/react-native/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
- package/react-native/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
- package/react-native/android/.gradle/8.9/gc.properties +0 -0
- package/react-native/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/react-native/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/react-native/android/.gradle/vcs-1/gc.properties +0 -0
- package/react-native/android/CMakeLists.txt +36 -0
- package/react-native/android/build.gradle +190 -0
- package/react-native/android/cpp-adapter.cpp +259 -0
- package/react-native/android/gradle.properties +5 -0
- package/react-native/android/src/main/AndroidManifest.xml +4 -0
- package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKModule.java +120 -0
- package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKPackage.java +28 -0
- package/react-native/cpp/include/Arc.hpp +159 -0
- package/react-native/cpp/include/Attachment.h +20 -0
- package/react-native/cpp/include/Authentication.h +23 -0
- package/react-native/cpp/include/Collection.h +13 -0
- package/react-native/cpp/include/ConnectionRequest.h +18 -0
- package/react-native/cpp/include/DQL.h +21 -0
- package/react-native/cpp/include/Document.h +17 -0
- package/react-native/cpp/include/FFIUtils.h +16 -0
- package/react-native/cpp/include/IO.h +13 -0
- package/react-native/cpp/include/Identity.h +17 -0
- package/react-native/cpp/include/Lifecycle.h +16 -0
- package/react-native/cpp/include/LiveQuery.h +17 -0
- package/react-native/cpp/include/Logger.h +22 -0
- package/react-native/cpp/include/Misc.h +30 -0
- package/react-native/cpp/include/Presence.h +18 -0
- package/react-native/cpp/include/SmallPeerInfo.h +19 -0
- package/react-native/cpp/include/Transports.h +25 -0
- package/react-native/cpp/include/TypedArray.hpp +167 -0
- package/react-native/cpp/include/Utils.h +70 -0
- package/react-native/cpp/include/main.h +10 -0
- package/react-native/cpp/src/Attachment.cpp +272 -0
- package/react-native/cpp/src/Authentication.cpp +227 -0
- package/react-native/cpp/src/Collection.cpp +56 -0
- package/react-native/cpp/src/ConnectionRequest.cpp +123 -0
- package/react-native/cpp/src/DQL.cpp +256 -0
- package/react-native/cpp/src/Document.cpp +146 -0
- package/react-native/cpp/src/FFIUtils.cpp +122 -0
- package/react-native/cpp/src/IO.cpp +35 -0
- package/react-native/cpp/src/Identity.cpp +122 -0
- package/react-native/cpp/src/Lifecycle.cpp +93 -0
- package/react-native/cpp/src/LiveQuery.cpp +63 -0
- package/react-native/cpp/src/Logger.cpp +199 -0
- package/react-native/cpp/src/Misc.cpp +322 -0
- package/react-native/cpp/src/Presence.cpp +166 -0
- package/react-native/cpp/src/SmallPeerInfo.cpp +142 -0
- package/react-native/cpp/src/Transports.cpp +275 -0
- package/react-native/cpp/src/TypedArray.cpp +303 -0
- package/react-native/cpp/src/Utils.cpp +139 -0
- package/react-native/cpp/src/main.cpp +178 -0
- package/react-native/dittoffi/dittoffi.h +4873 -0
- package/react-native/dittoffi/ifaddrs.cpp +385 -0
- package/react-native/dittoffi/ifaddrs.h +206 -0
- package/react-native/ios/DittoRNSDK.h +7 -0
- package/react-native/ios/DittoRNSDK.mm +159 -0
- package/react-native/ios/YeetJSIUtils.h +60 -0
- package/react-native/ios/YeetJSIUtils.mm +196 -0
- package/react-native/lib/commonjs/ditto.rn.js +93 -0
- package/react-native/lib/commonjs/ditto.rn.js.map +1 -0
- package/react-native/lib/commonjs/index.js +61 -0
- package/react-native/lib/commonjs/index.js.map +1 -0
- package/react-native/lib/module/ditto.rn.js +89 -0
- package/react-native/lib/module/ditto.rn.js.map +1 -0
- package/react-native/lib/module/index.js +27 -0
- package/react-native/lib/module/index.js.map +1 -0
- package/react-native/lib/typescript/ditto.rn.d.ts +15 -0
- package/react-native/lib/typescript/ditto.rn.d.ts.map +1 -0
- package/react-native/lib/typescript/index.d.ts +1 -0
- package/react-native/lib/typescript/index.d.ts.map +1 -0
- package/react-native/src/ditto.rn.ts +123 -0
- package/react-native/src/environment/environment.fallback.ts +4 -0
- package/react-native/src/index.ts +29 -0
- package/react-native/src/sources/@cbor-redux.ts +2 -0
- package/react-native/src/sources/@ditto.core.ts +1 -0
- package/react-native/src/sources/@environment.ts +1 -0
- package/react-native/src/sources/attachment-fetch-event.ts +54 -0
- package/react-native/src/sources/attachment-fetcher-manager.ts +145 -0
- package/react-native/src/sources/attachment-fetcher.ts +265 -0
- package/react-native/src/sources/attachment-token.ts +129 -0
- package/react-native/src/sources/attachment.ts +121 -0
- package/react-native/src/sources/augment.ts +108 -0
- package/react-native/src/sources/authenticator.ts +314 -0
- package/react-native/src/sources/base-pending-cursor-operation.ts +255 -0
- package/react-native/src/sources/base-pending-id-specific-operation.ts +112 -0
- package/react-native/src/sources/bridge.ts +557 -0
- package/react-native/src/sources/build-time-constants.ts +8 -0
- package/react-native/src/sources/cbor.ts +20 -0
- package/react-native/src/sources/collection-interface.ts +73 -0
- package/react-native/src/sources/collection.ts +219 -0
- package/react-native/src/sources/collections-event.ts +99 -0
- package/react-native/src/sources/connection-request.ts +142 -0
- package/react-native/src/sources/counter.ts +82 -0
- package/react-native/src/sources/ditto.ts +991 -0
- package/react-native/src/sources/document-id.ts +163 -0
- package/react-native/src/sources/document-path.ts +308 -0
- package/react-native/src/sources/document.ts +237 -0
- package/react-native/src/sources/epilogue.ts +32 -0
- package/react-native/src/sources/error-codes.ts +114 -0
- package/react-native/src/sources/error.ts +256 -0
- package/react-native/src/sources/essentials.ts +81 -0
- package/react-native/src/sources/ffi-error.ts +134 -0
- package/react-native/src/sources/ffi.ts +2190 -0
- package/react-native/src/sources/identity.ts +163 -0
- package/react-native/src/sources/init.ts +71 -0
- package/react-native/src/sources/internal.ts +143 -0
- package/react-native/src/sources/keep-alive.ts +73 -0
- package/react-native/src/sources/key-path.ts +198 -0
- package/react-native/src/sources/live-query-event.ts +208 -0
- package/react-native/src/sources/live-query-manager.ts +110 -0
- package/react-native/src/sources/live-query.ts +167 -0
- package/react-native/src/sources/logger.ts +196 -0
- package/react-native/src/sources/main.ts +61 -0
- package/react-native/src/sources/observer-manager.ts +185 -0
- package/react-native/src/sources/observer.ts +79 -0
- package/react-native/src/sources/pending-collections-operation.ts +241 -0
- package/react-native/src/sources/pending-cursor-operation.ts +218 -0
- package/react-native/src/sources/pending-id-specific-operation.ts +218 -0
- package/react-native/src/sources/presence-manager.ts +170 -0
- package/react-native/src/sources/presence.ts +427 -0
- package/react-native/src/sources/query-result-item.ts +131 -0
- package/react-native/src/sources/query-result.ts +55 -0
- package/react-native/src/sources/register.ts +95 -0
- package/react-native/src/sources/small-peer-info.ts +166 -0
- package/react-native/src/sources/static-tcp-client.ts +8 -0
- package/react-native/src/sources/store-observer.ts +170 -0
- package/react-native/src/sources/store.ts +630 -0
- package/react-native/src/sources/subscription-manager.ts +99 -0
- package/react-native/src/sources/subscription.ts +89 -0
- package/react-native/src/sources/sync-subscription.ts +90 -0
- package/react-native/src/sources/sync.ts +561 -0
- package/react-native/src/sources/test-helpers.ts +24 -0
- package/react-native/src/sources/transport-conditions-manager.ts +104 -0
- package/react-native/src/sources/transport-config.ts +430 -0
- package/react-native/src/sources/update-result.ts +66 -0
- package/react-native/src/sources/update-results-map.ts +65 -0
- package/react-native/src/sources/websocket-client.ts +7 -0
- package/react-native/src/sources/write-transaction-collection.ts +122 -0
- package/react-native/src/sources/write-transaction-pending-cursor-operation.ts +101 -0
- package/react-native/src/sources/write-transaction-pending-id-specific-operation.ts +74 -0
- package/react-native/src/sources/write-transaction.ts +121 -0
- package/react-native.config.js +9 -0
- package/web/ditto.es6.js +1 -1
- package/web/ditto.umd.js +1 -1
- 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 cPointerToJSPointerObject<char>(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,122 @@
|
|
|
1
|
+
#include "FFIUtils.h"
|
|
2
|
+
#include <Utils.h>
|
|
3
|
+
|
|
4
|
+
namespace sharedjsi
|
|
5
|
+
{
|
|
6
|
+
|
|
7
|
+
Function refCStringToString(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
|
+
char *str = jsPointerObjectToCPointer<char>(runtime, arguments[0]);
|
|
19
|
+
if (str) {
|
|
20
|
+
return String::createFromUtf8(runtime, str);
|
|
21
|
+
} else {
|
|
22
|
+
return Value::null();
|
|
23
|
+
}
|
|
24
|
+
return String::createFromUtf8(runtime, jsPointerObjectToCPointer<char>(runtime, arguments[0]));
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
Function boxCStringIntoString(Runtime &runtime) {
|
|
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
|
+
char *str = jsPointerObjectToCPointer<char>(runtime, arguments[0]);
|
|
39
|
+
if (str) {
|
|
40
|
+
String res = String::createFromUtf8(runtime, str);
|
|
41
|
+
::ditto_c_string_free(str);
|
|
42
|
+
return res;
|
|
43
|
+
} else {
|
|
44
|
+
return Value::null();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Function sliceRefToUInt8Array(Runtime &runtime) {
|
|
50
|
+
return Function::createFromHostFunction(runtime,
|
|
51
|
+
PropNameID::forAscii(runtime, STRINGIFIED_FUNC_NAME()),
|
|
52
|
+
0,
|
|
53
|
+
[](Runtime &runtime,
|
|
54
|
+
const Value &,
|
|
55
|
+
const Value *arguments,
|
|
56
|
+
size_t) -> Value {
|
|
57
|
+
auto fatPtrJs = arguments[0].asObject(runtime);
|
|
58
|
+
auto ptr = jsPointerObjectToCPointer<uint8_t>(runtime, fatPtrJs.getProperty(runtime, "ptr"));
|
|
59
|
+
auto len = static_cast<size_t>(fatPtrJs.getProperty(runtime, "len").asNumber());
|
|
60
|
+
|
|
61
|
+
slice_boxed_uint8 slice = {.ptr = ptr, .len = len};
|
|
62
|
+
if (!slice.ptr) {
|
|
63
|
+
return Value::null();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
TypedArray<TypedArrayKind::Uint8Array> typedArray(runtime, slice.len);
|
|
67
|
+
ArrayBuffer arrayBuffer = typedArray.getBuffer(runtime);
|
|
68
|
+
std::memcpy(arrayBuffer.data(runtime), slice.ptr, slice.len);
|
|
69
|
+
|
|
70
|
+
return typedArray;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
Function sliceBoxedToUInt8Array(Runtime &runtime) {
|
|
75
|
+
return Function::createFromHostFunction(runtime,
|
|
76
|
+
PropNameID::forAscii(runtime, STRINGIFIED_FUNC_NAME()),
|
|
77
|
+
0,
|
|
78
|
+
[](Runtime &runtime,
|
|
79
|
+
const Value &,
|
|
80
|
+
const Value *arguments,
|
|
81
|
+
size_t) -> Value {
|
|
82
|
+
auto fatPtrJs = arguments[0].asObject(runtime);
|
|
83
|
+
auto ptr = jsPointerObjectToCPointer<uint8_t>(runtime, fatPtrJs.getProperty(runtime, "ptr"));
|
|
84
|
+
auto len = static_cast<size_t>(fatPtrJs.getProperty(runtime, "len").asNumber());
|
|
85
|
+
|
|
86
|
+
slice_boxed_uint8 slice = {.ptr = ptr, .len = len};
|
|
87
|
+
if (!slice.ptr) {
|
|
88
|
+
return Value::null();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
TypedArray<TypedArrayKind::Uint8Array> typedArray(runtime, slice.len);
|
|
92
|
+
ArrayBuffer arrayBuffer = typedArray.getBuffer(runtime);
|
|
93
|
+
std::memcpy(arrayBuffer.data(runtime), slice.ptr, slice.len);
|
|
94
|
+
|
|
95
|
+
::ditto_c_bytes_free(slice);
|
|
96
|
+
|
|
97
|
+
return typedArray;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
Function withOutBoxCBytes(Runtime &runtime) {
|
|
102
|
+
return Function::createFromHostFunction(runtime,
|
|
103
|
+
PropNameID::forAscii(runtime,
|
|
104
|
+
STRINGIFIED_FUNC_NAME()),
|
|
105
|
+
0,
|
|
106
|
+
[](Runtime &runtime,
|
|
107
|
+
const Value &thisValue,
|
|
108
|
+
const Value *arguments,
|
|
109
|
+
size_t count) -> Value
|
|
110
|
+
{
|
|
111
|
+
auto callback = arguments[0].asObject(runtime).asFunction(runtime);
|
|
112
|
+
slice_boxed_uint8 box_c_bytes = { 0 };
|
|
113
|
+
auto out_box_cbytes = &box_c_bytes;
|
|
114
|
+
auto out_box_cbytes_js = cPointerToJSPointerObject<slice_boxed_uint8>(runtime, out_box_cbytes);
|
|
115
|
+
|
|
116
|
+
callback.call(runtime, out_box_cbytes_js);
|
|
117
|
+
|
|
118
|
+
return cSlicedBoxToJSSlicedBox(runtime, box_c_bytes);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#include "Utils.h"
|
|
2
|
+
|
|
3
|
+
#include <Misc.h>
|
|
4
|
+
#include <fstream>
|
|
5
|
+
|
|
6
|
+
namespace sharedjsi
|
|
7
|
+
{
|
|
8
|
+
|
|
9
|
+
Function readFile(Runtime &runtime)
|
|
10
|
+
{
|
|
11
|
+
return Function::createFromHostFunction(runtime,
|
|
12
|
+
PropNameID::forAscii(runtime,
|
|
13
|
+
STRINGIFIED_FUNC_NAME()),
|
|
14
|
+
0,
|
|
15
|
+
[](Runtime &runtime,
|
|
16
|
+
const Value &thisValue,
|
|
17
|
+
const Value *arguments,
|
|
18
|
+
size_t count) -> Value
|
|
19
|
+
{
|
|
20
|
+
std::string filePath = arguments[0].asString(runtime).utf8(runtime);
|
|
21
|
+
try {
|
|
22
|
+
std::ifstream fileStream(filePath, std::ios::binary);
|
|
23
|
+
if (!fileStream.is_open()) {
|
|
24
|
+
throw std::runtime_error("Cannot open file: " + filePath);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Read the file into a vector
|
|
28
|
+
std::vector<uint8_t> buffer((std::istreambuf_iterator<char>(fileStream)), std::istreambuf_iterator<char>());
|
|
29
|
+
return TypedArray<TypedArrayKind::Uint8Array>(runtime, buffer);
|
|
30
|
+
} catch (const std::exception& e) {
|
|
31
|
+
throw JSError(runtime, e.what());
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
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", static_cast<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 = bigIntOrNumberToUint64(runtime, arguments[1]);
|
|
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
|
+
uint64_t site_id = bigIntOrNumberToUint64(runtime, arguments[2]);
|
|
95
|
+
|
|
96
|
+
IdentityConfigResult_t config_result = ::ditto_identity_config_make_shared_key(app_id, shared_key, site_id);
|
|
97
|
+
return convertConfigResultToJSIObject(runtime, config_result);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
Function ditto_identity_config_make_online_with_authentication(Runtime &runtime)
|
|
102
|
+
{
|
|
103
|
+
return Function::createFromHostFunction(runtime,
|
|
104
|
+
PropNameID::forAscii(runtime,
|
|
105
|
+
STRINGIFIED_FUNC_NAME()),
|
|
106
|
+
0,
|
|
107
|
+
[](Runtime &runtime,
|
|
108
|
+
const Value &thisValue,
|
|
109
|
+
const Value *arguments,
|
|
110
|
+
size_t count) -> Value
|
|
111
|
+
{
|
|
112
|
+
std::string app_id_str = jsTypedArrayToCString(runtime, arguments[0]);
|
|
113
|
+
std::string baseURLVector = jsTypedArrayToCString(runtime, arguments[1]);
|
|
114
|
+
|
|
115
|
+
const char *app_id = app_id_str.c_str();
|
|
116
|
+
const char *base_url = baseURLVector.c_str();
|
|
117
|
+
|
|
118
|
+
IdentityConfigResult_t config_result = ::ditto_identity_config_make_online_with_authentication(app_id, base_url);
|
|
119
|
+
return convertConfigResultToJSIObject(runtime, config_result);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#include "Utils.h"
|
|
2
|
+
|
|
3
|
+
#include <Lifecycle.h>
|
|
4
|
+
|
|
5
|
+
namespace sharedjsi
|
|
6
|
+
{
|
|
7
|
+
Function ditto_shutdown(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
|
+
::ditto_shutdown(jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]));
|
|
19
|
+
return Value();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
Function ditto_free(Runtime &runtime)
|
|
24
|
+
{
|
|
25
|
+
return Function::createFromHostFunction(runtime,
|
|
26
|
+
PropNameID::forAscii(runtime,
|
|
27
|
+
STRINGIFIED_FUNC_NAME()),
|
|
28
|
+
0,
|
|
29
|
+
[](Runtime &runtime,
|
|
30
|
+
const Value &thisValue,
|
|
31
|
+
const Value *arguments,
|
|
32
|
+
size_t count) -> Value
|
|
33
|
+
{
|
|
34
|
+
::ditto_free(jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]));
|
|
35
|
+
return Value();
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
Function ditto_make(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 path = jsTypedArrayToCString(runtime, arguments[0]);
|
|
51
|
+
CIdentityConfig_t *identity_config = jsPointerObjectToCPointer<CIdentityConfig_t>(runtime, arguments[1]);
|
|
52
|
+
HistoryTracking_t history_tracking = HISTORY_TRACKING_DISABLED;
|
|
53
|
+
|
|
54
|
+
CDitto_t *pointer = ::ditto_make(path.c_str(), identity_config, history_tracking);
|
|
55
|
+
return cPointerToJSPointerObject(runtime, pointer);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
Function ditto_init_sdk_version(Runtime &runtime)
|
|
61
|
+
{
|
|
62
|
+
return Function::createFromHostFunction(runtime,
|
|
63
|
+
PropNameID::forAscii(runtime,
|
|
64
|
+
STRINGIFIED_FUNC_NAME()),
|
|
65
|
+
0,
|
|
66
|
+
[](Runtime &runtime,
|
|
67
|
+
const Value &thisValue,
|
|
68
|
+
const Value *arguments,
|
|
69
|
+
size_t count) -> Value
|
|
70
|
+
{
|
|
71
|
+
std::string platform_str = arguments[0].toString(runtime).utf8(runtime);
|
|
72
|
+
std::string language_str = arguments[1].toString(runtime).utf8(runtime);
|
|
73
|
+
std::string semver_str = arguments[2].toString(runtime).utf8(runtime);
|
|
74
|
+
const char *semver = semver_str.c_str();
|
|
75
|
+
|
|
76
|
+
Language_t language = LANGUAGE_UNKNOWN;
|
|
77
|
+
if (language_str == "JavaScript") {
|
|
78
|
+
language = LANGUAGE_JAVA_SCRIPT;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
Platform_t platform = PLATFORM_UNKNOWN;
|
|
82
|
+
if (platform_str == "Ios") {
|
|
83
|
+
platform = PLATFORM_IOS;
|
|
84
|
+
} else if (platform_str == "Android") {
|
|
85
|
+
platform = PLATFORM_ANDROID;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
::ditto_init_sdk_version(platform, language, semver);
|
|
89
|
+
return Value();
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
}
|
|
@@ -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 = bigIntOrNumberToInt64(runtime, arguments[1]);
|
|
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 = bigIntOrNumberToInt64(runtime, arguments[1]);
|
|
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 = bigIntOrNumberToInt64(runtime, arguments[1]);
|
|
58
|
+
|
|
59
|
+
::ditto_live_query_stop(ditto, liveQueryId);
|
|
60
|
+
return Value();
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|