@ts-for-gir/lib 3.0.0-beta.11

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