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.
Files changed (103) hide show
  1. package/lib/Logger.d.ts +10 -0
  2. package/lib/autolinking/Autolinking.d.ts +8 -0
  3. package/lib/autolinking/android/createCMakeExtension.d.ts +6 -0
  4. package/lib/autolinking/android/createGradleExtension.d.ts +5 -0
  5. package/lib/autolinking/android/createHybridObjectInitializer.d.ts +2 -0
  6. package/lib/autolinking/createAndroidAutolinking.d.ts +11 -0
  7. package/lib/autolinking/createIOSAutolinking.d.ts +5 -0
  8. package/lib/autolinking/ios/createHybridObjectInitializer.d.ts +9 -0
  9. package/lib/autolinking/ios/createPodspecRubyExtension.d.ts +5 -0
  10. package/lib/autolinking/ios/createSwiftCxxBridge.d.ts +2 -0
  11. package/lib/autolinking/ios/createSwiftUmbrellaHeader.d.ts +3 -0
  12. package/lib/config/NitroConfig.d.ts +52 -0
  13. package/lib/config/NitroUserConfig.d.ts +22 -0
  14. package/lib/config/getConfig.d.ts +2 -0
  15. package/lib/createGitAttributes.d.ts +1 -0
  16. package/lib/createPlatformSpec.d.ts +4 -0
  17. package/lib/getFiles.d.ts +1 -0
  18. package/lib/getPlatformSpecs.d.ts +17 -0
  19. package/lib/index.d.ts +2 -0
  20. package/lib/init.d.ts +1 -0
  21. package/lib/nitrogen.d.ts +11 -0
  22. package/lib/prettifyDirectory.d.ts +1 -0
  23. package/lib/syntax/BridgedType.d.ts +41 -0
  24. package/lib/syntax/CodeNode.d.ts +23 -0
  25. package/lib/syntax/Method.d.ts +41 -0
  26. package/lib/syntax/Parameter.d.ts +15 -0
  27. package/lib/syntax/Property.d.ts +50 -0
  28. package/lib/syntax/SourceFile.d.ts +70 -0
  29. package/lib/syntax/c++/CppEnum.d.ts +6 -0
  30. package/lib/syntax/c++/CppHybridObject.d.ts +3 -0
  31. package/lib/syntax/c++/CppHybridObjectRegistration.d.ts +17 -0
  32. package/lib/syntax/c++/CppStruct.d.ts +3 -0
  33. package/lib/syntax/c++/CppStruct.js +4 -0
  34. package/lib/syntax/c++/CppUnion.d.ts +6 -0
  35. package/lib/syntax/c++/getForwardDeclaration.d.ts +3 -0
  36. package/lib/syntax/c++/includeNitroHeader.d.ts +7 -0
  37. package/lib/syntax/createType.d.ts +15 -0
  38. package/lib/syntax/getAllTypes.d.ts +3 -0
  39. package/lib/syntax/getCustomTypeConfig.d.ts +8 -0
  40. package/lib/syntax/getInterfaceProperties.d.ts +4 -0
  41. package/lib/syntax/getReferencedTypes.d.ts +2 -0
  42. package/lib/syntax/helpers.d.ts +13 -0
  43. package/lib/syntax/isCoreType.d.ts +9 -0
  44. package/lib/syntax/kotlin/FbjniHybridObject.d.ts +3 -0
  45. package/lib/syntax/kotlin/JNINativeRegistrations.d.ts +8 -0
  46. package/lib/syntax/kotlin/KotlinBoxedPrimitive.d.ts +7 -0
  47. package/lib/syntax/kotlin/KotlinCxxBridgedType.d.ts +19 -0
  48. package/lib/syntax/kotlin/KotlinEnum.d.ts +3 -0
  49. package/lib/syntax/kotlin/KotlinFunction.d.ts +3 -0
  50. package/lib/syntax/kotlin/KotlinHybridObject.d.ts +3 -0
  51. package/lib/syntax/kotlin/KotlinHybridObjectRegistration.d.ts +17 -0
  52. package/lib/syntax/kotlin/KotlinStruct.d.ts +3 -0
  53. package/lib/syntax/kotlin/KotlinStruct.js +5 -1
  54. package/lib/syntax/kotlin/KotlinVariant.d.ts +3 -0
  55. package/lib/syntax/swift/SwiftCxxBridgedType.d.ts +21 -0
  56. package/lib/syntax/swift/SwiftCxxBridgedType.js +2 -1
  57. package/lib/syntax/swift/SwiftCxxTypeHelper.d.ts +0 -1
  58. package/lib/syntax/swift/SwiftCxxTypeHelper.js +3 -6
  59. package/lib/syntax/swift/SwiftEnum.d.ts +3 -0
  60. package/lib/syntax/swift/SwiftFunction.d.ts +3 -0
  61. package/lib/syntax/swift/SwiftHybridObject.d.ts +3 -0
  62. package/lib/syntax/swift/SwiftHybridObjectBridge.d.ts +11 -0
  63. package/lib/syntax/swift/SwiftHybridObjectRegistration.d.ts +19 -0
  64. package/lib/syntax/swift/SwiftStruct.d.ts +3 -0
  65. package/lib/syntax/swift/SwiftVariant.d.ts +3 -0
  66. package/lib/syntax/swift/isPrimitivelyCopyable.d.ts +7 -0
  67. package/lib/syntax/swift/isPrimitivelyCopyable.js +18 -0
  68. package/lib/syntax/types/ArrayBufferType.d.ts +10 -0
  69. package/lib/syntax/types/BigIntType.d.ts +10 -0
  70. package/lib/syntax/types/BooleanType.d.ts +10 -0
  71. package/lib/syntax/types/DateType.d.ts +10 -0
  72. package/lib/syntax/types/EnumType.d.ts +23 -0
  73. package/lib/syntax/types/ErrorType.d.ts +11 -0
  74. package/lib/syntax/types/FunctionType.d.ts +29 -0
  75. package/lib/syntax/types/HybridObjectBaseType.d.ts +11 -0
  76. package/lib/syntax/types/HybridObjectType.d.ts +23 -0
  77. package/lib/syntax/types/MapType.d.ts +10 -0
  78. package/lib/syntax/types/NamedWrappingType.d.ts +14 -0
  79. package/lib/syntax/types/NullType.d.ts +10 -0
  80. package/lib/syntax/types/NumberType.d.ts +10 -0
  81. package/lib/syntax/types/OptionalType.d.ts +13 -0
  82. package/lib/syntax/types/PromiseType.d.ts +16 -0
  83. package/lib/syntax/types/RecordType.d.ts +13 -0
  84. package/lib/syntax/types/ResultWrappingType.d.ts +13 -0
  85. package/lib/syntax/types/StringType.d.ts +10 -0
  86. package/lib/syntax/types/StructType.d.ts +14 -0
  87. package/lib/syntax/types/TupleType.d.ts +12 -0
  88. package/lib/syntax/types/Type.d.ts +55 -0
  89. package/lib/syntax/types/VariantType.d.ts +19 -0
  90. package/lib/syntax/types/VoidType.d.ts +10 -0
  91. package/lib/syntax/types/getTypeAs.d.ts +2 -0
  92. package/lib/utils.d.ts +22 -0
  93. package/lib/views/CppHybridViewComponent.d.ts +14 -0
  94. package/lib/views/createHostComponentJs.d.ts +3 -0
  95. package/lib/views/kotlin/KotlinHybridViewManager.d.ts +3 -0
  96. package/lib/views/swift/SwiftHybridViewManager.d.ts +3 -0
  97. package/lib/writeFile.d.ts +5 -0
  98. package/package.json +3 -3
  99. package/src/syntax/c++/CppStruct.ts +4 -0
  100. package/src/syntax/kotlin/KotlinStruct.ts +11 -3
  101. package/src/syntax/swift/SwiftCxxBridgedType.ts +1 -1
  102. package/src/syntax/swift/SwiftCxxTypeHelper.ts +3 -7
  103. package/src/syntax/swift/isPrimitivelyCopyable.ts +20 -0
