react-native-nitro-modules 0.0.2 → 0.0.4

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 (120) hide show
  1. package/NitroModules.podspec +49 -0
  2. package/android/CMakeLists.txt +44 -7
  3. package/android/build.gradle +28 -24
  4. package/cpp/core/AnyMap.cpp +181 -0
  5. package/cpp/core/AnyMap.hpp +191 -0
  6. package/cpp/core/HybridContext.hpp +51 -0
  7. package/cpp/core/HybridObject.cpp +220 -0
  8. package/cpp/core/HybridObject.hpp +241 -0
  9. package/cpp/core/PointerHolder.hpp +93 -0
  10. package/cpp/jsi/ArrayBuffer.hpp +79 -0
  11. package/cpp/jsi/JSICache.hpp +145 -0
  12. package/cpp/jsi/JSIConverter.hpp +610 -0
  13. package/cpp/jsi/Promise.cpp +54 -0
  14. package/cpp/jsi/Promise.hpp +54 -0
  15. package/cpp/platform/ThreadUtils.hpp +23 -0
  16. package/cpp/registry/HybridObjectRegistry.cpp +57 -0
  17. package/cpp/registry/HybridObjectRegistry.hpp +44 -0
  18. package/cpp/test-object/TestHybridObject.cpp +37 -0
  19. package/cpp/test-object/TestHybridObject.hpp +87 -0
  20. package/cpp/threading/CallInvokerDispatcher.hpp +33 -0
  21. package/cpp/threading/Dispatcher.cpp +56 -0
  22. package/cpp/threading/Dispatcher.hpp +82 -0
  23. package/cpp/turbomodule/NativeNitroModules.cpp +70 -0
  24. package/cpp/turbomodule/NativeNitroModules.h +7 -0
  25. package/cpp/turbomodule/NativeNitroModules.hpp +35 -0
  26. package/cpp/turbomodule/RegisterNativeNitroModules.cpp +33 -0
  27. package/cpp/turbomodule/RegisterNativeNitroModules.hpp +21 -0
  28. package/cpp/utils/BorrowingReference+Owning.hpp +34 -0
  29. package/cpp/utils/BorrowingReference.hpp +115 -0
  30. package/cpp/utils/DoesClassExist.hpp +23 -0
  31. package/cpp/utils/GetRuntimeID.hpp +28 -0
  32. package/cpp/utils/NitroDefines.hpp +32 -0
  33. package/cpp/utils/NitroHash.hpp +42 -0
  34. package/cpp/utils/NitroLogger.hpp +55 -0
  35. package/cpp/utils/OwningLock.hpp +54 -0
  36. package/cpp/utils/OwningReference.hpp +214 -0
  37. package/cpp/utils/TypeInfo.hpp +81 -0
  38. package/ios/core/HybridObjectSpec.swift +52 -0
  39. package/ios/core/RuntimeError.swift +17 -0
  40. package/ios/platform/ThreadUtils.cpp +28 -0
  41. package/ios/turbomodule/NitroModuleOnLoad.mm +31 -0
  42. package/lib/AnyMap.d.ts +16 -0
  43. package/lib/AnyMap.js +1 -0
  44. package/lib/HybridObject.d.ts +57 -0
  45. package/lib/HybridObject.js +1 -0
  46. package/lib/ModuleNotFoundError.d.ts +6 -0
  47. package/lib/ModuleNotFoundError.js +61 -0
  48. package/lib/NativeNitro.d.ts +8 -0
  49. package/lib/NativeNitro.js +3 -0
  50. package/lib/NativeNitroModules.d.ts +7 -0
  51. package/lib/NativeNitroModules.js +17 -0
  52. package/lib/NitroModules.d.ts +17 -0
  53. package/lib/NitroModules.js +21 -0
  54. package/lib/__tests__/index.test.d.ts +0 -0
  55. package/lib/__tests__/index.test.js +2 -0
  56. package/lib/commonjs/AnyMap.js +2 -0
  57. package/lib/commonjs/AnyMap.js.map +1 -0
  58. package/lib/commonjs/HybridObject.js +2 -0
  59. package/lib/commonjs/HybridObject.js.map +1 -0
  60. package/lib/commonjs/ModuleNotFoundError.js +72 -0
  61. package/lib/commonjs/ModuleNotFoundError.js.map +1 -0
  62. package/lib/commonjs/NativeNitroModules.js +24 -0
  63. package/lib/commonjs/NativeNitroModules.js.map +1 -0
  64. package/lib/commonjs/NitroModules.js +32 -0
  65. package/lib/commonjs/NitroModules.js.map +1 -0
  66. package/lib/commonjs/createTestObject.js +15 -0
  67. package/lib/commonjs/createTestObject.js.map +1 -0
  68. package/lib/commonjs/index.js +44 -5
  69. package/lib/commonjs/index.js.map +1 -1
  70. package/lib/createTestObject.d.ts +22 -0
  71. package/lib/createTestObject.js +7 -0
  72. package/lib/index.d.ts +4 -0
  73. package/lib/index.js +4 -0
  74. package/lib/module/AnyMap.js +2 -0
  75. package/lib/module/AnyMap.js.map +1 -0
  76. package/lib/module/HybridObject.js +2 -0
  77. package/lib/module/HybridObject.js.map +1 -0
  78. package/lib/module/ModuleNotFoundError.js +65 -0
  79. package/lib/module/ModuleNotFoundError.js.map +1 -0
  80. package/lib/module/NativeNitroModules.js +18 -0
  81. package/lib/module/NativeNitroModules.js.map +1 -0
  82. package/lib/module/NitroModules.js +27 -0
  83. package/lib/module/NitroModules.js.map +1 -0
  84. package/lib/module/createTestObject.js +8 -0
  85. package/lib/module/createTestObject.js.map +1 -0
  86. package/lib/module/index.js +4 -4
  87. package/lib/module/index.js.map +1 -1
  88. package/lib/tsconfig.tsbuildinfo +1 -0
  89. package/package.json +76 -49
  90. package/react-native.config.js +16 -0
  91. package/src/AnyMap.ts +22 -0
  92. package/src/HybridObject.ts +58 -0
  93. package/src/ModuleNotFoundError.ts +90 -0
  94. package/src/NativeNitroModules.ts +26 -0
  95. package/src/NitroModules.ts +30 -0
  96. package/src/__tests__/index.test.tsx +1 -0
  97. package/src/createTestObject.ts +40 -0
  98. package/src/index.ts +4 -0
  99. package/LICENSE +0 -20
  100. package/README.md +0 -32
  101. package/android/cpp-adapter.cpp +0 -8
  102. package/android/src/main/AndroidManifest.xml +0 -3
  103. package/android/src/main/AndroidManifestNew.xml +0 -2
  104. package/android/src/main/java/com/nitro/NitroModule.java +0 -34
  105. package/android/src/main/java/com/nitro/NitroPackage.java +0 -44
  106. package/cpp/react-native-nitro.cpp +0 -7
  107. package/cpp/react-native-nitro.h +0 -8
  108. package/ios/Nitro.h +0 -15
  109. package/ios/Nitro.mm +0 -21
  110. package/lib/commonjs/NativeNitro.js +0 -9
  111. package/lib/commonjs/NativeNitro.js.map +0 -1
  112. package/lib/module/NativeNitro.js +0 -3
  113. package/lib/module/NativeNitro.js.map +0 -1
  114. package/lib/typescript/src/NativeNitro.d.ts +0 -7
  115. package/lib/typescript/src/NativeNitro.d.ts.map +0 -1
  116. package/lib/typescript/src/index.d.ts +0 -2
  117. package/lib/typescript/src/index.d.ts.map +0 -1
  118. package/react-native-nitro.podspec +0 -41
  119. package/src/NativeNitro.ts +0 -8
  120. package/src/index.tsx +0 -5
