@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
package/src/native.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accessor for the JSI host object installed by the native module.
|
|
3
|
+
*
|
|
4
|
+
* The host object is installed directly into the runtime's global scope
|
|
5
|
+
* rather than exposed through React Native's codegen, because the data
|
|
6
|
+
* surface passes `ArrayBuffer`s that TurboModule specs cannot express.
|
|
7
|
+
*/
|
|
8
|
+
export interface DeRecNative {
|
|
9
|
+
version(): string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Asks the native module to install the host object.
|
|
14
|
+
*
|
|
15
|
+
* iOS needs this only as a fallback: the module implements
|
|
16
|
+
* `RCTTurboModuleWithJSIBindings`, so the platform installs the host object
|
|
17
|
+
* before any JavaScript runs. Android has no equivalent hook for a module that
|
|
18
|
+
* is not code-generated, so the install has to be triggered from here — a
|
|
19
|
+
* blocking synchronous `@ReactMethod`, which is why the host object is present
|
|
20
|
+
* by the time this returns.
|
|
21
|
+
*
|
|
22
|
+
* Everything is behind a lazy `require` and a `try`: this module is imported by
|
|
23
|
+
* unit tests running under plain Node, where `react-native` cannot resolve, and
|
|
24
|
+
* a missing native module must still surface as the explanatory error below
|
|
25
|
+
* rather than a resolution failure from a dependency the caller never named.
|
|
26
|
+
*/
|
|
27
|
+
function requestInstall(): void {
|
|
28
|
+
try {
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
30
|
+
const { NativeModules } = require('react-native') as {
|
|
31
|
+
NativeModules: Record<string, { install?: () => boolean } | undefined>;
|
|
32
|
+
};
|
|
33
|
+
NativeModules.DeRec?.install?.();
|
|
34
|
+
} catch {
|
|
35
|
+
// Left to the caller: the check below reports the actionable message.
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function getNative(): DeRecNative {
|
|
40
|
+
let installed = (globalThis as Record<string, unknown>).__DeRec;
|
|
41
|
+
if (installed === undefined || installed === null) {
|
|
42
|
+
requestInstall();
|
|
43
|
+
installed = (globalThis as Record<string, unknown>).__DeRec;
|
|
44
|
+
}
|
|
45
|
+
if (installed === undefined || installed === null) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
'DeRec native module is not installed. Rebuild the app after adding ' +
|
|
48
|
+
'@derec-alliance/react-native (pod install on iOS, Gradle sync on Android).',
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
return installed as DeRecNative;
|
|
52
|
+
}
|