@@ -0,0 +1,19 @@
1
+ import type { Language } from '../../getPlatformSpecs.js';
2
+ import type { BridgedType } from '../BridgedType.js';
3
+ import type { SourceFile, SourceImport } from '../SourceFile.js';
4
+ import type { Type } from '../types/Type.js';
5
+ export declare class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
6
+ readonly type: Type;
7
+ constructor(type: Type);
8
+ get hasType(): boolean;
9
+ get canBePassedByReference(): boolean;
10
+ get needsSpecialHandling(): boolean;
11
+ getRequiredImports(language: Language): SourceImport[];
12
+ getExtraFiles(): SourceFile[];
13
+ asJniReferenceType(referenceType?: 'alias' | 'local' | 'global'): string;
14
+ getTypeCode(language: 'kotlin' | 'c++', isBoxed?: boolean): string;
15
+ parse(parameterName: string, from: 'c++' | 'kotlin', to: 'kotlin' | 'c++', inLanguage: 'kotlin' | 'c++'): string;
16
+ parseFromCppToKotlin(parameterName: string, language: 'kotlin' | 'c++', isBoxed?: boolean): string;
17
+ parseFromKotlinToCpp(parameterName: string, language: 'kotlin' | 'c++', isBoxed?: boolean): string;
18
+ private getFullJHybridObjectName;
19
+ }
@@ -0,0 +1,3 @@
1
+ import type { SourceFile } from '../SourceFile.js';
2
+ import { EnumType } from '../types/EnumType.js';
3
+ export declare function createKotlinEnum(enumType: EnumType): SourceFile[];
@@ -0,0 +1,3 @@
1
+ import type { SourceFile } from '../SourceFile.js';
2
+ import type { FunctionType } from '../types/FunctionType.js';
3
+ export declare function createKotlinFunction(functionType: FunctionType): SourceFile[];
@@ -0,0 +1,3 @@
1
+ import type { HybridObjectSpec } from '../HybridObjectSpec.js';
2
+ import type { SourceFile } from '../SourceFile.js';
3
+ export declare function createKotlinHybridObject(spec: HybridObjectSpec): 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 Kotlin/Java class that will be default-constructed
9
+ */
10
+ jniClassName: string;
11
+ }
12
+ interface JNIHybridObjectRegistration {
13
+ cppCode: string;
14
+ requiredImports: SourceImport[];
15
+ }
16
+ export declare function createJNIHybridObjectRegistration({ hybridObjectName, jniClassName, }: Props): JNIHybridObjectRegistration;
17
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { SourceFile } from '../SourceFile.js';
2
+ import type { StructType } from '../types/StructType.js';
3
+ export declare function createKotlinStruct(structType: StructType): SourceFile[];
@@ -15,7 +15,11 @@ val ${p.escapedName}: ${bridged.getTypeCode('kotlin', false)}
15
15
  `.trim();
16
16
  });
17
17
  let secondaryConstructor;
18
- const needsSpecialHandling = structType.properties.some((p) => new KotlinCxxBridgedType(p).needsSpecialHandling);
18
+ const needsSpecialHandling = structType.properties.some((p) => {
19
+ const bridged = new KotlinCxxBridgedType(p);
20
+ const parseCode = bridged.parseFromKotlinToCpp(p.escapedName, 'kotlin', false);
21
+ return parseCode !== p.escapedName;
22
+ });
19
23
  if (needsSpecialHandling) {
20
24
  // If we need special handling for any of our properties, we need to add a convenience initializer.
21
25
  const params = structType.properties.map((p) => `${p.escapedName}: ${p.getCode('kotlin')}`);
@@ -0,0 +1,3 @@
1
+ import type { SourceFile } from '../SourceFile.js';
2
+ import { type VariantType } from '../types/VariantType.js';
3
+ export declare function createKotlinVariant(variant: VariantType): SourceFile[];
@@ -0,0 +1,21 @@
1
+ import type { BridgedType } from '../BridgedType.js';
2
+ import type { SourceFile, SourceImport } from '../SourceFile.js';
3
+ import type { Type } from '../types/Type.js';
4
+ import { type SwiftCxxHelper } from './SwiftCxxTypeHelper.js';
5
+ import type { Language } from '../../getPlatformSpecs.js';
6
+ export declare class SwiftCxxBridgedType implements BridgedType<'swift', 'c++'> {
7
+ readonly type: Type;
8
+ private readonly isBridgingToDirectCppTarget;
9
+ constructor(type: Type, isBridgingToDirectCppTarget?: boolean);
10
+ get hasType(): boolean;
11
+ get canBePassedByReference(): boolean;
12
+ get needsSpecialHandling(): boolean;
13
+ getRequiredBridge(): SwiftCxxHelper | undefined;
14
+ private getBridgeOrThrow;
15
+ getRequiredImports(language: Language): SourceImport[];
16
+ getExtraFiles(): SourceFile[];
17
+ getTypeCode(language: 'swift' | 'c++'): string;
18
+ parse(parameterName: string, from: 'c++' | 'swift', to: 'swift' | 'c++', inLanguage: 'swift' | 'c++'): string;
19
+ parseFromCppToSwift(cppParameterName: string, language: 'swift' | 'c++'): string;
20
+ parseFromSwiftToCpp(swiftParameterName: string, language: 'swift' | 'c++'): string;
21
+ }
@@ -14,7 +14,7 @@ import { StructType } from '../types/StructType.js';
14
14
  import { TupleType } from '../types/TupleType.js';
15
15
  import { VariantType } from '../types/VariantType.js';
16
16
  import { getReferencedTypes } from '../getReferencedTypes.js';
17
- import { createSwiftCxxHelpers, isPrimitivelyCopyable, } from './SwiftCxxTypeHelper.js';
17
+ import { createSwiftCxxHelpers, } from './SwiftCxxTypeHelper.js';
18
18
  import { createSwiftEnumBridge } from './SwiftEnum.js';
19
19
  import { createSwiftStructBridge } from './SwiftStruct.js';
20
20
  import { createSwiftVariant } from './SwiftVariant.js';
@@ -22,6 +22,7 @@ import { VoidType } from '../types/VoidType.js';
22
22
  import { NamedWrappingType } from '../types/NamedWrappingType.js';
23
23
  import { ErrorType } from '../types/ErrorType.js';
24
24
  import { createSwiftFunctionBridge } from './SwiftFunction.js';
25
+ import { isPrimitivelyCopyable } from './isPrimitivelyCopyable.js';
25
26
  // TODO: Remove enum bridge once Swift fixes bidirectional enums crashing the `-Swift.h` header.
26
27
  export class SwiftCxxBridgedType {
27
28
  type;
@@ -15,4 +15,3 @@ export interface SwiftCxxHelper {
15
15
  dependencies: SwiftCxxHelper[];
16
16
  }
17
17
  export declare function createSwiftCxxHelpers(type: Type): SwiftCxxHelper | undefined;
18
- export declare function isPrimitivelyCopyable(type: Type): boolean;
@@ -17,6 +17,7 @@ import { VoidType } from '../types/VoidType.js';
17
17
  import { NamedWrappingType } from '../types/NamedWrappingType.js';
18
18
  import { ErrorType } from '../types/ErrorType.js';
19
19
  import { ResultWrappingType } from '../types/ResultWrappingType.js';
20
+ import { isPrimitivelyCopyable } from './isPrimitivelyCopyable.js';
20
21
  export function createSwiftCxxHelpers(type) {
21
22
  switch (type.kind) {
22
23
  case 'hybrid-object':
@@ -116,7 +117,7 @@ return ${cxxNamespace}::get_${internalName}(cppType);
116
117
  */
117
118
  using ${name} = ${actualType};
118
119
  ${actualType} create_${name}(void* NON_NULL swiftUnsafePointer) noexcept;
119
- void* NON_NULL get_${name}(${name} cppType) noexcept;
120
+ void* NON_NULL get_${name}(${name} cppType);
120
121
  `.trim(),
