@dittolive/ditto 4.7.3 → 4.7.4-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.
- 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 +10 -5
- package/web/ditto.es6.js +1 -1
- package/web/ditto.umd.js +1 -1
- package/web/ditto.wasm +0 -0
- package/DittoReactNative.podspec +0 -27
- package/react-native/android/CMakeLists.txt +0 -36
- package/react-native/android/build.gradle +0 -190
- package/react-native/android/cpp-adapter.cpp +0 -259
- package/react-native/android/gradle.properties +0 -5
- package/react-native/android/src/main/AndroidManifest.xml +0 -4
- package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKModule.java +0 -120
- package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKPackage.java +0 -28
- package/react-native/cpp/include/Arc.hpp +0 -159
- package/react-native/cpp/include/Attachment.h +0 -20
- package/react-native/cpp/include/Authentication.h +0 -23
- package/react-native/cpp/include/Collection.h +0 -13
- package/react-native/cpp/include/ConnectionRequest.h +0 -18
- package/react-native/cpp/include/DQL.h +0 -21
- package/react-native/cpp/include/Document.h +0 -17
- package/react-native/cpp/include/FFIUtils.h +0 -16
- package/react-native/cpp/include/IO.h +0 -13
- package/react-native/cpp/include/Identity.h +0 -17
- package/react-native/cpp/include/Lifecycle.h +0 -16
- package/react-native/cpp/include/LiveQuery.h +0 -17
- package/react-native/cpp/include/Logger.h +0 -22
- package/react-native/cpp/include/Misc.h +0 -30
- package/react-native/cpp/include/Presence.h +0 -18
- package/react-native/cpp/include/SmallPeerInfo.h +0 -19
- package/react-native/cpp/include/Transports.h +0 -25
- package/react-native/cpp/include/TypedArray.hpp +0 -167
- package/react-native/cpp/include/Utils.h +0 -70
- package/react-native/cpp/include/main.h +0 -10
- package/react-native/cpp/src/Attachment.cpp +0 -272
- package/react-native/cpp/src/Authentication.cpp +0 -227
- package/react-native/cpp/src/Collection.cpp +0 -56
- package/react-native/cpp/src/ConnectionRequest.cpp +0 -123
- package/react-native/cpp/src/DQL.cpp +0 -256
- package/react-native/cpp/src/Document.cpp +0 -146
- package/react-native/cpp/src/FFIUtils.cpp +0 -122
- package/react-native/cpp/src/IO.cpp +0 -35
- package/react-native/cpp/src/Identity.cpp +0 -122
- package/react-native/cpp/src/Lifecycle.cpp +0 -93
- package/react-native/cpp/src/LiveQuery.cpp +0 -63
- package/react-native/cpp/src/Logger.cpp +0 -199
- package/react-native/cpp/src/Misc.cpp +0 -322
- package/react-native/cpp/src/Presence.cpp +0 -166
- package/react-native/cpp/src/SmallPeerInfo.cpp +0 -142
- package/react-native/cpp/src/Transports.cpp +0 -275
- package/react-native/cpp/src/TypedArray.cpp +0 -303
- package/react-native/cpp/src/Utils.cpp +0 -139
- package/react-native/cpp/src/main.cpp +0 -178
- package/react-native/dittoffi/dittoffi.h +0 -4873
- package/react-native/dittoffi/ifaddrs.cpp +0 -385
- package/react-native/dittoffi/ifaddrs.h +0 -206
- package/react-native/ios/DittoRNSDK.h +0 -7
- package/react-native/ios/DittoRNSDK.mm +0 -159
- package/react-native/ios/YeetJSIUtils.h +0 -60
- package/react-native/ios/YeetJSIUtils.mm +0 -196
- package/react-native/lib/commonjs/ditto.rn.js +0 -93
- package/react-native/lib/commonjs/ditto.rn.js.map +0 -1
- package/react-native/lib/commonjs/index.js +0 -61
- package/react-native/lib/commonjs/index.js.map +0 -1
- package/react-native/lib/module/ditto.rn.js +0 -89
- package/react-native/lib/module/ditto.rn.js.map +0 -1
- package/react-native/lib/module/index.js +0 -27
- package/react-native/lib/module/index.js.map +0 -1
- package/react-native/lib/typescript/ditto.rn.d.ts +0 -15
- package/react-native/lib/typescript/ditto.rn.d.ts.map +0 -1
- package/react-native/lib/typescript/index.d.ts +0 -1
- package/react-native/lib/typescript/index.d.ts.map +0 -1
- package/react-native/src/ditto.rn.ts +0 -123
- package/react-native/src/environment/environment.fallback.ts +0 -4
- package/react-native/src/index.ts +0 -29
- package/react-native/src/sources/@cbor-redux.ts +0 -2
- package/react-native/src/sources/@ditto.core.ts +0 -1
- package/react-native/src/sources/@environment.ts +0 -1
- package/react-native/src/sources/attachment-fetch-event.ts +0 -54
- package/react-native/src/sources/attachment-fetcher-manager.ts +0 -145
- package/react-native/src/sources/attachment-fetcher.ts +0 -265
- package/react-native/src/sources/attachment-token.ts +0 -129
- package/react-native/src/sources/attachment.ts +0 -121
- package/react-native/src/sources/augment.ts +0 -108
- package/react-native/src/sources/authenticator.ts +0 -314
- package/react-native/src/sources/base-pending-cursor-operation.ts +0 -255
- package/react-native/src/sources/base-pending-id-specific-operation.ts +0 -112
- package/react-native/src/sources/bridge.ts +0 -557
- package/react-native/src/sources/build-time-constants.ts +0 -8
- package/react-native/src/sources/cbor.ts +0 -20
- package/react-native/src/sources/collection-interface.ts +0 -73
- package/react-native/src/sources/collection.ts +0 -219
- package/react-native/src/sources/collections-event.ts +0 -99
- package/react-native/src/sources/connection-request.ts +0 -142
- package/react-native/src/sources/counter.ts +0 -82
- package/react-native/src/sources/ditto.ts +0 -991
- package/react-native/src/sources/document-id.ts +0 -163
- package/react-native/src/sources/document-path.ts +0 -308
- package/react-native/src/sources/document.ts +0 -237
- package/react-native/src/sources/epilogue.ts +0 -32
- package/react-native/src/sources/error-codes.ts +0 -114
- package/react-native/src/sources/error.ts +0 -256
- package/react-native/src/sources/essentials.ts +0 -81
- package/react-native/src/sources/ffi-error.ts +0 -134
- package/react-native/src/sources/ffi.ts +0 -2190
- package/react-native/src/sources/identity.ts +0 -163
- package/react-native/src/sources/init.ts +0 -71
- package/react-native/src/sources/internal.ts +0 -143
- package/react-native/src/sources/keep-alive.ts +0 -73
- package/react-native/src/sources/key-path.ts +0 -198
- package/react-native/src/sources/live-query-event.ts +0 -208
- package/react-native/src/sources/live-query-manager.ts +0 -110
- package/react-native/src/sources/live-query.ts +0 -167
- package/react-native/src/sources/logger.ts +0 -196
- package/react-native/src/sources/main.ts +0 -61
- package/react-native/src/sources/observer-manager.ts +0 -185
- package/react-native/src/sources/observer.ts +0 -79
- package/react-native/src/sources/pending-collections-operation.ts +0 -241
- package/react-native/src/sources/pending-cursor-operation.ts +0 -218
- package/react-native/src/sources/pending-id-specific-operation.ts +0 -218
- package/react-native/src/sources/presence-manager.ts +0 -170
- package/react-native/src/sources/presence.ts +0 -427
- package/react-native/src/sources/query-result-item.ts +0 -131
- package/react-native/src/sources/query-result.ts +0 -55
- package/react-native/src/sources/register.ts +0 -95
- package/react-native/src/sources/small-peer-info.ts +0 -166
- package/react-native/src/sources/static-tcp-client.ts +0 -8
- package/react-native/src/sources/store-observer.ts +0 -170
- package/react-native/src/sources/store.ts +0 -630
- package/react-native/src/sources/subscription-manager.ts +0 -99
- package/react-native/src/sources/subscription.ts +0 -89
- package/react-native/src/sources/sync-subscription.ts +0 -90
- package/react-native/src/sources/sync.ts +0 -561
- package/react-native/src/sources/test-helpers.ts +0 -24
- package/react-native/src/sources/transport-conditions-manager.ts +0 -104
- package/react-native/src/sources/transport-config.ts +0 -430
- package/react-native/src/sources/update-result.ts +0 -66
- package/react-native/src/sources/update-results-map.ts +0 -65
- package/react-native/src/sources/websocket-client.ts +0 -7
- package/react-native/src/sources/write-transaction-collection.ts +0 -122
- package/react-native/src/sources/write-transaction-pending-cursor-operation.ts +0 -101
- package/react-native/src/sources/write-transaction-pending-id-specific-operation.ts +0 -74
- package/react-native/src/sources/write-transaction.ts +0 -121
- package/react-native.config.js +0 -9
|
@@ -1,70 +0,0 @@
|
|
|
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
|
-
template<typename T>
|
|
47
|
-
Object cSlicedBoxToJSSlicedBox(Runtime &runtime, T box_c_bytes)
|
|
48
|
-
{
|
|
49
|
-
Object obj(runtime);
|
|
50
|
-
obj.setProperty(runtime, "ptr", cPointerToJSPointerObject<uint8_t>(runtime, box_c_bytes.ptr));
|
|
51
|
-
obj.setProperty(runtime, "len", static_cast<double>(box_c_bytes.len));
|
|
52
|
-
return obj;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
std::vector<uint8_t> jsTypedArrayToCVector(Runtime &runtime, const Value &arg);
|
|
56
|
-
std::string jsTypedArrayToCString(Runtime &runtime, const Value &arg);
|
|
57
|
-
|
|
58
|
-
slice_ref_uint8_t borrowVecAsOptRefSlice(std::vector<uint8_t> const& v);
|
|
59
|
-
slice_ref_uint8_t borrowVecAsRefSlice(std::vector<uint8_t> const& v);
|
|
60
|
-
|
|
61
|
-
Value int64ToBigIntOrNumber(Runtime &runtime, int64_t value);
|
|
62
|
-
Value uint64ToBigIntOrNumber(Runtime &runtime, uint64_t value);
|
|
63
|
-
int64_t bigIntOrNumberToInt64(Runtime &runtime, Value const& value);
|
|
64
|
-
uint64_t bigIntOrNumberToUint64(Runtime &runtime, Value const& value);
|
|
65
|
-
|
|
66
|
-
void ditto_tick(Runtime* jsi);
|
|
67
|
-
void ditto_enqueue_call(std::function<void(Runtime *)> && task);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
#endif /* UTILS_H */
|
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
#include "Utils.h"
|
|
2
|
-
|
|
3
|
-
#include <Attachment.h>
|
|
4
|
-
#include <Arc.hpp>
|
|
5
|
-
|
|
6
|
-
namespace sharedjsi
|
|
7
|
-
{
|
|
8
|
-
|
|
9
|
-
DEFINE_RETAIN_RELEASE_FOR(Function, v_retain, v_release);
|
|
10
|
-
|
|
11
|
-
class AttachmentResolver {
|
|
12
|
-
public:
|
|
13
|
-
Function onCompleteCb;
|
|
14
|
-
Function onProgressCb;
|
|
15
|
-
Function onDeletedCb;
|
|
16
|
-
|
|
17
|
-
AttachmentResolver(Function onComplete, Function onProgress, Function onDeleted)
|
|
18
|
-
: onCompleteCb(std::move(onComplete)), onDeletedCb(std::move(onDeleted)), onProgressCb(std::move(onProgress)) {}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
extern "C" {
|
|
22
|
-
void v_on_complete(void *ctx, AttachmentHandle_t *handle)
|
|
23
|
-
{
|
|
24
|
-
ditto_enqueue_call([=](Runtime *jsi) {
|
|
25
|
-
auto jsObject = reinterpret_cast<AttachmentResolver *>(ctx);
|
|
26
|
-
Runtime &runtime = *jsi;
|
|
27
|
-
jsObject->onCompleteCb.call(runtime, cPointerToJSPointerObject<AttachmentHandle>(runtime, handle));
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
void v_on_progress(void *ctx, uint64_t downloaded, uint64_t to_download)
|
|
32
|
-
{
|
|
33
|
-
ditto_enqueue_call([=](Runtime *jsi) {
|
|
34
|
-
auto jsObject = reinterpret_cast<AttachmentResolver *>(ctx);
|
|
35
|
-
Runtime &runtime = *jsi;
|
|
36
|
-
jsObject->onProgressCb.call(runtime, uint64ToBigIntOrNumber(runtime, downloaded), uint64ToBigIntOrNumber(runtime, to_download));
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
void v_on_deleted(void *ctx)
|
|
41
|
-
{
|
|
42
|
-
ditto_enqueue_call([=](Runtime *jsi) {
|
|
43
|
-
auto jsObject = reinterpret_cast<AttachmentResolver *>(ctx);
|
|
44
|
-
Runtime &runtime = *jsi;
|
|
45
|
-
jsObject->onDeletedCb.call(runtime);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
Function ditto_cancel_resolve_attachment(Runtime &runtime)
|
|
51
|
-
{
|
|
52
|
-
return Function::createFromHostFunction(runtime,
|
|
53
|
-
PropNameID::forAscii(runtime,
|
|
54
|
-
STRINGIFIED_FUNC_NAME()),
|
|
55
|
-
0,
|
|
56
|
-
[](Runtime &runtime,
|
|
57
|
-
const Value &thisValue,
|
|
58
|
-
const Value *arguments,
|
|
59
|
-
size_t count) -> Value
|
|
60
|
-
{
|
|
61
|
-
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
62
|
-
std::vector<uint8_t> id_vec = jsTypedArrayToCVector(runtime, arguments[1]);
|
|
63
|
-
slice_ref_uint8_t id = borrowVecAsOptRefSlice(id_vec);
|
|
64
|
-
uint64_t cancelToken = bigIntOrNumberToUint64(runtime, arguments[2]);
|
|
65
|
-
|
|
66
|
-
return static_cast<double>(::ditto_cancel_resolve_attachment(ditto, id, cancelToken));
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
Function ditto_free_attachment_handle(Runtime &runtime)
|
|
71
|
-
{
|
|
72
|
-
return Function::createFromHostFunction(runtime,
|
|
73
|
-
PropNameID::forAscii(runtime,
|
|
74
|
-
STRINGIFIED_FUNC_NAME()),
|
|
75
|
-
0,
|
|
76
|
-
[](Runtime &runtime,
|
|
77
|
-
const Value &thisValue,
|
|
78
|
-
const Value *arguments,
|
|
79
|
-
size_t count) -> Value
|
|
80
|
-
{
|
|
81
|
-
::ditto_free_attachment_handle(jsPointerObjectToCPointer<AttachmentHandle_t>(runtime, arguments[0]));
|
|
82
|
-
return Value();
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
Function ditto_get_attachment_status(Runtime &runtime)
|
|
87
|
-
{
|
|
88
|
-
return Function::createFromHostFunction(runtime,
|
|
89
|
-
PropNameID::forAscii(runtime,
|
|
90
|
-
STRINGIFIED_FUNC_NAME()),
|
|
91
|
-
0,
|
|
92
|
-
[](Runtime &runtime,
|
|
93
|
-
const Value &thisValue,
|
|
94
|
-
const Value *arguments,
|
|
95
|
-
size_t count) -> Value
|
|
96
|
-
{
|
|
97
|
-
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
98
|
-
std::vector<uint8_t> id_vec = jsTypedArrayToCVector(runtime, arguments[1]);
|
|
99
|
-
slice_ref_uint8_t id = borrowVecAsRefSlice(id_vec);
|
|
100
|
-
|
|
101
|
-
AttachmentHandleResult_t res = ::ditto_get_attachment_status(ditto, id);
|
|
102
|
-
|
|
103
|
-
Object obj(runtime);
|
|
104
|
-
obj.setProperty(runtime, "status_code", static_cast<double>(res.status_code));
|
|
105
|
-
obj.setProperty(runtime, "handle", cPointerToJSPointerObject<AttachmentHandle_t>(runtime, res.handle));
|
|
106
|
-
return obj;
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
Function ditto_get_complete_attachment_data(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
|
-
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
122
|
-
AttachmentHandle_t* handle = jsPointerObjectToCPointer<AttachmentHandle_t>(runtime, arguments[1]);
|
|
123
|
-
AttachmentDataResult_t res = ::ditto_get_complete_attachment_data(ditto, handle);
|
|
124
|
-
|
|
125
|
-
Object obj(runtime);
|
|
126
|
-
obj.setProperty(runtime, "status_code", static_cast<double>(res.status));
|
|
127
|
-
obj.setProperty(runtime, "data", cSlicedBoxToJSSlicedBox(runtime, res.data));
|
|
128
|
-
return obj;
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
Function ditto_get_complete_attachment_path(Runtime &runtime)
|
|
133
|
-
{
|
|
134
|
-
return Function::createFromHostFunction(runtime,
|
|
135
|
-
PropNameID::forAscii(runtime,
|
|
136
|
-
STRINGIFIED_FUNC_NAME()),
|
|
137
|
-
0,
|
|
138
|
-
[](Runtime &runtime,
|
|
139
|
-
const Value &thisValue,
|
|
140
|
-
const Value *arguments,
|
|
141
|
-
size_t count) -> Value
|
|
142
|
-
{
|
|
143
|
-
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
144
|
-
AttachmentHandle_t *attachmentHandler = jsPointerObjectToCPointer<AttachmentHandle_t>(runtime, arguments[1]);
|
|
145
|
-
|
|
146
|
-
char *res = ::ditto_get_complete_attachment_path(ditto, attachmentHandler);
|
|
147
|
-
return cPointerToJSPointerObject<char>(runtime, res);
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
Function ditto_new_attachment_from_bytes(Runtime &runtime)
|
|
152
|
-
{
|
|
153
|
-
return Function::createFromHostFunction(runtime,
|
|
154
|
-
PropNameID::forAscii(runtime,
|
|
155
|
-
STRINGIFIED_FUNC_NAME()),
|
|
156
|
-
0,
|
|
157
|
-
[](Runtime &runtime,
|
|
158
|
-
const Value &thisValue,
|
|
159
|
-
const Value *arguments,
|
|
160
|
-
size_t count) -> Value
|
|
161
|
-
{
|
|
162
|
-
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
163
|
-
std::vector<uint8_t> bytes_vec = jsTypedArrayToCVector(runtime, arguments[1]);
|
|
164
|
-
slice_ref_uint8_t bytes = borrowVecAsRefSlice(bytes_vec);
|
|
165
|
-
|
|
166
|
-
CAttachment_t c_attachment;
|
|
167
|
-
uint32_t res = ::ditto_new_attachment_from_bytes(ditto, bytes, &c_attachment);
|
|
168
|
-
|
|
169
|
-
if (res != 0) {
|
|
170
|
-
// It failed, bubble up the error.
|
|
171
|
-
return static_cast<double>(res);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
Object attachment = arguments[2].getObject(runtime);
|
|
175
|
-
|
|
176
|
-
attachment.setProperty(runtime, "len", uint64ToBigIntOrNumber(runtime , c_attachment.len));
|
|
177
|
-
// Factor this out as: cSliceToUInt8Array()
|
|
178
|
-
std::vector<uint8_t> id(c_attachment.id.ptr, c_attachment.id.ptr + c_attachment.id.len);
|
|
179
|
-
TypedArray<TypedArrayKind::Uint8Array> typedArray(runtime, id);
|
|
180
|
-
attachment.setProperty(runtime, "id", typedArray);
|
|
181
|
-
attachment.setProperty(runtime, "handle", cPointerToJSPointerObject(runtime, c_attachment.handle));
|
|
182
|
-
|
|
183
|
-
return 0;
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
Function ditto_new_attachment_from_file(Runtime &runtime)
|
|
188
|
-
{
|
|
189
|
-
return Function::createFromHostFunction(runtime,
|
|
190
|
-
PropNameID::forAscii(runtime,
|
|
191
|
-
STRINGIFIED_FUNC_NAME()),
|
|
192
|
-
0,
|
|
193
|
-
[](Runtime &runtime,
|
|
194
|
-
const Value &thisValue,
|
|
195
|
-
const Value *arguments,
|
|
196
|
-
size_t count) -> Value
|
|
197
|
-
{
|
|
198
|
-
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
199
|
-
std::string source_path_str = jsTypedArrayToCString(runtime, arguments[1]);
|
|
200
|
-
std::string file_operation_str = arguments[2].toString(runtime).utf8(runtime);
|
|
201
|
-
|
|
202
|
-
AttachmentFileOperation_t file_operation;
|
|
203
|
-
if (file_operation_str == "Copy") {
|
|
204
|
-
file_operation = ATTACHMENT_FILE_OPERATION_COPY;
|
|
205
|
-
} else if (file_operation_str == "Move") {
|
|
206
|
-
file_operation = ATTACHMENT_FILE_OPERATION_MOVE;
|
|
207
|
-
} else {
|
|
208
|
-
throw "Invalid attachment file operation.";
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
CAttachment_t c_attachment;
|
|
212
|
-
uint32_t res = ::ditto_new_attachment_from_file(ditto, source_path_str.c_str(), file_operation, &c_attachment);
|
|
213
|
-
|
|
214
|
-
if (res != 0) {
|
|
215
|
-
// It failed, bubble up the error.
|
|
216
|
-
return static_cast<double>(res);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
Object attachment = arguments[3].getObject(runtime);
|
|
220
|
-
|
|
221
|
-
attachment.setProperty(runtime, "len", uint64ToBigIntOrNumber(runtime, c_attachment.len));
|
|
222
|
-
// Factor this out as: cSliceToUInt8Array()
|
|
223
|
-
std::vector<uint8_t> id(c_attachment.id.ptr, c_attachment.id.ptr + c_attachment.id.len);
|
|
224
|
-
TypedArray<TypedArrayKind::Uint8Array> typedArray(runtime, id);
|
|
225
|
-
attachment.setProperty(runtime, "id", typedArray);
|
|
226
|
-
attachment.setProperty(runtime, "handle", cPointerToJSPointerObject(runtime, c_attachment.handle));
|
|
227
|
-
|
|
228
|
-
return 0;
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
Function ditto_resolve_attachment(Runtime &runtime)
|
|
233
|
-
{
|
|
234
|
-
return Function::createFromHostFunction(runtime,
|
|
235
|
-
PropNameID::forAscii(runtime,
|
|
236
|
-
STRINGIFIED_FUNC_NAME()),
|
|
237
|
-
0,
|
|
238
|
-
[](Runtime &runtime,
|
|
239
|
-
const Value &thisValue,
|
|
240
|
-
const Value *arguments,
|
|
241
|
-
size_t count) -> Value
|
|
242
|
-
{
|
|
243
|
-
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
244
|
-
|
|
245
|
-
std::vector<uint8_t> id_vec = jsTypedArrayToCVector(runtime, arguments[1]);
|
|
246
|
-
slice_ref_uint8_t id = borrowVecAsRefSlice(id_vec);
|
|
247
|
-
|
|
248
|
-
Function onCompleteCallback = arguments[2].getObject(runtime).getFunction(runtime);
|
|
249
|
-
Function onProgressCallback = arguments[3].getObject(runtime).getFunction(runtime);
|
|
250
|
-
Function onDeleteCallback = arguments[4].getObject(runtime).getFunction(runtime);
|
|
251
|
-
|
|
252
|
-
AttachmentResolver resolver(std::move(onCompleteCallback),
|
|
253
|
-
std::move(onProgressCallback),
|
|
254
|
-
std::move(onDeleteCallback));
|
|
255
|
-
Arc<AttachmentResolver> wrappedStateFfiWrapper(std::move(resolver));
|
|
256
|
-
|
|
257
|
-
CancelTokenResult_t res = ::ditto_resolve_attachment(ditto,
|
|
258
|
-
id,
|
|
259
|
-
Arc<AttachmentResolver>::into_raw(std::move(wrappedStateFfiWrapper)),
|
|
260
|
-
nullptr,
|
|
261
|
-
nullptr,
|
|
262
|
-
v_on_complete,
|
|
263
|
-
v_on_progress,
|
|
264
|
-
v_on_deleted);
|
|
265
|
-
|
|
266
|
-
Object obj(runtime);
|
|
267
|
-
obj.setProperty(runtime, "status_code", static_cast<double>(res.status_code));
|
|
268
|
-
obj.setProperty(runtime, "cancel_token", int64ToBigIntOrNumber(runtime, res.cancel_token));
|
|
269
|
-
return obj;
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
}
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
#include "Utils.h"
|
|
2
|
-
#include "Arc.hpp"
|
|
3
|
-
|
|
4
|
-
#include <Authentication.h>
|
|
5
|
-
|
|
6
|
-
namespace sharedjsi
|
|
7
|
-
{
|
|
8
|
-
|
|
9
|
-
DEFINE_RETAIN_RELEASE_FOR(Function, v_retain, v_release);
|
|
10
|
-
extern "C"
|
|
11
|
-
{
|
|
12
|
-
void v_auth_client_validity_update(void *ctx, int is_web_valid, int is_x509_valid)
|
|
13
|
-
{
|
|
14
|
-
Arc<Function> const& borrowedJsCallback = Arc<Function>::borrow_from_raw(ctx);
|
|
15
|
-
// copy ctor / retain so as to keep the ArcPointee<Function> alive until the enqueued_call completes.
|
|
16
|
-
ditto_enqueue_call([=, jsCallback=Arc<Function>(borrowedJsCallback)](Runtime *runtime) {
|
|
17
|
-
jsCallback->call(*runtime,
|
|
18
|
-
Value(static_cast<double>(is_web_valid)),
|
|
19
|
-
Value(static_cast<double>(is_x509_valid)));
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
void v_auth_client_expiring_callback(void *ctx, uint32_t secs_until_expiry)
|
|
24
|
-
{
|
|
25
|
-
Arc<Function> const& borrowedJsCallback = Arc<Function>::borrow_from_raw(ctx);
|
|
26
|
-
// copy ctor / retain so as to keep the ArcPointee<Function> alive until the enqueued_call completes.
|
|
27
|
-
ditto_enqueue_call([=, jsCallback=Arc<Function>(borrowedJsCallback)](Runtime *runtime) {
|
|
28
|
-
jsCallback->call(*runtime,
|
|
29
|
-
Value(static_cast<double>(secs_until_expiry)));
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
Function ditto_auth_client_set_validity_listener(Runtime &runtime)
|
|
35
|
-
{
|
|
36
|
-
return Function::createFromHostFunction(runtime, PropNameID::forAscii(runtime, STRINGIFIED_FUNC_NAME()), 0, [](Runtime &runtime, Value const &thisValue, Value const *arguments, size_t count) -> Value
|
|
37
|
-
{
|
|
38
|
-
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
39
|
-
Function jsCallback = arguments[1].getObject(runtime).getFunction(runtime);
|
|
40
|
-
Arc<Function> wrappedStateFfiWrapper /* = */ (std::move(jsCallback));
|
|
41
|
-
|
|
42
|
-
::ditto_auth_client_set_validity_listener(
|
|
43
|
-
ditto,
|
|
44
|
-
Arc<Function>::as_raw(wrappedStateFfiWrapper),
|
|
45
|
-
v_retain,
|
|
46
|
-
v_release,
|
|
47
|
-
v_auth_client_validity_update);
|
|
48
|
-
|
|
49
|
-
return Value();
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
Function ditto_auth_client_is_web_valid(Runtime &runtime)
|
|
54
|
-
{
|
|
55
|
-
return Function::createFromHostFunction(runtime,
|
|
56
|
-
PropNameID::forAscii(runtime,
|
|
57
|
-
STRINGIFIED_FUNC_NAME()),
|
|
58
|
-
0,
|
|
59
|
-
[](Runtime &runtime,
|
|
60
|
-
const Value &thisValue,
|
|
61
|
-
const Value *arguments,
|
|
62
|
-
size_t count) -> Value
|
|
63
|
-
{
|
|
64
|
-
return ::ditto_auth_client_is_web_valid(jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]));
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
Function ditto_auth_client_is_x509_valid(Runtime &runtime)
|
|
69
|
-
{
|
|
70
|
-
return Function::createFromHostFunction(runtime,
|
|
71
|
-
PropNameID::forAscii(runtime,
|
|
72
|
-
STRINGIFIED_FUNC_NAME()),
|
|
73
|
-
0,
|
|
74
|
-
[](Runtime &runtime,
|
|
75
|
-
const Value &thisValue,
|
|
76
|
-
const Value *arguments,
|
|
77
|
-
size_t count) -> Value
|
|
78
|
-
{
|
|
79
|
-
return ::ditto_auth_client_is_x509_valid(jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]));
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
Function ditto_auth_client_get_app_id(Runtime &runtime)
|
|
84
|
-
{
|
|
85
|
-
return Function::createFromHostFunction(runtime,
|
|
86
|
-
PropNameID::forAscii(runtime,
|
|
87
|
-
STRINGIFIED_FUNC_NAME()),
|
|
88
|
-
0,
|
|
89
|
-
[](Runtime &runtime,
|
|
90
|
-
const Value &thisValue,
|
|
91
|
-
const Value *arguments,
|
|
92
|
-
size_t count) -> Value
|
|
93
|
-
{
|
|
94
|
-
char *appId = ::ditto_auth_client_get_app_id(jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]));
|
|
95
|
-
return cPointerToJSPointerObject<char>(runtime, appId);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
Function ditto_auth_client_get_site_id(Runtime &runtime)
|
|
100
|
-
{
|
|
101
|
-
return Function::createFromHostFunction(runtime,
|
|
102
|
-
PropNameID::forAscii(runtime,
|
|
103
|
-
STRINGIFIED_FUNC_NAME()),
|
|
104
|
-
0,
|
|
105
|
-
[](Runtime &runtime,
|
|
106
|
-
const Value &thisValue,
|
|
107
|
-
const Value *arguments,
|
|
108
|
-
size_t count) -> Value
|
|
109
|
-
{
|
|
110
|
-
uint64_t siteId = ::ditto_auth_client_get_site_id(jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]));
|
|
111
|
-
return uint64ToBigIntOrNumber(runtime, siteId);
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
Function ditto_auth_client_make_login_provider(Runtime &runtime)
|
|
116
|
-
{
|
|
117
|
-
return Function::createFromHostFunction(runtime,
|
|
118
|
-
PropNameID::forAscii(runtime,
|
|
119
|
-
STRINGIFIED_FUNC_NAME()),
|
|
120
|
-
0,
|
|
121
|
-
[](Runtime &runtime,
|
|
122
|
-
const Value &thisValue,
|
|
123
|
-
const Value *arguments,
|
|
124
|
-
size_t count) -> Value
|
|
125
|
-
{
|
|
126
|
-
Function expiringCallback = arguments[0].getObject(runtime).getFunction(runtime);
|
|
127
|
-
Arc<Function> wrappedStateFfiWrapper(std::move(expiringCallback));
|
|
128
|
-
|
|
129
|
-
CLoginProvider_t *loginProvider = ::ditto_auth_client_make_login_provider(Arc<Function>::as_raw(wrappedStateFfiWrapper),
|
|
130
|
-
v_retain,
|
|
131
|
-
v_release,
|
|
132
|
-
v_auth_client_expiring_callback);
|
|
133
|
-
|
|
134
|
-
return cPointerToJSPointerObject(runtime, loginProvider);
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
Function ditto_auth_set_login_provider(Runtime &runtime)
|
|
139
|
-
{
|
|
140
|
-
return Function::createFromHostFunction(runtime,
|
|
141
|
-
PropNameID::forAscii(runtime,
|
|
142
|
-
STRINGIFIED_FUNC_NAME()),
|
|
143
|
-
0,
|
|
144
|
-
[](Runtime &runtime,
|
|
145
|
-
const Value &thisValue,
|
|
146
|
-
const Value *arguments,
|
|
147
|
-
size_t count) -> Value
|
|
148
|
-
{
|
|
149
|
-
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
150
|
-
CLoginProvider_t *loginProvider = jsPointerObjectToCPointer<CLoginProvider_t>(runtime, arguments[1]);
|
|
151
|
-
|
|
152
|
-
::ditto_auth_set_login_provider(ditto, loginProvider);
|
|
153
|
-
return Value();
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
Function ditto_auth_client_login_with_token(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
|
-
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
169
|
-
std::string token = jsTypedArrayToCString(runtime, arguments[1]);
|
|
170
|
-
std::string provider = jsTypedArrayToCString(runtime, arguments[2]);
|
|
171
|
-
|
|
172
|
-
return ::ditto_auth_client_login_with_token(ditto, token.c_str(), provider.c_str());
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
Function ditto_auth_client_login_with_credentials(Runtime &runtime)
|
|
177
|
-
{
|
|
178
|
-
return Function::createFromHostFunction(runtime,
|
|
179
|
-
PropNameID::forAscii(runtime,
|
|
180
|
-
STRINGIFIED_FUNC_NAME()),
|
|
181
|
-
0,
|
|
182
|
-
[](Runtime &runtime,
|
|
183
|
-
const Value &thisValue,
|
|
184
|
-
const Value *arguments,
|
|
185
|
-
size_t count) -> Value
|
|
186
|
-
{
|
|
187
|
-
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
188
|
-
|
|
189
|
-
std::string username = jsTypedArrayToCString(runtime, arguments[1]);
|
|
190
|
-
std::string password = jsTypedArrayToCString(runtime, arguments[2]);
|
|
191
|
-
std::string provider = jsTypedArrayToCString(runtime, arguments[3]);
|
|
192
|
-
|
|
193
|
-
return ::ditto_auth_client_login_with_credentials(ditto, username.c_str(), password.c_str(), provider.c_str());
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
Function ditto_auth_client_logout(Runtime &runtime)
|
|
198
|
-
{
|
|
199
|
-
return Function::createFromHostFunction(runtime,
|
|
200
|
-
PropNameID::forAscii(runtime,
|
|
201
|
-
STRINGIFIED_FUNC_NAME()),
|
|
202
|
-
0,
|
|
203
|
-
[](Runtime &runtime,
|
|
204
|
-
const Value &thisValue,
|
|
205
|
-
const Value *arguments,
|
|
206
|
-
size_t count) -> Value
|
|
207
|
-
{
|
|
208
|
-
return ::ditto_auth_client_logout(jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]));
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
Function ditto_auth_client_user_id(Runtime &runtime)
|
|
213
|
-
{
|
|
214
|
-
return Function::createFromHostFunction(runtime,
|
|
215
|
-
PropNameID::forAscii(runtime,
|
|
216
|
-
STRINGIFIED_FUNC_NAME()),
|
|
217
|
-
0,
|
|
218
|
-
[](Runtime &runtime,
|
|
219
|
-
const Value &thisValue,
|
|
220
|
-
const Value *arguments,
|
|
221
|
-
size_t count) -> Value
|
|
222
|
-
{
|
|
223
|
-
char *res = ::ditto_auth_client_user_id(jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]));
|
|
224
|
-
return cPointerToJSPointerObject<char>(runtime, res);
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
#include "Utils.h"
|
|
2
|
-
|
|
3
|
-
#include <Collection.h>
|
|
4
|
-
|
|
5
|
-
namespace sharedjsi
|
|
6
|
-
{
|
|
7
|
-
|
|
8
|
-
Function ditto_collection_insert_value(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
|
-
|
|
21
|
-
std::string collection_name_str = jsTypedArrayToCString(runtime, arguments[1]);
|
|
22
|
-
const char *collectionName = collection_name_str.c_str();
|
|
23
|
-
|
|
24
|
-
TypedArrayBase typedArrayBase(runtime, arguments[2].asObject(runtime));
|
|
25
|
-
std::vector<uint8_t> docCborVector = typedArrayBase.toVector(runtime);
|
|
26
|
-
slice_ref_uint8_t docCbor = { .ptr = docCborVector.data(), .len = docCborVector.size() };
|
|
27
|
-
|
|
28
|
-
WriteStrategyRs_t writeStrategy;
|
|
29
|
-
std::string writeStrategyStr = arguments[3].asString(runtime).utf8(runtime);
|
|
30
|
-
|
|
31
|
-
if (writeStrategyStr == "Merge") {
|
|
32
|
-
writeStrategy = WRITE_STRATEGY_RS_MERGE;
|
|
33
|
-
} else if (writeStrategyStr == "InsertIfAbsent") {
|
|
34
|
-
writeStrategy = WRITE_STRATEGY_RS_INSERT_IF_ABSENT;
|
|
35
|
-
} else if (writeStrategyStr == "InsertDefaultIfAbsent") {
|
|
36
|
-
writeStrategy = WRITE_STRATEGY_RS_INSERT_DEFAULT_IF_ABSENT;
|
|
37
|
-
} else if (writeStrategyStr == "UpdateDifferentValues") {
|
|
38
|
-
writeStrategy = WRITE_STRATEGY_RS_UPDATE_DIFFERENT_VALUES;
|
|
39
|
-
} else {
|
|
40
|
-
throw std::invalid_argument("Invalid write strategy");
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
std::string log_hint_str = jsTypedArrayToCString(runtime, arguments[4]);
|
|
44
|
-
const char *log_hint = log_hint_str.c_str();
|
|
45
|
-
|
|
46
|
-
CWriteTransaction_t *writeTransaction = jsPointerObjectToCPointer<CWriteTransaction_t>(runtime, arguments[5]);
|
|
47
|
-
|
|
48
|
-
DocIdResult_t res = ::ditto_collection_insert_value(ditto, collectionName, docCbor, writeStrategy, log_hint, writeTransaction);
|
|
49
|
-
|
|
50
|
-
Object obj(runtime);
|
|
51
|
-
obj.setProperty(runtime, "status_code", static_cast<double>(res.status_code));
|
|
52
|
-
obj.setProperty(runtime, "id", pointerToHexString(res.id.ptr));
|
|
53
|
-
return obj;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|