nitrogen 0.29.8 → 0.30.0
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/lib/Logger.d.ts +10 -0
- package/lib/autolinking/Autolinking.d.ts +8 -0
- package/lib/autolinking/android/createCMakeExtension.d.ts +6 -0
- package/lib/autolinking/android/createGradleExtension.d.ts +5 -0
- package/lib/autolinking/android/createHybridObjectInitializer.d.ts +2 -0
- package/lib/autolinking/createAndroidAutolinking.d.ts +11 -0
- package/lib/autolinking/createIOSAutolinking.d.ts +5 -0
- package/lib/autolinking/ios/createHybridObjectInitializer.d.ts +9 -0
- package/lib/autolinking/ios/createPodspecRubyExtension.d.ts +5 -0
- package/lib/autolinking/ios/createSwiftCxxBridge.d.ts +2 -0
- package/lib/autolinking/ios/createSwiftUmbrellaHeader.d.ts +3 -0
- package/lib/config/NitroConfig.d.ts +52 -0
- package/lib/config/NitroUserConfig.d.ts +22 -0
- package/lib/config/getConfig.d.ts +2 -0
- package/lib/createGitAttributes.d.ts +1 -0
- package/lib/createPlatformSpec.d.ts +4 -0
- package/lib/getFiles.d.ts +1 -0
- package/lib/getPlatformSpecs.d.ts +17 -0
- package/lib/index.d.ts +2 -0
- package/lib/init.d.ts +1 -0
- package/lib/nitrogen.d.ts +11 -0
- package/lib/prettifyDirectory.d.ts +1 -0
- package/lib/syntax/BridgedType.d.ts +41 -0
- package/lib/syntax/CodeNode.d.ts +23 -0
- package/lib/syntax/Method.d.ts +41 -0
- package/lib/syntax/Parameter.d.ts +15 -0
- package/lib/syntax/Property.d.ts +50 -0
- package/lib/syntax/SourceFile.d.ts +70 -0
- package/lib/syntax/c++/CppEnum.d.ts +6 -0
- package/lib/syntax/c++/CppHybridObject.d.ts +3 -0
- package/lib/syntax/c++/CppHybridObjectRegistration.d.ts +17 -0
- package/lib/syntax/c++/CppStruct.d.ts +3 -0
- package/lib/syntax/c++/CppStruct.js +4 -0
- package/lib/syntax/c++/CppUnion.d.ts +6 -0
- package/lib/syntax/c++/getForwardDeclaration.d.ts +3 -0
- package/lib/syntax/c++/includeNitroHeader.d.ts +7 -0
- package/lib/syntax/createType.d.ts +15 -0
- package/lib/syntax/getAllTypes.d.ts +3 -0
- package/lib/syntax/getCustomTypeConfig.d.ts +8 -0
- package/lib/syntax/getInterfaceProperties.d.ts +4 -0
- package/lib/syntax/getReferencedTypes.d.ts +2 -0
- package/lib/syntax/helpers.d.ts +13 -0
- package/lib/syntax/isCoreType.d.ts +9 -0
- package/lib/syntax/kotlin/FbjniHybridObject.d.ts +3 -0
- package/lib/syntax/kotlin/JNINativeRegistrations.d.ts +8 -0
- package/lib/syntax/kotlin/KotlinBoxedPrimitive.d.ts +7 -0
- package/lib/syntax/kotlin/KotlinCxxBridgedType.d.ts +19 -0
- package/lib/syntax/kotlin/KotlinEnum.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinFunction.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinHybridObject.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinHybridObjectRegistration.d.ts +17 -0
- package/lib/syntax/kotlin/KotlinStruct.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinStruct.js +5 -1
- package/lib/syntax/kotlin/KotlinVariant.d.ts +3 -0
- package/lib/syntax/swift/SwiftCxxBridgedType.d.ts +21 -0
- package/lib/syntax/swift/SwiftCxxBridgedType.js +2 -1
- package/lib/syntax/swift/SwiftCxxTypeHelper.d.ts +0 -1
- package/lib/syntax/swift/SwiftCxxTypeHelper.js +3 -6
- package/lib/syntax/swift/SwiftEnum.d.ts +3 -0
- package/lib/syntax/swift/SwiftFunction.d.ts +3 -0
- package/lib/syntax/swift/SwiftHybridObject.d.ts +3 -0
- package/lib/syntax/swift/SwiftHybridObjectBridge.d.ts +11 -0
- package/lib/syntax/swift/SwiftHybridObjectRegistration.d.ts +19 -0
- package/lib/syntax/swift/SwiftStruct.d.ts +3 -0
- package/lib/syntax/swift/SwiftVariant.d.ts +3 -0
- package/lib/syntax/swift/isPrimitivelyCopyable.d.ts +7 -0
- package/lib/syntax/swift/isPrimitivelyCopyable.js +18 -0
- package/lib/syntax/types/ArrayBufferType.d.ts +10 -0
- package/lib/syntax/types/BigIntType.d.ts +10 -0
- package/lib/syntax/types/BooleanType.d.ts +10 -0
- package/lib/syntax/types/DateType.d.ts +10 -0
- package/lib/syntax/types/EnumType.d.ts +23 -0
- package/lib/syntax/types/ErrorType.d.ts +11 -0
- package/lib/syntax/types/FunctionType.d.ts +29 -0
- package/lib/syntax/types/HybridObjectBaseType.d.ts +11 -0
- package/lib/syntax/types/HybridObjectType.d.ts +23 -0
- package/lib/syntax/types/MapType.d.ts +10 -0
- package/lib/syntax/types/NamedWrappingType.d.ts +14 -0
- package/lib/syntax/types/NullType.d.ts +10 -0
- package/lib/syntax/types/NumberType.d.ts +10 -0
- package/lib/syntax/types/OptionalType.d.ts +13 -0
- package/lib/syntax/types/PromiseType.d.ts +16 -0
- package/lib/syntax/types/RecordType.d.ts +13 -0
- package/lib/syntax/types/ResultWrappingType.d.ts +13 -0
- package/lib/syntax/types/StringType.d.ts +10 -0
- package/lib/syntax/types/StructType.d.ts +14 -0
- package/lib/syntax/types/TupleType.d.ts +12 -0
- package/lib/syntax/types/Type.d.ts +55 -0
- package/lib/syntax/types/VariantType.d.ts +19 -0
- package/lib/syntax/types/VoidType.d.ts +10 -0
- package/lib/syntax/types/getTypeAs.d.ts +2 -0
- package/lib/utils.d.ts +22 -0
- package/lib/views/CppHybridViewComponent.d.ts +14 -0
- package/lib/views/createHostComponentJs.d.ts +3 -0
- package/lib/views/kotlin/KotlinHybridViewManager.d.ts +3 -0
- package/lib/views/swift/SwiftHybridViewManager.d.ts +3 -0
- package/lib/writeFile.d.ts +5 -0
- package/package.json +3 -3
- package/src/syntax/c++/CppStruct.ts +4 -0
- package/src/syntax/kotlin/KotlinStruct.ts +11 -3
- package/src/syntax/swift/SwiftCxxBridgedType.ts +1 -1
- package/src/syntax/swift/SwiftCxxTypeHelper.ts +3 -7
- package/src/syntax/swift/isPrimitivelyCopyable.ts +20 -0
package/lib/Logger.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type LogLevel = 'debug' | 'info' | 'warning' | 'error';
|
|
2
|
+
export declare function isValidLogLevel(level: unknown): level is LogLevel;
|
|
3
|
+
export declare function setLogLevel(level: LogLevel): void;
|
|
4
|
+
export declare const Logger: {
|
|
5
|
+
withIndented(callback: () => void): void;
|
|
6
|
+
debug(message: string, ...extra: unknown[]): void;
|
|
7
|
+
info(message: string, ...extra: unknown[]): void;
|
|
8
|
+
warn(message: string, ...extra: unknown[]): void;
|
|
9
|
+
error(message: string, ...extra: unknown[]): void;
|
|
10
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Platform } from '../getPlatformSpecs.js';
|
|
2
|
+
import type { SourceFile } from '../syntax/SourceFile.js';
|
|
3
|
+
type AutolinkingFile = Omit<SourceFile, 'language'>;
|
|
4
|
+
export interface Autolinking {
|
|
5
|
+
platform: Platform;
|
|
6
|
+
sourceFiles: AutolinkingFile[];
|
|
7
|
+
}
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SourceFile } from '../../syntax/SourceFile.js';
|
|
2
|
+
export interface CMakeFile extends Omit<SourceFile, 'language'> {
|
|
3
|
+
language: 'cmake';
|
|
4
|
+
}
|
|
5
|
+
export declare function getBuildingWithGeneratedCmakeDefinition(): string;
|
|
6
|
+
export declare function createCMakeExtension(files: SourceFile[]): CMakeFile;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SourceFile, SourceImport } from '../syntax/SourceFile.js';
|
|
2
|
+
import type { Autolinking } from './Autolinking.js';
|
|
3
|
+
interface JNIHybridRegistration {
|
|
4
|
+
sourceImport: SourceImport;
|
|
5
|
+
registrationCode: string;
|
|
6
|
+
}
|
|
7
|
+
interface AndroidAutolinking extends Autolinking {
|
|
8
|
+
jniHybridRegistrations: JNIHybridRegistration[];
|
|
9
|
+
}
|
|
10
|
+
export declare function createAndroidAutolinking(allFiles: SourceFile[]): AndroidAutolinking;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SourceFile } from '../../syntax/SourceFile.js';
|
|
2
|
+
type ObjcFile = Omit<SourceFile, 'language'> & {
|
|
3
|
+
language: 'objective-c++';
|
|
4
|
+
};
|
|
5
|
+
type SwiftFile = Omit<SourceFile, 'language'> & {
|
|
6
|
+
language: 'swift';
|
|
7
|
+
};
|
|
8
|
+
export declare function createHybridObjectIntializer(): [ObjcFile, SwiftFile] | [];
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { NitroUserConfig } from './NitroUserConfig.js';
|
|
2
|
+
/**
|
|
3
|
+
* Represents the properly parsed `nitro.json` config of the current executing directory.
|
|
4
|
+
*/
|
|
5
|
+
export declare class NitroConfig {
|
|
6
|
+
private readonly config;
|
|
7
|
+
private static singleton;
|
|
8
|
+
constructor(config: NitroUserConfig);
|
|
9
|
+
static get current(): NitroConfig;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the name of the Android C++ library (aka name in CMakeLists.txt `add_library(..)`).
|
|
12
|
+
* This will be loaded via `System.loadLibrary(...)`.
|
|
13
|
+
* @example `NitroTest`
|
|
14
|
+
*/
|
|
15
|
+
getAndroidCxxLibName(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Returns the iOS module name (aka Pod name) of the module that will be generated.
|
|
18
|
+
* @example `NitroTest`
|
|
19
|
+
*/
|
|
20
|
+
getIosModuleName(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Represents the C++ namespace of the module that will be generated.
|
|
23
|
+
* This can have multiple sub-namespaces, and is always relative to `margelo::nitro`.
|
|
24
|
+
* @example `['image']` -> `margelo::nitro::image`
|
|
25
|
+
*/
|
|
26
|
+
getCxxNamespace(language: 'c++' | 'swift', ...subDefinitionName: string[]): string;
|
|
27
|
+
/**
|
|
28
|
+
* Represents the Android namespace of the module that will be generated.
|
|
29
|
+
* This can have multiple sub-namespaces, and is always relative to `com.margelo.nitro`.
|
|
30
|
+
* @example `['image']` -> `com.margelo.nitro.image`
|
|
31
|
+
*/
|
|
32
|
+
getAndroidPackage(language: 'java/kotlin' | 'c++/jni', ...subPackage: string[]): string;
|
|
33
|
+
/**
|
|
34
|
+
* Return the directory of the android package, and a given sub-package.
|
|
35
|
+
* This will be used on android to put files from a package in their respective package folder.
|
|
36
|
+
*/
|
|
37
|
+
getAndroidPackageDirectory(...subPackage: string[]): string[];
|
|
38
|
+
/**
|
|
39
|
+
* Get the autolinking configuration of all HybridObjects.
|
|
40
|
+
* Those will be generated and default-constructed.
|
|
41
|
+
*/
|
|
42
|
+
getAutolinkedHybridObjects(): NitroUserConfig['autolinking'];
|
|
43
|
+
/**
|
|
44
|
+
* Get the paths that will be ignored when loading the TypeScript project.
|
|
45
|
+
* In most cases, this just contains `node_modules/`.
|
|
46
|
+
*/
|
|
47
|
+
getIgnorePaths(): string[];
|
|
48
|
+
getGitAttributesGeneratedFlag(): boolean;
|
|
49
|
+
get isExternalConfig(): boolean;
|
|
50
|
+
getSwiftBridgeHeaderName(): string;
|
|
51
|
+
getSwiftBridgeNamespace(language: 'c++' | 'swift'): string;
|
|
52
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const NitroUserConfigSchema: z.ZodObject<{
|
|
3
|
+
cxxNamespace: z.ZodArray<z.ZodString>;
|
|
4
|
+
ios: z.ZodObject<{
|
|
5
|
+
iosModuleName: z.ZodString;
|
|
6
|
+
}, z.core.$strip>;
|
|
7
|
+
android: z.ZodObject<{
|
|
8
|
+
androidNamespace: z.ZodArray<z.ZodString>;
|
|
9
|
+
androidCxxLibName: z.ZodString;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
autolinking: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
12
|
+
cpp: z.ZodOptional<z.ZodString>;
|
|
13
|
+
swift: z.ZodOptional<z.ZodString>;
|
|
14
|
+
kotlin: z.ZodOptional<z.ZodString>;
|
|
15
|
+
}, z.core.$strip>>;
|
|
16
|
+
ignorePaths: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
17
|
+
gitAttributesGeneratedFlag: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
/**
|
|
20
|
+
* Represents the structure of a `nitro.json` config file.
|
|
21
|
+
*/
|
|
22
|
+
export type NitroUserConfig = z.infer<typeof NitroUserConfigSchema>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createGitAttributes(markAsGenerated: boolean, folder: string): Promise<string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getFiles(directory: string): Promise<string[]>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PlatformSpec } from 'react-native-nitro-modules';
|
|
2
|
+
import type { InterfaceDeclaration, Type, TypeAliasDeclaration } from 'ts-morph';
|
|
3
|
+
export type Platform = keyof Required<PlatformSpec>;
|
|
4
|
+
export type Language = Required<PlatformSpec>[keyof PlatformSpec];
|
|
5
|
+
export declare function isDirectlyHybridObject(type: Type): boolean;
|
|
6
|
+
export declare function extendsHybridObject(type: Type, recursive: boolean): boolean;
|
|
7
|
+
export declare function isHybridViewProps(type: Type): boolean;
|
|
8
|
+
export declare function isHybridViewMethods(type: Type): boolean;
|
|
9
|
+
export declare function isHybridView(type: Type): boolean;
|
|
10
|
+
export declare function isAnyHybridSubclass(type: Type): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* If the given interface ({@linkcode declaration}) extends `HybridObject`,
|
|
13
|
+
* this method returns the platforms it exists on.
|
|
14
|
+
* If it doesn't extend `HybridObject`, this returns `undefined`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getHybridObjectPlatforms(declaration: InterfaceDeclaration | TypeAliasDeclaration): PlatformSpec | undefined;
|
|
17
|
+
export declare function getHybridViewPlatforms(view: InterfaceDeclaration | TypeAliasDeclaration): PlatformSpec | undefined;
|
package/lib/index.d.ts
ADDED
package/lib/init.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function initNewNitroModule(baseDirectory: string, moduleName: string, ref?: string): Promise<void>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface NitrogenOptions {
|
|
2
|
+
baseDirectory: string;
|
|
3
|
+
outputDirectory: string;
|
|
4
|
+
}
|
|
5
|
+
interface NitrogenResult {
|
|
6
|
+
generatedFiles: string[];
|
|
7
|
+
targetSpecsCount: number;
|
|
8
|
+
generatedSpecsCount: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function runNitrogen({ baseDirectory, outputDirectory, }: NitrogenOptions): Promise<NitrogenResult>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function prettifyDirectory(directory: string): string;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Language } from '../getPlatformSpecs.js';
|
|
2
|
+
import type { SourceFile, SourceImport } from './SourceFile.js';
|
|
3
|
+
import type { Type } from './types/Type.js';
|
|
4
|
+
export interface BridgedType<FromLanguage extends Language, ToLanguage extends Language> {
|
|
5
|
+
/**
|
|
6
|
+
* The underlying type that is being bridged between {@linkcode FromLanguage} and {@linkcode ToLanguage}
|
|
7
|
+
*/
|
|
8
|
+
readonly type: Type;
|
|
9
|
+
/**
|
|
10
|
+
* Whether the underlying type has a valid type (is not void or null)
|
|
11
|
+
*/
|
|
12
|
+
readonly hasType: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Whether this type can be passed by reference
|
|
15
|
+
*/
|
|
16
|
+
readonly canBePassedByReference: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Whether this bridged type needs special handling, or can just be used as-is
|
|
19
|
+
*/
|
|
20
|
+
readonly needsSpecialHandling: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Get all imports required for this bridge to work
|
|
23
|
+
*/
|
|
24
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
25
|
+
/**
|
|
26
|
+
* Get all extra files that need to be created for this type, as well as the bridge.
|
|
27
|
+
*/
|
|
28
|
+
getExtraFiles(): SourceFile[];
|
|
29
|
+
/**
|
|
30
|
+
* Get the code for the type itself in the given language
|
|
31
|
+
*/
|
|
32
|
+
getTypeCode(language: FromLanguage | ToLanguage): string;
|
|
33
|
+
/**
|
|
34
|
+
* Parse the given parameter from the source language to the given target language, in the given language.
|
|
35
|
+
* For example, to convert an ArrayBuffer from Swift ({@linkcode from}) to C++ ({@linkcode to}) we
|
|
36
|
+
* have to wrap it in an ArrayBufferHolder in Swift ({@linkcode inLanguage}), and unwrap
|
|
37
|
+
* it from the ArrayBufferHolder again in C++ ({@linkcode inLanguage})
|
|
38
|
+
*/
|
|
39
|
+
parse(parameterName: string, from: FromLanguage, to: ToLanguage, inLanguage: FromLanguage | ToLanguage): string;
|
|
40
|
+
parse(parameterName: string, from: ToLanguage, to: FromLanguage, inLanguage: FromLanguage | ToLanguage): string;
|
|
41
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Language } from '../getPlatformSpecs.js';
|
|
2
|
+
import type { SourceFile, SourceImport } from './SourceFile.js';
|
|
3
|
+
export interface CodeNode {
|
|
4
|
+
/**
|
|
5
|
+
* Get the code of this code node (e.g. property, method) in the given language.
|
|
6
|
+
*/
|
|
7
|
+
getCode(language: Language): string;
|
|
8
|
+
/**
|
|
9
|
+
* Get all extra definition files this code node needs (e.g. extra type/struct declarations
|
|
10
|
+
* for complex types), or `[]` if none are required (e.g. if this uses primitive types only)
|
|
11
|
+
*
|
|
12
|
+
* All files returned here must be created in the project.
|
|
13
|
+
* To include them, see {@linkcode getRequiredImports | getRequiredImports()}
|
|
14
|
+
*/
|
|
15
|
+
getExtraFiles(): SourceFile[];
|
|
16
|
+
/**
|
|
17
|
+
* Get all required imports this code node needs (e.g. extra type/struct declarations for complex types),
|
|
18
|
+
* or `[]` if no imports are required (e.g. if this uses primitive types only).
|
|
19
|
+
*
|
|
20
|
+
* All imports returned here must be included in the current file (e.g. `#include "..."` or `import ...`)
|
|
21
|
+
*/
|
|
22
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
23
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { CodeNode } from './CodeNode.js';
|
|
2
|
+
import type { Language } from '../getPlatformSpecs.js';
|
|
3
|
+
import { type SourceFile, type SourceImport } from './SourceFile.js';
|
|
4
|
+
import { Parameter } from './Parameter.js';
|
|
5
|
+
import type { Type } from './types/Type.js';
|
|
6
|
+
export type MethodBody = string;
|
|
7
|
+
export interface MethodModifiers {
|
|
8
|
+
/**
|
|
9
|
+
* The name of the class that defines this C++ method.
|
|
10
|
+
* Example: `Person` -> `void Person::sayHi()`
|
|
11
|
+
*/
|
|
12
|
+
classDefinitionName?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Whether the function should be marked as inlineable.
|
|
15
|
+
*/
|
|
16
|
+
inline?: boolean;
|
|
17
|
+
virtual?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Whether the function is marked as `noexcept` (doesn't throw) or not.
|
|
20
|
+
*/
|
|
21
|
+
noexcept?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Whether this function overrides a base/super function.
|
|
24
|
+
*/
|
|
25
|
+
override?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Whether this method has a `@DoNotStrip` and `@Keep` attribute to avoid
|
|
28
|
+
* it from being stripped from the binary by the Java compiler or ProGuard.
|
|
29
|
+
*/
|
|
30
|
+
doNotStrip?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare class Method implements CodeNode {
|
|
33
|
+
readonly name: string;
|
|
34
|
+
readonly returnType: Type;
|
|
35
|
+
readonly parameters: Parameter[];
|
|
36
|
+
constructor(name: string, returnType: Type, parameters: Parameter[]);
|
|
37
|
+
get jsSignature(): string;
|
|
38
|
+
getCode(language: Language, modifiers?: MethodModifiers, body?: MethodBody): string;
|
|
39
|
+
getExtraFiles(): SourceFile[];
|
|
40
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
41
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ParameterDeclaration } from 'ts-morph';
|
|
2
|
+
import type { CodeNode } from './CodeNode.js';
|
|
3
|
+
import type { Language } from '../getPlatformSpecs.js';
|
|
4
|
+
import { type SourceFile, type SourceImport } from './SourceFile.js';
|
|
5
|
+
import type { NamedType, Type } from './types/Type.js';
|
|
6
|
+
export declare class Parameter implements CodeNode {
|
|
7
|
+
readonly type: NamedType;
|
|
8
|
+
constructor(name: string, type: Type);
|
|
9
|
+
constructor(parameter: ParameterDeclaration, language: Language);
|
|
10
|
+
get jsSignature(): string;
|
|
11
|
+
get name(): string;
|
|
12
|
+
getCode(language: Language): string;
|
|
13
|
+
getExtraFiles(): SourceFile[];
|
|
14
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
15
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { CodeNode } from './CodeNode.js';
|
|
2
|
+
import { type SourceFile, type SourceImport } from './SourceFile.js';
|
|
3
|
+
import type { Language } from '../getPlatformSpecs.js';
|
|
4
|
+
import type { Type } from './types/Type.js';
|
|
5
|
+
import { Method } from './Method.js';
|
|
6
|
+
export interface PropertyBody {
|
|
7
|
+
getter: string;
|
|
8
|
+
setter: string;
|
|
9
|
+
}
|
|
10
|
+
export type LanguageEnvironment = 'jvm' | 'swift' | 'other';
|
|
11
|
+
export interface PropertyModifiers {
|
|
12
|
+
/**
|
|
13
|
+
* The name of the class that defines this C++ property getter/setter method.
|
|
14
|
+
* Example: `Person` -> `int Person::getAge()`
|
|
15
|
+
*/
|
|
16
|
+
classDefinitionName?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Whether the property should be marked as inlineable.
|
|
19
|
+
*/
|
|
20
|
+
inline?: boolean;
|
|
21
|
+
virtual?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Whether the property is marked as `noexcept` (doesn't throw) or not.
|
|
24
|
+
*/
|
|
25
|
+
noexcept?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Whether this property overrides a base/super property.
|
|
28
|
+
*/
|
|
29
|
+
override?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Whether this property has a `@DoNotStrip` and `@Keep` attribute to avoid
|
|
32
|
+
* it from being stripped from the binary by the Java compiler or ProGuard.
|
|
33
|
+
*/
|
|
34
|
+
doNotStrip?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export declare class Property implements CodeNode {
|
|
37
|
+
readonly name: string;
|
|
38
|
+
readonly type: Type;
|
|
39
|
+
readonly isReadonly: boolean;
|
|
40
|
+
constructor(name: string, type: Type, isReadonly: boolean);
|
|
41
|
+
get jsSignature(): string;
|
|
42
|
+
getExtraFiles(): SourceFile[];
|
|
43
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
44
|
+
getGetterName(environment: LanguageEnvironment): string;
|
|
45
|
+
getSetterName(environment: LanguageEnvironment): string;
|
|
46
|
+
get cppGetter(): Method;
|
|
47
|
+
get cppSetter(): Method | undefined;
|
|
48
|
+
getCppMethods(): [getter: Method] | [getter: Method, setter: Method];
|
|
49
|
+
getCode(language: Language, modifiers?: PropertyModifiers, body?: PropertyBody): string;
|
|
50
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Language, Platform } from '../getPlatformSpecs.js';
|
|
2
|
+
import type { Type } from './types/Type.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a file with source code, in a specific programming language.
|
|
5
|
+
*/
|
|
6
|
+
export interface SourceFile {
|
|
7
|
+
/**
|
|
8
|
+
* The name of the file with extension (e.g. `Image.hpp`)
|
|
9
|
+
*/
|
|
10
|
+
name: string;
|
|
11
|
+
/**
|
|
12
|
+
* The subdirectory/subdirectories of the file, or empty (`[]`) if none.
|
|
13
|
+
*/
|
|
14
|
+
subdirectory: string[];
|
|
15
|
+
/**
|
|
16
|
+
* The full content of the file.
|
|
17
|
+
*/
|
|
18
|
+
content: string;
|
|
19
|
+
/**
|
|
20
|
+
* The language the {@linkcode content} is written in (e.g. `c++`)
|
|
21
|
+
*/
|
|
22
|
+
language: Language;
|
|
23
|
+
/**
|
|
24
|
+
* The platform this file can be used on or is created for. (e.g. `ios`)
|
|
25
|
+
*/
|
|
26
|
+
platform: Platform | 'shared';
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Represents a {@linkcode SourceFile} that also references other types.
|
|
30
|
+
*/
|
|
31
|
+
export interface FileWithReferencedTypes extends SourceFile {
|
|
32
|
+
/**
|
|
33
|
+
* All external types this {@linkcode SourceFile} references,
|
|
34
|
+
* either as return types, parameter types, or member types.
|
|
35
|
+
*/
|
|
36
|
+
referencedTypes: Type[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Represents an import for a specific header or module.
|
|
40
|
+
*
|
|
41
|
+
* E.g. `include "Image.hpp"`, or `import NitroModules`
|
|
42
|
+
*/
|
|
43
|
+
export interface SourceImport {
|
|
44
|
+
/**
|
|
45
|
+
* The name of the header or module to import (e.g. `Image.hpp`)
|
|
46
|
+
*/
|
|
47
|
+
name: string;
|
|
48
|
+
/**
|
|
49
|
+
* If this is a C++ import, it could also be forward-declared.
|
|
50
|
+
* @example
|
|
51
|
+
* ```cpp
|
|
52
|
+
* namespace NitroTest {
|
|
53
|
+
* class HybridImage;
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
forwardDeclaration?: string;
|
|
58
|
+
/**
|
|
59
|
+
* The language this file is written in (e.g. `c++`)
|
|
60
|
+
*/
|
|
61
|
+
language: Language;
|
|
62
|
+
/**
|
|
63
|
+
* Whether the import is a user-defined header (something local, like `"MyObject.hpp"`)
|
|
64
|
+
* or a shared system header (like `<NitroModules/HybridObject.hpp>`)
|
|
65
|
+
*/
|
|
66
|
+
space: 'user' | 'system';
|
|
67
|
+
}
|
|
68
|
+
type GroupedFiles = Record<SourceFile['platform'], SourceFile[]>;
|
|
69
|
+
export declare function groupByPlatform(files: SourceFile[]): GroupedFiles;
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SourceFile } from '../SourceFile.js';
|
|
2
|
+
import type { EnumMember } from '../types/EnumType.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a C++ enum that converts to a JS enum (aka just int)
|
|
5
|
+
*/
|
|
6
|
+
export declare function createCppEnum(typename: string, enumMembers: EnumMember[]): SourceFile;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { SourceImport } from '../SourceFile.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
/**
|
|
4
|
+
* The name of the Hybrid Object under which it should be registered and exposed to JS to.
|
|
5
|
+
*/
|
|
6
|
+
hybridObjectName: string;
|
|
7
|
+
/**
|
|
8
|
+
* The name of the C++ class that will be default-constructed
|
|
9
|
+
*/
|
|
10
|
+
cppClassName: string;
|
|
11
|
+
}
|
|
12
|
+
interface CppHybridObjectRegistration {
|
|
13
|
+
cppCode: string;
|
|
14
|
+
requiredImports: SourceImport[];
|
|
15
|
+
}
|
|
16
|
+
export declare function createCppHybridObjectRegistration({ hybridObjectName, cppClassName, }: Props): CppHybridObjectRegistration;
|
|
17
|
+
export {};
|
|
@@ -48,6 +48,7 @@ ${createFileMetadataString(`${typename}.hpp`)}
|
|
|
48
48
|
|
|
49
49
|
${includeNitroHeader('JSIConverter.hpp')}
|
|
50
50
|
${includeNitroHeader('NitroDefines.hpp')}
|
|
51
|
+
${includeNitroHeader('JSIHelpers.hpp')}
|
|
51
52
|
|
|
52
53
|
${cppForwardDeclarations.join('\n')}
|
|
53
54
|
|
|
@@ -90,6 +91,9 @@ namespace margelo::nitro {
|
|
|
90
91
|
return false;
|
|
91
92
|
}
|
|
92
93
|
jsi::Object obj = value.getObject(runtime);
|
|
94
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
93
97
|
${indent(cppCanConvertCalls, ' ')}
|
|
94
98
|
return true;
|
|
95
99
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SourceFile } from '../SourceFile.js';
|
|
2
|
+
import type { EnumMember } from '../types/EnumType.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a C++ enum that converts to a TypeScript union (aka just strings).
|
|
5
|
+
*/
|
|
6
|
+
export declare function createCppUnion(typename: string, enumMembers: EnumMember[]): SourceFile;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SourceImport } from '../SourceFile.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generates C++ code for including a `NitroModules` header.
|
|
4
|
+
* @example `Hash.hpp` -> `#include <NitroModules/Hash.hpp>`
|
|
5
|
+
*/
|
|
6
|
+
export declare function includeNitroHeader(headerName: string): string;
|
|
7
|
+
export declare function includeHeader(sourceImport: SourceImport, force?: boolean): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Type as TSMorphType } from 'ts-morph';
|
|
2
|
+
import type { Type } from './types/Type.js';
|
|
3
|
+
import { NamedWrappingType } from './types/NamedWrappingType.js';
|
|
4
|
+
import { type Language } from '../getPlatformSpecs.js';
|
|
5
|
+
export declare function createNamedType(language: Language, name: string, type: TSMorphType, isOptional: boolean): NamedWrappingType<Type>;
|
|
6
|
+
export declare function createVoidType(): Type;
|
|
7
|
+
/**
|
|
8
|
+
* Get a list of all currently known complex types.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getAllKnownTypes(language?: Language): Type[];
|
|
11
|
+
export declare function addKnownType(key: string, type: Type, language: Language): void;
|
|
12
|
+
/**
|
|
13
|
+
* Create a new type (or return it from cache if it is already known)
|
|
14
|
+
*/
|
|
15
|
+
export declare function createType(language: Language, type: TSMorphType, isOptional: boolean): Type;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CustomTypeConfig } from 'react-native-nitro-modules';
|
|
2
|
+
import type { Type as TSMorphType } from 'ts-morph';
|
|
3
|
+
interface Result {
|
|
4
|
+
name: string;
|
|
5
|
+
config: CustomTypeConfig;
|
|
6
|
+
}
|
|
7
|
+
export declare function getCustomTypeConfig(type: TSMorphType): Result;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SourceFile } from './SourceFile.js';
|
|
2
|
+
import type { Type } from './types/Type.js';
|
|
3
|
+
type Comment = '///' | '#';
|
|
4
|
+
export declare function createFileMetadataString(filename: string, comment?: Comment): string;
|
|
5
|
+
export declare function isFunction(type: Type): boolean;
|
|
6
|
+
export declare function toReferenceType(type: string): `const ${typeof type}&`;
|
|
7
|
+
export declare function escapeCppName(string: string): string;
|
|
8
|
+
export declare function isBooleanPropertyPrefix(name: string): boolean;
|
|
9
|
+
export declare function isNotDuplicate<T>(item: T, index: number, array: T[]): boolean;
|
|
10
|
+
export declare function isCppFile(file: SourceFile): boolean;
|
|
11
|
+
export declare function getRelativeDirectory(file: SourceFile): string;
|
|
12
|
+
export declare function getRelativeDirectoryGenerated(...subpath: string[]): string;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Type as TSMorphType } from 'ts-morph';
|
|
2
|
+
export declare function isPromise(type: TSMorphType): boolean;
|
|
3
|
+
export declare function isRecord(type: TSMorphType): boolean;
|
|
4
|
+
export declare function isArrayBuffer(type: TSMorphType): boolean;
|
|
5
|
+
export declare function isDate(type: TSMorphType): boolean;
|
|
6
|
+
export declare function isMap(type: TSMorphType): boolean;
|
|
7
|
+
export declare function isError(type: TSMorphType): boolean;
|
|
8
|
+
export declare function isCustomType(type: TSMorphType): boolean;
|
|
9
|
+
export declare function isSyncFunction(type: TSMorphType): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SourceImport } from '../SourceFile.js';
|
|
2
|
+
export interface JNINativeRegistration {
|
|
3
|
+
namespace: string;
|
|
4
|
+
className: string;
|
|
5
|
+
import: SourceImport;
|
|
6
|
+
}
|
|
7
|
+
export declare function addJNINativeRegistration(registerFunc: JNINativeRegistration): void;
|
|
8
|
+
export declare function getJNINativeRegistrations(): JNINativeRegistration[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Type } from '../types/Type.js';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a boxed version of the given primitive type.
|
|
4
|
+
* In JNI/Kotlin, primitive types (like `double` or `boolean`)
|
|
5
|
+
* cannot be nullable, so we need to box them - e.g. as `JDouble` or `JBoolean`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getKotlinBoxedPrimitiveType(type: Type): string;
|