nitrogen 0.29.8 → 0.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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/init.js +1 -1
- 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/KotlinCxxBridgedType.js +0 -14
- 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/KotlinHybridObject.js +1 -1
- package/lib/syntax/kotlin/KotlinHybridObjectRegistration.d.ts +17 -0
- package/lib/syntax/kotlin/KotlinStruct.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinStruct.js +51 -46
- package/lib/syntax/kotlin/KotlinVariant.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinVariant.js +37 -4
- package/lib/syntax/swift/SwiftCxxBridgedType.d.ts +21 -0
- package/lib/syntax/swift/SwiftCxxBridgedType.js +5 -2
- 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/init.ts +1 -1
- package/src/syntax/c++/CppStruct.ts +4 -0
- package/src/syntax/kotlin/KotlinCxxBridgedType.ts +0 -14
- package/src/syntax/kotlin/KotlinHybridObject.ts +1 -1
- package/src/syntax/kotlin/KotlinStruct.ts +54 -47
- package/src/syntax/kotlin/KotlinVariant.ts +37 -4
- package/src/syntax/swift/SwiftCxxBridgedType.ts +5 -2
- package/src/syntax/swift/SwiftCxxTypeHelper.ts +3 -7
- package/src/syntax/swift/isPrimitivelyCopyable.ts +20 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type NitroConfig } from '../../config/NitroConfig.js';
|
|
2
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
3
|
+
import type { HybridObjectSpec } from '../HybridObjectSpec.js';
|
|
4
|
+
import type { SourceFile, SourceImport } from '../SourceFile.js';
|
|
5
|
+
import type { GetCodeOptions, Type, TypeKind } from './Type.js';
|
|
6
|
+
interface GetHybridObjectCodeOptions extends GetCodeOptions {
|
|
7
|
+
mode?: 'strong' | 'weak';
|
|
8
|
+
}
|
|
9
|
+
export declare class HybridObjectType implements Type {
|
|
10
|
+
readonly hybridObjectName: string;
|
|
11
|
+
readonly implementationLanguage: Language;
|
|
12
|
+
readonly baseTypes: HybridObjectType[];
|
|
13
|
+
readonly sourceConfig: NitroConfig;
|
|
14
|
+
constructor(hybridObjectName: string, implementationLanguage: Language, baseTypes: HybridObjectType[], sourceConfig: NitroConfig);
|
|
15
|
+
constructor(spec: HybridObjectSpec);
|
|
16
|
+
get canBePassedByReference(): boolean;
|
|
17
|
+
get kind(): TypeKind;
|
|
18
|
+
getCode(language: Language, options?: GetHybridObjectCodeOptions): string;
|
|
19
|
+
getExtraFiles(): SourceFile[];
|
|
20
|
+
private getExternalCxxImportName;
|
|
21
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import type { SourceFile, SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class MapType implements Type {
|
|
5
|
+
get canBePassedByReference(): boolean;
|
|
6
|
+
get kind(): TypeKind;
|
|
7
|
+
getCode(language: Language): string;
|
|
8
|
+
getExtraFiles(): SourceFile[];
|
|
9
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
10
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import type { SourceFile, SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { GetCodeOptions, NamedType, Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class NamedWrappingType<T extends Type> implements NamedType {
|
|
5
|
+
readonly type: T;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
constructor(name: string, type: T);
|
|
8
|
+
get escapedName(): string;
|
|
9
|
+
get kind(): TypeKind;
|
|
10
|
+
get canBePassedByReference(): boolean;
|
|
11
|
+
getCode(language: Language, options?: GetCodeOptions): string;
|
|
12
|
+
getExtraFiles(): SourceFile[];
|
|
13
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import type { SourceFile, SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class NullType implements Type {
|
|
5
|
+
get canBePassedByReference(): boolean;
|
|
6
|
+
get kind(): TypeKind;
|
|
7
|
+
getCode(language: Language): string;
|
|
8
|
+
getExtraFiles(): SourceFile[];
|
|
9
|
+
getRequiredImports(): SourceImport[];
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import type { SourceFile, SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class NumberType implements Type {
|
|
5
|
+
get canBePassedByReference(): boolean;
|
|
6
|
+
get kind(): TypeKind;
|
|
7
|
+
getCode(language: Language): string;
|
|
8
|
+
getExtraFiles(): SourceFile[];
|
|
9
|
+
getRequiredImports(): SourceImport[];
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import { type SourceFile, type SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { GetCodeOptions, Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class OptionalType implements Type {
|
|
5
|
+
readonly wrappingType: Type;
|
|
6
|
+
constructor(wrappingType: Type);
|
|
7
|
+
get canBePassedByReference(): boolean;
|
|
8
|
+
get kind(): TypeKind;
|
|
9
|
+
get needsBraces(): boolean;
|
|
10
|
+
getCode(language: Language, options?: GetCodeOptions): string;
|
|
11
|
+
getExtraFiles(): SourceFile[];
|
|
12
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import { type SourceFile, type SourceImport } from '../SourceFile.js';
|
|
3
|
+
import { FunctionType } from './FunctionType.js';
|
|
4
|
+
import type { GetCodeOptions, Type, TypeKind } from './Type.js';
|
|
5
|
+
export declare class PromiseType implements Type {
|
|
6
|
+
readonly resultingType: Type;
|
|
7
|
+
readonly errorType: Type;
|
|
8
|
+
constructor(resultingType: Type);
|
|
9
|
+
get canBePassedByReference(): boolean;
|
|
10
|
+
get kind(): TypeKind;
|
|
11
|
+
get resolverFunction(): FunctionType;
|
|
12
|
+
get rejecterFunction(): FunctionType;
|
|
13
|
+
getCode(language: Language, options?: GetCodeOptions): string;
|
|
14
|
+
getExtraFiles(): SourceFile[];
|
|
15
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import { type SourceFile, type SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { GetCodeOptions, Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class RecordType implements Type {
|
|
5
|
+
readonly keyType: Type;
|
|
6
|
+
readonly valueType: Type;
|
|
7
|
+
constructor(keyType: Type, valueType: Type);
|
|
8
|
+
get canBePassedByReference(): boolean;
|
|
9
|
+
get kind(): TypeKind;
|
|
10
|
+
getCode(language: Language, options?: GetCodeOptions): string;
|
|
11
|
+
getExtraFiles(): SourceFile[];
|
|
12
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import { type SourceFile, type SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { GetCodeOptions, Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class ResultWrappingType implements Type {
|
|
5
|
+
readonly result: Type;
|
|
6
|
+
readonly error: Type;
|
|
7
|
+
constructor(result: Type);
|
|
8
|
+
get canBePassedByReference(): boolean;
|
|
9
|
+
get kind(): TypeKind;
|
|
10
|
+
getCode(language: Language, options?: GetCodeOptions): string;
|
|
11
|
+
getExtraFiles(): SourceFile[];
|
|
12
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import type { SourceFile, SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class StringType implements Type {
|
|
5
|
+
get canBePassedByReference(): boolean;
|
|
6
|
+
get kind(): TypeKind;
|
|
7
|
+
getCode(language: Language): string;
|
|
8
|
+
getExtraFiles(): SourceFile[];
|
|
9
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
10
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import { type FileWithReferencedTypes, type SourceFile, type SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { GetCodeOptions, NamedType, Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class StructType implements Type {
|
|
5
|
+
readonly structName: string;
|
|
6
|
+
readonly properties: NamedType[];
|
|
7
|
+
readonly declarationFile: FileWithReferencedTypes;
|
|
8
|
+
constructor(structName: string, properties: NamedType[]);
|
|
9
|
+
get canBePassedByReference(): boolean;
|
|
10
|
+
get kind(): TypeKind;
|
|
11
|
+
getCode(language: Language, { fullyQualified }?: GetCodeOptions): string;
|
|
12
|
+
getExtraFiles(): SourceFile[];
|
|
13
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import { type SourceFile, type SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { GetCodeOptions, Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class TupleType implements Type {
|
|
5
|
+
readonly itemTypes: Type[];
|
|
6
|
+
constructor(itemTypes: Type[]);
|
|
7
|
+
get canBePassedByReference(): boolean;
|
|
8
|
+
get kind(): TypeKind;
|
|
9
|
+
getCode(language: Language, options?: GetCodeOptions): string;
|
|
10
|
+
getExtraFiles(): SourceFile[];
|
|
11
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
12
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import type { SourceFile, SourceImport } from '../SourceFile.js';
|
|
3
|
+
export type TypeKind = 'array-buffer' | 'array' | 'bigint' | 'boolean' | 'custom-type' | 'enum' | 'error' | 'function' | 'hybrid-object' | 'hybrid-object-base' | 'map' | 'null' | 'number' | 'optional' | 'promise' | 'record' | 'string' | 'struct' | 'tuple' | 'variant' | 'result-wrapper' | 'date' | 'void';
|
|
4
|
+
export interface GetCodeOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Specifies whether the name (e.g. a C++ class name)
|
|
7
|
+
* should use the fully qualified namespace name prefix.
|
|
8
|
+
*/
|
|
9
|
+
fullyQualified?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Represents a TypeScript Type that can be represented in a native language (C++, Swift, Kotlin)
|
|
13
|
+
*/
|
|
14
|
+
export interface Type {
|
|
15
|
+
/**
|
|
16
|
+
* Get whether this type can be passed by reference in C++ (`const T&` vs `T`)
|
|
17
|
+
*/
|
|
18
|
+
readonly canBePassedByReference: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Get the kind of the type.
|
|
21
|
+
*/
|
|
22
|
+
readonly kind: TypeKind;
|
|
23
|
+
/**
|
|
24
|
+
* Get the native code required to represent this type for the given language (C++, Swift, Kotlin).
|
|
25
|
+
*
|
|
26
|
+
* E.g. for a `number` type, this would return `'double'` in C++.
|
|
27
|
+
*
|
|
28
|
+
* The `options` parameter can specify custom options. Subclasses may have more options.
|
|
29
|
+
*/
|
|
30
|
+
getCode(language: Language, options?: GetCodeOptions): string;
|
|
31
|
+
/**
|
|
32
|
+
* Get all required extra files that need to be **created** for this type to properly work.
|
|
33
|
+
*
|
|
34
|
+
* E.g. for `type Gender = 'male' | 'female'`, the enum `Gender` needs to be created first (as a separate file).
|
|
35
|
+
*/
|
|
36
|
+
getExtraFiles(): SourceFile[];
|
|
37
|
+
/**
|
|
38
|
+
* Get all required extra imports that need to be **imported** for this type to properly work.
|
|
39
|
+
*/
|
|
40
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
41
|
+
}
|
|
42
|
+
export interface NamedType extends Type {
|
|
43
|
+
/**
|
|
44
|
+
* Get the name of the value if it is a member or parameter.
|
|
45
|
+
*
|
|
46
|
+
* E.g. for a class member `double _something`, this returns `'_something'`.
|
|
47
|
+
*/
|
|
48
|
+
readonly name: string;
|
|
49
|
+
/**
|
|
50
|
+
* Get the name of the value escaped as a valid C++ variable name.
|
|
51
|
+
*
|
|
52
|
+
* E.g. for a class member `double some-value`, this returns `'some_value'`.
|
|
53
|
+
*/
|
|
54
|
+
readonly escapedName: string;
|
|
55
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import { type SourceFile, type SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { GetCodeOptions, Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare const VariantLabels: readonly ["first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eigth", "ninth", "tenth"];
|
|
5
|
+
type VariantLabel = (typeof VariantLabels)[number];
|
|
6
|
+
export declare class VariantType implements Type {
|
|
7
|
+
readonly variants: Type[];
|
|
8
|
+
readonly aliasName?: string;
|
|
9
|
+
constructor(variants: Type[], aliasName?: string);
|
|
10
|
+
get canBePassedByReference(): boolean;
|
|
11
|
+
get kind(): TypeKind;
|
|
12
|
+
get jsType(): string;
|
|
13
|
+
get cases(): [VariantLabel, Type][];
|
|
14
|
+
getAliasName(language: Language, options?: GetCodeOptions): string;
|
|
15
|
+
getCode(language: Language, options?: GetCodeOptions): string;
|
|
16
|
+
getExtraFiles(): SourceFile[];
|
|
17
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import type { SourceFile, SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class VoidType implements Type {
|
|
5
|
+
get canBePassedByReference(): boolean;
|
|
6
|
+
get kind(): TypeKind;
|
|
7
|
+
getCode(language: Language): string;
|
|
8
|
+
getExtraFiles(): SourceFile[];
|
|
9
|
+
getRequiredImports(): SourceImport[];
|
|
10
|
+
}
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SourceFile } from './syntax/SourceFile.js';
|
|
2
|
+
import type { SwiftCxxHelper } from './syntax/swift/SwiftCxxTypeHelper.js';
|
|
3
|
+
import type { Type } from 'ts-morph';
|
|
4
|
+
import { NitroConfig } from './config/NitroConfig.js';
|
|
5
|
+
export declare const NITROGEN_VERSION: string;
|
|
6
|
+
export declare function capitalizeName(name: string): string;
|
|
7
|
+
export declare function createIndentation(spacesCount: number): string;
|
|
8
|
+
export declare function indent(string: string, spacesCount: number): string;
|
|
9
|
+
export declare function indent(string: string, indentation: string): string;
|
|
10
|
+
export declare function errorToString(error: unknown): string;
|
|
11
|
+
export declare function escapeComments(string: string): string;
|
|
12
|
+
export declare function toUnixPath(p: string): string;
|
|
13
|
+
export declare function unsafeFastJoin(...segments: string[]): string;
|
|
14
|
+
/**
|
|
15
|
+
* Deduplicates all files via their full path.
|
|
16
|
+
* If content differs, you are f*cked.
|
|
17
|
+
*/
|
|
18
|
+
export declare function deduplicateFiles(files: SourceFile[]): SourceFile[];
|
|
19
|
+
export declare function filterDuplicateHelperBridges(bridge: SwiftCxxHelper, i: number, array: SwiftCxxHelper[]): boolean;
|
|
20
|
+
export declare function toLowerCamelCase(string: string): string;
|
|
21
|
+
export declare function getBaseTypes(type: Type): Type[];
|
|
22
|
+
export declare function getHybridObjectNitroModuleConfig(type: Type): NitroConfig | undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SourceFile } from '../syntax/SourceFile.js';
|
|
2
|
+
import type { HybridObjectSpec } from '../syntax/HybridObjectSpec.js';
|
|
3
|
+
interface ViewComponentNames {
|
|
4
|
+
propsClassName: `${string}Props`;
|
|
5
|
+
stateClassName: `${string}State`;
|
|
6
|
+
nameVariable: `${string}ComponentName`;
|
|
7
|
+
shadowNodeClassName: `${string}ShadowNode`;
|
|
8
|
+
descriptorClassName: `${string}ComponentDescriptor`;
|
|
9
|
+
component: `${string}Component`;
|
|
10
|
+
manager: `${string}Manager`;
|
|
11
|
+
}
|
|
12
|
+
export declare function getViewComponentNames(spec: HybridObjectSpec): ViewComponentNames;
|
|
13
|
+
export declare function createViewComponentShadowNodeFiles(spec: HybridObjectSpec): SourceFile[];
|
|
14
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitrogen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.1",
|
|
4
4
|
"description": "The code-generator for react-native-nitro-modules.",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"chalk": "^5.3.0",
|
|
39
|
-
"react-native-nitro-modules": "^0.
|
|
39
|
+
"react-native-nitro-modules": "^0.30.1",
|
|
40
40
|
"ts-morph": "^27.0.0",
|
|
41
|
-
"yargs": "^
|
|
41
|
+
"yargs": "^18.0.0",
|
|
42
42
|
"zod": "^4.0.5"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
package/src/init.ts
CHANGED
|
@@ -69,6 +69,7 @@ ${createFileMetadataString(`${typename}.hpp`)}
|
|
|
69
69
|
|
|
70
70
|
${includeNitroHeader('JSIConverter.hpp')}
|
|
71
71
|
${includeNitroHeader('NitroDefines.hpp')}
|
|
72
|
+
${includeNitroHeader('JSIHelpers.hpp')}
|
|
72
73
|
|
|
73
74
|
${cppForwardDeclarations.join('\n')}
|
|
74
75
|
|
|
@@ -111,6 +112,9 @@ namespace margelo::nitro {
|
|
|
111
112
|
return false;
|
|
112
113
|
}
|
|
113
114
|
jsi::Object obj = value.getObject(runtime);
|
|
115
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
114
118
|
${indent(cppCanConvertCalls, ' ')}
|
|
115
119
|
return true;
|
|
116
120
|
}
|
|
@@ -41,10 +41,6 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
|
|
|
41
41
|
case 'function':
|
|
42
42
|
// Function needs to be converted from JFunc_... to Lambda
|
|
43
43
|
return true
|
|
44
|
-
case 'struct':
|
|
45
|
-
// Structs don't need special handling - they have direct mappings
|
|
46
|
-
// Returning false prevents secondary constructor generation that causes duplicates
|
|
47
|
-
return false
|
|
48
44
|
case 'optional':
|
|
49
45
|
// Optionals need special handling if the wrapped type needs special handling
|
|
50
46
|
const optional = getTypeAs(this.type, OptionalType)
|
|
@@ -53,16 +49,6 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
|
|
|
53
49
|
default:
|
|
54
50
|
break
|
|
55
51
|
}
|
|
56
|
-
// check if any types this type references (e.g. underlying optional, array element, ...)
|
|
57
|
-
// needs special handling. if yes, we need it as well
|
|
58
|
-
const referencedTypes = getReferencedTypes(this.type)
|
|
59
|
-
.filter((t) => t !== this.type)
|
|
60
|
-
.map((t) => new KotlinCxxBridgedType(t))
|
|
61
|
-
for (const type of referencedTypes) {
|
|
62
|
-
if (type.needsSpecialHandling) {
|
|
63
|
-
return true
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
52
|
// no special handling needed
|
|
67
53
|
return false
|
|
68
54
|
}
|
|
@@ -9,42 +9,28 @@ import { KotlinCxxBridgedType } from './KotlinCxxBridgedType.js'
|
|
|
9
9
|
|
|
10
10
|
export function createKotlinStruct(structType: StructType): SourceFile[] {
|
|
11
11
|
const packageName = NitroConfig.current.getAndroidPackage('java/kotlin')
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const parameters = structType.properties
|
|
13
|
+
.map((p) =>
|
|
14
|
+
`
|
|
15
15
|
@DoNotStrip
|
|
16
16
|
@Keep
|
|
17
|
-
val ${p.escapedName}: ${
|
|
17
|
+
val ${p.escapedName}: ${p.getCode('kotlin')}
|
|
18
18
|
`.trim()
|
|
19
|
-
})
|
|
20
|
-
let secondaryConstructor: string
|
|
21
|
-
const needsSpecialHandling = structType.properties.some(
|
|
22
|
-
(p) => new KotlinCxxBridgedType(p).needsSpecialHandling
|
|
23
|
-
)
|
|
24
|
-
if (needsSpecialHandling) {
|
|
25
|
-
// If we need special handling for any of our properties, we need to add a convenience initializer.
|
|
26
|
-
const params = structType.properties.map(
|
|
27
|
-
(p) => `${p.escapedName}: ${p.getCode('kotlin')}`
|
|
28
19
|
)
|
|
29
|
-
|
|
20
|
+
.join(',\n')
|
|
21
|
+
|
|
22
|
+
const cxxCreateFunctionParameters = structType.properties
|
|
23
|
+
.map((p) => {
|
|
30
24
|
const bridged = new KotlinCxxBridgedType(p)
|
|
31
|
-
|
|
32
|
-
// We need special parsing for this type
|
|
33
|
-
return bridged.parseFromKotlinToCpp(p.escapedName, 'kotlin', false)
|
|
34
|
-
} else {
|
|
35
|
-
return p.escapedName
|
|
36
|
-
}
|
|
25
|
+
return `${p.escapedName}: ${bridged.getTypeCode('kotlin', false)}`
|
|
37
26
|
})
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} else {
|
|
46
|
-
secondaryConstructor = `/* main constructor */`
|
|
47
|
-
}
|
|
27
|
+
.join(', ')
|
|
28
|
+
const cxxCreateFunctionForward = structType.properties
|
|
29
|
+
.map((p) => {
|
|
30
|
+
const bridged = new KotlinCxxBridgedType(p)
|
|
31
|
+
return bridged.parseFromCppToKotlin(p.escapedName, 'kotlin', false)
|
|
32
|
+
})
|
|
33
|
+
.join(', ')
|
|
48
34
|
|
|
49
35
|
const extraImports = structType.properties
|
|
50
36
|
.flatMap((t) => t.getRequiredImports('kotlin'))
|
|
@@ -65,13 +51,21 @@ ${extraImports.join('\n')}
|
|
|
65
51
|
*/
|
|
66
52
|
@DoNotStrip
|
|
67
53
|
@Keep
|
|
68
|
-
data class ${structType.structName}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
54
|
+
data class ${structType.structName}(
|
|
55
|
+
${indent(parameters, ' ')}
|
|
56
|
+
) {
|
|
57
|
+
private companion object {
|
|
58
|
+
/**
|
|
59
|
+
* Constructor called from C++
|
|
60
|
+
*/
|
|
61
|
+
@DoNotStrip
|
|
62
|
+
@Keep
|
|
63
|
+
@Suppress("unused")
|
|
64
|
+
@JvmStatic
|
|
65
|
+
private fun fromCpp(${cxxCreateFunctionParameters}): ${structType.structName} {
|
|
66
|
+
return ${structType.structName}(${cxxCreateFunctionForward})
|
|
67
|
+
}
|
|
68
|
+
}
|
|
75
69
|
}
|
|
76
70
|
`.trim()
|
|
77
71
|
|
|
@@ -185,14 +179,27 @@ function createCppStructInitializer(
|
|
|
185
179
|
cppValueName: string,
|
|
186
180
|
structType: StructType
|
|
187
181
|
): string {
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
182
|
+
const jniTypes = structType.properties
|
|
183
|
+
.map((p) => {
|
|
184
|
+
const bridge = new KotlinCxxBridgedType(p)
|
|
185
|
+
return bridge.asJniReferenceType('alias')
|
|
186
|
+
})
|
|
187
|
+
.join(', ')
|
|
188
|
+
const params = structType.properties
|
|
189
|
+
.map((p) => {
|
|
190
|
+
const name = `${cppValueName}.${p.escapedName}`
|
|
191
|
+
const bridge = new KotlinCxxBridgedType(p)
|
|
192
|
+
return bridge.parse(name, 'c++', 'kotlin', 'c++')
|
|
193
|
+
})
|
|
194
|
+
.join(',\n')
|
|
195
|
+
|
|
196
|
+
return `
|
|
197
|
+
using JSignature = J${structType.structName}(${jniTypes});
|
|
198
|
+
static const auto clazz = javaClassStatic();
|
|
199
|
+
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
|
200
|
+
return create(
|
|
201
|
+
clazz,
|
|
202
|
+
${indent(params, ' ')}
|
|
203
|
+
);
|
|
204
|
+
`.trim()
|
|
198
205
|
}
|
|
@@ -7,19 +7,21 @@ import {
|
|
|
7
7
|
toReferenceType,
|
|
8
8
|
} from '../helpers.js'
|
|
9
9
|
import type { SourceFile } from '../SourceFile.js'
|
|
10
|
+
import { OptionalType } from '../types/OptionalType.js'
|
|
10
11
|
import { type VariantType } from '../types/VariantType.js'
|
|
11
12
|
import { KotlinCxxBridgedType } from './KotlinCxxBridgedType.js'
|
|
12
13
|
|
|
13
14
|
export function createKotlinVariant(variant: VariantType): SourceFile[] {
|
|
14
|
-
const jsName = variant.variants.map((v) => v.getCode('kotlin')).join('|')
|
|
15
|
+
const jsName = variant.variants.map((v) => v.getCode('kotlin')).join(' | ')
|
|
15
16
|
const kotlinName = variant.getAliasName('kotlin')
|
|
16
17
|
const namespace = `J${kotlinName}_impl`
|
|
17
18
|
|
|
18
19
|
const innerClasses = variant.cases.map(([label, v]) => {
|
|
19
20
|
const innerName = capitalizeName(label)
|
|
21
|
+
const bridge = new KotlinCxxBridgedType(v)
|
|
20
22
|
return `
|
|
21
23
|
@DoNotStrip
|
|
22
|
-
data class ${innerName}(@DoNotStrip val value: ${
|
|
24
|
+
data class ${innerName}(@DoNotStrip val value: ${bridge.getTypeCode('kotlin')}): ${kotlinName}()
|
|
23
25
|
`.trim()
|
|
24
26
|
})
|
|
25
27
|
|
|
@@ -35,14 +37,36 @@ val is${innerName}: Boolean
|
|
|
35
37
|
get() = this is ${innerName}
|
|
36
38
|
`.trim()
|
|
37
39
|
})
|
|
40
|
+
const asFunctions = variant.cases.map(([label, v]) => {
|
|
41
|
+
const innerName = capitalizeName(label)
|
|
42
|
+
const bridge = new KotlinCxxBridgedType(v)
|
|
43
|
+
const optional = new OptionalType(v)
|
|
44
|
+
return `
|
|
45
|
+
fun as${innerName}OrNull(): ${optional.getCode('kotlin')} {
|
|
46
|
+
val value = (this as? ${innerName})?.value ?: return null
|
|
47
|
+
return ${bridge.parseFromCppToKotlin('value', 'kotlin')}
|
|
48
|
+
}
|
|
49
|
+
`.trim()
|
|
50
|
+
})
|
|
51
|
+
const matchParameters = variant.cases.map(([label, v]) => {
|
|
52
|
+
return `${label}: (${v.getCode('kotlin')}) -> R`
|
|
53
|
+
})
|
|
54
|
+
const matchCases = variant.cases.map(([label, v]) => {
|
|
55
|
+
const innerName = capitalizeName(label)
|
|
56
|
+
const bridge = new KotlinCxxBridgedType(v)
|
|
57
|
+
return `
|
|
58
|
+
is ${innerName} -> ${label}(${bridge.parseFromCppToKotlin('value', 'kotlin')})
|
|
59
|
+
`.trim()
|
|
60
|
+
})
|
|
38
61
|
|
|
39
62
|
const createFunctions = variant.cases.map(([label, v]) => {
|
|
63
|
+
const bridge = new KotlinCxxBridgedType(v)
|
|
40
64
|
const innerName = capitalizeName(label)
|
|
41
65
|
return `
|
|
42
66
|
@JvmStatic
|
|
43
67
|
@DoNotStrip
|
|
44
|
-
fun create(value: ${
|
|
45
|
-
|
|
68
|
+
fun create(value: ${bridge.getTypeCode('kotlin')}): ${kotlinName} = ${innerName}(${bridge.parseFromCppToKotlin('value', 'kotlin')})
|
|
69
|
+
`.trim()
|
|
46
70
|
})
|
|
47
71
|
|
|
48
72
|
const extraImports = variant.variants
|
|
@@ -65,12 +89,21 @@ ${extraImports.join('\n')}
|
|
|
65
89
|
sealed class ${kotlinName} {
|
|
66
90
|
${indent(innerClasses.join('\n'), ' ')}
|
|
67
91
|
|
|
92
|
+
@Deprecated("getAs() is not type-safe. Use fold/asFirstOrNull/asSecondOrNull instead.", level = DeprecationLevel.ERROR)
|
|
68
93
|
inline fun <reified T> getAs(): T? = when (this) {
|
|
69
94
|
${indent(getterCases.join('\n'), ' ')}
|
|
70
95
|
}
|
|
71
96
|
|
|
72
97
|
${indent(isFunctions.join('\n'), ' ')}
|
|
73
98
|
|
|
99
|
+
${indent(asFunctions.join('\n'), ' ')}
|
|
100
|
+
|
|
101
|
+
inline fun <R> match(${matchParameters.join(', ')}): R {
|
|
102
|
+
return when (this) {
|
|
103
|
+
${indent(matchCases.join('\n'), ' ')}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
74
107
|
companion object {
|
|
75
108
|
${indent(createFunctions.join('\n'), ' ')}
|
|
76
109
|
}
|