@@ -0,0 +1,17 @@
1
+ //
2
+ // RuntimeError.swift
3
+ // NitroModules
4
+ //
5
+ // Created by Marc Rousavy on 17.07.24.
6
+ //
7
+
8
+ import Foundation
9
+
10
+ /**
11
+ * Represents an error that occured at any point during the application's runtime.
12
+ *
13
+ * Throw this error in Nitro Modules to provide clear and concise error messages to JS.
14
+ */
15
+ public enum RuntimeError: Error {
16
+ case error(withMessage: String)
17
+ }
@@ -0,0 +1,28 @@
1
+ //
2
+ // ThreadUtils.cpp
3
+ // react-native-nitro
4
+ //
5
+ // Created by Marc Rousavy on 14.07.24.
6
+ //
7
+
8
+ #include "ThreadUtils.hpp"
9
+ #include <pthread.h>
10
+ #include <thread>
11
+
12
+ namespace margelo::nitro {
13
+
14
+ std::string ThreadUtils::getThreadName() {
15
+ // Try using pthread APIs
16
+ char name[256];
17
+ if (pthread_getname_np(pthread_self(), name, sizeof(name)) == 0) {
18
+ return std::string(name);
19
+ }
20
+
21
+ // Fall back to this_thread ID
22
+ std::stringstream stream;
23
+ stream << std::this_thread::get_id();
24
+ std::string threadId = stream.str();
25
+ return "Thread #" + threadId;
26
+ }
27
+
28
+ } // namespace margelo::nitro
@@ -0,0 +1,31 @@
1
+ //
2
+ // NitroModuleOnLoad.mm
3
+ // DoubleConversion
4
+ //
5
+ // Created by Marc Rousavy on 21.06.24.
6
+ //
7
+
8
+ #import "HybridObjectRegistry.hpp"
9
+ #import "RegisterNativeNitroModules.hpp"
10
+ #import "TestHybridObject.hpp"
11
+ #import <Foundation/Foundation.h>
12
+
13
+ @interface NitroModulesOnLoad : NSObject
14
+ @end
15
+
16
+ @implementation NitroModulesOnLoad
17
+
18
+ using namespace margelo::nitro;
19
+
20
+ + (void)load {
21
+ // When this Objective-C class is loaded, it registers the CxxTurboModule in the react module system.
22
+ // We need Objective-C here because these things do not get compiled out - meaning this will always be
23
+ // called when the app starts.
24
+ RegisterNativeNitroModules::registerNativeNitroModules();
25
+
26
+ // Register Test HybridObject so it can be created from JS.
27
+ HybridObjectRegistry::registerHybridObjectConstructor(
28
+ "TestHybridObject", []() -> std::shared_ptr<TestHybridObject> { return std::make_shared<TestHybridObject>(); });
29
+ }
30
+
31
+ @end
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Represents a single value inside an untyped map.
3
+ */
4
+ export type ValueType = string | number | boolean | bigint | null | ValueType[] | {
5
+ [k: string]: ValueType;
6
+ };
7
+ /**
8
+ * Represents an untyped map, similar to a JSON structure.
9
+ * Supported types:
10
+ * - Primitives (`string`, `number`, `boolean`, `bigint`, `null`)
11
+ * - Arrays of primitives (`ValueType[]`)
12
+ * - Objects of primitives (`Record<string, ValueType>`)
13
+ * - Arrays of arrays or objects
14
+ * - Objects of arrays or objects
15
+ */
16
+ export type AnyMap = Record<string, ValueType>;
package/lib/AnyMap.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Describes the languages this component will be implemented in.
3
+ */
4
+ export interface PlatformSpec {
5
+ ios?: 'swift' | 'c++';
6
+ android?: 'kotlin' | 'c++';
7
+ }
8
+ /**
9
+ * Represents a Nitro `HybridObject` which is implemented natively in either C++,
10
+ * or Swift/Kotlin.
11
+ *
12
+ * Uses the Nitro Tunnel for efficient, low-overhead JS <-> Native communication.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * interface Photo extends HybridObject<{ ios: 'swift', android: 'kotlin' }> {
17
+ * readonly width: number
18
+ * readonly height: number
19
+ * toArrayBuffer(): ArrayBuffer
20
+ * saveToFile(path: string): Promise<void>
21
+ * }
22
+ * ```
23
+ */
24
+ export interface HybridObject<Spec extends PlatformSpec> {
25
+ /**
26
+ * The `HybridObject`'s name.
27
+ */
28
+ readonly name: string;
29
+ /**
30
+ * Returns a string representation of the given `HybridObject`.
31
+ *
32
+ * Unless overridden by the `HybridObject`, this will return a list of all properties.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * const hybridA = SomeModule.getExistingHybridInstance()
37
+ * console.log(hybridA.toString()) // [HybridObject HybridA]
38
+ * ```
39
+ */
40
+ toString(): string;
41
+ /**
42
+ * Returns whether this `HybridObject` is the same object as {@linkcode other}.
43
+ *
44
+ * While two `HybridObject`s might not be equal when compared with `==`, they might still
45
+ * hold the same underlying `HybridObject`, in which case {@linkcode equals | equals(other)}
46
+ * will return `true`.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * const hybridA = SomeModule.getExistingHybridInstance()
51
+ * const hybridB = SomeModule.getExistingHybridInstance()
52
+ * console.log(hybridA === hybridB) // false
53
+ * console.log(hybridA.equals(hybridB)) // true
54
+ * ```
55
+ */
56
+ equals(other: HybridObject<Spec>): boolean;
57
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ declare global {
2
+ var __turboModuleProxy: unknown | undefined;
3
+ }
4
+ export declare class ModuleNotFoundError extends Error {
5
+ constructor(cause?: unknown);
6
+ }
@@ -0,0 +1,61 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+ const BULLET_POINT = '\n* ';
3
+ function messageWithSuggestions(message, suggestions) {
4
+ return message + BULLET_POINT + suggestions.join(BULLET_POINT);
5
+ }
6
+ function getFrameworkType() {
7
+ // check if Expo
8
+ const ExpoConstants = NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants;
9
+ if (ExpoConstants != null) {
10
+ if (ExpoConstants.appOwnership === 'expo') {
11
+ // We're running Expo Go
12
+ return 'expo-go';
13
+ }
14
+ else {
15
+ // We're running Expo bare / standalone
16
+ return 'expo';
17
+ }
18
+ }
19
+ return 'react-native';
20
+ }
21
+ export class ModuleNotFoundError extends Error {
22
+ constructor(cause) {
23
+ // TurboModule not found, something went wrong!
24
+ if (global.__turboModuleProxy == null) {
25
+ // TurboModules are not available/new arch is not enabled.
26
+ const message = 'Failed to get NitroModules: NitroModules require the new architecture to be enabled!';
27
+ const suggestions = [];
28
+ suggestions.push('Enable the new architecture in your app to use NitroModules. (See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md)');
29
+ const error = messageWithSuggestions(message, suggestions);
30
+ super(error, { cause: cause });
31
+ return;
32
+ }
33
+ const framework = getFrameworkType();
34
+ if (framework === 'expo-go') {
35
+ super('NitroModules are not supported in Expo Go! Use EAS (`expo prebuild`) or eject to a bare workflow instead.');
36
+ return;
37
+ }
38
+ const message = 'Failed to get NitroModules: The native "NitroModules" TurboModule could not be found.';
39
+ const suggestions = [];
40
+ suggestions.push('Make sure react-native-nitro-modules/NitroModules is correctly autolinked (run `npx react-native config` to verify)');
41
+ suggestions.push('Make sure you enabled the new architecture (TurboModules) and CodeGen properly generated the "NativeNitroModules"/NitroModulesCxx specs. See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md');
42
+ suggestions.push('Make sure you are using react-native 0.74.0 or higher, because NitroModules are built with C++ TurboModules.');
43
+ suggestions.push('Make sure you rebuilt the app.');
44
+ if (framework === 'expo') {
45
+ suggestions.push('Make sure you ran `expo prebuild`.');
46
+ }
47
+ switch (Platform.OS) {
48
+ case 'ios':
49
+ case 'macos':
50
+ suggestions.push('Make sure you ran `pod install` in the ios/ directory.');
51
+ break;
52
+ case 'android':
53
+ suggestions.push('Make sure gradle is synced.');
54
+ break;
55
+ default:
56
+ throw new Error(`NitroModules are not yet supported on ${Platform.OS}!`);
57
+ }
58
+ const error = messageWithSuggestions(message, suggestions);
59
+ super(error, { cause: cause });
60
+ }
61
+ }
@@ -0,0 +1,8 @@
1
+ import type { TurboModule } from 'react-native';
2
+ import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
3
+ export interface Spec extends TurboModule {
4
+ install(): void;
5
+ createTestHybridObject(): UnsafeObject;
6
+ createSwiftTestHybridObject(): UnsafeObject;
7
+ }
8
+ export declare const NitroModules: Spec;
@@ -0,0 +1,3 @@
1
+ import { TurboModuleRegistry } from 'react-native';
2
+ export const NitroModules = TurboModuleRegistry.getEnforcing('NitroModulesCxx');
3
+ NitroModules.install();
@@ -0,0 +1,7 @@
1
+ import type { TurboModule } from 'react-native';
2
+ import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
3
+ export interface Spec extends TurboModule {
4
+ install(): void;
5
+ createHybridObject(name: string, args?: UnsafeObject): UnsafeObject;
6
+ }
7
+ export declare function getNativeNitroModules(): Spec;
@@ -0,0 +1,17 @@
1
+ import { TurboModuleRegistry } from 'react-native';
2
+ import { ModuleNotFoundError } from './ModuleNotFoundError';
3
+ let turboModule;
4
+ export function getNativeNitroModules() {
5
+ if (turboModule == null) {
6
+ try {
7
+ // 1. Get (and initialize) the C++ TurboModule
8
+ turboModule = TurboModuleRegistry.getEnforcing('NitroModulesCxx');
9
+ // 2. Install Dispatcher and required bindings into the Runtime
10
+ turboModule.install();
11
+ }
12
+ catch (e) {
13
+ throw new ModuleNotFoundError(e);
14
+ }
15
+ }
16
+ return turboModule;
17
+ }
@@ -0,0 +1,17 @@
1
+ import type { HybridObject } from './HybridObject';
2
+ /**
3
+ * A lazy proxy for initializing Nitro Modules HybridObjects.
4
+ */
5
+ export declare const NitroModules: {
6
+ /**
7
+ * Create a new instance of the `HybridObject` {@linkcode T}.
8
+ *
9
+ * {@linkcode T} has to be registered beforehand under the name {@linkcode name}
10
+ * in the native Nitro Modules `HybridObjectRegistry`.
11
+ *
12
+ * @param name The name of the `HybridObject` under which it was registered at.
13
+ * @returns An instance of {@linkcode T}
14
+ * @throws an Error if {@linkcode T} has not been registered under the name {@linkcode name}.
15
+ */
16
+ get<T extends HybridObject<any>>(name: string): T;
17
+ };
@@ -0,0 +1,21 @@
1
+ import { getNativeNitroModules } from './NativeNitroModules';
2
+ /**
3
+ * A lazy proxy for initializing Nitro Modules HybridObjects.
4
+ */
5
+ export const NitroModules = {
6
+ /**
7
+ * Create a new instance of the `HybridObject` {@linkcode T}.
8
+ *
9
+ * {@linkcode T} has to be registered beforehand under the name {@linkcode name}
10
+ * in the native Nitro Modules `HybridObjectRegistry`.
11
+ *
12
+ * @param name The name of the `HybridObject` under which it was registered at.
13
+ * @returns An instance of {@linkcode T}
14
+ * @throws an Error if {@linkcode T} has not been registered under the name {@linkcode name}.
15
+ */
16
+ get(name) {
17
+ const nitro = getNativeNitroModules();
18
+ const instance = nitro.createHybridObject(name);
19
+ return instance;
20
+ },
21
+ };
File without changes
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ it.todo('write a test');
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=AnyMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["AnyMap.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=HybridObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["HybridObject.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ModuleNotFoundError = void 0;
7
+ var _reactNative = require("react-native");
8
+ const BULLET_POINT = '\n* ';
9
+ function messageWithSuggestions(message, suggestions) {
10
+ return message + BULLET_POINT + suggestions.join(BULLET_POINT);
11
+ }
12
+ function getFrameworkType() {
13
+ // check if Expo
14
+ const ExpoConstants = _reactNative.NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants;
15
+ if (ExpoConstants != null) {
16
+ if (ExpoConstants.appOwnership === 'expo') {
17
+ // We're running Expo Go
18
+ return 'expo-go';
19
+ } else {
20
+ // We're running Expo bare / standalone
21
+ return 'expo';
22
+ }
23
+ }
24
+ return 'react-native';
25
+ }
26
+ class ModuleNotFoundError extends Error {
27
+ constructor(cause) {
28
+ // TurboModule not found, something went wrong!
29
+ if (global.__turboModuleProxy == null) {
30
+ // TurboModules are not available/new arch is not enabled.
31
+ const message = 'Failed to get NitroModules: NitroModules require the new architecture to be enabled!';
32
+ const suggestions = [];
33
+ suggestions.push('Enable the new architecture in your app to use NitroModules. (See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md)');
34
+ const error = messageWithSuggestions(message, suggestions);
35
+ super(error, {
36
+ cause: cause
37
+ });
38
+ return;
39
+ }
40
+ const framework = getFrameworkType();
41
+ if (framework === 'expo-go') {
42
+ super('NitroModules are not supported in Expo Go! Use EAS (`expo prebuild`) or eject to a bare workflow instead.');
43
+ return;
44
+ }
45
+ const message = 'Failed to get NitroModules: The native "NitroModules" TurboModule could not be found.';
46
+ const suggestions = [];
47
+ suggestions.push('Make sure react-native-nitro-modules/NitroModules is correctly autolinked (run `npx react-native config` to verify)');
48
+ suggestions.push('Make sure you enabled the new architecture (TurboModules) and CodeGen properly generated the "NativeNitroModules"/NitroModulesCxx specs. See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md');
49
+ suggestions.push('Make sure you are using react-native 0.74.0 or higher, because NitroModules are built with C++ TurboModules.');
50
+ suggestions.push('Make sure you rebuilt the app.');
51
+ if (framework === 'expo') {
52
+ suggestions.push('Make sure you ran `expo prebuild`.');
53
+ }
54
+ switch (_reactNative.Platform.OS) {
55
+ case 'ios':
56
+ case 'macos':
57
+ suggestions.push('Make sure you ran `pod install` in the ios/ directory.');
58
+ break;
59
+ case 'android':
60
+ suggestions.push('Make sure gradle is synced.');
61
+ break;
62
+ default:
63
+ throw new Error(`NitroModules are not yet supported on ${_reactNative.Platform.OS}!`);
64
+ }
65
+ const error = messageWithSuggestions(message, suggestions);
66
+ super(error, {
67
+ cause: cause
68
+ });
69
+ }
70
+ }
71
+ exports.ModuleNotFoundError = ModuleNotFoundError;
72
+ //# sourceMappingURL=ModuleNotFoundError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","BULLET_POINT","messageWithSuggestions","message","suggestions","join","getFrameworkType","ExpoConstants","NativeModules","NativeUnimoduleProxy","modulesConstants","ExponentConstants","appOwnership","ModuleNotFoundError","Error","constructor","cause","global","__turboModuleProxy","push","error","framework","Platform","OS","exports"],"sourceRoot":"../../src","sources":["ModuleNotFoundError.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAOA,MAAMC,YAAY,GAAG,MAAM;AAE3B,SAASC,sBAAsBA,CAC7BC,OAAe,EACfC,WAAqB,EACb;EACR,OAAOD,OAAO,GAAGF,YAAY,GAAGG,WAAW,CAACC,IAAI,CAACJ,YAAY,CAAC;AAChE;AAEA,SAASK,gBAAgBA,CAAA,EAAwC;EAC/D;EACA,MAAMC,aAAa,GACjBC,0BAAa,CAACC,oBAAoB,EAAEC,gBAAgB,EAAEC,iBAAiB;EACzE,IAAIJ,aAAa,IAAI,IAAI,EAAE;IACzB,IAAIA,aAAa,CAACK,YAAY,KAAK,MAAM,EAAE;MACzC;MACA,OAAO,SAAS;IAClB,CAAC,MAAM;MACL;MACA,OAAO,MAAM;IACf;EACF;EACA,OAAO,cAAc;AACvB;AAEO,MAAMC,mBAAmB,SAASC,KAAK,CAAC;EAC7CC,WAAWA,CAACC,KAAe,EAAE;IAC3B;IACA,IAAIC,MAAM,CAACC,kBAAkB,IAAI,IAAI,EAAE;MACrC;MACA,MAAMf,OAAO,GACX,sFAAsF;MACxF,MAAMC,WAAqB,GAAG,EAAE;MAChCA,WAAW,CAACe,IAAI,CACd,2JACF,CAAC;MACD,MAAMC,KAAK,GAAGlB,sBAAsB,CAACC,OAAO,EAAEC,WAAW,CAAC;MAC1D,KAAK,CAACgB,KAAK,EAAE;QAAEJ,KAAK,EAAEA;MAAM,CAAC,CAAC;MAC9B;IACF;IAEA,MAAMK,SAAS,GAAGf,gBAAgB,CAAC,CAAC;IACpC,IAAIe,SAAS,KAAK,SAAS,EAAE;MAC3B,KAAK,CACH,2GACF,CAAC;MACD;IACF;IAEA,MAAMlB,OAAO,GACX,uFAAuF;IACzF,MAAMC,WAAqB,GAAG,EAAE;IAChCA,WAAW,CAACe,IAAI,CACd,qHACF,CAAC;IACDf,WAAW,CAACe,IAAI,CACd,qOACF,CAAC;IACDf,WAAW,CAACe,IAAI,CACd,8GACF,CAAC;IACDf,WAAW,CAACe,IAAI,CAAC,gCAAgC,CAAC;IAClD,IAAIE,SAAS,KAAK,MAAM,EAAE;MACxBjB,WAAW,CAACe,IAAI,CAAC,oCAAoC,CAAC;IACxD;IACA,QAAQG,qBAAQ,CAACC,EAAE;MACjB,KAAK,KAAK;MACV,KAAK,OAAO;QACVnB,WAAW,CAACe,IAAI,CACd,wDACF,CAAC;QACD;MACF,KAAK,SAAS;QACZf,WAAW,CAACe,IAAI,CAAC,6BAA6B,CAAC;QAC/C;MACF;QACE,MAAM,IAAIL,KAAK,CAAC,yCAAyCQ,qBAAQ,CAACC,EAAE,GAAG,CAAC;IAC5E;IAEA,MAAMH,KAAK,GAAGlB,sBAAsB,CAACC,OAAO,EAAEC,WAAW,CAAC;IAC1D,KAAK,CAACgB,KAAK,EAAE;MAAEJ,KAAK,EAAEA;IAAM,CAAC,CAAC;EAChC;AACF;AAACQ,OAAA,CAAAX,mBAAA,GAAAA,mBAAA","ignoreList":[]}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getNativeNitroModules = getNativeNitroModules;
7
+ var _reactNative = require("react-native");
8
+ var _ModuleNotFoundError = require("./ModuleNotFoundError");
9
+ let turboModule;
10
+ function getNativeNitroModules() {
11
+ if (turboModule == null) {
12
+ try {
13
+ // 1. Get (and initialize) the C++ TurboModule
14
+ turboModule = _reactNative.TurboModuleRegistry.getEnforcing('NitroModulesCxx');
15
+
16
+ // 2. Install Dispatcher and required bindings into the Runtime
17
+ turboModule.install();
18
+ } catch (e) {
19
+ throw new _ModuleNotFoundError.ModuleNotFoundError(e);
20
+ }
21
+ }
22
+ return turboModule;
23
+ }
24
+ //# sourceMappingURL=NativeNitroModules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","_ModuleNotFoundError","turboModule","getNativeNitroModules","TurboModuleRegistry","getEnforcing","install","e","ModuleNotFoundError"],"sourceRoot":"../../src","sources":["NativeNitroModules.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,oBAAA,GAAAD,OAAA;AAOA,IAAIE,WAA6B;AAC1B,SAASC,qBAAqBA,CAAA,EAAS;EAC5C,IAAID,WAAW,IAAI,IAAI,EAAE;IACvB,IAAI;MACF;MACAA,WAAW,GAAGE,gCAAmB,CAACC,YAAY,CAAO,iBAAiB,CAAC;;MAEvE;MACAH,WAAW,CAACI,OAAO,CAAC,CAAC;IACvB,CAAC,CAAC,OAAOC,CAAC,EAAE;MACV,MAAM,IAAIC,wCAAmB,CAACD,CAAC,CAAC;IAClC;EACF;EAEA,OAAOL,WAAW;AACpB","ignoreList":[]}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NitroModules = void 0;
7
+ var _NativeNitroModules = require("./NativeNitroModules");
8
+ // TODO: Do we wanna support such constructors?
9
+ // @ts-expect-error
10
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
11
+
12
+ /**
13
+ * A lazy proxy for initializing Nitro Modules HybridObjects.
14
+ */
15
+ const NitroModules = exports.NitroModules = {
16
+ /**
17
+ * Create a new instance of the `HybridObject` {@linkcode T}.
18
+ *
19
+ * {@linkcode T} has to be registered beforehand under the name {@linkcode name}
20
+ * in the native Nitro Modules `HybridObjectRegistry`.
21
+ *
22
+ * @param name The name of the `HybridObject` under which it was registered at.
23
+ * @returns An instance of {@linkcode T}
24
+ * @throws an Error if {@linkcode T} has not been registered under the name {@linkcode name}.
25
+ */
26
+ get(name) {
27
+ const nitro = (0, _NativeNitroModules.getNativeNitroModules)();
28
+ const instance = nitro.createHybridObject(name);
29
+ return instance;
30
+ }
31
+ };
32
+ //# sourceMappingURL=NitroModules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_NativeNitroModules","require","NitroModules","exports","get","name","nitro","getNativeNitroModules","instance","createHybridObject"],"sourceRoot":"../../src","sources":["NitroModules.ts"],"mappings":";;;;;;AAAA,IAAAA,mBAAA,GAAAC,OAAA;AAGA;AACA;AACA;;AAKA;AACA;AACA;AACO,MAAMC,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAG;EAC1B;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEE,GAAGA,CAA8BC,IAAY,EAAK;IAChD,MAAMC,KAAK,GAAG,IAAAC,yCAAqB,EAAC,CAAC;IACrC,MAAMC,QAAQ,GAAGF,KAAK,CAACG,kBAAkB,CAACJ,IAAI,CAAC;IAC/C,OAAOG,QAAQ;EACjB;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createCppTestHybridObject = createCppTestHybridObject;
7
+ exports.createSwiftTestHybridObject = createSwiftTestHybridObject;
8
+ var _ = require(".");
9
+ function createCppTestHybridObject() {
10
+ return _.NitroModules.get('TestHybridObject');
11
+ }
12
+ function createSwiftTestHybridObject() {
13
+ return _.NitroModules.get('SwiftTestObject');
14
+ }
15
+ //# sourceMappingURL=createTestObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_","require","createCppTestHybridObject","NitroModules","get","createSwiftTestHybridObject"],"sourceRoot":"../../src","sources":["createTestObject.ts"],"mappings":";;;;;;;AAAA,IAAAA,CAAA,GAAAC,OAAA;AAyBO,SAASC,yBAAyBA,CAAA,EAAqB;EAC5D,OAAOC,cAAY,CAACC,GAAG,CAAmB,kBAAkB,CAAC;AAC/D;AAUO,SAASC,2BAA2BA,CAAA,EAA0B;EACnE,OAAOF,cAAY,CAACC,GAAG,CAAwB,iBAAiB,CAAC;AACnE","ignoreList":[]}
@@ -3,9 +3,48 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.multiply = multiply;
7
- const Nitro = require('./NativeNitro').default;
8
- function multiply(a, b) {
9
- return Nitro.multiply(a, b);
10
- }
6
+ var _createTestObject = require("./createTestObject");
7
+ Object.keys(_createTestObject).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _createTestObject[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _createTestObject[key];
14
+ }
15
+ });
16
+ });
17
+ var _HybridObject = require("./HybridObject");
18
+ Object.keys(_HybridObject).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _HybridObject[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _HybridObject[key];
25
+ }
26
+ });
27
+ });
28
+ var _NitroModules = require("./NitroModules");
29
+ Object.keys(_NitroModules).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _NitroModules[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _NitroModules[key];
36
+ }
37
+ });
38
+ });
39
+ var _AnyMap = require("./AnyMap");
40
+ Object.keys(_AnyMap).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _AnyMap[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _AnyMap[key];
47
+ }
48
+ });
49
+ });
11
50
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Nitro","require","default","multiply","a","b"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA,MAAMA,KAAK,GAAGC,OAAO,CAAC,eAAe,CAAC,CAACC,OAAO;AAEvC,SAASC,QAAQA,CAACC,CAAS,EAAEC,CAAS,EAAU;EACrD,OAAOL,KAAK,CAACG,QAAQ,CAACC,CAAC,EAAEC,CAAC,CAAC;AAC7B","ignoreList":[]}
1
+ {"version":3,"names":["_createTestObject","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_HybridObject","_NitroModules","_AnyMap"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;AAAA,IAAAA,iBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,iBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,iBAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,iBAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,aAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,aAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,aAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,aAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,aAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,aAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,aAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,aAAA,CAAAN,GAAA;IAAA;EAAA;AAAA;AACA,IAAAO,OAAA,GAAAX,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAS,OAAA,EAAAR,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAO,OAAA,CAAAP,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAG,OAAA,CAAAP,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -0,0 +1,22 @@
1
+ import { type HybridObject } from '.';
2
+ export interface TestHybridObject extends HybridObject<{}> {
3
+ int: number;
4
+ string: string;
5
+ nullableString: string | undefined;
6
+ multipleArguments(first: number, second: boolean, third: string): Record<string, number>;
7
+ getIntGetter(): () => number;
8
+ sayHelloCallback(callback: (name: string) => void): void;
9
+ createNewHybridObject(): TestHybridObject;
10
+ calculateFibonacci(count: number): bigint;
11
+ calculateFibonacciAsync(count: number): Promise<bigint>;
12
+ asyncVoidFunc(): Promise<void>;
13
+ syncVoidFunc(): void;
14
+ throwError(): void;
15
+ }
16
+ export declare function createCppTestHybridObject(): TestHybridObject;
17
+ export interface SwiftTestHybridObject extends HybridObject<{}> {
18
+ int: number;
19
+ throwError(): number;
20
+ asyncMethod(): Promise<number>;
21
+ }
22
+ export declare function createSwiftTestHybridObject(): SwiftTestHybridObject;
@@ -0,0 +1,7 @@
1
+ import { NitroModules } from '.';
2
+ export function createCppTestHybridObject() {
3
+ return NitroModules.get('TestHybridObject');
4
+ }
5
+ export function createSwiftTestHybridObject() {
6
+ return NitroModules.get('SwiftTestObject');
7
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './createTestObject';
2
+ export * from './HybridObject';
3
+ export * from './NitroModules';
4
+ export * from './AnyMap';
package/lib/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './createTestObject';
2
+ export * from './HybridObject';
3
+ export * from './NitroModules';
4
+ export * from './AnyMap';
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=AnyMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["AnyMap.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=HybridObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["HybridObject.ts"],"mappings":"","ignoreList":[]}