@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.
Files changed (65) hide show
  1. package/DeRec.podspec +25 -0
  2. package/LICENSE +201 -0
  3. package/README.md +222 -0
  4. package/android/CMakeLists.txt +38 -0
  5. package/android/build.gradle +79 -0
  6. package/android/src/main/AndroidManifest.xml +12 -0
  7. package/android/src/main/java/org/derec/DeRecModule.kt +56 -0
  8. package/android/src/main/java/org/derec/DeRecPackage.kt +24 -0
  9. package/android/src/main/jni/OnLoad.cpp +39 -0
  10. package/android/src/main/jniLibs/arm64-v8a/libderec_library.a +0 -0
  11. package/android/src/main/jniLibs/armeabi-v7a/libderec_library.a +0 -0
  12. package/android/src/main/jniLibs/x86_64/libderec_library.a +0 -0
  13. package/cpp/Convert.cpp +50 -0
  14. package/cpp/Convert.h +38 -0
  15. package/cpp/DeRecInstaller.cpp +186 -0
  16. package/cpp/DeRecInstaller.h +28 -0
  17. package/cpp/Invoker.h +20 -0
  18. package/cpp/JsCallbackBridge.cpp +144 -0
  19. package/cpp/JsCallbackBridge.h +148 -0
  20. package/cpp/Primitives.cpp +1193 -0
  21. package/cpp/Primitives.h +39 -0
  22. package/cpp/ProtocolHost.cpp +613 -0
  23. package/cpp/ProtocolHost.h +88 -0
  24. package/cpp/RuntimeInvoker.h +29 -0
  25. package/cpp/StoreCallbacks.cpp +1293 -0
  26. package/cpp/StoreCallbacks.h +111 -0
  27. package/cpp/WorkerThread.cpp +74 -0
  28. package/cpp/WorkerThread.h +54 -0
  29. package/cpp/derec_ffi.h +2145 -0
  30. package/ios/DeRec.h +23 -0
  31. package/ios/DeRec.mm +39 -0
  32. package/ios/DeRecFFI.xcframework/Info.plist +48 -0
  33. package/ios/DeRecFFI.xcframework/ios-arm64/Headers/derec_ffi.h +2145 -0
  34. package/ios/DeRecFFI.xcframework/ios-arm64/libderec_library.a +0 -0
  35. package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/Headers/derec_ffi.h +2145 -0
  36. package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/libderec_library.a +0 -0
  37. package/lib/binary.d.ts +19 -0
  38. package/lib/binary.js +164 -0
  39. package/lib/codec.d.ts +16 -0
  40. package/lib/codec.js +80 -0
  41. package/lib/errors.d.ts +23 -0
  42. package/lib/errors.js +35 -0
  43. package/lib/index.d.ts +4 -0
  44. package/lib/index.js +27 -0
  45. package/lib/messages.d.ts +41 -0
  46. package/lib/messages.js +192 -0
  47. package/lib/native.d.ts +11 -0
  48. package/lib/native.js +40 -0
  49. package/lib/primitives.d.ts +137 -0
  50. package/lib/primitives.js +329 -0
  51. package/lib/protocol.d.ts +188 -0
  52. package/lib/protocol.js +514 -0
  53. package/lib/types.d.ts +1014 -0
  54. package/lib/types.js +63 -0
  55. package/package.json +55 -0
  56. package/react-native.config.js +19 -0
  57. package/src/binary.ts +182 -0
  58. package/src/codec.ts +79 -0
  59. package/src/errors.ts +45 -0
  60. package/src/index.ts +7 -0
  61. package/src/messages.ts +192 -0
  62. package/src/native.ts +52 -0
  63. package/src/primitives.ts +770 -0
  64. package/src/protocol.ts +621 -0
  65. 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
+ }