@ts-for-gir/lib 4.0.0-beta.25 → 4.0.0-beta.26

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 (567) hide show
  1. package/package.json +12 -26
  2. package/src/constants.ts +154 -0
  3. package/src/dependency-manager.ts +427 -0
  4. package/src/formatters/default.ts +7 -0
  5. package/src/formatters/formatter.ts +3 -0
  6. package/src/formatters/index.ts +3 -0
  7. package/src/formatters/json.ts +7 -0
  8. package/src/generators/generator.ts +65 -0
  9. package/src/generators/index.ts +2 -0
  10. package/src/generics/clutter.ts +71 -0
  11. package/src/generics/generify.ts +74 -0
  12. package/src/generics/gio.ts +91 -0
  13. package/src/generics/glib.ts +31 -0
  14. package/src/generics/gtk.ts +99 -0
  15. package/src/generics/meta.ts +41 -0
  16. package/src/generics/st.ts +197 -0
  17. package/src/generics/visitor.ts +484 -0
  18. package/src/gir/alias.ts +73 -0
  19. package/src/gir/callback.ts +79 -0
  20. package/src/gir/const.ts +73 -0
  21. package/src/gir/constructor.ts +91 -0
  22. package/src/gir/data.ts +12 -0
  23. package/src/gir/dependency-resolver.ts +81 -0
  24. package/src/gir/direct-allocation-constructor.ts +65 -0
  25. package/src/gir/enum-member.ts +51 -0
  26. package/src/gir/enum.ts +126 -0
  27. package/src/gir/error.ts +82 -0
  28. package/src/gir/function.ts +296 -0
  29. package/src/gir/generics.ts +66 -0
  30. package/src/gir/gir-complex-record.ts +7 -0
  31. package/src/gir/index.ts +25 -0
  32. package/src/gir/introspected-base.ts +104 -0
  33. package/src/gir/introspected-class-member.ts +15 -0
  34. package/src/gir/introspected-classes.ts +1517 -0
  35. package/src/gir/introspected-namespace-member.ts +24 -0
  36. package/src/gir/namespace.ts +76 -0
  37. package/src/gir/parameter.ts +199 -0
  38. package/src/gir/promisify.ts +209 -0
  39. package/src/gir/property.ts +203 -0
  40. package/src/gir/record.ts +477 -0
  41. package/src/gir/registry.ts +184 -0
  42. package/src/gir/signal.ts +246 -0
  43. package/src/gir-module.ts +703 -0
  44. package/src/gir.ts +892 -0
  45. package/src/index.ts +16 -0
  46. package/src/injections/gee08.ts +89 -0
  47. package/src/injections/gee1.ts +35 -0
  48. package/src/injections/gio.ts +707 -0
  49. package/src/injections/glib.ts +275 -0
  50. package/src/injections/gobject.ts +901 -0
  51. package/src/injections/gtk4.ts +23 -0
  52. package/src/injections/inject.ts +43 -0
  53. package/src/injections/shell.ts +45 -0
  54. package/src/injections/tracker1.ts +42 -0
  55. package/src/library-version.ts +50 -0
  56. package/src/logger.ts +104 -0
  57. package/src/messages.ts +57 -0
  58. package/src/templates/index.ts +1 -0
  59. package/src/templates/template-engine.ts +178 -0
  60. package/src/types/answer-version.ts +4 -0
  61. package/src/types/any-introspected-type.ts +3 -0
  62. package/src/types/class-function-types.ts +49 -0
  63. package/src/types/class-member.ts +5 -0
  64. package/src/types/class-parent.ts +14 -0
  65. package/src/types/class.ts +45 -0
  66. package/src/types/config-flags.ts +5 -0
  67. package/src/types/construct-name.ts +13 -0
  68. package/src/types/dependency-map.ts +4 -0
  69. package/{lib/types/dependency.d.ts → src/types/dependency.ts} +17 -15
  70. package/{lib/types/file-info.d.ts → src/types/file-info.ts} +3 -3
  71. package/src/types/format.ts +1 -0
  72. package/src/types/generator-constructor.ts +7 -0
  73. package/src/types/generics-config.ts +90 -0
  74. package/src/types/gir-any-element.ts +35 -0
  75. package/src/types/gir-module-interface.ts +22 -0
  76. package/src/types/gir-module-resolved.ts +32 -0
  77. package/src/types/gir-type-name.ts +20 -0
  78. package/src/types/index.ts +94 -0
  79. package/{lib/types/inheritance-table.d.ts → src/types/inheritance-table.ts} +1 -1
  80. package/src/types/introspected.ts +18 -0
  81. package/src/types/local-name-check.ts +5 -0
  82. package/src/types/local-name-type.ts +1 -0
  83. package/src/types/local-name.ts +8 -0
  84. package/src/types/local-names.ts +5 -0
  85. package/src/types/metadata.ts +6 -0
  86. package/src/types/ns-loader.ts +7 -0
  87. package/src/types/options-base.ts +8 -0
  88. package/{lib/types/options-generation.d.ts → src/types/options-generation.ts} +22 -13
  89. package/src/types/options-load.ts +6 -0
  90. package/src/types/options-transform.ts +5 -0
  91. package/src/types/output-format.ts +1 -0
  92. package/{lib/types/package-data-parsed.d.ts → src/types/package-data-parsed.ts} +13 -13
  93. package/{lib/types/package-data.d.ts → src/types/package-data.ts} +12 -11
  94. package/src/types/package-section-parsed.ts +9 -0
  95. package/src/types/parsed-gir.ts +5 -0
  96. package/src/types/parsed-package-data.ts +7 -0
  97. package/src/types/property-case.ts +1 -0
  98. package/src/types/resolve-type.ts +4 -0
  99. package/src/types/template-data.ts +8 -0
  100. package/src/types/template-options.ts +33 -0
  101. package/src/types/transformation-case.ts +9 -0
  102. package/src/types/transformations.ts +5 -0
  103. package/{lib/types/ts-doc-tag.d.ts → src/types/ts-doc-tag.ts} +5 -3
  104. package/{lib/types/ts-doc.d.ts → src/types/ts-doc.ts} +5 -3
  105. package/{lib/types/type-gir-alias.d.ts → src/types/type-gir-alias.ts} +1 -1
  106. package/{lib/types/type-gir-class.d.ts → src/types/type-gir-class.ts} +1 -1
  107. package/src/types/type-gir-element.ts +25 -0
  108. package/{lib/types/type-gir-enumeration-member.d.ts → src/types/type-gir-enumeration-member.ts} +1 -1
  109. package/{lib/types/type-ts-enumeration-member.d.ts → src/types/type-gir-enumeration.ts} +1 -1
  110. package/src/types/type-gir-function.ts +8 -0
  111. package/{lib/types/type-gir-interface.d.ts → src/types/type-gir-interface.ts} +1 -1
  112. package/{lib/types/type-gir-method.d.ts → src/types/type-gir-method.ts} +1 -1
  113. package/src/types/type-gir-parameter.ts +1 -0
  114. package/{lib/types/type-gir-property.d.ts → src/types/type-gir-property.ts} +1 -1
  115. package/src/types/type-gir-variable.ts +1 -0
  116. package/src/types/type-ts-element.ts +13 -0
  117. package/{lib/types/type-gir-enumeration.d.ts → src/types/type-ts-enumeration-member.ts} +1 -1
  118. package/{lib/types/type-ts-function.d.ts → src/types/type-ts-function.ts} +1 -1
  119. package/{lib/types/type-ts-property.d.ts → src/types/type-ts-property.ts} +1 -1
  120. package/src/types/user-config-load-result.ts +6 -0
  121. package/{lib/types/user-config.d.ts → src/types/user-config.ts} +25 -17
  122. package/src/util.ts +84 -0
  123. package/src/utils/conflicts/conflict-resolver.ts +122 -0
  124. package/src/utils/conflicts/function-conflict-detector.ts +139 -0
  125. package/src/utils/conflicts/index.ts +2 -0
  126. package/src/utils/conflicts.ts +490 -0
  127. package/{lib/utils/documentation.js → src/utils/documentation.ts} +25 -22
  128. package/src/utils/files.ts +71 -0
  129. package/src/utils/function-type-guards.ts +61 -0
  130. package/src/utils/generation.ts +69 -0
  131. package/src/utils/gir-parsing.ts +243 -0
  132. package/src/utils/girs.ts +113 -0
  133. package/src/utils/index.ts +14 -0
  134. package/src/utils/naming.ts +188 -0
  135. package/{lib/utils/numbers.d.ts → src/utils/numbers.ts} +3 -1
  136. package/{lib/utils/objects.js → src/utils/objects.ts} +15 -7
  137. package/src/utils/path.ts +7 -0
  138. package/src/utils/registry.ts +5 -0
  139. package/src/utils/strings.ts +134 -0
  140. package/src/utils/type-resolution.ts +116 -0
  141. package/src/utils/types.ts +247 -0
  142. package/src/validators/class.ts +324 -0
  143. package/src/validators/function-parameters.ts +52 -0
  144. package/src/validators/interface.ts +20 -0
  145. package/src/visitor.ts +58 -0
  146. package/lib/constants.d.ts +0 -25
  147. package/lib/constants.js +0 -93
  148. package/lib/constants.js.map +0 -1
  149. package/lib/dependency-manager.d.ts +0 -151
  150. package/lib/dependency-manager.js +0 -340
  151. package/lib/dependency-manager.js.map +0 -1
  152. package/lib/formatters/default.d.ts +0 -4
  153. package/lib/formatters/default.js +0 -7
  154. package/lib/formatters/default.js.map +0 -1
  155. package/lib/formatters/formatter.d.ts +0 -3
  156. package/lib/formatters/formatter.js +0 -3
  157. package/lib/formatters/formatter.js.map +0 -1
  158. package/lib/formatters/json.d.ts +0 -4
  159. package/lib/formatters/json.js +0 -7
  160. package/lib/formatters/json.js.map +0 -1
  161. package/lib/generators/dts/glib.d.ts +0 -2
  162. package/lib/generators/dts/glib.js +0 -514
  163. package/lib/generators/dts/glib.js.map +0 -1
  164. package/lib/generators/dts/gobject.d.ts +0 -2
  165. package/lib/generators/dts/gobject.js +0 -117
  166. package/lib/generators/dts/gobject.js.map +0 -1
  167. package/lib/generators/dts-inline.d.ts +0 -10
  168. package/lib/generators/dts-inline.js +0 -57
  169. package/lib/generators/dts-inline.js.map +0 -1
  170. package/lib/generators/dts-modules.d.ts +0 -10
  171. package/lib/generators/dts-modules.js +0 -98
  172. package/lib/generators/dts-modules.js.map +0 -1
  173. package/lib/generators/dts.d.ts +0 -45
  174. package/lib/generators/dts.js +0 -683
  175. package/lib/generators/dts.js.map +0 -1
  176. package/lib/generators/generator.d.ts +0 -45
  177. package/lib/generators/generator.js +0 -9
  178. package/lib/generators/generator.js.map +0 -1
  179. package/lib/generators/index.d.ts +0 -5
  180. package/lib/generators/index.js +0 -6
  181. package/lib/generators/index.js.map +0 -1
  182. package/lib/generators/json.d.ts +0 -257
  183. package/lib/generators/json.js +0 -866
  184. package/lib/generators/json.js.map +0 -1
  185. package/lib/generics/clutter.d.ts +0 -41
  186. package/lib/generics/clutter.js +0 -52
  187. package/lib/generics/clutter.js.map +0 -1
  188. package/lib/generics/generify.d.ts +0 -2
  189. package/lib/generics/generify.js +0 -47
  190. package/lib/generics/generify.js.map +0 -1
  191. package/lib/generics/gio.d.ts +0 -7
  192. package/lib/generics/gio.js +0 -51
  193. package/lib/generics/gio.js.map +0 -1
  194. package/lib/generics/glib.d.ts +0 -7
  195. package/lib/generics/glib.js +0 -18
  196. package/lib/generics/glib.js.map +0 -1
  197. package/lib/generics/gtk.d.ts +0 -7
  198. package/lib/generics/gtk.js +0 -56
  199. package/lib/generics/gtk.js.map +0 -1
  200. package/lib/generics/meta.d.ts +0 -36
  201. package/lib/generics/meta.js +0 -29
  202. package/lib/generics/meta.js.map +0 -1
  203. package/lib/generics/st.d.ts +0 -31
  204. package/lib/generics/st.js +0 -98
  205. package/lib/generics/st.js.map +0 -1
  206. package/lib/generics/visitor.d.ts +0 -20
  207. package/lib/generics/visitor.js +0 -255
  208. package/lib/generics/visitor.js.map +0 -1
  209. package/lib/gir/alias.d.ts +0 -24
  210. package/lib/gir/alias.js +0 -43
  211. package/lib/gir/alias.js.map +0 -1
  212. package/lib/gir/base.d.ts +0 -62
  213. package/lib/gir/base.js +0 -83
  214. package/lib/gir/base.js.map +0 -1
  215. package/lib/gir/class.d.ts +0 -228
  216. package/lib/gir/class.js +0 -1151
  217. package/lib/gir/class.js.map +0 -1
  218. package/lib/gir/const.d.ts +0 -25
  219. package/lib/gir/const.js +0 -43
  220. package/lib/gir/const.js.map +0 -1
  221. package/lib/gir/enum.d.ts +0 -45
  222. package/lib/gir/enum.js +0 -164
  223. package/lib/gir/enum.js.map +0 -1
  224. package/lib/gir/function.d.ts +0 -200
  225. package/lib/gir/function.js +0 -683
  226. package/lib/gir/function.js.map +0 -1
  227. package/lib/gir/generics.d.ts +0 -5
  228. package/lib/gir/generics.js +0 -57
  229. package/lib/gir/generics.js.map +0 -1
  230. package/lib/gir/index.d.ts +0 -14
  231. package/lib/gir/index.js +0 -15
  232. package/lib/gir/index.js.map +0 -1
  233. package/lib/gir/namespace.d.ts +0 -21
  234. package/lib/gir/namespace.js +0 -57
  235. package/lib/gir/namespace.js.map +0 -1
  236. package/lib/gir/nodes.d.ts +0 -11
  237. package/lib/gir/nodes.js +0 -12
  238. package/lib/gir/nodes.js.map +0 -1
  239. package/lib/gir/promisify.d.ts +0 -5
  240. package/lib/gir/promisify.js +0 -158
  241. package/lib/gir/promisify.js.map +0 -1
  242. package/lib/gir/property.d.ts +0 -60
  243. package/lib/gir/property.js +0 -128
  244. package/lib/gir/property.js.map +0 -1
  245. package/lib/gir/registry.d.ts +0 -51
  246. package/lib/gir/registry.js +0 -147
  247. package/lib/gir/registry.js.map +0 -1
  248. package/lib/gir/signal.d.ts +0 -36
  249. package/lib/gir/signal.js +0 -169
  250. package/lib/gir/signal.js.map +0 -1
  251. package/lib/gir/util.d.ts +0 -49
  252. package/lib/gir/util.js +0 -561
  253. package/lib/gir/util.js.map +0 -1
  254. package/lib/gir-module.d.ts +0 -104
  255. package/lib/gir-module.js +0 -584
  256. package/lib/gir-module.js.map +0 -1
  257. package/lib/gir.d.ts +0 -254
  258. package/lib/gir.js +0 -639
  259. package/lib/gir.js.map +0 -1
  260. package/lib/index.d.ts +0 -13
  261. package/lib/index.js +0 -16
  262. package/lib/index.js.map +0 -1
  263. package/lib/injections/gee08.d.ts +0 -7
  264. package/lib/injections/gee08.js +0 -68
  265. package/lib/injections/gee08.js.map +0 -1
  266. package/lib/injections/gee1.d.ts +0 -7
  267. package/lib/injections/gee1.js +0 -28
  268. package/lib/injections/gee1.js.map +0 -1
  269. package/lib/injections/gio.d.ts +0 -7
  270. package/lib/injections/gio.js +0 -563
  271. package/lib/injections/gio.js.map +0 -1
  272. package/lib/injections/glib.d.ts +0 -7
  273. package/lib/injections/glib.js +0 -210
  274. package/lib/injections/glib.js.map +0 -1
  275. package/lib/injections/gobject.d.ts +0 -7
  276. package/lib/injections/gobject.js +0 -594
  277. package/lib/injections/gobject.js.map +0 -1
  278. package/lib/injections/gtk4.d.ts +0 -7
  279. package/lib/injections/gtk4.js +0 -19
  280. package/lib/injections/gtk4.js.map +0 -1
  281. package/lib/injections/inject.d.ts +0 -4
  282. package/lib/injections/inject.js +0 -33
  283. package/lib/injections/inject.js.map +0 -1
  284. package/lib/injections/shell.d.ts +0 -20
  285. package/lib/injections/shell.js +0 -34
  286. package/lib/injections/shell.js.map +0 -1
  287. package/lib/injections/tracker1.d.ts +0 -7
  288. package/lib/injections/tracker1.js +0 -30
  289. package/lib/injections/tracker1.js.map +0 -1
  290. package/lib/library-version.d.ts +0 -10
  291. package/lib/library-version.js +0 -45
  292. package/lib/library-version.js.map +0 -1
  293. package/lib/logger.d.ts +0 -36
  294. package/lib/logger.js +0 -134
  295. package/lib/logger.js.map +0 -1
  296. package/lib/messages.d.ts +0 -23
  297. package/lib/messages.js +0 -39
  298. package/lib/messages.js.map +0 -1
  299. package/lib/registry.d.ts +0 -8
  300. package/lib/registry.js +0 -12
  301. package/lib/registry.js.map +0 -1
  302. package/lib/transformation.d.ts +0 -169
  303. package/lib/transformation.js +0 -393
  304. package/lib/transformation.js.map +0 -1
  305. package/lib/types/answer-version.d.ts +0 -4
  306. package/lib/types/answer-version.js +0 -2
  307. package/lib/types/answer-version.js.map +0 -1
  308. package/lib/types/class-parent.d.ts +0 -13
  309. package/lib/types/class-parent.js +0 -2
  310. package/lib/types/class-parent.js.map +0 -1
  311. package/lib/types/config-flags.d.ts +0 -4
  312. package/lib/types/config-flags.js +0 -2
  313. package/lib/types/config-flags.js.map +0 -1
  314. package/lib/types/construct-name.d.ts +0 -1
  315. package/lib/types/construct-name.js +0 -2
  316. package/lib/types/construct-name.js.map +0 -1
  317. package/lib/types/dependency-map.d.ts +0 -4
  318. package/lib/types/dependency-map.js +0 -2
  319. package/lib/types/dependency-map.js.map +0 -1
  320. package/lib/types/dependency.js +0 -2
  321. package/lib/types/dependency.js.map +0 -1
  322. package/lib/types/file-info.js +0 -2
  323. package/lib/types/file-info.js.map +0 -1
  324. package/lib/types/format.d.ts +0 -1
  325. package/lib/types/format.js +0 -2
  326. package/lib/types/format.js.map +0 -1
  327. package/lib/types/gir-alias-element.d.ts +0 -4
  328. package/lib/types/gir-alias-element.js +0 -2
  329. package/lib/types/gir-alias-element.js.map +0 -1
  330. package/lib/types/gir-annotation.d.ts +0 -9
  331. package/lib/types/gir-annotation.js +0 -2
  332. package/lib/types/gir-annotation.js.map +0 -1
  333. package/lib/types/gir-any-element.d.ts +0 -2
  334. package/lib/types/gir-any-element.js +0 -2
  335. package/lib/types/gir-any-element.js.map +0 -1
  336. package/lib/types/gir-bitfield-element.d.ts +0 -6
  337. package/lib/types/gir-bitfield-element.js +0 -2
  338. package/lib/types/gir-bitfield-element.js.map +0 -1
  339. package/lib/types/gir-callable-param-element.d.ts +0 -4
  340. package/lib/types/gir-callable-param-element.js +0 -2
  341. package/lib/types/gir-callable-param-element.js.map +0 -1
  342. package/lib/types/gir-callable-params.d.ts +0 -7
  343. package/lib/types/gir-callable-params.js +0 -2
  344. package/lib/types/gir-callable-params.js.map +0 -1
  345. package/lib/types/gir-callable-return.d.ts +0 -5
  346. package/lib/types/gir-callable-return.js +0 -2
  347. package/lib/types/gir-callable-return.js.map +0 -1
  348. package/lib/types/gir-callback-element.d.ts +0 -6
  349. package/lib/types/gir-callback-element.js +0 -2
  350. package/lib/types/gir-callback-element.js.map +0 -1
  351. package/lib/types/gir-class-element.d.ts +0 -17
  352. package/lib/types/gir-class-element.js +0 -2
  353. package/lib/types/gir-class-element.js.map +0 -1
  354. package/lib/types/gir-constant-element.d.ts +0 -4
  355. package/lib/types/gir-constant-element.js +0 -2
  356. package/lib/types/gir-constant-element.js.map +0 -1
  357. package/lib/types/gir-constructor-element.d.ts +0 -6
  358. package/lib/types/gir-constructor-element.js +0 -2
  359. package/lib/types/gir-constructor-element.js.map +0 -1
  360. package/lib/types/gir-enum-element.d.ts +0 -6
  361. package/lib/types/gir-enum-element.js +0 -2
  362. package/lib/types/gir-enum-element.js.map +0 -1
  363. package/lib/types/gir-field-element.d.ts +0 -5
  364. package/lib/types/gir-field-element.js +0 -2
  365. package/lib/types/gir-field-element.js.map +0 -1
  366. package/lib/types/gir-function-element.d.ts +0 -6
  367. package/lib/types/gir-function-element.js +0 -2
  368. package/lib/types/gir-function-element.js.map +0 -1
  369. package/lib/types/gir-instance-parameter.d.ts +0 -7
  370. package/lib/types/gir-instance-parameter.js +0 -2
  371. package/lib/types/gir-instance-parameter.js.map +0 -1
  372. package/lib/types/gir-interface-element.d.ts +0 -16
  373. package/lib/types/gir-interface-element.js +0 -2
  374. package/lib/types/gir-interface-element.js.map +0 -1
  375. package/lib/types/gir-member-element.d.ts +0 -5
  376. package/lib/types/gir-member-element.js +0 -2
  377. package/lib/types/gir-member-element.js.map +0 -1
  378. package/lib/types/gir-method-element.d.ts +0 -7
  379. package/lib/types/gir-method-element.js +0 -2
  380. package/lib/types/gir-method-element.js.map +0 -1
  381. package/lib/types/gir-module-resolved-by.d.ts +0 -15
  382. package/lib/types/gir-module-resolved-by.js +0 -2
  383. package/lib/types/gir-module-resolved-by.js.map +0 -1
  384. package/lib/types/gir-modules-grouped-map.d.ts +0 -4
  385. package/lib/types/gir-modules-grouped-map.js +0 -2
  386. package/lib/types/gir-modules-grouped-map.js.map +0 -1
  387. package/lib/types/gir-modules-grouped.d.ts +0 -12
  388. package/lib/types/gir-modules-grouped.js +0 -2
  389. package/lib/types/gir-modules-grouped.js.map +0 -1
  390. package/lib/types/gir-namespace.d.ts +0 -27
  391. package/lib/types/gir-namespace.js +0 -2
  392. package/lib/types/gir-namespace.js.map +0 -1
  393. package/lib/types/gir-property-element.d.ts +0 -4
  394. package/lib/types/gir-property-element.js +0 -2
  395. package/lib/types/gir-property-element.js.map +0 -1
  396. package/lib/types/gir-record-element.d.ts +0 -10
  397. package/lib/types/gir-record-element.js +0 -2
  398. package/lib/types/gir-record-element.js.map +0 -1
  399. package/lib/types/gir-repository.d.ts +0 -5
  400. package/lib/types/gir-repository.js +0 -2
  401. package/lib/types/gir-repository.js.map +0 -1
  402. package/lib/types/gir-signal.d.ts +0 -10
  403. package/lib/types/gir-signal.js +0 -2
  404. package/lib/types/gir-signal.js.map +0 -1
  405. package/lib/types/gir-type-name.d.ts +0 -2
  406. package/lib/types/gir-type-name.js +0 -2
  407. package/lib/types/gir-type-name.js.map +0 -1
  408. package/lib/types/gir-union-element.d.ts +0 -9
  409. package/lib/types/gir-union-element.js +0 -2
  410. package/lib/types/gir-union-element.js.map +0 -1
  411. package/lib/types/gir-unparsed-number.d.ts +0 -2
  412. package/lib/types/gir-unparsed-number.js +0 -2
  413. package/lib/types/gir-unparsed-number.js.map +0 -1
  414. package/lib/types/gir-virtual-method.d.ts +0 -6
  415. package/lib/types/gir-virtual-method.js +0 -2
  416. package/lib/types/gir-virtual-method.js.map +0 -1
  417. package/lib/types/index.d.ts +0 -79
  418. package/lib/types/index.js +0 -80
  419. package/lib/types/index.js.map +0 -1
  420. package/lib/types/inheritance-table.js +0 -2
  421. package/lib/types/inheritance-table.js.map +0 -1
  422. package/lib/types/local-name-check.d.ts +0 -4
  423. package/lib/types/local-name-check.js +0 -2
  424. package/lib/types/local-name-check.js.map +0 -1
  425. package/lib/types/local-name-type.d.ts +0 -1
  426. package/lib/types/local-name-type.js +0 -2
  427. package/lib/types/local-name-type.js.map +0 -1
  428. package/lib/types/local-name.d.ts +0 -7
  429. package/lib/types/local-name.js +0 -2
  430. package/lib/types/local-name.js.map +0 -1
  431. package/lib/types/local-names.d.ts +0 -4
  432. package/lib/types/local-names.js +0 -2
  433. package/lib/types/local-names.js.map +0 -1
  434. package/lib/types/metadata.d.ts +0 -8
  435. package/lib/types/metadata.js +0 -2
  436. package/lib/types/metadata.js.map +0 -1
  437. package/lib/types/options-base.d.ts +0 -4
  438. package/lib/types/options-base.js +0 -2
  439. package/lib/types/options-base.js.map +0 -1
  440. package/lib/types/options-generation.js +0 -2
  441. package/lib/types/options-generation.js.map +0 -1
  442. package/lib/types/options-load.d.ts +0 -5
  443. package/lib/types/options-load.js +0 -2
  444. package/lib/types/options-load.js.map +0 -1
  445. package/lib/types/options-transform.d.ts +0 -4
  446. package/lib/types/options-transform.js +0 -2
  447. package/lib/types/options-transform.js.map +0 -1
  448. package/lib/types/output-format.d.ts +0 -1
  449. package/lib/types/output-format.js +0 -2
  450. package/lib/types/output-format.js.map +0 -1
  451. package/lib/types/package-data-parsed.js +0 -2
  452. package/lib/types/package-data-parsed.js.map +0 -1
  453. package/lib/types/package-data.js +0 -2
  454. package/lib/types/package-data.js.map +0 -1
  455. package/lib/types/package-section-parsed.d.ts +0 -8
  456. package/lib/types/package-section-parsed.js +0 -2
  457. package/lib/types/package-section-parsed.js.map +0 -1
  458. package/lib/types/parsed-gir.d.ts +0 -5
  459. package/lib/types/parsed-gir.js +0 -2
  460. package/lib/types/parsed-gir.js.map +0 -1
  461. package/lib/types/parsed-package-data.d.ts +0 -6
  462. package/lib/types/parsed-package-data.js +0 -2
  463. package/lib/types/parsed-package-data.js.map +0 -1
  464. package/lib/types/part-of-class.d.ts +0 -7
  465. package/lib/types/part-of-class.js +0 -2
  466. package/lib/types/part-of-class.js.map +0 -1
  467. package/lib/types/part-of-module.d.ts +0 -6
  468. package/lib/types/part-of-module.js +0 -2
  469. package/lib/types/part-of-module.js.map +0 -1
  470. package/lib/types/property-case.d.ts +0 -1
  471. package/lib/types/property-case.js +0 -2
  472. package/lib/types/property-case.js.map +0 -1
  473. package/lib/types/resolve-type.d.ts +0 -4
  474. package/lib/types/resolve-type.js +0 -6
  475. package/lib/types/resolve-type.js.map +0 -1
  476. package/lib/types/template-data.d.ts +0 -7
  477. package/lib/types/template-data.js +0 -2
  478. package/lib/types/template-data.js.map +0 -1
  479. package/lib/types/transformation-case.d.ts +0 -1
  480. package/lib/types/transformation-case.js +0 -2
  481. package/lib/types/transformation-case.js.map +0 -1
  482. package/lib/types/transformations.d.ts +0 -4
  483. package/lib/types/transformations.js +0 -2
  484. package/lib/types/transformations.js.map +0 -1
  485. package/lib/types/ts-doc-tag.js +0 -2
  486. package/lib/types/ts-doc-tag.js.map +0 -1
  487. package/lib/types/ts-doc.js +0 -2
  488. package/lib/types/ts-doc.js.map +0 -1
  489. package/lib/types/type-gir-alias.js +0 -2
  490. package/lib/types/type-gir-alias.js.map +0 -1
  491. package/lib/types/type-gir-class.js +0 -2
  492. package/lib/types/type-gir-class.js.map +0 -1
  493. package/lib/types/type-gir-element.d.ts +0 -3
  494. package/lib/types/type-gir-element.js +0 -2
  495. package/lib/types/type-gir-element.js.map +0 -1
  496. package/lib/types/type-gir-enumeration-member.js +0 -2
  497. package/lib/types/type-gir-enumeration-member.js.map +0 -1
  498. package/lib/types/type-gir-enumeration.js +0 -2
  499. package/lib/types/type-gir-enumeration.js.map +0 -1
  500. package/lib/types/type-gir-function.d.ts +0 -1
  501. package/lib/types/type-gir-function.js +0 -2
  502. package/lib/types/type-gir-function.js.map +0 -1
  503. package/lib/types/type-gir-interface.js +0 -2
  504. package/lib/types/type-gir-interface.js.map +0 -1
  505. package/lib/types/type-gir-method.js +0 -2
  506. package/lib/types/type-gir-method.js.map +0 -1
  507. package/lib/types/type-gir-parameter.d.ts +0 -1
  508. package/lib/types/type-gir-parameter.js +0 -2
  509. package/lib/types/type-gir-parameter.js.map +0 -1
  510. package/lib/types/type-gir-property.js +0 -2
  511. package/lib/types/type-gir-property.js.map +0 -1
  512. package/lib/types/type-gir-variable.d.ts +0 -1
  513. package/lib/types/type-gir-variable.js +0 -2
  514. package/lib/types/type-gir-variable.js.map +0 -1
  515. package/lib/types/type-ts-element.d.ts +0 -3
  516. package/lib/types/type-ts-element.js +0 -2
  517. package/lib/types/type-ts-element.js.map +0 -1
  518. package/lib/types/type-ts-enumeration-member.js +0 -2
  519. package/lib/types/type-ts-enumeration-member.js.map +0 -1
  520. package/lib/types/type-ts-function.js +0 -2
  521. package/lib/types/type-ts-function.js.map +0 -1
  522. package/lib/types/type-ts-property.js +0 -2
  523. package/lib/types/type-ts-property.js.map +0 -1
  524. package/lib/types/user-config-load-result.d.ts +0 -6
  525. package/lib/types/user-config-load-result.js +0 -2
  526. package/lib/types/user-config-load-result.js.map +0 -1
  527. package/lib/types/user-config.js +0 -2
  528. package/lib/types/user-config.js.map +0 -1
  529. package/lib/util.d.ts +0 -20
  530. package/lib/util.js +0 -67
  531. package/lib/util.js.map +0 -1
  532. package/lib/utils/documentation.d.ts +0 -13
  533. package/lib/utils/documentation.js.map +0 -1
  534. package/lib/utils/files.d.ts +0 -21
  535. package/lib/utils/files.js +0 -62
  536. package/lib/utils/files.js.map +0 -1
  537. package/lib/utils/girs.d.ts +0 -45
  538. package/lib/utils/girs.js +0 -101
  539. package/lib/utils/girs.js.map +0 -1
  540. package/lib/utils/index.d.ts +0 -8
  541. package/lib/utils/index.js +0 -9
  542. package/lib/utils/index.js.map +0 -1
  543. package/lib/utils/naming.d.ts +0 -13
  544. package/lib/utils/naming.js +0 -40
  545. package/lib/utils/naming.js.map +0 -1
  546. package/lib/utils/numbers.js +0 -9
  547. package/lib/utils/numbers.js.map +0 -1
  548. package/lib/utils/objects.d.ts +0 -136
  549. package/lib/utils/objects.js.map +0 -1
  550. package/lib/utils/path.d.ts +0 -1
  551. package/lib/utils/path.js +0 -7
  552. package/lib/utils/path.js.map +0 -1
  553. package/lib/utils/strings.d.ts +0 -74
  554. package/lib/utils/strings.js +0 -121
  555. package/lib/utils/strings.js.map +0 -1
  556. package/lib/validators/class.d.ts +0 -7
  557. package/lib/validators/class.js +0 -217
  558. package/lib/validators/class.js.map +0 -1
  559. package/lib/validators/function-parameters.d.ts +0 -14
  560. package/lib/validators/function-parameters.js +0 -31
  561. package/lib/validators/function-parameters.js.map +0 -1
  562. package/lib/validators/interface.d.ts +0 -5
  563. package/lib/validators/interface.js +0 -16
  564. package/lib/validators/interface.js.map +0 -1
  565. package/lib/visitor.d.ts +0 -35
  566. package/lib/visitor.js +0 -29
  567. package/lib/visitor.js.map +0 -1
