@gtkx/gir 0.20.0 → 0.21.0

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 (115) hide show
  1. package/dist/index.d.ts +25 -12
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +21 -10
  4. package/dist/index.js.map +1 -1
  5. package/dist/internal/loader.d.ts +30 -0
  6. package/dist/internal/loader.d.ts.map +1 -0
  7. package/dist/internal/loader.js +109 -0
  8. package/dist/internal/loader.js.map +1 -0
  9. package/dist/internal/normalizer.d.ts +98 -15
  10. package/dist/internal/normalizer.d.ts.map +1 -1
  11. package/dist/internal/normalizer.js +381 -412
  12. package/dist/internal/normalizer.js.map +1 -1
  13. package/dist/internal/parser.d.ts +23 -31
  14. package/dist/internal/parser.d.ts.map +1 -1
  15. package/dist/internal/parser.js +228 -244
  16. package/dist/internal/parser.js.map +1 -1
  17. package/dist/internal/raw-types.d.ts +58 -109
  18. package/dist/internal/raw-types.d.ts.map +1 -1
  19. package/dist/internal/raw-types.js +0 -8
  20. package/dist/internal/raw-types.js.map +1 -1
  21. package/dist/intrinsics.d.ts.map +1 -1
  22. package/dist/intrinsics.js +7 -0
  23. package/dist/intrinsics.js.map +1 -1
  24. package/dist/model/alias.d.ts +21 -0
  25. package/dist/model/alias.d.ts.map +1 -0
  26. package/dist/model/alias.js +22 -0
  27. package/dist/model/alias.js.map +1 -0
  28. package/dist/model/callables.d.ts +102 -0
  29. package/dist/model/callables.d.ts.map +1 -0
  30. package/dist/model/callables.js +123 -0
  31. package/dist/model/callables.js.map +1 -0
  32. package/dist/model/callback.d.ts +22 -0
  33. package/dist/model/callback.d.ts.map +1 -0
  34. package/dist/model/callback.js +20 -0
  35. package/dist/model/callback.js.map +1 -0
  36. package/dist/model/class.d.ts +92 -0
  37. package/dist/model/class.d.ts.map +1 -0
  38. package/dist/model/class.js +171 -0
  39. package/dist/model/class.js.map +1 -0
  40. package/dist/model/constant.d.ts +21 -0
  41. package/dist/model/constant.d.ts.map +1 -0
  42. package/dist/model/constant.js +20 -0
  43. package/dist/model/constant.js.map +1 -0
  44. package/dist/model/enumeration.d.ts +41 -0
  45. package/dist/model/enumeration.d.ts.map +1 -0
  46. package/dist/model/enumeration.js +47 -0
  47. package/dist/model/enumeration.js.map +1 -0
  48. package/dist/model/field.d.ts +21 -0
  49. package/dist/model/field.d.ts.map +1 -0
  50. package/dist/model/field.js +20 -0
  51. package/dist/model/field.js.map +1 -0
  52. package/dist/model/interface.d.ts +44 -0
  53. package/dist/model/interface.d.ts.map +1 -0
  54. package/dist/model/interface.js +67 -0
  55. package/dist/model/interface.js.map +1 -0
  56. package/dist/model/namespace.d.ts +44 -0
  57. package/dist/model/namespace.d.ts.map +1 -0
  58. package/dist/model/namespace.js +36 -0
  59. package/dist/model/namespace.js.map +1 -0
  60. package/dist/model/parameter.d.ts +43 -0
  61. package/dist/model/parameter.d.ts.map +1 -0
  62. package/dist/model/parameter.js +54 -0
  63. package/dist/model/parameter.js.map +1 -0
  64. package/dist/model/property.d.ts +62 -0
  65. package/dist/model/property.d.ts.map +1 -0
  66. package/dist/model/property.js +69 -0
  67. package/dist/model/property.js.map +1 -0
  68. package/dist/model/record.d.ts +56 -0
  69. package/dist/model/record.d.ts.map +1 -0
  70. package/dist/model/record.js +70 -0
  71. package/dist/model/record.js.map +1 -0
  72. package/dist/model/repository-like.d.ts +19 -0
  73. package/dist/model/repository-like.d.ts.map +1 -0
  74. package/dist/model/repository-like.js +2 -0
  75. package/dist/model/repository-like.js.map +1 -0
  76. package/dist/model/signal.d.ts +22 -0
  77. package/dist/model/signal.d.ts.map +1 -0
  78. package/dist/model/signal.js +22 -0
  79. package/dist/model/signal.js.map +1 -0
  80. package/dist/model/type.d.ts +71 -0
  81. package/dist/model/type.d.ts.map +1 -0
  82. package/dist/model/type.js +112 -0
  83. package/dist/model/type.js.map +1 -0
  84. package/dist/repository.d.ts +92 -138
  85. package/dist/repository.d.ts.map +1 -1
  86. package/dist/repository.js +155 -219
  87. package/dist/repository.js.map +1 -1
  88. package/package.json +2 -2
  89. package/src/index.ts +25 -39
  90. package/src/internal/loader.ts +127 -0
  91. package/src/internal/normalizer.ts +451 -475
  92. package/src/internal/parser.ts +242 -284
  93. package/src/internal/raw-types.ts +65 -116
  94. package/src/intrinsics.ts +7 -0
  95. package/src/model/alias.ts +31 -0
  96. package/src/model/callables.ts +172 -0
  97. package/src/model/callback.ts +30 -0
  98. package/src/model/class.ts +215 -0
  99. package/src/model/constant.ts +29 -0
  100. package/src/model/enumeration.ts +64 -0
  101. package/src/model/field.ts +29 -0
  102. package/src/model/interface.ts +89 -0
  103. package/src/model/namespace.ts +60 -0
  104. package/src/model/parameter.ts +74 -0
  105. package/src/model/property.ts +97 -0
  106. package/src/model/record.ts +97 -0
  107. package/src/model/repository-like.ts +20 -0
  108. package/src/model/signal.ts +32 -0
  109. package/src/model/type.ts +143 -0
  110. package/src/repository.ts +197 -283
  111. package/dist/types.d.ts +0 -655
  112. package/dist/types.d.ts.map +0 -1
  113. package/dist/types.js +0 -879
  114. package/dist/types.js.map +0 -1
  115. package/src/types.ts +0 -1192