121
122
  requiredIncludes: type.getRequiredImports('c++'),
122
123
  },
@@ -125,7 +126,7 @@ void* NON_NULL get_${name}(${name} cppType) noexcept;
125
126
  ${actualType} create_${name}(void* NON_NULL swiftUnsafePointer) noexcept {
126
127
  ${indent(createImplementation, ' ')}
127
128
  }
128
- void* NON_NULL get_${name}(${name} cppType) noexcept {
129
+ void* NON_NULL get_${name}(${name} cppType) {
129
130
  ${indent(getImplementation, ' ')}
130
131
  }
131
132
  `.trim(),
@@ -219,10 +220,6 @@ inline ${wrappedBridge.getTypeCode('c++')} get_${name}(const ${actualType}& opti
219
220
  dependencies: [],
220
221
  };
221
222
  }
222
- export function isPrimitivelyCopyable(type) {
223
- const bridgedType = new SwiftCxxBridgedType(type, true);
224
- return !bridgedType.needsSpecialHandling;
225
- }
226
223
  /**
227
224
  * Creates a C++ `create_vector_T<T>(size)` function that can be called from Swift.
228
225
  */
@@ -0,0 +1,3 @@
1
+ import type { SourceFile } from '../SourceFile.js';
2
+ import type { EnumType } from '../types/EnumType.js';
3
+ export declare function createSwiftEnumBridge(enumType: EnumType): SourceFile;
@@ -0,0 +1,3 @@
1
+ import type { SourceFile } from '../SourceFile.js';
2
+ import type { FunctionType } from '../types/FunctionType.js';
3
+ export declare function createSwiftFunctionBridge(functionType: FunctionType): SourceFile;
@@ -0,0 +1,3 @@
1
+ import type { HybridObjectSpec } from '../HybridObjectSpec.js';
2
+ import type { SourceFile } from '../SourceFile.js';
3
+ export declare function createSwiftHybridObject(spec: HybridObjectSpec): SourceFile[];
@@ -0,0 +1,11 @@
1
+ import type { HybridObjectSpec } from '../HybridObjectSpec.js';
2
+ import type { SourceFile } from '../SourceFile.js';
3
+ /**
4
+ * Creates a Swift class that bridges Swift over to C++.
5
+ * We need this because not all Swift types are accessible in C++, and vice versa.
6
+ *
7
+ * For example, Enums need to be converted to Int32 (because of a Swift compiler bug),
8
+ * Promise<..> has to be converted to a Promise<..>, exceptions have to be handled
9
+ * via custom Result types, etc..
10
+ */
11
+ export declare function createSwiftHybridObjectCxxBridge(spec: HybridObjectSpec): SourceFile[];
@@ -0,0 +1,19 @@
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 Swift class that will be default-constructed
9
+ */
10
+ swiftClassName: string;
11
+ }
12
+ interface SwiftHybridObjectRegistration {
13
+ cppCode: string;
14
+ swiftFunction: string;
15
+ requiredImports: SourceImport[];
16
+ }
17
+ export declare function getHybridObjectConstructorCall(hybridObjectName: string): string;
18
+ export declare function createSwiftHybridObjectRegistration({ hybridObjectName, swiftClassName, }: Props): SwiftHybridObjectRegistration;
19
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { FileWithReferencedTypes } from '../SourceFile.js';
2
+ import { StructType } from '../types/StructType.js';
3
+ export declare function createSwiftStructBridge(struct: StructType): FileWithReferencedTypes;
@@ -0,0 +1,3 @@
1
+ import type { SourceFile } from '../SourceFile.js';
2
+ import type { VariantType } from '../types/VariantType.js';
3
+ export declare function createSwiftVariant(variant: VariantType): SourceFile;
@@ -0,0 +1,7 @@
1
+ import type { Type } from '../types/Type.js';
2
+ /**
3
+ * Returns `true` if the given {@linkcode type} is a datatype that
4
+ * can be copied without running a copy constructor or special logic
5
+ * to copy the data over. In other words; it's _primitively copyable_.
6
+ */
7
+ export declare function isPrimitivelyCopyable(type: Type): boolean;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Returns `true` if the given {@linkcode type} is a datatype that
3
+ * can be copied without running a copy constructor or special logic
4
+ * to copy the data over. In other words; it's _primitively copyable_.
5
+ */
6
+ export function isPrimitivelyCopyable(type) {
7
+ switch (type.kind) {
8
+ case 'number':
9
+ case 'boolean':
10
+ case 'bigint':
11
+ case 'enum':
12
+ case 'null':
13
+ case 'void':
14
+ return true;
15
+ default:
16
+ return false;
17
+ }
18
+ }
@@ -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 ArrayBufferType 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,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 BigIntType 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 BooleanType 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 DateType 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,23 @@
1
+ import { EnumDeclaration } from 'ts-morph';
2
+ import { Type as TSMorphType, type ts } from 'ts-morph';
3
+ import type { Language } from '../../getPlatformSpecs.js';
4
+ import { type SourceFile, type SourceImport } from '../SourceFile.js';
5
+ import type { GetCodeOptions, Type, TypeKind } from './Type.js';
6
+ export interface EnumMember {
7
+ name: string;
8
+ value: number;
9
+ stringValue: string;
10
+ }
11
+ export declare class EnumType implements Type {
12
+ readonly enumName: string;
13
+ readonly enumMembers: EnumMember[];
14
+ readonly jsType: 'enum' | 'union';
15
+ readonly declarationFile: SourceFile;
16
+ constructor(enumName: string, enumDeclaration: EnumDeclaration);
17
+ constructor(enumName: string, union: TSMorphType<ts.UnionType>);
18
+ get canBePassedByReference(): boolean;
19
+ get kind(): TypeKind;
20
+ getCode(language: Language, { fullyQualified }?: GetCodeOptions): string;
21
+ getExtraFiles(): SourceFile[];
22
+ getRequiredImports(language: Language): SourceImport[];
23
+ }
@@ -0,0 +1,11 @@
1
+ import type { Language } from '../../getPlatformSpecs.js';
2
+ import { type SourceFile, type SourceImport } from '../SourceFile.js';
3
+ import type { Type, TypeKind } from './Type.js';
4
+ export declare class ErrorType implements Type {
5
+ constructor();
6
+ get canBePassedByReference(): boolean;
7
+ get kind(): TypeKind;
8
+ getCode(language: Language): string;
9
+ getExtraFiles(): SourceFile[];
10
+ getRequiredImports(language: Language): SourceImport[];
11
+ }
@@ -0,0 +1,29 @@
1
+ import type { Language } from '../../getPlatformSpecs.js';
2
+ import { type SourceFile, type SourceImport } from '../SourceFile.js';
3
+ import type { GetCodeOptions, NamedType, Type, TypeKind } from './Type.js';
4
+ export interface GetFunctionCodeOptions extends GetCodeOptions {
5
+ includeNameInfo?: boolean;
6
+ }
7
+ export declare class FunctionType implements Type {
8
+ readonly returnType: Type;
9
+ readonly parameters: NamedType[];
10
+ constructor(returnType: Type, parameters: NamedType[], isSync?: boolean);
11
+ get specializationName(): string;
12
+ get jsName(): string;
13
+ get canBePassedByReference(): boolean;
14
+ get kind(): TypeKind;
15
+ /**
16
+ * For a function, get the forward recreation of it:
17
+ * If variable is called `func`, this would return:
18
+ * ```cpp
19
+ * [func = std::move(func)](Params... params) -> ReturnType {
20
+ * return func(params...);
21
+ * }
22
+ * ```
23
+ */
24
+ getForwardRecreationCode(variableName: string, language: Language): string;
25
+ getCppFunctionPointerType(name: string, includeNameInfo?: boolean): string;
26
+ getCode(language: Language, options?: GetFunctionCodeOptions): string;
27
+ getExtraFiles(): SourceFile[];
28
+ getRequiredImports(language: Language): SourceImport[];
29
+ }
@@ -0,0 +1,11 @@
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 HybridObjectBaseType implements Type {
5
+ constructor();
6
+ get canBePassedByReference(): boolean;
7
+ get kind(): TypeKind;
8
+ getCode(language: Language): string;
9
+ getExtraFiles(): SourceFile[];
10
+ getRequiredImports(language: Language): SourceImport[];
11
+ }
@@ -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 {};