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

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 (669) hide show
  1. package/README.md +156 -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 +45 -0
  6. package/lib/commands/generate.js +71 -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 +103 -0
  15. package/lib/config.js +385 -0
  16. package/lib/config.js.map +1 -0
  17. package/lib/conflict-resolver.d.ts +154 -0
  18. package/lib/conflict-resolver.js +1095 -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/generation-handler.d.ts +12 -0
  24. package/lib/generation-handler.js +63 -0
  25. package/lib/generation-handler.js.map +1 -0
  26. package/lib/generator.d.ts +5 -0
  27. package/lib/generator.js +2 -0
  28. package/lib/generator.js.map +1 -0
  29. package/lib/gir-factory.d.ts +50 -0
  30. package/lib/gir-factory.js +354 -0
  31. package/lib/gir-factory.js.map +1 -0
  32. package/lib/gir-module.d.ts +256 -0
  33. package/lib/gir-module.js +2075 -0
  34. package/lib/gir-module.js.map +1 -0
  35. package/lib/html-doc-generator.d.ts +13 -0
  36. package/lib/html-doc-generator.js +18 -0
  37. package/lib/html-doc-generator.js.map +1 -0
  38. package/lib/index.d.ts +17 -0
  39. package/lib/index.js +18 -0
  40. package/lib/index.js.map +1 -0
  41. package/lib/injection/callbacks/gjs/Gio-2.0.d.ts +2 -0
  42. package/lib/injection/callbacks/gjs/Gio-2.0.js +36 -0
  43. package/lib/injection/callbacks/gjs/Gio-2.0.js.map +1 -0
  44. package/lib/injection/callbacks/gjs/index.d.ts +2 -0
  45. package/lib/injection/callbacks/gjs/index.js +3 -0
  46. package/lib/injection/callbacks/gjs/index.js.map +1 -0
  47. package/lib/injection/callbacks/index.d.ts +4 -0
  48. package/lib/injection/callbacks/index.js +4 -0
  49. package/lib/injection/callbacks/index.js.map +1 -0
  50. package/lib/injection/callbacks/node-gtk/index.d.ts +2 -0
  51. package/lib/injection/callbacks/node-gtk/index.js +2 -0
  52. package/lib/injection/callbacks/node-gtk/index.js.map +1 -0
  53. package/lib/injection/classes/GLib-2-0.d.ts +2 -0
  54. package/lib/injection/classes/GLib-2-0.js +35 -0
  55. package/lib/injection/classes/GLib-2-0.js.map +1 -0
  56. package/lib/injection/classes/gjs/GLib-2.0.d.ts +2 -0
  57. package/lib/injection/classes/gjs/GLib-2.0.js +74 -0
  58. package/lib/injection/classes/gjs/GLib-2.0.js.map +1 -0
  59. package/lib/injection/classes/gjs/GObject-2.0.d.ts +2 -0
  60. package/lib/injection/classes/gjs/GObject-2.0.js +634 -0
  61. package/lib/injection/classes/gjs/GObject-2.0.js.map +1 -0
  62. package/lib/injection/classes/gjs/Gio-2.0.d.ts +5 -0
  63. package/lib/injection/classes/gjs/Gio-2.0.js +218 -0
  64. package/lib/injection/classes/gjs/Gio-2.0.js.map +1 -0
  65. package/lib/injection/classes/gjs/index.d.ts +2 -0
  66. package/lib/injection/classes/gjs/index.js +5 -0
  67. package/lib/injection/classes/gjs/index.js.map +1 -0
  68. package/lib/injection/classes/index.d.ts +4 -0
  69. package/lib/injection/classes/index.js +5 -0
  70. package/lib/injection/classes/index.js.map +1 -0
  71. package/lib/injection/classes/node-gtk/GLib-2.0.d.ts +2 -0
  72. package/lib/injection/classes/node-gtk/GLib-2.0.js +19 -0
  73. package/lib/injection/classes/node-gtk/GLib-2.0.js.map +1 -0
  74. package/lib/injection/classes/node-gtk/GObject-2.0.d.ts +2 -0
  75. package/lib/injection/classes/node-gtk/GObject-2.0.js +66 -0
  76. package/lib/injection/classes/node-gtk/GObject-2.0.js.map +1 -0
  77. package/lib/injection/classes/node-gtk/Gdk-4.0.d.ts +2 -0
  78. package/lib/injection/classes/node-gtk/Gdk-4.0.js +32 -0
  79. package/lib/injection/classes/node-gtk/Gdk-4.0.js.map +1 -0
  80. package/lib/injection/classes/node-gtk/Gio-2.0.d.ts +2 -0
  81. package/lib/injection/classes/node-gtk/Gio-2.0.js +14 -0
  82. package/lib/injection/classes/node-gtk/Gio-2.0.js.map +1 -0
  83. package/lib/injection/classes/node-gtk/Graphene-1.0.d.ts +2 -0
  84. package/lib/injection/classes/node-gtk/Graphene-1.0.js +133 -0
  85. package/lib/injection/classes/node-gtk/Graphene-1.0.js.map +1 -0
  86. package/lib/injection/classes/node-gtk/Gtk-3.0.d.ts +2 -0
  87. package/lib/injection/classes/node-gtk/Gtk-3.0.js +31 -0
  88. package/lib/injection/classes/node-gtk/Gtk-3.0.js.map +1 -0
  89. package/lib/injection/classes/node-gtk/Gtk-4.0.d.ts +2 -0
  90. package/lib/injection/classes/node-gtk/Gtk-4.0.js +52 -0
  91. package/lib/injection/classes/node-gtk/Gtk-4.0.js.map +1 -0
  92. package/lib/injection/classes/node-gtk/Pango-1.0.d.ts +2 -0
  93. package/lib/injection/classes/node-gtk/Pango-1.0.js +31 -0
  94. package/lib/injection/classes/node-gtk/Pango-1.0.js.map +1 -0
  95. package/lib/injection/classes/node-gtk/index.d.ts +2 -0
  96. package/lib/injection/classes/node-gtk/index.js +19 -0
  97. package/lib/injection/classes/node-gtk/index.js.map +1 -0
  98. package/lib/injection/index.d.ts +3 -0
  99. package/lib/injection/index.js +4 -0
  100. package/lib/injection/index.js.map +1 -0
  101. package/lib/injection/injector.d.ts +17 -0
  102. package/lib/injection/injector.js +136 -0
  103. package/lib/injection/injector.js.map +1 -0
  104. package/lib/logger.d.ts +36 -0
  105. package/lib/logger.js +133 -0
  106. package/lib/logger.js.map +1 -0
  107. package/lib/messages.d.ts +30 -0
  108. package/lib/messages.js +45 -0
  109. package/lib/messages.js.map +1 -0
  110. package/lib/module-loader.d.ts +131 -0
  111. package/lib/module-loader.js +467 -0
  112. package/lib/module-loader.js.map +1 -0
  113. package/lib/start.d.ts +2 -0
  114. package/lib/start.js +15 -0
  115. package/lib/start.js.map +1 -0
  116. package/lib/symtable.d.ts +24 -0
  117. package/lib/symtable.js +63 -0
  118. package/lib/symtable.js.map +1 -0
  119. package/lib/template-processor.d.ts +46 -0
  120. package/lib/template-processor.js +154 -0
  121. package/lib/template-processor.js.map +1 -0
  122. package/lib/transformation.d.ts +156 -0
  123. package/lib/transformation.js +523 -0
  124. package/lib/transformation.js.map +1 -0
  125. package/lib/type-definition-generator.d.ts +117 -0
  126. package/lib/type-definition-generator.js +929 -0
  127. package/lib/type-definition-generator.js.map +1 -0
  128. package/lib/types/answer-version.d.ts +4 -0
  129. package/lib/types/answer-version.js +2 -0
  130. package/lib/types/answer-version.js.map +1 -0
  131. package/lib/types/build-type.d.ts +1 -0
  132. package/lib/types/build-type.js +2 -0
  133. package/lib/types/build-type.js.map +1 -0
  134. package/lib/types/class-parent.d.ts +11 -0
  135. package/lib/types/class-parent.js +2 -0
  136. package/lib/types/class-parent.js.map +1 -0
  137. package/lib/types/config-flags.d.ts +4 -0
  138. package/lib/types/config-flags.js +2 -0
  139. package/lib/types/config-flags.js.map +1 -0
  140. package/lib/types/conflict-child-element.d.ts +10 -0
  141. package/lib/types/conflict-child-element.js +2 -0
  142. package/lib/types/conflict-child-element.js.map +1 -0
  143. package/lib/types/conflict-grouped-element.d.ts +6 -0
  144. package/lib/types/conflict-grouped-element.js +2 -0
  145. package/lib/types/conflict-grouped-element.js.map +1 -0
  146. package/lib/types/conflict-grouped-elements.d.ts +4 -0
  147. package/lib/types/conflict-grouped-elements.js +2 -0
  148. package/lib/types/conflict-grouped-elements.js.map +1 -0
  149. package/lib/types/construct-name.d.ts +1 -0
  150. package/lib/types/construct-name.js +2 -0
  151. package/lib/types/construct-name.js.map +1 -0
  152. package/lib/types/dependency-map.d.ts +4 -0
  153. package/lib/types/dependency-map.js +2 -0
  154. package/lib/types/dependency-map.js.map +1 -0
  155. package/lib/types/dependency.d.ts +14 -0
  156. package/lib/types/dependency.js +2 -0
  157. package/lib/types/dependency.js.map +1 -0
  158. package/lib/types/environment.d.ts +1 -0
  159. package/lib/types/environment.js +2 -0
  160. package/lib/types/environment.js.map +1 -0
  161. package/lib/types/generate-config.d.ts +30 -0
  162. package/lib/types/generate-config.js +2 -0
  163. package/lib/types/generate-config.js.map +1 -0
  164. package/lib/types/generator-type.d.ts +4 -0
  165. package/lib/types/generator-type.js +6 -0
  166. package/lib/types/generator-type.js.map +1 -0
  167. package/lib/types/gir-alias-element.d.ts +13 -0
  168. package/lib/types/gir-alias-element.js +2 -0
  169. package/lib/types/gir-alias-element.js.map +1 -0
  170. package/lib/types/gir-annotation.d.ts +9 -0
  171. package/lib/types/gir-annotation.js +2 -0
  172. package/lib/types/gir-annotation.js.map +1 -0
  173. package/lib/types/gir-any-element.d.ts +2 -0
  174. package/lib/types/gir-any-element.js +2 -0
  175. package/lib/types/gir-any-element.js.map +1 -0
  176. package/lib/types/gir-any-type.d.ts +5 -0
  177. package/lib/types/gir-any-type.js +2 -0
  178. package/lib/types/gir-any-type.js.map +1 -0
  179. package/lib/types/gir-array-type.d.ts +20 -0
  180. package/lib/types/gir-array-type.js +3 -0
  181. package/lib/types/gir-array-type.js.map +1 -0
  182. package/lib/types/gir-bitfield-element.d.ts +17 -0
  183. package/lib/types/gir-bitfield-element.js +2 -0
  184. package/lib/types/gir-bitfield-element.js.map +1 -0
  185. package/lib/types/gir-boolean.d.ts +1 -0
  186. package/lib/types/gir-boolean.js +2 -0
  187. package/lib/types/gir-boolean.js.map +1 -0
  188. package/lib/types/gir-boxed-element.d.ts +15 -0
  189. package/lib/types/gir-boxed-element.js +2 -0
  190. package/lib/types/gir-boxed-element.js.map +1 -0
  191. package/lib/types/gir-c-include.d.ts +7 -0
  192. package/lib/types/gir-c-include.js +2 -0
  193. package/lib/types/gir-c-include.js.map +1 -0
  194. package/lib/types/gir-callable-attrs.d.ts +15 -0
  195. package/lib/types/gir-callable-attrs.js +3 -0
  196. package/lib/types/gir-callable-attrs.js.map +1 -0
  197. package/lib/types/gir-callable-param-element.d.ts +30 -0
  198. package/lib/types/gir-callable-param-element.js +2 -0
  199. package/lib/types/gir-callable-param-element.js.map +1 -0
  200. package/lib/types/gir-callable-param.d.ts +7 -0
  201. package/lib/types/gir-callable-param.js +2 -0
  202. package/lib/types/gir-callable-param.js.map +1 -0
  203. package/lib/types/gir-callable-return.d.ts +22 -0
  204. package/lib/types/gir-callable-return.js +2 -0
  205. package/lib/types/gir-callable-return.js.map +1 -0
  206. package/lib/types/gir-callback-element.d.ts +15 -0
  207. package/lib/types/gir-callback-element.js +2 -0
  208. package/lib/types/gir-callback-element.js.map +1 -0
  209. package/lib/types/gir-class-element.d.ts +48 -0
  210. package/lib/types/gir-class-element.js +2 -0
  211. package/lib/types/gir-class-element.js.map +1 -0
  212. package/lib/types/gir-constant-element.d.ts +15 -0
  213. package/lib/types/gir-constant-element.js +2 -0
  214. package/lib/types/gir-constant-element.js.map +1 -0
  215. package/lib/types/gir-constructor-element.d.ts +8 -0
  216. package/lib/types/gir-constructor-element.js +2 -0
  217. package/lib/types/gir-constructor-element.js.map +1 -0
  218. package/lib/types/gir-direction.d.ts +5 -0
  219. package/lib/types/gir-direction.js +7 -0
  220. package/lib/types/gir-direction.js.map +1 -0
  221. package/lib/types/gir-doc-element.d.ts +68 -0
  222. package/lib/types/gir-doc-element.js +2 -0
  223. package/lib/types/gir-doc-element.js.map +1 -0
  224. package/lib/types/gir-enum-element.d.ts +19 -0
  225. package/lib/types/gir-enum-element.js +2 -0
  226. package/lib/types/gir-enum-element.js.map +1 -0
  227. package/lib/types/gir-field-element.d.ts +18 -0
  228. package/lib/types/gir-field-element.js +2 -0
  229. package/lib/types/gir-field-element.js.map +1 -0
  230. package/lib/types/gir-function-element.d.ts +8 -0
  231. package/lib/types/gir-function-element.js +2 -0
  232. package/lib/types/gir-function-element.js.map +1 -0
  233. package/lib/types/gir-implements.d.ts +8 -0
  234. package/lib/types/gir-implements.js +2 -0
  235. package/lib/types/gir-implements.js.map +1 -0
  236. package/lib/types/gir-include.d.ts +9 -0
  237. package/lib/types/gir-include.js +2 -0
  238. package/lib/types/gir-include.js.map +1 -0
  239. package/lib/types/gir-info-attrs.d.ts +13 -0
  240. package/lib/types/gir-info-attrs.js +2 -0
  241. package/lib/types/gir-info-attrs.js.map +1 -0
  242. package/lib/types/gir-info-elements.d.ts +5 -0
  243. package/lib/types/gir-info-elements.js +2 -0
  244. package/lib/types/gir-info-elements.js.map +1 -0
  245. package/lib/types/gir-instance-parameter.d.ts +21 -0
  246. package/lib/types/gir-instance-parameter.js +2 -0
  247. package/lib/types/gir-instance-parameter.js.map +1 -0
  248. package/lib/types/gir-interface-element.d.ts +31 -0
  249. package/lib/types/gir-interface-element.js +2 -0
  250. package/lib/types/gir-interface-element.js.map +1 -0
  251. package/lib/types/gir-member-element.d.ts +17 -0
  252. package/lib/types/gir-member-element.js +2 -0
  253. package/lib/types/gir-member-element.js.map +1 -0
  254. package/lib/types/gir-method-element.d.ts +13 -0
  255. package/lib/types/gir-method-element.js +2 -0
  256. package/lib/types/gir-method-element.js.map +1 -0
  257. package/lib/types/gir-module-resolved-by.d.ts +10 -0
  258. package/lib/types/gir-module-resolved-by.js +2 -0
  259. package/lib/types/gir-module-resolved-by.js.map +1 -0
  260. package/lib/types/gir-modules-grouped-map.d.ts +4 -0
  261. package/lib/types/gir-modules-grouped-map.js +2 -0
  262. package/lib/types/gir-modules-grouped-map.js.map +1 -0
  263. package/lib/types/gir-modules-grouped.d.ts +12 -0
  264. package/lib/types/gir-modules-grouped.js +2 -0
  265. package/lib/types/gir-modules-grouped.js.map +1 -0
  266. package/lib/types/gir-namespace.d.ts +30 -0
  267. package/lib/types/gir-namespace.js +2 -0
  268. package/lib/types/gir-namespace.js.map +1 -0
  269. package/lib/types/gir-package.d.ts +7 -0
  270. package/lib/types/gir-package.js +2 -0
  271. package/lib/types/gir-package.js.map +1 -0
  272. package/lib/types/gir-prerequisite.d.ts +5 -0
  273. package/lib/types/gir-prerequisite.js +2 -0
  274. package/lib/types/gir-prerequisite.js.map +1 -0
  275. package/lib/types/gir-property-element.d.ts +21 -0
  276. package/lib/types/gir-property-element.js +2 -0
  277. package/lib/types/gir-property-element.js.map +1 -0
  278. package/lib/types/gir-record-element.d.ts +30 -0
  279. package/lib/types/gir-record-element.js +2 -0
  280. package/lib/types/gir-record-element.js.map +1 -0
  281. package/lib/types/gir-repository.d.ts +16 -0
  282. package/lib/types/gir-repository.js +2 -0
  283. package/lib/types/gir-repository.js.map +1 -0
  284. package/lib/types/gir-signal.d.ts +25 -0
  285. package/lib/types/gir-signal.js +2 -0
  286. package/lib/types/gir-signal.js.map +1 -0
  287. package/lib/types/gir-transfer-ownership-type.d.ts +5 -0
  288. package/lib/types/gir-transfer-ownership-type.js +7 -0
  289. package/lib/types/gir-transfer-ownership-type.js.map +1 -0
  290. package/lib/types/gir-transfer-ownership.d.ts +5 -0
  291. package/lib/types/gir-transfer-ownership.js +2 -0
  292. package/lib/types/gir-transfer-ownership.js.map +1 -0
  293. package/lib/types/gir-type.d.ts +14 -0
  294. package/lib/types/gir-type.js +2 -0
  295. package/lib/types/gir-type.js.map +1 -0
  296. package/lib/types/gir-union-element.d.ts +22 -0
  297. package/lib/types/gir-union-element.js +2 -0
  298. package/lib/types/gir-union-element.js.map +1 -0
  299. package/lib/types/gir-unparsed-number.d.ts +2 -0
  300. package/lib/types/gir-unparsed-number.js +2 -0
  301. package/lib/types/gir-unparsed-number.js.map +1 -0
  302. package/lib/types/gir-var-args.d.ts +5 -0
  303. package/lib/types/gir-var-args.js +2 -0
  304. package/lib/types/gir-var-args.js.map +1 -0
  305. package/lib/types/gir-virtual-method.d.ts +10 -0
  306. package/lib/types/gir-virtual-method.js +2 -0
  307. package/lib/types/gir-virtual-method.js.map +1 -0
  308. package/lib/types/index.d.ts +118 -0
  309. package/lib/types/index.js +119 -0
  310. package/lib/types/index.js.map +1 -0
  311. package/lib/types/inheritance-table.d.ts +3 -0
  312. package/lib/types/inheritance-table.js +2 -0
  313. package/lib/types/inheritance-table.js.map +1 -0
  314. package/lib/types/injection-callback.d.ts +16 -0
  315. package/lib/types/injection-callback.js +2 -0
  316. package/lib/types/injection-callback.js.map +1 -0
  317. package/lib/types/injection-class.d.ts +24 -0
  318. package/lib/types/injection-class.js +2 -0
  319. package/lib/types/injection-class.js.map +1 -0
  320. package/lib/types/injection-function.d.ts +7 -0
  321. package/lib/types/injection-function.js +2 -0
  322. package/lib/types/injection-function.js.map +1 -0
  323. package/lib/types/injection-generic-parameter.d.ts +2 -0
  324. package/lib/types/injection-generic-parameter.js +2 -0
  325. package/lib/types/injection-generic-parameter.js.map +1 -0
  326. package/lib/types/injection-instance-parameter.d.ts +2 -0
  327. package/lib/types/injection-instance-parameter.js +2 -0
  328. package/lib/types/injection-instance-parameter.js.map +1 -0
  329. package/lib/types/injection-parameter.d.ts +8 -0
  330. package/lib/types/injection-parameter.js +2 -0
  331. package/lib/types/injection-parameter.js.map +1 -0
  332. package/lib/types/injection-property.d.ts +4 -0
  333. package/lib/types/injection-property.js +2 -0
  334. package/lib/types/injection-property.js.map +1 -0
  335. package/lib/types/injection-type.d.ts +2 -0
  336. package/lib/types/injection-type.js +2 -0
  337. package/lib/types/injection-type.js.map +1 -0
  338. package/lib/types/injection.d.ts +5 -0
  339. package/lib/types/injection.js +2 -0
  340. package/lib/types/injection.js.map +1 -0
  341. package/lib/types/local-name-check.d.ts +4 -0
  342. package/lib/types/local-name-check.js +2 -0
  343. package/lib/types/local-name-check.js.map +1 -0
  344. package/lib/types/local-name-type.d.ts +1 -0
  345. package/lib/types/local-name-type.js +2 -0
  346. package/lib/types/local-name-type.js.map +1 -0
  347. package/lib/types/local-name.d.ts +7 -0
  348. package/lib/types/local-name.js +2 -0
  349. package/lib/types/local-name.js.map +1 -0
  350. package/lib/types/local-names.d.ts +4 -0
  351. package/lib/types/local-names.js +2 -0
  352. package/lib/types/local-names.js.map +1 -0
  353. package/lib/types/module-type.d.ts +1 -0
  354. package/lib/types/module-type.js +2 -0
  355. package/lib/types/module-type.js.map +1 -0
  356. package/lib/types/parsed-gir.d.ts +4 -0
  357. package/lib/types/parsed-gir.js +2 -0
  358. package/lib/types/parsed-gir.js.map +1 -0
  359. package/lib/types/part-of-class.d.ts +7 -0
  360. package/lib/types/part-of-class.js +2 -0
  361. package/lib/types/part-of-class.js.map +1 -0
  362. package/lib/types/part-of-module.d.ts +6 -0
  363. package/lib/types/part-of-module.js +2 -0
  364. package/lib/types/part-of-module.js.map +1 -0
  365. package/lib/types/resolve-type.d.ts +4 -0
  366. package/lib/types/resolve-type.js +6 -0
  367. package/lib/types/resolve-type.js.map +1 -0
  368. package/lib/types/sym-table-items.d.ts +4 -0
  369. package/lib/types/sym-table-items.js +2 -0
  370. package/lib/types/sym-table-items.js.map +1 -0
  371. package/lib/types/transformation-case.d.ts +1 -0
  372. package/lib/types/transformation-case.js +2 -0
  373. package/lib/types/transformation-case.js.map +1 -0
  374. package/lib/types/transformations.d.ts +11 -0
  375. package/lib/types/transformations.js +2 -0
  376. package/lib/types/transformations.js.map +1 -0
  377. package/lib/types/ts-alias.d.ts +10 -0
  378. package/lib/types/ts-alias.js +2 -0
  379. package/lib/types/ts-alias.js.map +1 -0
  380. package/lib/types/ts-callback-interface.d.ts +10 -0
  381. package/lib/types/ts-callback-interface.js +2 -0
  382. package/lib/types/ts-callback-interface.js.map +1 -0
  383. package/lib/types/ts-callback.d.ts +17 -0
  384. package/lib/types/ts-callback.js +2 -0
  385. package/lib/types/ts-callback.js.map +1 -0
  386. package/lib/types/ts-class.d.ts +85 -0
  387. package/lib/types/ts-class.js +2 -0
  388. package/lib/types/ts-class.js.map +1 -0
  389. package/lib/types/ts-doc-tag.d.ts +21 -0
  390. package/lib/types/ts-doc-tag.js +2 -0
  391. package/lib/types/ts-doc-tag.js.map +1 -0
  392. package/lib/types/ts-doc.d.ts +20 -0
  393. package/lib/types/ts-doc.js +2 -0
  394. package/lib/types/ts-doc.js.map +1 -0
  395. package/lib/types/ts-enum.d.ts +12 -0
  396. package/lib/types/ts-enum.js +2 -0
  397. package/lib/types/ts-enum.js.map +1 -0
  398. package/lib/types/ts-function.d.ts +44 -0
  399. package/lib/types/ts-function.js +2 -0
  400. package/lib/types/ts-function.js.map +1 -0
  401. package/lib/types/ts-generic-parameter.d.ts +8 -0
  402. package/lib/types/ts-generic-parameter.js +2 -0
  403. package/lib/types/ts-generic-parameter.js.map +1 -0
  404. package/lib/types/ts-instance-parameter.d.ts +4 -0
  405. package/lib/types/ts-instance-parameter.js +2 -0
  406. package/lib/types/ts-instance-parameter.js.map +1 -0
  407. package/lib/types/ts-member.d.ts +10 -0
  408. package/lib/types/ts-member.js +2 -0
  409. package/lib/types/ts-member.js.map +1 -0
  410. package/lib/types/ts-method.d.ts +5 -0
  411. package/lib/types/ts-method.js +2 -0
  412. package/lib/types/ts-method.js.map +1 -0
  413. package/lib/types/ts-parameter.d.ts +15 -0
  414. package/lib/types/ts-parameter.js +2 -0
  415. package/lib/types/ts-parameter.js.map +1 -0
  416. package/lib/types/ts-property.d.ts +17 -0
  417. package/lib/types/ts-property.js +2 -0
  418. package/lib/types/ts-property.js.map +1 -0
  419. package/lib/types/ts-signal.d.ts +17 -0
  420. package/lib/types/ts-signal.js +2 -0
  421. package/lib/types/ts-signal.js.map +1 -0
  422. package/lib/types/ts-type-name.d.ts +1 -0
  423. package/lib/types/ts-type-name.js +2 -0
  424. package/lib/types/ts-type-name.js.map +1 -0
  425. package/lib/types/ts-type-separator.d.ts +1 -0
  426. package/lib/types/ts-type-separator.js +2 -0
  427. package/lib/types/ts-type-separator.js.map +1 -0
  428. package/lib/types/ts-type.d.ts +22 -0
  429. package/lib/types/ts-type.js +2 -0
  430. package/lib/types/ts-type.js.map +1 -0
  431. package/lib/types/ts-var.d.ts +17 -0
  432. package/lib/types/ts-var.js +2 -0
  433. package/lib/types/ts-var.js.map +1 -0
  434. package/lib/types/type-gir-alias.d.ts +2 -0
  435. package/lib/types/type-gir-alias.js +2 -0
  436. package/lib/types/type-gir-alias.js.map +1 -0
  437. package/lib/types/type-gir-class.d.ts +2 -0
  438. package/lib/types/type-gir-class.js +2 -0
  439. package/lib/types/type-gir-class.js.map +1 -0
  440. package/lib/types/type-gir-element.d.ts +3 -0
  441. package/lib/types/type-gir-element.js +2 -0
  442. package/lib/types/type-gir-element.js.map +1 -0
  443. package/lib/types/type-gir-enumeration-member.d.ts +2 -0
  444. package/lib/types/type-gir-enumeration-member.js +2 -0
  445. package/lib/types/type-gir-enumeration-member.js.map +1 -0
  446. package/lib/types/type-gir-enumeration.d.ts +2 -0
  447. package/lib/types/type-gir-enumeration.js +2 -0
  448. package/lib/types/type-gir-enumeration.js.map +1 -0
  449. package/lib/types/type-gir-function.d.ts +1 -0
  450. package/lib/types/type-gir-function.js +2 -0
  451. package/lib/types/type-gir-function.js.map +1 -0
  452. package/lib/types/type-gir-interface.d.ts +2 -0
  453. package/lib/types/type-gir-interface.js +2 -0
  454. package/lib/types/type-gir-interface.js.map +1 -0
  455. package/lib/types/type-gir-method.d.ts +2 -0
  456. package/lib/types/type-gir-method.js +2 -0
  457. package/lib/types/type-gir-method.js.map +1 -0
  458. package/lib/types/type-gir-parameter.d.ts +1 -0
  459. package/lib/types/type-gir-parameter.js +2 -0
  460. package/lib/types/type-gir-parameter.js.map +1 -0
  461. package/lib/types/type-gir-property.d.ts +2 -0
  462. package/lib/types/type-gir-property.js +2 -0
  463. package/lib/types/type-gir-property.js.map +1 -0
  464. package/lib/types/type-gir-variable.d.ts +1 -0
  465. package/lib/types/type-gir-variable.js +2 -0
  466. package/lib/types/type-gir-variable.js.map +1 -0
  467. package/lib/types/type-ts-element.d.ts +3 -0
  468. package/lib/types/type-ts-element.js +2 -0
  469. package/lib/types/type-ts-element.js.map +1 -0
  470. package/lib/types/type-ts-enumeration-member.d.ts +2 -0
  471. package/lib/types/type-ts-enumeration-member.js +2 -0
  472. package/lib/types/type-ts-enumeration-member.js.map +1 -0
  473. package/lib/types/type-ts-function.d.ts +1 -0
  474. package/lib/types/type-ts-function.js +2 -0
  475. package/lib/types/type-ts-function.js.map +1 -0
  476. package/lib/types/type-ts-property.d.ts +1 -0
  477. package/lib/types/type-ts-property.js +2 -0
  478. package/lib/types/type-ts-property.js.map +1 -0
  479. package/lib/types/user-config-load-result.d.ts +6 -0
  480. package/lib/types/user-config-load-result.js +2 -0
  481. package/lib/types/user-config-load-result.js.map +1 -0
  482. package/lib/types/user-config.d.ts +38 -0
  483. package/lib/types/user-config.js +2 -0
  484. package/lib/types/user-config.js.map +1 -0
  485. package/lib/utils.d.ts +88 -0
  486. package/lib/utils.js +189 -0
  487. package/lib/utils.js.map +1 -0
  488. package/package.json +72 -0
  489. package/src/commands/doc.ts +65 -0
  490. package/src/commands/generate.ts +86 -0
  491. package/src/commands/index.ts +3 -0
  492. package/src/commands/list.ts +96 -0
  493. package/src/config.ts +426 -0
  494. package/src/conflict-resolver.ts +1350 -0
  495. package/src/constants.ts +29 -0
  496. package/src/generation-handler.ts +79 -0
  497. package/src/generator.ts +10 -0
  498. package/src/gir-factory.ts +488 -0
  499. package/src/gir-module.ts +2816 -0
  500. package/src/html-doc-generator.ts +23 -0
  501. package/src/index.ts +17 -0
  502. package/src/injection/callbacks/gjs/Gio-2.0.ts +37 -0
  503. package/src/injection/callbacks/gjs/index.ts +5 -0
  504. package/src/injection/callbacks/index.ts +6 -0
  505. package/src/injection/callbacks/node-gtk/index.ts +3 -0
  506. package/src/injection/classes/GLib-2-0.ts +36 -0
  507. package/src/injection/classes/gjs/GLib-2.0.ts +75 -0
  508. package/src/injection/classes/gjs/GObject-2.0.ts +635 -0
  509. package/src/injection/classes/gjs/Gio-2.0.ts +219 -0
  510. package/src/injection/classes/gjs/index.ts +7 -0
  511. package/src/injection/classes/index.ts +7 -0
  512. package/src/injection/classes/node-gtk/GLib-2.0.ts +20 -0
  513. package/src/injection/classes/node-gtk/GObject-2.0.ts +67 -0
  514. package/src/injection/classes/node-gtk/Gdk-4.0.ts +33 -0
  515. package/src/injection/classes/node-gtk/Gio-2.0.ts +15 -0
  516. package/src/injection/classes/node-gtk/Graphene-1.0.ts +134 -0
  517. package/src/injection/classes/node-gtk/Gtk-3.0.ts +32 -0
  518. package/src/injection/classes/node-gtk/Gtk-4.0.ts +53 -0
  519. package/src/injection/classes/node-gtk/Pango-1.0.ts +32 -0
  520. package/src/injection/classes/node-gtk/index.ts +21 -0
  521. package/src/injection/index.ts +3 -0
  522. package/src/injection/injector.ts +179 -0
  523. package/src/logger.ts +134 -0
  524. package/src/messages.ts +68 -0
  525. package/src/module-loader.ts +573 -0
  526. package/src/start.ts +16 -0
  527. package/src/symtable.ts +70 -0
  528. package/src/template-processor.ts +170 -0
  529. package/src/transformation.ts +583 -0
  530. package/src/type-definition-generator.ts +1387 -0
  531. package/src/types/answer-version.ts +4 -0
  532. package/src/types/build-type.ts +1 -0
  533. package/src/types/class-parent.ts +12 -0
  534. package/src/types/config-flags.ts +5 -0
  535. package/src/types/conflict-child-element.ts +11 -0
  536. package/src/types/conflict-grouped-element.ts +7 -0
  537. package/src/types/conflict-grouped-elements.ts +5 -0
  538. package/src/types/construct-name.ts +11 -0
  539. package/src/types/dependency-map.ts +4 -0
  540. package/src/types/dependency.ts +14 -0
  541. package/src/types/environment.ts +1 -0
  542. package/src/types/generate-config.ts +31 -0
  543. package/src/types/generator-type.ts +4 -0
  544. package/src/types/gir-alias-element.ts +15 -0
  545. package/src/types/gir-annotation.ts +10 -0
  546. package/src/types/gir-any-element.ts +35 -0
  547. package/src/types/gir-any-type.ts +7 -0
  548. package/src/types/gir-array-type.ts +23 -0
  549. package/src/types/gir-bitfield-element.ts +20 -0
  550. package/src/types/gir-boolean.ts +1 -0
  551. package/src/types/gir-boxed-element.ts +19 -0
  552. package/src/types/gir-c-include.ts +7 -0
  553. package/src/types/gir-callable-attrs.ts +19 -0
  554. package/src/types/gir-callable-param-element.ts +45 -0
  555. package/src/types/gir-callable-param.ts +9 -0
  556. package/src/types/gir-callable-return.ts +25 -0
  557. package/src/types/gir-callback-element.ts +28 -0
  558. package/src/types/gir-class-element.ts +71 -0
  559. package/src/types/gir-constant-element.ts +17 -0
  560. package/src/types/gir-constructor-element.ts +18 -0
  561. package/src/types/gir-direction.ts +5 -0
  562. package/src/types/gir-doc-element.ts +73 -0
  563. package/src/types/gir-enum-element.ts +28 -0
  564. package/src/types/gir-field-element.ts +31 -0
  565. package/src/types/gir-function-element.ts +19 -0
  566. package/src/types/gir-implements.ts +9 -0
  567. package/src/types/gir-include.ts +9 -0
  568. package/src/types/gir-info-attrs.ts +16 -0
  569. package/src/types/gir-info-elements.ts +8 -0
  570. package/src/types/gir-instance-parameter.ts +25 -0
  571. package/src/types/gir-interface-element.ts +53 -0
  572. package/src/types/gir-member-element.ts +19 -0
  573. package/src/types/gir-method-element.ts +25 -0
  574. package/src/types/gir-module-resolved-by.ts +11 -0
  575. package/src/types/gir-modules-grouped-map.ts +5 -0
  576. package/src/types/gir-modules-grouped.ts +13 -0
  577. package/src/types/gir-namespace.ts +47 -0
  578. package/src/types/gir-package.ts +7 -0
  579. package/src/types/gir-prerequisite.ts +5 -0
  580. package/src/types/gir-property-element.ts +31 -0
  581. package/src/types/gir-record-element.ts +47 -0
  582. package/src/types/gir-repository.ts +20 -0
  583. package/src/types/gir-signal.ts +43 -0
  584. package/src/types/gir-transfer-ownership-type.ts +5 -0
  585. package/src/types/gir-transfer-ownership.ts +6 -0
  586. package/src/types/gir-type.ts +16 -0
  587. package/src/types/gir-union-element.ts +35 -0
  588. package/src/types/gir-unparsed-number.ts +2 -0
  589. package/src/types/gir-var-args.ts +6 -0
  590. package/src/types/gir-virtual-method.ts +22 -0
  591. package/src/types/index.ts +118 -0
  592. package/src/types/inheritance-table.ts +3 -0
  593. package/src/types/injection-callback.ts +20 -0
  594. package/src/types/injection-class.ts +30 -0
  595. package/src/types/injection-function.ts +23 -0
  596. package/src/types/injection-generic-parameter.ts +3 -0
  597. package/src/types/injection-instance-parameter.ts +3 -0
  598. package/src/types/injection-parameter.ts +9 -0
  599. package/src/types/injection-property.ts +7 -0
  600. package/src/types/injection-type.ts +3 -0
  601. package/src/types/injection.ts +6 -0
  602. package/src/types/local-name-check.ts +5 -0
  603. package/src/types/local-name-type.ts +1 -0
  604. package/src/types/local-name.ts +8 -0
  605. package/src/types/local-names.ts +5 -0
  606. package/src/types/module-type.ts +1 -0
  607. package/src/types/parsed-gir.ts +5 -0
  608. package/src/types/part-of-class.ts +9 -0
  609. package/src/types/part-of-module.ts +8 -0
  610. package/src/types/resolve-type.ts +4 -0
  611. package/src/types/sym-table-items.ts +5 -0
  612. package/src/types/transformation-case.ts +7 -0
  613. package/src/types/transformations.ts +12 -0
  614. package/src/types/ts-alias.ts +11 -0
  615. package/src/types/ts-callback-interface.ts +11 -0
  616. package/src/types/ts-callback.ts +21 -0
  617. package/src/types/ts-class.ts +109 -0
  618. package/src/types/ts-doc-tag.ts +23 -0
  619. package/src/types/ts-doc.ts +23 -0
  620. package/src/types/ts-enum.ts +15 -0
  621. package/src/types/ts-function.ts +59 -0
  622. package/src/types/ts-generic-parameter.ts +8 -0
  623. package/src/types/ts-instance-parameter.ts +4 -0
  624. package/src/types/ts-member.ts +11 -0
  625. package/src/types/ts-method.ts +6 -0
  626. package/src/types/ts-parameter.ts +20 -0
  627. package/src/types/ts-property.ts +22 -0
  628. package/src/types/ts-signal.ts +21 -0
  629. package/src/types/ts-type-name.ts +1 -0
  630. package/src/types/ts-type-separator.ts +1 -0
  631. package/src/types/ts-type.ts +25 -0
  632. package/src/types/ts-var.ts +21 -0
  633. package/src/types/type-gir-alias.ts +2 -0
  634. package/src/types/type-gir-class.ts +2 -0
  635. package/src/types/type-gir-element.ts +25 -0
  636. package/src/types/type-gir-enumeration-member.ts +2 -0
  637. package/src/types/type-gir-enumeration.ts +2 -0
  638. package/src/types/type-gir-function.ts +8 -0
  639. package/src/types/type-gir-interface.ts +2 -0
  640. package/src/types/type-gir-method.ts +2 -0
  641. package/src/types/type-gir-parameter.ts +1 -0
  642. package/src/types/type-gir-property.ts +2 -0
  643. package/src/types/type-gir-variable.ts +1 -0
  644. package/src/types/type-ts-element.ts +13 -0
  645. package/src/types/type-ts-enumeration-member.ts +2 -0
  646. package/src/types/type-ts-function.ts +1 -0
  647. package/src/types/type-ts-property.ts +1 -0
  648. package/src/types/user-config-load-result.ts +6 -0
  649. package/src/types/user-config.ts +39 -0
  650. package/src/utils.ts +217 -0
  651. package/templates/Cogl-2.0.d.ts +0 -0
  652. package/templates/Gjs/GObject-2.0.d.ts +238 -0
  653. package/templates/Gjs/Gio-2.0.d.ts +64 -0
  654. package/templates/Gjs/Gjs.d.ts +135 -0
  655. package/templates/Gjs/Gjs.js +21 -0
  656. package/templates/Gjs/cast.ts +52 -0
  657. package/templates/Gjs/index.d.ts +279 -0
  658. package/templates/Gjs/index.js +4 -0
  659. package/templates/Gjs/module.d.ts +10 -0
  660. package/templates/Gjs/module.js +16 -0
  661. package/templates/Granite-1.0.d.ts +7 -0
  662. package/templates/Granite-7.0.d.ts +7 -0
  663. package/templates/GstBase-0.10.d.ts +5 -0
  664. package/templates/RygelServer-2.6.d.ts +3 -0
  665. package/templates/node-gtk/GObject-2.0.d.ts +57 -0
  666. package/templates/node-gtk/index.d.ts +40 -0
  667. package/templates/node-gtk/index.js +9 -0
  668. package/templates/node-gtk/module.d.ts +10 -0
  669. package/templates/node-gtk/module.js +17 -0
