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,62 @@
1
+ import {} from '../SourceFile.js';
2
+ import { ErrorType } from './ErrorType.js';
3
+ import { FunctionType } from './FunctionType.js';
4
+ import { NamedWrappingType } from './NamedWrappingType.js';
5
+ import { VoidType } from './VoidType.js';
6
+ export class PromiseType {
7
+ resultingType;
8
+ errorType;
9
+ constructor(resultingType) {
10
+ this.resultingType = resultingType;
11
+ this.errorType = new ErrorType();
12
+ }
13
+ get canBePassedByReference() {
14
+ // It's a future<..>, it cannot be copied.
15
+ return true;
16
+ }
17
+ get kind() {
18
+ return 'promise';
19
+ }
20
+ get resolverFunction() {
21
+ if (this.resultingType.kind === 'void') {
22
+ return new FunctionType(new VoidType(), []);
23
+ }
24
+ else {
25
+ return new FunctionType(new VoidType(), [
26
+ new NamedWrappingType('value', this.resultingType),
27
+ ]);
28
+ }
29
+ }
30
+ get rejecterFunction() {
31
+ return new FunctionType(new VoidType(), [
32
+ new NamedWrappingType('error', this.errorType),
33
+ ]);
34
+ }
35
+ getCode(language, options) {
36
+ const resultingCode = this.resultingType.getCode(language, options);
37
+ switch (language) {
38
+ case 'c++':
39
+ return `std::shared_ptr<Promise<${resultingCode}>>`;
40
+ case 'swift':
41
+ return `Promise<${resultingCode}>`;
42
+ case 'kotlin':
43
+ return `Promise<${resultingCode}>`;
44
+ default:
45
+ throw new Error(`Language ${language} is not yet supported for PromiseType!`);
46
+ }
47
+ }
48
+ getExtraFiles() {
49
+ return this.resultingType.getExtraFiles();
50
+ }
51
+ getRequiredImports(language) {
52
+ const imports = this.resultingType.getRequiredImports(language);
53
+ if (language === 'c++') {
54
+ imports.push({
55
+ language: 'c++',
56
+ name: 'NitroModules/Promise.hpp',
57
+ space: 'system',
58
+ });
59
+ }
60
+ return imports;
61
+ }
62
+ }
@@ -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,47 @@
1
+ import {} from '../SourceFile.js';
2
+ export class RecordType {
3
+ keyType;
4
+ valueType;
5
+ constructor(keyType, valueType) {
6
+ this.keyType = keyType;
7
+ this.valueType = valueType;
8
+ }
9
+ get canBePassedByReference() {
10
+ // It's a unordered_map<..>, heavy to copy.
11
+ return true;
12
+ }
13
+ get kind() {
14
+ return 'record';
15
+ }
16
+ getCode(language, options) {
17
+ const keyCode = this.keyType.getCode(language, options);
18
+ const valueCode = this.valueType.getCode(language, options);
19
+ switch (language) {
20
+ case 'c++':
21
+ return `std::unordered_map<${keyCode}, ${valueCode}>`;
22
+ case 'swift':
23
+ return `Dictionary<${keyCode}, ${valueCode}>`;
24
+ case 'kotlin':
25
+ return `Map<${keyCode}, ${valueCode}>`;
26
+ default:
27
+ throw new Error(`Language ${language} is not yet supported for RecordType!`);
28
+ }
29
+ }
30
+ getExtraFiles() {
31
+ return [...this.keyType.getExtraFiles(), ...this.valueType.getExtraFiles()];
32
+ }
33
+ getRequiredImports(language) {
34
+ const imports = [
35
+ ...this.keyType.getRequiredImports(language),
36
+ ...this.valueType.getRequiredImports(language),
37
+ ];
38
+ if (language === 'c++') {
39
+ imports.push({
40
+ language: 'c++',
41
+ name: 'unordered_map',
42
+ space: 'system',
43
+ });
44
+ }
45
+ return imports;
46
+ }
47
+ }
@@ -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,44 @@
1
+ import {} from '../SourceFile.js';
2
+ import { ErrorType } from './ErrorType.js';
3
+ export class ResultWrappingType {
4
+ result;
5
+ error;
6
+ constructor(result) {
7
+ this.result = result;
8
+ this.error = new ErrorType();
9
+ }
10
+ get canBePassedByReference() {
11
+ return this.result.canBePassedByReference;
12
+ }
13
+ get kind() {
14
+ return 'result-wrapper';
15
+ }
16
+ getCode(language, options) {
17
+ const type = this.result.getCode(language, options);
18
+ switch (language) {
19
+ case 'c++':
20
+ return `Result<${type}>`;
21
+ case 'swift':
22
+ return type;
23
+ default:
24
+ throw new Error(`Language ${language} is not yet supported for VariantType!`);
25
+ }
26
+ }
27
+ getExtraFiles() {
28
+ return [...this.result.getExtraFiles(), ...this.error.getExtraFiles()];
29
+ }
30
+ getRequiredImports(language) {
31
+ const imports = [
32
+ ...this.result.getRequiredImports(language),
33
+ ...this.error.getRequiredImports(language),
34
+ ];
35
+ if (language === 'c++') {
36
+ imports.push({
37
+ language: 'c++',
38
+ name: 'NitroModules/Result.hpp',
39
+ space: 'system',
40
+ });
41
+ }
42
+ return imports;
43
+ }
44
+ }
@@ -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,35 @@
1
+ export class StringType {
2
+ get canBePassedByReference() {
3
+ // It's a string<..>, heavy to copy.
4
+ return true;
5
+ }
6
+ get kind() {
7
+ return 'string';
8
+ }
9
+ getCode(language) {
10
+ switch (language) {
11
+ case 'c++':
12
+ return 'std::string';
13
+ case 'swift':
14
+ return 'String';
15
+ case 'kotlin':
16
+ return 'String';
17
+ default:
18
+ throw new Error(`Language ${language} is not yet supported for StringType!`);
19
+ }
20
+ }
21
+ getExtraFiles() {
22
+ return [];
23
+ }
24
+ getRequiredImports(language) {
25
+ const imports = [];
26
+ if (language === 'c++') {
27
+ imports.push({
28
+ language: 'c++',
29
+ name: 'string',
30
+ space: 'system',
31
+ });
32
+ }
33
+ return imports;
34
+ }
35
+ }
@@ -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,61 @@
1
+ import { NitroConfig } from '../../config/NitroConfig.js';
2
+ import { createCppStruct } from '../c++/CppStruct.js';
3
+ import { getForwardDeclaration } from '../c++/getForwardDeclaration.js';
4
+ import {} from '../SourceFile.js';
5
+ export class StructType {
6
+ structName;
7
+ properties;
8
+ declarationFile;
9
+ constructor(structName, properties) {
10
+ this.structName = structName;
11
+ this.properties = properties;
12
+ this.declarationFile = createCppStruct(structName, properties);
13
+ if (this.structName.startsWith('__')) {
14
+ throw new Error(`Struct name cannot start with two underscores (__) as this is reserved syntax for Nitrogen! (In ${this.structName})`);
15
+ }
16
+ if (this.properties.length === 0) {
17
+ throw new Error(`Empty structs are not supported in Nitrogen! Add at least one property to ${this.structName}.`);
18
+ }
19
+ }
20
+ get canBePassedByReference() {
21
+ // It's a struct, heavy to copy.
22
+ return true;
23
+ }
24
+ get kind() {
25
+ return 'struct';
26
+ }
27
+ getCode(language, { fullyQualified } = {}) {
28
+ switch (language) {
29
+ case 'c++':
30
+ if (fullyQualified) {
31
+ return NitroConfig.current.getCxxNamespace('c++', this.structName);
32
+ }
33
+ else {
34
+ return this.structName;
35
+ }
36
+ case 'swift':
37
+ return this.structName;
38
+ case 'kotlin':
39
+ return this.structName;
40
+ default:
41
+ throw new Error(`Language ${language} is not yet supported for StructType!`);
42
+ }
43
+ }
44
+ getExtraFiles() {
45
+ const referencedTypes = this.declarationFile.referencedTypes.flatMap((r) => r.getExtraFiles());
46
+ return [this.declarationFile, ...referencedTypes];
47
+ }
48
+ getRequiredImports(language) {
49
+ const imports = [];
50
+ if (language === 'c++') {
51
+ const cxxNamespace = NitroConfig.current.getCxxNamespace('c++');
52
+ imports.push({
53
+ name: this.declarationFile.name,
54
+ language: this.declarationFile.language,
55
+ forwardDeclaration: getForwardDeclaration('struct', this.structName, cxxNamespace),
56
+ space: 'user',
57
+ });
58
+ }
59
+ return imports;
60
+ }
61
+ }
@@ -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,39 @@
1
+ import {} from '../SourceFile.js';
2
+ export class TupleType {
3
+ itemTypes;
4
+ constructor(itemTypes) {
5
+ this.itemTypes = itemTypes;
6
+ }
7
+ get canBePassedByReference() {
8
+ // It's a tuple<..> - heavy to copy
9
+ return true;
10
+ }
11
+ get kind() {
12
+ return 'tuple';
13
+ }
14
+ getCode(language, options) {
15
+ const types = this.itemTypes.map((t) => t.getCode(language, options));
16
+ switch (language) {
17
+ case 'c++':
18
+ return `std::tuple<${types.join(', ')}>`;
19
+ case 'swift':
20
+ throw new Error(`Tuple (${types.join(', ')}) is not yet supported in Swift due to a Swift bug! See https://github.com/swiftlang/swift/issues/75865`);
21
+ default:
22
+ throw new Error(`Language ${language} is not yet supported for TupleType!`);
23
+ }
24
+ }
25
+ getExtraFiles() {
26
+ return this.itemTypes.flatMap((t) => t.getExtraFiles());
27
+ }
28
+ getRequiredImports(language) {
29
+ const imports = this.itemTypes.flatMap((t) => t.getRequiredImports(language));
30
+ if (language === 'c++') {
31
+ imports.push({
32
+ language: 'c++',
33
+ name: 'tuple',
34
+ space: 'system',
35
+ });
36
+ }
37
+ return imports;
38
+ }
39
+ }
@@ -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 @@
1
+ export {};
@@ -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,75 @@
1
+ import { escapeCppName, isNotDuplicate } from '../helpers.js';
2
+ import {} from '../SourceFile.js';
3
+ export const VariantLabels = [
4
+ 'first',
5
+ 'second',
6
+ 'third',
7
+ 'fourth',
8
+ 'fifth',
9
+ 'sixth',
10
+ 'seventh',
11
+ 'eigth',
12
+ 'ninth',
13
+ 'tenth',
14
+ ];
15
+ export class VariantType {
16
+ variants;
17
+ aliasName;
18
+ constructor(variants, aliasName) {
19
+ this.variants = variants;
20
+ this.aliasName = aliasName;
21
+ }
22
+ get canBePassedByReference() {
23
+ // It's a variant<..> - heavy to copy
24
+ return true;
25
+ }
26
+ get kind() {
27
+ return 'variant';
28
+ }
29
+ get jsType() {
30
+ return this.variants.map((v) => v.kind).join(' | ');
31
+ }
32
+ get cases() {
33
+ return this.variants.map((v, i) => {
34
+ const label = VariantLabels[i];
35
+ if (label == null)
36
+ throw new Error(`Variant<...> (\`${this.jsType}\`) does not support ${i} cases!`);
37
+ return [label, v];
38
+ });
39
+ }
40
+ getAliasName(language, options) {
41
+ if (this.aliasName == null) {
42
+ const variants = this.variants.map((v) => v.getCode(language, options));
43
+ return escapeCppName(`Variant_${variants.join('_')}`);
44
+ }
45
+ return this.aliasName;
46
+ }
47
+ getCode(language, options) {
48
+ const types = this.variants
49
+ .map((v) => v.getCode(language, options))
50
+ .filter(isNotDuplicate);
51
+ switch (language) {
52
+ case 'c++':
53
+ return `std::variant<${types.join(', ')}>`;
54
+ case 'swift':
55
+ case 'kotlin':
56
+ return this.getAliasName(language, options);
57
+ default:
58
+ throw new Error(`Language ${language} is not yet supported for VariantType!`);
59
+ }
60
+ }
61
+ getExtraFiles() {
62
+ return this.variants.flatMap((v) => v.getExtraFiles());
63
+ }
64
+ getRequiredImports(language) {
65
+ const imports = this.variants.flatMap((v) => v.getRequiredImports(language));
66
+ if (language === 'c++') {
67
+ imports.push({
68
+ language: 'c++',
69
+ name: 'variant',
70
+ space: 'system',
71
+ });
72
+ }
73
+ return imports;
74
+ }
75
+ }
@@ -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
+ }
@@ -0,0 +1,27 @@
1
+ export class VoidType {
2
+ get canBePassedByReference() {
3
+ // It's void.
4
+ return false;
5
+ }
6
+ get kind() {
7
+ return 'void';
8
+ }
9
+ getCode(language) {
10
+ switch (language) {
11
+ case 'c++':
12
+ return 'void';
13
+ case 'swift':
14
+ return 'Void';
15
+ case 'kotlin':
16
+ return 'Unit';
17
+ default:
18
+ throw new Error(`Language ${language} is not yet supported for VoidType!`);
19
+ }
20
+ }
21
+ getExtraFiles() {
22
+ return [];
23
+ }
24
+ getRequiredImports() {
25
+ return [];
26
+ }
27
+ }
@@ -0,0 +1,2 @@
1
+ import type { Type } from './Type.js';
2
+ export declare function getTypeAs<T>(type: Type, classReference: new (...args: any[]) => T): T;
@@ -0,0 +1,12 @@
1
+ import { NamedWrappingType } from './NamedWrappingType.js';
2
+ export function getTypeAs(type, classReference) {
3
+ if (type instanceof classReference) {
4
+ return type;
5
+ }
6
+ else if (type instanceof NamedWrappingType) {
7
+ return getTypeAs(type.type, classReference);
8
+ }
9
+ else {
10
+ throw new Error(`Type of kind "${type.kind}" is not a ${classReference}!`);
11
+ }
12
+ }
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;