@ts-for-gir/cli 3.0.0-beta.10

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 (773) hide show
  1. package/README.md +420 -0
  2. package/lib/commands/doc.d.ts +27 -0
  3. package/lib/commands/doc.js +48 -0
  4. package/lib/commands/doc.js.map +1 -0
  5. package/lib/commands/generate.d.ts +49 -0
  6. package/lib/commands/generate.js +73 -0
  7. package/lib/commands/generate.js.map +1 -0
  8. package/lib/commands/index.d.ts +3 -0
  9. package/lib/commands/index.js +4 -0
  10. package/lib/commands/index.js.map +1 -0
  11. package/lib/commands/list.d.ts +21 -0
  12. package/lib/commands/list.js +77 -0
  13. package/lib/commands/list.js.map +1 -0
  14. package/lib/config.d.ts +88 -0
  15. package/lib/config.js +471 -0
  16. package/lib/config.js.map +1 -0
  17. package/lib/conflict-resolver.d.ts +155 -0
  18. package/lib/conflict-resolver.js +1103 -0
  19. package/lib/conflict-resolver.js.map +1 -0
  20. package/lib/constants.d.ts +18 -0
  21. package/lib/constants.js +23 -0
  22. package/lib/constants.js.map +1 -0
  23. package/lib/dependency-manager.d.ts +34 -0
  24. package/lib/dependency-manager.js +78 -0
  25. package/lib/dependency-manager.js.map +1 -0
  26. package/lib/generation-handler.d.ts +12 -0
  27. package/lib/generation-handler.js +63 -0
  28. package/lib/generation-handler.js.map +1 -0
  29. package/lib/generator.d.ts +5 -0
  30. package/lib/generator.js +2 -0
  31. package/lib/generator.js.map +1 -0
  32. package/lib/gir-factory.d.ts +52 -0
  33. package/lib/gir-factory.js +376 -0
  34. package/lib/gir-factory.js.map +1 -0
  35. package/lib/gir-module.d.ts +259 -0
  36. package/lib/gir-module.js +2181 -0
  37. package/lib/gir-module.js.map +1 -0
  38. package/lib/html-doc-generator.d.ts +13 -0
  39. package/lib/html-doc-generator.js +18 -0
  40. package/lib/html-doc-generator.js.map +1 -0
  41. package/lib/index.d.ts +17 -0
  42. package/lib/index.js +18 -0
  43. package/lib/index.js.map +1 -0
  44. package/lib/injection/callbacks/gjs/Gio-2.0.d.ts +2 -0
  45. package/lib/injection/callbacks/gjs/Gio-2.0.js +36 -0
  46. package/lib/injection/callbacks/gjs/Gio-2.0.js.map +1 -0
  47. package/lib/injection/callbacks/gjs/index.d.ts +2 -0
  48. package/lib/injection/callbacks/gjs/index.js +3 -0
  49. package/lib/injection/callbacks/gjs/index.js.map +1 -0
  50. package/lib/injection/callbacks/index.d.ts +4 -0
  51. package/lib/injection/callbacks/index.js +4 -0
  52. package/lib/injection/callbacks/index.js.map +1 -0
  53. package/lib/injection/callbacks/node-gtk/index.d.ts +2 -0
  54. package/lib/injection/callbacks/node-gtk/index.js +2 -0
  55. package/lib/injection/callbacks/node-gtk/index.js.map +1 -0
  56. package/lib/injection/classes/GLib-2-0.d.ts +2 -0
  57. package/lib/injection/classes/GLib-2-0.js +35 -0
  58. package/lib/injection/classes/GLib-2-0.js.map +1 -0
  59. package/lib/injection/classes/gjs/GLib-2.0.d.ts +2 -0
  60. package/lib/injection/classes/gjs/GLib-2.0.js +205 -0
  61. package/lib/injection/classes/gjs/GLib-2.0.js.map +1 -0
  62. package/lib/injection/classes/gjs/GObject-2.0.d.ts +2 -0
  63. package/lib/injection/classes/gjs/GObject-2.0.js +634 -0
  64. package/lib/injection/classes/gjs/GObject-2.0.js.map +1 -0
  65. package/lib/injection/classes/gjs/Gio-2.0.d.ts +5 -0
  66. package/lib/injection/classes/gjs/Gio-2.0.js +218 -0
  67. package/lib/injection/classes/gjs/Gio-2.0.js.map +1 -0
  68. package/lib/injection/classes/gjs/index.d.ts +2 -0
  69. package/lib/injection/classes/gjs/index.js +5 -0
  70. package/lib/injection/classes/gjs/index.js.map +1 -0
  71. package/lib/injection/classes/index.d.ts +4 -0
  72. package/lib/injection/classes/index.js +5 -0
  73. package/lib/injection/classes/index.js.map +1 -0
  74. package/lib/injection/classes/node-gtk/GLib-2.0.d.ts +2 -0
  75. package/lib/injection/classes/node-gtk/GLib-2.0.js +19 -0
  76. package/lib/injection/classes/node-gtk/GLib-2.0.js.map +1 -0
  77. package/lib/injection/classes/node-gtk/GObject-2.0.d.ts +2 -0
  78. package/lib/injection/classes/node-gtk/GObject-2.0.js +66 -0
  79. package/lib/injection/classes/node-gtk/GObject-2.0.js.map +1 -0
  80. package/lib/injection/classes/node-gtk/Gdk-4.0.d.ts +2 -0
  81. package/lib/injection/classes/node-gtk/Gdk-4.0.js +32 -0
  82. package/lib/injection/classes/node-gtk/Gdk-4.0.js.map +1 -0
  83. package/lib/injection/classes/node-gtk/Gio-2.0.d.ts +2 -0
  84. package/lib/injection/classes/node-gtk/Gio-2.0.js +14 -0
  85. package/lib/injection/classes/node-gtk/Gio-2.0.js.map +1 -0
  86. package/lib/injection/classes/node-gtk/Graphene-1.0.d.ts +2 -0
  87. package/lib/injection/classes/node-gtk/Graphene-1.0.js +133 -0
  88. package/lib/injection/classes/node-gtk/Graphene-1.0.js.map +1 -0
  89. package/lib/injection/classes/node-gtk/Gtk-3.0.d.ts +2 -0
  90. package/lib/injection/classes/node-gtk/Gtk-3.0.js +31 -0
  91. package/lib/injection/classes/node-gtk/Gtk-3.0.js.map +1 -0
  92. package/lib/injection/classes/node-gtk/Gtk-4.0.d.ts +2 -0
  93. package/lib/injection/classes/node-gtk/Gtk-4.0.js +52 -0
  94. package/lib/injection/classes/node-gtk/Gtk-4.0.js.map +1 -0
  95. package/lib/injection/classes/node-gtk/Pango-1.0.d.ts +2 -0
  96. package/lib/injection/classes/node-gtk/Pango-1.0.js +31 -0
  97. package/lib/injection/classes/node-gtk/Pango-1.0.js.map +1 -0
  98. package/lib/injection/classes/node-gtk/index.d.ts +2 -0
  99. package/lib/injection/classes/node-gtk/index.js +19 -0
  100. package/lib/injection/classes/node-gtk/index.js.map +1 -0
  101. package/lib/injection/index.d.ts +3 -0
  102. package/lib/injection/index.js +4 -0
  103. package/lib/injection/index.js.map +1 -0
  104. package/lib/injection/injector.d.ts +17 -0
  105. package/lib/injection/injector.js +139 -0
  106. package/lib/injection/injector.js.map +1 -0
  107. package/lib/logger.d.ts +36 -0
  108. package/lib/logger.js +137 -0
  109. package/lib/logger.js.map +1 -0
  110. package/lib/messages.d.ts +31 -0
  111. package/lib/messages.js +46 -0
  112. package/lib/messages.js.map +1 -0
  113. package/lib/module-loader.d.ts +134 -0
  114. package/lib/module-loader.js +475 -0
  115. package/lib/module-loader.js.map +1 -0
  116. package/lib/start.d.ts +2 -0
  117. package/lib/start.js +15 -0
  118. package/lib/start.js.map +1 -0
  119. package/lib/symtable.d.ts +24 -0
  120. package/lib/symtable.js +63 -0
  121. package/lib/symtable.js.map +1 -0
  122. package/lib/template-processor.d.ts +74 -0
  123. package/lib/template-processor.js +165 -0
  124. package/lib/template-processor.js.map +1 -0
  125. package/lib/transformation.d.ts +156 -0
  126. package/lib/transformation.js +524 -0
  127. package/lib/transformation.js.map +1 -0
  128. package/lib/type-definition-generator.d.ts +116 -0
  129. package/lib/type-definition-generator.js +996 -0
  130. package/lib/type-definition-generator.js.map +1 -0
  131. package/lib/types/answer-version.d.ts +4 -0
  132. package/lib/types/answer-version.js +2 -0
  133. package/lib/types/answer-version.js.map +1 -0
  134. package/lib/types/build-type.d.ts +1 -0
  135. package/lib/types/build-type.js +2 -0
  136. package/lib/types/build-type.js.map +1 -0
  137. package/lib/types/class-parent.d.ts +13 -0
  138. package/lib/types/class-parent.js +2 -0
  139. package/lib/types/class-parent.js.map +1 -0
  140. package/lib/types/config-flags.d.ts +4 -0
  141. package/lib/types/config-flags.js +2 -0
  142. package/lib/types/config-flags.js.map +1 -0
  143. package/lib/types/conflict-child-element.d.ts +10 -0
  144. package/lib/types/conflict-child-element.js +2 -0
  145. package/lib/types/conflict-child-element.js.map +1 -0
  146. package/lib/types/conflict-grouped-element.d.ts +6 -0
  147. package/lib/types/conflict-grouped-element.js +2 -0
  148. package/lib/types/conflict-grouped-element.js.map +1 -0
  149. package/lib/types/conflict-grouped-elements.d.ts +4 -0
  150. package/lib/types/conflict-grouped-elements.js +2 -0
  151. package/lib/types/conflict-grouped-elements.js.map +1 -0
  152. package/lib/types/construct-name.d.ts +1 -0
  153. package/lib/types/construct-name.js +2 -0
  154. package/lib/types/construct-name.js.map +1 -0
  155. package/lib/types/dependency-map.d.ts +4 -0
  156. package/lib/types/dependency-map.js +2 -0
  157. package/lib/types/dependency-map.js.map +1 -0
  158. package/lib/types/dependency.d.ts +15 -0
  159. package/lib/types/dependency.js +2 -0
  160. package/lib/types/dependency.js.map +1 -0
  161. package/lib/types/environment.d.ts +1 -0
  162. package/lib/types/environment.js +2 -0
  163. package/lib/types/environment.js.map +1 -0
  164. package/lib/types/file-info.d.ts +14 -0
  165. package/lib/types/file-info.js +2 -0
  166. package/lib/types/file-info.js.map +1 -0
  167. package/lib/types/generate-config.d.ts +34 -0
  168. package/lib/types/generate-config.js +2 -0
  169. package/lib/types/generate-config.js.map +1 -0
  170. package/lib/types/generator-type.d.ts +4 -0
  171. package/lib/types/generator-type.js +6 -0
  172. package/lib/types/generator-type.js.map +1 -0
  173. package/lib/types/gir-alias-element.d.ts +13 -0
  174. package/lib/types/gir-alias-element.js +2 -0
  175. package/lib/types/gir-alias-element.js.map +1 -0
  176. package/lib/types/gir-annotation.d.ts +9 -0
  177. package/lib/types/gir-annotation.js +2 -0
  178. package/lib/types/gir-annotation.js.map +1 -0
  179. package/lib/types/gir-any-element.d.ts +2 -0
  180. package/lib/types/gir-any-element.js +2 -0
  181. package/lib/types/gir-any-element.js.map +1 -0
  182. package/lib/types/gir-any-type.d.ts +5 -0
  183. package/lib/types/gir-any-type.js +2 -0
  184. package/lib/types/gir-any-type.js.map +1 -0
  185. package/lib/types/gir-array-type.d.ts +20 -0
  186. package/lib/types/gir-array-type.js +3 -0
  187. package/lib/types/gir-array-type.js.map +1 -0
  188. package/lib/types/gir-bitfield-element.d.ts +17 -0
  189. package/lib/types/gir-bitfield-element.js +2 -0
  190. package/lib/types/gir-bitfield-element.js.map +1 -0
  191. package/lib/types/gir-boolean.d.ts +1 -0
  192. package/lib/types/gir-boolean.js +2 -0
  193. package/lib/types/gir-boolean.js.map +1 -0
  194. package/lib/types/gir-boxed-element.d.ts +15 -0
  195. package/lib/types/gir-boxed-element.js +2 -0
  196. package/lib/types/gir-boxed-element.js.map +1 -0
  197. package/lib/types/gir-c-include.d.ts +7 -0
  198. package/lib/types/gir-c-include.js +2 -0
  199. package/lib/types/gir-c-include.js.map +1 -0
  200. package/lib/types/gir-callable-attrs.d.ts +15 -0
  201. package/lib/types/gir-callable-attrs.js +3 -0
  202. package/lib/types/gir-callable-attrs.js.map +1 -0
  203. package/lib/types/gir-callable-param-element.d.ts +30 -0
  204. package/lib/types/gir-callable-param-element.js +2 -0
  205. package/lib/types/gir-callable-param-element.js.map +1 -0
  206. package/lib/types/gir-callable-param.d.ts +7 -0
  207. package/lib/types/gir-callable-param.js +2 -0
  208. package/lib/types/gir-callable-param.js.map +1 -0
  209. package/lib/types/gir-callable-return.d.ts +22 -0
  210. package/lib/types/gir-callable-return.js +2 -0
  211. package/lib/types/gir-callable-return.js.map +1 -0
  212. package/lib/types/gir-callback-element.d.ts +15 -0
  213. package/lib/types/gir-callback-element.js +2 -0
  214. package/lib/types/gir-callback-element.js.map +1 -0
  215. package/lib/types/gir-class-element.d.ts +48 -0
  216. package/lib/types/gir-class-element.js +2 -0
  217. package/lib/types/gir-class-element.js.map +1 -0
  218. package/lib/types/gir-constant-element.d.ts +15 -0
  219. package/lib/types/gir-constant-element.js +2 -0
  220. package/lib/types/gir-constant-element.js.map +1 -0
  221. package/lib/types/gir-constructor-element.d.ts +8 -0
  222. package/lib/types/gir-constructor-element.js +2 -0
  223. package/lib/types/gir-constructor-element.js.map +1 -0
  224. package/lib/types/gir-direction.d.ts +5 -0
  225. package/lib/types/gir-direction.js +7 -0
  226. package/lib/types/gir-direction.js.map +1 -0
  227. package/lib/types/gir-doc-element.d.ts +68 -0
  228. package/lib/types/gir-doc-element.js +2 -0
  229. package/lib/types/gir-doc-element.js.map +1 -0
  230. package/lib/types/gir-enum-element.d.ts +19 -0
  231. package/lib/types/gir-enum-element.js +2 -0
  232. package/lib/types/gir-enum-element.js.map +1 -0
  233. package/lib/types/gir-field-element.d.ts +18 -0
  234. package/lib/types/gir-field-element.js +2 -0
  235. package/lib/types/gir-field-element.js.map +1 -0
  236. package/lib/types/gir-function-element.d.ts +8 -0
  237. package/lib/types/gir-function-element.js +2 -0
  238. package/lib/types/gir-function-element.js.map +1 -0
  239. package/lib/types/gir-implements.d.ts +8 -0
  240. package/lib/types/gir-implements.js +2 -0
  241. package/lib/types/gir-implements.js.map +1 -0
  242. package/lib/types/gir-include.d.ts +9 -0
  243. package/lib/types/gir-include.js +2 -0
  244. package/lib/types/gir-include.js.map +1 -0
  245. package/lib/types/gir-info-attrs.d.ts +13 -0
  246. package/lib/types/gir-info-attrs.js +2 -0
  247. package/lib/types/gir-info-attrs.js.map +1 -0
  248. package/lib/types/gir-info-elements.d.ts +5 -0
  249. package/lib/types/gir-info-elements.js +2 -0
  250. package/lib/types/gir-info-elements.js.map +1 -0
  251. package/lib/types/gir-instance-parameter.d.ts +21 -0
  252. package/lib/types/gir-instance-parameter.js +2 -0
  253. package/lib/types/gir-instance-parameter.js.map +1 -0
  254. package/lib/types/gir-interface-element.d.ts +31 -0
  255. package/lib/types/gir-interface-element.js +2 -0
  256. package/lib/types/gir-interface-element.js.map +1 -0
  257. package/lib/types/gir-member-element.d.ts +17 -0
  258. package/lib/types/gir-member-element.js +2 -0
  259. package/lib/types/gir-member-element.js.map +1 -0
  260. package/lib/types/gir-method-element.d.ts +13 -0
  261. package/lib/types/gir-method-element.js +2 -0
  262. package/lib/types/gir-method-element.js.map +1 -0
  263. package/lib/types/gir-module-resolved-by.d.ts +10 -0
  264. package/lib/types/gir-module-resolved-by.js +2 -0
  265. package/lib/types/gir-module-resolved-by.js.map +1 -0
  266. package/lib/types/gir-modules-grouped-map.d.ts +4 -0
  267. package/lib/types/gir-modules-grouped-map.js +2 -0
  268. package/lib/types/gir-modules-grouped-map.js.map +1 -0
  269. package/lib/types/gir-modules-grouped.d.ts +12 -0
  270. package/lib/types/gir-modules-grouped.js +2 -0
  271. package/lib/types/gir-modules-grouped.js.map +1 -0
  272. package/lib/types/gir-namespace.d.ts +30 -0
  273. package/lib/types/gir-namespace.js +2 -0
  274. package/lib/types/gir-namespace.js.map +1 -0
  275. package/lib/types/gir-package.d.ts +7 -0
  276. package/lib/types/gir-package.js +2 -0
  277. package/lib/types/gir-package.js.map +1 -0
  278. package/lib/types/gir-prerequisite.d.ts +5 -0
  279. package/lib/types/gir-prerequisite.js +2 -0
  280. package/lib/types/gir-prerequisite.js.map +1 -0
  281. package/lib/types/gir-property-element.d.ts +21 -0
  282. package/lib/types/gir-property-element.js +2 -0
  283. package/lib/types/gir-property-element.js.map +1 -0
  284. package/lib/types/gir-record-element.d.ts +30 -0
  285. package/lib/types/gir-record-element.js +2 -0
  286. package/lib/types/gir-record-element.js.map +1 -0
  287. package/lib/types/gir-repository.d.ts +16 -0
  288. package/lib/types/gir-repository.js +2 -0
  289. package/lib/types/gir-repository.js.map +1 -0
  290. package/lib/types/gir-signal.d.ts +25 -0
  291. package/lib/types/gir-signal.js +2 -0
  292. package/lib/types/gir-signal.js.map +1 -0
  293. package/lib/types/gir-transfer-ownership-type.d.ts +5 -0
  294. package/lib/types/gir-transfer-ownership-type.js +7 -0
  295. package/lib/types/gir-transfer-ownership-type.js.map +1 -0
  296. package/lib/types/gir-transfer-ownership.d.ts +5 -0
  297. package/lib/types/gir-transfer-ownership.js +2 -0
  298. package/lib/types/gir-transfer-ownership.js.map +1 -0
  299. package/lib/types/gir-type.d.ts +14 -0
  300. package/lib/types/gir-type.js +2 -0
  301. package/lib/types/gir-type.js.map +1 -0
  302. package/lib/types/gir-union-element.d.ts +22 -0
  303. package/lib/types/gir-union-element.js +2 -0
  304. package/lib/types/gir-union-element.js.map +1 -0
  305. package/lib/types/gir-unparsed-number.d.ts +2 -0
  306. package/lib/types/gir-unparsed-number.js +2 -0
  307. package/lib/types/gir-unparsed-number.js.map +1 -0
  308. package/lib/types/gir-var-args.d.ts +5 -0
  309. package/lib/types/gir-var-args.js +2 -0
  310. package/lib/types/gir-var-args.js.map +1 -0
  311. package/lib/types/gir-virtual-method.d.ts +10 -0
  312. package/lib/types/gir-virtual-method.js +2 -0
  313. package/lib/types/gir-virtual-method.js.map +1 -0
  314. package/lib/types/index.d.ts +120 -0
  315. package/lib/types/index.js +121 -0
  316. package/lib/types/index.js.map +1 -0
  317. package/lib/types/inheritance-table.d.ts +3 -0
  318. package/lib/types/inheritance-table.js +2 -0
  319. package/lib/types/inheritance-table.js.map +1 -0
  320. package/lib/types/injection-callback.d.ts +16 -0
  321. package/lib/types/injection-callback.js +2 -0
  322. package/lib/types/injection-callback.js.map +1 -0
  323. package/lib/types/injection-class.d.ts +25 -0
  324. package/lib/types/injection-class.js +2 -0
  325. package/lib/types/injection-class.js.map +1 -0
  326. package/lib/types/injection-function.d.ts +7 -0
  327. package/lib/types/injection-function.js +2 -0
  328. package/lib/types/injection-function.js.map +1 -0
  329. package/lib/types/injection-generic-parameter.d.ts +2 -0
  330. package/lib/types/injection-generic-parameter.js +2 -0
  331. package/lib/types/injection-generic-parameter.js.map +1 -0
  332. package/lib/types/injection-instance-parameter.d.ts +2 -0
  333. package/lib/types/injection-instance-parameter.js +2 -0
  334. package/lib/types/injection-instance-parameter.js.map +1 -0
  335. package/lib/types/injection-parameter.d.ts +8 -0
  336. package/lib/types/injection-parameter.js +2 -0
  337. package/lib/types/injection-parameter.js.map +1 -0
  338. package/lib/types/injection-property.d.ts +4 -0
  339. package/lib/types/injection-property.js +2 -0
  340. package/lib/types/injection-property.js.map +1 -0
  341. package/lib/types/injection-type.d.ts +2 -0
  342. package/lib/types/injection-type.js +2 -0
  343. package/lib/types/injection-type.js.map +1 -0
  344. package/lib/types/injection.d.ts +5 -0
  345. package/lib/types/injection.js +2 -0
  346. package/lib/types/injection.js.map +1 -0
  347. package/lib/types/local-name-check.d.ts +4 -0
  348. package/lib/types/local-name-check.js +2 -0
  349. package/lib/types/local-name-check.js.map +1 -0
  350. package/lib/types/local-name-type.d.ts +1 -0
  351. package/lib/types/local-name-type.js +2 -0
  352. package/lib/types/local-name-type.js.map +1 -0
  353. package/lib/types/local-name.d.ts +7 -0
  354. package/lib/types/local-name.js +2 -0
  355. package/lib/types/local-name.js.map +1 -0
  356. package/lib/types/local-names.d.ts +4 -0
  357. package/lib/types/local-names.js +2 -0
  358. package/lib/types/local-names.js.map +1 -0
  359. package/lib/types/module-type.d.ts +1 -0
  360. package/lib/types/module-type.js +2 -0
  361. package/lib/types/module-type.js.map +1 -0
  362. package/lib/types/parsed-gir.d.ts +4 -0
  363. package/lib/types/parsed-gir.js +2 -0
  364. package/lib/types/parsed-gir.js.map +1 -0
  365. package/lib/types/part-of-class.d.ts +7 -0
  366. package/lib/types/part-of-class.js +2 -0
  367. package/lib/types/part-of-class.js.map +1 -0
  368. package/lib/types/part-of-module.d.ts +6 -0
  369. package/lib/types/part-of-module.js +2 -0
  370. package/lib/types/part-of-module.js.map +1 -0
  371. package/lib/types/promisify-func.d.ts +7 -0
  372. package/lib/types/promisify-func.js +2 -0
  373. package/lib/types/promisify-func.js.map +1 -0
  374. package/lib/types/resolve-type.d.ts +4 -0
  375. package/lib/types/resolve-type.js +6 -0
  376. package/lib/types/resolve-type.js.map +1 -0
  377. package/lib/types/sym-table-items.d.ts +4 -0
  378. package/lib/types/sym-table-items.js +2 -0
  379. package/lib/types/sym-table-items.js.map +1 -0
  380. package/lib/types/transformation-case.d.ts +1 -0
  381. package/lib/types/transformation-case.js +2 -0
  382. package/lib/types/transformation-case.js.map +1 -0
  383. package/lib/types/transformations.d.ts +11 -0
  384. package/lib/types/transformations.js +2 -0
  385. package/lib/types/transformations.js.map +1 -0
  386. package/lib/types/ts-alias.d.ts +10 -0
  387. package/lib/types/ts-alias.js +2 -0
  388. package/lib/types/ts-alias.js.map +1 -0
  389. package/lib/types/ts-callback-interface.d.ts +10 -0
  390. package/lib/types/ts-callback-interface.js +2 -0
  391. package/lib/types/ts-callback-interface.js.map +1 -0
  392. package/lib/types/ts-callback.d.ts +17 -0
  393. package/lib/types/ts-callback.js +2 -0
  394. package/lib/types/ts-callback.js.map +1 -0
  395. package/lib/types/ts-class.d.ts +85 -0
  396. package/lib/types/ts-class.js +2 -0
  397. package/lib/types/ts-class.js.map +1 -0
  398. package/lib/types/ts-doc-tag.d.ts +21 -0
  399. package/lib/types/ts-doc-tag.js +2 -0
  400. package/lib/types/ts-doc-tag.js.map +1 -0
  401. package/lib/types/ts-doc.d.ts +16 -0
  402. package/lib/types/ts-doc.js +2 -0
  403. package/lib/types/ts-doc.js.map +1 -0
  404. package/lib/types/ts-enum.d.ts +12 -0
  405. package/lib/types/ts-enum.js +2 -0
  406. package/lib/types/ts-enum.js.map +1 -0
  407. package/lib/types/ts-function.d.ts +55 -0
  408. package/lib/types/ts-function.js +2 -0
  409. package/lib/types/ts-function.js.map +1 -0
  410. package/lib/types/ts-generic-parameter.d.ts +8 -0
  411. package/lib/types/ts-generic-parameter.js +2 -0
  412. package/lib/types/ts-generic-parameter.js.map +1 -0
  413. package/lib/types/ts-instance-parameter.d.ts +4 -0
  414. package/lib/types/ts-instance-parameter.js +2 -0
  415. package/lib/types/ts-instance-parameter.js.map +1 -0
  416. package/lib/types/ts-member.d.ts +10 -0
  417. package/lib/types/ts-member.js +2 -0
  418. package/lib/types/ts-member.js.map +1 -0
  419. package/lib/types/ts-method.d.ts +5 -0
  420. package/lib/types/ts-method.js +2 -0
  421. package/lib/types/ts-method.js.map +1 -0
  422. package/lib/types/ts-parameter.d.ts +15 -0
  423. package/lib/types/ts-parameter.js +2 -0
  424. package/lib/types/ts-parameter.js.map +1 -0
  425. package/lib/types/ts-property.d.ts +17 -0
  426. package/lib/types/ts-property.js +2 -0
  427. package/lib/types/ts-property.js.map +1 -0
  428. package/lib/types/ts-signal.d.ts +17 -0
  429. package/lib/types/ts-signal.js +2 -0
  430. package/lib/types/ts-signal.js.map +1 -0
  431. package/lib/types/ts-type-name.d.ts +1 -0
  432. package/lib/types/ts-type-name.js +2 -0
  433. package/lib/types/ts-type-name.js.map +1 -0
  434. package/lib/types/ts-type-separator.d.ts +1 -0
  435. package/lib/types/ts-type-separator.js +2 -0
  436. package/lib/types/ts-type-separator.js.map +1 -0
  437. package/lib/types/ts-type.d.ts +26 -0
  438. package/lib/types/ts-type.js +2 -0
  439. package/lib/types/ts-type.js.map +1 -0
  440. package/lib/types/ts-var.d.ts +17 -0
  441. package/lib/types/ts-var.js +2 -0
  442. package/lib/types/ts-var.js.map +1 -0
  443. package/lib/types/type-gir-alias.d.ts +2 -0
  444. package/lib/types/type-gir-alias.js +2 -0
  445. package/lib/types/type-gir-alias.js.map +1 -0
  446. package/lib/types/type-gir-class.d.ts +2 -0
  447. package/lib/types/type-gir-class.js +2 -0
  448. package/lib/types/type-gir-class.js.map +1 -0
  449. package/lib/types/type-gir-element.d.ts +3 -0
  450. package/lib/types/type-gir-element.js +2 -0
  451. package/lib/types/type-gir-element.js.map +1 -0
  452. package/lib/types/type-gir-enumeration-member.d.ts +2 -0
  453. package/lib/types/type-gir-enumeration-member.js +2 -0
  454. package/lib/types/type-gir-enumeration-member.js.map +1 -0
  455. package/lib/types/type-gir-enumeration.d.ts +2 -0
  456. package/lib/types/type-gir-enumeration.js +2 -0
  457. package/lib/types/type-gir-enumeration.js.map +1 -0
  458. package/lib/types/type-gir-function.d.ts +1 -0
  459. package/lib/types/type-gir-function.js +2 -0
  460. package/lib/types/type-gir-function.js.map +1 -0
  461. package/lib/types/type-gir-interface.d.ts +2 -0
  462. package/lib/types/type-gir-interface.js +2 -0
  463. package/lib/types/type-gir-interface.js.map +1 -0
  464. package/lib/types/type-gir-method.d.ts +2 -0
  465. package/lib/types/type-gir-method.js +2 -0
  466. package/lib/types/type-gir-method.js.map +1 -0
  467. package/lib/types/type-gir-parameter.d.ts +1 -0
  468. package/lib/types/type-gir-parameter.js +2 -0
  469. package/lib/types/type-gir-parameter.js.map +1 -0
  470. package/lib/types/type-gir-property.d.ts +2 -0
  471. package/lib/types/type-gir-property.js +2 -0
  472. package/lib/types/type-gir-property.js.map +1 -0
  473. package/lib/types/type-gir-variable.d.ts +1 -0
  474. package/lib/types/type-gir-variable.js +2 -0
  475. package/lib/types/type-gir-variable.js.map +1 -0
  476. package/lib/types/type-ts-element.d.ts +3 -0
  477. package/lib/types/type-ts-element.js +2 -0
  478. package/lib/types/type-ts-element.js.map +1 -0
  479. package/lib/types/type-ts-enumeration-member.d.ts +2 -0
  480. package/lib/types/type-ts-enumeration-member.js +2 -0
  481. package/lib/types/type-ts-enumeration-member.js.map +1 -0
  482. package/lib/types/type-ts-function.d.ts +1 -0
  483. package/lib/types/type-ts-function.js +2 -0
  484. package/lib/types/type-ts-function.js.map +1 -0
  485. package/lib/types/type-ts-property.d.ts +1 -0
  486. package/lib/types/type-ts-property.js +2 -0
  487. package/lib/types/type-ts-property.js.map +1 -0
  488. package/lib/types/user-config-load-result.d.ts +6 -0
  489. package/lib/types/user-config-load-result.js +2 -0
  490. package/lib/types/user-config-load-result.js.map +1 -0
  491. package/lib/types/user-config.d.ts +42 -0
  492. package/lib/types/user-config.js +2 -0
  493. package/lib/types/user-config.js.map +1 -0
  494. package/lib/utils.d.ts +292 -0
  495. package/lib/utils.js +403 -0
  496. package/lib/utils.js.map +1 -0
  497. package/package.json +89 -0
  498. package/src/commands/doc.ts +65 -0
  499. package/src/commands/generate.ts +88 -0
  500. package/src/commands/index.ts +3 -0
  501. package/src/commands/list.ts +96 -0
  502. package/src/config.ts +528 -0
  503. package/src/conflict-resolver.ts +1358 -0
  504. package/src/constants.ts +29 -0
  505. package/src/dependency-manager.ts +91 -0
  506. package/src/generation-handler.ts +79 -0
  507. package/src/generator.ts +10 -0
  508. package/src/gir-factory.ts +526 -0
  509. package/src/gir-module.ts +2953 -0
  510. package/src/html-doc-generator.ts +23 -0
  511. package/src/index.ts +17 -0
  512. package/src/injection/callbacks/gjs/Gio-2.0.ts +37 -0
  513. package/src/injection/callbacks/gjs/index.ts +5 -0
  514. package/src/injection/callbacks/index.ts +6 -0
  515. package/src/injection/callbacks/node-gtk/index.ts +3 -0
  516. package/src/injection/classes/GLib-2-0.ts +36 -0
  517. package/src/injection/classes/gjs/GLib-2.0.ts +206 -0
  518. package/src/injection/classes/gjs/GObject-2.0.ts +635 -0
  519. package/src/injection/classes/gjs/Gio-2.0.ts +219 -0
  520. package/src/injection/classes/gjs/index.ts +7 -0
  521. package/src/injection/classes/index.ts +7 -0
  522. package/src/injection/classes/node-gtk/GLib-2.0.ts +20 -0
  523. package/src/injection/classes/node-gtk/GObject-2.0.ts +67 -0
  524. package/src/injection/classes/node-gtk/Gdk-4.0.ts +33 -0
  525. package/src/injection/classes/node-gtk/Gio-2.0.ts +15 -0
  526. package/src/injection/classes/node-gtk/Graphene-1.0.ts +134 -0
  527. package/src/injection/classes/node-gtk/Gtk-3.0.ts +32 -0
  528. package/src/injection/classes/node-gtk/Gtk-4.0.ts +53 -0
  529. package/src/injection/classes/node-gtk/Pango-1.0.ts +32 -0
  530. package/src/injection/classes/node-gtk/index.ts +21 -0
  531. package/src/injection/index.ts +3 -0
  532. package/src/injection/injector.ts +184 -0
  533. package/src/logger.ts +134 -0
  534. package/src/messages.ts +69 -0
  535. package/src/module-loader.ts +576 -0
  536. package/src/start.ts +16 -0
  537. package/src/symtable.ts +72 -0
  538. package/src/template-processor.ts +199 -0
  539. package/src/transformation.ts +584 -0
  540. package/src/type-definition-generator.ts +1467 -0
  541. package/src/types/answer-version.ts +4 -0
  542. package/src/types/build-type.ts +1 -0
  543. package/src/types/class-parent.ts +14 -0
  544. package/src/types/config-flags.ts +5 -0
  545. package/src/types/conflict-child-element.ts +11 -0
  546. package/src/types/conflict-grouped-element.ts +7 -0
  547. package/src/types/conflict-grouped-elements.ts +5 -0
  548. package/src/types/construct-name.ts +11 -0
  549. package/src/types/dependency-map.ts +4 -0
  550. package/src/types/dependency.ts +16 -0
  551. package/src/types/environment.ts +1 -0
  552. package/src/types/file-info.ts +14 -0
  553. package/src/types/generate-config.ts +35 -0
  554. package/src/types/generator-type.ts +4 -0
  555. package/src/types/gir-alias-element.ts +15 -0
  556. package/src/types/gir-annotation.ts +10 -0
  557. package/src/types/gir-any-element.ts +35 -0
  558. package/src/types/gir-any-type.ts +7 -0
  559. package/src/types/gir-array-type.ts +23 -0
  560. package/src/types/gir-bitfield-element.ts +20 -0
  561. package/src/types/gir-boolean.ts +1 -0
  562. package/src/types/gir-boxed-element.ts +19 -0
  563. package/src/types/gir-c-include.ts +7 -0
  564. package/src/types/gir-callable-attrs.ts +19 -0
  565. package/src/types/gir-callable-param-element.ts +45 -0
  566. package/src/types/gir-callable-param.ts +9 -0
  567. package/src/types/gir-callable-return.ts +25 -0
  568. package/src/types/gir-callback-element.ts +28 -0
  569. package/src/types/gir-class-element.ts +71 -0
  570. package/src/types/gir-constant-element.ts +17 -0
  571. package/src/types/gir-constructor-element.ts +18 -0
  572. package/src/types/gir-direction.ts +5 -0
  573. package/src/types/gir-doc-element.ts +73 -0
  574. package/src/types/gir-enum-element.ts +28 -0
  575. package/src/types/gir-field-element.ts +31 -0
  576. package/src/types/gir-function-element.ts +19 -0
  577. package/src/types/gir-implements.ts +9 -0
  578. package/src/types/gir-include.ts +9 -0
  579. package/src/types/gir-info-attrs.ts +16 -0
  580. package/src/types/gir-info-elements.ts +8 -0
  581. package/src/types/gir-instance-parameter.ts +25 -0
  582. package/src/types/gir-interface-element.ts +53 -0
  583. package/src/types/gir-member-element.ts +19 -0
  584. package/src/types/gir-method-element.ts +25 -0
  585. package/src/types/gir-module-resolved-by.ts +11 -0
  586. package/src/types/gir-modules-grouped-map.ts +5 -0
  587. package/src/types/gir-modules-grouped.ts +13 -0
  588. package/src/types/gir-namespace.ts +47 -0
  589. package/src/types/gir-package.ts +7 -0
  590. package/src/types/gir-prerequisite.ts +5 -0
  591. package/src/types/gir-property-element.ts +31 -0
  592. package/src/types/gir-record-element.ts +47 -0
  593. package/src/types/gir-repository.ts +20 -0
  594. package/src/types/gir-signal.ts +43 -0
  595. package/src/types/gir-transfer-ownership-type.ts +5 -0
  596. package/src/types/gir-transfer-ownership.ts +6 -0
  597. package/src/types/gir-type.ts +16 -0
  598. package/src/types/gir-union-element.ts +35 -0
  599. package/src/types/gir-unparsed-number.ts +2 -0
  600. package/src/types/gir-var-args.ts +6 -0
  601. package/src/types/gir-virtual-method.ts +22 -0
  602. package/src/types/index.ts +120 -0
  603. package/src/types/inheritance-table.ts +3 -0
  604. package/src/types/injection-callback.ts +20 -0
  605. package/src/types/injection-class.ts +30 -0
  606. package/src/types/injection-function.ts +31 -0
  607. package/src/types/injection-generic-parameter.ts +3 -0
  608. package/src/types/injection-instance-parameter.ts +3 -0
  609. package/src/types/injection-parameter.ts +9 -0
  610. package/src/types/injection-property.ts +7 -0
  611. package/src/types/injection-type.ts +3 -0
  612. package/src/types/injection.ts +6 -0
  613. package/src/types/local-name-check.ts +5 -0
  614. package/src/types/local-name-type.ts +1 -0
  615. package/src/types/local-name.ts +8 -0
  616. package/src/types/local-names.ts +5 -0
  617. package/src/types/module-type.ts +1 -0
  618. package/src/types/parsed-gir.ts +5 -0
  619. package/src/types/part-of-class.ts +9 -0
  620. package/src/types/part-of-module.ts +8 -0
  621. package/src/types/promisify-func.ts +9 -0
  622. package/src/types/resolve-type.ts +4 -0
  623. package/src/types/sym-table-items.ts +5 -0
  624. package/src/types/transformation-case.ts +7 -0
  625. package/src/types/transformations.ts +12 -0
  626. package/src/types/ts-alias.ts +11 -0
  627. package/src/types/ts-callback-interface.ts +11 -0
  628. package/src/types/ts-callback.ts +21 -0
  629. package/src/types/ts-class.ts +109 -0
  630. package/src/types/ts-doc-tag.ts +23 -0
  631. package/src/types/ts-doc.ts +18 -0
  632. package/src/types/ts-enum.ts +15 -0
  633. package/src/types/ts-function.ts +70 -0
  634. package/src/types/ts-generic-parameter.ts +8 -0
  635. package/src/types/ts-instance-parameter.ts +4 -0
  636. package/src/types/ts-member.ts +11 -0
  637. package/src/types/ts-method.ts +6 -0
  638. package/src/types/ts-parameter.ts +20 -0
  639. package/src/types/ts-property.ts +22 -0
  640. package/src/types/ts-signal.ts +21 -0
  641. package/src/types/ts-type-name.ts +1 -0
  642. package/src/types/ts-type-separator.ts +1 -0
  643. package/src/types/ts-type.ts +28 -0
  644. package/src/types/ts-var.ts +21 -0
  645. package/src/types/type-gir-alias.ts +2 -0
  646. package/src/types/type-gir-class.ts +2 -0
  647. package/src/types/type-gir-element.ts +25 -0
  648. package/src/types/type-gir-enumeration-member.ts +2 -0
  649. package/src/types/type-gir-enumeration.ts +2 -0
  650. package/src/types/type-gir-function.ts +8 -0
  651. package/src/types/type-gir-interface.ts +2 -0
  652. package/src/types/type-gir-method.ts +2 -0
  653. package/src/types/type-gir-parameter.ts +1 -0
  654. package/src/types/type-gir-property.ts +2 -0
  655. package/src/types/type-gir-variable.ts +1 -0
  656. package/src/types/type-ts-element.ts +13 -0
  657. package/src/types/type-ts-enumeration-member.ts +2 -0
  658. package/src/types/type-ts-function.ts +1 -0
  659. package/src/types/type-ts-property.ts +1 -0
  660. package/src/types/user-config-load-result.ts +6 -0
  661. package/src/types/user-config.ts +43 -0
  662. package/src/utils.ts +433 -0
  663. package/templates/Cogl-2.0.d.ts +0 -0
  664. package/templates/Gjs/GObject-2.0.d.ts +238 -0
  665. package/templates/Gjs/Gio-2.0.d.ts +101 -0
  666. package/templates/Gjs/Gjs.d.ts +204 -0
  667. package/templates/Gjs/Gjs.js +21 -0
  668. package/templates/Gjs/GnomeShell.d.ts +154 -0
  669. package/templates/Gjs/GnomeShell.js +10 -0
  670. package/templates/Gjs/index.d.ts +594 -0
  671. package/templates/Gjs/index.js +4 -0
  672. package/templates/Gjs/misc/dbusUtils.d.ts +15 -0
  673. package/templates/Gjs/misc/dbusUtils.js +6 -0
  674. package/templates/Gjs/misc/extensionUtils.d.ts +99 -0
  675. package/templates/Gjs/misc/extensionUtils.js +6 -0
  676. package/templates/Gjs/misc/fileUtils.d.ts +51 -0
  677. package/templates/Gjs/misc/fileUtils.js +6 -0
  678. package/templates/Gjs/misc/gnomeSession.d.ts +74 -0
  679. package/templates/Gjs/misc/gnomeSession.js +6 -0
  680. package/templates/Gjs/misc/parentalControlsManager.d.ts +42 -0
  681. package/templates/Gjs/misc/parentalControlsManager.js +6 -0
  682. package/templates/Gjs/misc/signals.d.ts +15 -0
  683. package/templates/Gjs/misc/signals.js +6 -0
  684. package/templates/Gjs/module.d.ts +6 -0
  685. package/templates/Gjs/module.js +16 -0
  686. package/templates/Gjs/tsconfig.alias.json +10 -0
  687. package/templates/Gjs/ui/accessDialog.d.ts +19 -0
  688. package/templates/Gjs/ui/accessDialog.js +6 -0
  689. package/templates/Gjs/ui/altTab.d.ts +124 -0
  690. package/templates/Gjs/ui/altTab.js +6 -0
  691. package/templates/Gjs/ui/animation.d.ts +58 -0
  692. package/templates/Gjs/ui/animation.js +6 -0
  693. package/templates/Gjs/ui/appDisplay.d.ts +204 -0
  694. package/templates/Gjs/ui/appDisplay.js +6 -0
  695. package/templates/Gjs/ui/appFavorites.d.ts +34 -0
  696. package/templates/Gjs/ui/appFavorites.js +6 -0
  697. package/templates/Gjs/ui/appMenu.d.ts +74 -0
  698. package/templates/Gjs/ui/appMenu.js +6 -0
  699. package/templates/Gjs/ui/audioDeviceSelection.d.ts +51 -0
  700. package/templates/Gjs/ui/audioDeviceSelection.js +6 -0
  701. package/templates/Gjs/ui/background.d.ts +255 -0
  702. package/templates/Gjs/ui/background.js +5 -0
  703. package/templates/Gjs/ui/backgroundMenu.d.ts +19 -0
  704. package/templates/Gjs/ui/backgroundMenu.js +5 -0
  705. package/templates/Gjs/ui/barLevel.d.ts +42 -0
  706. package/templates/Gjs/ui/barLevel.js +5 -0
  707. package/templates/Gjs/ui/boxpointer.d.ts +103 -0
  708. package/templates/Gjs/ui/boxpointer.js +5 -0
  709. package/templates/Gjs/ui/calendar.d.ts +261 -0
  710. package/templates/Gjs/ui/calendar.js +5 -0
  711. package/templates/Gjs/ui/checkBox.d.ts +22 -0
  712. package/templates/Gjs/ui/checkBox.js +5 -0
  713. package/templates/Gjs/ui/closeDialog.d.ts +40 -0
  714. package/templates/Gjs/ui/closeDialog.js +5 -0
  715. package/templates/Gjs/ui/components/__init__.d.ts +9 -0
  716. package/templates/Gjs/ui/components/__init__.js +6 -0
  717. package/templates/Gjs/ui/components/automountManager.d.ts +8 -0
  718. package/templates/Gjs/ui/components/automountManager.js +6 -0
  719. package/templates/Gjs/ui/components/autorunManager.d.ts +8 -0
  720. package/templates/Gjs/ui/components/autorunManager.js +6 -0
  721. package/templates/Gjs/ui/components/index.d.ts +6 -0
  722. package/templates/Gjs/ui/components/index.js +6 -0
  723. package/templates/Gjs/ui/components/keyring.d.ts +19 -0
  724. package/templates/Gjs/ui/components/keyring.js +6 -0
  725. package/templates/Gjs/ui/components/networkAgent.d.ts +10 -0
  726. package/templates/Gjs/ui/components/networkAgent.js +6 -0
  727. package/templates/Gjs/ui/components/polkitAgent.d.ts +19 -0
  728. package/templates/Gjs/ui/components/polkitAgent.js +6 -0
  729. package/templates/Gjs/ui/components/telepathyClient.d.ts +10 -0
  730. package/templates/Gjs/ui/components/telepathyClient.js +6 -0
  731. package/templates/Gjs/ui/dialog.d.ts +78 -0
  732. package/templates/Gjs/ui/dialog.js +6 -0
  733. package/templates/Gjs/ui/dnd.d.ts +127 -0
  734. package/templates/Gjs/ui/dnd.js +6 -0
  735. package/templates/Gjs/ui/iconGrid.d.ts +172 -0
  736. package/templates/Gjs/ui/iconGrid.js +6 -0
  737. package/templates/Gjs/ui/layout.d.ts +311 -0
  738. package/templates/Gjs/ui/layout.js +6 -0
  739. package/templates/Gjs/ui/main.d.ts +215 -0
  740. package/templates/Gjs/ui/main.js +6 -0
  741. package/templates/Gjs/ui/messageList.d.ts +113 -0
  742. package/templates/Gjs/ui/messageList.js +6 -0
  743. package/templates/Gjs/ui/messageTray.d.ts +423 -0
  744. package/templates/Gjs/ui/messageTray.js +6 -0
  745. package/templates/Gjs/ui/modalDialog.d.ts +96 -0
  746. package/templates/Gjs/ui/modalDialog.js +6 -0
  747. package/templates/Gjs/ui/mpris.d.ts +78 -0
  748. package/templates/Gjs/ui/mpris.js +6 -0
  749. package/templates/Gjs/ui/notificationDaemon.d.ts +5 -0
  750. package/templates/Gjs/ui/notificationDaemon.js +6 -0
  751. package/templates/Gjs/ui/panel.d.ts +65 -0
  752. package/templates/Gjs/ui/panel.js +6 -0
  753. package/templates/Gjs/ui/panelMenu.d.ts +51 -0
  754. package/templates/Gjs/ui/panelMenu.js +6 -0
  755. package/templates/Gjs/ui/popupMenu.d.ts +228 -0
  756. package/templates/Gjs/ui/popupMenu.js +6 -0
  757. package/templates/Gjs/ui/ripples.d.ts +44 -0
  758. package/templates/Gjs/ui/ripples.js +6 -0
  759. package/templates/Gjs/ui/search.d.ts +158 -0
  760. package/templates/Gjs/ui/search.js +6 -0
  761. package/templates/Gjs/ui/switcherPopup.d.ts +107 -0
  762. package/templates/Gjs/ui/switcherPopup.js +6 -0
  763. package/templates/Gjs/ui/userWidget.d.ts +13 -0
  764. package/templates/Gjs/ui/userWidget.js +6 -0
  765. package/templates/Granite-1.0.d.ts +7 -0
  766. package/templates/Granite-7.0.d.ts +7 -0
  767. package/templates/GstBase-0.10.d.ts +5 -0
  768. package/templates/RygelServer-2.6.d.ts +3 -0
  769. package/templates/node-gtk/GObject-2.0.d.ts +57 -0
  770. package/templates/node-gtk/index.d.ts +40 -0
  771. package/templates/node-gtk/index.js +9 -0
  772. package/templates/node-gtk/module.d.ts +6 -0
  773. package/templates/node-gtk/module.js +17 -0
