nitrogen 0.35.3 → 0.35.5

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.
@@ -56,6 +56,8 @@ def add_nitrogen_files(spec)
56
56
  "SWIFT_OBJC_INTEROP_MODE" => "objcxx",
57
57
  # Enables stricter modular headers
58
58
  "DEFINES_MODULE" => "YES",
59
+ # Disable auto-generated ObjC header for Swift (Static linkage on Xcode 26.4 breaks here)
60
+ "SWIFT_INSTALL_OBJC_HEADER" => "NO",
59
61
  })
60
62
  end
61
63
  `.trim();
@@ -32,6 +32,10 @@ val ${name}: ${type.getTypeCode('kotlin', false)}
32
32
  .map((i) => `import ${i.name}`)
33
33
  .filter(isNotDuplicate);
34
34
  const secondaryConstructor = createKotlinConstructor(structType);
35
+ const equalityComparators = structType.properties.map((p) => `Objects.deepEquals(this.${p.escapedName}, other.${p.escapedName})`);
36
+ const propertiesList = structType.properties
37
+ .map((p) => p.escapedName)
38
+ .join(',\n');
35
39
  const code = `
36
40
  ${createFileMetadataString(`${structType.structName}.kt`)}
37
41
 
@@ -39,6 +43,7 @@ package ${packageName}
39
43
 
40
44
  import androidx.annotation.Keep
41
45
  import com.facebook.proguard.annotations.DoNotStrip
46
+ import java.util.Objects
42
47
  ${extraImports.join('\n')}
43
48
 
