@derec-alliance/react-native 0.0.1
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/DeRec.podspec +25 -0
- package/LICENSE +201 -0
- package/README.md +222 -0
- package/android/CMakeLists.txt +38 -0
- package/android/build.gradle +79 -0
- package/android/src/main/AndroidManifest.xml +12 -0
- package/android/src/main/java/org/derec/DeRecModule.kt +56 -0
- package/android/src/main/java/org/derec/DeRecPackage.kt +24 -0
- package/android/src/main/jni/OnLoad.cpp +39 -0
- package/android/src/main/jniLibs/arm64-v8a/libderec_library.a +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libderec_library.a +0 -0
- package/android/src/main/jniLibs/x86_64/libderec_library.a +0 -0
- package/cpp/Convert.cpp +50 -0
- package/cpp/Convert.h +38 -0
- package/cpp/DeRecInstaller.cpp +186 -0
- package/cpp/DeRecInstaller.h +28 -0
- package/cpp/Invoker.h +20 -0
- package/cpp/JsCallbackBridge.cpp +144 -0
- package/cpp/JsCallbackBridge.h +148 -0
- package/cpp/Primitives.cpp +1193 -0
- package/cpp/Primitives.h +39 -0
- package/cpp/ProtocolHost.cpp +613 -0
- package/cpp/ProtocolHost.h +88 -0
- package/cpp/RuntimeInvoker.h +29 -0
- package/cpp/StoreCallbacks.cpp +1293 -0
- package/cpp/StoreCallbacks.h +111 -0
- package/cpp/WorkerThread.cpp +74 -0
- package/cpp/WorkerThread.h +54 -0
- package/cpp/derec_ffi.h +2145 -0
- package/ios/DeRec.h +23 -0
- package/ios/DeRec.mm +39 -0
- package/ios/DeRecFFI.xcframework/Info.plist +48 -0
- package/ios/DeRecFFI.xcframework/ios-arm64/Headers/derec_ffi.h +2145 -0
- package/ios/DeRecFFI.xcframework/ios-arm64/libderec_library.a +0 -0
- package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/Headers/derec_ffi.h +2145 -0
- package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/libderec_library.a +0 -0
- package/lib/binary.d.ts +19 -0
- package/lib/binary.js +164 -0
- package/lib/codec.d.ts +16 -0
- package/lib/codec.js +80 -0
- package/lib/errors.d.ts +23 -0
- package/lib/errors.js +35 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +27 -0
- package/lib/messages.d.ts +41 -0
- package/lib/messages.js +192 -0
- package/lib/native.d.ts +11 -0
- package/lib/native.js +40 -0
- package/lib/primitives.d.ts +137 -0
- package/lib/primitives.js +329 -0
- package/lib/protocol.d.ts +188 -0
- package/lib/protocol.js +514 -0
- package/lib/types.d.ts +1014 -0
- package/lib/types.js +63 -0
- package/package.json +55 -0
- package/react-native.config.js +19 -0
- package/src/binary.ts +182 -0
- package/src/codec.ts +79 -0
- package/src/errors.ts +45 -0
- package/src/index.ts +7 -0
- package/src/messages.ts +192 -0
- package/src/native.ts +52 -0
- package/src/primitives.ts +770 -0
- package/src/protocol.ts +621 -0
- package/src/types.ts +1040 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (c) 2026 DeRec Alliance. All rights reserved.
|
|
3
|
+
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
#include <jsi/jsi.h>
|
|
7
|
+
|
|
8
|
+
#include <memory>
|
|
9
|
+
#include <string>
|
|
10
|
+
|
|
11
|
+
#include "Invoker.h"
|
|
12
|
+
#include "JsCallbackBridge.h"
|
|
13
|
+
#include "StoreCallbacks.h"
|
|
14
|
+
#include "WorkerThread.h"
|
|
15
|
+
|
|
16
|
+
extern "C" {
|
|
17
|
+
#include "derec_ffi.h"
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
namespace derec {
|
|
21
|
+
|
|
22
|
+
/// One `DeRecProtocol` instance exposed to JavaScript.
|
|
23
|
+
///
|
|
24
|
+
/// All `derec_protocol_*` calls run on `worker_`, never on the JavaScript
|
|
25
|
+
/// thread: store callbacks re-enter JavaScript and block the calling thread
|
|
26
|
+
/// until they settle, so running them on the JavaScript thread would deadlock.
|
|
27
|
+
///
|
|
28
|
+
/// `~ProtocolHost` is not guaranteed to run on the JavaScript thread: JSI's
|
|
29
|
+
/// own contract for `HostObject` says finalization "may be as late as when
|
|
30
|
+
/// the Runtime is shut down" and gives "no control over which thread it is
|
|
31
|
+
/// called on." The destructor therefore touches no `jsi::Runtime` and makes
|
|
32
|
+
/// no JSI call — `invalidate`, `drainAndJoin` and `derec_protocol_free` are
|
|
33
|
+
/// all plain native calls. Destroying `stores_` (dropping its
|
|
34
|
+
/// `shared_ptr<jsi::Object>` references to the application's JS stores) is
|
|
35
|
+
/// safe under the same contract, which explicitly permits "calling the dtor
|
|
36
|
+
/// on a jsi object" from any thread.
|
|
37
|
+
class ProtocolHost : public facebook::jsi::HostObject {
|
|
38
|
+
public:
|
|
39
|
+
ProtocolHost(DeRecProtocolHandle* handle,
|
|
40
|
+
uint64_t secretId,
|
|
41
|
+
std::shared_ptr<Invoker> invoker,
|
|
42
|
+
std::shared_ptr<InstanceState> state,
|
|
43
|
+
std::shared_ptr<StoreBindings> stores);
|
|
44
|
+
|
|
45
|
+
~ProtocolHost() override;
|
|
46
|
+
|
|
47
|
+
facebook::jsi::Value get(facebook::jsi::Runtime& rt,
|
|
48
|
+
const facebook::jsi::PropNameID& name) override;
|
|
49
|
+
|
|
50
|
+
std::vector<facebook::jsi::PropNameID> getPropertyNames(
|
|
51
|
+
facebook::jsi::Runtime& rt) override;
|
|
52
|
+
|
|
53
|
+
private:
|
|
54
|
+
/// Run `body` on the worker thread and resolve a JavaScript Promise with
|
|
55
|
+
/// its result. `body` returns the raw bytes or JSON the JavaScript side
|
|
56
|
+
/// converts; it must not touch the runtime. Throws synchronously — before
|
|
57
|
+
/// any Promise is created — if this instance has been freed, or if the
|
|
58
|
+
/// calling thread is itself executing a store callback body, since
|
|
59
|
+
/// enqueuing onto the worker in that case would deadlock against the very
|
|
60
|
+
/// callback whose completion the worker is blocked waiting on.
|
|
61
|
+
facebook::jsi::Value runAsync(
|
|
62
|
+
facebook::jsi::Runtime& rt,
|
|
63
|
+
std::function<std::vector<uint8_t>()> body,
|
|
64
|
+
std::function<facebook::jsi::Value(facebook::jsi::Runtime&,
|
|
65
|
+
std::vector<uint8_t>&)> convert);
|
|
66
|
+
|
|
67
|
+
/// Release the handle in the order the FFI's safety contract requires.
|
|
68
|
+
/// Every step is individually idempotent (`invalidate`, `drainAndJoin` and
|
|
69
|
+
/// `derec_protocol_free` all tolerate repeat calls), so this may run once
|
|
70
|
+
/// from an explicit `free()` and again from the destructor.
|
|
71
|
+
void teardown();
|
|
72
|
+
|
|
73
|
+
DeRecProtocolHandle* handle_;
|
|
74
|
+
uint64_t secretId_;
|
|
75
|
+
std::shared_ptr<Invoker> invoker_;
|
|
76
|
+
std::shared_ptr<InstanceState> state_;
|
|
77
|
+
// `shared_ptr`, not `unique_ptr`: each store trampoline in `StoreCallbacks.cpp`
|
|
78
|
+
// captures `shared_from_this()` into the lambda it hands to
|
|
79
|
+
// `JsCallbackBridge::callSync`, which the JavaScript `CallInvoker`'s own
|
|
80
|
+
// queue may still be holding after `worker_.drainAndJoin()` returns and this
|
|
81
|
+
// object is torn down. `stores_` merely being an owning reference is what
|
|
82
|
+
// lets that queued task keep `StoreBindings` (and the JS store objects it
|
|
83
|
+
// retains) alive until it actually runs.
|
|
84
|
+
std::shared_ptr<StoreBindings> stores_;
|
|
85
|
+
WorkerThread worker_;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
} // namespace derec
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (c) 2026 DeRec Alliance. All rights reserved.
|
|
3
|
+
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
#include <ReactCommon/CallInvoker.h>
|
|
7
|
+
|
|
8
|
+
#include <memory>
|
|
9
|
+
#include <utility>
|
|
10
|
+
|
|
11
|
+
#include "Invoker.h"
|
|
12
|
+
|
|
13
|
+
namespace derec {
|
|
14
|
+
|
|
15
|
+
/// Adapts React Native's `CallInvoker` to the binding's `Invoker` seam.
|
|
16
|
+
class RuntimeInvoker : public Invoker {
|
|
17
|
+
public:
|
|
18
|
+
explicit RuntimeInvoker(std::shared_ptr<facebook::react::CallInvoker> inner)
|
|
19
|
+
: inner_(std::move(inner)) {}
|
|
20
|
+
|
|
21
|
+
void invokeAsync(std::function<void()> work) override {
|
|
22
|
+
inner_->invokeAsync(std::move(work));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private:
|
|
26
|
+
std::shared_ptr<facebook::react::CallInvoker> inner_;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
} // namespace derec
|