@dittolive/ditto 4.5.4-alpha.1 → 4.6.0
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 +5 -3
- package/README.md +2 -2
- package/node/ditto.cjs.js +1111 -563
- 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 +3 -11
- package/react-native/android/CMakeLists.txt +0 -1
- package/react-native/android/build.gradle +7 -3
- package/react-native/android/cpp-adapter.cpp +68 -59
- package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKModule.java +35 -0
- package/react-native/cpp/include/Arc.hpp +1 -1
- package/react-native/cpp/include/Attachment.h +5 -1
- package/react-native/cpp/include/DQL.h +9 -9
- package/react-native/cpp/include/FFIUtils.h +14 -0
- package/react-native/cpp/include/IO.h +13 -0
- package/react-native/cpp/include/Lifecycle.h +0 -1
- package/react-native/cpp/include/Misc.h +3 -0
- package/react-native/cpp/include/Utils.h +0 -2
- package/react-native/cpp/src/Attachment.cpp +200 -13
- package/react-native/cpp/src/Authentication.cpp +3 -3
- package/react-native/cpp/src/DQL.cpp +23 -23
- package/react-native/cpp/src/Document.cpp +10 -10
- package/react-native/cpp/src/FFIUtils.cpp +64 -0
- package/react-native/cpp/src/IO.cpp +35 -0
- package/react-native/cpp/src/Identity.cpp +3 -3
- package/react-native/cpp/src/Lifecycle.cpp +2 -19
- package/react-native/cpp/src/LiveQuery.cpp +3 -3
- package/react-native/cpp/src/Logger.cpp +171 -172
- package/react-native/cpp/src/Misc.cpp +52 -4
- package/react-native/cpp/src/Presence.cpp +1 -1
- package/react-native/cpp/src/SmallPeerInfo.cpp +1 -1
- package/react-native/cpp/src/Transports.cpp +10 -5
- package/react-native/cpp/src/Utils.cpp +110 -114
- package/react-native/cpp/src/main.cpp +28 -15
- package/react-native/dittoffi/dittoffi.h +328 -280
- package/react-native/ios/DittoRNSDK.mm +123 -71
- package/react-native/src/ditto.rn.ts +30 -6
- package/react-native/src/index.ts +7 -4
- package/react-native/src/sources/@cbor-redux.ts +1 -1
- package/react-native/src/sources/attachment-fetch-event.ts +2 -2
- package/react-native/src/sources/attachment-fetcher-manager.ts +5 -4
- package/react-native/src/sources/attachment-fetcher.ts +152 -21
- package/react-native/src/sources/attachment-token.ts +94 -13
- package/react-native/src/sources/attachment.ts +66 -19
- package/react-native/src/sources/augment.ts +13 -6
- package/react-native/src/sources/base-pending-cursor-operation.ts +22 -6
- package/react-native/src/sources/base-pending-id-specific-operation.ts +3 -0
- package/react-native/src/sources/bridge.ts +2 -2
- package/react-native/src/sources/cbor.ts +0 -15
- package/react-native/src/sources/collection-interface.ts +12 -6
- package/react-native/src/sources/collection.ts +9 -2
- package/react-native/src/sources/ditto.ts +26 -18
- package/react-native/src/sources/document-id.ts +11 -7
- package/react-native/src/sources/document-path.ts +4 -2
- package/react-native/src/sources/document.ts +49 -5
- package/react-native/src/sources/error-codes.ts +28 -0
- package/react-native/src/sources/error.ts +20 -1
- package/react-native/src/sources/essentials.ts +25 -3
- package/react-native/src/sources/ffi-error.ts +2 -1
- package/react-native/src/sources/ffi.ts +180 -102
- package/react-native/src/sources/internal.ts +37 -3
- package/react-native/src/sources/live-query-manager.ts +10 -1
- package/react-native/src/sources/live-query.ts +1 -1
- package/react-native/src/sources/observer-manager.ts +7 -0
- package/react-native/src/sources/pending-id-specific-operation.ts +2 -2
- package/react-native/src/sources/presence-manager.ts +12 -2
- package/react-native/src/sources/presence.ts +5 -0
- package/react-native/src/sources/query-result-item.ts +15 -0
- package/react-native/src/sources/small-peer-info.ts +2 -2
- package/react-native/src/sources/static-tcp-client.ts +2 -0
- package/react-native/src/sources/store-observer.ts +4 -2
- package/react-native/src/sources/store.ts +253 -3
- package/react-native/src/sources/sync.ts +6 -3
- package/react-native/src/sources/transport-config.ts +2 -2
- package/react-native/src/sources/update-results-map.ts +8 -0
- package/react-native/src/sources/write-transaction-collection.ts +1 -1
- package/react-native/src/sources/write-transaction.ts +1 -1
- package/types/ditto.d.ts +2866 -2568
- package/web/ditto.es6.js +1 -1
- package/web/ditto.umd.js +1 -1
- package/web/ditto.wasm +0 -0
- package/react-native/android/.project +0 -34
|
@@ -1,9 +1,52 @@
|
|
|
1
1
|
#include "Utils.h"
|
|
2
2
|
|
|
3
3
|
#include <Attachment.h>
|
|
4
|
+
#include <Arc.hpp>
|
|
4
5
|
|
|
5
6
|
namespace sharedjsi
|
|
6
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, BigInt::fromUint64(runtime, downloaded), BigInt::fromUint64(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
|
+
|
|
7
50
|
Function ditto_cancel_resolve_attachment(Runtime &runtime)
|
|
8
51
|
{
|
|
9
52
|
return Function::createFromHostFunction(runtime,
|
|
@@ -18,11 +61,10 @@ Function ditto_cancel_resolve_attachment(Runtime &runtime)
|
|
|
18
61
|
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
19
62
|
std::vector<uint8_t> id_vec = jsTypedArrayToCVector(runtime, arguments[1]);
|
|
20
63
|
slice_ref_uint8_t id = borrowVecAsOptRefSlice(id_vec);
|
|
21
|
-
|
|
22
|
-
uint64_t cancelToken = arguments[2].
|
|
23
|
-
|
|
24
|
-
::ditto_cancel_resolve_attachment(ditto, id, cancelToken);
|
|
25
|
-
return Value();
|
|
64
|
+
|
|
65
|
+
uint64_t cancelToken = arguments[2].asBigInt(runtime).asInt64(runtime);
|
|
66
|
+
|
|
67
|
+
return static_cast<double>(::ditto_cancel_resolve_attachment(ditto, id, cancelToken));
|
|
26
68
|
});
|
|
27
69
|
}
|
|
28
70
|
|
|
@@ -42,6 +84,52 @@ Function ditto_free_attachment_handle(Runtime &runtime)
|
|
|
42
84
|
});
|
|
43
85
|
}
|
|
44
86
|
|
|
87
|
+
Function ditto_get_attachment_status(Runtime &runtime)
|
|
88
|
+
{
|
|
89
|
+
return Function::createFromHostFunction(runtime,
|
|
90
|
+
PropNameID::forAscii(runtime,
|
|
91
|
+
STRINGIFIED_FUNC_NAME()),
|
|
92
|
+
0,
|
|
93
|
+
[](Runtime &runtime,
|
|
94
|
+
const Value &thisValue,
|
|
95
|
+
const Value *arguments,
|
|
96
|
+
size_t count) -> Value
|
|
97
|
+
{
|
|
98
|
+
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
99
|
+
std::vector<uint8_t> id_vec = jsTypedArrayToCVector(runtime, arguments[1]);
|
|
100
|
+
slice_ref_uint8_t id = borrowVecAsRefSlice(id_vec);
|
|
101
|
+
|
|
102
|
+
AttachmentHandleResult_t res = ::ditto_get_attachment_status(ditto, id);
|
|
103
|
+
|
|
104
|
+
Object obj(runtime);
|
|
105
|
+
obj.setProperty(runtime, "status_code", static_cast<double>(res.status_code));
|
|
106
|
+
obj.setProperty(runtime, "handle", cPointerToJSPointerObject<AttachmentHandle_t>(runtime, res.handle));
|
|
107
|
+
return obj;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
Function ditto_get_complete_attachment_data(Runtime &runtime)
|
|
112
|
+
{
|
|
113
|
+
return Function::createFromHostFunction(runtime,
|
|
114
|
+
PropNameID::forAscii(runtime,
|
|
115
|
+
STRINGIFIED_FUNC_NAME()),
|
|
116
|
+
0,
|
|
117
|
+
[](Runtime &runtime,
|
|
118
|
+
const Value &thisValue,
|
|
119
|
+
const Value *arguments,
|
|
120
|
+
size_t count) -> Value
|
|
121
|
+
{
|
|
122
|
+
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
123
|
+
AttachmentHandle_t* handle = jsPointerObjectToCPointer<AttachmentHandle_t>(runtime, arguments[1]);
|
|
124
|
+
AttachmentDataResult_t res = ::ditto_get_complete_attachment_data(ditto, handle);
|
|
125
|
+
|
|
126
|
+
Object obj(runtime);
|
|
127
|
+
obj.setProperty(runtime, "status_code", static_cast<double>(res.status));
|
|
128
|
+
obj.setProperty(runtime, "data", cSlicedBoxToJSSlicedBox(runtime, res.data));
|
|
129
|
+
return obj;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
45
133
|
Function ditto_get_complete_attachment_path(Runtime &runtime)
|
|
46
134
|
{
|
|
47
135
|
return Function::createFromHostFunction(runtime,
|
|
@@ -55,9 +143,9 @@ Function ditto_get_complete_attachment_path(Runtime &runtime)
|
|
|
55
143
|
{
|
|
56
144
|
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
57
145
|
AttachmentHandle_t *attachmentHandler = jsPointerObjectToCPointer<AttachmentHandle_t>(runtime, arguments[1]);
|
|
58
|
-
|
|
59
|
-
::ditto_get_complete_attachment_path(ditto, attachmentHandler);
|
|
60
|
-
return
|
|
146
|
+
|
|
147
|
+
char *res = ::ditto_get_complete_attachment_path(ditto, attachmentHandler);
|
|
148
|
+
return cPointerToJSPointerObject<char>(runtime, res);
|
|
61
149
|
});
|
|
62
150
|
}
|
|
63
151
|
|
|
@@ -74,13 +162,112 @@ Function ditto_new_attachment_from_bytes(Runtime &runtime)
|
|
|
74
162
|
{
|
|
75
163
|
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
76
164
|
std::vector<uint8_t> bytes_vec = jsTypedArrayToCVector(runtime, arguments[1]);
|
|
77
|
-
slice_ref_uint8_t bytes =
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
::ditto_new_attachment_from_bytes(ditto, bytes,
|
|
81
|
-
|
|
165
|
+
slice_ref_uint8_t bytes = borrowVecAsRefSlice(bytes_vec);
|
|
166
|
+
|
|
167
|
+
CAttachment_t c_attachment;
|
|
168
|
+
uint32_t res = ::ditto_new_attachment_from_bytes(ditto, bytes, &c_attachment);
|
|
169
|
+
|
|
170
|
+
if (res != 0) {
|
|
171
|
+
// It failed, bubble up the error.
|
|
172
|
+
return static_cast<double>(res);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
Object const& attachment = arguments[2].getObject(runtime);
|
|
176
|
+
|
|
177
|
+
attachment.setProperty(runtime, "len", BigInt::fromUint64(runtime , c_attachment.len));
|
|
178
|
+
// Factor this out as: cSliceToUInt8Array()
|
|
179
|
+
std::vector<uint8_t> id(c_attachment.id.ptr, c_attachment.id.ptr + c_attachment.id.len);
|
|
180
|
+
TypedArray<TypedArrayKind::Uint8Array> typedArray(runtime, id);
|
|
181
|
+
attachment.setProperty(runtime, "id", typedArray);
|
|
182
|
+
attachment.setProperty(runtime, "handle", cPointerToJSPointerObject(runtime, c_attachment.handle));
|
|
183
|
+
|
|
184
|
+
return 0;
|
|
82
185
|
});
|
|
83
186
|
}
|
|
84
187
|
|
|
188
|
+
Function ditto_new_attachment_from_file(Runtime &runtime)
|
|
189
|
+
{
|
|
190
|
+
return Function::createFromHostFunction(runtime,
|
|
191
|
+
PropNameID::forAscii(runtime,
|
|
192
|
+
STRINGIFIED_FUNC_NAME()),
|
|
193
|
+
0,
|
|
194
|
+
[](Runtime &runtime,
|
|
195
|
+
const Value &thisValue,
|
|
196
|
+
const Value *arguments,
|
|
197
|
+
size_t count) -> Value
|
|
198
|
+
{
|
|
199
|
+
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
200
|
+
std::string source_path_str = jsTypedArrayToCString(runtime, arguments[1]);
|
|
201
|
+
std::string file_operation_str = arguments[2].toString(runtime).utf8(runtime);
|
|
202
|
+
|
|
203
|
+
AttachmentFileOperation_t file_operation;
|
|
204
|
+
if (file_operation_str == "Copy") {
|
|
205
|
+
file_operation = ATTACHMENT_FILE_OPERATION_COPY;
|
|
206
|
+
} else if (file_operation_str == "Move") {
|
|
207
|
+
file_operation = ATTACHMENT_FILE_OPERATION_MOVE;
|
|
208
|
+
} else {
|
|
209
|
+
throw "Invalid attachment file operation.";
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
CAttachment_t c_attachment;
|
|
213
|
+
uint32_t res = ::ditto_new_attachment_from_file(ditto, source_path_str.c_str(), file_operation, &c_attachment);
|
|
214
|
+
|
|
215
|
+
if (res != 0) {
|
|
216
|
+
// It failed, bubble up the error.
|
|
217
|
+
return static_cast<double>(res);
|
|
218
|
+
}
|
|
85
219
|
|
|
220
|
+
Object const& attachment = arguments[3].getObject(runtime);
|
|
221
|
+
|
|
222
|
+
attachment.setProperty(runtime, "len", BigInt::fromUint64(runtime, c_attachment.len));
|
|
223
|
+
// Factor this out as: cSliceToUInt8Array()
|
|
224
|
+
std::vector<uint8_t> id(c_attachment.id.ptr, c_attachment.id.ptr + c_attachment.id.len);
|
|
225
|
+
TypedArray<TypedArrayKind::Uint8Array> typedArray(runtime, id);
|
|
226
|
+
attachment.setProperty(runtime, "id", typedArray);
|
|
227
|
+
attachment.setProperty(runtime, "handle", cPointerToJSPointerObject(runtime, c_attachment.handle));
|
|
228
|
+
|
|
229
|
+
return 0;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
Function ditto_resolve_attachment(Runtime &runtime)
|
|
234
|
+
{
|
|
235
|
+
return Function::createFromHostFunction(runtime,
|
|
236
|
+
PropNameID::forAscii(runtime,
|
|
237
|
+
STRINGIFIED_FUNC_NAME()),
|
|
238
|
+
0,
|
|
239
|
+
[](Runtime &runtime,
|
|
240
|
+
const Value &thisValue,
|
|
241
|
+
const Value *arguments,
|
|
242
|
+
size_t count) -> Value
|
|
243
|
+
{
|
|
244
|
+
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
245
|
+
|
|
246
|
+
std::vector<uint8_t> id_vec = jsTypedArrayToCVector(runtime, arguments[1]);
|
|
247
|
+
slice_ref_uint8_t id = borrowVecAsRefSlice(id_vec);
|
|
248
|
+
|
|
249
|
+
Function onCompleteCallback = arguments[2].getObject(runtime).getFunction(runtime);
|
|
250
|
+
Function onProgressCallback = arguments[3].getObject(runtime).getFunction(runtime);
|
|
251
|
+
Function onDeleteCallback = arguments[4].getObject(runtime).getFunction(runtime);
|
|
252
|
+
|
|
253
|
+
AttachmentResolver resolver(std::move(onCompleteCallback),
|
|
254
|
+
std::move(onProgressCallback),
|
|
255
|
+
std::move(onDeleteCallback));
|
|
256
|
+
Arc<AttachmentResolver> wrappedStateFfiWrapper(std::move(resolver));
|
|
257
|
+
|
|
258
|
+
CancelTokenResult_t res = ::ditto_resolve_attachment(ditto,
|
|
259
|
+
id,
|
|
260
|
+
Arc<AttachmentResolver>::into_raw(std::move(wrappedStateFfiWrapper)),
|
|
261
|
+
nullptr,
|
|
262
|
+
nullptr,
|
|
263
|
+
v_on_complete,
|
|
264
|
+
v_on_progress,
|
|
265
|
+
v_on_deleted);
|
|
266
|
+
|
|
267
|
+
Object obj(runtime);
|
|
268
|
+
obj.setProperty(runtime, "status_code", static_cast<double>(res.status_code));
|
|
269
|
+
obj.setProperty(runtime, "cancel_token", BigInt::fromInt64(runtime, res.cancel_token));
|
|
270
|
+
return obj;
|
|
271
|
+
});
|
|
272
|
+
}
|
|
86
273
|
}
|
|
@@ -92,7 +92,7 @@ Function ditto_auth_client_get_app_id(Runtime &runtime)
|
|
|
92
92
|
size_t count) -> Value
|
|
93
93
|
{
|
|
94
94
|
char *appId = ::ditto_auth_client_get_app_id(jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]));
|
|
95
|
-
return
|
|
95
|
+
return cPointerToJSPointerObject<char>(runtime, appId);
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
|
|
@@ -108,7 +108,7 @@ Function ditto_auth_client_get_site_id(Runtime &runtime)
|
|
|
108
108
|
size_t count) -> Value
|
|
109
109
|
{
|
|
110
110
|
uint64_t siteId = ::ditto_auth_client_get_site_id(jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]));
|
|
111
|
-
return
|
|
111
|
+
return BigInt::fromUint64(runtime, siteId);
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
114
|
|
|
@@ -221,7 +221,7 @@ Function ditto_auth_client_user_id(Runtime &runtime)
|
|
|
221
221
|
size_t count) -> Value
|
|
222
222
|
{
|
|
223
223
|
char *res = ::ditto_auth_client_user_id(jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]));
|
|
224
|
-
return
|
|
224
|
+
return cPointerToJSPointerObject<char>(runtime, res);
|
|
225
225
|
});
|
|
226
226
|
}
|
|
227
227
|
}
|
|
@@ -18,7 +18,7 @@ void v_change_handler_with_query_result(void *ctx, ChangeHandlerWithQueryResult_
|
|
|
18
18
|
Arc<Function> jsCallback /* = */ (borrowedJsCallback);
|
|
19
19
|
ditto_enqueue_call([=](Runtime *jsi) {
|
|
20
20
|
Runtime &runtime = *jsi;
|
|
21
|
-
|
|
21
|
+
dittoffi_query_result_t *query_result = result.query_result;
|
|
22
22
|
|
|
23
23
|
Object obj(runtime);
|
|
24
24
|
obj.setProperty(runtime, "query_result", cPointerToJSPointerObject(runtime, query_result));
|
|
@@ -28,7 +28,7 @@ void v_change_handler_with_query_result(void *ctx, ChangeHandlerWithQueryResult_
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
Function
|
|
31
|
+
Function dittoffi_try_add_sync_subscription(Runtime &runtime)
|
|
32
32
|
{
|
|
33
33
|
return Function::createFromHostFunction(runtime,
|
|
34
34
|
PropNameID::forAscii(runtime,
|
|
@@ -46,7 +46,7 @@ Function dittoffi_try_experimental_add_dql_subscription(Runtime &runtime)
|
|
|
46
46
|
std::vector<uint8_t> query_args_cbor_vec = jsTypedArrayToCVector(runtime, arguments[2]);
|
|
47
47
|
slice_ref_uint8_t query_args_cbor = borrowVecAsOptRefSlice(query_args_cbor_vec);
|
|
48
48
|
|
|
49
|
-
dittoffi_result_void_t res = ::
|
|
49
|
+
dittoffi_result_void_t res = ::dittoffi_try_add_sync_subscription(ditto, query, query_args_cbor);
|
|
50
50
|
|
|
51
51
|
Object obj(runtime);
|
|
52
52
|
obj.setProperty(runtime, "error", cPointerToJSPointerObject(runtime, res.error));
|
|
@@ -54,7 +54,7 @@ Function dittoffi_try_experimental_add_dql_subscription(Runtime &runtime)
|
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
Function
|
|
57
|
+
Function dittoffi_try_remove_sync_subscription(Runtime &runtime)
|
|
58
58
|
{
|
|
59
59
|
return Function::createFromHostFunction(runtime,
|
|
60
60
|
PropNameID::forAscii(runtime,
|
|
@@ -71,7 +71,7 @@ Function dittoffi_try_experimental_remove_dql_subscription(Runtime &runtime)
|
|
|
71
71
|
|
|
72
72
|
std::vector<uint8_t> query_args_cbor_vec = jsTypedArrayToCVector(runtime, arguments[2]);
|
|
73
73
|
slice_ref_uint8_t query_args_cbor = borrowVecAsOptRefSlice(query_args_cbor_vec);
|
|
74
|
-
dittoffi_result_void_t res = ::
|
|
74
|
+
dittoffi_result_void_t res = ::dittoffi_try_remove_sync_subscription(ditto, query, query_args_cbor);
|
|
75
75
|
|
|
76
76
|
Object obj(runtime);
|
|
77
77
|
obj.setProperty(runtime, "error", cPointerToJSPointerObject(runtime, res.error));
|
|
@@ -79,7 +79,7 @@ Function dittoffi_try_experimental_remove_dql_subscription(Runtime &runtime)
|
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
Function
|
|
82
|
+
Function dittoffi_try_exec_statement(Runtime &runtime)
|
|
83
83
|
{
|
|
84
84
|
return Function::createFromHostFunction(runtime,
|
|
85
85
|
PropNameID::forAscii(runtime,
|
|
@@ -97,7 +97,7 @@ Function dittoffi_try_experimental_exec_statement_str(Runtime &runtime)
|
|
|
97
97
|
|
|
98
98
|
std::vector<uint8_t> args_vec = jsTypedArrayToCVector(runtime, arguments[3]);
|
|
99
99
|
slice_ref_uint8_t args_cbor = borrowVecAsOptRefSlice(args_vec);
|
|
100
|
-
|
|
100
|
+
dittoffi_result_dittoffi_query_result_ptr res = ::dittoffi_try_exec_statement(ditto, writeTransaction, query, args_cbor);
|
|
101
101
|
|
|
102
102
|
Object obj(runtime);
|
|
103
103
|
obj.setProperty(runtime, "success", cPointerToJSPointerObject(runtime, res.success));
|
|
@@ -147,14 +147,14 @@ Function dittoffi_try_experimental_register_change_observer_str_detached(Runtime
|
|
|
147
147
|
v_change_handler_with_query_result);
|
|
148
148
|
|
|
149
149
|
Object obj(runtime);
|
|
150
|
-
obj.setProperty(runtime, "success",
|
|
150
|
+
obj.setProperty(runtime, "success", BigInt::fromInt64(runtime, res.success));
|
|
151
151
|
obj.setProperty(runtime, "error", cPointerToJSPointerObject(runtime, res.error));
|
|
152
152
|
return obj;
|
|
153
153
|
});
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
|
|
157
|
-
Function
|
|
157
|
+
Function dittoffi_query_result_item_count(Runtime &runtime)
|
|
158
158
|
{
|
|
159
159
|
return Function::createFromHostFunction(runtime,
|
|
160
160
|
PropNameID::forAscii(runtime, STRINGIFIED_FUNC_NAME()),
|
|
@@ -164,13 +164,13 @@ Function ditto_dql_response_result_count(Runtime &runtime)
|
|
|
164
164
|
const Value *arguments,
|
|
165
165
|
size_t count) -> Value
|
|
166
166
|
{
|
|
167
|
-
size_t res = ::
|
|
167
|
+
size_t res = ::dittoffi_query_result_item_count(jsPointerObjectToCPointer<dittoffi_query_result>(runtime, arguments[0]));
|
|
168
168
|
return static_cast<double>(res);
|
|
169
169
|
});
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
|
|
173
|
-
Function
|
|
173
|
+
Function dittoffi_query_result_item_at(Runtime &runtime)
|
|
174
174
|
{
|
|
175
175
|
return Function::createFromHostFunction(runtime,
|
|
176
176
|
PropNameID::forAscii(runtime, STRINGIFIED_FUNC_NAME()),
|
|
@@ -181,15 +181,15 @@ Function ditto_dql_response_result_at(Runtime &runtime)
|
|
|
181
181
|
size_t count) -> Value
|
|
182
182
|
{
|
|
183
183
|
|
|
184
|
-
|
|
184
|
+
dittoffi_query_result *dql_response = jsPointerObjectToCPointer<dittoffi_query_result>(runtime, arguments[0]);
|
|
185
185
|
size_t idx = arguments[1].asNumber();
|
|
186
186
|
|
|
187
|
-
|
|
187
|
+
dittoffi_query_result_item_t *res = ::dittoffi_query_result_item_at(dql_response, idx);
|
|
188
188
|
return cPointerToJSPointerObject(runtime, res);
|
|
189
189
|
});
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
Function
|
|
192
|
+
Function dittoffi_query_result_mutated_document_id_count(Runtime &runtime)
|
|
193
193
|
{
|
|
194
194
|
return Function::createFromHostFunction(runtime,
|
|
195
195
|
PropNameID::forAscii(runtime, STRINGIFIED_FUNC_NAME()),
|
|
@@ -199,12 +199,12 @@ Function ditto_dql_response_affected_document_id_count(Runtime &runtime)
|
|
|
199
199
|
const Value *arguments,
|
|
200
200
|
size_t count) -> Value
|
|
201
201
|
{
|
|
202
|
-
size_t res = ::
|
|
202
|
+
size_t res = ::dittoffi_query_result_mutated_document_id_count(jsPointerObjectToCPointer<dittoffi_query_result>(runtime, arguments[0]));
|
|
203
203
|
return static_cast<double>(res);
|
|
204
204
|
});
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
Function
|
|
207
|
+
Function dittoffi_query_result_mutated_document_id_at(Runtime &runtime)
|
|
208
208
|
{
|
|
209
209
|
return Function::createFromHostFunction(runtime,
|
|
210
210
|
PropNameID::forAscii(runtime, STRINGIFIED_FUNC_NAME()),
|
|
@@ -215,15 +215,15 @@ Function ditto_dql_response_affected_document_id_at(Runtime &runtime)
|
|
|
215
215
|
size_t count) -> Value
|
|
216
216
|
{
|
|
217
217
|
|
|
218
|
-
|
|
218
|
+
dittoffi_query_result *dql_response = jsPointerObjectToCPointer<dittoffi_query_result>(runtime, arguments[0]);
|
|
219
219
|
size_t idx = arguments[1].asNumber();
|
|
220
220
|
|
|
221
|
-
slice_boxed_uint8_t res = ::
|
|
221
|
+
slice_boxed_uint8_t res = ::dittoffi_query_result_mutated_document_id_at(dql_response, idx);
|
|
222
222
|
return cSlicedBoxToJSSlicedBox(runtime, res);
|
|
223
223
|
});
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
Function
|
|
226
|
+
Function dittoffi_query_result_item_cbor(Runtime &runtime)
|
|
227
227
|
{
|
|
228
228
|
return Function::createFromHostFunction(runtime,
|
|
229
229
|
PropNameID::forAscii(runtime, STRINGIFIED_FUNC_NAME()),
|
|
@@ -233,12 +233,12 @@ Function ditto_result_cbor(Runtime &runtime)
|
|
|
233
233
|
const Value *arguments,
|
|
234
234
|
size_t count) -> Value
|
|
235
235
|
{
|
|
236
|
-
slice_boxed_uint8_t res = ::
|
|
236
|
+
slice_boxed_uint8_t res = ::dittoffi_query_result_item_cbor(jsPointerObjectToCPointer<dittoffi_query_result_item_t>(runtime, arguments[0]));
|
|
237
237
|
return cSlicedBoxToJSSlicedBox(runtime, res);
|
|
238
238
|
});
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
-
Function
|
|
241
|
+
Function dittoffi_query_result_item_json(Runtime &runtime)
|
|
242
242
|
{
|
|
243
243
|
return Function::createFromHostFunction(runtime,
|
|
244
244
|
PropNameID::forAscii(runtime, STRINGIFIED_FUNC_NAME()),
|
|
@@ -249,8 +249,8 @@ Function ditto_result_json(Runtime &runtime)
|
|
|
249
249
|
size_t count) -> Value
|
|
250
250
|
{
|
|
251
251
|
|
|
252
|
-
char *res = ::
|
|
253
|
-
return
|
|
252
|
+
char *res = ::dittoffi_query_result_item_json(jsPointerObjectToCPointer<dittoffi_query_result_item_t>(runtime, arguments[0]));
|
|
253
|
+
return cPointerToJSPointerObject<char>(runtime, res);
|
|
254
254
|
});
|
|
255
255
|
}
|
|
256
256
|
}
|
|
@@ -52,10 +52,10 @@ Function ditto_document_id_query_compatible(Runtime &runtime)
|
|
|
52
52
|
const Value *arguments,
|
|
53
53
|
size_t count) -> Value
|
|
54
54
|
{
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
std::vector<uint8_t> id_vec = jsTypedArrayToCVector(runtime, arguments[0]);
|
|
57
57
|
slice_ref_uint8_t id = borrowVecAsRefSlice(id_vec);
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
std::string stringPrimitiveStr = arguments[1].getString(runtime).utf8(runtime);
|
|
60
60
|
StringPrimitiveFormat_t stringPrimitiveFormat;
|
|
61
61
|
if (stringPrimitiveStr == "WithQuotes") {
|
|
@@ -65,9 +65,9 @@ Function ditto_document_id_query_compatible(Runtime &runtime)
|
|
|
65
65
|
} else {
|
|
66
66
|
throw std::invalid_argument("Invalid string primitive format.");
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
|
|
69
69
|
char *res = ::ditto_document_id_query_compatible(id, stringPrimitiveFormat);
|
|
70
|
-
return
|
|
70
|
+
return cPointerToJSPointerObject<char>(runtime, res);
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
|
|
@@ -85,7 +85,7 @@ Function ditto_document_get_cbor_with_path_type(Runtime &runtime) {
|
|
|
85
85
|
std::string path_str = jsTypedArrayToCString(runtime, arguments[1]);
|
|
86
86
|
const char *path = path_str.c_str();
|
|
87
87
|
std::string pathTypeStr = arguments[2].asString(runtime).utf8(runtime);
|
|
88
|
-
|
|
88
|
+
|
|
89
89
|
static const std::unordered_map<std::string, PathAccessorType_t> lookup = {
|
|
90
90
|
{"String", PATH_ACCESSOR_TYPE_STRING},
|
|
91
91
|
{"Number", PATH_ACCESSOR_TYPE_NUMBER},
|
|
@@ -104,7 +104,7 @@ Function ditto_document_get_cbor_with_path_type(Runtime &runtime) {
|
|
|
104
104
|
{"Rga", PATH_ACCESSOR_TYPE_R_W_MAP},
|
|
105
105
|
{"RWMap", PATH_ACCESSOR_TYPE_R_W_MAP},
|
|
106
106
|
};
|
|
107
|
-
|
|
107
|
+
|
|
108
108
|
PathAccessorType_t path_type;
|
|
109
109
|
auto it = lookup.find(pathTypeStr);
|
|
110
110
|
if (it != lookup.end()) {
|
|
@@ -112,9 +112,9 @@ Function ditto_document_get_cbor_with_path_type(Runtime &runtime) {
|
|
|
112
112
|
} else {
|
|
113
113
|
throw std::invalid_argument("Invalid path type string");
|
|
114
114
|
}
|
|
115
|
-
|
|
115
|
+
|
|
116
116
|
CBORPathResult_t res = ::ditto_document_get_cbor_with_path_type(document, path, path_type);
|
|
117
|
-
|
|
117
|
+
|
|
118
118
|
Object obj(runtime);
|
|
119
119
|
obj.setProperty(runtime, "status_code", static_cast<double>(res.status_code));
|
|
120
120
|
obj.setProperty(runtime, "cbor", cSlicedBoxToJSSlicedBox(runtime, res.cbor));
|
|
@@ -134,10 +134,10 @@ Function ditto_validate_document_id(Runtime &runtime)
|
|
|
134
134
|
const Value *arguments,
|
|
135
135
|
size_t count) -> Value
|
|
136
136
|
{
|
|
137
|
-
|
|
137
|
+
|
|
138
138
|
std::vector<uint8_t> doc_id_vec = jsTypedArrayToCVector(runtime, arguments[0]);
|
|
139
139
|
slice_ref_uint8_t doc_id = borrowVecAsRefSlice(doc_id_vec);
|
|
140
|
-
|
|
140
|
+
|
|
141
141
|
slice_boxed_uint8 *out_cbor = jsPointerObjectToCPointer<slice_boxed_uint8>(runtime, arguments[1]);
|
|
142
142
|
uint32_t res = ::ditto_validate_document_id(doc_id, out_cbor);
|
|
143
143
|
return static_cast<double>(res);
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
return String::createFromUtf8(runtime, jsPointerObjectToCPointer<char>(runtime, arguments[0]));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
Function boxCStringIntoString(Runtime &runtime) {
|
|
23
|
+
return Function::createFromHostFunction(runtime,
|
|
24
|
+
PropNameID::forAscii(runtime,
|
|
25
|
+
STRINGIFIED_FUNC_NAME()),
|
|
26
|
+
0,
|
|
27
|
+
[](Runtime &runtime,
|
|
28
|
+
const Value &thisValue,
|
|
29
|
+
const Value *arguments,
|
|
30
|
+
size_t count) -> Value
|
|
31
|
+
{
|
|
32
|
+
char *str = jsPointerObjectToCPointer<char>(runtime, arguments[0]);
|
|
33
|
+
if (str) {
|
|
34
|
+
String res = String::createFromUtf8(runtime, str);
|
|
35
|
+
::ditto_c_string_free(str);
|
|
36
|
+
return res;
|
|
37
|
+
} else {
|
|
38
|
+
return Value::null();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
Function withOutBoxCBytes(Runtime &runtime) {
|
|
44
|
+
return Function::createFromHostFunction(runtime,
|
|
45
|
+
PropNameID::forAscii(runtime,
|
|
46
|
+
STRINGIFIED_FUNC_NAME()),
|
|
47
|
+
0,
|
|
48
|
+
[](Runtime &runtime,
|
|
49
|
+
const Value &thisValue,
|
|
50
|
+
const Value *arguments,
|
|
51
|
+
size_t count) -> Value
|
|
52
|
+
{
|
|
53
|
+
auto callback = arguments[0].asObject(runtime).asFunction(runtime);
|
|
54
|
+
slice_boxed_uint8 box_c_bytes = { 0 };
|
|
55
|
+
auto out_box_cbytes = &box_c_bytes;
|
|
56
|
+
auto out_box_cbytes_js = cPointerToJSPointerObject<slice_boxed_uint8>(runtime, out_box_cbytes);
|
|
57
|
+
|
|
58
|
+
callback.call(runtime, out_box_cbytes_js);
|
|
59
|
+
|
|
60
|
+
return cSlicedBoxToJSSlicedBox(runtime, box_c_bytes);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -7,7 +7,7 @@ namespace sharedjsi
|
|
|
7
7
|
|
|
8
8
|
Object convertConfigResultToJSIObject(Runtime &runtime, IdentityConfigResult_t result) {
|
|
9
9
|
Object obj(runtime);
|
|
10
|
-
obj.setProperty(runtime, "status_code", (
|
|
10
|
+
obj.setProperty(runtime, "status_code", static_cast<double>(result.status_code));
|
|
11
11
|
obj.setProperty(runtime, "identity_config", cPointerToJSPointerObject(runtime, result.identity_config));
|
|
12
12
|
return obj;
|
|
13
13
|
}
|
|
@@ -49,7 +49,7 @@ Function ditto_identity_config_make_offline_playground(Runtime &runtime)
|
|
|
49
49
|
{
|
|
50
50
|
std::string app_id_str = jsTypedArrayToCString(runtime, arguments[0]);
|
|
51
51
|
const char *app_id = app_id_str.c_str();
|
|
52
|
-
uint64_t site_id = arguments[1].
|
|
52
|
+
uint64_t site_id = arguments[1].asBigInt(runtime).asUint64(runtime);
|
|
53
53
|
|
|
54
54
|
IdentityConfigResult_t config_result = ::ditto_identity_config_make_offline_playground(app_id, site_id);
|
|
55
55
|
return convertConfigResultToJSIObject(runtime, config_result);
|
|
@@ -92,7 +92,7 @@ Function ditto_identity_config_make_shared_key(Runtime &runtime)
|
|
|
92
92
|
std::string shared_key_str = jsTypedArrayToCString(runtime, arguments[1]);
|
|
93
93
|
const char *shared_key = shared_key_str.c_str();
|
|
94
94
|
|
|
95
|
-
uint64_t site_id = arguments[2].
|
|
95
|
+
uint64_t site_id = arguments[2].asBigInt(runtime).asUint64(runtime);
|
|
96
96
|
|
|
97
97
|
IdentityConfigResult_t config_result = ::ditto_identity_config_make_shared_key(app_id, shared_key, site_id);
|
|
98
98
|
return convertConfigResultToJSIObject(runtime, config_result);
|