@@ -0,0 +1,2953 @@
1
+ // TODO move this class into a web-worker? https://www.npmjs.com/package/web-worker
2
+
3
+ import {
4
+ Transformation,
5
+ C_TYPE_MAP,
6
+ FULL_TYPE_MAP,
7
+ POD_TYPE_MAP,
8
+ POD_TYPE_MAP_ARRAY,
9
+ IGNORE_GIR_TYPE_TS_DOC_TYPES,
10
+ } from './transformation.js'
11
+ import { STATIC_NAME_ALREADY_EXISTS, MAX_CLASS_PARENT_DEPTH } from './constants.js'
12
+ import { Logger } from './logger.js'
13
+ import { Injector } from './injection/injector.js'
14
+ import { GirFactory } from './gir-factory.js'
15
+ import { ConflictResolver } from './conflict-resolver.js'
16
+ import { DependencyManager } from './dependency-manager.js'
17
+ import {
18
+ NO_TSDATA,
19
+ WARN_NOT_FOUND_TYPE,
20
+ WARN_CONSTANT_ALREADY_EXPORTED,
21
+ WARN_DUPLICATE_SYMBOL,
22
+ WARN_DUPLICATE_PARAMETER,
23
+ WARN_DUPLICATE_ENUM_IDENTIFIER,
24
+ } from './messages.js'
25
+ import { isEqual, find, clone, girBool, removeNamespace, addNamespace, girElementIsIntrospectable } from './utils.js'
26
+ import { SymTable } from './symtable.js'
27
+ import type {
28
+ Dependency,
29
+ GirRepository,
30
+ GirNamespace,
31
+ GirAliasElement,
32
+ GirEnumElement,
33
+ GirMemberElement,
34
+ GirFunctionElement,
35
+ GirClassElement,
36
+ GirArrayType,
37
+ GirType,
38
+ GirCallableParams,
39
+ GirCallableParamElement,
40
+ GirVirtualMethodElement,
41
+ GirSignalElement,
42
+ GirCallableReturn,
43
+ GirRecordElement,
44
+ GirCallbackElement,
45
+ GirConstantElement,
46
+ GirBitfieldElement,
47
+ GirFieldElement,
48
+ GirMethodElement,
49
+ GirPropertyElement,
50
+ GirAnyElement,
51
+ GirUnionElement,
52
+ GirInstanceParameter,
53
+ GirInterfaceElement,
54
+ GirConstructorElement,
55
+ GirDocElement,
56
+ TypeGirVariable,
57
+ TypeGirClass,
58
+ TypeGirEnumerationMember,
59
+ LocalNameCheck,
60
+ LocalNameType,
61
+ LocalName,
62
+ LocalNames,
63
+ TsDoc,
64
+ TsDocTag,
65
+ TsClass,
66
+ TsMethod,
67
+ TsFunction,
68
+ TsProperty,
69
+ TsVar,
70
+ TsParameter,
71
+ TsInstanceParameter,
72
+ TsCallbackInterface,
73
+ TsMember,
74
+ TsEnum,
75
+ TsAlias,
76
+ TsType,
77
+ TsGenericParameter,
78
+ TsCallback,
79
+ InheritanceTable,
80
+ ParsedGir,
81
+ GenerateConfig,
82
+ ClassParent,
83
+ InjectionParameter,
84
+ TsSignal,
85
+ PromisifyFunc,
86
+ } from './types/index.js'
87
+
88
+ export class GirModule {
89
+ /**
90
+ * Array of all gir modules
91
+ */
92
+ static allGirModules: GirModule[] = []
93
+ /**
94
+ * E.g. 'Gtk'
95
+ */
96
+ namespace: string
97
+ /**
98
+ * E.g. '3.0'
99
+ */
100
+ version = '0.0'
101
+ /**
102
+ * E.g. 'Gtk-3.0'
103
+ */
104
+ packageName: string
105
+ /**
106
+ * E.g. 'Gtk30'
107
+ * Is used in the generated index.d.ts, for example: `import * as Gtk30 from "./Gtk-3.0.js";`
108
+ */
109
+ importName: string
110
+
111
+ dependencies: Dependency[] = []
112
+ private _transitiveDependencies: Dependency[] = []
113
+
114
+ set transitiveDependencies(deps: Dependency[]) {
115
+ this._transitiveDependencies = this.checkTransitiveDependencies(deps)
116
+ }
117
+
118
+ get transitiveDependencies(): Dependency[] {
119
+ return this._transitiveDependencies
120
+ }
121
+
122
+ get allDependencies(): Dependency[] {
123
+ return [...new Set([...this.dependencies, ...this.transitiveDependencies])]
124
+ }
125
+
126
+ repo: GirRepository
127
+ ns: GirNamespace = { $: { name: '', version: '0.0' } }
128
+ /**
129
+ * Used to find namespaces that are used in other modules
130
+ */
131
+ symTable: SymTable
132
+
133
+ transformation: Transformation
134
+
135
+ girFactory = new GirFactory()
136
+
137
+ dependencyManager: DependencyManager
138
+
139
+ conflictResolver: ConflictResolver
140
+
141
+ log: Logger
142
+
143
+ inject: Injector
144
+
145
+ extends?: string
146
+
147
+ /**
148
+ * To prevent constants from being exported twice, the names already exported are saved here for comparison.
149
+ * Please note: Such a case is only known for Zeitgeist-2.0 with the constant "ATTACHMENT"
150
+ */
151
+ constNames: { [varName: string]: GirConstantElement } = {}
152
+
153
+ constructor(xml: ParsedGir, private readonly config: GenerateConfig) {
154
+ this.repo = xml.repository
155
+
156
+ if (!this.repo.namespace || !this.repo.namespace.length) {
157
+ throw new Error(`Namespace not found!`)
158
+ }
159
+
160
+ this.dependencyManager = DependencyManager.getInstance(this.config)
161
+ this.dependencies = this.dependencyManager.fromGirIncludes(this.repo.include || [])
162
+ this.ns = this.repo.namespace[0]
163
+ this.namespace = this.ns.$.name
164
+ this.version = this.ns.$.version
165
+ this.packageName = `${this.namespace}-${this.version}`
166
+ this.transformation = new Transformation(this.packageName, config)
167
+ this.log = new Logger(config.environment, config.verbose, this.packageName || 'GirModule')
168
+ this.conflictResolver = new ConflictResolver(config.environment, config.verbose)
169
+ this.inject = new Injector(this.config.environment)
170
+ this.importName = this.transformation.transformModuleNamespaceName(this.packageName)
171
+
172
+ this.symTable = new SymTable(this.config, this.packageName, this.namespace)
173
+ }
174
+
175
+ private checkTransitiveDependencies(transitiveDependencies: Dependency[]) {
176
+ // Always pull in GObject-2.0, as we may need it for e.g. GObject-2.0.type
177
+ if (this.packageName !== 'GObject-2.0') {
178
+ if (!find(transitiveDependencies, (x) => x.packageName === 'GObject-2.0')) {
179
+ transitiveDependencies.push(this.dependencyManager.get('GObject', '2.0'))
180
+ }
181
+ }
182
+
183
+ // Add missing dependencies
184
+ if (this.packageName === 'UnityExtras-7.0') {
185
+ if (!find(transitiveDependencies, (x) => x.packageName === 'Unity-7.0')) {
186
+ transitiveDependencies.push(this.dependencyManager.get('Unity', '7.0'))
187
+ }
188
+ }
189
+ if (this.packageName === 'UnityExtras-6.0') {
190
+ if (!find(transitiveDependencies, (x) => x.packageName === 'Unity-6.0')) {
191
+ transitiveDependencies.push(this.dependencyManager.get('Unity', '6.0'))
192
+ }
193
+ }
194
+ if (this.packageName === 'GTop-2.0') {
195
+ if (!find(transitiveDependencies, (x) => x.packageName === 'GLib-2.0')) {
196
+ transitiveDependencies.push(this.dependencyManager.get('GLib', '2.0'))
197
+ }
198
+ }
199
+
200
+ return transitiveDependencies
201
+ }
202
+
203
+ private getTsDoc(girDoc: GirDocElement) {
204
+ const tsDoc: TsDoc = {
205
+ text: '',
206
+ tags: [],
207
+ }
208
+ if (girDoc.doc?.[0]?._) {
209
+ let text = girDoc.doc?.[0]?._ || ''
210
+ text = this.transformation.transformGirDocText(text)
211
+ tsDoc.text = text
212
+ }
213
+
214
+ return tsDoc
215
+ }
216
+
217
+ private getTsDocGirElementTags(tsTypeName?: string, girTypeName?: string): TsDocTag[] {
218
+ const tags: TsDocTag[] = []
219
+
220
+ if (!girTypeName || IGNORE_GIR_TYPE_TS_DOC_TYPES.includes(girTypeName)) {
221
+ return tags
222
+ }
223
+
224
+ tags.push({
225
+ tagName: girTypeName,
226
+ paramName: '',
227
+ text: '',
228
+ })
229
+
230
+ return tags
231
+ }
232
+
233
+ private getTsDocReturnTags(
234
+ girElement?:
235
+ | GirCallbackElement
236
+ | GirConstructorElement
237
+ | GirFunctionElement
238
+ | GirMethodElement
239
+ | GirSignalElement
240
+ | GirVirtualMethodElement,
241
+ ): TsDocTag[] {
242
+ const girReturnValue = girElement?.['return-value']?.[0]
243
+ if (!girReturnValue || !girReturnValue.doc?.[0]?._) {
244
+ return []
245
+ }
246
+ const returnTag: TsDocTag = {
247
+ tagName: 'returns',
248
+ paramName: '',
249
+ text: this.transformation.transformGirDocTagText(girReturnValue.doc[0]._),
250
+ }
251
+
252
+ return [returnTag]
253
+ }
254
+
255
+ private getTsDocInParamTags(inParams?: GirCallableParamElement[]): TsDocTag[] {
256
+ const tags: TsDocTag[] = []
257
+ if (!inParams?.length) {
258
+ return tags
259
+ }
260
+
261
+ for (const inParam of inParams) {
262
+ if (!inParam._tsData) {
263
+ throw new Error(NO_TSDATA('getTsDocInParamTags'))
264
+ }
265
+ if (!inParam._tsData?.doc) {
266
+ inParam._tsData.doc = this.getTsDoc(inParam)
267
+ }
268
+ if (inParam._tsData?.name) {
269
+ tags.push({
270
+ paramName: inParam._tsData.name,
271
+ tagName: 'param',
272
+ text: inParam._tsData.doc.text
273
+ ? this.transformation.transformGirDocTagText(inParam._tsData.doc.text)
274
+ : '',
275
+ })
276
+ }
277
+ }
278
+
279
+ return tags
280
+ }
281
+
282
+ private annotateFunctionArguments(
283
+ girFunc:
284
+ | GirMethodElement
285
+ | GirFunctionElement
286
+ | GirConstructorElement
287
+ | GirVirtualMethodElement
288
+ | GirCallbackElement
289
+ | GirSignalElement,
290
+ ): void {
291
+ const funcName = girFunc._fullSymName
292
+ if (funcName && girFunc.parameters) {
293
+ for (const girParams of girFunc.parameters) {
294
+ if (girParams.parameter) {
295
+ for (const girParam of girParams.parameter) {
296
+ girParam._module = this
297
+ if (girParam.$ && girParam.$.name) {
298
+ girParam._fullSymName = `${funcName}.${girParam.$.name}`
299
+ }
300
+ }
301
+ }
302
+ }
303
+ }
304
+ }
305
+
306
+ private annotateFunctionReturn(
307
+ girFunc:
308
+ | GirMethodElement
309
+ | GirFunctionElement
310
+ | GirConstructorElement
311
+ | GirVirtualMethodElement
312
+ | GirCallbackElement
313
+ | GirSignalElement,
314
+ ): void {
315
+ const retVals = girFunc['return-value']
316
+ if (retVals && girFunc._fullSymName)
317
+ for (const retVal of retVals) {
318
+ retVal._module = this
319
+ retVal.girTypeName = 'callable-return'
320
+ if (retVal.$ && retVal.$.name) {
321
+ retVal._fullSymName = `${girFunc._fullSymName}.${retVal.$.name}`
322
+ }
323
+ }
324
+ }
325
+
326
+ /**
327
+ * Functions which are not part of a class
328
+ * @param girFuncs
329
+ */
330
+ private annotateFunctions(girFuncs: GirFunctionElement[] | GirCallbackElement[]): void {
331
+ if (Array.isArray(girFuncs))
332
+ for (const girFunc of girFuncs) {
333
+ if (girFunc?.$?.name) {
334
+ // girFunc._girType = girType
335
+ girFunc._fullSymName = `${this.namespace}.${girFunc.$.name}`
336
+ this.annotateFunctionArguments(girFunc)
337
+ this.annotateFunctionReturn(girFunc)
338
+ }
339
+ }
340
+ }
341
+
342
+ /**
343
+ * Functions and methods of a class
344
+ */
345
+ private annotateMethods(
346
+ girClass: GirClassElement | GirRecordElement | GirInterfaceElement,
347
+ girFuncs:
348
+ | GirMethodElement[]
349
+ | GirFunctionElement[]
350
+ | GirConstructorElement[]
351
+ | GirVirtualMethodElement[]
352
+ | GirSignalElement[],
353
+ ): void {
354
+ if (Array.isArray(girFuncs))
355
+ for (const girFunc of girFuncs) {
356
+ if (girFunc?.$?.name) {
357
+ // girFunc._girType = girType
358
+ // girFunc._tsType = tsType
359
+ girFunc._class = girClass
360
+ const nsName = girClass ? girClass._fullSymName : this.namespace
361
+ if (nsName) girFunc._fullSymName = `${nsName}.${girFunc.$.name}`
362
+ this.annotateFunctionArguments(girFunc)
363
+ this.annotateFunctionReturn(girFunc)
364
+ }
365
+ }
366
+ }
367
+
368
+ /**
369
+ * Variables which are not part of a class
370
+ */
371
+ private annotateVariables(girVars: GirConstantElement[]): void {
372
+ for (const girVar of girVars) {
373
+ girVar._module = this
374
+ if (girVar.$ && girVar.$.name) {
375
+ girVar._fullSymName = `${this.namespace}.${girVar.$.name}`
376
+ }
377
+ }
378
+ }
379
+
380
+ private annotateFields(
381
+ girClass: GirClassElement | GirRecordElement | GirInterfaceElement | null,
382
+ girVars: GirPropertyElement[],
383
+ ): void
384
+
385
+ private annotateFields(
386
+ girClass: GirClassElement | GirRecordElement | GirInterfaceElement | null,
387
+ girVars: GirFieldElement[],
388
+ ): void
389
+
390
+ /**
391
+ * Fields are variables which are part of a class
392
+ * @see https://www.typescriptlang.org/docs/handbook/2/classes.html#fields
393
+ */
394
+ private annotateFields(
395
+ girClass: GirClassElement | GirRecordElement | GirInterfaceElement,
396
+ girVars: GirPropertyElement[] | GirFieldElement[],
397
+ ): void {
398
+ for (const girVar of girVars) {
399
+ const nsName = girClass ? girClass._fullSymName : this.namespace
400
+ girVar._module = this
401
+ if (girClass) {
402
+ girVar._class = girClass
403
+ }
404
+
405
+ if (girVar.$ && girVar.$.name && nsName) {
406
+ girVar._fullSymName = `${nsName}.${girVar.$.name}`
407
+ }
408
+ }
409
+ }
410
+
411
+ private annotateClass(girClass: GirClassElement, girTypeName: 'class'): void
412
+ private annotateClass(girClass: GirRecordElement, girTypeName: 'record'): void
413
+ private annotateClass(girClass: GirInterfaceElement, girTypeName: 'interface'): void
414
+
415
+ private annotateClass(girClass: GirClassElement | GirRecordElement | GirInterfaceElement) {
416
+ girClass._module = this
417
+ girClass._fullSymName = `${this.namespace}.${girClass.$.name}`
418
+
419
+ const constructors = Array.isArray(girClass.constructor) ? girClass.constructor : []
420
+ const signals = ((girClass as GirClassElement | GirInterfaceElement).signal ||
421
+ girClass['glib:signal'] ||
422
+ []) as GirSignalElement[]
423
+ const functions = girClass.function || []
424
+ const methods = girClass.method || []
425
+ const vMethods = (girClass as GirClassElement)['virtual-method'] || new Array<GirVirtualMethodElement>()
426
+ const properties = girClass.property
427
+ const fields = girClass.field
428
+
429
+ this.annotateMethods(girClass, constructors)
430
+ this.annotateMethods(girClass, functions)
431
+ this.annotateMethods(girClass, methods)
432
+ this.annotateMethods(girClass, vMethods)
433
+ this.annotateMethods(girClass, signals)
434
+ if (properties) this.annotateFields(girClass, properties)
435
+ if (fields) this.annotateFields(girClass, fields)
436
+ }
437
+
438
+ /**
439
+ * Annotates the custom `_module`, `_fullSymName` and `_girType` properties.
440
+ * Also registers the element on the `symTable`.
441
+ * @param girElements
442
+ * @param girType
443
+ */
444
+ private annotateAndRegisterGirElement(girElements: GirAnyElement[]): void {
445
+ for (const girElement of girElements) {
446
+ if (girElement?.$ && girElement.$.name) {
447
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
448
+ if (!girElementIsIntrospectable(girElement as any)) continue
449
+
450
+ girElement._module = this
451
+ girElement._fullSymName = `${this.namespace}.${girElement.$.name}`
452
+ if (this.symTable.get(this.allDependencies, girElement._fullSymName)) {
453
+ this.log.warn(WARN_DUPLICATE_SYMBOL(girElement._fullSymName))
454
+ }
455
+
456
+ this.symTable.set(this.allDependencies, girElement._fullSymName, girElement)
457
+ }
458
+ }
459
+ }
460
+
461
+ /**
462
+ * TODO: find better name for this method
463
+ * @param girVar
464
+ * @param fullTypeName
465
+ * @returns e.g.
466
+ * ```ts
467
+ * {
468
+ * namespace: "Gtk",
469
+ * resValue: "Gtk.Widget"
470
+ * }
471
+ *
472
+ */
473
+ private fullTypeLookup(
474
+ girVar:
475
+ | GirCallableParamElement
476
+ | GirCallableReturn
477
+ | GirFieldElement
478
+ | GirAliasElement
479
+ | GirFieldElement
480
+ | GirPropertyElement
481
+ | GirConstantElement,
482
+ fullTypeName: string | null,
483
+ ) {
484
+ let resValue = ''
485
+ let namespace = ''
486
+
487
+ if (!fullTypeName) {
488
+ return {
489
+ value: resValue,
490
+ fullTypeName,
491
+ namespace,
492
+ }
493
+ }
494
+
495
+ // Fully qualify our type name
496
+ if (!fullTypeName.includes('.')) {
497
+ let tryFullTypeName = ''
498
+
499
+ if (!resValue && girVar._module && girVar._module !== this) {
500
+ tryFullTypeName = `${girVar._module.namespace}.${fullTypeName}`
501
+ resValue = this.fullTypeLookupWithNamespace(tryFullTypeName).value
502
+ if (resValue) {
503
+ fullTypeName = tryFullTypeName
504
+ namespace = girVar._module.namespace
505
+ }
506
+ }
507
+
508
+ if (!resValue) {
509
+ tryFullTypeName = `${this.namespace}.${fullTypeName}`
510
+ resValue = this.fullTypeLookupWithNamespace(tryFullTypeName).value
511
+ if (resValue) {
512
+ fullTypeName = tryFullTypeName
513
+ namespace = this.namespace
514
+ }
515
+ }
516
+
517
+ const girClass = (
518
+ girVar as
519
+ | GirCallableParamElement
520
+ | GirCallableReturn
521
+ | GirFieldElement
522
+ | GirAliasElement
523
+ | GirFieldElement
524
+ | GirPropertyElement
525
+ )._class as GirClassElement | undefined
526
+
527
+ if (!resValue && girClass?._module?.namespace && girClass._module !== this) {
528
+ tryFullTypeName = `${girClass._module.namespace}.${fullTypeName}`
529
+ resValue = this.fullTypeLookupWithNamespace(tryFullTypeName).value
530
+ if (resValue) {
531
+ fullTypeName = tryFullTypeName
532
+ namespace = girClass?._module?.namespace
533
+ }
534
+ }
535
+ }
536
+
537
+ if (!resValue && fullTypeName) {
538
+ resValue = this.fullTypeLookupWithNamespace(fullTypeName).value
539
+ }
540
+
541
+ return {
542
+ value: resValue,
543
+ namespace,
544
+ }
545
+ }
546
+
547
+ /**
548
+ * this method needs to be refactored, an array can also be an array of an array for example
549
+ * @param girVar
550
+ * @returns
551
+ */
552
+ getArrayData(
553
+ girVar:
554
+ | GirCallableReturn
555
+ | GirAliasElement
556
+ | GirFieldElement
557
+ | GirCallableParamElement
558
+ | GirPropertyElement
559
+ | GirConstantElement,
560
+ ) {
561
+ let arrayType: GirType | null = null
562
+ let arrCType: string | undefined
563
+ let isArray = false
564
+ let overrideTypeName: string | undefined
565
+ let typeArray: GirType[] | undefined
566
+
567
+ let collection: GirArrayType[] | GirType[] | undefined
568
+
569
+ if ((girVar as GirCallableReturn | GirFieldElement).array) {
570
+ collection = (girVar as GirCallableReturn | GirFieldElement).array
571
+ } else if (/^GLib.S?List$/.test(girVar.type?.[0].$?.name || '')) {
572
+ // This converts GLib.List<T> / GLib.SList<T> to T[]
573
+ collection = girVar.type
574
+ }
575
+
576
+ if (collection && collection.length > 0) {
577
+ isArray = true
578
+ typeArray = collection[0].type
579
+ if (collection[0].$) {
580
+ const ea = collection[0].$
581
+ arrCType = ea['c:type']
582
+ }
583
+ }
584
+
585
+ if (typeArray && typeArray?.length > 0) {
586
+ arrayType = typeArray[0]
587
+ }
588
+
589
+ if (isArray && arrayType?.$?.name && POD_TYPE_MAP_ARRAY[arrayType.$.name]) {
590
+ isArray = false
591
+ overrideTypeName = POD_TYPE_MAP_ARRAY[arrayType.$.name] as string | undefined
592
+ }
593
+
594
+ return {
595
+ arrCType,
596
+ arrayType,
597
+ isArray,
598
+ overrideTypeName,
599
+ }
600
+ }
601
+
602
+ /**
603
+ * Get the typescript type of a GirElement like a `GirPropertyElement` or `GirCallableReturn`
604
+ * @param girVar
605
+ */
606
+ private getTsType(
607
+ girVar:
608
+ | GirCallableReturn
609
+ | GirAliasElement
610
+ | GirFieldElement
611
+ | GirCallableParamElement
612
+ | GirPropertyElement
613
+ | GirConstantElement,
614
+ tsClass: TsClass | null,
615
+ defaults: Partial<TsType> = {},
616
+ ) {
617
+ let type: GirType | undefined = girVar.type?.[0]
618
+ let fullTypeName: string | null = null
619
+ let typeName = defaults.type || ''
620
+ let isFunction = defaults.isFunction || false
621
+ let isCallback = defaults.isCallback || false
622
+ const nullable = this.typeIsNullable(girVar) || defaults.nullable || false
623
+ const optional = this.typeIsOptional(girVar) || defaults.optional || false
624
+
625
+ const girCallbacks: GirCallbackElement[] = []
626
+ const array = this.getArrayData(girVar)
627
+
628
+ if (array.overrideTypeName) {
629
+ typeName = array.overrideTypeName
630
+ }
631
+
632
+ if (array.arrayType) {
633
+ type = array.arrayType
634
+ }
635
+
636
+ const cType = type?.$ ? type.$['c:type'] : array.arrCType
637
+ fullTypeName = type?.$?.name || null
638
+ const callbacks = (girVar as GirFieldElement).callback
639
+
640
+ if (!typeName && callbacks?.length) {
641
+ for (const girCallback of callbacks) {
642
+ if (!girElementIsIntrospectable(girCallback)) continue
643
+
644
+ if (!girCallback._tsData) {
645
+ const tsCallback = this.getFunctionTsData(girCallback, 'callback', tsClass, {
646
+ isStatic: false,
647
+ isArrowType: true,
648
+ isGlobal: false,
649
+ isVirtual: false,
650
+ returnType: null,
651
+ generics: [],
652
+ })
653
+
654
+ if (!tsCallback) continue
655
+
656
+ girCallback._tsData = {
657
+ ...tsCallback,
658
+ girTypeName: 'callback',
659
+ tsTypeName: this.girFactory.girTypeNameToTsTypeName('callback', false),
660
+ tsCallbackInterface: this.getCallbackInterfaceTsData(girCallback),
661
+ doc: this.getTsDoc(girCallback),
662
+ overloads: [],
663
+ }
664
+ }
665
+
666
+ if (girCallback._tsData) {
667
+ girCallbacks.push(girCallback)
668
+ isFunction = true
669
+ isCallback = true
670
+ }
671
+ }
672
+ }
673
+
674
+ if (!isFunction) {
675
+ const res = this.fullTypeLookup(girVar, fullTypeName)
676
+ if (res.value) {
677
+ typeName = res.value
678
+ fullTypeName = typeName
679
+ }
680
+ }
681
+
682
+ if (!typeName && type?.$?.name && POD_TYPE_MAP[type.$.name]) {
683
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
684
+ typeName = POD_TYPE_MAP[type.$.name]
685
+ }
686
+
687
+ if (cType) {
688
+ if (!typeName && C_TYPE_MAP(cType)) {
689
+ typeName = C_TYPE_MAP(cType) || ''
690
+ }
691
+
692
+ if (!typeName && POD_TYPE_MAP[cType]) {
693
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
694
+ typeName = POD_TYPE_MAP[cType]
695
+ }
696
+ }
697
+
698
+ if (!typeName) {
699
+ typeName = 'any'
700
+ const logName = cType || fullTypeName || girVar.$.name || ''
701
+ this.log.warn(WARN_NOT_FOUND_TYPE(logName))
702
+ }
703
+
704
+ // TODO: transform array to type with generics?
705
+ const tsType = this.girFactory.newTsType({
706
+ ...defaults,
707
+ type: typeName,
708
+ optional,
709
+ nullable,
710
+ callbacks: girCallbacks,
711
+ isArray: array.isArray,
712
+ isFunction,
713
+ isCallback,
714
+ })
715
+
716
+ return tsType
717
+ }
718
+
719
+ /**
720
+ *
721
+ * @param girFunc
722
+ * @returns
723
+ */
724
+ private getReturnType(
725
+ girFunc:
726
+ | GirMethodElement
727
+ | GirFunctionElement
728
+ | GirConstructorElement
729
+ | GirCallbackElement
730
+ | GirSignalElement
731
+ | GirVirtualMethodElement,
732
+ tsClass: TsClass | null,
733
+ generics: TsGenericParameter[] = [],
734
+ ) {
735
+ let outArrayLengthIndex = -1
736
+
737
+ if (girFunc['return-value'] && girFunc['return-value'].length > 1) {
738
+ throw new Error('Several return values found!')
739
+ }
740
+
741
+ // There are no multiple return values, so we always use index 0
742
+ const girVar = girFunc['return-value']?.[0] || null
743
+
744
+ // We still use an array to allow multiple return values for later
745
+ const returnTypes: TsType[] = []
746
+
747
+ if (girVar) {
748
+ returnTypes.push(this.getTsType(girVar, tsClass, { generics }))
749
+
750
+ outArrayLengthIndex = girVar.array && girVar.array[0].$?.length ? Number(girVar.array[0].$.length) : -1
751
+ } else {
752
+ returnTypes.push(this.girFactory.newTsType({ type: 'void', generics }))
753
+ }
754
+
755
+ const retTypeIsVoid = returnTypes.length === 1 && returnTypes[0].type === 'void'
756
+
757
+ return { returnTypes, outArrayLengthIndex, retTypeIsVoid }
758
+ }
759
+
760
+ private arrayLengthIndexLookup(girVar: GirCallableParamElement): number {
761
+ if (!girVar.array) return -1
762
+
763
+ const arr: GirArrayType = girVar.array[0]
764
+ if (!arr.$) return -1
765
+
766
+ if (arr.$.length) {
767
+ return parseInt(arr.$.length)
768
+ }
769
+
770
+ return -1
771
+ }
772
+
773
+ private closureDataIndexLookup(girVar: GirCallableParamElement): number {
774
+ if (!girVar.$.closure) return -1
775
+
776
+ return parseInt(girVar.$.closure)
777
+ }
778
+
779
+ private destroyDataIndexLookup(girVar: GirCallableParamElement): number {
780
+ if (!girVar.$.destroy) return -1
781
+
782
+ return parseInt(girVar.$.destroy)
783
+ }
784
+
785
+ private processParams(
786
+ params: GirCallableParamElement[],
787
+ skip: GirCallableParamElement[],
788
+ getIndex: (param: GirCallableParamElement) => number,
789
+ ): void {
790
+ for (const param of params) {
791
+ const index = getIndex(param)
792
+ if (index < 0) continue
793
+ if (index >= params.length) continue
794
+ skip.push(params[index])
795
+ }
796
+ }
797
+
798
+ /**
799
+ * Checks if the parameter is nullable (which results in ` | null`).
800
+ *
801
+ * @param girVar girVar to test
802
+ */
803
+ private typeIsNullable(
804
+ girVar:
805
+ | GirCallableParamElement
806
+ | GirCallableReturn
807
+ | GirAliasElement
808
+ | GirFieldElement
809
+ | GirConstantElement
810
+ | GirPropertyElement,
811
+ ): boolean {
812
+ const a = (girVar as GirCallableParamElement).$
813
+
814
+ if (!a) return false
815
+
816
+ // Ignore depreciated `allow-none` if one of the new implementation `optional` or `nullable` is set
817
+ if (girBool(a.optional) || girBool(a.nullable)) {
818
+ return girBool(a.nullable)
819
+ } else {
820
+ return girBool(a.nullable) || girBool(a['allow-none'])
821
+ }
822
+ }
823
+
824
+ /**
825
+ * Checks if the parameter is optional (which results in `foo?: bar`).
826
+ * @param girVar girVar to test
827
+ */
828
+ private typeIsOptional(
829
+ girVar:
830
+ | GirCallableParamElement
831
+ | GirCallableReturn
832
+ | GirAliasElement
833
+ | GirFieldElement
834
+ | GirConstantElement
835
+ | GirPropertyElement,
836
+ ): boolean {
837
+ const a = (girVar as GirCallableParamElement).$
838
+ if (!a) return false
839
+
840
+ // Ignore depreciated `allow-none` if one of the new implementation `optional` or `nullable` is set
841
+ if (girBool(a.optional) || girBool(a.nullable)) {
842
+ return girBool(a.optional)
843
+ } else {
844
+ return girBool(a.optional) || girBool(a['allow-none'])
845
+ }
846
+ }
847
+
848
+ private setParameterTsData(
849
+ girParam: GirCallableParamElement,
850
+ girParams: GirCallableParamElement[],
851
+ paramNames: string[],
852
+ skip: GirCallableParamElement[],
853
+ parent: TsFunction | TsSignal,
854
+ ) {
855
+ // I think it's safest to force inout params to have the
856
+ // same type for in and out
857
+ const tsType = this.getTsType(girParam, parent.parent)
858
+ // const optDirection = girParam.$.direction
859
+
860
+ if (girParam._tsData) {
861
+ // this.log.warn('[setParameterTsData] _tsData already set!')
862
+ return girParam._tsData
863
+ }
864
+
865
+ if (tsType.isCallback) {
866
+ throw new Error('Callback type is not implemented here')
867
+ }
868
+
869
+ let paramName = this.transformation.transformParameterName(girParam, false)
870
+
871
+ if (paramNames.includes(paramName)) {
872
+ this.log.warn(WARN_DUPLICATE_PARAMETER(paramName, girParam._fullSymName))
873
+ paramName += '_'
874
+ }
875
+ paramNames.push(paramName)
876
+
877
+ // In Typescript no optional parameters are allowed if the following ones are not optional
878
+ if (tsType.optional) {
879
+ const index = girParams.indexOf(girParam)
880
+ const following = girParams
881
+ .slice(index)
882
+ .filter(() => skip.indexOf(girParam) === -1)
883
+ .filter((p) => p.$.direction !== 'out')
884
+
885
+ if (following.some((p) => !this.typeIsOptional(p))) {
886
+ tsType.optional = false
887
+ }
888
+ }
889
+
890
+ const tsParam: TsParameter = {
891
+ name: paramName,
892
+ type: [tsType],
893
+ isRest: false,
894
+ girTypeName: 'callable-param',
895
+ doc: this.getTsDoc(girParam),
896
+ parent,
897
+ }
898
+
899
+ girParam._tsData = tsParam
900
+
901
+ // // TODO: remove this, wee need a special solution for Gio.AsyncReadyCallback instead
902
+ girParam = this.inject.toParameterType(girParam)
903
+
904
+ return girParam._tsData
905
+ }
906
+
907
+ private getInstanceParameterTsData(instanceParameter: GirInstanceParameter): TsInstanceParameter | undefined {
908
+ const typeName = instanceParameter.type?.[0]?.$?.name || undefined
909
+ const rec = typeName ? this.ns.record?.find((r) => r.$.name == typeName) : undefined
910
+ const structFor = rec?.$['glib:is-gtype-struct-for']
911
+ if (structFor && instanceParameter.$.name) {
912
+ // TODO: Should use of a constructor, and even of an instance, be discouraged?
913
+ return {
914
+ name: instanceParameter.$.name,
915
+ structFor,
916
+ }
917
+ }
918
+ return undefined
919
+ }
920
+
921
+ private setParametersTsData(
922
+ outArrayLengthIndex: number,
923
+ girParams: GirCallableParams[] = [],
924
+ parent: TsFunction | TsCallback,
925
+ ) {
926
+ const outParams: GirCallableParamElement[] = []
927
+ const inParams: GirCallableParamElement[] = []
928
+ const paramNames: string[] = []
929
+ const instanceParameters: GirInstanceParameter[] = []
930
+
931
+ if (girParams && girParams.length > 0) {
932
+ for (const girParam of girParams) {
933
+ const params = girParam?.parameter || []
934
+
935
+ // Instance parameter needs to be exposed for class methods (see comment above getClassMethods())
936
+ const instanceParameter = girParams[0]['instance-parameter']?.[0]
937
+ if (instanceParameter) {
938
+ instanceParameter._tsData = this.getInstanceParameterTsData(instanceParameter)
939
+ if (instanceParameter._tsData) {
940
+ instanceParameters.push(instanceParameter)
941
+ }
942
+ }
943
+ if (params.length) {
944
+ const skip = outArrayLengthIndex === -1 ? [] : [params[outArrayLengthIndex]]
945
+
946
+ this.processParams(params, skip, (girVar) => this.arrayLengthIndexLookup(girVar))
947
+ this.processParams(params, skip, (girVar) => this.closureDataIndexLookup(girVar))
948
+ this.processParams(params, skip, (girVar) => this.destroyDataIndexLookup(girVar))
949
+
950
+ for (const param of params) {
951
+ if (skip.includes(param)) {
952
+ continue
953
+ }
954
+
955
+ param._tsData = this.setParameterTsData(param, params, paramNames, skip, parent)
956
+
957
+ const optDirection = param.$.direction
958
+ if (optDirection === 'out' || optDirection === 'inout') {
959
+ outParams.push(param)
960
+ if (optDirection === 'out') continue
961
+ }
962
+ inParams.push(param)
963
+ }
964
+ }
965
+ }
966
+ }
967
+
968
+ return { outParams, paramNames, inParams, instanceParameters }
969
+ }
970
+
971
+ private getVariableTsData(
972
+ girVar: GirPropertyElement,
973
+ girTypeName: 'property',
974
+ tsTypeName: 'property' | 'constructor-property' | 'static-property',
975
+ tsClass: TsClass | null,
976
+ optional: boolean,
977
+ nullable: boolean,
978
+ allowQuotes: boolean,
979
+ ): GirPropertyElement['_tsData']
980
+
981
+ private getVariableTsData(
982
+ girVar: GirConstantElement,
983
+ girTypeName: 'constant',
984
+ tsTypeName: 'constant',
985
+ tsClass: TsClass | null,
986
+ optional: boolean,
987
+ nullable: boolean,
988
+ allowQuotes: boolean,
989
+ ): GirConstantElement['_tsData']
990
+
991
+ private getVariableTsData(
992
+ girVar: GirFieldElement,
993
+ girTypeName: 'field',
994
+ tsTypeName: 'property' | 'static-property',
995
+ tsClass: TsClass | null,
996
+ optional: boolean,
997
+ nullable: boolean,
998
+ allowQuotes: boolean,
999
+ ): GirFieldElement['_tsData']
1000
+
1001
+ private getVariableTsData(
1002
+ girVar: GirPropertyElement | GirFieldElement | GirConstantElement,
1003
+ girTypeName: 'property' | TypeGirVariable | 'field',
1004
+ tsTypeName: 'constant' | 'property' | 'constructor-property' | 'static-property',
1005
+ tsClass: TsClass | null,
1006
+ optional = false,
1007
+ nullable = false,
1008
+ allowQuotes = false,
1009
+ generics: TsGenericParameter[] = [],
1010
+ ) {
1011
+ if (!girVar.$.name) return undefined
1012
+ if (
1013
+ !girVar ||
1014
+ !girVar.$ ||
1015
+ !girBool(girVar.$.introspectable, true) ||
1016
+ girBool((girVar as GirFieldElement).$.private)
1017
+ ) {
1018
+ return undefined
1019
+ }
1020
+
1021
+ if (girVar._tsData) {
1022
+ // this.log.warn('[getVariableTsData] _tsData already set!')
1023
+ return girVar._tsData
1024
+ }
1025
+
1026
+ let name = girVar.$.name
1027
+
1028
+ switch (girTypeName) {
1029
+ case 'property':
1030
+ name = this.transformation.transformPropertyName(girVar.$.name, allowQuotes)
1031
+ break
1032
+ case 'constant':
1033
+ name = this.transformation.transformConstantName(girVar.$.name, allowQuotes)
1034
+ break
1035
+ case 'field':
1036
+ name = this.transformation.transformFieldName(girVar.$.name, allowQuotes)
1037
+ break
1038
+ }
1039
+ // Use the out type because it can be a union which isn't appropriate
1040
+ // for a property
1041
+ const tsType = this.getTsType(girVar, tsClass, { optional, nullable, generics })
1042
+
1043
+ const tsData: TsProperty | TsVar = {
1044
+ name,
1045
+ type: [tsType],
1046
+ isInjected: false,
1047
+ girTypeName,
1048
+ tsTypeName,
1049
+ doc: this.getTsDoc(girVar),
1050
+ }
1051
+
1052
+ tsData.doc.tags.push(...this.getTsDocGirElementTags(tsData.tsTypeName, tsData.girTypeName))
1053
+
1054
+ return tsData
1055
+ }
1056
+
1057
+ private getPropertyTsData(
1058
+ girProp: GirPropertyElement,
1059
+ girTypeName: 'property',
1060
+ tsTypeName: 'property' | 'constructor-property' | 'static-property',
1061
+ tsClass: TsClass,
1062
+ construct?: boolean,
1063
+ optional?: boolean,
1064
+ nullable?: boolean,
1065
+ indentCount?: number,
1066
+ ): TsProperty | undefined
1067
+
1068
+ private getPropertyTsData(
1069
+ girProp: GirFieldElement,
1070
+ girTypeName: 'field',
1071
+ tsTypeName: 'property' | 'static-property',
1072
+ tsClass: TsClass,
1073
+ construct?: boolean,
1074
+ optional?: boolean,
1075
+ nullable?: boolean,
1076
+ indentCount?: number,
1077
+ ): TsVar | undefined
1078
+
1079
+ /**
1080
+ *
1081
+ * @param girProp
1082
+ * @param girTypeName
1083
+ * @param tsTypeName
1084
+ * @param construct construct means include the property even if it's construct-only,
1085
+ * @param optional optional means if it's construct-only it will also be marked optional (?)
1086
+ * @param nullable
1087
+ * @returns
1088
+ */
1089
+ private getPropertyTsData(
1090
+ girProp: GirPropertyElement | GirFieldElement,
1091
+ girTypeName: 'property' | 'field',
1092
+ tsTypeName: 'constructor-property' | 'property' | 'static-property',
1093
+ tsClass: TsClass,
1094
+ construct = false,
1095
+ optional?: boolean,
1096
+ nullable?: boolean,
1097
+ ): TsProperty | undefined {
1098
+ if (!girBool(girProp.$.writable) && construct) return undefined
1099
+ if (girBool((girProp as GirFieldElement).$.private)) return undefined
1100
+
1101
+ if (girProp._tsData) {
1102
+ // this.log.warn('[getPropertyTsData] _tsData already set!')
1103
+ return girProp._tsData as TsProperty
1104
+ }
1105
+
1106
+ if (optional === undefined) optional = this.typeIsOptional(girProp)
1107
+ if (nullable === undefined) nullable = this.typeIsNullable(girProp)
1108
+
1109
+ const readonly =
1110
+ !girBool(girProp.$.writable) || (!construct && girBool((girProp as GirPropertyElement).$['construct-only']))
1111
+
1112
+ let tsData: TsProperty | undefined
1113
+
1114
+ switch (girTypeName) {
1115
+ case 'property':
1116
+ tsData = this.getVariableTsData(
1117
+ girProp as GirPropertyElement,
1118
+ girTypeName,
1119
+ tsTypeName,
1120
+ tsClass,
1121
+ construct && optional,
1122
+ construct && nullable,
1123
+ true,
1124
+ ) as TsProperty
1125
+ break
1126
+ case 'field':
1127
+ if (tsTypeName !== 'property') {
1128
+ throw new Error(`Wrong tsType: "${tsTypeName}" for girType: "${girTypeName}`)
1129
+ }
1130
+ tsData = this.getVariableTsData(
1131
+ girProp as GirFieldElement,
1132
+ girTypeName,
1133
+ tsTypeName,
1134
+ tsClass,
1135
+ construct && optional,
1136
+ construct && nullable,
1137
+ true,
1138
+ ) as TsProperty
1139
+ break
1140
+ default:
1141
+ throw new Error(`Unknown property type: ${girTypeName as string}`)
1142
+ }
1143
+
1144
+ if (!tsData?.name) {
1145
+ return undefined
1146
+ }
1147
+
1148
+ tsData = {
1149
+ ...tsData,
1150
+ readonly,
1151
+ }
1152
+ return tsData
1153
+ }
1154
+
1155
+ /**
1156
+ *
1157
+ * @param girFunc
1158
+ * @param prefix E.g. vfunc
1159
+ * @param overrideReturnType
1160
+ * @param isArrowType
1161
+ * @param indentCount
1162
+ */
1163
+ private getFunctionTsData(
1164
+ girFunc:
1165
+ | GirMethodElement
1166
+ | GirFunctionElement
1167
+ | GirConstructorElement
1168
+ | GirCallbackElement
1169
+ | GirVirtualMethodElement,
1170
+ girTypeName: 'virtual' | 'method' | 'constructor' | 'function' | 'callback' | 'static-function',
1171
+ tsClass: TsClass | null,
1172
+ overwrite: {
1173
+ isStatic: boolean
1174
+ isArrowType: boolean
1175
+ isGlobal: boolean
1176
+ isVirtual: boolean
1177
+ isInjected?: boolean
1178
+ returnType: string | null
1179
+ generics: TsGenericParameter[]
1180
+ },
1181
+ ): TsFunction | undefined {
1182
+ if (!girFunc || !girFunc.$ || !girBool(girFunc.$.introspectable, true) || girFunc.$['shadowed-by']) {
1183
+ return undefined
1184
+ }
1185
+
1186
+ let hasUnresolvedConflict: boolean | undefined
1187
+
1188
+ // TODO: Fix that we overwrite tsData every time seems wrong to me, but if I just return the already defined `_tsData` leads to problems with the overload methods
1189
+ if (girFunc._tsData) {
1190
+ hasUnresolvedConflict = girFunc._tsData?.hasUnresolvedConflict // WORKAROUND do not overwrite conflicts
1191
+ }
1192
+
1193
+ let name = girFunc.$.name
1194
+ const { returnTypes, outArrayLengthIndex, retTypeIsVoid } = this.getReturnType(girFunc, tsClass)
1195
+
1196
+ const shadows = (girFunc as GirMethodElement).$.shadows
1197
+
1198
+ if (shadows) {
1199
+ name = shadows
1200
+ }
1201
+
1202
+ // Overwrites
1203
+ overwrite.isStatic = overwrite.isStatic || girTypeName === 'static-function' || girTypeName === 'constructor'
1204
+ overwrite.isGlobal = overwrite.isGlobal || girTypeName === 'function'
1205
+ overwrite.isVirtual = overwrite.isVirtual || girTypeName === 'virtual'
1206
+ overwrite.isInjected = overwrite.isInjected || false
1207
+
1208
+ // Function name transformation by environment
1209
+ name = this.transformation.transformFunctionName(name, overwrite.isVirtual)
1210
+
1211
+ const tsData: TsFunction = {
1212
+ isArrowType: overwrite.isArrowType,
1213
+ isStatic: overwrite.isStatic,
1214
+ isGlobal: overwrite.isGlobal,
1215
+ isVirtual: overwrite.isVirtual,
1216
+ isInjected: overwrite.isInjected,
1217
+ returnTypes,
1218
+ retTypeIsVoid,
1219
+ name,
1220
+ overrideReturnType: overwrite.returnType || undefined,
1221
+ inParams: [],
1222
+ outParams: [],
1223
+ instanceParameters: [],
1224
+ generics: overwrite.generics,
1225
+ hasUnresolvedConflict,
1226
+ girTypeName,
1227
+ tsTypeName: this.girFactory.girTypeNameToTsTypeName(girTypeName, overwrite.isStatic),
1228
+ doc: this.getTsDoc(girFunc as GirDocElement),
1229
+ overloads: [],
1230
+ parent: tsClass,
1231
+ }
1232
+
1233
+ const { inParams, outParams, instanceParameters } = this.setParametersTsData(
1234
+ outArrayLengthIndex,
1235
+ girFunc.parameters,
1236
+ tsData,
1237
+ )
1238
+
1239
+ tsData.inParams.push(...inParams)
1240
+ tsData.outParams.push(...outParams)
1241
+ tsData.instanceParameters.push(...instanceParameters)
1242
+
1243
+ tsData.doc.tags.push(...this.getTsDocGirElementTags(tsData.tsTypeName, tsData.girTypeName))
1244
+ tsData.doc.tags.push(...this.getTsDocInParamTags(tsData?.inParams))
1245
+ tsData.doc.tags.push(...this.getTsDocReturnTags(girFunc))
1246
+
1247
+ return tsData
1248
+ }
1249
+
1250
+ overloadPromisifiedFunctions(girFunctions: GirFunctionElement[]): void {
1251
+ if (!this.config.promisify) return
1252
+
1253
+ const promisifyAsyncReturn = ['Gio.AsyncReadyCallback', 'AsyncReadyCallback']
1254
+ const promisifyFuncMap = {} as { [name: string]: PromisifyFunc }
1255
+
1256
+ // Find the functions that can be promisified
1257
+ for (const girFunction of girFunctions) {
1258
+ const tsFunction = girFunction._tsData
1259
+ if (!tsFunction) continue
1260
+
1261
+ // Check if function name satisfies async,finish scheme
1262
+ const isAsync = tsFunction.name.endsWith('_async') || tsFunction.name.endsWith('_begin')
1263
+ const isFinish = tsFunction.name.endsWith('_finish')
1264
+ if (!isAsync && !isFinish) continue
1265
+
1266
+ // Handle async functions
1267
+ if (isAsync) {
1268
+ if (tsFunction.inParams.length === 0) continue
1269
+ const lastParam = tsFunction.inParams[tsFunction.inParams.length - 1]
1270
+ if (lastParam.type && lastParam.type.length > 0) {
1271
+ const type = lastParam.type[0].$.name
1272
+ if (type && promisifyAsyncReturn.includes(type)) {
1273
+ if (!(tsFunction.name in promisifyFuncMap)) promisifyFuncMap[tsFunction.name] = {}
1274
+ promisifyFuncMap[tsFunction.name].asyncFn = tsFunction
1275
+ }
1276
+ }
1277
+ }
1278
+
1279
+ // Handle finish functions
1280
+ if (isFinish) {
1281
+ if (tsFunction.returnTypes.length === 0) continue
1282
+ let name = `${tsFunction.name.replace(/(_finish)$/, '')}_async`
1283
+ if (!(name in promisifyFuncMap)) name = `${tsFunction.name.replace(/(_finish)$/, '')}_begin`
1284
+ if (!(name in promisifyFuncMap)) promisifyFuncMap[name] = {}
1285
+ promisifyFuncMap[name].finishFn = tsFunction
1286
+ }
1287
+ }
1288
+
1289
+ // Generate TsFunctions for promisify-able functions and add to the array
1290
+ for (const [, func] of Object.entries(promisifyFuncMap)) {
1291
+ if (!func.asyncFn || !func.finishFn) continue
1292
+
1293
+ const inParams = this.girFactory.newGirCallableParamElements(
1294
+ func.asyncFn.inParams.slice(0, -1),
1295
+ func.asyncFn,
1296
+ )
1297
+
1298
+ const outParams = this.girFactory.newGirCallableParamElements(func.finishFn.outParams, func.asyncFn)
1299
+
1300
+ const returnTypes = this.girFactory.newTsTypes(outParams.length > 0 ? [] : func.finishFn.returnTypes)
1301
+
1302
+ let docReturnText = func.finishFn.doc.tags.find((tag) => tag.tagName === 'returns')?.text || ''
1303
+ if (docReturnText) {
1304
+ docReturnText = `A Promise of: ${docReturnText}`
1305
+ } else {
1306
+ docReturnText = `A Promise of the result of {@link ${func.asyncFn.name}}`
1307
+ }
1308
+
1309
+ const docText = `Promisified version of {@link ${func.asyncFn.name}}\n\n${func.asyncFn.doc.text}`
1310
+
1311
+ const docTags = func.asyncFn.doc.tags.filter(
1312
+ (tag) => tag.paramName !== 'callback' && tag.paramName !== 'returns',
1313
+ )
1314
+
1315
+ docTags.push({
1316
+ tagName: 'returns',
1317
+ text: docReturnText,
1318
+ paramName: '',
1319
+ })
1320
+
1321
+ const doc = this.girFactory.newTsDoc({
1322
+ text: docText,
1323
+ tags: docTags,
1324
+ })
1325
+
1326
+ const promisifyFn = this.girFactory.newTsFunction(
1327
+ {
1328
+ ...func.asyncFn,
1329
+ inParams,
1330
+ outParams,
1331
+ returnTypes,
1332
+ isPromise: true,
1333
+ doc,
1334
+ },
1335
+ func.asyncFn.parent,
1336
+ )
1337
+
1338
+ func.asyncFn.overloads.push(promisifyFn)
1339
+ }
1340
+ }
1341
+
1342
+ private getCallbackInterfaceTsData(girCallback: GirCallbackElement | GirConstructorElement) {
1343
+ if (!girElementIsIntrospectable(girCallback)) return undefined
1344
+
1345
+ const namespace = this.namespace
1346
+
1347
+ const tsDataInterface: TsCallbackInterface = {
1348
+ name: `${namespace}.${girCallback.$.name}`,
1349
+ generics: [],
1350
+ }
1351
+
1352
+ return tsDataInterface
1353
+ }
1354
+
1355
+ private setCallbackTsData(girCallback: GirCallbackElement, tsClass: TsClass | null) {
1356
+ const tsFunction = this.getFunctionTsData(girCallback, 'callback', tsClass, {
1357
+ isStatic: false,
1358
+ isArrowType: true,
1359
+ isGlobal: false,
1360
+ isVirtual: false,
1361
+ returnType: null,
1362
+ generics: [],
1363
+ })
1364
+ if (tsFunction) {
1365
+ const tsCallback: TsCallback = {
1366
+ ...tsFunction,
1367
+ girTypeName: 'callback',
1368
+ tsTypeName: this.girFactory.girTypeNameToTsTypeName('callback', false),
1369
+ tsCallbackInterface: this.getCallbackInterfaceTsData(girCallback),
1370
+ overloads: [],
1371
+ }
1372
+ girCallback._tsData = tsCallback
1373
+
1374
+ this.inject.toCallback(girCallback)
1375
+ }
1376
+ return girCallback._tsData
1377
+ }
1378
+
1379
+ private getSignalCallbackInterfaceTsData(
1380
+ girCallback: GirSignalElement,
1381
+ girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1382
+ ) {
1383
+ if (!girElementIsIntrospectable(girCallback)) return undefined
1384
+
1385
+ if (!girClass._tsData || !girClass._module) {
1386
+ throw new Error(NO_TSDATA('getSignalCallbackTsData'))
1387
+ }
1388
+
1389
+ const className = girClass._tsData.name
1390
+ const signalName = girCallback.$.name
1391
+ const signalInterfaceName = this.transformation.transformSignalInterfaceName(signalName)
1392
+ const namespace = girClass._module.namespace
1393
+
1394
+ const tsDataInterface: TsCallbackInterface = {
1395
+ name: `${namespace}.${className}.${signalInterfaceName}SignalCallback`,
1396
+ generics: [],
1397
+ overwriteDoc: {
1398
+ text: `Signal callback interface for \`${signalName}\``,
1399
+ tags: [],
1400
+ },
1401
+ }
1402
+
1403
+ return tsDataInterface
1404
+ }
1405
+
1406
+ private getConstructorFunctionTsData(parentClass: TsClass, girConstructor: GirConstructorElement) {
1407
+ if (!girElementIsIntrospectable(girConstructor)) return
1408
+
1409
+ const constructorTypeName = addNamespace(parentClass.name, parentClass.namespace)
1410
+
1411
+ return this.getFunctionTsData(girConstructor, 'constructor', parentClass, {
1412
+ isStatic: true,
1413
+ isArrowType: false,
1414
+ isGlobal: false,
1415
+ isVirtual: false,
1416
+ returnType: constructorTypeName,
1417
+ generics: [],
1418
+ })
1419
+ }
1420
+
1421
+ private getSignalCallbackTsData(
1422
+ girSignalFunc: GirSignalElement,
1423
+ girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1424
+ ) {
1425
+ if (!girClass._tsData) {
1426
+ throw new Error(NO_TSDATA('getSignalCallbackTsData'))
1427
+ }
1428
+
1429
+ if (girSignalFunc._tsData) {
1430
+ return girSignalFunc._tsData
1431
+ }
1432
+
1433
+ // Leads to errors here
1434
+ // if (!girElementIsIntrospectable(girSignalFunc)) return undefined
1435
+
1436
+ const name = this.transformation.transform('signalName', girSignalFunc.$.name)
1437
+
1438
+ const { returnTypes, outArrayLengthIndex, retTypeIsVoid } = this.getReturnType(girSignalFunc, girClass._tsData)
1439
+
1440
+ if (this.config.environment === 'node') {
1441
+ returnTypes[0].type === 'void'
1442
+ }
1443
+
1444
+ const tsCallback: TsCallback = {
1445
+ name, // TODO: 'callback'?
1446
+ returnTypes,
1447
+ isArrowType: true,
1448
+ isStatic: false,
1449
+ isGlobal: false,
1450
+ isVirtual: false,
1451
+ isInjected: false,
1452
+ retTypeIsVoid,
1453
+ inParams: [],
1454
+ instanceParameters: [],
1455
+ outParams: [],
1456
+ generics: [],
1457
+ girTypeName: 'callback',
1458
+ tsTypeName: this.girFactory.girTypeNameToTsTypeName('callback', false),
1459
+ doc: this.getTsDoc(girSignalFunc),
1460
+ overloads: [],
1461
+ parent: girClass._tsData,
1462
+ }
1463
+
1464
+ const { inParams, outParams, instanceParameters } = this.setParametersTsData(
1465
+ outArrayLengthIndex,
1466
+ girSignalFunc.parameters,
1467
+ tsCallback,
1468
+ )
1469
+
1470
+ if (this.config.environment === 'gjs') {
1471
+ inParams.unshift(
1472
+ this.girFactory.newGirCallableParamElement(
1473
+ {
1474
+ name: '$obj',
1475
+ type: [
1476
+ {
1477
+ type: girClass._tsData.name,
1478
+ },
1479
+ ],
1480
+ },
1481
+ tsCallback,
1482
+ ),
1483
+ )
1484
+ }
1485
+
1486
+ tsCallback.inParams.push(...inParams)
1487
+ tsCallback.outParams.push(...outParams)
1488
+ tsCallback.instanceParameters.push(...instanceParameters)
1489
+
1490
+ tsCallback.doc.tags.push(...this.getTsDocGirElementTags(tsCallback.tsTypeName, tsCallback.girTypeName))
1491
+ tsCallback.doc.tags.push(...this.getTsDocInParamTags(tsCallback?.inParams))
1492
+ tsCallback.doc.tags.push(...this.getTsDocReturnTags(girSignalFunc))
1493
+
1494
+ return tsCallback
1495
+ }
1496
+
1497
+ /**
1498
+ * Generates signal methods like `connect`, `connect_after` and `emit` on Gjs or `connect`, `on`, `once`, `off` and `emit` an node-gtk
1499
+ * for a default gir signal element
1500
+ * @param girSignal
1501
+ * @returns
1502
+ */
1503
+ private getClassSignalMethodsTsData(girSignal: GirSignalElement, parentClass: TsClass) {
1504
+ if (!girSignal._tsData) {
1505
+ throw new Error(NO_TSDATA('getClassSignalMethodsTsData'))
1506
+ }
1507
+
1508
+ const inParams = girSignal._tsData.inParams.slice(1).map((inParam) => {
1509
+ const injectParam: InjectionParameter = {
1510
+ ...inParam._tsData,
1511
+ type: inParam._tsData?.type || [],
1512
+ name: inParam._tsData?.name || 'unknown',
1513
+ }
1514
+ return injectParam
1515
+ })
1516
+
1517
+ return this.girFactory.newTsSignalMethods(
1518
+ girSignal._tsData?.name,
1519
+ girSignal._tsData?.tsCallbackInterface?.name,
1520
+ inParams,
1521
+ parentClass,
1522
+ this.config.environment,
1523
+ false,
1524
+ )
1525
+ }
1526
+
1527
+ /**
1528
+ * Generates signal methods for the GObject properties of a gir class element
1529
+ * @param girClass
1530
+ */
1531
+ private getClassPropertySignalsMethods(
1532
+ girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1533
+ ) {
1534
+ if (!girClass._tsData) {
1535
+ throw new Error(NO_TSDATA('getClassPropertySignalsMethods'))
1536
+ }
1537
+
1538
+ const tsMethods: TsMethod[] = []
1539
+
1540
+ const propertyNames = this.getClassNonStaticPropertyNames(girClass)
1541
+ const namespacePrefix = this.namespace === 'GObject' ? '' : 'GObject.'
1542
+
1543
+ // TODO: Signals: Generate SignalMethods instead of direct types
1544
+ for (const propertyName of propertyNames) {
1545
+ let callbackType = 'any'
1546
+ if (this.config.environment === 'gjs') {
1547
+ const objParam = `$obj: ${girClass._tsData.name}`
1548
+ // TODO: create arrowType object instead of a pure string type, see Pango-1.0.Pango.FontMapClass.load_font for an example
1549
+ callbackType = `((${objParam}, pspec: ${namespacePrefix}ParamSpec) => void)`
1550
+ } else if (this.config.environment === 'node') {
1551
+ callbackType = `(...args: any[]) => void`
1552
+ }
1553
+ tsMethods.push(
1554
+ ...this.girFactory.newTsSignalMethods(
1555
+ `notify::${propertyName}`,
1556
+ callbackType,
1557
+ [],
1558
+ girClass._tsData,
1559
+ this.config.environment,
1560
+ ),
1561
+ )
1562
+ }
1563
+
1564
+ return tsMethods
1565
+ }
1566
+
1567
+ private getGeneralSignalsMethods(parentClass: TsClass) {
1568
+ return this.girFactory.newTsSignalMethods(undefined, undefined, [], parentClass, this.config.environment, true)
1569
+ }
1570
+
1571
+ private setSignalTsData(
1572
+ girSignal: GirSignalElement,
1573
+ girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1574
+ ) {
1575
+ if (!girClass._tsData) {
1576
+ throw NO_TSDATA('setSignalTsData')
1577
+ }
1578
+
1579
+ if (!girSignal._tsData) {
1580
+ girSignal._tsData = {
1581
+ ...this.getSignalCallbackTsData(girSignal, girClass),
1582
+ tsCallbackInterface: this.getSignalCallbackInterfaceTsData(girSignal, girClass),
1583
+ tsMethods: [],
1584
+ girTypeName: 'signal',
1585
+ tsTypeName: this.girFactory.girTypeNameToTsTypeName('signal', false),
1586
+ doc: this.getTsDoc(girSignal),
1587
+ overloads: [],
1588
+ }
1589
+
1590
+ girSignal._tsData.doc.tags.push(
1591
+ ...this.getTsDocGirElementTags(girSignal._tsData.tsTypeName, girSignal._tsData.girTypeName),
1592
+ )
1593
+ // TODO: this are the callback parameters
1594
+ girSignal._tsData.doc.tags.push(...this.getTsDocInParamTags(girSignal._tsData?.inParams))
1595
+ girSignal._tsData.doc.tags.push(...this.getTsDocReturnTags(girSignal))
1596
+
1597
+ if (!girSignal._tsData) {
1598
+ throw NO_TSDATA('setSignalTsData')
1599
+ }
1600
+
1601
+ girSignal._tsData.tsMethods = this.getClassSignalMethodsTsData(girSignal, girClass._tsData)
1602
+ }
1603
+
1604
+ return girSignal._tsData
1605
+ }
1606
+
1607
+ private fixEnumerationDuplicateIdentifier(girEnum: GirEnumElement | GirBitfieldElement) {
1608
+ if (!girElementIsIntrospectable(girEnum)) return girEnum
1609
+
1610
+ if (!girEnum._tsData) {
1611
+ throw new Error(NO_TSDATA('fixEnumerationDuplicateIdentifier'))
1612
+ }
1613
+
1614
+ if (!girEnum.member?.length) {
1615
+ return girEnum
1616
+ }
1617
+
1618
+ const memberNames: string[] = []
1619
+
1620
+ for (const girEnumMember of girEnum.member) {
1621
+ if (!girEnumMember._tsData) {
1622
+ throw new Error(NO_TSDATA('fixEnumerationDuplicateIdentifier'))
1623
+ }
1624
+ if (memberNames.find((name) => name === girEnumMember._tsData?.name)) {
1625
+ const renamed = '_' + girEnumMember._tsData.name
1626
+ this.log.warn(WARN_DUPLICATE_ENUM_IDENTIFIER(girEnumMember._tsData.name, renamed))
1627
+ girEnumMember._tsData.name = renamed
1628
+ }
1629
+ memberNames.push(girEnumMember._tsData.name)
1630
+ }
1631
+ return girEnum
1632
+ }
1633
+
1634
+ private getEnumerationMemberTsData(girEnumMember: GirMemberElement, girTypeName: TypeGirEnumerationMember) {
1635
+ const memberName = girEnumMember.$.name || girEnumMember.$['glib:nick'] || girEnumMember.$['c:identifier']
1636
+ if (!girElementIsIntrospectable(girEnumMember, memberName)) return undefined
1637
+
1638
+ if (girEnumMember._tsData) {
1639
+ // this.log.warn('[getEnumerationMemberTsData] _tsData already set!')
1640
+ return girEnumMember._tsData
1641
+ }
1642
+
1643
+ const name = this.transformation.transformEnumMember(memberName)
1644
+ const tsData: TsMember = {
1645
+ name,
1646
+ girTypeName,
1647
+ tsTypeName: this.girFactory.girTypeNameToTsTypeName(girTypeName, false),
1648
+ doc: this.getTsDoc(girEnumMember),
1649
+ }
1650
+
1651
+ tsData.doc.tags.push(...this.getTsDocGirElementTags(tsData.tsTypeName, tsData.girTypeName))
1652
+
1653
+ return tsData
1654
+ }
1655
+
1656
+ private getEnumerationTsData(girEnum: GirEnumElement | GirBitfieldElement, girTypeName: 'bitfield' | 'enum') {
1657
+ if (!girElementIsIntrospectable(girEnum)) return undefined
1658
+
1659
+ if (girEnum._tsData) {
1660
+ // this.log.warn('[getEnumerationMemberTsData] _tsData already set!')
1661
+ return girEnum._tsData
1662
+ }
1663
+
1664
+ // E.g. the NetworkManager-1.0 has enum names starting with 80211
1665
+ const name = this.transformation.transformEnumName(girEnum)
1666
+
1667
+ const tsData: TsEnum = {
1668
+ name,
1669
+ girTypeName,
1670
+ tsTypeName: this.girFactory.girTypeNameToTsTypeName(girTypeName, false),
1671
+ doc: this.getTsDoc(girEnum),
1672
+ }
1673
+
1674
+ tsData.doc.tags.push(...this.getTsDocGirElementTags(tsData.tsTypeName, tsData.girTypeName))
1675
+
1676
+ return tsData
1677
+ }
1678
+
1679
+ private getAliasTsData(girAlias: GirAliasElement, tsClass: TsClass | null) {
1680
+ if (!girElementIsIntrospectable(girAlias)) return undefined
1681
+
1682
+ if (girAlias._tsData) {
1683
+ // this.log.warn('[getEnumerationMemberTsData] _tsData already set!')
1684
+ return girAlias._tsData
1685
+ }
1686
+
1687
+ const { type: typeName } = this.getTsType(girAlias, tsClass)
1688
+ const name = girAlias.$.name
1689
+ const tsData: TsAlias = {
1690
+ name,
1691
+ type: typeName,
1692
+ girTypeName: 'alias',
1693
+ tsTypeName: this.girFactory.girTypeNameToTsTypeName('alias', false),
1694
+ }
1695
+ return tsData
1696
+ }
1697
+
1698
+ private getConstantTsData(girConst: GirConstantElement, tsClass: TsClass | null) {
1699
+ if (!girElementIsIntrospectable(girConst)) return undefined
1700
+
1701
+ if (girConst._tsData) {
1702
+ // this.log.warn('[getConstantTsData] _tsData already set!')
1703
+ return girConst._tsData
1704
+ }
1705
+
1706
+ let tsData: TsVar | undefined = this.getVariableTsData(
1707
+ girConst,
1708
+ 'constant',
1709
+ 'constant',
1710
+ tsClass,
1711
+ false,
1712
+ false,
1713
+ false,
1714
+ )
1715
+ if (tsData?.name) {
1716
+ if (!this.constNames[tsData.name]) {
1717
+ this.constNames[tsData.name] = girConst
1718
+ } else {
1719
+ this.log.warn(WARN_CONSTANT_ALREADY_EXPORTED(tsData.name))
1720
+ tsData = undefined
1721
+ }
1722
+ }
1723
+ return tsData
1724
+ }
1725
+
1726
+ private getClassConstructPropsTsData(
1727
+ girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1728
+ constructPropNames: LocalNames,
1729
+ ) {
1730
+ const constructProps: GirPropertyElement[] = []
1731
+ const girProperties = (girClass as GirClassElement | GirInterfaceElement).property
1732
+ if (!girProperties?.length) {
1733
+ return constructProps
1734
+ }
1735
+ for (const girProp of girProperties) {
1736
+ if (!girElementIsIntrospectable(girProp) || !girProp.$.name) continue
1737
+ // Do not modify the original girProp, create a new one by clone `girProp` to `girConstrProp`
1738
+ const girConstrProp = clone(girProp)
1739
+
1740
+ if (!girClass._tsData) continue
1741
+
1742
+ if (!girConstrProp._tsData) {
1743
+ girConstrProp._tsData = this.getPropertyTsData(
1744
+ girConstrProp,
1745
+ 'property',
1746
+ 'constructor-property',
1747
+ girClass._tsData,
1748
+ true,
1749
+ true,
1750
+ true,
1751
+ 0,
1752
+ )
1753
+ }
1754
+
1755
+ if (!girConstrProp._tsData) {
1756
+ continue
1757
+ }
1758
+
1759
+ const localName = this.checkOrSetLocalName(girConstrProp, constructPropNames, 'property')
1760
+
1761
+ if (!localName?.added) {
1762
+ continue
1763
+ }
1764
+
1765
+ if (girConstrProp._fullSymName)
1766
+ this.symTable.set(this.allDependencies, girConstrProp._fullSymName, girConstrProp)
1767
+ constructProps.push(girConstrProp)
1768
+ }
1769
+
1770
+ return constructProps
1771
+ }
1772
+
1773
+ /**
1774
+ * Some class/static methods are defined in a separate record which is not
1775
+ * exported, but the methods are available as members of the JS constructor.
1776
+ * In gjs one can use an instance of the object, a JS constructor or a GType
1777
+ * as the method's instance-parameter.
1778
+ * @see https://discourse.gnome.org/t/using-class-methods-like-gtk-widget-class-get-css-name-from-gjs/4001
1779
+ * @param girClass
1780
+ */
1781
+ private getClassRecordMethods(
1782
+ girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1783
+ ): GirMethodElement[] {
1784
+ const girMethods: GirMethodElement[] = []
1785
+
1786
+ if (!girClass.$.name) return girMethods
1787
+ const fName = girClass.$.name + 'Class'
1788
+ let rec = this.ns.record?.find((r) => r.$.name == fName)
1789
+ if (!rec || !this.isGtypeStructFor(girClass, rec)) {
1790
+ rec = this.ns.record?.find((r) => this.isGtypeStructFor(girClass, r))
1791
+ fName == rec?.$.name
1792
+ }
1793
+ if (!rec) return girMethods
1794
+
1795
+ // Record methods
1796
+ const methods = rec.method || []
1797
+
1798
+ for (const girMethod of methods) {
1799
+ if (!girElementIsIntrospectable(girMethod) || !girClass._tsData) continue
1800
+
1801
+ if (!girMethod._tsData)
1802
+ girMethod._tsData = this.getFunctionTsData(girMethod, 'static-function', girClass._tsData, {
1803
+ isStatic: true,
1804
+ isArrowType: false,
1805
+ isGlobal: false,
1806
+ isVirtual: false,
1807
+ returnType: null,
1808
+ generics: [],
1809
+ })
1810
+
1811
+ if (!girMethod._tsData) continue
1812
+
1813
+ if (girMethod._tsData) {
1814
+ if (girMethod._fullSymName) this.symTable.set(this.allDependencies, girMethod._fullSymName, girMethod)
1815
+ girMethods.push(girMethod)
1816
+ }
1817
+ }
1818
+
1819
+ this.overloadPromisifiedFunctions(methods)
1820
+
1821
+ return girMethods
1822
+ }
1823
+
1824
+ /**
1825
+ * Instance methods
1826
+ * @param girClass
1827
+ * @param localNames
1828
+ */
1829
+ private getClassMethodsTsData(
1830
+ girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1831
+ localNames: LocalNames,
1832
+ ) {
1833
+ const girMethods: GirMethodElement[] = []
1834
+ if (girClass.method) {
1835
+ for (const girMethod of girClass.method) {
1836
+ if (!girElementIsIntrospectable(girMethod) || !girClass._tsData) continue
1837
+
1838
+ if (!girMethod._tsData)
1839
+ girMethod._tsData = this.getFunctionTsData(girMethod, 'method', girClass._tsData, {
1840
+ isStatic: false,
1841
+ isArrowType: false,
1842
+ isGlobal: false,
1843
+ isVirtual: false,
1844
+ returnType: null,
1845
+ generics: [],
1846
+ })
1847
+
1848
+ if (!girMethod._tsData) continue
1849
+
1850
+ const localName = this.checkOrSetLocalName(girMethod, localNames, 'method')
1851
+ if (localName?.added && localName.method) {
1852
+ if (girMethod._fullSymName)
1853
+ this.symTable.set(this.allDependencies, girMethod._fullSymName, girMethod)
1854
+ girMethods.push(localName.method)
1855
+ }
1856
+ }
1857
+
1858
+ this.overloadPromisifiedFunctions(girClass.method)
1859
+ }
1860
+ return girMethods
1861
+ }
1862
+
1863
+ private getClassFieldsTsData(
1864
+ girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1865
+ localNames: LocalNames,
1866
+ ) {
1867
+ const girFields: GirFieldElement[] = []
1868
+ if (!girClass._tsData) {
1869
+ this.log.warn(NO_TSDATA('setClassFieldsTsData'))
1870
+ return girFields
1871
+ }
1872
+
1873
+ if (girClass.field) {
1874
+ for (const girField of girClass.field) {
1875
+ if (!girElementIsIntrospectable(girField)) continue
1876
+ if (!girField._tsData)
1877
+ girField._tsData = this.getVariableTsData(
1878
+ girField,
1879
+ 'field',
1880
+ 'property',
1881
+ girClass._tsData,
1882
+ false,
1883
+ false,
1884
+ false,
1885
+ )
1886
+
1887
+ if (!girField._tsData) {
1888
+ continue
1889
+ }
1890
+
1891
+ const localName = this.checkOrSetLocalName(girField, localNames, 'field')
1892
+ if (localName?.added && localName.field) {
1893
+ if (girField._fullSymName) this.symTable.set(this.allDependencies, girField._fullSymName, girField)
1894
+ girFields.push(localName.field)
1895
+ }
1896
+ }
1897
+ }
1898
+
1899
+ return girFields
1900
+ }
1901
+
1902
+ private getGObjectProperties(girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement) {
1903
+ const girProperties: GirPropertyElement[] = []
1904
+ if (girClass._fullSymName && !STATIC_NAME_ALREADY_EXISTS.includes(girClass._fullSymName)) {
1905
+ // Records, classes and interfaces all have a static name
1906
+ const type = this.girFactory.newTsType({ type: 'string' })
1907
+ const staticNameProp = this.girFactory.newGirProperty({
1908
+ isStatic: true,
1909
+ name: 'name',
1910
+ type: [type],
1911
+ girTypeName: 'property',
1912
+ })
1913
+ girProperties.push(staticNameProp)
1914
+ }
1915
+
1916
+ if (girClass._tsData?.isDerivedFromGObject && girClass._module) {
1917
+ if (this.config.environment === 'gjs') {
1918
+ const type = this.girFactory.newTsType({
1919
+ // TODO: Type not as string
1920
+ type: 'GObject.GType',
1921
+ generics: this.girFactory.newGenerics([
1922
+ {
1923
+ value: girClass._tsData.name,
1924
+ },
1925
+ ]),
1926
+ })
1927
+ const staticGTypeProp = this.girFactory.newGirProperty({
1928
+ isStatic: true,
1929
+ name: '$gtype',
1930
+ type: [type],
1931
+ girTypeName: 'property',
1932
+ })
1933
+ girProperties.push(staticGTypeProp)
1934
+ } else if (this.config.environment === 'node') {
1935
+ const staticGTypeProp = this.girFactory.newGirProperty({
1936
+ isStatic: false,
1937
+ name: '__gtype__',
1938
+ type: [{ type: 'number' }],
1939
+ girTypeName: 'property',
1940
+ })
1941
+ girProperties.push(staticGTypeProp)
1942
+ }
1943
+ }
1944
+
1945
+ return girProperties
1946
+ }
1947
+
1948
+ private getClassPropertiesTsData(
1949
+ girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1950
+ localNames: LocalNames,
1951
+ ) {
1952
+ const girProperties: GirPropertyElement[] = []
1953
+ const properties = (girClass as GirClassElement | GirInterfaceElement).property
1954
+ if (properties) {
1955
+ for (const girProperty of properties) {
1956
+ if (!girElementIsIntrospectable(girProperty) || !girClass._tsData) continue
1957
+
1958
+ girProperty._tsData = this.getPropertyTsData(girProperty, 'property', 'property', girClass._tsData)
1959
+ if (!girProperty._tsData) continue
1960
+
1961
+ const localName = this.checkOrSetLocalName(girProperty, localNames, 'property')
1962
+ if (localName?.added && localName.property) {
1963
+ if (girProperty._fullSymName)
1964
+ this.symTable.set(this.allDependencies, girProperty._fullSymName, girProperty)
1965
+ girProperties.push(localName.property)
1966
+ }
1967
+ }
1968
+ }
1969
+ return girProperties
1970
+ }
1971
+
1972
+ private getClassNonStaticPropertyNames(
1973
+ girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1974
+ ) {
1975
+ const propertyNames: string[] = []
1976
+
1977
+ if (!girClass._tsData) {
1978
+ return propertyNames
1979
+ }
1980
+
1981
+ const girProperties = girClass._tsData.properties
1982
+
1983
+ if (girProperties.length > 0) {
1984
+ for (const girProperty of girProperties) {
1985
+ if (!girElementIsIntrospectable(girProperty)) continue
1986
+ if (
1987
+ girProperty.$.name &&
1988
+ !propertyNames.includes(girProperty.$.name) &&
1989
+ !girProperty._tsData?.isStatic
1990
+ ) {
1991
+ propertyNames.push(girProperty.$.name)
1992
+ }
1993
+ }
1994
+ }
1995
+
1996
+ // Extended property names
1997
+ for (const fullSymName of Object.keys(girClass._tsData.inherit)) {
1998
+ const girProperties = girClass._tsData.inherit[fullSymName]?.class.properties
1999
+ if (girProperties.length > 0) {
2000
+ for (const girProperty of girProperties) {
2001
+ if (!girElementIsIntrospectable(girProperty)) continue
2002
+ if (
2003
+ girProperty.$.name &&
2004
+ !propertyNames.includes(girProperty.$.name) &&
2005
+ !girProperty._tsData?.isStatic
2006
+ ) {
2007
+ propertyNames.push(girProperty.$.name)
2008
+ }
2009
+ }
2010
+ }
2011
+ }
2012
+
2013
+ // Implemented property names
2014
+ for (const fullSymName of Object.keys(girClass._tsData.implements)) {
2015
+ const girProperties = girClass._tsData.implements[fullSymName]?.interface.properties
2016
+ if (girProperties.length > 0) {
2017
+ for (const girProperty of girProperties) {
2018
+ if (!girElementIsIntrospectable(girProperty)) continue
2019
+ if (
2020
+ girProperty._tsData &&
2021
+ girProperty.$.name &&
2022
+ !propertyNames.includes(girProperty.$.name) &&
2023
+ !girProperty._tsData?.isStatic
2024
+ ) {
2025
+ propertyNames.push(girProperty.$.name)
2026
+ }
2027
+ }
2028
+ }
2029
+ }
2030
+
2031
+ return propertyNames
2032
+ }
2033
+
2034
+ private getClassConstructorsTsData(
2035
+ girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2036
+ ) {
2037
+ if (!girClass._tsData) {
2038
+ throw new Error(NO_TSDATA('getClassConstructorsTsData'))
2039
+ }
2040
+ const girConstructors: GirConstructorElement[] = []
2041
+
2042
+ // JS constructor(s)
2043
+ if (girClass._tsData?.isDerivedFromGObject) {
2044
+ const constructorInParam: InjectionParameter = {
2045
+ name: 'config',
2046
+ type: [
2047
+ {
2048
+ optional: true,
2049
+ type: girClass._tsData.constructPropInterfaceName,
2050
+ },
2051
+ ],
2052
+ }
2053
+ const realConstructor = this.girFactory.newGirFunction(
2054
+ {
2055
+ name: 'constructor',
2056
+ isStatic: true,
2057
+ inParams: [constructorInParam],
2058
+ girTypeName: 'constructor',
2059
+ },
2060
+ girClass._tsData,
2061
+ )
2062
+ const initConstructor = this.girFactory.newGirFunction(
2063
+ {
2064
+ name: '_init',
2065
+ inParams: [constructorInParam],
2066
+ girTypeName: 'method',
2067
+ },
2068
+ girClass._tsData,
2069
+ )
2070
+ girConstructors.push(realConstructor, initConstructor)
2071
+ }
2072
+
2073
+ if (Array.isArray(girClass.constructor)) {
2074
+ for (const girConstructor of girClass.constructor) {
2075
+ if (!girElementIsIntrospectable(girConstructor)) continue
2076
+
2077
+ girConstructor._tsData = this.getConstructorFunctionTsData(girClass._tsData, girConstructor)
2078
+
2079
+ if (!girConstructor._tsData?.name) continue
2080
+
2081
+ // Also add `new` pseudo constructors
2082
+ const ADD_NEW_PSEUDO_CONSTRUCTOR = true
2083
+
2084
+ // Inject an additional real constructor if static new(...) exists
2085
+ if (girConstructor._tsData.name === 'new') {
2086
+ const realConstructor = clone(girConstructor)
2087
+ realConstructor._tsData = clone(realConstructor._tsData)
2088
+
2089
+ if (realConstructor._tsData) {
2090
+ realConstructor._tsData.overloads = []
2091
+ realConstructor.$.name = 'constructor'
2092
+ realConstructor._tsData.name = 'constructor'
2093
+ girConstructors.push(realConstructor)
2094
+ }
2095
+
2096
+ if (ADD_NEW_PSEUDO_CONSTRUCTOR) {
2097
+ girConstructors.push(girConstructor)
2098
+ }
2099
+ } else {
2100
+ girConstructors.push(girConstructor)
2101
+ }
2102
+ }
2103
+ }
2104
+
2105
+ return girConstructors
2106
+ }
2107
+
2108
+ private getClassVirtualMethodsTsData(
2109
+ girClass: GirClassElement | GirInterfaceElement | GirUnionElement | GirRecordElement,
2110
+ ) {
2111
+ const methods: GirVirtualMethodElement[] =
2112
+ (girClass as GirClassElement | GirInterfaceElement)['virtual-method'] || []
2113
+ const girMethods: GirVirtualMethodElement[] = []
2114
+
2115
+ for (const girVMethod of methods) {
2116
+ if (!girElementIsIntrospectable(girVMethod) || !girClass._tsData) continue
2117
+
2118
+ girVMethod._tsData = this.getFunctionTsData(girVMethod, 'virtual', girClass._tsData, {
2119
+ isStatic: false,
2120
+ isArrowType: false,
2121
+ isGlobal: false,
2122
+ isVirtual: true,
2123
+ returnType: null,
2124
+ generics: [],
2125
+ })
2126
+ if (!girVMethod._tsData) continue
2127
+
2128
+ if (girVMethod?._tsData?.name) {
2129
+ girMethods.push(girVMethod)
2130
+ }
2131
+ }
2132
+
2133
+ return girMethods
2134
+ }
2135
+
2136
+ /**
2137
+ *
2138
+ * @param girClass This is the class / interface the `parentClass` implements signals from
2139
+ * @returns
2140
+ */
2141
+ private getClassSignalsTsData(
2142
+ girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2143
+ ) {
2144
+ const girSignals: GirSignalElement[] = []
2145
+
2146
+ const signals: GirSignalElement[] =
2147
+ (girClass as GirClassElement | GirInterfaceElement).signal ||
2148
+ (girClass as GirClassElement | GirInterfaceElement)['glib:signal'] ||
2149
+ []
2150
+ if (signals) {
2151
+ for (const girSignal of signals) {
2152
+ girSignal._tsData = this.setSignalTsData(girSignal, girClass)
2153
+ if (!girSignal._tsData) continue
2154
+ if (girSignal._fullSymName) this.symTable.set(this.allDependencies, girSignal._fullSymName, girSignal)
2155
+
2156
+ girSignals.push(girSignal)
2157
+ }
2158
+ }
2159
+ return girSignals
2160
+ }
2161
+
2162
+ getClassParentObject(
2163
+ parentName: string,
2164
+ namespace: string,
2165
+ type: 'parent' | 'prerequisite' | 'implements',
2166
+ ): ClassParent {
2167
+ let qualifiedParentName: string
2168
+ let parentModName: string
2169
+
2170
+ // WORKAROUND: Fix wrong parent names
2171
+ if (
2172
+ (this.packageName === 'GstAudio-0.10' || this.packageName === 'ClutterGst-1.0') &&
2173
+ (parentName === 'GstBase.BaseTransform' ||
2174
+ parentName === 'GstBase.BaseSink' ||
2175
+ parentName === 'GstBase.PushSrc')
2176
+ ) {
2177
+ const rename = parentName.replace('GstBase.', 'Gst.')
2178
+ this.log.warn(`[getClassParentObject] Rename parent class "${parentName}" -> "${rename}"`)
2179
+ parentName = rename
2180
+ }
2181
+
2182
+ if (parentName === 'GraniteServicesSettingsSerializable') {
2183
+ parentName = 'ServicesSettingsSerializable'
2184
+ this.log.warn(
2185
+ `[getClassParentObject] Rename parent class "GraniteServicesSettingsSerializable" -> "ServicesSettingsSerializable"`,
2186
+ )
2187
+ }
2188
+
2189
+ if (parentName.indexOf('.') < 0) {
2190
+ qualifiedParentName = namespace + '.' + parentName
2191
+ parentModName = namespace
2192
+ } else {
2193
+ qualifiedParentName = parentName
2194
+ const split = parentName.split('.')
2195
+ parentName = split[split.length - 1]
2196
+ parentModName = split.slice(0, split.length - 1).join('.')
2197
+ }
2198
+ const localParentName = parentModName == namespace ? parentName : qualifiedParentName
2199
+
2200
+ const dependencyExists = !!this.symTable.get(this.allDependencies, qualifiedParentName)
2201
+
2202
+ const cls = this.getClassParent({
2203
+ qualifiedParentName,
2204
+ parentName,
2205
+ })
2206
+
2207
+ return {
2208
+ qualifiedParentName,
2209
+ localParentName,
2210
+ type,
2211
+ parentName,
2212
+ cls,
2213
+ dependencyExists,
2214
+ // TODO: are there other types that can be inherited or implemented?
2215
+ girTypeName: type === 'parent' ? 'class' : 'interface',
2216
+ }
2217
+ }
2218
+
2219
+ private getClassParents(girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement) {
2220
+ const parents: ClassParent[] = []
2221
+
2222
+ if (!girClass._module?.namespace) {
2223
+ throw new Error('Namespace not found!')
2224
+ }
2225
+
2226
+ if (!girClass._tsData) {
2227
+ throw new Error(NO_TSDATA('getClassParents'))
2228
+ }
2229
+
2230
+ const prerequisites = (girClass as GirInterfaceElement)?.prerequisite
2231
+ const implmts = (girClass as GirInterfaceElement)?.implements
2232
+
2233
+ if (implmts) {
2234
+ for (const implement of implmts) {
2235
+ const parentName = implement.$?.name
2236
+ if (!parentName) continue
2237
+ const parent = this.getClassParentObject(parentName, girClass._module.namespace, 'implements')
2238
+ if (parent.dependencyExists) {
2239
+ parents.push(parent)
2240
+ }
2241
+ }
2242
+ }
2243
+
2244
+ if (prerequisites) {
2245
+ for (const prerequisite of prerequisites) {
2246
+ const parentName = prerequisite.$?.name
2247
+ if (!parentName) continue
2248
+ const parent = this.getClassParentObject(parentName, girClass._module.namespace, 'prerequisite')
2249
+ if (parent.dependencyExists) {
2250
+ parents.push(parent)
2251
+ }
2252
+ }
2253
+ }
2254
+
2255
+ if ((girClass as GirClassElement).$.parent) {
2256
+ const parentName = (girClass as GirClassElement).$.parent
2257
+ if (parentName) {
2258
+ const parent = this.getClassParentObject(parentName, girClass._module.namespace, 'parent')
2259
+ if (parent.dependencyExists) {
2260
+ parents.push(parent)
2261
+ }
2262
+ }
2263
+ }
2264
+
2265
+ // Please reply: Do all interfaces always inherit from GObject.Object?
2266
+ // If this is a interface and GObject.Object is not in the parents array, add GObject.Object to the parents
2267
+ if (girClass._tsData.girTypeName === 'interface' && girClass._fullSymName !== 'GObject.Object') {
2268
+ if (!parents.find((parent) => parent.qualifiedParentName === 'GObject.Object')) {
2269
+ // TODO make sure this class exists in symTable
2270
+ const gObjectObjectCls =
2271
+ this.symTable.getByHand<GirClassElement>('GObject-2.0.GObject.Object') || undefined
2272
+ const parent: ClassParent = {
2273
+ qualifiedParentName: 'GObject.Object',
2274
+ localParentName: girClass._module.namespace === 'GObject' ? 'Object' : 'GObject.Object',
2275
+ type: 'parent',
2276
+ parentName: 'Object',
2277
+ cls: gObjectObjectCls,
2278
+ dependencyExists: !!gObjectObjectCls,
2279
+ girTypeName: 'class',
2280
+ }
2281
+ if (parent.dependencyExists) {
2282
+ parents.push(parent)
2283
+ }
2284
+ }
2285
+ }
2286
+
2287
+ return parents
2288
+ }
2289
+
2290
+ private setClassBaseTsData(
2291
+ girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2292
+ girTypeName: TypeGirClass,
2293
+ ) {
2294
+ if (!girClass?.$?.name) return undefined
2295
+
2296
+ const girModule: GirModule = girClass._module ? girClass._module : this
2297
+ let className = this.transformation.transformClassName(girClass.$.name)
2298
+ /**
2299
+ * E.g. 'Gtk'
2300
+ */
2301
+ const namespace = girModule.namespace
2302
+ /**
2303
+ * E.g. '3.0'
2304
+ */
2305
+ const version = girModule.version
2306
+
2307
+ let qualifiedName: string
2308
+ if (!className.includes('.')) {
2309
+ qualifiedName = namespace + '.' + className
2310
+ } else {
2311
+ qualifiedName = className
2312
+ const split = className.split('.')
2313
+ className = split[split.length - 1]
2314
+ }
2315
+
2316
+ girClass._tsData = {
2317
+ name: className,
2318
+ qualifiedName,
2319
+ parents: [],
2320
+ namespace,
2321
+ version,
2322
+ isAbstract: this.isAbstractClass(girClass),
2323
+ localNames: {},
2324
+ constructPropNames: {},
2325
+ inheritConstructPropInterfaceNames: [],
2326
+ constructPropInterfaceName: `${namespace}.${className}.ConstructorProperties`,
2327
+ fields: [],
2328
+ properties: [],
2329
+ conflictProperties: [],
2330
+ constructProps: [],
2331
+ propertySignalMethods: [],
2332
+ methods: [],
2333
+ conflictMethods: [],
2334
+ virtualMethods: [],
2335
+ constructors: [],
2336
+ staticFunctions: [],
2337
+ signals: [],
2338
+ generics: [],
2339
+ inherit: {},
2340
+ implements: {},
2341
+ girTypeName,
2342
+ tsTypeName: this.girFactory.girTypeNameToTsTypeName(girTypeName, false),
2343
+ doc: this.getTsDoc(girClass),
2344
+ }
2345
+
2346
+ girClass._tsData.doc.tags.push(
2347
+ ...this.getTsDocGirElementTags(girClass._tsData.tsTypeName, girClass._tsData.girTypeName),
2348
+ )
2349
+
2350
+ girClass._tsData.parents = this.getClassParents(girClass)
2351
+
2352
+ if (girClass._tsData.parents.length) {
2353
+ for (const parent of girClass._tsData.parents) {
2354
+ girClass._tsData.inheritConstructPropInterfaceNames.push(
2355
+ `${parent.qualifiedParentName}.ConstructorProperties`,
2356
+ )
2357
+ }
2358
+ }
2359
+
2360
+ girClass._tsData.isDerivedFromGObject = this.isDerivedFromGObject(girClass)
2361
+
2362
+ return girClass._tsData
2363
+ }
2364
+
2365
+ private setClassTsData(
2366
+ girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2367
+ girTypeName: TypeGirClass,
2368
+ ): TsClass | undefined {
2369
+ if (!girClass?.$?.name) return undefined
2370
+
2371
+ if (girClass._tsData) {
2372
+ return girClass._tsData
2373
+ }
2374
+
2375
+ girClass._tsData = this.setClassBaseTsData(girClass, girTypeName)
2376
+ if (!girClass._tsData) {
2377
+ return undefined
2378
+ }
2379
+
2380
+ // BASE
2381
+
2382
+ if (girClass._tsData.isDerivedFromGObject) {
2383
+ girClass._tsData.constructProps.push(
2384
+ ...this.getClassConstructPropsTsData(girClass, girClass._tsData.constructPropNames),
2385
+ )
2386
+ }
2387
+
2388
+ girClass._tsData.constructors.push(...this.getClassConstructorsTsData(girClass))
2389
+ girClass._tsData.staticFunctions.push(...this.getClassStaticFunctionsTsData(girClass, girClass._tsData))
2390
+
2391
+ girClass._tsData.fields.push(...this.getClassFieldsTsData(girClass, girClass._tsData.localNames))
2392
+
2393
+ girClass._tsData.properties.push(...this.getClassPropertiesTsData(girClass, girClass._tsData.localNames))
2394
+ girClass._tsData.methods.push(...this.getClassMethodsTsData(girClass, girClass._tsData.localNames))
2395
+ girClass._tsData.virtualMethods.push(...this.getClassVirtualMethodsTsData(girClass))
2396
+ girClass._tsData.signals.push(...this.getClassSignalsTsData(girClass))
2397
+
2398
+ girClass._tsData.properties.push(...this.getGObjectProperties(girClass))
2399
+
2400
+ // Copy fields, properties, methods, virtual methods and signals from inheritance tree
2401
+ this.traverseInheritanceTree(girClass, girClass._tsData.girTypeName, (extendsCls, depth) => {
2402
+ if (!girClass._tsData || !extendsCls._tsData || !extendsCls._fullSymName || !extendsCls._module) {
2403
+ return
2404
+ }
2405
+
2406
+ if (girClass._fullSymName === extendsCls._fullSymName) {
2407
+ return
2408
+ }
2409
+
2410
+ const key = extendsCls._module.packageName + '.' + extendsCls._fullSymName
2411
+ if (girClass._tsData.inherit[key]) return
2412
+
2413
+ girClass._tsData.inherit[key] = {
2414
+ depth,
2415
+ class: extendsCls._tsData,
2416
+ }
2417
+ })
2418
+
2419
+ // Copy properties, methods and signals from implemented interface
2420
+ this.forEachInterface(girClass, girClass._tsData.girTypeName, (iface, depth) => {
2421
+ if (!girClass._tsData || !iface._tsData || !iface._fullSymName || !iface._module) {
2422
+ return
2423
+ }
2424
+
2425
+ if (girClass._fullSymName === iface._fullSymName) {
2426
+ return
2427
+ }
2428
+
2429
+ const key = iface._module.packageName + '.' + iface._fullSymName
2430
+ if (girClass._tsData.implements[key]) return
2431
+
2432
+ girClass._tsData.implements[key] = {
2433
+ depth,
2434
+ interface: iface._tsData,
2435
+ }
2436
+ })
2437
+
2438
+ this.inject.toClass(girClass)
2439
+
2440
+ girClass._tsData.propertySignalMethods.push(
2441
+ ...this.getClassPropertySignalsMethods(girClass),
2442
+ ...this.getGeneralSignalsMethods(girClass._tsData),
2443
+ )
2444
+
2445
+ if (this.config.fixConflicts) {
2446
+ this.conflictResolver.repairClass(girClass)
2447
+ }
2448
+
2449
+ return girClass._tsData
2450
+ }
2451
+
2452
+ private isDerivedFromGObject(
2453
+ girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2454
+ ): boolean {
2455
+ if (typeof girClass._tsData?.isDerivedFromGObject === 'boolean') return girClass._tsData.isDerivedFromGObject
2456
+ let ret = false
2457
+
2458
+ const onClassOrInterface = (
2459
+ cls: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2460
+ ) => {
2461
+ if (cls._tsData?.isDerivedFromGObject === true || cls._fullSymName === 'GObject.Object') {
2462
+ ret = true
2463
+ }
2464
+ }
2465
+ if (!girClass._tsData) throw new Error(NO_TSDATA('isDerivedFromGObject'))
2466
+ this.traverseInheritanceTree(girClass, girClass._tsData.tsTypeName, onClassOrInterface)
2467
+ this.forEachInterface(girClass, girClass._tsData.tsTypeName, onClassOrInterface)
2468
+ return ret
2469
+ }
2470
+
2471
+ private getClassParent(parent: Pick<ClassParent, 'qualifiedParentName' | 'parentName'>) {
2472
+ let parentPtr: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement | undefined =
2473
+ undefined
2474
+ if (this.symTable.get(this.allDependencies, parent.qualifiedParentName)) {
2475
+ parentPtr =
2476
+ (this.symTable.get(this.allDependencies, parent.qualifiedParentName) as GirClassElement) || undefined
2477
+ }
2478
+
2479
+ if (!parentPtr && parent.parentName == 'Object') {
2480
+ parentPtr = (this.symTable.getByHand('GObject-2.0.GObject.Object') as GirClassElement) || undefined
2481
+ }
2482
+
2483
+ return parentPtr
2484
+ }
2485
+
2486
+ private traverseInheritanceTree(
2487
+ girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2488
+ gitTypeName: TypeGirClass,
2489
+ callback: (
2490
+ girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2491
+ depth: number,
2492
+ ) => void,
2493
+ depth = 0,
2494
+ recursive = true,
2495
+ ): void {
2496
+ if (!girClass.$.name) return
2497
+ if (!girClass._tsData) girClass._tsData = this.setClassTsData(girClass, gitTypeName)
2498
+ if (!girClass._tsData) return
2499
+
2500
+ callback(girClass, depth)
2501
+
2502
+ const parents = girClass._tsData.parents
2503
+ if (recursive && parents.length) {
2504
+ ++depth
2505
+
2506
+ if (depth >= MAX_CLASS_PARENT_DEPTH) {
2507
+ this.log.error('[traverseInheritanceTree] Maximum recursion depth reached')
2508
+ return
2509
+ }
2510
+
2511
+ for (const parent of parents) {
2512
+ if (!parent.parentName || parent.type !== 'parent') {
2513
+ continue
2514
+ }
2515
+
2516
+ if (parent.cls) {
2517
+ if (parent.cls === girClass) {
2518
+ this.log.warn('[traverseInheritanceTree] A class cannot inherit itself')
2519
+ continue
2520
+ }
2521
+
2522
+ this.traverseInheritanceTree(parent.cls, parent.girTypeName, callback, depth, recursive)
2523
+ }
2524
+ }
2525
+ }
2526
+ }
2527
+
2528
+ private forEachInterface(
2529
+ girIface: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2530
+ girTypeName: TypeGirClass,
2531
+ callback: (
2532
+ cls: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2533
+ depth: number,
2534
+ ) => void,
2535
+ recursive = true,
2536
+ depth = 0,
2537
+ ): void {
2538
+ if (!girIface.$.name) return
2539
+ if (!girIface._tsData) girIface._tsData = this.setClassTsData(girIface, girTypeName)
2540
+ if (!girIface._tsData) {
2541
+ throw new Error(NO_TSDATA('forEachInterface'))
2542
+ }
2543
+
2544
+ const parents = girIface._tsData.parents
2545
+ if (parents.length) {
2546
+ ++depth
2547
+ for (const parent of parents) {
2548
+ if (!parent.parentName || parent.type === 'parent') {
2549
+ continue
2550
+ }
2551
+
2552
+ if (parent.cls) {
2553
+ callback(parent.cls as GirInterfaceElement, depth)
2554
+ // iface's prerequisite is also an interface, or it's
2555
+ // a class and we also want to recurse classes
2556
+
2557
+ if (recursive)
2558
+ this.forEachInterface(
2559
+ parent.cls as GirInterfaceElement,
2560
+ parent.girTypeName,
2561
+ callback,
2562
+ recursive,
2563
+ depth,
2564
+ )
2565
+ }
2566
+ }
2567
+ }
2568
+ }
2569
+
2570
+ /**
2571
+ *
2572
+ * @param girElement
2573
+ * @param localNames Can be (constructor) properties, fields or methods
2574
+ * @param type
2575
+ */
2576
+ private checkOrSetLocalName(
2577
+ girElement:
2578
+ | GirMethodElement
2579
+ | GirPropertyElement
2580
+ | GirFieldElement
2581
+ | GirConstructorElement
2582
+ | GirFunctionElement,
2583
+ localNames: LocalNames,
2584
+ type: LocalNameType,
2585
+ ): LocalNameCheck | null {
2586
+ let isOverloadable = false
2587
+
2588
+ if (!girElement._tsData) {
2589
+ return null
2590
+ }
2591
+
2592
+ const name = girElement._tsData?.name
2593
+
2594
+ if (!name) {
2595
+ return null
2596
+ }
2597
+
2598
+ // Methods are overloadable by typescript
2599
+ // TODO Add support for properties
2600
+ if (type === 'method') {
2601
+ isOverloadable = true
2602
+ }
2603
+
2604
+ // Only names of the same type are overloadable
2605
+ if (localNames[name]?.type && localNames[name].type !== type) {
2606
+ // In GIO there are some methods and properties with the same name
2607
+ // E.g. on `WebKit2.WebView.isLoading` and `WebKit2.WebView.isLoading()`
2608
+ // See Gjs doc https://gjs-docs.gnome.org/webkit240~4.0_api/webkit2.webview#property-is_loading
2609
+ // TODO prefer functions over properties (Overwrite the properties with the functions if they have the same name)
2610
+
2611
+ return null
2612
+ }
2613
+
2614
+ // If name is found in localNames this variable was already defined
2615
+ if (localNames?.[name]?.[type]?._tsData) {
2616
+ // Ignore duplicates with the same type
2617
+ // TODO should we use `this.functionSignaturesMatch` here?
2618
+
2619
+ if (type === 'method') {
2620
+ const tsMethod1 = (girElement as GirMethodElement)._tsData
2621
+ const tsMethod2 = (localNames[name][type] as GirMethodElement)._tsData
2622
+ if (!tsMethod1 || !tsMethod2) {
2623
+ return null
2624
+ }
2625
+ // if (ConflictResolver.functionConflict(tsMethod1, tsMethod2)) {
2626
+ // return null
2627
+ // }
2628
+ } else {
2629
+ // TODO better handling of property and field
2630
+ if (isEqual(localNames[name][type]?._tsData, girElement._tsData)) {
2631
+ return null
2632
+ }
2633
+ }
2634
+
2635
+ // Ignore if current method is not overloadable
2636
+ if (!isOverloadable) {
2637
+ return null
2638
+ }
2639
+ }
2640
+
2641
+ localNames[name] = localNames[name] || {}
2642
+ const localName: LocalName = {
2643
+ ...localNames[name],
2644
+ [type]: girElement,
2645
+ type,
2646
+ }
2647
+
2648
+ localNames[name] = localName
2649
+ return { ...localName, added: true }
2650
+ }
2651
+
2652
+ private isGtypeStructFor(
2653
+ e: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2654
+ rec: GirRecordElement,
2655
+ ) {
2656
+ const isFor = rec.$['glib:is-gtype-struct-for']
2657
+ return isFor && isFor == e.$.name
2658
+ }
2659
+
2660
+ /**
2661
+ * E.g GObject.ObjectClass is a abstract class and required by UPowerGlib-1.0, UDisks-2.0 and others
2662
+ * @param girClass
2663
+ * @returns `true` if this is this a abstract class.
2664
+ */
2665
+ private isAbstractClass(girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement) {
2666
+ return girClass.$?.['glib:is-gtype-struct-for'] ? true : false
2667
+ }
2668
+
2669
+ /**
2670
+ *
2671
+ * @param girClass
2672
+ * @returns
2673
+ */
2674
+ private getOtherStaticFunctions(
2675
+ girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2676
+ ): GirFunctionElement[] {
2677
+ const girFunctions: GirFunctionElement[] = []
2678
+
2679
+ if (!girClass._tsData) return girFunctions
2680
+
2681
+ if (girClass.function?.length) {
2682
+ for (const girFunction of girClass.function) {
2683
+ girFunction._tsData = this.getFunctionTsData(girFunction, 'static-function', girClass._tsData, {
2684
+ isStatic: true,
2685
+ isArrowType: false,
2686
+ isGlobal: false,
2687
+ isVirtual: false,
2688
+ returnType: null,
2689
+ generics: [],
2690
+ })
2691
+
2692
+ if (!girFunction._tsData?.name) continue
2693
+ if (girFunction._tsData.name.startsWith('new')) continue
2694
+
2695
+ girFunctions.push(girFunction)
2696
+ }
2697
+ }
2698
+ return girFunctions
2699
+ }
2700
+
2701
+ private getStaticNewFunctions(
2702
+ girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2703
+ parentClass: TsClass,
2704
+ ): Array<GirFunctionElement | GirConstructorElement> {
2705
+ const girFunctions: Array<GirFunctionElement | GirConstructorElement> = []
2706
+ if (girClass.function?.length) {
2707
+ for (const girFunction of girClass.function) {
2708
+ girFunction._tsData = this.getConstructorFunctionTsData(parentClass, girFunction)
2709
+ if (!girFunction._tsData?.name.startsWith('new')) continue
2710
+ girFunctions.push(girFunction)
2711
+ }
2712
+ }
2713
+ return girFunctions
2714
+ }
2715
+
2716
+ /**
2717
+ * Static methods, <constructor> and <function>
2718
+ * @param girClass
2719
+ * @param constructorTypeName Used to overwrite the constructor return type
2720
+ * @param useReference This value should be `false` for inherited and implemented classes / interfaces.
2721
+ * Otherwise other modules would overwrite the return value of the constructor methods
2722
+ */
2723
+ private getClassStaticFunctionsTsData(
2724
+ girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2725
+ parentClass: TsClass,
2726
+ ) {
2727
+ const girStaticFuncs: Array<GirFunctionElement | GirConstructorElement | GirMethodElement> = []
2728
+
2729
+ girStaticFuncs.push(...this.getStaticNewFunctions(girClass, parentClass))
2730
+ girStaticFuncs.push(...this.getOtherStaticFunctions(girClass))
2731
+ girStaticFuncs.push(...this.getClassRecordMethods(girClass))
2732
+
2733
+ return girStaticFuncs
2734
+ }
2735
+
2736
+ private setModuleTsData() {
2737
+ if (this.ns.enumeration) {
2738
+ for (const girEnum of this.ns.enumeration) {
2739
+ if (girEnum.member) {
2740
+ for (const girEnumMember of girEnum.member) {
2741
+ girEnumMember._tsData = this.getEnumerationMemberTsData(girEnumMember, 'enum-member')
2742
+ if (!girEnumMember._tsData) continue
2743
+ }
2744
+ }
2745
+ girEnum._tsData = this.getEnumerationTsData(girEnum, 'enum')
2746
+ this.fixEnumerationDuplicateIdentifier(girEnum)
2747
+ if (!girEnum._tsData) continue
2748
+ }
2749
+ }
2750
+
2751
+ if (this.ns.bitfield)
2752
+ for (const girBitfield of this.ns.bitfield) {
2753
+ if (girBitfield.member)
2754
+ for (const girEnumMember of girBitfield.member) {
2755
+ girEnumMember._tsData = this.getEnumerationMemberTsData(girEnumMember, 'bitfield-member')
2756
+ }
2757
+ girBitfield._tsData = this.getEnumerationTsData(girBitfield, 'bitfield')
2758
+ if (!girBitfield._tsData) continue
2759
+ this.fixEnumerationDuplicateIdentifier(girBitfield)
2760
+ }
2761
+
2762
+ if (this.ns.constant)
2763
+ for (const girConst of this.ns.constant) {
2764
+ girConst._tsData = this.getConstantTsData(girConst, null)
2765
+ if (!girConst._tsData) continue
2766
+ }
2767
+
2768
+ if (this.ns.function) {
2769
+ for (const girFunc of this.ns.function) {
2770
+ girFunc._tsData = this.getFunctionTsData(girFunc, 'function', null, {
2771
+ isStatic: false,
2772
+ isArrowType: false,
2773
+ isGlobal: true,
2774
+ isVirtual: false,
2775
+ returnType: null,
2776
+ generics: [],
2777
+ })
2778
+ if (!girFunc._tsData) continue
2779
+ }
2780
+
2781
+ this.overloadPromisifiedFunctions(this.ns.function)
2782
+ }
2783
+
2784
+ if (this.ns.callback)
2785
+ for (const girCallback of this.ns.callback) {
2786
+ girCallback._tsData = this.setCallbackTsData(girCallback, null)
2787
+ }
2788
+
2789
+ if (this.ns.interface)
2790
+ for (const girIface of this.ns.interface) {
2791
+ girIface._tsData = this.setClassTsData(girIface, 'interface')
2792
+ }
2793
+
2794
+ if (this.ns.class)
2795
+ for (const girClass of this.ns.class) {
2796
+ girClass._tsData = this.setClassTsData(girClass, 'class')
2797
+ if (!girClass._tsData) continue
2798
+ }
2799
+
2800
+ if (this.ns.record)
2801
+ for (const girRecord of this.ns.record) {
2802
+ girRecord._tsData = this.setClassTsData(girRecord, 'record')
2803
+ if (!girRecord._tsData) continue
2804
+ }
2805
+
2806
+ if (this.ns.union)
2807
+ for (const girUnion of this.ns.union) {
2808
+ girUnion._tsData = this.setClassTsData(girUnion, 'union')
2809
+ if (!girUnion._tsData) continue
2810
+ }
2811
+
2812
+ if (this.ns.alias) {
2813
+ for (const girAlias of this.ns.alias) {
2814
+ // GType is not a number in GJS
2815
+ if (this.packageName !== 'GObject-2.0' || girAlias.$.name !== 'Type')
2816
+ girAlias._tsData = this.getAliasTsData(girAlias, null)
2817
+ if (!girAlias._tsData) continue
2818
+ }
2819
+ }
2820
+ }
2821
+
2822
+ /**
2823
+ * TODO: find better name for this method
2824
+ * @param fullTypeName
2825
+ * @returns
2826
+ */
2827
+ private fullTypeLookupWithNamespace(fullTypeName: string) {
2828
+ let resValue = ''
2829
+ let namespace = ''
2830
+
2831
+ // Check overwrites first
2832
+ if (!resValue && fullTypeName && FULL_TYPE_MAP(this.config.environment, fullTypeName)) {
2833
+ resValue = FULL_TYPE_MAP(this.config.environment, fullTypeName) || ''
2834
+ }
2835
+
2836
+ // Only use the fullTypeName as the type if it is found in the symTable
2837
+ if (!resValue && this.symTable.get(this.allDependencies, fullTypeName)) {
2838
+ if (fullTypeName.startsWith(this.namespace + '.')) {
2839
+ resValue = removeNamespace(fullTypeName, this.namespace)
2840
+ resValue = this.transformation.transformTypeName(resValue)
2841
+ // TODO: check if resValue is a class, enum or interface before transformClassName
2842
+ resValue = this.transformation.transformClassName(resValue)
2843
+ namespace = this.namespace
2844
+ resValue = namespace + '.' + resValue
2845
+ } else {
2846
+ const resValues = fullTypeName.split('.')
2847
+ resValues.map((name) => this.transformation.transformTypeName(name))
2848
+ // TODO: check if resValues[resValues.length - 1] is a class, enum, interface before transformClassName
2849
+ resValues[resValues.length - 1] = this.transformation.transformClassName(
2850
+ resValues[resValues.length - 1],
2851
+ )
2852
+ resValue = resValues.join('.')
2853
+ namespace = resValues[0]
2854
+ }
2855
+ }
2856
+
2857
+ return {
2858
+ value: resValue,
2859
+ namespace,
2860
+ }
2861
+ }
2862
+
2863
+ private loadInheritance(inheritanceTable: InheritanceTable): void {
2864
+ // Class hierarchy
2865
+ for (const girClass of this.ns.class ? this.ns.class : []) {
2866
+ let parent: string | null = null
2867
+ if (girClass.$ && girClass.$.parent) parent = girClass.$.parent
2868
+ if (!parent) continue
2869
+ if (!girClass._fullSymName) continue
2870
+
2871
+ if (!parent.includes('.')) {
2872
+ parent = addNamespace(parent, this.namespace)
2873
+ }
2874
+
2875
+ const className = girClass._fullSymName
2876
+
2877
+ const arr: string[] = inheritanceTable[className] || []
2878
+ arr.push(parent)
2879
+ inheritanceTable[className] = arr
2880
+ }
2881
+
2882
+ // Class interface implementations
2883
+ for (const girClass of this.ns.class ? this.ns.class : []) {
2884
+ if (!girClass._fullSymName) continue
2885
+
2886
+ const names: string[] = []
2887
+
2888
+ if (girClass.implements) {
2889
+ for (const girImplements of girClass.implements) {
2890
+ if (girImplements.$.name) {
2891
+ let name: string = girImplements.$.name
2892
+ if (!name.includes('.')) {
2893
+ name = girClass._fullSymName.substring(0, girClass._fullSymName.indexOf('.') + 1) + name
2894
+ }
2895
+ names.push(name)
2896
+ }
2897
+ }
2898
+ }
2899
+
2900
+ if (names.length > 0) {
2901
+ const className = girClass._fullSymName
2902
+ const arr: string[] = inheritanceTable[className] || []
2903
+ inheritanceTable[className] = arr.concat(names)
2904
+ }
2905
+ }
2906
+ }
2907
+
2908
+ private loadTypes(): void {
2909
+ if (this.ns.bitfield) this.annotateAndRegisterGirElement(this.ns.bitfield)
2910
+ if (this.ns.callback) this.annotateAndRegisterGirElement(this.ns.callback)
2911
+ if (this.ns.class) this.annotateAndRegisterGirElement(this.ns.class)
2912
+ if (this.ns.constant) this.annotateAndRegisterGirElement(this.ns.constant)
2913
+ if (this.ns.enumeration) this.annotateAndRegisterGirElement(this.ns.enumeration)
2914
+ if (this.ns.function) this.annotateAndRegisterGirElement(this.ns.function)
2915
+ if (this.ns.interface) this.annotateAndRegisterGirElement(this.ns.interface)
2916
+ if (this.ns.record) this.annotateAndRegisterGirElement(this.ns.record)
2917
+ if (this.ns.union) this.annotateAndRegisterGirElement(this.ns.union)
2918
+ if (this.ns.alias) this.annotateAndRegisterGirElement(this.ns.alias)
2919
+
2920
+ if (this.ns.callback) for (const girCallback of this.ns.callback) this.annotateFunctionArguments(girCallback)
2921
+
2922
+ for (const girClass of this.ns.class || []) {
2923
+ this.annotateClass(girClass, 'class')
2924
+ }
2925
+ for (const girClass of this.ns.record || []) {
2926
+ this.annotateClass(girClass, 'record')
2927
+ }
2928
+ for (const girClass of this.ns.interface || []) {
2929
+ this.annotateClass(girClass, 'interface')
2930
+ }
2931
+
2932
+ if (this.ns.function) this.annotateFunctions(this.ns.function)
2933
+ if (this.ns.callback) this.annotateFunctions(this.ns.callback)
2934
+
2935
+ if (this.ns.constant) this.annotateVariables(this.ns.constant)
2936
+ }
2937
+
2938
+ /**
2939
+ * Before processing the typescript data, each module should be initialized first.
2940
+ * This is done in the `GenerationHandler`.
2941
+ */
2942
+ public init(inheritanceTable: InheritanceTable) {
2943
+ this.loadTypes()
2944
+ this.loadInheritance(inheritanceTable)
2945
+ }
2946
+
2947
+ /**
2948
+ * Start processing the typescript data
2949
+ */
2950
+ public start() {
2951
+ this.setModuleTsData()
2952
+ }
2953
+ }