nitrogen 0.2.23 → 0.29.4

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 (333) hide show
  1. package/README.md +15 -109
  2. package/lib/Logger.d.ts +10 -0
  3. package/lib/Logger.js +56 -0
  4. package/lib/autolinking/Autolinking.d.ts +8 -0
  5. package/lib/autolinking/Autolinking.js +1 -0
  6. package/lib/autolinking/android/createCMakeExtension.d.ts +6 -0
  7. package/lib/autolinking/android/createCMakeExtension.js +106 -0
  8. package/lib/autolinking/android/createGradleExtension.d.ts +5 -0
  9. package/lib/autolinking/android/createGradleExtension.js +36 -0
  10. package/lib/autolinking/android/createHybridObjectInitializer.d.ts +2 -0
  11. package/lib/autolinking/android/createHybridObjectInitializer.js +159 -0
  12. package/lib/autolinking/createAndroidAutolinking.d.ts +11 -0
  13. package/lib/autolinking/createAndroidAutolinking.js +13 -0
  14. package/lib/autolinking/createIOSAutolinking.d.ts +5 -0
  15. package/lib/autolinking/createIOSAutolinking.js +19 -0
  16. package/lib/autolinking/ios/createHybridObjectInitializer.d.ts +9 -0
  17. package/lib/autolinking/ios/createHybridObjectInitializer.js +97 -0
  18. package/lib/autolinking/ios/createPodspecRubyExtension.d.ts +5 -0
  19. package/lib/autolinking/ios/createPodspecRubyExtension.js +69 -0
  20. package/lib/autolinking/ios/createSwiftCxxBridge.d.ts +2 -0
  21. package/lib/autolinking/ios/createSwiftCxxBridge.js +117 -0
  22. package/lib/autolinking/ios/createSwiftUmbrellaHeader.d.ts +3 -0
  23. package/lib/autolinking/ios/createSwiftUmbrellaHeader.js +74 -0
  24. package/lib/config/NitroConfig.d.ts +52 -0
  25. package/lib/config/NitroConfig.js +112 -0
  26. package/lib/config/NitroUserConfig.d.ts +22 -0
  27. package/lib/config/NitroUserConfig.js +88 -0
  28. package/lib/config/getConfig.d.ts +2 -0
  29. package/lib/config/getConfig.js +84 -0
  30. package/lib/createGitAttributes.d.ts +1 -0
  31. package/lib/createGitAttributes.js +11 -0
  32. package/lib/createPlatformSpec.d.ts +4 -0
  33. package/lib/createPlatformSpec.js +127 -0
  34. package/lib/getFiles.d.ts +1 -0
  35. package/lib/getFiles.js +28 -0
  36. package/lib/getPlatformSpecs.d.ts +17 -0
  37. package/lib/getPlatformSpecs.js +153 -0
  38. package/lib/index.d.ts +2 -0
  39. package/lib/index.js +113 -10
  40. package/lib/init.d.ts +1 -0
  41. package/lib/init.js +123 -0
  42. package/lib/nitrogen.d.ts +11 -0
  43. package/lib/nitrogen.js +165 -0
  44. package/lib/prettifyDirectory.d.ts +1 -0
  45. package/lib/prettifyDirectory.js +27 -0
  46. package/lib/syntax/BridgedType.d.ts +41 -0
  47. package/lib/syntax/BridgedType.js +1 -0
  48. package/lib/syntax/CodeNode.d.ts +23 -0
  49. package/lib/syntax/CodeNode.js +1 -0
  50. package/lib/syntax/HybridObjectSpec.d.ts +13 -0
  51. package/lib/syntax/HybridObjectSpec.js +1 -0
  52. package/lib/syntax/Method.d.ts +41 -0
  53. package/lib/syntax/Method.js +108 -0
  54. package/lib/syntax/Parameter.d.ts +15 -0
  55. package/lib/syntax/Parameter.js +65 -0
  56. package/lib/syntax/Property.d.ts +50 -0
  57. package/lib/syntax/Property.js +147 -0
  58. package/lib/syntax/SourceFile.d.ts +70 -0
  59. package/lib/syntax/SourceFile.js +7 -0
  60. package/lib/syntax/c++/CppEnum.d.ts +6 -0
  61. package/lib/syntax/c++/CppEnum.js +110 -0
  62. package/lib/syntax/c++/CppHybridObject.d.ts +3 -0
  63. package/lib/syntax/c++/CppHybridObject.js +146 -0
  64. package/lib/syntax/c++/CppHybridObjectRegistration.d.ts +17 -0
  65. package/lib/syntax/c++/CppHybridObjectRegistration.js +18 -0
  66. package/lib/syntax/c++/CppStruct.d.ts +3 -0
  67. package/lib/syntax/c++/CppStruct.js +108 -0
  68. package/lib/syntax/c++/CppUnion.d.ts +6 -0
  69. package/lib/syntax/c++/CppUnion.js +88 -0
  70. package/lib/syntax/c++/getForwardDeclaration.d.ts +3 -0
  71. package/lib/syntax/c++/getForwardDeclaration.js +14 -0
  72. package/lib/syntax/c++/includeNitroHeader.d.ts +7 -0
  73. package/lib/syntax/c++/includeNitroHeader.js +34 -0
  74. package/lib/syntax/createType.d.ts +15 -0
  75. package/lib/syntax/createType.js +303 -0
  76. package/lib/syntax/getAllTypes.d.ts +3 -0
  77. package/lib/syntax/getAllTypes.js +11 -0
  78. package/lib/syntax/getCustomTypeConfig.d.ts +8 -0
  79. package/lib/syntax/getCustomTypeConfig.js +53 -0
  80. package/lib/syntax/getHybridObjectName.d.ts +36 -0
  81. package/lib/syntax/getHybridObjectName.js +10 -0
  82. package/lib/syntax/getInterfaceProperties.d.ts +4 -0
  83. package/lib/syntax/getInterfaceProperties.js +9 -0
  84. package/lib/syntax/getReferencedTypes.d.ts +2 -0
  85. package/lib/syntax/getReferencedTypes.js +47 -0
  86. package/lib/syntax/helpers.d.ts +13 -0
  87. package/lib/syntax/helpers.js +53 -0
  88. package/lib/syntax/isCoreType.d.ts +9 -0
  89. package/lib/syntax/isCoreType.js +47 -0
  90. package/lib/syntax/kotlin/FbjniHybridObject.d.ts +3 -0
  91. package/lib/syntax/kotlin/FbjniHybridObject.js +261 -0
  92. package/lib/syntax/kotlin/JNINativeRegistrations.d.ts +8 -0
  93. package/lib/syntax/kotlin/JNINativeRegistrations.js +7 -0
  94. package/lib/syntax/kotlin/KotlinBoxedPrimitive.d.ts +7 -0
  95. package/lib/syntax/kotlin/KotlinBoxedPrimitive.js +17 -0
  96. package/lib/syntax/kotlin/KotlinCxxBridgedType.d.ts +19 -0
  97. package/lib/syntax/kotlin/KotlinCxxBridgedType.js +893 -0
  98. package/lib/syntax/kotlin/KotlinEnum.d.ts +3 -0
  99. package/lib/syntax/kotlin/KotlinEnum.js +113 -0
  100. package/lib/syntax/kotlin/KotlinFunction.d.ts +3 -0
  101. package/lib/syntax/kotlin/KotlinFunction.js +256 -0
  102. package/lib/syntax/kotlin/KotlinHybridObject.d.ts +3 -0
  103. package/lib/syntax/kotlin/KotlinHybridObject.js +177 -0
  104. package/lib/syntax/kotlin/KotlinHybridObjectRegistration.d.ts +17 -0
  105. package/lib/syntax/kotlin/KotlinHybridObjectRegistration.js +26 -0
  106. package/lib/syntax/kotlin/KotlinStruct.d.ts +3 -0
  107. package/lib/syntax/kotlin/KotlinStruct.js +172 -0
  108. package/lib/syntax/kotlin/KotlinVariant.d.ts +3 -0
  109. package/lib/syntax/kotlin/KotlinVariant.js +191 -0
  110. package/lib/syntax/swift/SwiftCxxBridgedType.d.ts +21 -0
  111. package/lib/syntax/swift/SwiftCxxBridgedType.js +819 -0
  112. package/lib/syntax/swift/SwiftCxxTypeHelper.d.ts +17 -0
  113. package/lib/syntax/swift/SwiftCxxTypeHelper.js +613 -0
  114. package/lib/syntax/swift/SwiftEnum.d.ts +3 -0
  115. package/lib/syntax/swift/SwiftEnum.js +52 -0
  116. package/lib/syntax/swift/SwiftFunction.d.ts +3 -0
  117. package/lib/syntax/swift/SwiftFunction.js +83 -0
  118. package/lib/syntax/swift/SwiftHybridObject.d.ts +3 -0
  119. package/lib/syntax/swift/SwiftHybridObject.js +103 -0
  120. package/lib/syntax/swift/SwiftHybridObjectBridge.d.ts +11 -0
  121. package/lib/syntax/swift/SwiftHybridObjectBridge.js +451 -0
  122. package/lib/syntax/swift/SwiftHybridObjectRegistration.d.ts +19 -0
  123. package/lib/syntax/swift/SwiftHybridObjectRegistration.js +42 -0
  124. package/lib/syntax/swift/SwiftStruct.d.ts +3 -0
  125. package/lib/syntax/swift/SwiftStruct.js +75 -0
  126. package/lib/syntax/swift/SwiftVariant.d.ts +3 -0
  127. package/lib/syntax/swift/SwiftVariant.js +58 -0
  128. package/lib/syntax/types/ArrayBufferType.d.ts +10 -0
  129. package/lib/syntax/types/ArrayBufferType.js +37 -0
  130. package/lib/syntax/types/ArrayType.d.ts +12 -0
  131. package/lib/syntax/types/ArrayType.js +52 -0
  132. package/lib/syntax/types/BigIntType.d.ts +10 -0
  133. package/lib/syntax/types/BigIntType.js +27 -0
  134. package/lib/syntax/types/BooleanType.d.ts +10 -0
  135. package/lib/syntax/types/BooleanType.js +27 -0
  136. package/lib/syntax/types/CustomType.d.ts +14 -0
  137. package/lib/syntax/types/CustomType.js +36 -0
  138. package/lib/syntax/types/DateType.d.ts +10 -0
  139. package/lib/syntax/types/DateType.js +35 -0
  140. package/lib/syntax/types/EnumType.d.ts +23 -0
  141. package/lib/syntax/types/EnumType.js +101 -0
  142. package/lib/syntax/types/ErrorType.d.ts +11 -0
  143. package/lib/syntax/types/ErrorType.js +37 -0
  144. package/lib/syntax/types/FunctionType.d.ts +29 -0
  145. package/lib/syntax/types/FunctionType.js +147 -0
  146. package/lib/syntax/types/HybridObjectBaseType.d.ts +11 -0
  147. package/lib/syntax/types/HybridObjectBaseType.js +38 -0
  148. package/lib/syntax/types/HybridObjectType.d.ts +23 -0
  149. package/lib/syntax/types/HybridObjectType.js +131 -0
  150. package/lib/syntax/types/MapType.d.ts +10 -0
  151. package/lib/syntax/types/MapType.js +37 -0
  152. package/lib/syntax/types/NamedWrappingType.d.ts +14 -0
  153. package/lib/syntax/types/NamedWrappingType.js +27 -0
  154. package/lib/syntax/types/NullType.d.ts +10 -0
  155. package/lib/syntax/types/NullType.js +23 -0
  156. package/lib/syntax/types/NumberType.d.ts +10 -0
  157. package/lib/syntax/types/NumberType.js +27 -0
  158. package/lib/syntax/types/OptionalType.d.ts +13 -0
  159. package/lib/syntax/types/OptionalType.js +59 -0
  160. package/lib/syntax/types/PromiseType.d.ts +16 -0
  161. package/lib/syntax/types/PromiseType.js +62 -0
  162. package/lib/syntax/types/RecordType.d.ts +13 -0
  163. package/lib/syntax/types/RecordType.js +47 -0
  164. package/lib/syntax/types/ResultWrappingType.d.ts +13 -0
  165. package/lib/syntax/types/ResultWrappingType.js +44 -0
  166. package/lib/syntax/types/StringType.d.ts +10 -0
  167. package/lib/syntax/types/StringType.js +35 -0
  168. package/lib/syntax/types/StructType.d.ts +14 -0
  169. package/lib/syntax/types/StructType.js +61 -0
  170. package/lib/syntax/types/TupleType.d.ts +12 -0
  171. package/lib/syntax/types/TupleType.js +39 -0
  172. package/lib/syntax/types/Type.d.ts +55 -0
  173. package/lib/syntax/types/Type.js +1 -0
  174. package/lib/syntax/types/VariantType.d.ts +19 -0
  175. package/lib/syntax/types/VariantType.js +75 -0
  176. package/lib/syntax/types/VoidType.d.ts +10 -0
  177. package/lib/syntax/types/VoidType.js +27 -0
  178. package/lib/syntax/types/getTypeAs.d.ts +2 -0
  179. package/lib/syntax/types/getTypeAs.js +12 -0
  180. package/lib/utils.d.ts +22 -0
  181. package/lib/utils.js +126 -0
  182. package/lib/views/CppHybridViewComponent.d.ts +14 -0
  183. package/lib/views/CppHybridViewComponent.js +254 -0
  184. package/lib/views/createHostComponentJs.d.ts +3 -0
  185. package/lib/views/createHostComponentJs.js +27 -0
  186. package/lib/views/kotlin/KotlinHybridViewManager.d.ts +3 -0
  187. package/lib/views/kotlin/KotlinHybridViewManager.js +229 -0
  188. package/lib/views/swift/SwiftHybridViewManager.d.ts +3 -0
  189. package/lib/views/swift/SwiftHybridViewManager.js +131 -0
  190. package/lib/writeFile.d.ts +5 -0
  191. package/lib/writeFile.js +19 -0
  192. package/package.json +58 -29
  193. package/src/Logger.ts +63 -0
  194. package/src/autolinking/Autolinking.ts +9 -0
  195. package/src/autolinking/android/createCMakeExtension.ts +123 -0
  196. package/src/autolinking/android/createGradleExtension.ts +43 -0
  197. package/src/autolinking/android/createHybridObjectInitializer.ts +174 -0
  198. package/src/autolinking/createAndroidAutolinking.ts +28 -0
  199. package/src/autolinking/createIOSAutolinking.ts +24 -0
  200. package/src/autolinking/ios/createHybridObjectInitializer.ts +112 -0
  201. package/src/autolinking/ios/createPodspecRubyExtension.ts +76 -0
  202. package/src/autolinking/ios/createSwiftCxxBridge.ts +137 -0
  203. package/src/autolinking/ios/createSwiftUmbrellaHeader.ts +90 -0
  204. package/src/config/NitroConfig.ts +139 -0
  205. package/src/config/NitroUserConfig.ts +105 -0
  206. package/src/config/getConfig.ts +91 -0
  207. package/src/createGitAttributes.ts +15 -0
  208. package/src/createPlatformSpec.ts +176 -0
  209. package/src/getFiles.ts +31 -0
  210. package/src/getPlatformSpecs.ts +202 -0
  211. package/src/index.ts +146 -0
  212. package/src/init.ts +186 -0
  213. package/src/nitrogen.ts +246 -0
  214. package/src/prettifyDirectory.ts +32 -0
  215. package/src/syntax/BridgedType.ts +59 -0
  216. package/src/syntax/CodeNode.ts +24 -0
  217. package/src/syntax/HybridObjectSpec.ts +14 -0
  218. package/src/syntax/Method.ts +154 -0
  219. package/src/syntax/Parameter.ts +81 -0
  220. package/src/syntax/Property.ts +203 -0
  221. package/src/syntax/SourceFile.ts +80 -0
  222. package/src/syntax/c++/CppEnum.ts +128 -0
  223. package/src/syntax/c++/CppHybridObject.ts +165 -0
  224. package/src/syntax/c++/CppHybridObjectRegistration.ts +39 -0
  225. package/src/syntax/c++/CppStruct.ts +129 -0
  226. package/src/syntax/c++/CppUnion.ts +105 -0
  227. package/src/syntax/c++/getForwardDeclaration.ts +19 -0
  228. package/src/syntax/c++/includeNitroHeader.ts +40 -0
  229. package/src/syntax/createType.ts +365 -0
  230. package/src/syntax/getAllTypes.ts +18 -0
  231. package/src/syntax/getCustomTypeConfig.ts +71 -0
  232. package/src/syntax/getHybridObjectName.ts +48 -0
  233. package/src/syntax/getInterfaceProperties.ts +21 -0
  234. package/src/syntax/getReferencedTypes.ts +57 -0
  235. package/src/syntax/helpers.ts +79 -0
  236. package/src/syntax/isCoreType.ts +60 -0
  237. package/src/syntax/kotlin/FbjniHybridObject.ts +313 -0
  238. package/src/syntax/kotlin/JNINativeRegistrations.ts +19 -0
  239. package/src/syntax/kotlin/KotlinBoxedPrimitive.ts +19 -0
  240. package/src/syntax/kotlin/KotlinCxxBridgedType.ts +942 -0
  241. package/src/syntax/kotlin/KotlinEnum.ts +130 -0
  242. package/src/syntax/kotlin/KotlinFunction.ts +277 -0
  243. package/src/syntax/kotlin/KotlinHybridObject.ts +205 -0
  244. package/src/syntax/kotlin/KotlinHybridObjectRegistration.ts +51 -0
  245. package/src/syntax/kotlin/KotlinStruct.ts +198 -0
  246. package/src/syntax/kotlin/KotlinVariant.ts +212 -0
  247. package/src/syntax/swift/SwiftCxxBridgedType.ts +874 -0
  248. package/src/syntax/swift/SwiftCxxTypeHelper.ts +674 -0
  249. package/src/syntax/swift/SwiftEnum.ts +65 -0
  250. package/src/syntax/swift/SwiftFunction.ts +91 -0
  251. package/src/syntax/swift/SwiftHybridObject.ts +121 -0
  252. package/src/syntax/swift/SwiftHybridObjectBridge.ts +522 -0
  253. package/src/syntax/swift/SwiftHybridObjectRegistration.ts +75 -0
  254. package/src/syntax/swift/SwiftStruct.ts +85 -0
  255. package/src/syntax/swift/SwiftVariant.ts +67 -0
  256. package/src/syntax/types/ArrayBufferType.ts +49 -0
  257. package/src/syntax/types/ArrayType.ts +62 -0
  258. package/src/syntax/types/BigIntType.ts +35 -0
  259. package/src/syntax/types/BooleanType.ts +35 -0
  260. package/src/syntax/types/CustomType.ts +47 -0
  261. package/src/syntax/types/DateType.ts +43 -0
  262. package/src/syntax/types/EnumType.ts +130 -0
  263. package/src/syntax/types/ErrorType.ts +44 -0
  264. package/src/syntax/types/FunctionType.ts +167 -0
  265. package/src/syntax/types/HybridObjectBaseType.ts +54 -0
  266. package/src/syntax/types/HybridObjectType.ts +198 -0
  267. package/src/syntax/types/MapType.ts +49 -0
  268. package/src/syntax/types/NamedWrappingType.ts +33 -0
  269. package/src/syntax/types/NullType.ts +30 -0
  270. package/src/syntax/types/NumberType.ts +34 -0
  271. package/src/syntax/types/OptionalType.ts +66 -0
  272. package/src/syntax/types/PromiseType.ts +72 -0
  273. package/src/syntax/types/RecordType.ts +56 -0
  274. package/src/syntax/types/ResultWrappingType.ts +53 -0
  275. package/src/syntax/types/StringType.ts +44 -0
  276. package/src/syntax/types/StructType.ts +83 -0
  277. package/src/syntax/types/TupleType.ts +53 -0
  278. package/src/syntax/types/Type.ts +82 -0
  279. package/src/syntax/types/VariantType.ts +92 -0
  280. package/src/syntax/types/VoidType.ts +34 -0
  281. package/src/syntax/types/getTypeAs.ts +15 -0
  282. package/src/utils.ts +162 -0
  283. package/src/views/CppHybridViewComponent.ts +301 -0
  284. package/src/views/createHostComponentJs.ts +34 -0
  285. package/src/views/kotlin/KotlinHybridViewManager.ts +258 -0
  286. package/src/views/swift/SwiftHybridViewManager.ts +153 -0
  287. package/src/writeFile.ts +27 -0
  288. package/.jshintignore +0 -6
  289. package/.jshintrc +0 -3
  290. package/.npmignore +0 -3
  291. package/.travis.yml +0 -13
  292. package/LICENSE +0 -13
  293. package/browser/nitrogen-min.js +0 -3
  294. package/browser/nitrogen.js +0 -6369
  295. package/lib/apiKey.js +0 -67
  296. package/lib/blob.js +0 -57
  297. package/lib/commandManager.js +0 -350
  298. package/lib/device.js +0 -19
  299. package/lib/memoryStore.js +0 -24
  300. package/lib/message.js +0 -298
  301. package/lib/permission.js +0 -121
  302. package/lib/principal.js +0 -330
  303. package/lib/service.js +0 -349
  304. package/lib/session.js +0 -494
  305. package/lib/user.js +0 -20
  306. package/publish +0 -2
  307. package/scripts/build-documentation +0 -4
  308. package/scripts/build-module +0 -27
  309. package/scripts/module.js +0 -12
  310. package/scripts/postamble.js +0 -1
  311. package/scripts/preamble.js +0 -2
  312. package/scripts/run-test-server +0 -9
  313. package/test/config.js +0 -12
  314. package/test/fixtures/images/image.jpg +0 -0
  315. package/test/fixtures/images/motion0.jpg +0 -0
  316. package/test/fixtures/images/motion1.jpg +0 -0
  317. package/test/fixtures/images/motion2.jpg +0 -0
  318. package/test/fixtures/index.js +0 -76
  319. package/test/main.js +0 -5
  320. package/test/memoryStore.js +0 -22
  321. package/test/mocha.opts +0 -3
  322. package/test/units/apiKey.js +0 -46
  323. package/test/units/blob.js +0 -35
  324. package/test/units/commandManager.js +0 -67
  325. package/test/units/device.js +0 -26
  326. package/test/units/heartbeat.js +0 -28
  327. package/test/units/message.js +0 -79
  328. package/test/units/permissions.js +0 -43
  329. package/test/units/principal.js +0 -116
  330. package/test/units/service.js +0 -92
  331. package/test/units/session.js +0 -97
  332. package/test/units/user.js +0 -48
  333. package/yuidoc.json +0 -8