@@ -0,0 +1,1350 @@
1
+ import { GirFactory } from './gir-factory.js'
2
+ import { Logger } from './logger.js'
3
+ import { NO_TSDATA } from './messages.js'
4
+ import { isEqual, merge, clone, typeIsOptional } from './utils.js'
5
+ import { SIGNAL_METHOD_NAMES, MAX_CLASS_PARENT_DEPTH } from './constants.js'
6
+ import type {
7
+ Environment,
8
+ GirClassElement,
9
+ GirRecordElement,
10
+ GirUnionElement,
11
+ GirInterfaceElement,
12
+ GirCallableParamElement,
13
+ GirMethodElement,
14
+ GirVirtualMethodElement,
15
+ GirConstructorElement,
16
+ GirFunctionElement,
17
+ GirPropertyElement,
18
+ GirFieldElement,
19
+ TsSignal,
20
+ TsFunction,
21
+ TsProperty,
22
+ TsVar,
23
+ TsTypeSeparator,
24
+ TsType,
25
+ TsClass,
26
+ TsParameter,
27
+ TypeGirFunction,
28
+ TypeGirProperty,
29
+ ConflictChildElement,
30
+ ConflictGroupedElements,
31
+ ConflictGroupedElement,
32
+ } from './types/index.js'
33
+
34
+ /**
35
+ * Resolve conflicts between types caused by overloads / inheritances and implementations
36
+ * With multiple implementations or a inherit it can happen that the interfaces / parent have the same method and/or property names with incompatible types,
37
+ * we are trying to resolve this conflicts by merging, overloading or removing this conflicts.
38
+ */
39
+ export class ConflictResolver {
40
+ private log: Logger
41
+
42
+ private girFactory = new GirFactory()
43
+
44
+ constructor(private readonly environment: Environment) {
45
+ this.log = new Logger(environment, true, 'ConflictResolver')
46
+ }
47
+
48
+ private girElArrToChildArr<T = TsFunction | TsProperty | TsVar>(
49
+ dataArr: Array<
50
+ | GirMethodElement
51
+ | GirVirtualMethodElement
52
+ | GirConstructorElement
53
+ | GirFunctionElement
54
+ | GirPropertyElement
55
+ | GirFieldElement
56
+ >,
57
+ depth: number,
58
+ ): ConflictChildElement<T>[] {
59
+ return dataArr
60
+ .filter((data) => !!data?._tsData)
61
+ .map((data) => {
62
+ if (!data?._tsData) throw new Error('_tsData not set!')
63
+ return {
64
+ depth,
65
+ data: data?._tsData as unknown as T,
66
+ }
67
+ })
68
+ }
69
+
70
+ private tsElArrToChildArr<T extends ConflictChildElement>(
71
+ dataArr: Array<TsFunction | TsProperty | TsVar>,
72
+ depth: number,
73
+ ): T[] {
74
+ return dataArr
75
+ .filter((m) => !!m)
76
+ .map((data) => {
77
+ return {
78
+ depth,
79
+ data,
80
+ } as T
81
+ })
82
+ }
83
+
84
+ /**
85
+ * Get class elements and parent elements (implementations and inherits)
86
+ * @param tsClass
87
+ * @param depth
88
+ * @returns
89
+ */
90
+ private getClassElements(tsClass: TsClass, depth: number, processedClasses: string[]) {
91
+ const tsClassFullPackageSymName = `${tsClass.namespace}-${tsClass.version}.${tsClass.namespace}.${tsClass.name}`
92
+
93
+ const signalMethods: ConflictChildElement<TsFunction>[] = []
94
+ const propertySignalMethods: ConflictChildElement<TsFunction>[] = []
95
+ const methods: ConflictChildElement<TsFunction>[] = []
96
+ const virtualMethods: ConflictChildElement<TsFunction>[] = []
97
+ const staticFunctions: ConflictChildElement<TsFunction>[] = []
98
+ const constructors: ConflictChildElement<TsFunction>[] = []
99
+
100
+ const properties: ConflictChildElement<TsProperty | TsVar>[] = []
101
+ const fields: ConflictChildElement<TsProperty | TsVar>[] = []
102
+ const constructProps: ConflictChildElement<TsProperty | TsVar>[] = []
103
+
104
+ const depthLimitReached = depth >= MAX_CLASS_PARENT_DEPTH
105
+ const classAlreadyProcessed = processedClasses.includes(tsClassFullPackageSymName)
106
+
107
+ if (depthLimitReached || classAlreadyProcessed) {
108
+ if (depthLimitReached) {
109
+ this.log.error(`[getClassElements] Maximum recursion depth reached (limit: ${MAX_CLASS_PARENT_DEPTH})!`)
110
+ }
111
+ return {
112
+ signalMethods,
113
+ propertySignalMethods,
114
+ methods,
115
+ virtualMethods,
116
+ staticFunctions,
117
+ constructors,
118
+ properties,
119
+ fields,
120
+ constructProps,
121
+ }
122
+ }
123
+
124
+ // Signals
125
+ const _signals = tsClass.signals.map((s) => s._tsData).filter((s) => !!s) as TsSignal[]
126
+ for (const tsSignal of _signals) {
127
+ signalMethods.push(...this.tsElArrToChildArr<ConflictChildElement<TsFunction>>(tsSignal.tsMethods, depth))
128
+ }
129
+ // Property signals
130
+ propertySignalMethods.push(
131
+ ...this.tsElArrToChildArr<ConflictChildElement<TsFunction>>(tsClass.propertySignalMethods, depth),
132
+ )
133
+ // Methods
134
+ if (tsClass.methods.length) methods.push(...this.girElArrToChildArr<TsFunction>(tsClass.methods, depth))
135
+ // Virtual methods
136
+ if (tsClass.virtualMethods.length)
137
+ virtualMethods.push(...this.girElArrToChildArr<TsFunction>(tsClass.virtualMethods, depth))
138
+ // Static functions
139
+ if (tsClass.staticFunctions.length)
140
+ staticFunctions.push(...this.girElArrToChildArr<TsFunction>(tsClass.staticFunctions, depth))
141
+ // Constructors
142
+ if (tsClass.constructors.length)
143
+ constructors.push(...this.girElArrToChildArr<TsFunction>(tsClass.constructors, depth))
144
+ // Properties
145
+ if (tsClass.properties.length)
146
+ properties.push(...this.girElArrToChildArr<TsProperty | TsVar>(tsClass.properties, depth))
147
+ // Fields
148
+ if (tsClass.fields.length) fields.push(...this.girElArrToChildArr<TsProperty | TsVar>(tsClass.fields, depth))
149
+ // Constructor properties
150
+ if (tsClass.constructProps.length)
151
+ constructProps.push(...this.girElArrToChildArr<TsProperty | TsVar>(tsClass.constructProps, depth))
152
+
153
+ for (const ifacePackageFullSymName of Object.keys(tsClass.implements)) {
154
+ if (tsClassFullPackageSymName === ifacePackageFullSymName) {
155
+ this.log.warn("[getImplementedInterfaceElements] A interface can't implement itself")
156
+ continue
157
+ }
158
+
159
+ const { interface: implementation, depth: parentDepth } = tsClass.implements[ifacePackageFullSymName]
160
+ const implementationElements = this.getClassElements(
161
+ implementation,
162
+ parentDepth + depth + 1,
163
+ processedClasses,
164
+ )
165
+
166
+ signalMethods.push(...implementationElements.signalMethods)
167
+ propertySignalMethods.push(...implementationElements.propertySignalMethods)
168
+ methods.push(...implementationElements.methods)
169
+ virtualMethods.push(...implementationElements.virtualMethods)
170
+ staticFunctions.push(...implementationElements.staticFunctions)
171
+ constructors.push(...implementationElements.constructors)
172
+ properties.push(...implementationElements.properties)
173
+ fields.push(...implementationElements.fields)
174
+ constructProps.push(...implementationElements.constructProps)
175
+ }
176
+
177
+ for (const ifaceFullPackageSymName of Object.keys(tsClass.inherit)) {
178
+ if (tsClassFullPackageSymName === ifaceFullPackageSymName) {
179
+ this.log.warn("[getClassElements] A class can't inherit itself")
180
+ continue
181
+ }
182
+
183
+ const { class: inherit, depth: parentDepth } = tsClass.inherit[ifaceFullPackageSymName]
184
+ const inheritElements = this.getClassElements(inherit, parentDepth + depth + 1, processedClasses)
185
+
186
+ signalMethods.push(...inheritElements.signalMethods)
187
+ propertySignalMethods.push(...inheritElements.propertySignalMethods)
188
+ methods.push(...inheritElements.methods)
189
+ virtualMethods.push(...inheritElements.virtualMethods)
190
+ staticFunctions.push(...inheritElements.staticFunctions)
191
+ constructors.push(...inheritElements.constructors)
192
+ properties.push(...inheritElements.properties)
193
+ fields.push(...inheritElements.fields)
194
+ constructProps.push(...inheritElements.constructProps)
195
+ }
196
+
197
+ processedClasses.push(tsClassFullPackageSymName)
198
+
199
+ return {
200
+ signalMethods,
201
+ propertySignalMethods,
202
+ methods,
203
+ virtualMethods,
204
+ staticFunctions,
205
+ constructors,
206
+ properties,
207
+ fields,
208
+ constructProps,
209
+ }
210
+ }
211
+
212
+ private tsElementIsMethod(el: TsFunction | TsVar) {
213
+ return !this.tsElementIsStatic(el) && this.tsElementIsMethodOrFunction(el)
214
+ }
215
+
216
+ private tsElementIsStaticFunction(el: TsFunction | TsVar) {
217
+ return this.tsElementIsStatic(el) && this.tsElementIsMethodOrFunction(el)
218
+ }
219
+
220
+ private tsElementIsProperty(el: TsFunction | TsVar) {
221
+ return !this.tsElementIsStatic(el) && this.tsElementIsPropertyOrVariable(el)
222
+ }
223
+
224
+ private tsElementIsStaticProperty(el: TsFunction | TsVar) {
225
+ return this.tsElementIsStatic(el) && this.tsElementIsPropertyOrVariable(el)
226
+ }
227
+
228
+ private tsElementIsSignal(el: TsFunction | TsVar) {
229
+ return el.tsTypeName === 'event-methods'
230
+ }
231
+
232
+ private tsElementIsConstructor(el: TsFunction | TsVar) {
233
+ return el.tsTypeName === 'constructor'
234
+ }
235
+
236
+ private tsElementIsMethodOrFunction(el: TsFunction | TsVar) {
237
+ return el.tsTypeName === 'function' || el.tsTypeName === 'method' || el.tsTypeName === 'static-function'
238
+ }
239
+
240
+ private tsElementIsPropertyOrVariable(el: TsFunction | TsVar | TsProperty) {
241
+ return (
242
+ el.tsTypeName === 'constant' ||
243
+ el.tsTypeName === 'constructor-property' ||
244
+ el.tsTypeName === 'property' ||
245
+ el.tsTypeName === 'static-property'
246
+ )
247
+ }
248
+
249
+ private tsElementIsStatic(el: TsFunction | TsVar) {
250
+ return (
251
+ // el.tsTypeName === 'constructor' ||
252
+ (el as TsFunction).isStatic || el.tsTypeName === 'static-property' || el.tsTypeName === 'static-function'
253
+ )
254
+ }
255
+
256
+ private typeIsString(type: TsType) {
257
+ return (
258
+ type.type === 'string' ||
259
+ (type.type.startsWith("'") && type.type.endsWith("'")) ||
260
+ (type.type.startsWith('"') && type.type.endsWith('"'))
261
+ )
262
+ }
263
+
264
+ private mergeTypes(leftSeparator: TsTypeSeparator, ...types: Array<TsType | undefined>) {
265
+ const dest: TsType[] = []
266
+
267
+ for (const type of types) {
268
+ if (!type) continue
269
+ if (!dest.find((destType) => isEqual(destType, type))) {
270
+ dest.push({ ...type, leftSeparator })
271
+ }
272
+ }
273
+
274
+ return dest
275
+ }
276
+
277
+ private setTypesProperty(types: TsType[], property: 'optional', value: boolean) {
278
+ for (const type of types) {
279
+ type[property] = value
280
+ }
281
+ return types
282
+ }
283
+
284
+ /**
285
+ * Merges two parameter name and type of two parameters
286
+ * @param a
287
+ * @param b
288
+ * @returns
289
+ */
290
+ private mergeParam(a: GirCallableParamElement | undefined, b: GirCallableParamElement | undefined) {
291
+ if (!a?._tsData && !b?._tsData) {
292
+ throw new Error('At least one parameter must be defined!')
293
+ }
294
+
295
+ let dest: GirCallableParamElement
296
+
297
+ if (a?._tsData && b?._tsData) {
298
+ dest = merge({}, clone(a), clone(b))
299
+ if (!dest._tsData) {
300
+ throw new Error('Error on merge parameters!')
301
+ }
302
+ dest._tsData.type = []
303
+ dest._tsData.type = this.mergeTypes('|', ...a._tsData.type, ...b._tsData.type)
304
+ if (a._tsData.name !== b._tsData.name) {
305
+ dest._tsData.name = `${a._tsData.name}_or_${b._tsData.name}`
306
+ }
307
+ } else {
308
+ dest = clone((a || b) as GirCallableParamElement)
309
+ if (!dest._tsData) {
310
+ throw new Error('Error on merge parameters!')
311
+ }
312
+ // If `a` or `b` is undefined make the types optional
313
+ dest._tsData.type = this.setTypesProperty(dest._tsData.type, 'optional', true)
314
+ }
315
+
316
+ if (typeIsOptional(dest._tsData.type)) {
317
+ dest._tsData.type = this.setTypesProperty(dest._tsData.type, 'optional', true)
318
+ }
319
+
320
+ return dest
321
+ }
322
+
323
+ /**
324
+ * Merges parameter names and types of multiple functions
325
+ * @param params
326
+ * @returns
327
+ */
328
+ private mergeParams(...params: GirCallableParamElement[][]) {
329
+ let dest: GirCallableParamElement[] = []
330
+
331
+ for (const a of params) {
332
+ for (const b of params) {
333
+ if (a === b) {
334
+ continue
335
+ }
336
+ if (isEqual(a, b)) {
337
+ dest = clone(a)
338
+ } else {
339
+ const length = Math.max(a.length, b.length)
340
+ dest = new Array<GirCallableParamElement>(length)
341
+ for (let i = 0; i < length; i++) {
342
+ const aParam = a[i] as GirCallableParamElement | undefined
343
+ const bParam = b[i] as GirCallableParamElement | undefined
344
+ dest[i] = this.mergeParam(aParam, bParam)
345
+ }
346
+ }
347
+ }
348
+ }
349
+
350
+ return dest
351
+ }
352
+
353
+ private paramCanBeOptional(
354
+ girParam: GirCallableParamElement,
355
+ girParams: GirCallableParamElement[],
356
+ skip: GirCallableParamElement[] = [],
357
+ ) {
358
+ if (!girParam._tsData) return false
359
+ let canBeOptional = true
360
+ const index = girParams.indexOf(girParam)
361
+ const following = girParams
362
+ .slice(index)
363
+ .filter((p) => !!p._tsData)
364
+ .filter(() => !skip.includes(girParam))
365
+ .filter((p) => p.$.direction !== 'out')
366
+ .map((p) => p._tsData)
367
+
368
+ if (following.some((p) => p && !typeIsOptional(p.type))) {
369
+ canBeOptional = false
370
+ }
371
+
372
+ return canBeOptional
373
+ }
374
+
375
+ /**
376
+ * In Typescript no optional parameters are allowed if the following ones are not optional
377
+ * @param girParams
378
+ * @returns
379
+ */
380
+ private fixOptionalParameters(girParams: GirCallableParamElement[]) {
381
+ for (const girParam of girParams) {
382
+ if (!girParam._tsData) throw new Error(NO_TSDATA('fixOptionalParameters'))
383
+ if (typeIsOptional(girParam._tsData.type) && !this.paramCanBeOptional(girParam, girParams)) {
384
+ this.setTypesProperty(girParam._tsData.type, 'optional', false)
385
+ }
386
+ }
387
+ return girParams
388
+ }
389
+
390
+ /**
391
+ * Merge function types and parameters together
392
+ * @param baseFunc The function to change or null if you want to create a new property
393
+ * @param funcs The functions you want to merge
394
+ * @returns
395
+ */
396
+ public mergeFunctions(baseFunc: TsFunction | null, ...funcs: TsFunction[]) {
397
+ const returnTypesMap: TsType[] = []
398
+ for (const func of funcs) {
399
+ returnTypesMap.push(...func.returnTypes)
400
+ }
401
+ const returnTypes = this.mergeTypes('|', ...returnTypesMap)
402
+
403
+ const inParamsMap = funcs.map((func) => func.inParams)
404
+ const inParams: GirCallableParamElement[] = []
405
+ if (this.paramsHasConflict(...inParamsMap)) {
406
+ inParams.push(...this.mergeParams(...inParamsMap))
407
+ }
408
+
409
+ const outParamsMap = funcs.map((func) => func.outParams)
410
+ const outParams: GirCallableParamElement[] = []
411
+ if (this.paramsHasConflict(...outParamsMap)) {
412
+ outParams.push(...this.mergeParams(...outParamsMap))
413
+ }
414
+
415
+ if (!funcs[0]) {
416
+ throw new Error('At least one function must exist!')
417
+ }
418
+
419
+ if (baseFunc) {
420
+ baseFunc.returnTypes = returnTypes
421
+ return baseFunc
422
+ }
423
+
424
+ return this.girFactory.newTsFunction(
425
+ {
426
+ name: funcs[0].name,
427
+ returnTypes: returnTypes,
428
+ isStatic: funcs[0].isStatic || false,
429
+ inParams: inParams.map((inParam) => inParam._tsData).filter((inParam) => !!inParam) as TsParameter[],
430
+ outParams: outParams
431
+ .map((outParam) => outParam._tsData)
432
+ .filter((outParam) => !!outParam) as TsParameter[],
433
+ girTypeName: funcs[0].girTypeName,
434
+ },
435
+ funcs[0].parent,
436
+ )
437
+ }
438
+
439
+ /**
440
+ * Merge property types together
441
+ * @param baseProp The property to change or null if you want to create a new property
442
+ * @param props The properties you want to merge
443
+ * @returns
444
+ */
445
+ public mergeProperties(typeSeparator: TsTypeSeparator, baseProp: TsProperty | null, ...props: TsProperty[]) {
446
+ const typesMap: TsType[] = []
447
+ for (const prop of props) {
448
+ typesMap.push(...prop.type)
449
+ }
450
+
451
+ const types = this.mergeTypes(typeSeparator, ...typesMap)
452
+
453
+ // Merge readonly
454
+ let readonly = false
455
+ for (const prop of props) {
456
+ readonly = readonly || prop.readonly || false
457
+ }
458
+
459
+ if (!props[0] || !props[0].name) {
460
+ throw new Error('At least one property to merge must exist!')
461
+ }
462
+
463
+ if (baseProp) {
464
+ baseProp.type = types
465
+ baseProp.readonly = readonly
466
+ return baseProp
467
+ }
468
+
469
+ const newProp = this.girFactory.newTsProperty({
470
+ readonly: readonly,
471
+ isStatic: props[0].isStatic || false,
472
+ name: props[0].name,
473
+ type: types,
474
+ girTypeName: props[0].girTypeName,
475
+ })
476
+ return newProp
477
+ }
478
+
479
+ /**
480
+ * Check if there is a type conflict between the ts elements a and b
481
+ * @param a
482
+ * @param b
483
+ * @returns
484
+ */
485
+ public hasConflict(a: ConflictChildElement, b: ConflictChildElement) {
486
+ if (a !== b && a.data.name === b.data.name) {
487
+ const name = a.data.name
488
+ // Ignore element with name of:
489
+ if (name === 'constructor' || name === '_init') {
490
+ return false
491
+ }
492
+ if (this.elementHasConflict(a.data, b.data)) {
493
+ return true
494
+ }
495
+ }
496
+
497
+ return false
498
+ }
499
+
500
+ public newAnyTsProperty(name: string, girTypeName: TypeGirProperty) {
501
+ return this.girFactory.newTsProperty({
502
+ name,
503
+ girTypeName,
504
+ type: [{ type: 'any' }],
505
+ })
506
+ }
507
+
508
+ /**
509
+ * Returns a new any function: `name(...args: any[]): any`
510
+ * @param name The name of the function
511
+ */
512
+ public newAnyTsFunction(name: string, girTypeName: TypeGirFunction, isStatic: boolean, parent: TsClass | null) {
513
+ return this.girFactory.newTsFunction(
514
+ {
515
+ name,
516
+ isStatic,
517
+ inParams: [
518
+ {
519
+ name: 'args',
520
+ isRest: true,
521
+ type: [this.girFactory.newTsType({ type: 'any', isArray: true })],
522
+ },
523
+ ],
524
+ returnTypes: [{ type: 'any' }],
525
+ girTypeName,
526
+ },
527
+ parent,
528
+ )
529
+ }
530
+
531
+ public getCompatibleTsProperty(elements: TsProperty[], baseProp: TsProperty) {
532
+ return elements.find((prop) => !this.propertyHasConflict(baseProp, prop))
533
+ }
534
+
535
+ public getCompatibleTsFunction(elements: TsFunction[], baseFunc: TsFunction) {
536
+ return elements.find((func) => !this.functionHasConflict(baseFunc, func))
537
+ }
538
+
539
+ /**
540
+ * Use this instead of `getCompatibleTsProperty` and `getCompatibleTsProperty` if you can, because it's much faster
541
+ * @param elements
542
+ * @param name
543
+ * @returns
544
+ */
545
+ public getTsElementByName(elements: (TsProperty | TsFunction)[], name: string) {
546
+ return elements.find((el) => el.name === name)
547
+ }
548
+
549
+ protected canAddConflictProperty(conflictProperties: TsProperty[], prop: TsProperty) {
550
+ const canAdd =
551
+ prop.name &&
552
+ // Only one property can be defined, no overloads
553
+ !this.getTsElementByName(conflictProperties, prop.name) &&
554
+ // Do not set properties with signal method names
555
+ !SIGNAL_METHOD_NAMES(this.environment).includes(prop.name)
556
+
557
+ return canAdd
558
+ }
559
+
560
+ public groupSignalConflicts(signalsMethods: ConflictChildElement<TsFunction>[], baseClass: TsClass) {
561
+ const groupedConflicts: ConflictGroupedElements = {}
562
+ for (const base of signalsMethods) {
563
+ for (const b of signalsMethods) {
564
+ if (base === b) {
565
+ continue
566
+ }
567
+
568
+ if (base.data.name !== 'connect' && base.data.name !== 'connect_after') {
569
+ continue
570
+ }
571
+
572
+ const sigNameParam = base.data.inParams[0]
573
+ // const callbackParam = base.data.inParams[1]
574
+
575
+ const eventName = sigNameParam?._tsData?.type?.[0]?.type
576
+ // TODO do not render the callback type as a full string, create a TSCallback instead
577
+ // const callbackType = callbackParam?._tsData?.type?.[0]?.type
578
+ // console.debug('eventName', eventName, callbackType)
579
+
580
+ if (!eventName || eventName === 'string') {
581
+ continue
582
+ }
583
+ groupedConflicts[eventName] ||= {
584
+ baseElements: [],
585
+ inheritedElements: [],
586
+ baseClass,
587
+ }
588
+
589
+ const groupedConflict = groupedConflicts[eventName]
590
+ const isBaseElement = base.depth === 0
591
+ if (isBaseElement) {
592
+ if (!groupedConflict.baseElements.find((c) => isEqual(c.data, base.data))) {
593
+ groupedConflict.baseElements.push(base)
594
+ }
595
+ } else {
596
+ if (!groupedConflict.inheritedElements.find((c) => isEqual(c.data, base.data))) {
597
+ groupedConflict.inheritedElements.push(base)
598
+ }
599
+ }
600
+ }
601
+ }
602
+
603
+ return groupedConflicts
604
+ }
605
+
606
+ public fixSignalConflicts(groupedElements: ConflictGroupedElements) {
607
+ for (const eventName of Object.keys(groupedElements)) {
608
+ const elements = groupedElements[eventName]
609
+
610
+ const bases = elements.baseElements
611
+
612
+ if (!bases.length) {
613
+ // TODO
614
+ // return this.fixIndirectSignalConflicts(elements.inheritedElements, elements.baseClass)
615
+ return
616
+ }
617
+
618
+ for (const base of bases) {
619
+ if (base.data.hasUnresolvedConflict) {
620
+ continue
621
+ }
622
+ for (const b of elements.inheritedElements) {
623
+ if (b === base || b.data.hasUnresolvedConflict) {
624
+ continue
625
+ }
626
+ // TODO
627
+ }
628
+ }
629
+ }
630
+ }
631
+
632
+ /**
633
+ * Check conflicts between the implementations / inheritances
634
+ * To fix type errors like:
635
+ * ```
636
+ * Interface 'PopoverMenu' can\'t simultaneously extend types 'Popover' and 'Native'.
637
+ * Named property 'parent' of types 'Popover' and 'Native' are not identical.
638
+ */
639
+ public fixIndirectConflicts(name: string, elements: ConflictChildElement[], baseClass: TsClass) {
640
+ for (const base of elements) {
641
+ if (base.data.hasUnresolvedConflict) {
642
+ continue
643
+ }
644
+ for (const b of elements) {
645
+ if (b === base || b.data.hasUnresolvedConflict) {
646
+ continue
647
+ }
648
+
649
+ const className = `${baseClass.namespace}-${baseClass.version}.${baseClass.name}`
650
+
651
+ // If a element is a function / method
652
+ if (this.tsElementIsMethodOrFunction(base.data)) {
653
+ const baseFunc = base.data as TsFunction
654
+
655
+ // Function vs. Property
656
+ if (this.tsElementIsPropertyOrVariable(b.data)) {
657
+ this.log.debug(`${className}.${name} External Function vs. Property`, baseFunc, b.data)
658
+ b.data.hasUnresolvedConflict = true
659
+ }
660
+
661
+ // Function vs. Signal
662
+ else if (this.tsElementIsSignal(b.data)) {
663
+ this.log.debug(`${className}.${name} External Function vs. Signal`, baseFunc, b.data)
664
+ baseFunc.hasUnresolvedConflict = true
665
+ }
666
+
667
+ // Function vs. Function
668
+ else if (this.tsElementIsMethodOrFunction(b.data)) {
669
+ const bFunc = b.data as TsFunction
670
+ this.log.debug(
671
+ `${className}.${name} External Function vs. Function`,
672
+ baseFunc.inParams.map((p) => p._tsData?.name).join(', '),
673
+ bFunc.inParams.map((p) => p._tsData?.name).join(', '),
674
+ )
675
+
676
+ // Just add conflicting methods to the class
677
+ if (!baseClass.conflictMethods.includes(baseFunc)) {
678
+ baseClass.conflictMethods.push(baseFunc)
679
+ }
680
+ if (!baseClass.conflictMethods.includes(bFunc)) {
681
+ baseClass.conflictMethods.push(bFunc)
682
+ }
683
+ }
684
+
685
+ // Function vs. Constructor
686
+ else if (this.tsElementIsConstructor(base.data)) {
687
+ const bConstr = b.data as TsFunction
688
+ this.log.debug(`${className}.${name} External Function vs. Constructor`, baseFunc, bConstr)
689
+
690
+ // Just add conflicting methods to the class
691
+ if (!baseClass.conflictMethods.includes(baseFunc)) {
692
+ baseClass.conflictMethods.push(baseFunc)
693
+ }
694
+ if (!baseClass.conflictMethods.includes(bConstr)) {
695
+ baseClass.conflictMethods.push(bConstr)
696
+ }
697
+ }
698
+
699
+ // Function vs. Unknown
700
+ else {
701
+ this.log.debug(`${className}.${name} External Unknown ${b.data.tsTypeName}`, baseFunc, b.data)
702
+ baseFunc.hasUnresolvedConflict = true
703
+ }
704
+ }
705
+
706
+ // If a element is a constructor
707
+ else if (this.tsElementIsConstructor(base.data)) {
708
+ const baseConstr = base.data as TsFunction
709
+
710
+ // Constructor vs. Function
711
+ if (this.tsElementIsMethodOrFunction(b.data)) {
712
+ const bFunc = b.data as TsFunction
713
+ this.log.debug(
714
+ `${className}.${name} External Constructor vs. Function`,
715
+ baseConstr.inParams.map((p) => p._tsData?.name).join(', '),
716
+ bFunc.inParams.map((p) => p._tsData?.name).join(', '),
717
+ )
718
+
719
+ if (!baseClass.conflictMethods.includes(baseConstr)) {
720
+ baseClass.conflictMethods.push(baseConstr)
721
+ }
722
+ if (!baseClass.conflictMethods.includes(bFunc)) {
723
+ baseClass.conflictMethods.push(bFunc)
724
+ }
725
+ }
726
+
727
+ // Constructor vs. Constructor
728
+ else if (this.tsElementIsConstructor(base.data)) {
729
+ this.log.debug(`${className}.${name} External Constructor vs. Constructor`, baseConstr, b.data)
730
+
731
+ const anyFunc = this.newAnyTsFunction(
732
+ name,
733
+ baseConstr.girTypeName,
734
+ baseConstr.isStatic,
735
+ baseConstr.parent,
736
+ )
737
+
738
+ // Check if any function is not already added
739
+ if (!this.getTsElementByName(baseClass.conflictMethods, anyFunc.name)) {
740
+ baseClass.conflictMethods.push(anyFunc)
741
+ }
742
+ }
743
+ }
744
+
745
+ // If a element is a property / variable
746
+ else if (this.tsElementIsPropertyOrVariable(base.data)) {
747
+ const baseProp = base.data as TsProperty
748
+
749
+ // Property vs. Function
750
+ if (this.tsElementIsMethodOrFunction(b.data)) {
751
+ const bFunc = b.data as TsFunction
752
+ this.log.debug(
753
+ `${className}.${name} External Property vs. Function`,
754
+ baseProp.type[0].type,
755
+ bFunc,
756
+ )
757
+ baseProp.hasUnresolvedConflict = true
758
+ }
759
+
760
+ // Property vs. Property
761
+ else if (this.tsElementIsPropertyOrVariable(b.data)) {
762
+ const bProp = b.data as TsProperty
763
+ this.log.debug(
764
+ `${className}.${name} External Property vs. Property`,
765
+ baseProp.type[0].type,
766
+ bProp.type[0].type,
767
+ )
768
+
769
+ switch (name) {
770
+ case 'parent':
771
+ case 'window':
772
+ case 'parent_instance':
773
+ case 'priv':
774
+ const mergedProp = this.mergeProperties('&', null, baseProp, bProp)
775
+ if (this.canAddConflictProperty(baseClass.conflictProperties, mergedProp)) {
776
+ baseClass.conflictProperties.push(mergedProp)
777
+ }
778
+ break
779
+
780
+ default:
781
+ const anyProp = this.newAnyTsProperty(name, baseProp.girTypeName)
782
+ if (this.canAddConflictProperty(baseClass.conflictProperties, anyProp)) {
783
+ baseClass.conflictProperties.push(anyProp)
784
+ }
785
+ break
786
+ }
787
+ }
788
+
789
+ // Property vs. Signal
790
+ else if (this.tsElementIsSignal(b.data)) {
791
+ this.log.debug(`${className}.${name} External Property vs. Signal`, baseProp, b.data)
792
+ base.data.hasUnresolvedConflict = true
793
+ } else {
794
+ this.log.error(`${className}.${name} External Unknown ${b.data.tsTypeName}`, baseProp, b.data)
795
+ }
796
+ }
797
+
798
+ // Other
799
+ else {
800
+ this.log.error(`${className}.${name} External Unknown ${base.data.tsTypeName}`)
801
+ base.data.hasUnresolvedConflict = true
802
+ }
803
+ }
804
+ }
805
+ }
806
+
807
+ /**
808
+ * Check conflicts within the class itself (ignores implementations / inheritances)
809
+ */
810
+ public fixInternalConflicts(name: string, elements: ConflictChildElement[], baseClass: TsClass) {
811
+ for (const base of elements) {
812
+ if (base.data.hasUnresolvedConflict) {
813
+ continue
814
+ }
815
+ for (const b of elements) {
816
+ if (b === base || b.data.hasUnresolvedConflict) {
817
+ continue
818
+ }
819
+
820
+ const className = `${baseClass.namespace}-${baseClass.version}.${baseClass.name}`
821
+
822
+ // Conflict between injected and original elements
823
+ if (base.data.isInjected !== b.data.isInjected) {
824
+ if (!base.data.isInjected) {
825
+ base.data.hasUnresolvedConflict = true
826
+ } else if (!b.data.isInjected) {
827
+ b.data.hasUnresolvedConflict = true
828
+ }
829
+ // Copy doc from original element if not set in the injected element
830
+ if (!b.data.doc.text && base.data.doc.text) {
831
+ b.data.doc = base.data.doc
832
+ } else if (!base.data.doc.text && b.data.doc.text) {
833
+ base.data.doc = b.data.doc
834
+ }
835
+ continue
836
+ }
837
+
838
+ // If a element is a function / method
839
+ if (this.tsElementIsMethodOrFunction(base.data)) {
840
+ const baseFunc = base.data as TsFunction
841
+
842
+ // Function vs. Property
843
+ if (this.tsElementIsPropertyOrVariable(b.data)) {
844
+ this.log.debug(`${className}.${name} Internal Function vs. Property`, baseFunc, b.data)
845
+ b.data.hasUnresolvedConflict = true
846
+ }
847
+
848
+ // Function vs. Signal
849
+ else if (this.tsElementIsSignal(b.data)) {
850
+ this.log.debug(`${className}.${name} Internal Function vs. Signal`, baseFunc, b.data)
851
+ // Do nothing
852
+ }
853
+
854
+ // Function vs. Function
855
+ else if (this.tsElementIsMethodOrFunction(b.data)) {
856
+ const bFunc = b.data as TsFunction
857
+ this.log.debug(
858
+ `${className}.${name} Internal Function vs. Function`,
859
+ baseFunc.inParams.map((p) => p._tsData?.name).join(', '),
860
+ bFunc.inParams.map((p) => p._tsData?.name).join(', '),
861
+ )
862
+
863
+ // Conflict between virtual and non-virtual methods (this should only occur in node-gtk, because Gjs has a vfunc_ prefix for virtual methods)
864
+ if (baseFunc.isVirtual !== bFunc.isVirtual) {
865
+ if (!baseFunc.isVirtual) {
866
+ baseFunc.hasUnresolvedConflict = true
867
+ } else {
868
+ bFunc.hasUnresolvedConflict = true
869
+ }
870
+ continue
871
+ }
872
+
873
+ // Do nothing..
874
+ } else {
875
+ this.log.error(`${className}.${name} Internal Unknown ${b.data.tsTypeName}`, baseFunc, b.data)
876
+ b.data.hasUnresolvedConflict = true
877
+ }
878
+ }
879
+
880
+ // If a element is a property / variable
881
+ else if (this.tsElementIsPropertyOrVariable(base.data)) {
882
+ const baseProp = base.data as TsProperty
883
+
884
+ // Property vs. Function
885
+ if (this.tsElementIsMethodOrFunction(b.data)) {
886
+ const bFunc = b.data as TsFunction
887
+ this.log.debug(
888
+ `${className}.${name} Internal Property vs. Function`,
889
+ baseProp.type[0].type,
890
+ bFunc,
891
+ )
892
+ baseProp.hasUnresolvedConflict = true
893
+ }
894
+
895
+ // Property vs. Property
896
+ else if (this.tsElementIsPropertyOrVariable(b.data)) {
897
+ const bProp = b.data as TsProperty
898
+ this.log.debug(
899
+ `${className}.${name} Internal Property vs. Property`,
900
+ baseProp.type[0].type,
901
+ bProp.type[0].type,
902
+ )
903
+
904
+ switch (name) {
905
+ case 'parent':
906
+ case 'window':
907
+ case 'parent_instance':
908
+ this.mergeProperties('&', baseProp, baseProp, bProp)
909
+ break
910
+
911
+ default:
912
+ // Set property type to any
913
+ baseProp.type = [this.girFactory.newTsType({ ...bProp.type, type: 'any' })]
914
+ break
915
+ }
916
+ }
917
+
918
+ // Property vs. Signal
919
+ else if (this.tsElementIsSignal(b.data)) {
920
+ this.log.debug(`${className}.${name} Internal Property vs. Signal`, baseProp, b.data)
921
+ base.data.hasUnresolvedConflict = true
922
+ } else {
923
+ this.log.error(`${className}.${name} Internal Unknown ${b.data.tsTypeName}`, baseProp, b.data)
924
+ }
925
+ }
926
+
927
+ // If a element is a signal
928
+ else if (this.tsElementIsSignal(base.data)) {
929
+ const baseSig = base.data as TsSignal
930
+ // Signal vs. Function
931
+ if (this.tsElementIsMethodOrFunction(b.data)) {
932
+ this.log.debug(`${className}.${name} Internal Signal vs. Function`, baseSig, b.data)
933
+ // Do nothing
934
+ }
935
+ // Signal vs. Property
936
+ else if (this.tsElementIsPropertyOrVariable(b.data)) {
937
+ this.log.debug(`${className}.${name} Internal Signal vs. Property`, baseSig, b.data)
938
+ b.data.hasUnresolvedConflict = true
939
+ }
940
+ }
941
+
942
+ // Other
943
+ else {
944
+ this.log.error(`${className}.${name} Internal Unknown ${base.data.tsTypeName}`)
945
+ }
946
+ }
947
+ }
948
+ }
949
+
950
+ /**
951
+ * Check conflicts of the class with implementations and inheritances
952
+ */
953
+ public fixDirectConflicts(name: string, elements: ConflictGroupedElement) {
954
+ const className = `${elements.baseClass.namespace}-${elements.baseClass.version}.${elements.baseClass.name}`
955
+
956
+ for (const base of elements.baseElements) {
957
+ if (base.data.hasUnresolvedConflict) {
958
+ continue
959
+ }
960
+
961
+ // Each conflicting elements
962
+ for (const b of elements.inheritedElements) {
963
+ if (b === base || b.data.hasUnresolvedConflict) {
964
+ continue
965
+ }
966
+
967
+ // If base element is a function
968
+ if (this.tsElementIsMethodOrFunction(base.data)) {
969
+ const baseFunc = base.data as TsFunction
970
+
971
+ // Function vs. Function
972
+ if (this.tsElementIsMethodOrFunction(b.data)) {
973
+ const bFunc = b.data as TsFunction
974
+ this.log.debug(
975
+ `${className}.${name} Direct Function vs. Function`,
976
+ baseFunc.inParams.map((p) => p._tsData?.name).join(', '),
977
+ bFunc.inParams.map((p) => p._tsData?.name).join(', '),
978
+ )
979
+
980
+ // Add a function to overload methods if there is not already a compatible version
981
+ if (!this.getCompatibleTsFunction(baseFunc.overloads, bFunc)) {
982
+ baseFunc.overloads.push(bFunc)
983
+ }
984
+ }
985
+
986
+ // Function vs. Constructor
987
+ else if (this.tsElementIsConstructor(b.data)) {
988
+ const bConstr = b.data as TsFunction
989
+ this.log.debug(
990
+ `${className}.${name} Direct Function vs. Constructor`,
991
+ baseFunc.inParams.map((p) => p._tsData?.name).join(', '),
992
+ bConstr.inParams.map((p) => p._tsData?.name).join(', '),
993
+ )
994
+
995
+ // Add a function to overload methods if there is not already a compatible version
996
+ if (!this.getCompatibleTsFunction(baseFunc.overloads, bConstr)) {
997
+ baseFunc.overloads.push(bConstr)
998
+ }
999
+ }
1000
+
1001
+ // Function vs. Property
1002
+ else if (this.tsElementIsPropertyOrVariable(b.data)) {
1003
+ this.log.debug(`${className}.${name} Direct Function vs. Property`)
1004
+ b.data.hasUnresolvedConflict = true
1005
+ }
1006
+
1007
+ // Function vs. Signal
1008
+ else if (this.tsElementIsSignal(b.data)) {
1009
+ this.log.debug(`${className}.${name} Direct Function vs. Signal`)
1010
+ baseFunc.hasUnresolvedConflict = true
1011
+ }
1012
+ }
1013
+
1014
+ // If base element is a property / variable
1015
+ else if (this.tsElementIsPropertyOrVariable(base.data)) {
1016
+ const baseProp = base.data as TsProperty
1017
+
1018
+ // Property vs. Property
1019
+ if (this.tsElementIsPropertyOrVariable(b.data)) {
1020
+ const bProp = b.data as TsProperty
1021
+ this.log.debug(
1022
+ `${className}.${name} Direct Property vs. Property`,
1023
+ baseProp.type[0].type,
1024
+ bProp.type[0].type,
1025
+ )
1026
+ switch (name) {
1027
+ case 'parent':
1028
+ case 'window':
1029
+ case 'parent_instance':
1030
+ this.mergeProperties('&', baseProp, baseProp, bProp)
1031
+ break
1032
+
1033
+ default:
1034
+ // Set property type to any
1035
+ baseProp.type = [this.girFactory.newTsType({ ...bProp.type, type: 'any' })]
1036
+ break
1037
+ }
1038
+ }
1039
+
1040
+ // Property vs. Function
1041
+ else if (this.tsElementIsMethodOrFunction(b.data)) {
1042
+ this.log.debug(`${className}.${name} Direct Property vs. Function`)
1043
+ baseProp.hasUnresolvedConflict = true
1044
+ }
1045
+
1046
+ // Property vs. Signal
1047
+ else if (this.tsElementIsSignal(b.data)) {
1048
+ this.log.debug(`${className}.${name} Direct Property vs. Signal`)
1049
+ baseProp.hasUnresolvedConflict = true
1050
+ }
1051
+ }
1052
+
1053
+ // If base element is a signal method
1054
+ else if (this.tsElementIsSignal(base.data)) {
1055
+ // Signal vs. Property
1056
+ if (this.tsElementIsPropertyOrVariable(b.data)) {
1057
+ this.log.debug(`${className}.${name} Direct Signal vs. Property`)
1058
+ b.data.hasUnresolvedConflict = true
1059
+ }
1060
+
1061
+ // Signal vs. Function
1062
+ if (this.tsElementIsMethodOrFunction(b.data)) {
1063
+ this.log.debug(`${className}.${name} Direct Signal vs. Function`)
1064
+ b.data.hasUnresolvedConflict = true
1065
+ }
1066
+ }
1067
+ // If a element is a constructor
1068
+ else if (this.tsElementIsConstructor(base.data)) {
1069
+ const baseConstr = base.data as TsFunction
1070
+
1071
+ // Constructor vs. Function
1072
+ if (this.tsElementIsMethodOrFunction(b.data)) {
1073
+ const bFunc = b.data as TsFunction
1074
+ this.log.debug(
1075
+ `${className}.${name} Direct Constructor vs. Function`,
1076
+ baseConstr.inParams.map((p) => p._tsData?.name).join(', '),
1077
+ bFunc.inParams.map((p) => p._tsData?.name).join(', '),
1078
+ )
1079
+
1080
+ // Add a function to overload methods if there is not already a compatible version
1081
+ if (!this.getCompatibleTsFunction(baseConstr.overloads, bFunc)) {
1082
+ baseConstr.overloads.push(bFunc)
1083
+ }
1084
+ }
1085
+
1086
+ // Constructor vs. Constructor
1087
+ else if (this.tsElementIsConstructor(base.data)) {
1088
+ const bConstr = b.data as TsFunction
1089
+ this.log.debug(`${className}.${name} Direct Constructor vs. Constructor`, baseConstr, bConstr)
1090
+
1091
+ // Add the constructor to overload methods if there is not already a compatible version
1092
+ if (!this.getCompatibleTsFunction(baseConstr.overloads, bConstr)) {
1093
+ baseConstr.overloads.push(bConstr)
1094
+ }
1095
+ }
1096
+ } else {
1097
+ this.log.warn(`{className}.${name} Unknown ${base.data.tsTypeName}`, base)
1098
+ base.data.hasUnresolvedConflict = true
1099
+ }
1100
+ }
1101
+ }
1102
+ }
1103
+
1104
+ /**
1105
+ * Fix the conflicts of a class
1106
+ * @param groupedElements
1107
+ */
1108
+ public fixConflicts(groupedElements: ConflictGroupedElements) {
1109
+ for (const key of Object.keys(groupedElements)) {
1110
+ const elements = groupedElements[key]
1111
+ // Remove the key prefix `_`
1112
+ const name = key.substring(1)
1113
+
1114
+ if (elements.baseElements.length === 0) {
1115
+ this.fixIndirectConflicts(name, elements.inheritedElements, elements.baseClass)
1116
+ }
1117
+ this.fixInternalConflicts(name, elements.baseElements, elements.baseClass)
1118
+
1119
+ this.fixDirectConflicts(name, elements)
1120
+ }
1121
+ }
1122
+
1123
+ /**
1124
+ * Group conflicts by name and sort them by depth for simpler handling of conflicts
1125
+ */
1126
+ public groupConflicts(elements: ConflictChildElement[], tsClass: TsClass) {
1127
+ const groupedConflicts: ConflictGroupedElements = {}
1128
+
1129
+ const IGNORE_CONFLICT_NAMES = ['$gtype', '__gtype__']
1130
+
1131
+ for (const a of elements) {
1132
+ const name = a.data.name
1133
+ for (const b of elements) {
1134
+ if (
1135
+ a === b ||
1136
+ !name ||
1137
+ !b.data.name ||
1138
+ IGNORE_CONFLICT_NAMES.includes(name) ||
1139
+ IGNORE_CONFLICT_NAMES.includes(b.data.name)
1140
+ ) {
1141
+ continue
1142
+ }
1143
+ if (a && name && b && b.data.name && a !== b && this.hasConflict(a, b)) {
1144
+ const key = `_${name}` // if the key would be `toString` this would be always true so we prefix `_`
1145
+ groupedConflicts[key] ||= {
1146
+ baseElements: [],
1147
+ inheritedElements: [],
1148
+ baseClass: tsClass,
1149
+ }
1150
+ const groupedConflict = groupedConflicts[key]
1151
+ const isBaseElement = a.depth === 0
1152
+ if (isBaseElement) {
1153
+ if (!groupedConflict.baseElements.find((c) => isEqual(c.data, a.data))) {
1154
+ groupedConflict.baseElements.push(a)
1155
+ }
1156
+ } else {
1157
+ if (
1158
+ !groupedConflict.baseElements.find((c) => isEqual(c.data, a.data)) &&
1159
+ !groupedConflict.inheritedElements.find((c) => isEqual(c.data, a.data))
1160
+ ) {
1161
+ groupedConflict.inheritedElements.push(a)
1162
+ }
1163
+ }
1164
+ }
1165
+ }
1166
+ }
1167
+
1168
+ // Sort by depth
1169
+ for (const key of Object.keys(groupedConflicts)) {
1170
+ groupedConflicts[key].inheritedElements = groupedConflicts[key].inheritedElements.sort(
1171
+ (a, b) => a.depth - b.depth,
1172
+ )
1173
+ }
1174
+
1175
+ return groupedConflicts
1176
+ }
1177
+
1178
+ /**
1179
+ * With multiple implementations or a inherit it can happen that the interfaces / parent have the same method and/or property name with incompatible types.
1180
+ * We merge these types here to solve this problem.
1181
+ * @param girClass
1182
+ */
1183
+ public repairClass(girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement) {
1184
+ if (!girClass._tsData) throw new Error(NO_TSDATA('repairClass'))
1185
+
1186
+ const classElements = this.getClassElements(girClass._tsData, 0, [])
1187
+
1188
+ // Do not pass a reference of the array here
1189
+ const elements = [
1190
+ ...classElements.signalMethods,
1191
+ ...classElements.propertySignalMethods,
1192
+ ...classElements.methods,
1193
+ ...classElements.virtualMethods,
1194
+ ...classElements.staticFunctions,
1195
+ ...classElements.constructors,
1196
+ ...classElements.properties,
1197
+ ...classElements.fields,
1198
+ ]
1199
+
1200
+ const groupedElementConflicts = this.groupConflicts(elements, girClass._tsData)
1201
+ const groupedConstructPropConflicts = this.groupConflicts(classElements.constructProps, girClass._tsData)
1202
+
1203
+ this.fixConflicts(groupedElementConflicts)
1204
+ this.fixConflicts(groupedConstructPropConflicts)
1205
+
1206
+ return girClass
1207
+ }
1208
+
1209
+ /**
1210
+ * Returns true if `p1s` and `p2s` conflicting with each other.
1211
+ * The parameters must have the same length and the same type but can have different names
1212
+ * @param params
1213
+ * @returns
1214
+ */
1215
+ public paramsHasConflict(...params: GirCallableParamElement[][]) {
1216
+ let conflict = false
1217
+ for (const p1s of params) {
1218
+ for (const p2s of params) {
1219
+ if (p1s.length !== p2s.length) {
1220
+ conflict = true
1221
+ return conflict
1222
+ }
1223
+
1224
+ for (const [i, p1] of p1s.entries()) {
1225
+ const p2 = p2s[i]
1226
+ if (p2._tsData && p1._tsData) {
1227
+ if (this.typesHasConflict(p2._tsData?.type, p1._tsData?.type)) {
1228
+ conflict = true
1229
+ return conflict
1230
+ }
1231
+ } else {
1232
+ conflict = true
1233
+ return conflict
1234
+ }
1235
+ }
1236
+ }
1237
+ }
1238
+
1239
+ return conflict
1240
+ }
1241
+
1242
+ public typesHasConflict(a: TsType[], b: TsType[]) {
1243
+ if (a.length !== b.length) {
1244
+ return true
1245
+ }
1246
+ // return !isEqual(a, b.data)
1247
+ for (let i = 0; i < a.length; i++) {
1248
+ const aType = a[i]
1249
+ const bType = b[i]
1250
+ if (
1251
+ aType.type !== bType.type ||
1252
+ aType.nullable !== bType.nullable ||
1253
+ aType.optional !== bType.optional ||
1254
+ aType.isFunction !== bType.isFunction ||
1255
+ aType.isCallback !== bType.isCallback ||
1256
+ aType.isArray !== bType.isArray ||
1257
+ aType.callbacks.length !== bType.callbacks.length ||
1258
+ aType.generics.length !== bType.generics.length ||
1259
+ !isEqual(aType.callbacks, bType.callbacks) ||
1260
+ !isEqual(aType.generics, bType.generics) ||
1261
+ !isEqual(aType, bType) // TODO
1262
+ ) {
1263
+ return true
1264
+ }
1265
+ }
1266
+
1267
+ return false
1268
+ }
1269
+
1270
+ /**
1271
+ * Returns `true` if the function / method types of `a` and `b` are not compatible with each other.
1272
+ * The parameters must have the same length and the same type but can have different names
1273
+ * @param a
1274
+ * @param b
1275
+ * @returns
1276
+ */
1277
+ public functionHasConflict(a: TsFunction, b: TsFunction) {
1278
+ // TODO find a better solution for that, not all this methods are conflicting
1279
+ if (a.isVirtual !== b.isVirtual) {
1280
+ return true
1281
+ }
1282
+
1283
+ if (this.typesHasConflict(a.returnTypes, b.returnTypes)) {
1284
+ return true
1285
+ }
1286
+
1287
+ if (this.paramsHasConflict(a.inParams, b.inParams)) {
1288
+ return true
1289
+ }
1290
+
1291
+ if (this.paramsHasConflict(a.outParams, b.outParams)) {
1292
+ return true
1293
+ }
1294
+
1295
+ return false
1296
+ }
1297
+
1298
+ /**
1299
+ * Returns `true` if the property types of `a` and `b` are not compatible with each other.
1300
+ * @param a
1301
+ * @param b
1302
+ * @returns
1303
+ */
1304
+ public propertyHasConflict(a: TsVar & TsProperty, b: TsVar & TsProperty) {
1305
+ if (!!a.isStatic !== !!b.isStatic) return false
1306
+ if (a.name !== b.name) return false
1307
+
1308
+ if (!!a.readonly !== !!b.readonly || this.typesHasConflict(a.type, b.type)) return true
1309
+
1310
+ return false
1311
+ }
1312
+
1313
+ public signalHasConflict(a: TsSignal, b: TsSignal) {
1314
+ if (!!a.isStatic !== !!b.isStatic) return false
1315
+ if (a.name !== b.name) return false
1316
+
1317
+ // TODO
1318
+ return false
1319
+ }
1320
+
1321
+ /**
1322
+ * Returns true if the elements (properties or methods) of `a` and `b` are not compatible with each other (has no conflict).
1323
+ * @param a
1324
+ * @param b
1325
+ * @returns
1326
+ */
1327
+ public elementHasConflict(
1328
+ a: TsFunction | TsVar | TsProperty | TsSignal,
1329
+ b: TsFunction | TsVar | TsProperty | TsSignal,
1330
+ ) {
1331
+ if (a.name !== b.name) {
1332
+ return false
1333
+ } else if (this.tsElementIsStatic(a) !== this.tsElementIsStatic(b)) {
1334
+ return false
1335
+ } else if (this.tsElementIsMethodOrFunction(a) && this.tsElementIsMethodOrFunction(b)) {
1336
+ return this.functionHasConflict(a as TsFunction, b as TsFunction)
1337
+ } else if (this.tsElementIsPropertyOrVariable(a) && this.tsElementIsPropertyOrVariable(b)) {
1338
+ return this.propertyHasConflict(a as TsVar & TsProperty, b as TsVar & TsProperty)
1339
+ } else if (this.tsElementIsConstructor(a) && this.tsElementIsConstructor(b)) {
1340
+ return this.functionHasConflict(a as TsFunction, b as TsFunction)
1341
+ } else if (this.tsElementIsSignal(a) && this.tsElementIsSignal(b)) {
1342
+ // TODO
1343
+ return this.signalHasConflict(a as TsSignal, b as TsSignal)
1344
+ } else if (a.tsTypeName !== b.tsTypeName) {
1345
+ return true
1346
+ } else {
1347
+ return true
1348
+ }
1349
+ }
1350
+ }