nitro-core 0.0.0 → 0.37.2-nightly.32.gcd7b91624dde
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/LICENSE +20 -0
- package/README.md +52 -0
- package/js/lib/commonjs/AnyHybridObject.js +3 -0
- package/js/lib/commonjs/AnyHybridObject.js.map +1 -0
- package/js/lib/commonjs/AnyMap.js +3 -0
- package/js/lib/commonjs/AnyMap.js.map +1 -0
- package/js/lib/commonjs/BoxedHybridObject.js +3 -0
- package/js/lib/commonjs/BoxedHybridObject.js.map +1 -0
- package/js/lib/commonjs/CustomType.js +3 -0
- package/js/lib/commonjs/CustomType.js.map +1 -0
- package/js/lib/commonjs/HybridObject.js +3 -0
- package/js/lib/commonjs/HybridObject.js.map +1 -0
- package/js/lib/commonjs/Int64.js +3 -0
- package/js/lib/commonjs/Int64.js.map +1 -0
- package/js/lib/commonjs/NitroModules.js +35 -0
- package/js/lib/commonjs/NitroModules.js.map +1 -0
- package/js/lib/commonjs/NitroModulesProxy.js +3 -0
- package/js/lib/commonjs/NitroModulesProxy.js.map +1 -0
- package/js/lib/commonjs/Sync.js +3 -0
- package/js/lib/commonjs/Sync.js.map +1 -0
- package/js/lib/commonjs/checkNitroVersion.js +25 -0
- package/js/lib/commonjs/checkNitroVersion.js.map +1 -0
- package/js/lib/commonjs/getHybridObjectConstructor.js +65 -0
- package/js/lib/commonjs/getHybridObjectConstructor.js.map +1 -0
- package/js/lib/commonjs/globals.js +3 -0
- package/js/lib/commonjs/globals.js.map +1 -0
- package/js/lib/commonjs/index.js +29 -0
- package/js/lib/commonjs/index.js.map +1 -0
- package/js/lib/commonjs/package.json +1 -0
- package/js/lib/commonjs/version.js +6 -0
- package/js/lib/commonjs/version.js.map +1 -0
- package/js/lib/module/AnyHybridObject.js +2 -0
- package/js/lib/module/AnyHybridObject.js.map +1 -0
- package/js/lib/module/AnyMap.js +2 -0
- package/js/lib/module/AnyMap.js.map +1 -0
- package/js/lib/module/BoxedHybridObject.js +2 -0
- package/js/lib/module/BoxedHybridObject.js.map +1 -0
- package/js/lib/module/CustomType.js +2 -0
- package/js/lib/module/CustomType.js.map +1 -0
- package/js/lib/module/HybridObject.js +2 -0
- package/js/lib/module/HybridObject.js.map +1 -0
- package/js/lib/module/Int64.js +2 -0
- package/js/lib/module/Int64.js.map +1 -0
- package/js/lib/module/NitroModules.js +37 -0
- package/js/lib/module/NitroModules.js.map +1 -0
- package/js/lib/module/NitroModulesProxy.js +2 -0
- package/js/lib/module/NitroModulesProxy.js.map +1 -0
- package/js/lib/module/Sync.js +2 -0
- package/js/lib/module/Sync.js.map +1 -0
- package/js/lib/module/checkNitroVersion.js +21 -0
- package/js/lib/module/checkNitroVersion.js.map +1 -0
- package/js/lib/module/getHybridObjectConstructor.js +62 -0
- package/js/lib/module/getHybridObjectConstructor.js.map +1 -0
- package/js/lib/module/globals.js +3 -0
- package/js/lib/module/globals.js.map +1 -0
- package/js/lib/module/index.js +13 -0
- package/js/lib/module/index.js.map +1 -0
- package/js/lib/module/package.json +1 -0
- package/js/lib/module/version.js +3 -0
- package/js/lib/module/version.js.map +1 -0
- package/js/lib/typescript/commonjs/AnyHybridObject.d.ts +10 -0
- package/js/lib/typescript/commonjs/AnyHybridObject.d.ts.map +1 -0
- package/js/lib/typescript/commonjs/AnyMap.d.ts +21 -0
- package/js/lib/typescript/commonjs/AnyMap.d.ts.map +1 -0
- package/js/lib/typescript/commonjs/BoxedHybridObject.d.ts +13 -0
- package/js/lib/typescript/commonjs/BoxedHybridObject.d.ts.map +1 -0
- package/js/lib/typescript/commonjs/CustomType.d.ts +57 -0
- package/js/lib/typescript/commonjs/CustomType.d.ts.map +1 -0
- package/js/lib/typescript/commonjs/HybridObject.d.ts +96 -0
- package/js/lib/typescript/commonjs/HybridObject.d.ts.map +1 -0
- package/js/lib/typescript/commonjs/Int64.d.ts +13 -0
- package/js/lib/typescript/commonjs/Int64.d.ts.map +1 -0
- package/js/lib/typescript/commonjs/NitroModules.d.ts +25 -0
- package/js/lib/typescript/commonjs/NitroModules.d.ts.map +1 -0
- package/js/lib/typescript/commonjs/NitroModulesProxy.d.ts +98 -0
- package/js/lib/typescript/commonjs/NitroModulesProxy.d.ts.map +1 -0
- package/js/lib/typescript/commonjs/Sync.d.ts +11 -0
- package/js/lib/typescript/commonjs/Sync.d.ts.map +1 -0
- package/js/lib/typescript/commonjs/checkNitroVersion.d.ts +11 -0
- package/js/lib/typescript/commonjs/checkNitroVersion.d.ts.map +1 -0
- package/js/lib/typescript/commonjs/getHybridObjectConstructor.d.ts +18 -0
- package/js/lib/typescript/commonjs/getHybridObjectConstructor.d.ts.map +1 -0
- package/js/lib/typescript/commonjs/globals.d.ts +28 -0
- package/js/lib/typescript/commonjs/globals.d.ts.map +1 -0
- package/js/lib/typescript/commonjs/index.d.ts +13 -0
- package/js/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/js/lib/typescript/commonjs/package.json +1 -0
- package/js/lib/typescript/commonjs/version.d.ts +2 -0
- package/js/lib/typescript/commonjs/version.d.ts.map +1 -0
- package/js/lib/typescript/module/AnyHybridObject.d.ts +10 -0
- package/js/lib/typescript/module/AnyHybridObject.d.ts.map +1 -0
- package/js/lib/typescript/module/AnyMap.d.ts +21 -0
- package/js/lib/typescript/module/AnyMap.d.ts.map +1 -0
- package/js/lib/typescript/module/BoxedHybridObject.d.ts +13 -0
- package/js/lib/typescript/module/BoxedHybridObject.d.ts.map +1 -0
- package/js/lib/typescript/module/CustomType.d.ts +57 -0
- package/js/lib/typescript/module/CustomType.d.ts.map +1 -0
- package/js/lib/typescript/module/HybridObject.d.ts +96 -0
- package/js/lib/typescript/module/HybridObject.d.ts.map +1 -0
- package/js/lib/typescript/module/Int64.d.ts +13 -0
- package/js/lib/typescript/module/Int64.d.ts.map +1 -0
- package/js/lib/typescript/module/NitroModules.d.ts +25 -0
- package/js/lib/typescript/module/NitroModules.d.ts.map +1 -0
- package/js/lib/typescript/module/NitroModulesProxy.d.ts +98 -0
- package/js/lib/typescript/module/NitroModulesProxy.d.ts.map +1 -0
- package/js/lib/typescript/module/Sync.d.ts +11 -0
- package/js/lib/typescript/module/Sync.d.ts.map +1 -0
- package/js/lib/typescript/module/checkNitroVersion.d.ts +11 -0
- package/js/lib/typescript/module/checkNitroVersion.d.ts.map +1 -0
- package/js/lib/typescript/module/getHybridObjectConstructor.d.ts +18 -0
- package/js/lib/typescript/module/getHybridObjectConstructor.d.ts.map +1 -0
- package/js/lib/typescript/module/globals.d.ts +28 -0
- package/js/lib/typescript/module/globals.d.ts.map +1 -0
- package/js/lib/typescript/module/index.d.ts +13 -0
- package/js/lib/typescript/module/index.d.ts.map +1 -0
- package/js/lib/typescript/module/package.json +1 -0
- package/js/lib/typescript/module/version.d.ts +2 -0
- package/js/lib/typescript/module/version.d.ts.map +1 -0
- package/js/src/AnyHybridObject.ts +10 -0
- package/js/src/AnyMap.ts +27 -0
- package/js/src/BoxedHybridObject.ts +13 -0
- package/js/src/CustomType.ts +61 -0
- package/js/src/HybridObject.ts +96 -0
- package/js/src/Int64.ts +9 -0
- package/js/src/NitroModules.ts +43 -0
- package/js/src/NitroModulesProxy.ts +104 -0
- package/js/src/Sync.ts +8 -0
- package/js/src/checkNitroVersion.ts +29 -0
- package/js/src/getHybridObjectConstructor.ts +69 -0
- package/js/src/globals.ts +29 -0
- package/js/src/index.ts +13 -0
- package/js/src/version.ts +2 -0
- package/native/android/src/main/AndroidManifest.xml +2 -0
- package/native/android/src/main/cpp/NitroOnLoad.cpp +22 -0
- package/native/android/src/main/cpp/NitroOnLoad.hpp +8 -0
- package/native/android/src/main/cpp/core/ByteBufferArrayBuffer.hpp +55 -0
- package/native/android/src/main/cpp/core/HardwareBufferArrayBuffer.hpp +107 -0
- package/native/android/src/main/cpp/core/JAnyMap.cpp +218 -0
- package/native/android/src/main/cpp/core/JAnyMap.hpp +222 -0
- package/native/android/src/main/cpp/core/JAnyValue.hpp +191 -0
- package/native/android/src/main/cpp/core/JArrayBuffer.hpp +187 -0
- package/native/android/src/main/cpp/core/JHybridObject.cpp +84 -0
- package/native/android/src/main/cpp/core/JHybridObject.hpp +59 -0
- package/native/android/src/main/cpp/core/JInstant.hpp +54 -0
- package/native/android/src/main/cpp/core/JNull.hpp +33 -0
- package/native/android/src/main/cpp/core/JPromise.hpp +167 -0
- package/native/android/src/main/cpp/platform/NitroLogger.cpp +39 -0
- package/native/android/src/main/cpp/platform/ThreadUtils.cpp +42 -0
- package/native/android/src/main/cpp/registry/DefaultConstructableObject.hpp +79 -0
- package/native/android/src/main/cpp/registry/JHybridObjectInitializer.hpp +29 -0
- package/native/android/src/main/cpp/threading/UIThreadDispatcher.cpp +21 -0
- package/native/android/src/main/cpp/threading/UIThreadDispatcher.hpp +14 -0
- package/native/android/src/main/cpp/utils/JHardwareBufferUtils.cpp +150 -0
- package/native/android/src/main/cpp/utils/JHardwareBufferUtils.hpp +39 -0
- package/native/android/src/main/cpp/utils/JNICallable.hpp +50 -0
- package/native/android/src/main/cpp/utils/JNISharedPtr.hpp +69 -0
- package/native/android/src/main/cpp/utils/JNativeRunnable.hpp +33 -0
- package/native/android/src/main/cpp/utils/JRunnable.hpp +18 -0
- package/native/android/src/main/cpp/utils/JThreadUtils.hpp +39 -0
- package/native/android/src/main/cpp/utils/JUnit.hpp +38 -0
- package/native/android/src/main/java/com/margelo/nitro/JNIOnLoad.java +27 -0
- package/native/android/src/main/java/com/margelo/nitro/core/AnyMap.kt +176 -0
- package/native/android/src/main/java/com/margelo/nitro/core/AnyValue.kt +261 -0
- package/native/android/src/main/java/com/margelo/nitro/core/ArrayBuffer.kt +287 -0
- package/native/android/src/main/java/com/margelo/nitro/core/HybridObject.kt +129 -0
- package/native/android/src/main/java/com/margelo/nitro/core/Null.kt +28 -0
- package/native/android/src/main/java/com/margelo/nitro/core/Promise.kt +207 -0
- package/native/android/src/main/java/com/margelo/nitro/utils/HardwareBuffer+updateFrom.kt +14 -0
- package/native/android/src/main/java/com/margelo/nitro/utils/HardwareBufferUtils.kt +53 -0
- package/native/android/src/main/java/com/margelo/nitro/utils/NativeRunnable.kt +18 -0
- package/native/android/src/main/java/com/margelo/nitro/utils/ThreadUtils.kt +43 -0
- package/native/apple/core/AnyMap.swift +467 -0
- package/native/apple/core/ArrayBuffer.swift +164 -0
- package/native/apple/core/ArrayBufferHolder.hpp +80 -0
- package/native/apple/core/HybridObject.swift +54 -0
- package/native/apple/core/Null.swift +14 -0
- package/native/apple/core/Promise.swift +247 -0
- package/native/apple/core/PromiseHolder.hpp +93 -0
- package/native/apple/core/RuntimeError.swift +51 -0
- package/native/apple/platform/NitroLogger.cpp +37 -0
- package/native/apple/platform/ThreadUtils.cpp +52 -0
- package/native/apple/threading/UIThreadDispatcher.cpp +19 -0
- package/native/apple/threading/UIThreadDispatcher.hpp +19 -0
- package/native/apple/utils/AnyMapUtils.hpp +103 -0
- package/native/apple/utils/Date+fromChrono.swift +27 -0
- package/native/apple/utils/DateToChronoDate.hpp +35 -0
- package/native/apple/utils/MemoryHelper.swift +19 -0
- package/native/apple/utils/Result.hpp +193 -0
- package/native/apple/utils/RuntimeError.hpp +35 -0
- package/native/apple/utils/SwiftClosure.hpp +67 -0
- package/native/apple/utils/SwiftClosure.swift +51 -0
- package/native/cpp/core/AnyMap.cpp +202 -0
- package/native/cpp/core/AnyMap.hpp +216 -0
- package/native/cpp/core/ArrayBuffer.cpp +115 -0
- package/native/cpp/core/ArrayBuffer.hpp +169 -0
- package/native/cpp/core/BoxedHybridObject.cpp +30 -0
- package/native/cpp/core/BoxedHybridObject.hpp +36 -0
- package/native/cpp/core/HybridFunction.hpp +270 -0
- package/native/cpp/core/HybridObject.cpp +117 -0
- package/native/cpp/core/HybridObject.hpp +152 -0
- package/native/cpp/core/Null.hpp +42 -0
- package/native/cpp/core/Promise.cpp +148 -0
- package/native/cpp/core/Promise.hpp +373 -0
- package/native/cpp/entrypoint/HybridNitroModulesProxy.cpp +114 -0
- package/native/cpp/entrypoint/HybridNitroModulesProxy.hpp +58 -0
- package/native/cpp/entrypoint/InstallNitro.cpp +29 -0
- package/native/cpp/entrypoint/InstallNitro.hpp +41 -0
- package/native/cpp/jsi/JSICache.cpp +72 -0
- package/native/cpp/jsi/JSICache.hpp +129 -0
- package/native/cpp/jsi/JSIConverter+AnyMap.hpp +89 -0
- package/native/cpp/jsi/JSIConverter+ArrayBuffer.hpp +106 -0
- package/native/cpp/jsi/JSIConverter+Date.hpp +81 -0
- package/native/cpp/jsi/JSIConverter+Exception.hpp +59 -0
- package/native/cpp/jsi/JSIConverter+Function.hpp +99 -0
- package/native/cpp/jsi/JSIConverter+HostObject.hpp +73 -0
- package/native/cpp/jsi/JSIConverter+NativeState.hpp +93 -0
- package/native/cpp/jsi/JSIConverter+Null.hpp +38 -0
- package/native/cpp/jsi/JSIConverter+Optional.hpp +50 -0
- package/native/cpp/jsi/JSIConverter+Promise.hpp +106 -0
- package/native/cpp/jsi/JSIConverter+Tuple.hpp +93 -0
- package/native/cpp/jsi/JSIConverter+UnorderedMap.hpp +73 -0
- package/native/cpp/jsi/JSIConverter+Variant.hpp +67 -0
- package/native/cpp/jsi/JSIConverter+Vector.hpp +69 -0
- package/native/cpp/jsi/JSIConverter.hpp +197 -0
- package/native/cpp/jsi/JSIHelpers.hpp +52 -0
- package/native/cpp/platform/NitroLogger.hpp +71 -0
- package/native/cpp/platform/ThreadUtils.hpp +44 -0
- package/native/cpp/prototype/HybridObjectPrototype.cpp +130 -0
- package/native/cpp/prototype/HybridObjectPrototype.hpp +87 -0
- package/native/cpp/prototype/Prototype.hpp +178 -0
- package/native/cpp/prototype/PrototypeChain.hpp +78 -0
- package/native/cpp/registry/HybridObjectRegistry.cpp +105 -0
- package/native/cpp/registry/HybridObjectRegistry.hpp +53 -0
- package/native/cpp/templates/CountTrailingOptionals.hpp +64 -0
- package/native/cpp/templates/FutureType.hpp +28 -0
- package/native/cpp/templates/InstanceMethod.hpp +23 -0
- package/native/cpp/templates/IsFunctionProp.hpp +23 -0
- package/native/cpp/templates/IsSharedPtrTo.hpp +27 -0
- package/native/cpp/templates/PromiseType.hpp +44 -0
- package/native/cpp/templates/TypeIndex.hpp +29 -0
- package/native/cpp/threading/Dispatcher.cpp +77 -0
- package/native/cpp/threading/Dispatcher.hpp +83 -0
- package/native/cpp/threading/ThreadPool.cpp +97 -0
- package/native/cpp/threading/ThreadPool.hpp +66 -0
- package/native/cpp/utils/AssertPromiseState.hpp +34 -0
- package/native/cpp/utils/BorrowingReference.hpp +223 -0
- package/native/cpp/utils/CommonGlobals.cpp +217 -0
- package/native/cpp/utils/CommonGlobals.hpp +158 -0
- package/native/cpp/utils/FastVectorCopy.hpp +45 -0
- package/native/cpp/utils/JSCallback.hpp +132 -0
- package/native/cpp/utils/NitroDefines.hpp +73 -0
- package/native/cpp/utils/NitroHash.hpp +61 -0
- package/native/cpp/utils/NitroTypeInfo.cpp +80 -0
- package/native/cpp/utils/NitroTypeInfo.hpp +66 -0
- package/native/cpp/utils/PropNameIDCache.cpp +42 -0
- package/native/cpp/utils/PropNameIDCache.hpp +57 -0
- package/native/cpp/utils/ReferenceState.hpp +40 -0
- package/native/cpp/utils/WeakReference+Borrowing.hpp +33 -0
- package/native/cpp/utils/WeakReference.hpp +119 -0
- package/package.json +51 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Marc Rousavy
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# nitro-core
|
|
2
|
+
|
|
3
|
+
Nitro's shared runtime sources and JavaScript API.
|
|
4
|
+
|
|
5
|
+
The package contains native sources in `native/{cpp,apple,android}/`, TypeScript
|
|
6
|
+
sources in `js/src/`, and compiled JavaScript and declarations in `js/lib/`.
|
|
7
|
+
Native sources and JS use the same package version. Core has no React Native
|
|
8
|
+
dependency. Views, TurboModules, and React Native dispatchers live in
|
|
9
|
+
`react-native-nitro-modules`, which stages Core sources for CocoaPods and Android
|
|
10
|
+
builds.
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import type { HybridObject } from 'nitro-core'
|
|
14
|
+
|
|
15
|
+
export interface Image extends HybridObject<{ ios: 'swift', android: 'kotlin' }> {
|
|
16
|
+
readonly width: number
|
|
17
|
+
readonly height: number
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The package includes `HybridObject`, platform and custom type definitions,
|
|
22
|
+
`NitroModulesProxy`, and helpers such as `getHybridObjectConstructor`.
|
|
23
|
+
Nitrogen reads these definitions when generating native bindings.
|
|
24
|
+
|
|
25
|
+
Importing the package does not install Nitro or require a native runtime.
|
|
26
|
+
The host integration installs the native proxy and dispatcher, checks its
|
|
27
|
+
version, then calls `getNitroModules()` to initialize the exported
|
|
28
|
+
`NitroModules` binding. The binding is the native object itself.
|
|
29
|
+
Call `getInstalledNitro()` to check whether the current runtime has a proxy.
|
|
30
|
+
|
|
31
|
+
Each loaded module instance has its own `NitroModules` binding. Code loaded
|
|
32
|
+
independently, including a separate CommonJS or ESM copy, should call
|
|
33
|
+
`getNitroModules()` to initialize its binding and access the runtime's native
|
|
34
|
+
proxy.
|
|
35
|
+
|
|
36
|
+
React Native applications should initialize Nitro through
|
|
37
|
+
`react-native-nitro-modules`, which re-exports these APIs and handles native
|
|
38
|
+
installation and worklets support:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { NitroModules, type HybridObject } from 'react-native-nitro-modules'
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Keep `nitro-core`, Nitrogen, and the host integration on the same release version.
|
|
45
|
+
The host integration package supplies platform build integration and stages the
|
|
46
|
+
native sources from its exact `nitro-core` dependency. Staged files are generated;
|
|
47
|
+
Core implementation changes belong in this package. React Native adapter changes
|
|
48
|
+
belong in `react-native-nitro-modules`.
|
|
49
|
+
|
|
50
|
+
The React Native entry resolves to compiled JavaScript. After editing this
|
|
51
|
+
package, run `bun run build` before rebuilding an app. Validate native changes
|
|
52
|
+
in both `tests/standalone` and `tests/react-native` in this repository.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnyHybridObject.js","sourceRoot":"","sources":["../../src/AnyHybridObject.ts"],"names":[],"mappings":"","sourcesContent":["import type { HybridObject } from './HybridObject.js'\n\n/**\n * Represents a value of the base `HybridObject` type all other\n * HybridObjects inherit from.\n * This is not type-checked to an actual `HybridObject` (boxed).\n */\nexport interface AnyHybridObject extends HybridObject<{}> {\n __anyHybridObjectTag?: never\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnyMap.js","sourceRoot":"","sources":["../../src/AnyMap.ts"],"names":[],"mappings":"","sourcesContent":["import type { Int64 } from './Int64.js'\n\n/**\n * Represents a single value inside an untyped map.\n */\nexport type ValueType =\n | string\n | number\n | boolean\n | Int64\n | null\n | ValueType[]\n | { [k: string]: ValueType }\n\n/**\n * Represents an untyped map, similar to a JSON structure.\n * Supported types:\n * - Primitives (`string`, `number`, `boolean`, `Int64`, `null`)\n * - Arrays of primitives (`ValueType[]`)\n * - Objects of primitives (`Record<string, ValueType>`)\n * - Arrays of arrays or objects\n * - Objects of arrays or objects\n *\n * @note It is recommended to always use typed `interface`s instead of `AnyMap` for\n * both type safety, as well as better performance.\n */\nexport type AnyMap = Record<string, ValueType>\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BoxedHybridObject.js","sourceRoot":"","sources":["../../src/BoxedHybridObject.ts"],"names":[],"mappings":"","sourcesContent":["import type { HybridObject } from './HybridObject.js'\n\n/**\n * Represents a boxed {@linkcode HybridObject} that can later be unboxed again.\n * This is implemented as a `jsi::HostObject`.\n */\nexport interface BoxedHybridObject<T extends HybridObject<{}>> {\n /**\n * Unboxes the {@linkcode HybridObject}.\n * This can be called from a different Runtime than the one it was boxed in.\n */\n unbox(): T\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomType.js","sourceRoot":"","sources":["../../src/CustomType.ts"],"names":[],"mappings":"","sourcesContent":["export interface CustomTypeConfig {\n /**\n * Represents the name of the C++ header that will be included\n * to support your type.\n *\n * This C++ header should be written by you, and findable within\n * the user-search-paths so it can be included.\n */\n include: string\n /**\n * A flag that enables const-reference passing for heavy types\n * to prevent unnecessary copies.\n * When `true`, the type will be passed to clients as a `const T&` instead of just `T`.\n * @default false\n */\n canBePassedByReference?: boolean\n}\n\n/**\n * Represents a custom, manually written native type.\n * - {@linkcode TypeName}: Represents the name of the C++ type (class, struct, alias).\n * - {@linkcode Config}: Configures how the C++ type is included, used, and typed.\n *\n * **You** then need to create a header file that is importable with the filename specified in {@linkcode Config.include}.\n * @example\n * ```ts\n * type MyOwnString = CustomType<string, 'MyOwnString', { include: 'MyOwnString.hpp' }>\n * interface MyHybrid extends HybridObject<{ … }> {\n * getValue(): MyOwnString\n * }\n * ```\n * The C++ header will always be included by Nitro as a user-search-path header, that is;\n * ```cpp\n * #include \"MyOwnString.hpp\"\n * ```\n * The C++ header (`MyOwnString.hpp`) then needs to define the type `MyOwnString`\n * within the namespace of your Nitro Module (`namespace margelo::nitro::...`),\n * and an overload for `JSIConverter<MyOwnString>` within the Nitro core namespace\n * (`namespace margelo::nitro`):\n * ```cpp\n * namespace margelo::nitro::test {\n * using MyOwnString = std::string;\n * }\n * namespace margelo::nitro {\n * template<>\n * struct JSIConverter<test::MyOwnString> final {\n * static test::MyOwnString fromJSI(jsi::Runtime&, const jsi::Value&);\n * static jsi::Value toJSI(jsi::Runtime&, test::MyOwnString);\n * static bool canConvert(jsi::Runtime&, const jsi::Value& value);\n * }\n * }\n * ```\n */\nexport type CustomType<\n T,\n TypeName extends string,\n Config extends CustomTypeConfig,\n> = T & {\n readonly __customTypeName?: TypeName\n readonly __customTypeConfig?: Config\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HybridObject.js","sourceRoot":"","sources":["../../src/HybridObject.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Describes the languages this component will be implemented in.\n *\n * By default, everything has a C++ base, and can optionally be bridged down\n * to platform-specific languages like Swift or Kotlin\n */\nexport interface PlatformSpec {\n ios?: 'c++' | 'swift'\n android?: 'c++' | 'kotlin'\n}\n\n/**\n * Represents a Nitro `HybridObject` which is implemented in a native language like\n * C++, Swift or Kotlin.\n * Every Nitro `HybridObject` has a C++ base, and can optionally be bridged down to Swift or Kotlin.\n *\n * `HybridObject`s use the Nitro Tunnel for efficient, low-overhead JS <-> Native communication.\n *\n * All `HybridObject`s are implemented using `NativeState`, and inherit their properties\n * and methods from their prototype, so the actual JS object is empty.\n *\n * @type Platforms: The type of platforms this HybridObject will be implemented in.\n * @example\n * ```ts\n * interface Photo extends HybridObject<{ ios: 'swift', android: 'kotlin' }> {\n * readonly width: number\n * readonly height: number\n * toArrayBuffer(): ArrayBuffer\n * saveToFile(path: string): Promise<void>\n * }\n * ```\n */\nexport interface HybridObject<Platforms extends PlatformSpec> {\n /**\n * Holds a type-name describing the native `HybridObject` instance.\n *\n * This is the only property actually present on the actual JavaScript object,\n * because all other properties and methods are inherited from a shared Prototype.\n *\n * Nitro prototypes also have a `__type`.\n *\n * - For actual HybridObject instances, this is `HybridObject<...>`\n * - For prototypes this is `Prototype<...>`.\n *\n * @internal\n * @private\n * @note This value is available in debug only.\n */\n readonly __type?: string\n /**\n * The `HybridObject`'s name.\n */\n readonly name: string\n /**\n * Returns a string representation of the given `HybridObject`.\n *\n * Unless overridden by the `HybridObject`, this will return the name of the object.\n *\n * @example\n * ```ts\n * const hybridA = SomeModule.getExistingHybridInstance()\n * console.log(hybridA.toString()) // [HybridObject HybridA]\n * ```\n */\n toString(): string\n /**\n * Returns whether this `HybridObject` is the same object as {@linkcode other}.\n *\n * While two `HybridObject`s might not be equal when compared with `==`, they might still\n * hold the same underlying `HybridObject`, in which case {@linkcode equals | equals(other)}\n * will return `true`.\n *\n * @example\n * ```ts\n * const hybridA = SomeModule.getExistingHybridInstance()\n * const hybridB = SomeModule.getExistingHybridInstance()\n * console.log(hybridA.equals(hybridB)) // true\n * ```\n */\n equals(other: HybridObject<Platforms>): boolean\n /**\n * Disposes any resources this {@linkcode HybridObject} might hold natively,\n * and releases this {@linkcode HybridObject}'s `NativeState`.\n *\n * After calling {@linkcode dispose()}, this object can no longer be used.\n *\n * Eagerly disposing a {@linkcode HybridObject} could be beneficial for a queue-/handler-architecture\n * where a bunch of Hybrid Objects are allocated, and later deallocated once a callback (e.g. a render function)\n * completes.\n *\n * @note It is **NOT** required to call {@linkcode dispose()} manually, as the JavaScript\n * Garbage Collector automatically disposes and releases any resources when needed.\n * It is purely optional to eagerly-, and manually-, call {@linkcode dispose()} here - **use with caution!**\n */\n dispose(): void\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Int64.js","sourceRoot":"","sources":["../../src/Int64.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Represents an unsigned 64-bit integer (or \"uint64\").\n */\nexport type UInt64 = bigint & { __unsignedTag?: never }\n\n/**\n * Represents a signed 64-bit integer (or \"int64\").\n */\nexport type Int64 = bigint & { __signedTag?: never }\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NitroModules = void 0;
|
|
4
|
+
exports.getInstalledNitro = getInstalledNitro;
|
|
5
|
+
exports.getNitroModules = getNitroModules;
|
|
6
|
+
exports.isRuntimeAlive = isRuntimeAlive;
|
|
7
|
+
require("./globals.js");
|
|
8
|
+
/**
|
|
9
|
+
* Returns the native proxy, if this JavaScript runtime has installed Nitro.
|
|
10
|
+
* This does not install Nitro or initialize the {@linkcode NitroModules} binding.
|
|
11
|
+
*/
|
|
12
|
+
function getInstalledNitro() {
|
|
13
|
+
return globalThis.NitroModulesProxy;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns the installed native proxy and initializes {@linkcode NitroModules}.
|
|
17
|
+
* The host integration is responsible for installing Nitro first.
|
|
18
|
+
*/
|
|
19
|
+
function getNitroModules() {
|
|
20
|
+
const nitroModules = getInstalledNitro();
|
|
21
|
+
if (nitroModules == null) {
|
|
22
|
+
throw new Error('Nitro is not installed in this JavaScript runtime. Initialize the host integration before using NitroModules.');
|
|
23
|
+
}
|
|
24
|
+
exports.NitroModules = nitroModules;
|
|
25
|
+
return nitroModules;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns whether the runtime still has Nitro's JSI cache and dispatcher.
|
|
29
|
+
*/
|
|
30
|
+
function isRuntimeAlive() {
|
|
31
|
+
const cache = globalThis.__nitroJsiCache;
|
|
32
|
+
const dispatcher = globalThis.__nitroDispatcher;
|
|
33
|
+
return cache != null && dispatcher != null;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=NitroModules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NitroModules.js","sourceRoot":"","sources":["../../src/NitroModules.ts"],"names":[],"mappings":";;;AAgBA,8CAEC;AAMD,0CASC;AAKD,wCAIC;AAzCD,wBAAqB;AAWrB;;;GAGG;AACH,SAAgB,iBAAiB;IAC/B,OAAO,UAAU,CAAC,iBAAkD,CAAA;AACtE,CAAC;AAED;;;GAGG;AACH,SAAgB,eAAe;IAC7B,MAAM,YAAY,GAAG,iBAAiB,EAAE,CAAA;IACxC,IAAI,YAAY,IAAI,IAAI,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,+GAA+G,CAChH,CAAA;IACH,CAAC;IACD,oBAAY,GAAG,YAAY,CAAA;IAC3B,OAAO,YAAY,CAAA;AACrB,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc;IAC5B,MAAM,KAAK,GAAG,UAAU,CAAC,eAAe,CAAA;IACxC,MAAM,UAAU,GAAG,UAAU,CAAC,iBAAiB,CAAA;IAC/C,OAAO,KAAK,IAAI,IAAI,IAAI,UAAU,IAAI,IAAI,CAAA;AAC5C,CAAC","sourcesContent":["import type { NitroModulesProxy } from './NitroModulesProxy.js'\nimport './globals.js'\n\n/**\n * The installed native Nitro entry point.\n *\n * A host integration must call {@linkcode getNitroModules} after installing\n * Nitro into the JavaScript runtime. The binding then refers to that same\n * native object, including its NativeState and prototype.\n */\nexport let NitroModules: NitroModulesProxy\n\n/**\n * Returns the native proxy, if this JavaScript runtime has installed Nitro.\n * This does not install Nitro or initialize the {@linkcode NitroModules} binding.\n */\nexport function getInstalledNitro(): NitroModulesProxy | undefined {\n return globalThis.NitroModulesProxy as NitroModulesProxy | undefined\n}\n\n/**\n * Returns the installed native proxy and initializes {@linkcode NitroModules}.\n * The host integration is responsible for installing Nitro first.\n */\nexport function getNitroModules(): NitroModulesProxy {\n const nitroModules = getInstalledNitro()\n if (nitroModules == null) {\n throw new Error(\n 'Nitro is not installed in this JavaScript runtime. Initialize the host integration before using NitroModules.'\n )\n }\n NitroModules = nitroModules\n return nitroModules\n}\n\n/**\n * Returns whether the runtime still has Nitro's JSI cache and dispatcher.\n */\nexport function isRuntimeAlive(): boolean {\n const cache = globalThis.__nitroJsiCache\n const dispatcher = globalThis.__nitroDispatcher\n return cache != null && dispatcher != null\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NitroModulesProxy.js","sourceRoot":"","sources":["../../src/NitroModulesProxy.ts"],"names":[],"mappings":"","sourcesContent":["import type { HybridObject } from './HybridObject.js'\nimport type { BoxedHybridObject } from './BoxedHybridObject.js'\n\n/**\n * The native entry point for Nitro Modules in a JavaScript runtime.\n *\n * This is a `HybridObject` on the native side as well, and is expected to be\n * installed into the runtime's `global` by the host integration.\n */\nexport interface NitroModulesProxy extends HybridObject<{\n ios: 'c++'\n android: 'c++'\n}> {\n /**\n * Create a new instance of the `HybridObject` {@linkcode T}.\n *\n * {@linkcode T} has to be registered beforehand under the name {@linkcode name}\n * in the native Nitro Modules `HybridObjectRegistry`.\n *\n * @param name The name of the `HybridObject` under which it was registered at.\n * @returns An instance of {@linkcode T}\n * @throws an Error if {@linkcode T} has not been registered under the name {@linkcode name}.\n */\n createHybridObject<T extends HybridObject<{}>>(name: string): T\n /**\n * Returns whether a HybridObject under the given {@linkcode name} is registered, or not.\n */\n hasHybridObject(name: string): boolean\n /**\n * Returns whether the given {@linkcode object} is a {@linkcode HybridObject}, or not.\n */\n isHybridObject(object: object): object is HybridObject<{}>\n /**\n * Get a list of all registered Hybrid Objects.\n */\n getAllHybridObjectNames(): string[]\n\n /**\n * Gets the current build type configuration as defined in the `NITRO_DEBUG`\n * preprocessor flag.\n */\n buildType: 'debug' | 'release'\n /**\n * Gets the native Nitro Modules core runtime version that this app is built with.\n * This should be kept in sync with the JS version (package.json), otherwise it could\n * introduce undefined behaviour.\n */\n version: string\n\n /**\n * Boxes the given {@linkcode hybridObject} into a {@linkcode BoxedHybridObject<T>}, which can\n * later be unboxed in a separate Runtime.\n *\n * While Nitro is runtime-agnostic and all `HybridObject`s can be used from a any Runtime,\n * some threading/worklet libraries (like [react-native-worklets-core](https://github.com/margelo/react-native-worklets-core))\n * do not yet support copying over `HybridObject`s as they use newer JSI APIs like `jsi::NativeState`.\n *\n * While those APIs are not yet available, you can still use every Nitro Hybrid Object in a separate\n * Runtime/Worklet context by just boxing it yourself:\n *\n * @example\n * ```ts\n * const something = NitroModules.createHybridObject<Something>('Something')\n * const boxed = NitroModules.box(something)\n * const context = Worklets.createContext('DummyContext')\n * context.runAsync(() => {\n * 'worklet'\n * const unboxed = boxed.unbox()\n * console.log(unboxed.name) // --> \"Something\"\n * })\n * ```\n */\n box<T extends HybridObject<{}>>(obj: T): BoxedHybridObject<T>\n\n /**\n * Returns whether the given {@linkcode object} has NativeState or not.\n */\n hasNativeState(object: unknown): boolean\n\n /**\n * Re-calculates `memorySize` of the given {@linkcode HybridObject} and notifies\n * the JS VM about the newly updated memory footprint.\n *\n * This is achieved by just doing a round-trip from JS -> native -> JS.\n */\n updateMemorySize<T extends HybridObject<{}>>(obj: T): T\n\n /**\n * Allocate a new native {@linkcode ArrayBuffer} with the\n * given {@linkcode size}.\n *\n * As opposed to creating an {@linkcode ArrayBuffer} from JS,\n * this method returns a buffer that can be directly read from\n * and written to in Nitro Modules without copying, as native\n * owns it - not JS.\n */\n createNativeArrayBuffer(size: number): ArrayBuffer\n\n /**\n * Gets a total number of currently allocated {@linkcode HybridObject}s.\n * @internal\n */\n debug_getTotalAllocatedHybridObjects(): number\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sync.js","sourceRoot":"","sources":["../../src/Sync.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Marks the given function as _synchronous_, allowing it to be called synchronously on the same\n * Thread.\n *\n * This allows for fast native -> JS calls and avoids any asynchronous dispatching, but requires careful\n * threading considerations.\n */\nexport type Sync<T> = T extends Function ? T & { __syncTag?: never } : never\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertNitroVersion = assertNitroVersion;
|
|
4
|
+
exports.warnIfNitroVersionMismatch = warnIfNitroVersionMismatch;
|
|
5
|
+
const version_js_1 = require("./version.js");
|
|
6
|
+
/**
|
|
7
|
+
* Checks compatibility before reusing a proxy installed by another copy of Nitro.
|
|
8
|
+
*/
|
|
9
|
+
function assertNitroVersion(nitroModules) {
|
|
10
|
+
if (nitroModules.version !== version_js_1.version) {
|
|
11
|
+
throw new Error(`Nitro was installed twice: once with native version ${nitroModules.version} and once with JS version ${version_js_1.version}. ` +
|
|
12
|
+
'This usually means different versions of Nitro exist in node_modules (e.g. in monorepos or double-linked setups).');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Warns when the installed native runtime differs from this JavaScript package.
|
|
17
|
+
* Host integrations should call this in development after installing Nitro.
|
|
18
|
+
*/
|
|
19
|
+
function warnIfNitroVersionMismatch(nitroModules) {
|
|
20
|
+
if (nitroModules.version !== version_js_1.version) {
|
|
21
|
+
console.warn(`The native Nitro Modules core runtime version is ${nitroModules.version}, but the JS code is using version ${version_js_1.version}. ` +
|
|
22
|
+
'This could lead to undefined behaviour! Make sure to keep your Nitro versions in sync.');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=checkNitroVersion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkNitroVersion.js","sourceRoot":"","sources":["../../src/checkNitroVersion.ts"],"names":[],"mappings":";;AAMA,gDAOC;AAMD,gEASC;AA3BD,6CAAmD;AAEnD;;GAEG;AACH,SAAgB,kBAAkB,CAAC,YAA+B;IAChE,IAAI,YAAY,CAAC,OAAO,KAAK,oBAAS,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CACb,uDAAuD,YAAY,CAAC,OAAO,6BAA6B,oBAAS,IAAI;YACnH,mHAAmH,CACtH,CAAA;IACH,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAgB,0BAA0B,CACxC,YAA+B;IAE/B,IAAI,YAAY,CAAC,OAAO,KAAK,oBAAS,EAAE,CAAC;QACvC,OAAO,CAAC,IAAI,CACV,oDAAoD,YAAY,CAAC,OAAO,sCAAsC,oBAAS,IAAI;YACzH,wFAAwF,CAC3F,CAAA;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { NitroModulesProxy } from './NitroModulesProxy.js'\nimport { version as jsVersion } from './version.js'\n\n/**\n * Checks compatibility before reusing a proxy installed by another copy of Nitro.\n */\nexport function assertNitroVersion(nitroModules: NitroModulesProxy): void {\n if (nitroModules.version !== jsVersion) {\n throw new Error(\n `Nitro was installed twice: once with native version ${nitroModules.version} and once with JS version ${jsVersion}. ` +\n 'This usually means different versions of Nitro exist in node_modules (e.g. in monorepos or double-linked setups).'\n )\n }\n}\n\n/**\n * Warns when the installed native runtime differs from this JavaScript package.\n * Host integrations should call this in development after installing Nitro.\n */\nexport function warnIfNitroVersionMismatch(\n nitroModules: NitroModulesProxy\n): void {\n if (nitroModules.version !== jsVersion) {\n console.warn(\n `The native Nitro Modules core runtime version is ${nitroModules.version}, but the JS code is using version ${jsVersion}. ` +\n 'This could lead to undefined behaviour! Make sure to keep your Nitro versions in sync.'\n )\n }\n}\n"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHybridObjectConstructor = getHybridObjectConstructor;
|
|
4
|
+
const NitroModules_js_1 = require("./NitroModules.js");
|
|
5
|
+
const cache = new Map();
|
|
6
|
+
/**
|
|
7
|
+
* Get a constructor function for the given `HybridObject` {@linkcode T}.
|
|
8
|
+
* @param name The name of the `HybridObject` under which it was registered at.
|
|
9
|
+
* @returns A constructor that creates instances of {@linkcode T}
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* export const HybridImage = getHybridObjectConstructor<Image>('Image')
|
|
13
|
+
*
|
|
14
|
+
* const image1 = new HybridImage()
|
|
15
|
+
* const image2 = new HybridImage()
|
|
16
|
+
* image1 instanceof HybridImage // --> true
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
function getHybridObjectConstructor(name) {
|
|
20
|
+
// Cache functions for performance.
|
|
21
|
+
if (cache.has(name)) {
|
|
22
|
+
return cache.get(name);
|
|
23
|
+
}
|
|
24
|
+
// A function that creates the HybridObject.
|
|
25
|
+
// This can be called with `new`, and internally sets the prototype.
|
|
26
|
+
const constructorFunc = function () {
|
|
27
|
+
const instance = (0, NitroModules_js_1.getNitroModules)().createHybridObject(name);
|
|
28
|
+
const prototype = Object.getPrototypeOf(instance);
|
|
29
|
+
if (constructorFunc.prototype !== prototype) {
|
|
30
|
+
constructorFunc.prototype = prototype;
|
|
31
|
+
constructorFunc.prototypeInitialized = true;
|
|
32
|
+
}
|
|
33
|
+
return instance;
|
|
34
|
+
};
|
|
35
|
+
// Configure lazy prototype. If `instanceof` is called before a `T`
|
|
36
|
+
// has been created, we just lazy-create a new `T` instance to set the proto.
|
|
37
|
+
constructorFunc.prototypeInitialized = false;
|
|
38
|
+
Object.defineProperty(constructorFunc, Symbol.hasInstance, {
|
|
39
|
+
value: (instance) => {
|
|
40
|
+
if (!constructorFunc.prototypeInitialized) {
|
|
41
|
+
// User didn't call `new T()` yet, so we don't
|
|
42
|
+
// know the prototype yet. Just create one temp object to find
|
|
43
|
+
// out the prototype.
|
|
44
|
+
const tempInstance = (0, NitroModules_js_1.getNitroModules)().createHybridObject(name);
|
|
45
|
+
constructorFunc.prototype = Object.getPrototypeOf(tempInstance);
|
|
46
|
+
constructorFunc.prototypeInitialized = true;
|
|
47
|
+
}
|
|
48
|
+
// Loop through the prototype chain of the value
|
|
49
|
+
// we're testing for to see if it is a direct instance
|
|
50
|
+
// of `T`, or a derivative of it.
|
|
51
|
+
let proto = Object.getPrototypeOf(instance);
|
|
52
|
+
while (proto != null) {
|
|
53
|
+
if (proto === constructorFunc.prototype) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
proto = Object.getPrototypeOf(proto);
|
|
57
|
+
}
|
|
58
|
+
// No prototype overlap.
|
|
59
|
+
return false;
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
cache.set(name, constructorFunc);
|
|
63
|
+
return constructorFunc;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=getHybridObjectConstructor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getHybridObjectConstructor.js","sourceRoot":"","sources":["../../src/getHybridObjectConstructor.ts"],"names":[],"mappings":";;AAkBA,gEAkDC;AAnED,uDAAmD;AAEnD,MAAM,KAAK,GAAG,IAAI,GAAG,EAAoB,CAAA;AAEzC;;;;;;;;;;;;GAYG;AACH,SAAgB,0BAA0B,CACxC,IAAY;IAEZ,mCAAmC;IACnC,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACpB,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAkB,CAAA;IACzC,CAAC;IAED,4CAA4C;IAC5C,oEAAoE;IACpE,MAAM,eAAe,GAAG;QACtB,MAAM,QAAQ,GAAG,IAAA,iCAAe,GAAE,CAAC,kBAAkB,CAAI,IAAI,CAAC,CAAA;QAC9D,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAA;QACjD,IAAI,eAAe,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5C,eAAe,CAAC,SAAS,GAAG,SAAS,CAAA;YACrC,eAAe,CAAC,oBAAoB,GAAG,IAAI,CAAA;QAC7C,CAAC;QACD,OAAO,QAAQ,CAAA;IACjB,CAAkE,CAAA;IAElE,mEAAmE;IACnE,6EAA6E;IAC7E,eAAe,CAAC,oBAAoB,GAAG,KAAK,CAAA;IAC5C,MAAM,CAAC,cAAc,CAAC,eAAe,EAAE,MAAM,CAAC,WAAW,EAAE;QACzD,KAAK,EAAE,CAAC,QAAiB,EAAE,EAAE;YAC3B,IAAI,CAAC,eAAe,CAAC,oBAAoB,EAAE,CAAC;gBAC1C,8CAA8C;gBAC9C,8DAA8D;gBAC9D,qBAAqB;gBACrB,MAAM,YAAY,GAAG,IAAA,iCAAe,GAAE,CAAC,kBAAkB,CAAI,IAAI,CAAC,CAAA;gBAClE,eAAe,CAAC,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,YAAY,CAAC,CAAA;gBAC/D,eAAe,CAAC,oBAAoB,GAAG,IAAI,CAAA;YAC7C,CAAC;YACD,gDAAgD;YAChD,sDAAsD;YACtD,iCAAiC;YACjC,IAAI,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAA;YAC3C,OAAO,KAAK,IAAI,IAAI,EAAE,CAAC;gBACrB,IAAI,KAAK,KAAK,eAAe,CAAC,SAAS,EAAE,CAAC;oBACxC,OAAO,IAAI,CAAA;gBACb,CAAC;gBACD,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;YACtC,CAAC;YACD,wBAAwB;YACxB,OAAO,KAAK,CAAA;QACd,CAAC;KACF,CAAC,CAAA;IAEF,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,eAAe,CAAC,CAAA;IAChC,OAAO,eAAe,CAAA;AACxB,CAAC","sourcesContent":["import type { HybridObject } from './HybridObject.js'\nimport { getNitroModules } from './NitroModules.js'\n\nconst cache = new Map<string, Function>()\n\n/**\n * Get a constructor function for the given `HybridObject` {@linkcode T}.\n * @param name The name of the `HybridObject` under which it was registered at.\n * @returns A constructor that creates instances of {@linkcode T}\n * @example\n * ```ts\n * export const HybridImage = getHybridObjectConstructor<Image>('Image')\n *\n * const image1 = new HybridImage()\n * const image2 = new HybridImage()\n * image1 instanceof HybridImage // --> true\n * ```\n */\nexport function getHybridObjectConstructor<T extends HybridObject<{}>>(\n name: string\n): { new (): T } {\n // Cache functions for performance.\n if (cache.has(name)) {\n return cache.get(name) as { new (): T }\n }\n\n // A function that creates the HybridObject.\n // This can be called with `new`, and internally sets the prototype.\n const constructorFunc = function () {\n const instance = getNitroModules().createHybridObject<T>(name)\n const prototype = Object.getPrototypeOf(instance)\n if (constructorFunc.prototype !== prototype) {\n constructorFunc.prototype = prototype\n constructorFunc.prototypeInitialized = true\n }\n return instance\n } as unknown as { new (): T } & { prototypeInitialized?: boolean }\n\n // Configure lazy prototype. If `instanceof` is called before a `T`\n // has been created, we just lazy-create a new `T` instance to set the proto.\n constructorFunc.prototypeInitialized = false\n Object.defineProperty(constructorFunc, Symbol.hasInstance, {\n value: (instance: unknown) => {\n if (!constructorFunc.prototypeInitialized) {\n // User didn't call `new T()` yet, so we don't\n // know the prototype yet. Just create one temp object to find\n // out the prototype.\n const tempInstance = getNitroModules().createHybridObject<T>(name)\n constructorFunc.prototype = Object.getPrototypeOf(tempInstance)\n constructorFunc.prototypeInitialized = true\n }\n // Loop through the prototype chain of the value\n // we're testing for to see if it is a direct instance\n // of `T`, or a derivative of it.\n let proto = Object.getPrototypeOf(instance)\n while (proto != null) {\n if (proto === constructorFunc.prototype) {\n return true\n }\n proto = Object.getPrototypeOf(proto)\n }\n // No prototype overlap.\n return false\n },\n })\n\n cache.set(name, constructorFunc)\n return constructorFunc\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"globals.js","sourceRoot":"","sources":["../../src/globals.ts"],"names":[],"mappings":"","sourcesContent":["declare global {\n /**\n * The native `JSICache` for Nitro.\n * This is created on the fly natively when needed.\n * @readonly\n */\n var __nitroJsiCache: {} | undefined\n /**\n * The native `Dispatcher` for Nitro.\n *\n * A `Dispatcher` is only available in a `jsi::Runtime` when\n * it was installed using `Dispatcher::installRuntimeGlobalDispatcher(...)`.\n *\n * If you use a `jsi::Runtime` that does not have a `Dispatcher` ({@linkcode __nitroDispatcher} `==` `null`),\n * any asynchronous operations (`Callbacks` or `Promises`) will throw an error.\n * You would need to either:\n * - A) Install a `Dispatcher` that can safely thread-hop (\"dispatch\") to this `jsi::Runtime` on the native side\n * - B) Only use synchronous methods and no callbacks on this `jsi::Runtime`.\n * @readonly\n */\n var __nitroDispatcher: {} | undefined\n /**\n * The global proxy object that can create other autolinked HybridObjects.\n */\n var NitroModulesProxy: {} | undefined\n}\n\n// ensures this file is treated as a module\nexport {}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
require("./globals.js");
|
|
18
|
+
__exportStar(require("./AnyHybridObject.js"), exports);
|
|
19
|
+
__exportStar(require("./AnyMap.js"), exports);
|
|
20
|
+
__exportStar(require("./BoxedHybridObject.js"), exports);
|
|
21
|
+
__exportStar(require("./CustomType.js"), exports);
|
|
22
|
+
__exportStar(require("./getHybridObjectConstructor.js"), exports);
|
|
23
|
+
__exportStar(require("./HybridObject.js"), exports);
|
|
24
|
+
__exportStar(require("./Int64.js"), exports);
|
|
25
|
+
__exportStar(require("./NitroModules.js"), exports);
|
|
26
|
+
__exportStar(require("./NitroModulesProxy.js"), exports);
|
|
27
|
+
__exportStar(require("./Sync.js"), exports);
|
|
28
|
+
__exportStar(require("./checkNitroVersion.js"), exports);
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wBAAqB;AAErB,uDAAoC;AACpC,8CAA2B;AAC3B,yDAAsC;AACtC,kDAA+B;AAC/B,kEAA+C;AAC/C,oDAAiC;AACjC,6CAA0B;AAC1B,oDAAiC;AACjC,yDAAsC;AACtC,4CAAyB;AACzB,yDAAsC","sourcesContent":["import './globals.js'\n\nexport * from './AnyHybridObject.js'\nexport * from './AnyMap.js'\nexport * from './BoxedHybridObject.js'\nexport * from './CustomType.js'\nexport * from './getHybridObjectConstructor.js'\nexport * from './HybridObject.js'\nexport * from './Int64.js'\nexport * from './NitroModules.js'\nexport * from './NitroModulesProxy.js'\nexport * from './Sync.js'\nexport * from './checkNitroVersion.js'\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.version = void 0;
|
|
4
|
+
// Updated by scripts/set-version.mjs with the native NITRO_VERSION.
|
|
5
|
+
exports.version = '0.37.2-nightly.32.gcd7b91624dde';
|
|
6
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,oEAAoE;AACvD,QAAA,OAAO,GAAG,iCAAiC,CAAA","sourcesContent":["// Updated by scripts/set-version.mjs with the native NITRO_VERSION.\nexport const version = '0.37.2-nightly.32.gcd7b91624dde'\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnyHybridObject.js","sourceRoot":"","sources":["../../src/AnyHybridObject.ts"],"names":[],"mappings":"","sourcesContent":["import type { HybridObject } from './HybridObject.js'\n\n/**\n * Represents a value of the base `HybridObject` type all other\n * HybridObjects inherit from.\n * This is not type-checked to an actual `HybridObject` (boxed).\n */\nexport interface AnyHybridObject extends HybridObject<{}> {\n __anyHybridObjectTag?: never\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnyMap.js","sourceRoot":"","sources":["../../src/AnyMap.ts"],"names":[],"mappings":"","sourcesContent":["import type { Int64 } from './Int64.js'\n\n/**\n * Represents a single value inside an untyped map.\n */\nexport type ValueType =\n | string\n | number\n | boolean\n | Int64\n | null\n | ValueType[]\n | { [k: string]: ValueType }\n\n/**\n * Represents an untyped map, similar to a JSON structure.\n * Supported types:\n * - Primitives (`string`, `number`, `boolean`, `Int64`, `null`)\n * - Arrays of primitives (`ValueType[]`)\n * - Objects of primitives (`Record<string, ValueType>`)\n * - Arrays of arrays or objects\n * - Objects of arrays or objects\n *\n * @note It is recommended to always use typed `interface`s instead of `AnyMap` for\n * both type safety, as well as better performance.\n */\nexport type AnyMap = Record<string, ValueType>\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BoxedHybridObject.js","sourceRoot":"","sources":["../../src/BoxedHybridObject.ts"],"names":[],"mappings":"","sourcesContent":["import type { HybridObject } from './HybridObject.js'\n\n/**\n * Represents a boxed {@linkcode HybridObject} that can later be unboxed again.\n * This is implemented as a `jsi::HostObject`.\n */\nexport interface BoxedHybridObject<T extends HybridObject<{}>> {\n /**\n * Unboxes the {@linkcode HybridObject}.\n * This can be called from a different Runtime than the one it was boxed in.\n */\n unbox(): T\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomType.js","sourceRoot":"","sources":["../../src/CustomType.ts"],"names":[],"mappings":"","sourcesContent":["export interface CustomTypeConfig {\n /**\n * Represents the name of the C++ header that will be included\n * to support your type.\n *\n * This C++ header should be written by you, and findable within\n * the user-search-paths so it can be included.\n */\n include: string\n /**\n * A flag that enables const-reference passing for heavy types\n * to prevent unnecessary copies.\n * When `true`, the type will be passed to clients as a `const T&` instead of just `T`.\n * @default false\n */\n canBePassedByReference?: boolean\n}\n\n/**\n * Represents a custom, manually written native type.\n * - {@linkcode TypeName}: Represents the name of the C++ type (class, struct, alias).\n * - {@linkcode Config}: Configures how the C++ type is included, used, and typed.\n *\n * **You** then need to create a header file that is importable with the filename specified in {@linkcode Config.include}.\n * @example\n * ```ts\n * type MyOwnString = CustomType<string, 'MyOwnString', { include: 'MyOwnString.hpp' }>\n * interface MyHybrid extends HybridObject<{ … }> {\n * getValue(): MyOwnString\n * }\n * ```\n * The C++ header will always be included by Nitro as a user-search-path header, that is;\n * ```cpp\n * #include \"MyOwnString.hpp\"\n * ```\n * The C++ header (`MyOwnString.hpp`) then needs to define the type `MyOwnString`\n * within the namespace of your Nitro Module (`namespace margelo::nitro::...`),\n * and an overload for `JSIConverter<MyOwnString>` within the Nitro core namespace\n * (`namespace margelo::nitro`):\n * ```cpp\n * namespace margelo::nitro::test {\n * using MyOwnString = std::string;\n * }\n * namespace margelo::nitro {\n * template<>\n * struct JSIConverter<test::MyOwnString> final {\n * static test::MyOwnString fromJSI(jsi::Runtime&, const jsi::Value&);\n * static jsi::Value toJSI(jsi::Runtime&, test::MyOwnString);\n * static bool canConvert(jsi::Runtime&, const jsi::Value& value);\n * }\n * }\n * ```\n */\nexport type CustomType<\n T,\n TypeName extends string,\n Config extends CustomTypeConfig,\n> = T & {\n readonly __customTypeName?: TypeName\n readonly __customTypeConfig?: Config\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HybridObject.js","sourceRoot":"","sources":["../../src/HybridObject.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Describes the languages this component will be implemented in.\n *\n * By default, everything has a C++ base, and can optionally be bridged down\n * to platform-specific languages like Swift or Kotlin\n */\nexport interface PlatformSpec {\n ios?: 'c++' | 'swift'\n android?: 'c++' | 'kotlin'\n}\n\n/**\n * Represents a Nitro `HybridObject` which is implemented in a native language like\n * C++, Swift or Kotlin.\n * Every Nitro `HybridObject` has a C++ base, and can optionally be bridged down to Swift or Kotlin.\n *\n * `HybridObject`s use the Nitro Tunnel for efficient, low-overhead JS <-> Native communication.\n *\n * All `HybridObject`s are implemented using `NativeState`, and inherit their properties\n * and methods from their prototype, so the actual JS object is empty.\n *\n * @type Platforms: The type of platforms this HybridObject will be implemented in.\n * @example\n * ```ts\n * interface Photo extends HybridObject<{ ios: 'swift', android: 'kotlin' }> {\n * readonly width: number\n * readonly height: number\n * toArrayBuffer(): ArrayBuffer\n * saveToFile(path: string): Promise<void>\n * }\n * ```\n */\nexport interface HybridObject<Platforms extends PlatformSpec> {\n /**\n * Holds a type-name describing the native `HybridObject` instance.\n *\n * This is the only property actually present on the actual JavaScript object,\n * because all other properties and methods are inherited from a shared Prototype.\n *\n * Nitro prototypes also have a `__type`.\n *\n * - For actual HybridObject instances, this is `HybridObject<...>`\n * - For prototypes this is `Prototype<...>`.\n *\n * @internal\n * @private\n * @note This value is available in debug only.\n */\n readonly __type?: string\n /**\n * The `HybridObject`'s name.\n */\n readonly name: string\n /**\n * Returns a string representation of the given `HybridObject`.\n *\n * Unless overridden by the `HybridObject`, this will return the name of the object.\n *\n * @example\n * ```ts\n * const hybridA = SomeModule.getExistingHybridInstance()\n * console.log(hybridA.toString()) // [HybridObject HybridA]\n * ```\n */\n toString(): string\n /**\n * Returns whether this `HybridObject` is the same object as {@linkcode other}.\n *\n * While two `HybridObject`s might not be equal when compared with `==`, they might still\n * hold the same underlying `HybridObject`, in which case {@linkcode equals | equals(other)}\n * will return `true`.\n *\n * @example\n * ```ts\n * const hybridA = SomeModule.getExistingHybridInstance()\n * const hybridB = SomeModule.getExistingHybridInstance()\n * console.log(hybridA.equals(hybridB)) // true\n * ```\n */\n equals(other: HybridObject<Platforms>): boolean\n /**\n * Disposes any resources this {@linkcode HybridObject} might hold natively,\n * and releases this {@linkcode HybridObject}'s `NativeState`.\n *\n * After calling {@linkcode dispose()}, this object can no longer be used.\n *\n * Eagerly disposing a {@linkcode HybridObject} could be beneficial for a queue-/handler-architecture\n * where a bunch of Hybrid Objects are allocated, and later deallocated once a callback (e.g. a render function)\n * completes.\n *\n * @note It is **NOT** required to call {@linkcode dispose()} manually, as the JavaScript\n * Garbage Collector automatically disposes and releases any resources when needed.\n * It is purely optional to eagerly-, and manually-, call {@linkcode dispose()} here - **use with caution!**\n */\n dispose(): void\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Int64.js","sourceRoot":"","sources":["../../src/Int64.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Represents an unsigned 64-bit integer (or \"uint64\").\n */\nexport type UInt64 = bigint & { __unsignedTag?: never }\n\n/**\n * Represents a signed 64-bit integer (or \"int64\").\n */\nexport type Int64 = bigint & { __signedTag?: never }\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import './globals.js';
|
|
2
|
+
/**
|
|
3
|
+
* The installed native Nitro entry point.
|
|
4
|
+
*
|
|
5
|
+
* A host integration must call {@linkcode getNitroModules} after installing
|
|
6
|
+
* Nitro into the JavaScript runtime. The binding then refers to that same
|
|
7
|
+
* native object, including its NativeState and prototype.
|
|
8
|
+
*/
|
|
9
|
+
export let NitroModules;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the native proxy, if this JavaScript runtime has installed Nitro.
|
|
12
|
+
* This does not install Nitro or initialize the {@linkcode NitroModules} binding.
|
|
13
|
+
*/
|
|
14
|
+
export function getInstalledNitro() {
|
|
15
|
+
return globalThis.NitroModulesProxy;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Returns the installed native proxy and initializes {@linkcode NitroModules}.
|
|
19
|
+
* The host integration is responsible for installing Nitro first.
|
|
20
|
+
*/
|
|
21
|
+
export function getNitroModules() {
|
|
22
|
+
const nitroModules = getInstalledNitro();
|
|
23
|
+
if (nitroModules == null) {
|
|
24
|
+
throw new Error('Nitro is not installed in this JavaScript runtime. Initialize the host integration before using NitroModules.');
|
|
25
|
+
}
|
|
26
|
+
NitroModules = nitroModules;
|
|
27
|
+
return nitroModules;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Returns whether the runtime still has Nitro's JSI cache and dispatcher.
|
|
31
|
+
*/
|
|
32
|
+
export function isRuntimeAlive() {
|
|
33
|
+
const cache = globalThis.__nitroJsiCache;
|
|
34
|
+
const dispatcher = globalThis.__nitroDispatcher;
|
|
35
|
+
return cache != null && dispatcher != null;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=NitroModules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NitroModules.js","sourceRoot":"","sources":["../../src/NitroModules.ts"],"names":[],"mappings":"AACA,OAAO,cAAc,CAAA;AAErB;;;;;;GAMG;AACH,MAAM,CAAC,IAAI,YAA+B,CAAA;AAE1C;;;GAGG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,UAAU,CAAC,iBAAkD,CAAA;AACtE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,YAAY,GAAG,iBAAiB,EAAE,CAAA;IACxC,IAAI,YAAY,IAAI,IAAI,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,+GAA+G,CAChH,CAAA;IACH,CAAC;IACD,YAAY,GAAG,YAAY,CAAA;IAC3B,OAAO,YAAY,CAAA;AACrB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,KAAK,GAAG,UAAU,CAAC,eAAe,CAAA;IACxC,MAAM,UAAU,GAAG,UAAU,CAAC,iBAAiB,CAAA;IAC/C,OAAO,KAAK,IAAI,IAAI,IAAI,UAAU,IAAI,IAAI,CAAA;AAC5C,CAAC","sourcesContent":["import type { NitroModulesProxy } from './NitroModulesProxy.js'\nimport './globals.js'\n\n/**\n * The installed native Nitro entry point.\n *\n * A host integration must call {@linkcode getNitroModules} after installing\n * Nitro into the JavaScript runtime. The binding then refers to that same\n * native object, including its NativeState and prototype.\n */\nexport let NitroModules: NitroModulesProxy\n\n/**\n * Returns the native proxy, if this JavaScript runtime has installed Nitro.\n * This does not install Nitro or initialize the {@linkcode NitroModules} binding.\n */\nexport function getInstalledNitro(): NitroModulesProxy | undefined {\n return globalThis.NitroModulesProxy as NitroModulesProxy | undefined\n}\n\n/**\n * Returns the installed native proxy and initializes {@linkcode NitroModules}.\n * The host integration is responsible for installing Nitro first.\n */\nexport function getNitroModules(): NitroModulesProxy {\n const nitroModules = getInstalledNitro()\n if (nitroModules == null) {\n throw new Error(\n 'Nitro is not installed in this JavaScript runtime. Initialize the host integration before using NitroModules.'\n )\n }\n NitroModules = nitroModules\n return nitroModules\n}\n\n/**\n * Returns whether the runtime still has Nitro's JSI cache and dispatcher.\n */\nexport function isRuntimeAlive(): boolean {\n const cache = globalThis.__nitroJsiCache\n const dispatcher = globalThis.__nitroDispatcher\n return cache != null && dispatcher != null\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NitroModulesProxy.js","sourceRoot":"","sources":["../../src/NitroModulesProxy.ts"],"names":[],"mappings":"","sourcesContent":["import type { HybridObject } from './HybridObject.js'\nimport type { BoxedHybridObject } from './BoxedHybridObject.js'\n\n/**\n * The native entry point for Nitro Modules in a JavaScript runtime.\n *\n * This is a `HybridObject` on the native side as well, and is expected to be\n * installed into the runtime's `global` by the host integration.\n */\nexport interface NitroModulesProxy extends HybridObject<{\n ios: 'c++'\n android: 'c++'\n}> {\n /**\n * Create a new instance of the `HybridObject` {@linkcode T}.\n *\n * {@linkcode T} has to be registered beforehand under the name {@linkcode name}\n * in the native Nitro Modules `HybridObjectRegistry`.\n *\n * @param name The name of the `HybridObject` under which it was registered at.\n * @returns An instance of {@linkcode T}\n * @throws an Error if {@linkcode T} has not been registered under the name {@linkcode name}.\n */\n createHybridObject<T extends HybridObject<{}>>(name: string): T\n /**\n * Returns whether a HybridObject under the given {@linkcode name} is registered, or not.\n */\n hasHybridObject(name: string): boolean\n /**\n * Returns whether the given {@linkcode object} is a {@linkcode HybridObject}, or not.\n */\n isHybridObject(object: object): object is HybridObject<{}>\n /**\n * Get a list of all registered Hybrid Objects.\n */\n getAllHybridObjectNames(): string[]\n\n /**\n * Gets the current build type configuration as defined in the `NITRO_DEBUG`\n * preprocessor flag.\n */\n buildType: 'debug' | 'release'\n /**\n * Gets the native Nitro Modules core runtime version that this app is built with.\n * This should be kept in sync with the JS version (package.json), otherwise it could\n * introduce undefined behaviour.\n */\n version: string\n\n /**\n * Boxes the given {@linkcode hybridObject} into a {@linkcode BoxedHybridObject<T>}, which can\n * later be unboxed in a separate Runtime.\n *\n * While Nitro is runtime-agnostic and all `HybridObject`s can be used from a any Runtime,\n * some threading/worklet libraries (like [react-native-worklets-core](https://github.com/margelo/react-native-worklets-core))\n * do not yet support copying over `HybridObject`s as they use newer JSI APIs like `jsi::NativeState`.\n *\n * While those APIs are not yet available, you can still use every Nitro Hybrid Object in a separate\n * Runtime/Worklet context by just boxing it yourself:\n *\n * @example\n * ```ts\n * const something = NitroModules.createHybridObject<Something>('Something')\n * const boxed = NitroModules.box(something)\n * const context = Worklets.createContext('DummyContext')\n * context.runAsync(() => {\n * 'worklet'\n * const unboxed = boxed.unbox()\n * console.log(unboxed.name) // --> \"Something\"\n * })\n * ```\n */\n box<T extends HybridObject<{}>>(obj: T): BoxedHybridObject<T>\n\n /**\n * Returns whether the given {@linkcode object} has NativeState or not.\n */\n hasNativeState(object: unknown): boolean\n\n /**\n * Re-calculates `memorySize` of the given {@linkcode HybridObject} and notifies\n * the JS VM about the newly updated memory footprint.\n *\n * This is achieved by just doing a round-trip from JS -> native -> JS.\n */\n updateMemorySize<T extends HybridObject<{}>>(obj: T): T\n\n /**\n * Allocate a new native {@linkcode ArrayBuffer} with the\n * given {@linkcode size}.\n *\n * As opposed to creating an {@linkcode ArrayBuffer} from JS,\n * this method returns a buffer that can be directly read from\n * and written to in Nitro Modules without copying, as native\n * owns it - not JS.\n */\n createNativeArrayBuffer(size: number): ArrayBuffer\n\n /**\n * Gets a total number of currently allocated {@linkcode HybridObject}s.\n * @internal\n */\n debug_getTotalAllocatedHybridObjects(): number\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sync.js","sourceRoot":"","sources":["../../src/Sync.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Marks the given function as _synchronous_, allowing it to be called synchronously on the same\n * Thread.\n *\n * This allows for fast native -> JS calls and avoids any asynchronous dispatching, but requires careful\n * threading considerations.\n */\nexport type Sync<T> = T extends Function ? T & { __syncTag?: never } : never\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { version as jsVersion } from './version.js';
|
|
2
|
+
/**
|
|
3
|
+
* Checks compatibility before reusing a proxy installed by another copy of Nitro.
|
|
4
|
+
*/
|
|
5
|
+
export function assertNitroVersion(nitroModules) {
|
|
6
|
+
if (nitroModules.version !== jsVersion) {
|
|
7
|
+
throw new Error(`Nitro was installed twice: once with native version ${nitroModules.version} and once with JS version ${jsVersion}. ` +
|
|
8
|
+
'This usually means different versions of Nitro exist in node_modules (e.g. in monorepos or double-linked setups).');
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Warns when the installed native runtime differs from this JavaScript package.
|
|
13
|
+
* Host integrations should call this in development after installing Nitro.
|
|
14
|
+
*/
|
|
15
|
+
export function warnIfNitroVersionMismatch(nitroModules) {
|
|
16
|
+
if (nitroModules.version !== jsVersion) {
|
|
17
|
+
console.warn(`The native Nitro Modules core runtime version is ${nitroModules.version}, but the JS code is using version ${jsVersion}. ` +
|
|
18
|
+
'This could lead to undefined behaviour! Make sure to keep your Nitro versions in sync.');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=checkNitroVersion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkNitroVersion.js","sourceRoot":"","sources":["../../src/checkNitroVersion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,cAAc,CAAA;AAEnD;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,YAA+B;IAChE,IAAI,YAAY,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CACb,uDAAuD,YAAY,CAAC,OAAO,6BAA6B,SAAS,IAAI;YACnH,mHAAmH,CACtH,CAAA;IACH,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CACxC,YAA+B;IAE/B,IAAI,YAAY,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACvC,OAAO,CAAC,IAAI,CACV,oDAAoD,YAAY,CAAC,OAAO,sCAAsC,SAAS,IAAI;YACzH,wFAAwF,CAC3F,CAAA;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { NitroModulesProxy } from './NitroModulesProxy.js'\nimport { version as jsVersion } from './version.js'\n\n/**\n * Checks compatibility before reusing a proxy installed by another copy of Nitro.\n */\nexport function assertNitroVersion(nitroModules: NitroModulesProxy): void {\n if (nitroModules.version !== jsVersion) {\n throw new Error(\n `Nitro was installed twice: once with native version ${nitroModules.version} and once with JS version ${jsVersion}. ` +\n 'This usually means different versions of Nitro exist in node_modules (e.g. in monorepos or double-linked setups).'\n )\n }\n}\n\n/**\n * Warns when the installed native runtime differs from this JavaScript package.\n * Host integrations should call this in development after installing Nitro.\n */\nexport function warnIfNitroVersionMismatch(\n nitroModules: NitroModulesProxy\n): void {\n if (nitroModules.version !== jsVersion) {\n console.warn(\n `The native Nitro Modules core runtime version is ${nitroModules.version}, but the JS code is using version ${jsVersion}. ` +\n 'This could lead to undefined behaviour! Make sure to keep your Nitro versions in sync.'\n )\n }\n}\n"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { getNitroModules } from './NitroModules.js';
|
|
2
|
+
const cache = new Map();
|
|
3
|
+
/**
|
|
4
|
+
* Get a constructor function for the given `HybridObject` {@linkcode T}.
|
|
5
|
+
* @param name The name of the `HybridObject` under which it was registered at.
|
|
6
|
+
* @returns A constructor that creates instances of {@linkcode T}
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* export const HybridImage = getHybridObjectConstructor<Image>('Image')
|
|
10
|
+
*
|
|
11
|
+
* const image1 = new HybridImage()
|
|
12
|
+
* const image2 = new HybridImage()
|
|
13
|
+
* image1 instanceof HybridImage // --> true
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export function getHybridObjectConstructor(name) {
|
|
17
|
+
// Cache functions for performance.
|
|
18
|
+
if (cache.has(name)) {
|
|
19
|
+
return cache.get(name);
|
|
20
|
+
}
|
|
21
|
+
// A function that creates the HybridObject.
|
|
22
|
+
// This can be called with `new`, and internally sets the prototype.
|
|
23
|
+
const constructorFunc = function () {
|
|
24
|
+
const instance = getNitroModules().createHybridObject(name);
|
|
25
|
+
const prototype = Object.getPrototypeOf(instance);
|
|
26
|
+
if (constructorFunc.prototype !== prototype) {
|
|
27
|
+
constructorFunc.prototype = prototype;
|
|
28
|
+
constructorFunc.prototypeInitialized = true;
|
|
29
|
+
}
|
|
30
|
+
return instance;
|
|
31
|
+
};
|
|
32
|
+
// Configure lazy prototype. If `instanceof` is called before a `T`
|
|
33
|
+
// has been created, we just lazy-create a new `T` instance to set the proto.
|
|
34
|
+
constructorFunc.prototypeInitialized = false;
|
|
35
|
+
Object.defineProperty(constructorFunc, Symbol.hasInstance, {
|
|
36
|
+
value: (instance) => {
|
|
37
|
+
if (!constructorFunc.prototypeInitialized) {
|
|
38
|
+
// User didn't call `new T()` yet, so we don't
|
|
39
|
+
// know the prototype yet. Just create one temp object to find
|
|
40
|
+
// out the prototype.
|
|
41
|
+
const tempInstance = getNitroModules().createHybridObject(name);
|
|
42
|
+
constructorFunc.prototype = Object.getPrototypeOf(tempInstance);
|
|
43
|
+
constructorFunc.prototypeInitialized = true;
|
|
44
|
+
}
|
|
45
|
+
// Loop through the prototype chain of the value
|
|
46
|
+
// we're testing for to see if it is a direct instance
|
|
47
|
+
// of `T`, or a derivative of it.
|
|
48
|
+
let proto = Object.getPrototypeOf(instance);
|
|
49
|
+
while (proto != null) {
|
|
50
|
+
if (proto === constructorFunc.prototype) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
proto = Object.getPrototypeOf(proto);
|
|
54
|
+
}
|
|
55
|
+
// No prototype overlap.
|
|
56
|
+
return false;
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
cache.set(name, constructorFunc);
|
|
60
|
+
return constructorFunc;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=getHybridObjectConstructor.js.map
|