@@ -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,147 @@
1
+ import { capitalizeName } from '../utils.js';
2
+ import {} from './SourceFile.js';
3
+ import { Method } from './Method.js';
4
+ import { VoidType } from './types/VoidType.js';
5
+ import { Parameter } from './Parameter.js';
6
+ import { isBooleanPropertyPrefix } from './helpers.js';
7
+ export class Property {
8
+ name;
9
+ type;
10
+ isReadonly;
11
+ constructor(name, type, isReadonly) {
12
+ this.name = name;
13
+ this.type = type;
14
+ this.isReadonly = isReadonly;
15
+ if (this.name.startsWith('__')) {
16
+ throw new Error(`Property names are not allowed to start with two underscores (__)! (In ${this.jsSignature})`);
17
+ }
18
+ }
19
+ get jsSignature() {
20
+ return `${this.name}: ${this.type.kind}`;
21
+ }
22
+ getExtraFiles() {
23
+ return this.type.getExtraFiles();
24
+ }
25
+ getRequiredImports(language) {
26
+ return this.type.getRequiredImports(language);
27
+ }
28
+ getGetterName(environment) {
29
+ if (this.type.kind === 'boolean' && isBooleanPropertyPrefix(this.name)) {
30
+ // Boolean accessors where the property starts with "is" or "has" are renamed in JVM and Swift
31
+ switch (environment) {
32
+ case 'jvm':
33
+ case 'swift':
34
+ // isSomething -> isSomething()
35
+ return this.name;
36
+ default:
37
+ break;
38
+ }
39
+ }
40
+ // isSomething -> getIsSomething()
41
+ return `get${capitalizeName(this.name)}`;
42
+ }
43
+ getSetterName(environment) {
44
+ if (this.type.kind === 'boolean' && this.name.startsWith('is')) {
45
+ // Boolean accessors where the property starts with "is" are renamed in JVM
46
+ if (environment === 'jvm') {
47
+ // isSomething -> setSomething()
48
+ const cleanName = this.name.replace('is', '');
49
+ return `set${capitalizeName(cleanName)}`;
50
+ }
51
+ }
52
+ // isSomething -> setIsSomething()
53
+ return `set${capitalizeName(this.name)}`;
54
+ }
55
+ get cppGetter() {
56
+ return new Method(this.getGetterName('other'), this.type, []);
57
+ }
58
+ get cppSetter() {
59
+ if (this.isReadonly)
60
+ return undefined;
61
+ const parameter = new Parameter(this.name, this.type);
62
+ return new Method(this.getSetterName('other'), new VoidType(), [parameter]);
63
+ }
64
+ getCppMethods() {
65
+ if (this.cppSetter != null) {
66
+ // get + set
67
+ return [this.cppGetter, this.cppSetter];
68
+ }
69
+ else {
70
+ // get
71
+ return [this.cppGetter];
72
+ }
73
+ }
74
+ getCode(language, modifiers, body) {
75
+ if (body != null) {
76
+ body.getter = body.getter.trim();
77
+ body.setter = body.setter.trim();
78
+ }
79
+ switch (language) {
80
+ case 'c++': {
81
+ const methods = this.getCppMethods();
82
+ const [getter, setter] = methods;
83
+ const lines = [];
84
+ lines.push(getter.getCode('c++', modifiers, body?.getter));
85
+ if (setter != null) {
86
+ lines.push(setter.getCode('c++', modifiers, body?.setter));
87
+ }
88
+ return lines.join('\n');
89
+ }
90
+ case 'swift': {
91
+ const type = this.type.getCode('swift');
92
+ let accessors;
93
+ if (body == null) {
94
+ accessors = this.isReadonly ? `get` : `get set`;
95
+ }
96
+ else {
97
+ const lines = [];
98
+ lines.push(`
99
+ get {
100
+ ${body.getter}
101
+ }
102
+ `);
103
+ if (!this.isReadonly) {
104
+ lines.push(`
105
+ set {
106
+ ${body.setter}
107
+ }
108
+ `);
109
+ }
110
+ accessors = '\n' + lines.join('\n') + '\n';
111
+ }
112
+ return `var ${this.name}: ${type} { ${accessors} }`;
113
+ }
114
+ case 'kotlin': {
115
+ const type = this.type.getCode('kotlin');
116
+ let keyword = this.isReadonly ? 'val' : 'var';
117
+ if (modifiers?.virtual)
118
+ keyword = `abstract ${keyword}`;
119
+ const lines = [];
120
+ if (modifiers?.doNotStrip) {
121
+ lines.push('@get:DoNotStrip', '@get:Keep');
122
+ if (!this.isReadonly) {
123
+ lines.push('@set:DoNotStrip', '@set:Keep');
124
+ }
125
+ }
126
+ lines.push(`${keyword} ${this.name}: ${type}`);
127
+ if (body != null) {
128
+ lines.push(`
129
+ get() {
130
+ ${body.getter}
131
+ }
132
+ `);
133
+ if (!this.isReadonly) {
134
+ lines.push(`
135
+ set(value) {
136
+ ${body.setter}
137
+ }
138
+ `);
139
+ }
140
+ }
141
+ return lines.join('\n');
142
+ }
143
+ default:
144
+ throw new Error(`Language ${language} is not yet supported for properties!`);
145
+ }
146
+ }
147
+ }
@@ -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,7 @@
1
+ export function groupByPlatform(files) {
2
+ const result = { shared: [], ios: [], android: [] };
3
+ for (const file of files) {
4
+ result[file.platform].push(file);
5
+ }
6
+ return result;
7
+ }
@@ -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,110 @@
1
+ import { NitroConfig } from '../../config/NitroConfig.js';
2
+ import { indent, toLowerCamelCase } from '../../utils.js';
3
+ import { createFileMetadataString } from '../helpers.js';
4
+ import { includeNitroHeader } from './includeNitroHeader.js';
5
+ function getEnumMinValue(enumMembers) {
6
+ return Math.min(...enumMembers.map((m) => m.value));
7
+ }
8
+ function getEnumMaxValue(enumMembers) {
9
+ return Math.max(...enumMembers.map((m) => m.value));
10
+ }
11
+ function isIncrementingEnum(enumMembers) {
12
+ let lastValue = getEnumMinValue(enumMembers) - 1;
13
+ for (const enumMember of enumMembers) {
14
+ if (enumMember.value !== lastValue + 1) {
15
+ // it is not just one higher than the last value!
16
+ return false;
17
+ }
18
+ lastValue = enumMember.value;
19
+ }
20
+ // all enum values were incrementing!
21
+ return true;
22
+ }
23
+ /**
24
+ * Creates a C++ enum that converts to a JS enum (aka just int)
25
+ */
26
+ export function createCppEnum(typename, enumMembers) {
27
+ // Namespace typename
28
+ const fullyQualifiedTypename = NitroConfig.current.getCxxNamespace('c++', typename);
29
+ // Map enum to C++ code
30
+ const cppEnumMembers = enumMembers
31
+ .map((m) => `${m.name} SWIFT_NAME(${toLowerCamelCase(m.name)}) = ${m.value},`)
32
+ .join('\n');
33
+ const cxxNamespace = NitroConfig.current.getCxxNamespace('c++');
34
+ let isInsideValidValues;
35
+ if (isIncrementingEnum(enumMembers)) {
36
+ // It's just incrementing one after another, so we can simplify this to a bounds check
37
+ const minValue = getEnumMinValue(enumMembers);
38
+ const maxValue = getEnumMaxValue(enumMembers);
39
+ isInsideValidValues = `
40
+ // Check if we are within the bounds of the enum.
41
+ return integer >= ${minValue} && integer <= ${maxValue};
42
+ `.trim();
43
+ }
44
+ else {
45
+ const cases = enumMembers.map((m) => `case ${m.value} /* ${m.name} */: return true;`);
46
+ isInsideValidValues = `
47
+ switch (integer) {
48
+ ${indent(cases.join('\n'), ' ')}
49
+ default: return false;
50
+ }
51
+ `.trim();
52
+ }
53
+ // Create entire C++ file
54
+ const cppCode = `
55
+ ${createFileMetadataString(`${typename}.hpp`)}
56
+
57
+ #pragma once
58
+
59
+ ${includeNitroHeader('JSIConverter.hpp')}
60
+ ${includeNitroHeader('NitroDefines.hpp')}
61
+
62
+ namespace ${cxxNamespace} {
63
+
64
+ /**
65
+ * An enum which can be represented as a JavaScript enum (${typename}).
66
+ */
67
+ enum class ${typename} {
68
+ ${indent(cppEnumMembers, ' ')}
69
+ } CLOSED_ENUM;
70
+
71
+ } // namespace ${cxxNamespace}
72
+
73
+ namespace margelo::nitro {
74
+
75
+ // C++ ${typename} <> JS ${typename} (enum)
76
+ template <>
77
+ struct JSIConverter<${fullyQualifiedTypename}> final {
78
+ static inline ${fullyQualifiedTypename} fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
79
+ int enumValue = JSIConverter<int>::fromJSI(runtime, arg);
80
+ return static_cast<${fullyQualifiedTypename}>(enumValue);
81
+ }
82
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, ${fullyQualifiedTypename} arg) {
83
+ int enumValue = static_cast<int>(arg);
84
+ return JSIConverter<int>::toJSI(runtime, enumValue);
85
+ }
86
+ static inline bool canConvert(jsi::Runtime&, const jsi::Value& value) {
87
+ if (!value.isNumber()) {
88
+ return false;
89
+ }
90
+ double number = value.getNumber();
91
+ int integer = static_cast<int>(number);
92
+ if (number != integer) {
93
+ // The integer is not the same value as the double - we truncated floating points.
94
+ // Enums are all integers, so the input floating point number is obviously invalid.
95
+ return false;
96
+ }
97
+ ${indent(isInsideValidValues, ' ')}
98
+ }
99
+ };
100
+
101
+ } // namespace margelo::nitro
102
+ `;
103
+ return {
104
+ content: cppCode,
105
+ subdirectory: [],
106
+ name: `${typename}.hpp`,
107
+ language: 'c++',
108
+ platform: 'shared',
109
+ };
110
+ }
@@ -0,0 +1,3 @@
1
+ import type { SourceFile } from '../SourceFile.js';
2
+ import type { HybridObjectSpec } from '../HybridObjectSpec.js';
3
+ export declare function createCppHybridObject(spec: HybridObjectSpec): SourceFile[];
@@ -0,0 +1,146 @@
1
+ import { createFileMetadataString, isNotDuplicate } from '../helpers.js';
2
+ import { indent } from '../../utils.js';
3
+ import { includeHeader, includeNitroHeader } from './includeNitroHeader.js';
4
+ import { getHybridObjectName } from '../getHybridObjectName.js';
5
+ import { HybridObjectType } from '../types/HybridObjectType.js';
6
+ export function createCppHybridObject(spec) {
7
+ // Extra includes
8
+ const extraFiles = [
9
+ ...spec.properties.flatMap((p) => p.getExtraFiles()),
10
+ ...spec.methods.flatMap((m) => m.getExtraFiles()),
11
+ ];
12
+ const extraIncludes = [
13
+ ...spec.properties.flatMap((p) => p.getRequiredImports('c++')),
14
+ ...spec.methods.flatMap((m) => m.getRequiredImports('c++')),
15
+ ...spec.baseTypes.flatMap((b) => new HybridObjectType(b).getRequiredImports('c++')),
16
+ ];
17
+ const cppForwardDeclarations = extraIncludes
18
+ .map((i) => i.forwardDeclaration)
19
+ .filter((v) => v != null)
20
+ .filter(isNotDuplicate);
21
+ const cppExtraIncludes = extraIncludes
22
+ .map((i) => includeHeader(i))
23
+ .filter(isNotDuplicate);
24
+ const cxxNamespace = spec.config.getCxxNamespace('c++');
25
+ const name = getHybridObjectName(spec.name);
26
+ const bases = ['public virtual HybridObject'];
27
+ for (const base of spec.baseTypes) {
28
+ const baseName = getHybridObjectName(base.name).HybridTSpec;
29
+ const fullName = base.config.isExternalConfig
30
+ ? base.config.getCxxNamespace('c++', baseName)
31
+ : baseName;
32
+ bases.push(`public virtual ${fullName}`);
33
+ }
34
+ // Generate the full header / code
35
+ const cppHeaderCode = `
36
+ ${createFileMetadataString(`${name.HybridTSpec}.hpp`)}
37
+
38
+ #pragma once
39
+
40
+ ${includeNitroHeader('HybridObject.hpp')}
41
+
42
+ ${cppForwardDeclarations.join('\n')}
43
+
44
+ ${cppExtraIncludes.join('\n')}
45
+
46
+ namespace ${cxxNamespace} {
47
+
48
+ using namespace margelo::nitro;
49
+
50
+ /**
51
+ * An abstract base class for \`${spec.name}\`
52
+ * Inherit this class to create instances of \`${name.HybridTSpec}\` in C++.
53
+ * You must explicitly call \`HybridObject\`'s constructor yourself, because it is virtual.
54
+ * @example
55
+ * \`\`\`cpp
56
+ * class ${name.HybridT}: public ${name.HybridTSpec} {
57
+ * public:
58
+ * ${name.HybridT}(...): HybridObject(TAG) { ... }
59
+ * // ...
60
+ * };
61
+ * \`\`\`
62
+ */
63
+ class ${name.HybridTSpec}: ${bases.join(', ')} {
64
+ public:
65
+ // Constructor
66
+ explicit ${name.HybridTSpec}(): HybridObject(TAG) { }
67
+
68
+ // Destructor
69
+ ~${name.HybridTSpec}() override = default;
70
+
71
+ public:
72
+ // Properties
73
+ ${indent(spec.properties.map((p) => p.getCode('c++', { virtual: true })).join('\n'), ' ')}
74
+
75
+ public:
76
+ // Methods
77
+ ${indent(spec.methods.map((m) => m.getCode('c++', { virtual: true })).join('\n'), ' ')}
78
+
79
+ protected:
80
+ // Hybrid Setup
81
+ void loadHybridMethods() override;
82
+
83
+ protected:
84
+ // Tag for logging
85
+ static constexpr auto TAG = "${spec.name}";
86
+ };
87
+
88
+ } // namespace ${cxxNamespace}
89
+ `;
90
+ // Each C++ method needs to be registered in the HybridObject - that's getters, setters and normal methods.
91
+ const registrations = [];
92
+ for (const property of spec.properties) {
93
+ const getterMethod = property.getGetterName('other');
94
+ const setterMethod = property.getSetterName('other');
95
+ // getter
96
+ registrations.push(`prototype.registerHybridGetter("${property.name}", &${name.HybridTSpec}::${getterMethod});`);
97
+ if (!property.isReadonly) {
98
+ // setter
99
+ registrations.push(`prototype.registerHybridSetter("${property.name}", &${name.HybridTSpec}::${setterMethod});`);
100
+ }
101
+ }
102
+ for (const method of spec.methods) {
103
+ // method
104
+ registrations.push(`prototype.registerHybridMethod("${method.name}", &${name.HybridTSpec}::${method.name});`);
105
+ }
106
+ const basePrototypeRegistrations = ['HybridObject::loadHybridMethods();'];
107
+ for (const base of spec.baseTypes) {
108
+ const hybridObjectName = getHybridObjectName(base.name);
109
+ basePrototypeRegistrations.push(`${hybridObjectName.HybridTSpec}::loadHybridMethods();`);
110
+ }
111
+ const cppBodyCode = `
112
+ ${createFileMetadataString(`${name.HybridTSpec}.cpp`)}
113
+
114
+ #include "${name.HybridTSpec}.hpp"
115
+
116
+ namespace ${cxxNamespace} {
117
+
118
+ void ${name.HybridTSpec}::loadHybridMethods() {
119
+ // load base methods/properties
120
+ ${indent(basePrototypeRegistrations.join('\n'), ' ')}
121
+ // load custom methods/properties
122
+ registerHybrids(this, [](Prototype& prototype) {
123
+ ${indent(registrations.join('\n'), ' ')}
124
+ });
125
+ }
126
+
127
+ } // namespace ${cxxNamespace}
128
+ `;
129
+ const files = [];
130
+ files.push({
131
+ content: cppHeaderCode,
132
+ name: `${name.HybridTSpec}.hpp`,
133
+ subdirectory: [],
134
+ language: 'c++',
135
+ platform: 'shared',
136
+ });
137
+ files.push({
138
+ content: cppBodyCode,
139
+ name: `${name.HybridTSpec}.cpp`,
140
+ subdirectory: [],
141
+ language: 'c++',
142
+ platform: 'shared',
143
+ });
144
+ files.push(...extraFiles);
145
+ return files;
146
+ }
@@ -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 {};
@@ -0,0 +1,18 @@
1
+ export function createCppHybridObjectRegistration({ hybridObjectName, cppClassName, }) {
2
+ return {
3
+ requiredImports: [
4
+ { name: `${cppClassName}.hpp`, language: 'c++', space: 'user' },
5
+ ],
6
+ cppCode: `
7
+ HybridObjectRegistry::registerHybridObjectConstructor(
8
+ "${hybridObjectName}",
9
+ []() -> std::shared_ptr<HybridObject> {
10
+ static_assert(std::is_default_constructible_v<${cppClassName}>,
11
+ "The HybridObject \\"${cppClassName}\\" is not default-constructible! "
12
+ "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
13
+ return std::make_shared<${cppClassName}>();
14
+ }
15
+ );
16
+ `.trim(),
17
+ };
18
+ }
@@ -0,0 +1,3 @@
1
+ import type { FileWithReferencedTypes } from '../SourceFile.js';
2
+ import type { NamedType } from '../types/Type.js';
3
+ export declare function createCppStruct(typename: string, properties: NamedType[]): FileWithReferencedTypes;