@@ -0,0 +1,97 @@
1
+ import type { GirConstructor, GirFunction, GirMethod } from "./callables.js";
2
+ import type { GirField } from "./field.js";
3
+
4
+ /**
5
+ * Record (boxed type or plain struct) with helper methods.
6
+ */
7
+ export class GirRecord {
8
+ readonly name: string;
9
+ readonly qualifiedName: string;
10
+ readonly cType: string;
11
+ readonly opaque: boolean;
12
+ readonly disguised: boolean;
13
+ readonly glibTypeName?: string;
14
+ readonly glibGetType?: string;
15
+ readonly isGtypeStructFor?: string;
16
+ readonly copyFunction?: string;
17
+ readonly freeFunction?: string;
18
+ readonly fields: GirField[];
19
+ readonly methods: GirMethod[];
20
+ readonly constructors: GirConstructor[];
21
+ readonly staticFunctions: GirFunction[];
22
+ readonly doc?: string;
23
+
24
+ constructor(data: {
25
+ name: string;
26
+ qualifiedName: string;
27
+ cType: string;
28
+ opaque: boolean;
29
+ disguised: boolean;
30
+ glibTypeName?: string;
31
+ glibGetType?: string;
32
+ isGtypeStructFor?: string;
33
+ copyFunction?: string;
34
+ freeFunction?: string;
35
+ fields: GirField[];
36
+ methods: GirMethod[];
37
+ constructors: GirConstructor[];
38
+ staticFunctions: GirFunction[];
39
+ doc?: string;
40
+ }) {
41
+ this.name = data.name;
42
+ this.qualifiedName = data.qualifiedName;
43
+ this.cType = data.cType;
44
+ this.opaque = data.opaque;
45
+ this.disguised = data.disguised;
46
+ this.glibTypeName = data.glibTypeName;
47
+ this.glibGetType = data.glibGetType;
48
+ this.isGtypeStructFor = data.isGtypeStructFor;
49
+ this.copyFunction = data.copyFunction;
50
+ this.freeFunction = data.freeFunction;
51
+ this.fields = data.fields;
52
+ this.methods = data.methods;
53
+ this.constructors = data.constructors;
54
+ this.staticFunctions = data.staticFunctions;
55
+ this.doc = data.doc;
56
+ }
57
+
58
+ /** True if this has custom copy/free functions. */
59
+ isFundamental(): boolean {
60
+ return this.copyFunction !== undefined && this.freeFunction !== undefined;
61
+ }
62
+
63
+ /** True if this is a GLib boxed type (has glibTypeName). */
64
+ isBoxed(): boolean {
65
+ return this.glibTypeName !== undefined;
66
+ }
67
+
68
+ /** True if this is a GType struct (vtable for a class/interface). */
69
+ isGtypeStruct(): boolean {
70
+ return this.isGtypeStructFor !== undefined;
71
+ }
72
+
73
+ /** True if this is a plain C struct (no GType, has public fields). */
74
+ isPlainStruct(): boolean {
75
+ return !this.glibTypeName && !this.opaque && this.getPublicFields().length > 0;
76
+ }
77
+
78
+ /** Gets public (non-private) fields only. */
79
+ getPublicFields(): GirField[] {
80
+ return this.fields.filter((f) => !f.private);
81
+ }
82
+
83
+ /** Finds a method by name. */
84
+ getMethod(name: string): GirMethod | null {
85
+ return this.methods.find((m) => m.name === name) ?? null;
86
+ }
87
+
88
+ /** Finds a field by name. */
89
+ getField(name: string): GirField | null {
90
+ return this.fields.find((f) => f.name === name) ?? null;
91
+ }
92
+
93
+ /** Finds a constructor by name. */
94
+ getConstructor(name: string): GirConstructor | null {
95
+ return this.constructors.find((c) => c.name === name) ?? null;
96
+ }
97
+ }
@@ -0,0 +1,20 @@
1
+ import type { GirClass } from "./class.js";
2
+ import type { GirInterface } from "./interface.js";
3
+
4
+ /**
5
+ * The kind of a user-defined type (not intrinsic).
6
+ */
7
+ export type TypeKind = "class" | "interface" | "record" | "enum" | "flags" | "callback";
8
+
9
+ /**
10
+ * Minimal repository interface used by model classes for type graph traversal.
11
+ *
12
+ * This interface breaks the circular dependency between model classes and
13
+ * the concrete GirRepository. Model classes depend on this interface,
14
+ * and GirRepository implements it.
15
+ */
16
+ export type RepositoryLike = {
17
+ resolveClass(qualifiedName: string): GirClass | null;
18
+ resolveInterface(qualifiedName: string): GirInterface | null;
19
+ findClasses(predicate: (cls: GirClass) => boolean): GirClass[];
20
+ };
@@ -0,0 +1,32 @@
1
+ import type { GirParameter } from "./parameter.js";
2
+ import type { GirType } from "./type.js";
3
+
4
+ /**
5
+ * GObject signal with helper methods.
6
+ */
7
+ export class GirSignal {
8
+ readonly name: string;
9
+ readonly when: "first" | "last" | "cleanup";
10
+ readonly returnType: GirType | null;
11
+ readonly parameters: GirParameter[];
12
+ readonly doc?: string;
13
+
14
+ constructor(data: {
15
+ name: string;
16
+ when: "first" | "last" | "cleanup";
17
+ returnType: GirType | null;
18
+ parameters: GirParameter[];
19
+ doc?: string;
20
+ }) {
21
+ this.name = data.name;
22
+ this.when = data.when;
23
+ this.returnType = data.returnType;
24
+ this.parameters = data.parameters;
25
+ this.doc = data.doc;
26
+ }
27
+
28
+ /** True if the signal returns a value. */
29
+ hasReturnValue(): boolean {
30
+ return this.returnType !== null && !this.returnType.isVoid();
31
+ }
32
+ }
@@ -0,0 +1,143 @@
1
+ import { isIntrinsicType, isNumericType, isStringType, isVoidType } from "../intrinsics.js";
2
+
3
+ /**
4
+ * Container type discriminator for generic GLib containers.
5
+ */
6
+ export type ContainerType = "ghashtable" | "gptrarray" | "garray" | "gbytearray" | "glist" | "gslist";
7
+
8
+ /**
9
+ * Type reference with helper methods.
10
+ *
11
+ * Type names are either fully qualified (`"Gtk.Widget"`) for namespace types
12
+ * or unqualified (`"gint"`, `"utf8"`) for intrinsic types.
13
+ */
14
+ export class GirType {
15
+ readonly name: string;
16
+ readonly cType?: string;
17
+ readonly isArray: boolean;
18
+ readonly elementType: GirType | null;
19
+ readonly typeParameters: readonly GirType[];
20
+ readonly containerType?: ContainerType;
21
+ readonly transferOwnership?: "none" | "full" | "container";
22
+ readonly nullable: boolean;
23
+ readonly sizeParamIndex?: number;
24
+ readonly zeroTerminated?: boolean;
25
+ readonly fixedSize?: number;
26
+
27
+ constructor(data: {
28
+ name: string;
29
+ cType?: string;
30
+ isArray: boolean;
31
+ elementType: GirType | null;
32
+ typeParameters?: readonly GirType[];
33
+ containerType?: ContainerType;
34
+ transferOwnership?: "none" | "full" | "container";
35
+ nullable: boolean;
36
+ sizeParamIndex?: number;
37
+ zeroTerminated?: boolean;
38
+ fixedSize?: number;
39
+ }) {
40
+ this.name = data.name;
41
+ this.cType = data.cType;
42
+ this.isArray = data.isArray;
43
+ this.elementType = data.elementType;
44
+ this.typeParameters = data.typeParameters ?? [];
45
+ this.containerType = data.containerType;
46
+ this.transferOwnership = data.transferOwnership;
47
+ this.nullable = data.nullable;
48
+ this.sizeParamIndex = data.sizeParamIndex;
49
+ this.zeroTerminated = data.zeroTerminated;
50
+ this.fixedSize = data.fixedSize;
51
+ }
52
+
53
+ /** True if this is an intrinsic/primitive type. */
54
+ isIntrinsic(): boolean {
55
+ return isIntrinsicType(this.name);
56
+ }
57
+
58
+ /** True if this is a string type (utf8 or filename). */
59
+ isString(): boolean {
60
+ return isStringType(this.name);
61
+ }
62
+
63
+ /** True if this is a numeric type. */
64
+ isNumeric(): boolean {
65
+ return isNumericType(this.name);
66
+ }
67
+
68
+ /** True if this is a boolean type. */
69
+ isBoolean(): boolean {
70
+ return this.name === "gboolean";
71
+ }
72
+
73
+ /** True if this is void. */
74
+ isVoid(): boolean {
75
+ return isVoidType(this.name);
76
+ }
77
+
78
+ /** True if this is GVariant. */
79
+ isVariant(): boolean {
80
+ return this.name === "GVariant";
81
+ }
82
+
83
+ /** True if this is GParamSpec. */
84
+ isParamSpec(): boolean {
85
+ return this.name === "GParamSpec";
86
+ }
87
+
88
+ /** True if this is a GHashTable container. */
89
+ isHashTable(): boolean {
90
+ return this.containerType === "ghashtable";
91
+ }
92
+
93
+ /** True if this is a GPtrArray container. */
94
+ isPtrArray(): boolean {
95
+ return this.containerType === "gptrarray";
96
+ }
97
+
98
+ /** True if this is a GArray container. */
99
+ isGArray(): boolean {
100
+ return this.containerType === "garray";
101
+ }
102
+
103
+ /** True if this is a GByteArray container. */
104
+ isByteArray(): boolean {
105
+ return this.containerType === "gbytearray";
106
+ }
107
+
108
+ /** True if this is a GList or GSList container. */
109
+ isList(): boolean {
110
+ return this.containerType === "glist" || this.containerType === "gslist";
111
+ }
112
+
113
+ /** True if this is any generic container type. */
114
+ isGenericContainer(): boolean {
115
+ return this.containerType !== undefined;
116
+ }
117
+
118
+ /** Gets the key type for GHashTable, or null for other types. */
119
+ getKeyType(): GirType | null {
120
+ if (!this.isHashTable() || this.typeParameters.length < 1) return null;
121
+ return this.typeParameters[0] ?? null;
122
+ }
123
+
124
+ /** Gets the value type for GHashTable, or null for other types. */
125
+ getValueType(): GirType | null {
126
+ if (!this.isHashTable() || this.typeParameters.length < 2) return null;
127
+ return this.typeParameters[1] ?? null;
128
+ }
129
+
130
+ /** Gets the namespace part of a qualified name, or null for intrinsics. */
131
+ getNamespace(): string | null {
132
+ if (this.isIntrinsic()) return null;
133
+ const dot = this.name.indexOf(".");
134
+ return dot >= 0 ? this.name.slice(0, dot) : null;
135
+ }
136
+
137
+ /** Gets the simple name part (without namespace). */
138
+ getSimpleName(): string {
139
+ if (this.isIntrinsic()) return this.name;
140
+ const dot = this.name.indexOf(".");
141
+ return dot >= 0 ? this.name.slice(dot + 1) : this.name;
142
+ }
143
+ }