@dittolive/ditto 4.5.1-experimental.aarch64-linux.1.aarch64 → 4.5.2-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DittoReactNative.podspec +25 -0
- package/README.md +2 -2
- package/node/ditto.cjs.js +1 -1
- package/node/ditto.cjs.js.map +1 -0
- package/node/ditto.cjs.pretty.js +9655 -0
- package/node/ditto.cjs.pretty.js.map +1 -0
- package/node/ditto.darwin-arm64.node +0 -0
- package/node/ditto.darwin-x64.node +0 -0
- package/node/{ditto.linux-arm64.node → ditto.linux-x64.node} +0 -0
- package/node/transports.darwin-arm64.node +0 -0
- package/node/transports.darwin-x64.node +0 -0
- package/package.json +2 -1
- package/react-native/android/CMakeLists.txt +37 -0
- package/react-native/android/build.gradle +186 -0
- package/react-native/android/cpp-adapter.cpp +254 -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 +85 -0
- package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKPackage.java +28 -0
- package/react-native/cpp/include/Arc.hpp +141 -0
- package/react-native/cpp/include/Attachment.h +16 -0
- package/react-native/cpp/include/Authentication.h +23 -0
- package/react-native/cpp/include/Collection.h +13 -0
- package/react-native/cpp/include/DQL.h +21 -0
- package/react-native/cpp/include/Document.h +17 -0
- package/react-native/cpp/include/Identity.h +17 -0
- package/react-native/cpp/include/Lifecycle.h +17 -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 +27 -0
- package/react-native/cpp/include/Presence.h +14 -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 +61 -0
- package/react-native/cpp/include/main.h +10 -0
- package/react-native/cpp/src/Attachment.cpp +86 -0
- package/react-native/cpp/src/Authentication.cpp +227 -0
- package/react-native/cpp/src/Collection.cpp +54 -0
- package/react-native/cpp/src/DQL.cpp +256 -0
- package/react-native/cpp/src/Document.cpp +146 -0
- package/react-native/cpp/src/Identity.cpp +123 -0
- package/react-native/cpp/src/Lifecycle.cpp +110 -0
- package/react-native/cpp/src/LiveQuery.cpp +63 -0
- package/react-native/cpp/src/Logger.cpp +200 -0
- package/react-native/cpp/src/Misc.cpp +283 -0
- package/react-native/cpp/src/Presence.cpp +79 -0
- package/react-native/cpp/src/SmallPeerInfo.cpp +142 -0
- package/react-native/cpp/src/Transports.cpp +270 -0
- package/react-native/cpp/src/TypedArray.cpp +303 -0
- package/react-native/cpp/src/Utils.cpp +138 -0
- package/react-native/cpp/src/main.cpp +152 -0
- package/react-native/dittoffi/dittoffi.h +4700 -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 +107 -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 +92 -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 +88 -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 +91 -0
- package/react-native/src/environment/environment.fallback.ts +4 -0
- package/react-native/src/index.ts +26 -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 +144 -0
- package/react-native/src/sources/attachment-fetcher.ts +134 -0
- package/react-native/src/sources/attachment-token.ts +48 -0
- package/react-native/src/sources/attachment.ts +74 -0
- package/react-native/src/sources/augment.ts +101 -0
- package/react-native/src/sources/authenticator.ts +314 -0
- package/react-native/src/sources/base-pending-cursor-operation.ts +239 -0
- package/react-native/src/sources/base-pending-id-specific-operation.ts +109 -0
- package/react-native/src/sources/bridge.ts +553 -0
- package/react-native/src/sources/build-time-constants.ts +8 -0
- package/react-native/src/sources/cbor.ts +35 -0
- package/react-native/src/sources/collection-interface.ts +67 -0
- package/react-native/src/sources/collection.ts +212 -0
- package/react-native/src/sources/collections-event.ts +99 -0
- package/react-native/src/sources/counter.ts +82 -0
- package/react-native/src/sources/ditto.ts +979 -0
- package/react-native/src/sources/document-id.ts +159 -0
- package/react-native/src/sources/document-path.ts +306 -0
- package/react-native/src/sources/document.ts +193 -0
- package/react-native/src/sources/epilogue.ts +30 -0
- package/react-native/src/sources/error-codes.ts +52 -0
- package/react-native/src/sources/error.ts +208 -0
- package/react-native/src/sources/essentials.ts +53 -0
- package/react-native/src/sources/ffi-error.ts +122 -0
- package/react-native/src/sources/ffi.ts +2012 -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 +109 -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 +102 -0
- package/react-native/src/sources/live-query.ts +166 -0
- package/react-native/src/sources/logger.ts +196 -0
- package/react-native/src/sources/main.ts +60 -0
- package/react-native/src/sources/observer-manager.ts +178 -0
- package/react-native/src/sources/observer.ts +79 -0
- package/react-native/src/sources/pending-collections-operation.ts +232 -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 +161 -0
- package/react-native/src/sources/presence.ts +233 -0
- package/react-native/src/sources/query-result-item.ts +116 -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 +177 -0
- package/react-native/src/sources/static-tcp-client.ts +6 -0
- package/react-native/src/sources/store-observer.ts +177 -0
- package/react-native/src/sources/store.ts +385 -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 +559 -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 +57 -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/types/ditto.d.ts.map +1 -0
- package/web/ditto.es6.js +1 -1
- package/web/ditto.es6.js.map +1 -0
- package/web/ditto.es6.pretty.js +12600 -0
- package/web/ditto.es6.pretty.js.map +1 -0
- package/web/ditto.umd.js +1 -1
- package/web/ditto.umd.js.map +1 -0
- package/web/ditto.umd.pretty.js +12669 -0
- package/web/ditto.umd.pretty.js.map +1 -0
- package/web/ditto.wasm +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#include "Utils.h"
|
|
2
|
+
|
|
3
|
+
#include <Attachment.h>
|
|
4
|
+
|
|
5
|
+
namespace sharedjsi
|
|
6
|
+
{
|
|
7
|
+
Function ditto_cancel_resolve_attachment(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
|
+
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
19
|
+
std::vector<uint8_t> id_vec = jsTypedArrayToCVector(runtime, arguments[1]);
|
|
20
|
+
slice_ref_uint8_t id = borrowVecAsOptRefSlice(id_vec);
|
|
21
|
+
|
|
22
|
+
uint64_t cancelToken = arguments[2].asNumber();
|
|
23
|
+
|
|
24
|
+
::ditto_cancel_resolve_attachment(ditto, id, cancelToken);
|
|
25
|
+
return Value();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
Function ditto_free_attachment_handle(Runtime &runtime)
|
|
30
|
+
{
|
|
31
|
+
return Function::createFromHostFunction(runtime,
|
|
32
|
+
PropNameID::forAscii(runtime,
|
|
33
|
+
STRINGIFIED_FUNC_NAME()),
|
|
34
|
+
0,
|
|
35
|
+
[](Runtime &runtime,
|
|
36
|
+
const Value &thisValue,
|
|
37
|
+
const Value *arguments,
|
|
38
|
+
size_t count) -> Value
|
|
39
|
+
{
|
|
40
|
+
::ditto_free_attachment_handle(jsPointerObjectToCPointer<AttachmentHandle_t>(runtime, arguments[0]));
|
|
41
|
+
return Value();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
Function ditto_get_complete_attachment_path(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
|
+
AttachmentHandle_t *attachmentHandler = jsPointerObjectToCPointer<AttachmentHandle_t>(runtime, arguments[1]);
|
|
58
|
+
|
|
59
|
+
::ditto_get_complete_attachment_path(ditto, attachmentHandler);
|
|
60
|
+
return Value();
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Function ditto_new_attachment_from_bytes(Runtime &runtime)
|
|
65
|
+
{
|
|
66
|
+
return Function::createFromHostFunction(runtime,
|
|
67
|
+
PropNameID::forAscii(runtime,
|
|
68
|
+
STRINGIFIED_FUNC_NAME()),
|
|
69
|
+
0,
|
|
70
|
+
[](Runtime &runtime,
|
|
71
|
+
const Value &thisValue,
|
|
72
|
+
const Value *arguments,
|
|
73
|
+
size_t count) -> Value
|
|
74
|
+
{
|
|
75
|
+
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
76
|
+
std::vector<uint8_t> bytes_vec = jsTypedArrayToCVector(runtime, arguments[1]);
|
|
77
|
+
slice_ref_uint8_t bytes = borrowVecAsOptRefSlice(bytes_vec);
|
|
78
|
+
CAttachment_t * out_attachment = jsPointerObjectToCPointer<CAttachment_t>(runtime, arguments[2]);
|
|
79
|
+
|
|
80
|
+
::ditto_new_attachment_from_bytes(ditto, bytes, out_attachment);
|
|
81
|
+
return Value();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
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 String::createFromUtf8(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 static_cast<double>(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 String::createFromUtf8(runtime, res ? res : "");
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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 {
|
|
38
|
+
throw std::invalid_argument("Invalid write strategy");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
std::string log_hint_str = jsTypedArrayToCString(runtime, arguments[4]);
|
|
42
|
+
const char *log_hint = log_hint_str.c_str();
|
|
43
|
+
|
|
44
|
+
CWriteTransaction_t *writeTransaction = jsPointerObjectToCPointer<CWriteTransaction_t>(runtime, arguments[5]);
|
|
45
|
+
|
|
46
|
+
DocIdResult_t res = ::ditto_collection_insert_value(ditto, collectionName, docCbor, writeStrategy, log_hint, writeTransaction);
|
|
47
|
+
|
|
48
|
+
Object obj(runtime);
|
|
49
|
+
obj.setProperty(runtime, "status_code", static_cast<double>(res.status_code));
|
|
50
|
+
obj.setProperty(runtime, "id", pointerToHexString(res.id.ptr));
|
|
51
|
+
return obj;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
#include <DQL.h>
|
|
2
|
+
#include <dittoffi.h>
|
|
3
|
+
|
|
4
|
+
#include "Arc.hpp"
|
|
5
|
+
#include "Utils.h"
|
|
6
|
+
#include "LiveQuery.h"
|
|
7
|
+
|
|
8
|
+
namespace sharedjsi
|
|
9
|
+
{
|
|
10
|
+
|
|
11
|
+
DEFINE_RETAIN_RELEASE_FOR(Function, v_retain, v_release);
|
|
12
|
+
|
|
13
|
+
extern "C" {
|
|
14
|
+
void v_change_handler_with_query_result(void *ctx, ChangeHandlerWithQueryResult_t result)
|
|
15
|
+
{
|
|
16
|
+
Arc<Function> const& borrowedJsCallback = Arc<Function>::borrow_from_raw(ctx);
|
|
17
|
+
// copy ctor / retain so as to keep the ArcPointee<Function> alive until the enqueued_call completes.
|
|
18
|
+
Arc<Function> jsCallback /* = */ (borrowedJsCallback);
|
|
19
|
+
ditto_enqueue_call([=](Runtime *jsi) {
|
|
20
|
+
Runtime &runtime = *jsi;
|
|
21
|
+
CDqlResponse_t *query_result = result.query_result;
|
|
22
|
+
|
|
23
|
+
Object obj(runtime);
|
|
24
|
+
obj.setProperty(runtime, "query_result", cPointerToJSPointerObject(runtime, query_result));
|
|
25
|
+
|
|
26
|
+
jsCallback->call(runtime, obj);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
Function dittoffi_try_experimental_add_dql_subscription(Runtime &runtime)
|
|
32
|
+
{
|
|
33
|
+
return Function::createFromHostFunction(runtime,
|
|
34
|
+
PropNameID::forAscii(runtime,
|
|
35
|
+
STRINGIFIED_FUNC_NAME()),
|
|
36
|
+
0,
|
|
37
|
+
[](Runtime &runtime,
|
|
38
|
+
const Value &thisValue,
|
|
39
|
+
const Value *arguments,
|
|
40
|
+
size_t count) -> Value
|
|
41
|
+
{
|
|
42
|
+
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
43
|
+
std::string query_str = jsTypedArrayToCString(runtime, arguments[1]);
|
|
44
|
+
const char *query = query_str.c_str();
|
|
45
|
+
|
|
46
|
+
std::vector<uint8_t> query_args_cbor_vec = jsTypedArrayToCVector(runtime, arguments[2]);
|
|
47
|
+
slice_ref_uint8_t query_args_cbor = borrowVecAsOptRefSlice(query_args_cbor_vec);
|
|
48
|
+
|
|
49
|
+
dittoffi_result_void_t res = ::dittoffi_try_experimental_add_dql_subscription(ditto, query, query_args_cbor);
|
|
50
|
+
|
|
51
|
+
Object obj(runtime);
|
|
52
|
+
obj.setProperty(runtime, "error", cPointerToJSPointerObject(runtime, res.error));
|
|
53
|
+
return obj;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
Function dittoffi_try_experimental_remove_dql_subscription(Runtime &runtime)
|
|
58
|
+
{
|
|
59
|
+
return Function::createFromHostFunction(runtime,
|
|
60
|
+
PropNameID::forAscii(runtime,
|
|
61
|
+
STRINGIFIED_FUNC_NAME()),
|
|
62
|
+
0,
|
|
63
|
+
[](Runtime &runtime,
|
|
64
|
+
const Value &thisValue,
|
|
65
|
+
const Value *arguments,
|
|
66
|
+
size_t count) -> Value
|
|
67
|
+
{
|
|
68
|
+
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
69
|
+
std::string query_str = jsTypedArrayToCString(runtime, arguments[1]);
|
|
70
|
+
const char *query = query_str.c_str();
|
|
71
|
+
|
|
72
|
+
std::vector<uint8_t> query_args_cbor_vec = jsTypedArrayToCVector(runtime, arguments[2]);
|
|
73
|
+
slice_ref_uint8_t query_args_cbor = borrowVecAsOptRefSlice(query_args_cbor_vec);
|
|
74
|
+
dittoffi_result_void_t res = ::dittoffi_try_experimental_remove_dql_subscription(ditto, query, query_args_cbor);
|
|
75
|
+
|
|
76
|
+
Object obj(runtime);
|
|
77
|
+
obj.setProperty(runtime, "error", cPointerToJSPointerObject(runtime, res.error));
|
|
78
|
+
return obj;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
Function dittoffi_try_experimental_exec_statement_str(Runtime &runtime)
|
|
83
|
+
{
|
|
84
|
+
return Function::createFromHostFunction(runtime,
|
|
85
|
+
PropNameID::forAscii(runtime,
|
|
86
|
+
STRINGIFIED_FUNC_NAME()),
|
|
87
|
+
0,
|
|
88
|
+
[](Runtime &runtime,
|
|
89
|
+
const Value &thisValue,
|
|
90
|
+
const Value *arguments,
|
|
91
|
+
size_t count) -> Value
|
|
92
|
+
{
|
|
93
|
+
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
94
|
+
CWriteTransaction *writeTransaction = jsPointerObjectToCPointer<CWriteTransaction_t>(runtime, arguments[1]);
|
|
95
|
+
std::string query_vec = jsTypedArrayToCString(runtime, arguments[2]);
|
|
96
|
+
const char *query = query_vec.c_str();
|
|
97
|
+
|
|
98
|
+
std::vector<uint8_t> args_vec = jsTypedArrayToCVector(runtime, arguments[3]);
|
|
99
|
+
slice_ref_uint8_t args_cbor = borrowVecAsOptRefSlice(args_vec);
|
|
100
|
+
dittoffi_result_CDqlResponse_ptr res = ::dittoffi_try_experimental_exec_statement_str(ditto, writeTransaction, query, args_cbor);
|
|
101
|
+
|
|
102
|
+
Object obj(runtime);
|
|
103
|
+
obj.setProperty(runtime, "success", cPointerToJSPointerObject(runtime, res.success));
|
|
104
|
+
obj.setProperty(runtime, "error", cPointerToJSPointerObject(runtime, res.error));
|
|
105
|
+
return obj;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
Function dittoffi_try_experimental_register_change_observer_str_detached(Runtime &runtime)
|
|
110
|
+
{
|
|
111
|
+
return Function::createFromHostFunction(runtime,
|
|
112
|
+
PropNameID::forAscii(runtime, STRINGIFIED_FUNC_NAME()),
|
|
113
|
+
0,
|
|
114
|
+
[](Runtime &runtime,
|
|
115
|
+
const Value &thisValue,
|
|
116
|
+
const Value *arguments,
|
|
117
|
+
size_t count) -> Value
|
|
118
|
+
{
|
|
119
|
+
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
120
|
+
std::string query_str = jsTypedArrayToCString(runtime, arguments[1]);
|
|
121
|
+
const char *query = query_str.c_str();
|
|
122
|
+
|
|
123
|
+
std::vector<uint8_t> query_args_cbor_vec = jsTypedArrayToCVector(runtime, arguments[2]);
|
|
124
|
+
slice_ref_uint8_t query_args_cbor = borrowVecAsOptRefSlice(query_args_cbor_vec);
|
|
125
|
+
|
|
126
|
+
Function jsCallback = arguments[3].getObject(runtime).getFunction(runtime);
|
|
127
|
+
Arc<Function> wrappedStateFfiWrapper(std::move(jsCallback));
|
|
128
|
+
|
|
129
|
+
LiveQueryAvailability lq_availability = LIVE_QUERY_AVAILABILITY_ALWAYS;
|
|
130
|
+
// std::string lq_availability_str = arguments[3].getString(runtime).utf8(runtime);
|
|
131
|
+
// if (lq_availability_str == "Always") {
|
|
132
|
+
// lq_availability = LIVE_QUERY_AVAILABILITY_ALWAYS;
|
|
133
|
+
// } if (lq_availability_str == "WhenSignalled") {
|
|
134
|
+
// lq_availability = LIVE_QUERY_AVAILABILITY_WHEN_SIGNALLED;
|
|
135
|
+
// } else {
|
|
136
|
+
// throw std::invalid_argument("Invalid live query string");
|
|
137
|
+
// }
|
|
138
|
+
|
|
139
|
+
dittoffi_result_int64_t res = ::dittoffi_try_experimental_register_change_observer_str(
|
|
140
|
+
ditto,
|
|
141
|
+
query,
|
|
142
|
+
query_args_cbor,
|
|
143
|
+
lq_availability,
|
|
144
|
+
Arc<Function>::as_raw(wrappedStateFfiWrapper),
|
|
145
|
+
v_retain,
|
|
146
|
+
v_release,
|
|
147
|
+
v_change_handler_with_query_result);
|
|
148
|
+
|
|
149
|
+
Object obj(runtime);
|
|
150
|
+
obj.setProperty(runtime, "success", static_cast<double>(res.success));
|
|
151
|
+
obj.setProperty(runtime, "error", cPointerToJSPointerObject(runtime, res.error));
|
|
152
|
+
return obj;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
Function ditto_dql_response_result_count(Runtime &runtime)
|
|
158
|
+
{
|
|
159
|
+
return Function::createFromHostFunction(runtime,
|
|
160
|
+
PropNameID::forAscii(runtime, STRINGIFIED_FUNC_NAME()),
|
|
161
|
+
0,
|
|
162
|
+
[](Runtime &runtime,
|
|
163
|
+
const Value &thisValue,
|
|
164
|
+
const Value *arguments,
|
|
165
|
+
size_t count) -> Value
|
|
166
|
+
{
|
|
167
|
+
size_t res = ::ditto_dql_response_result_count(jsPointerObjectToCPointer<CDqlResponse>(runtime, arguments[0]));
|
|
168
|
+
return static_cast<double>(res);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
Function ditto_dql_response_result_at(Runtime &runtime)
|
|
174
|
+
{
|
|
175
|
+
return Function::createFromHostFunction(runtime,
|
|
176
|
+
PropNameID::forAscii(runtime, STRINGIFIED_FUNC_NAME()),
|
|
177
|
+
0,
|
|
178
|
+
[](Runtime &runtime,
|
|
179
|
+
const Value &thisValue,
|
|
180
|
+
const Value *arguments,
|
|
181
|
+
size_t count) -> Value
|
|
182
|
+
{
|
|
183
|
+
|
|
184
|
+
CDqlResponse *dql_response = jsPointerObjectToCPointer<CDqlResponse>(runtime, arguments[0]);
|
|
185
|
+
size_t idx = arguments[1].asNumber();
|
|
186
|
+
|
|
187
|
+
CDqlResult_t *res = ::ditto_dql_response_result_at(dql_response, idx);
|
|
188
|
+
return cPointerToJSPointerObject(runtime, res);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
Function ditto_dql_response_affected_document_id_count(Runtime &runtime)
|
|
193
|
+
{
|
|
194
|
+
return Function::createFromHostFunction(runtime,
|
|
195
|
+
PropNameID::forAscii(runtime, STRINGIFIED_FUNC_NAME()),
|
|
196
|
+
0,
|
|
197
|
+
[](Runtime &runtime,
|
|
198
|
+
const Value &thisValue,
|
|
199
|
+
const Value *arguments,
|
|
200
|
+
size_t count) -> Value
|
|
201
|
+
{
|
|
202
|
+
size_t res = ::ditto_dql_response_affected_document_id_count(jsPointerObjectToCPointer<CDqlResponse>(runtime, arguments[0]));
|
|
203
|
+
return static_cast<double>(res);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
Function ditto_dql_response_affected_document_id_at(Runtime &runtime)
|
|
208
|
+
{
|
|
209
|
+
return Function::createFromHostFunction(runtime,
|
|
210
|
+
PropNameID::forAscii(runtime, STRINGIFIED_FUNC_NAME()),
|
|
211
|
+
0,
|
|
212
|
+
[](Runtime &runtime,
|
|
213
|
+
const Value &thisValue,
|
|
214
|
+
const Value *arguments,
|
|
215
|
+
size_t count) -> Value
|
|
216
|
+
{
|
|
217
|
+
|
|
218
|
+
CDqlResponse *dql_response = jsPointerObjectToCPointer<CDqlResponse>(runtime, arguments[0]);
|
|
219
|
+
size_t idx = arguments[1].asNumber();
|
|
220
|
+
|
|
221
|
+
slice_boxed_uint8_t res = ::ditto_dql_response_affected_document_id_at(dql_response, idx);
|
|
222
|
+
return cSlicedBoxToJSSlicedBox(runtime, res);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
Function ditto_result_cbor(Runtime &runtime)
|
|
227
|
+
{
|
|
228
|
+
return Function::createFromHostFunction(runtime,
|
|
229
|
+
PropNameID::forAscii(runtime, STRINGIFIED_FUNC_NAME()),
|
|
230
|
+
0,
|
|
231
|
+
[](Runtime &runtime,
|
|
232
|
+
const Value &thisValue,
|
|
233
|
+
const Value *arguments,
|
|
234
|
+
size_t count) -> Value
|
|
235
|
+
{
|
|
236
|
+
slice_boxed_uint8_t res = ::ditto_result_cbor(jsPointerObjectToCPointer<CDqlResult_t>(runtime, arguments[0]));
|
|
237
|
+
return cSlicedBoxToJSSlicedBox(runtime, res);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
Function ditto_result_json(Runtime &runtime)
|
|
242
|
+
{
|
|
243
|
+
return Function::createFromHostFunction(runtime,
|
|
244
|
+
PropNameID::forAscii(runtime, STRINGIFIED_FUNC_NAME()),
|
|
245
|
+
0,
|
|
246
|
+
[](Runtime &runtime,
|
|
247
|
+
const Value &thisValue,
|
|
248
|
+
const Value *arguments,
|
|
249
|
+
size_t count) -> Value
|
|
250
|
+
{
|
|
251
|
+
|
|
252
|
+
char *res = ::ditto_result_json(jsPointerObjectToCPointer<CDqlResult_t>(runtime, arguments[0]));
|
|
253
|
+
return String::createFromUtf8(runtime, res);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|