@@ -0,0 +1,477 @@
1
+ import { ConsoleReporter } from "@ts-for-gir/reporter";
2
+ import type { FormatGenerator } from "../generators/generator.ts";
3
+ import { ArrayType, ClassStructTypeIdentifier, NativeType, type TypeExpression, TypeIdentifier } from "../gir.ts";
4
+ import type { GirRecordElement, GirUnionElement, OptionsLoad, RecordResolution } from "../types/index.ts";
5
+ import { parseDoc, parseMetadata } from "../utils/gir-parsing.ts";
6
+ import { sanitizeIdentifierName } from "../utils/naming.ts";
7
+ import { resolveTypeIdentifier } from "../utils/type-resolution.ts";
8
+ import { parseTypeIdentifier } from "../utils/types.ts";
9
+ import type { GirVisitor } from "../visitor.ts";
10
+ import { IntrospectedConstructor } from "./constructor.ts";
11
+ import {
12
+ IntrospectedBaseClass,
13
+ type IntrospectedClassCallback,
14
+ IntrospectedClassFunction,
15
+ IntrospectedStaticClassFunction,
16
+ } from "./introspected-classes.ts";
17
+ import type { IntrospectedNamespace } from "./namespace.ts";
18
+ import { IntrospectedField, type IntrospectedProperty } from "./property.ts";
19
+ import type { IntrospectedSignal } from "./signal.ts";
20
+
21
+ const log = new ConsoleReporter(true, "gir/class", true);
22
+
23
+ export class IntrospectedRecord extends IntrospectedBaseClass {
24
+ private _isForeign: boolean = false;
25
+ private _structFor: ClassStructTypeIdentifier | null = null;
26
+ private _isSimple: boolean | null = null;
27
+ private _isSimpleWithoutPointers: string | null = null;
28
+
29
+ /**
30
+ * Returns all signals for this record (records typically don't have signals)
31
+ */
32
+ getAllSignals(): Array<{
33
+ name: string;
34
+ signal?: IntrospectedSignal;
35
+ isNotifySignal?: boolean;
36
+ isDetailSignal?: boolean;
37
+ parameterTypes?: string[];
38
+ returnType?: string;
39
+ }> {
40
+ // Records typically don't have signals, but we provide a consistent API
41
+ return [];
42
+ }
43
+
44
+ isForeign(): boolean {
45
+ return this._isForeign;
46
+ }
47
+
48
+ get structFor() {
49
+ return this._structFor;
50
+ }
51
+
52
+ getType(): TypeIdentifier {
53
+ if (this._structFor) {
54
+ return this._structFor;
55
+ }
56
+
57
+ return new TypeIdentifier(this.name, this.namespace.namespace);
58
+ }
59
+
60
+ someParent(predicate: (p: IntrospectedRecord) => boolean): boolean {
61
+ const resolution = this.resolveParents();
62
+ const parent = resolution.extends();
63
+
64
+ return !!parent && (predicate(parent.node) || parent.node.someParent(predicate));
65
+ }
66
+
67
+ findParent(predicate: (p: IntrospectedRecord) => boolean): IntrospectedRecord | undefined {
68
+ const resolution = this.resolveParents();
69
+
70
+ const parent = resolution.extends();
71
+
72
+ if (parent) {
73
+ if (predicate(parent.node)) return parent.node;
74
+
75
+ const found = parent.node.findParent(predicate);
76
+
77
+ if (found) return found;
78
+ }
79
+
80
+ return undefined;
81
+ }
82
+
83
+ findParentMap<K>(predicate: (p: IntrospectedRecord) => K | undefined): K | undefined {
84
+ const resolution = this.resolveParents();
85
+
86
+ const parent = resolution.extends();
87
+
88
+ if (parent) {
89
+ const result = predicate(parent.node);
90
+
91
+ if (result !== undefined) return result;
92
+
93
+ return parent.node.findParentMap(predicate);
94
+ }
95
+
96
+ return undefined;
97
+ }
98
+
99
+ accept(visitor: GirVisitor): IntrospectedRecord {
100
+ const node = this.copy({
101
+ constructors: this.constructors.map((c) => c.accept(visitor)),
102
+ members: this.members.map((m) => m.accept(visitor)),
103
+ props: this.props.map((p) => p.accept(visitor)),
104
+ fields: this.fields.map((f) => f.accept(visitor)),
105
+ callbacks: this.callbacks.map((c) => c.accept(visitor)),
106
+ });
107
+
108
+ return visitor.visitRecord?.(node) ?? node;
109
+ }
110
+
111
+ resolveParents(): RecordResolution {
112
+ const { namespace, superType } = this;
113
+
114
+ return {
115
+ *[Symbol.iterator]() {
116
+ let current = this.extends();
117
+
118
+ while (current !== undefined) {
119
+ yield current;
120
+ current = current.extends();
121
+ }
122
+ },
123
+ extends() {
124
+ const resolved_parent = superType ? resolveTypeIdentifier(namespace, superType) : undefined;
125
+ if (resolved_parent instanceof IntrospectedRecord) return resolved_parent.resolveParents();
126
+
127
+ return undefined;
128
+ },
129
+ node: this,
130
+ identifier: this.getType(),
131
+ };
132
+ }
133
+
134
+ copy(
135
+ options: {
136
+ parent?: undefined;
137
+ constructors?: IntrospectedConstructor[];
138
+ members?: IntrospectedClassFunction[];
139
+ props?: IntrospectedProperty[];
140
+ fields?: IntrospectedField[];
141
+ callbacks?: IntrospectedClassCallback[];
142
+ } = {},
143
+ ): IntrospectedRecord {
144
+ const {
145
+ name,
146
+ namespace,
147
+ superType,
148
+ members,
149
+ constructors,
150
+ _isForeign,
151
+ _structFor,
152
+ props,
153
+ fields,
154
+ callbacks,
155
+ generics,
156
+ mainConstructor,
157
+ } = this;
158
+
159
+ const clazz = new IntrospectedRecord({ name, namespace });
160
+
161
+ clazz._copyBaseProperties(this);
162
+
163
+ if (superType) {
164
+ clazz.superType = superType;
165
+ }
166
+
167
+ clazz._structFor = _structFor;
168
+ clazz._isForeign = _isForeign;
169
+ clazz.props = (options.props ?? props).map((p) => p.copy({ parent: clazz }));
170
+ clazz.fields = (options.fields ?? fields).map((f) => f.copy({ parent: clazz }));
171
+ clazz.callbacks = (options.callbacks ?? callbacks).map((c) => c.copy({ parent: clazz }));
172
+ clazz.mainConstructor = mainConstructor?.copy({ parent: clazz }) ?? null;
173
+ clazz.constructors = (options.constructors ?? constructors).map((c) => c.copy({ parent: clazz }));
174
+ clazz.members = (options.members ?? members).map((m) => m.copy({ parent: clazz }));
175
+ clazz.generics = [...generics];
176
+
177
+ return clazz;
178
+ }
179
+
180
+ static foreign(name: string, namespace: IntrospectedNamespace): IntrospectedRecord {
181
+ const foreignRecord = new IntrospectedRecord({ name, namespace });
182
+ foreignRecord._isForeign = true;
183
+ return foreignRecord;
184
+ }
185
+
186
+ static fromXML(
187
+ element: GirRecordElement | GirUnionElement,
188
+ namespace: IntrospectedNamespace,
189
+ options: OptionsLoad,
190
+ ): IntrospectedRecord {
191
+ if (!element.$.name) {
192
+ throw new Error("Invalid GIR File: No name provided for union.");
193
+ }
194
+
195
+ const name = sanitizeIdentifierName(namespace.namespace, element.$.name);
196
+
197
+ if (options.verbose) {
198
+ log.debug(` >> GirRecord: Parsing definition ${element.$.name} (${name})...`);
199
+ }
200
+
201
+ const clazz = new IntrospectedRecord({ name, namespace });
202
+
203
+ IntrospectedRecord.configureRecordProperties(element, clazz);
204
+ IntrospectedRecord.setupTypeStructOrResolveNames(element, clazz, namespace, name);
205
+ IntrospectedRecord.parseRecordDocumentation(element, clazz, options);
206
+ IntrospectedRecord.parseRecordMembers(element, clazz, options);
207
+
208
+ return clazz;
209
+ }
210
+
211
+ private static configureRecordProperties(
212
+ element: GirRecordElement | GirUnionElement,
213
+ clazz: IntrospectedRecord,
214
+ ): void {
215
+ const isPrivate = IntrospectedRecord.isRecordPrivate(element);
216
+ clazz.setPrivate(isPrivate);
217
+
218
+ const isForeign = "foreign" in element.$ && element.$.foreign === "1";
219
+ clazz._isForeign = isForeign;
220
+ }
221
+
222
+ private static isRecordPrivate(element: GirRecordElement | GirUnionElement): boolean {
223
+ if (!element.$.name) {
224
+ return false;
225
+ }
226
+
227
+ return (
228
+ element.$.name.startsWith("_") ||
229
+ ("disguised" in element.$ && element.$.disguised === "1") ||
230
+ ("opaque" in element.$ && element.$.opaque === "1")
231
+ );
232
+ }
233
+
234
+ private static setupTypeStructOrResolveNames(
235
+ element: GirRecordElement | GirUnionElement,
236
+ clazz: IntrospectedRecord,
237
+ namespace: IntrospectedNamespace,
238
+ name: string,
239
+ ): void {
240
+ const gtypeStructFor = element.$["glib:is-gtype-struct-for"];
241
+
242
+ if (typeof gtypeStructFor === "string" && gtypeStructFor) {
243
+ const structFor = parseTypeIdentifier(namespace.namespace, gtypeStructFor);
244
+ clazz._structFor = new ClassStructTypeIdentifier(structFor.name, structFor.namespace);
245
+ } else {
246
+ IntrospectedRecord.registerResolveNames(element, clazz, namespace, name);
247
+ }
248
+ }
249
+
250
+ private static registerResolveNames(
251
+ element: GirRecordElement | GirUnionElement,
252
+ clazz: IntrospectedRecord,
253
+ namespace: IntrospectedNamespace,
254
+ name: string,
255
+ ): void {
256
+ if (element.$["glib:type-name"]) {
257
+ clazz.resolve_names.push(element.$["glib:type-name"]);
258
+ namespace.registerResolveName(element.$["glib:type-name"], namespace.namespace, name);
259
+ }
260
+
261
+ if (element.$["c:type"]) {
262
+ clazz.resolve_names.push(element.$["c:type"]);
263
+ namespace.registerResolveName(element.$["c:type"], namespace.namespace, name);
264
+ }
265
+ }
266
+
267
+ private static parseRecordDocumentation(
268
+ element: GirRecordElement | GirUnionElement,
269
+ clazz: IntrospectedRecord,
270
+ options: OptionsLoad,
271
+ ): void {
272
+ if (options.loadDocs) {
273
+ clazz.doc = parseDoc(element);
274
+ clazz.metadata = parseMetadata(element);
275
+ }
276
+ }
277
+
278
+ private static parseRecordMembers(
279
+ element: GirRecordElement | GirUnionElement,
280
+ clazz: IntrospectedRecord,
281
+ options: OptionsLoad,
282
+ ): void {
283
+ try {
284
+ IntrospectedRecord.parseRecordMethods(element, clazz, options);
285
+ IntrospectedRecord.parseRecordConstructors(element, clazz, options);
286
+ IntrospectedRecord.parseRecordStaticMethods(element, clazz, options);
287
+ IntrospectedRecord.parseRecordFields(element, clazz);
288
+ } catch (e) {
289
+ log.reportParsingFailure(clazz.name, "record", clazz.namespace.namespace, e as Error);
290
+ }
291
+ }
292
+
293
+ private static parseRecordMethods(
294
+ element: GirRecordElement | GirUnionElement,
295
+ clazz: IntrospectedRecord,
296
+ options: OptionsLoad,
297
+ ): void {
298
+ if (element.method) {
299
+ clazz.members.push(...element.method.map((method) => IntrospectedClassFunction.fromXML(method, clazz, options)));
300
+ }
301
+ }
302
+
303
+ private static parseRecordConstructors(
304
+ element: GirRecordElement | GirUnionElement,
305
+ clazz: IntrospectedRecord,
306
+ options: OptionsLoad,
307
+ ): void {
308
+ if (Array.isArray(element.constructor)) {
309
+ element.constructor.forEach((ctor) => {
310
+ const c = IntrospectedConstructor.fromXML(ctor, clazz, options);
311
+ clazz.constructors.push(c);
312
+ });
313
+ }
314
+ }
315
+
316
+ private static parseRecordStaticMethods(
317
+ element: GirRecordElement | GirUnionElement,
318
+ clazz: IntrospectedRecord,
319
+ options: OptionsLoad,
320
+ ): void {
321
+ if (element.function) {
322
+ clazz.members.push(
323
+ ...element.function.map((func) => IntrospectedStaticClassFunction.fromXML(func, clazz, options)),
324
+ );
325
+ }
326
+ }
327
+
328
+ private static parseRecordFields(element: GirRecordElement | GirUnionElement, clazz: IntrospectedRecord): void {
329
+ if (element.field) {
330
+ clazz.fields.push(
331
+ ...element.field
332
+ .filter((field) => !("callback" in field))
333
+ .map((field) => IntrospectedField.fromXML(field, clazz)),
334
+ );
335
+ }
336
+ }
337
+
338
+ /**
339
+ * Calculate if a type expression is "simple" without pointers
340
+ */
341
+ isSimpleTypeWithoutPointers(typeContainer: TypeExpression): boolean {
342
+ if (!this.isSimpleType(typeContainer)) {
343
+ return false;
344
+ }
345
+
346
+ if (typeContainer.isPointer) {
347
+ return false;
348
+ }
349
+
350
+ // Primitive types can be directly allocated.
351
+ if (typeContainer instanceof NativeType) {
352
+ return true;
353
+ }
354
+
355
+ if (typeContainer instanceof ArrayType) {
356
+ if (typeContainer.type.equals(this.getType())) {
357
+ return true;
358
+ }
359
+
360
+ return this.isSimpleTypeWithoutPointers(typeContainer.type);
361
+ }
362
+
363
+ if (typeContainer instanceof TypeIdentifier) {
364
+ const type = typeContainer;
365
+
366
+ const child_ns = this.namespace.assertInstalledImport(type.namespace);
367
+
368
+ const alias = child_ns.getAlias(type.name);
369
+ if (alias) {
370
+ return this.isSimpleTypeWithoutPointers(alias.type);
371
+ }
372
+
373
+ const child = child_ns.getClass(type.name);
374
+ if (child === this) {
375
+ return false;
376
+ }
377
+
378
+ if (child instanceof IntrospectedRecord) {
379
+ return child.isSimpleWithoutPointers() !== null;
380
+ }
381
+ }
382
+
383
+ return false;
384
+ }
385
+
386
+ /**
387
+ * Calculate if a type expression is "simple"
388
+ */
389
+ isSimpleType(typeContainer: TypeExpression): boolean {
390
+ // Primitive types can be directly allocated.
391
+ if (typeContainer instanceof NativeType) {
392
+ return true;
393
+ }
394
+
395
+ if (typeContainer instanceof ArrayType) {
396
+ if (typeContainer.type.equals(this.getType())) {
397
+ return true;
398
+ }
399
+
400
+ return this.isSimpleType(typeContainer.type);
401
+ }
402
+
403
+ if (typeContainer instanceof TypeIdentifier) {
404
+ const type = typeContainer;
405
+
406
+ const child_ns = this.namespace.assertInstalledImport(type.namespace);
407
+
408
+ const alias = child_ns.getAlias(type.name);
409
+ if (alias) {
410
+ return this.isSimpleType(alias.type);
411
+ }
412
+
413
+ const child = child_ns.getClass(type.name);
414
+ if (child === this) {
415
+ return false;
416
+ }
417
+
418
+ if (child instanceof IntrospectedRecord) {
419
+ return child.isSimple();
420
+ }
421
+ }
422
+
423
+ return false;
424
+ }
425
+
426
+ /**
427
+ * Check if a record is "simple" and can be constructed by GJS
428
+ */
429
+ isSimple() {
430
+ // Records with no fields are not
431
+ // constructable.
432
+ if (this.fields.length === 0) {
433
+ return false;
434
+ }
435
+
436
+ // Because we may have to recursively check
437
+ // if types are instantiable we cache whether
438
+ // or not a given Record is simple.
439
+ if (this._isSimple !== null) {
440
+ return this._isSimple;
441
+ }
442
+
443
+ const isSimple = this.fields.every((f) => this.isSimpleType(f.type));
444
+
445
+ this._isSimple = isSimple;
446
+
447
+ return isSimple;
448
+ }
449
+
450
+ isSimpleWithoutPointers() {
451
+ // Records which are "simple without pointers" is a subset of
452
+ // "simple" records.
453
+ if (!this.isSimple()) {
454
+ return null;
455
+ }
456
+
457
+ // Because we may have to recursively check
458
+ // if types are instantiable we cache whether
459
+ // or not a given Record is simple.
460
+ if (this._isSimpleWithoutPointers !== null) {
461
+ return this._isSimpleWithoutPointers;
462
+ }
463
+
464
+ const isSimpleWithoutPointers = this.fields.find((f) => {
465
+ return !this.isSimpleTypeWithoutPointers(f.type);
466
+ });
467
+
468
+ if (!isSimpleWithoutPointers) this._isSimpleWithoutPointers = "all fields good";
469
+ else this._isSimpleWithoutPointers = null;
470
+
471
+ return this._isSimpleWithoutPointers;
472
+ }
473
+
474
+ asString<T extends FormatGenerator<unknown>>(generator: T): ReturnType<T["generateRecord"]> {
475
+ return generator.generateRecord(this) as ReturnType<T["generateRecord"]>;
476
+ }
477
+ }
@@ -0,0 +1,184 @@
1
+ import { DefaultFormatter } from "../formatters/default.ts";
2
+ import type { Formatter } from "../formatters/formatter.ts";
3
+ import { JSONFormatter } from "../formatters/json.ts";
4
+ import type { FormatGenerator } from "../generators/generator.ts";
5
+ import { generify } from "../generics/generify.ts";
6
+ import type { GirModule } from "../index.ts";
7
+ import { inject } from "../injections/inject.ts";
8
+ import type { GeneratorConstructor, OptionsGeneration, OptionsTransform } from "../types/index.ts";
9
+ import { TwoKeyMap } from "../util.ts";
10
+ import { ClassVisitor } from "../validators/class.ts";
11
+ import { FunctionParametersVisitor } from "../validators/function-parameters.ts";
12
+ import { InterfaceVisitor } from "../validators/interface.ts";
13
+ import type { GirVisitor } from "../visitor.ts";
14
+ import type { IntrospectedNamespace } from "./namespace.ts";
15
+
16
+ // TODO: Singleton
17
+ export class NSRegistry {
18
+ mapping: TwoKeyMap<string, string, IntrospectedNamespace> = new TwoKeyMap();
19
+ private formatters: Map<string, Formatter> = new Map();
20
+ private generators: Map<string, GeneratorConstructor<unknown>> = new Map();
21
+ c_mapping: Map<string, { version: string; name: string }[]> = new Map();
22
+ transformations: GirVisitor[] = [];
23
+ subtypes = new TwoKeyMap<string, string, TwoKeyMap<string, string, boolean>>();
24
+
25
+ constructor() {
26
+ this.formatters.set("json", new JSONFormatter());
27
+ }
28
+
29
+ registerTransformation(visitor: GirVisitor) {
30
+ this.transformations.push(visitor);
31
+
32
+ // Apply transformations to already built namespaces.
33
+ this.mapping.forEach((n) => {
34
+ n.accept(visitor);
35
+ });
36
+ }
37
+
38
+ registerFormatter(output: string, formatter: Formatter) {
39
+ this.formatters.set(output, formatter);
40
+ }
41
+
42
+ getFormatter(output: string) {
43
+ return this.formatters.get(output) ?? new DefaultFormatter();
44
+ }
45
+
46
+ registerGenerator<T>(
47
+ output: string,
48
+ generator: { new (namespace: IntrospectedNamespace, options: OptionsGeneration): FormatGenerator<T> },
49
+ ) {
50
+ this.generators.set(output, generator);
51
+ }
52
+
53
+ async getGenerator<T>(output: string): Promise<GeneratorConstructor<T> | undefined> {
54
+ // Handle loading external generators...
55
+ if (!this.generators.has(output)) {
56
+ let Generator: { default: GeneratorConstructor<unknown> };
57
+ try {
58
+ Generator = (await import(`@gi.ts/generator-${output}`)) as { default: GeneratorConstructor<unknown> };
59
+
60
+ if (Generator) {
61
+ console.log(`Loading generator "@gi.ts/generator-${output}"...`);
62
+ this.generators.set(output, Generator.default);
63
+ return Generator.default as GeneratorConstructor<T>;
64
+ }
65
+ } catch {
66
+ try {
67
+ Generator = (await import(`gi-ts-generator-${output}`)) as {
68
+ default: GeneratorConstructor<unknown>;
69
+ };
70
+
71
+ console.log(`Loading generator "gi-ts-generator-${output}"...`);
72
+ this.generators.set(output, Generator.default);
73
+ return Generator.default as GeneratorConstructor<T>;
74
+ } catch {
75
+ try {
76
+ Generator = (await import(`${output}`)) as { default: GeneratorConstructor<unknown> };
77
+
78
+ console.log(`Loading generator "${output}"...`);
79
+ this.generators.set(output, Generator.default);
80
+ return Generator.default as GeneratorConstructor<T>;
81
+ } catch {}
82
+ }
83
+ }
84
+ }
85
+
86
+ return this.generators.get(output) as GeneratorConstructor<T> | undefined;
87
+ }
88
+
89
+ private _transformNamespace(namespace: IntrospectedNamespace) {
90
+ this.transformations.forEach((t) => {
91
+ namespace.accept(t);
92
+ });
93
+ }
94
+
95
+ namespace(name: string, version: string): IntrospectedNamespace | null {
96
+ const namespace = this.mapping.get(name, version);
97
+
98
+ return namespace ?? null;
99
+ }
100
+
101
+ namespacesForPrefix(c_prefix: string): IntrospectedNamespace[] {
102
+ return (this.c_mapping.get(c_prefix) ?? []).map((c_mapping) =>
103
+ this.assertNamespace(c_mapping.name, c_mapping.version),
104
+ );
105
+ }
106
+
107
+ transform(options: OptionsTransform) {
108
+ const GLib = this.assertNamespace("GLib", "2.0");
109
+ const Gio = this.assertNamespace("Gio", "2.0");
110
+ const GObject = this.assertNamespace("GObject", "2.0");
111
+
112
+ // These follow the GLib version.
113
+ Gio.package_version = [...GLib.package_version];
114
+ GObject.package_version = [...GLib.package_version];
115
+
116
+ const interfaceVisitor = new InterfaceVisitor();
117
+ this.registerTransformation(interfaceVisitor);
118
+
119
+ const classVisitor = new ClassVisitor();
120
+ this.registerTransformation(classVisitor);
121
+
122
+ const enumParamsVisitor = new FunctionParametersVisitor();
123
+ this.registerTransformation(enumParamsVisitor);
124
+
125
+ console.log("Adding generics...");
126
+ generify(this, options.inferGenerics);
127
+
128
+ console.log("Injecting types...");
129
+ inject(this);
130
+ }
131
+
132
+ defaultVersionOf(name: string): string | null {
133
+ // GJS has a hard dependency on these versions.
134
+ if (name === "GLib" || name === "Gio" || name === "GObject") {
135
+ return "2.0";
136
+ }
137
+
138
+ const meta = this.mapping.getIfOnly(name);
139
+
140
+ if (meta) {
141
+ return meta[0];
142
+ }
143
+
144
+ return null;
145
+ }
146
+
147
+ assertDefaultVersionOf(name: string): string {
148
+ const version = this.defaultVersionOf(name);
149
+
150
+ if (version) {
151
+ return version;
152
+ }
153
+
154
+ // This mirrors GJS' and GI's default behavior.
155
+ // If we can't find a single version of an unspecified dependency, we throw an error.
156
+ throw new Error(`No single version found for unspecified dependency: ${JSON.stringify(name)}.`);
157
+ }
158
+
159
+ assertNamespace(name: string, version: string): IntrospectedNamespace {
160
+ const namespace = this.mapping.get(name, version) ?? null;
161
+
162
+ if (!namespace) {
163
+ throw new Error(`Namespace '${name}' not found.`);
164
+ }
165
+
166
+ return namespace;
167
+ }
168
+
169
+ register(namespace: GirModule): IntrospectedNamespace {
170
+ this.mapping.set(namespace.namespace, namespace.version, namespace);
171
+
172
+ namespace.c_prefixes.forEach((c_prefix) => {
173
+ const c_map = this.c_mapping.get(c_prefix) || [];
174
+
175
+ c_map.push({ name: namespace.namespace, version: namespace.version });
176
+
177
+ this.c_mapping.set(c_prefix, c_map);
178
+ });
179
+
180
+ this._transformNamespace(namespace);
181
+
182
+ return namespace;
183
+ }
184
+ }