44
49
  /**
@@ -51,6 +56,18 @@ data class ${structType.structName}(
51
56
  ) {
52
57
  ${indent(secondaryConstructor, ' ')}
53
58
 
59
+ override fun equals(other: Any?): Boolean {
60
+ if (this === other) return true
61
+ if (other !is ${structType.structName}) return false
62
+ return ${equalityComparators.join(`\n && `)}
63
+ }
64
+
65
+ override fun hashCode(): Int {
66
+ return arrayOf(
67
+ ${indent(propertiesList, ' ')}
68
+ ).contentDeepHashCode()
69
+ }
70
+
54
71
  companion object {
55
72
  /**
56
73
  * Constructor called from C++
@@ -48,6 +48,13 @@ fun as${innerName}OrNull(): ${optional.getCode('kotlin')} {
48
48
  const bridge = new KotlinCxxBridgedType(v);
49
49
  return `
50
50
  is ${innerName} -> ${label}(${bridge.parseFromCppToKotlin('value', 'kotlin')})
51
+ `.trim();
52
+ });
53
+ const asCases = variant.cases.map(([label, v]) => {
54
+ const innerName = capitalizeName(label);
55
+ const bridge = new KotlinCxxBridgedType(v);
56
+ return `
57
+ is ${innerName} -> (${bridge.parseFromCppToKotlin('value', 'kotlin')}) as? T
51
58
  `.trim();
52
59
  });
53
60
  const createFunctions = variant.cases.map(([label, v]) => {
@@ -79,16 +86,24 @@ ${extraImports.join('\n')}
79
86
  sealed class ${kotlinName} {
80
87
  ${indent(innerClasses.join('\n'), ' ')}
81
88
 
82
- ${indent(isFunctions.join('\n'), ' ')}
83
-
84
- ${indent(asFunctions.join('\n'), ' ')}
85
-
89
+ inline fun <reified T> asType(): T? {
90
+ return when (this) {
91
+ ${indent(asCases.join('\n'), ' ')}
92
+ }
93
+ }
94
+ inline fun <reified T> isType(): Boolean {
95
+ return asType<T>() != null
96
+ }
86
97
  inline fun <R> match(${matchParameters.join(', ')}): R {
87
98
  return when (this) {
88
99
  ${indent(matchCases.join('\n'), ' ')}
89
100
  }
90
101
  }
91
102
 
103
+ ${indent(isFunctions.join('\n'), ' ')}
104
+
105
+ ${indent(asFunctions.join('\n'), ' ')}
106
+
92
107
  companion object {
93
108
  ${indent(createFunctions.join('\n'), ' ')}
94
109
  }
@@ -29,6 +29,11 @@ export function createSwiftVariant(variant) {
29
29
  return `case ${label}(${type})`;
30
30
  })
31
31
  .join('\n');
32
+ const asCases = variant.cases
33
+ .map(([label]) => {
34
+ return `case .${label}(let value): return value as? T`;
35
+ })
36
+ .join('\n');
32
37
  const jsSignature = variant.variants.map((t) => t.kind).join(' | ');
33
38
  const allPrimitives = variant.variants.every((v) => isPrimitive(v));
34
39
  const enumDeclaration = allPrimitives ? 'enum' : 'indirect enum';
@@ -49,6 +54,17 @@ ${extraImports.join('\n')}
49
54
  public ${enumDeclaration} ${typename} {
50
55
  ${indent(cases, ' ')}
51
56
  }
57
+
58
+ public extension ${typename} {
59
+ func asType<T>(_ type: T.Type = T.self) -> T? {
60
+ switch self {
61
+ ${indent(asCases, ' ')}
62
+ }
63
+ }
64
+ func isType<T>(_ type: T.Type = T.self) -> Bool {
65
+ return self.asType(type) != nil
66
+ }
67
+ }
52
68
  `.trim();
53
69
  return {
54
70
  content: code,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nitrogen",
3
- "version": "0.35.3",
3
+ "version": "0.35.5",
4
4
  "description": "The code-generator for react-native-nitro-modules.",
5
5
  "main": "lib/index",
6
6
  "types": "lib/index.d.ts",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "chalk": "^5.3.0",
38
- "react-native-nitro-modules": "^0.35.3",
38
+ "react-native-nitro-modules": "^0.35.5",
39
39
  "ts-morph": "^27.0.0",
40
40
  "yargs": "^18.0.0",
41
41
  "zod": "^4.0.5"
@@ -63,6 +63,8 @@ def add_nitrogen_files(spec)
63
63
  "SWIFT_OBJC_INTEROP_MODE" => "objcxx",
64
64
  # Enables stricter modular headers
65
65
  "DEFINES_MODULE" => "YES",
66
+ # Disable auto-generated ObjC header for Swift (Static linkage on Xcode 26.4 breaks here)
67
+ "SWIFT_INSTALL_OBJC_HEADER" => "NO",
66
68
  })
67
69
  end
68
70
  `.trim()
@@ -45,6 +45,13 @@ val ${name}: ${type.getTypeCode('kotlin', false)}
45
45
 
46
46
  const secondaryConstructor = createKotlinConstructor(structType)
47
47
 
48
+ const equalityComparators = structType.properties.map(
49
+ (p) => `Objects.deepEquals(this.${p.escapedName}, other.${p.escapedName})`
50
+ )
51
+ const propertiesList = structType.properties
52
+ .map((p) => p.escapedName)
53
+ .join(',\n')
54
+
48
55
  const code = `
49
56
  ${createFileMetadataString(`${structType.structName}.kt`)}
50
57
 
@@ -52,6 +59,7 @@ package ${packageName}
52
59
 
53
60
  import androidx.annotation.Keep
54
61
  import com.facebook.proguard.annotations.DoNotStrip
62
+ import java.util.Objects
55
63
  ${extraImports.join('\n')}
56
64
 
57
65
  /**
@@ -64,6 +72,18 @@ data class ${structType.structName}(
64
72
  ) {
65
73
  ${indent(secondaryConstructor, ' ')}
66
74
 
75
+ override fun equals(other: Any?): Boolean {
76
+ if (this === other) return true
77
+ if (other !is ${structType.structName}) return false
78
+ return ${equalityComparators.join(`\n && `)}
79
+ }
80
+
81
+ override fun hashCode(): Int {
82
+ return arrayOf(
83
+ ${indent(propertiesList, ' ')}
84
+ ).contentDeepHashCode()
85
+ }
86
+
67
87
  companion object {
68
88
  /**
69
89
  * Constructor called from C++
@@ -58,6 +58,13 @@ fun as${innerName}OrNull(): ${optional.getCode('kotlin')} {
58
58
  is ${innerName} -> ${label}(${bridge.parseFromCppToKotlin('value', 'kotlin')})
59
59
  `.trim()
60
60
  })
61
+ const asCases = variant.cases.map(([label, v]) => {
62
+ const innerName = capitalizeName(label)
63
+ const bridge = new KotlinCxxBridgedType(v)
64
+ return `
65
+ is ${innerName} -> (${bridge.parseFromCppToKotlin('value', 'kotlin')}) as? T
66
+ `.trim()
67
+ })
61
68
 
62
69
  const createFunctions = variant.cases.map(([label, v]) => {
63
70
  const bridge = new KotlinCxxBridgedType(v)
@@ -90,16 +97,24 @@ ${extraImports.join('\n')}
90
97
  sealed class ${kotlinName} {
91
98
  ${indent(innerClasses.join('\n'), ' ')}
92
99
 
93
- ${indent(isFunctions.join('\n'), ' ')}
94
-
95
- ${indent(asFunctions.join('\n'), ' ')}
96
-
100
+ inline fun <reified T> asType(): T? {
101
+ return when (this) {
102
+ ${indent(asCases.join('\n'), ' ')}
103
+ }
104
+ }
105
+ inline fun <reified T> isType(): Boolean {
106
+ return asType<T>() != null
107
+ }
97
108
  inline fun <R> match(${matchParameters.join(', ')}): R {
98
109
  return when (this) {
99
110
  ${indent(matchCases.join('\n'), ' ')}
100
111
  }
101
112
  }
102
113
 
114
+ ${indent(isFunctions.join('\n'), ' ')}
115
+
116
+ ${indent(asFunctions.join('\n'), ' ')}
117
+
103
118
  companion object {
104
119
  ${indent(createFunctions.join('\n'), ' ')}
105
120
  }
@@ -34,6 +34,12 @@ export function createSwiftVariant(variant: VariantType): SourceFile {
34
34
  return `case ${label}(${type})`
35
35
  })
36
36
  .join('\n')
37
+ const asCases = variant.cases
38
+ .map(([label]) => {
39
+ return `case .${label}(let value): return value as? T`
40
+ })
41
+ .join('\n')
42
+
37
43
  const jsSignature = variant.variants.map((t) => t.kind).join(' | ')
38
44
 
39
45
  const allPrimitives = variant.variants.every((v) => isPrimitive(v))
@@ -57,6 +63,17 @@ ${extraImports.join('\n')}
57
63
  public ${enumDeclaration} ${typename} {
58
64
  ${indent(cases, ' ')}
59
65
  }
66
+
67
+ public extension ${typename} {
68
+ func asType<T>(_ type: T.Type = T.self) -> T? {
69
+ switch self {
70
+ ${indent(asCases, ' ')}
71
+ }
72
+ }
73
+ func isType<T>(_ type: T.Type = T.self) -> Bool {
74
+ return self.asType(type) != nil
75
+ }
76
+ }
60
77
  `.trim()
61
78
 
62
79
  return {