@gtkx/gir 0.18.0 → 0.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +1 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/internal/normalizer.d.ts +1 -0
  6. package/dist/internal/normalizer.d.ts.map +1 -0
  7. package/dist/internal/normalizer.js +1 -0
  8. package/dist/internal/normalizer.js.map +1 -0
  9. package/dist/internal/parser.d.ts +1 -0
  10. package/dist/internal/parser.d.ts.map +1 -0
  11. package/dist/internal/parser.js +1 -0
  12. package/dist/internal/parser.js.map +1 -0
  13. package/dist/internal/raw-types.d.ts +1 -0
  14. package/dist/internal/raw-types.d.ts.map +1 -0
  15. package/dist/internal/raw-types.js +1 -0
  16. package/dist/internal/raw-types.js.map +1 -0
  17. package/dist/intrinsics.d.ts +1 -0
  18. package/dist/intrinsics.d.ts.map +1 -0
  19. package/dist/intrinsics.js +1 -0
  20. package/dist/intrinsics.js.map +1 -0
  21. package/dist/repository.d.ts +1 -0
  22. package/dist/repository.d.ts.map +1 -0
  23. package/dist/repository.js +1 -0
  24. package/dist/repository.js.map +1 -0
  25. package/dist/types.d.ts +1 -0
  26. package/dist/types.d.ts.map +1 -0
  27. package/dist/types.js +1 -0
  28. package/dist/types.js.map +1 -0
  29. package/dist/utils.d.ts +1 -0
  30. package/dist/utils.d.ts.map +1 -0
  31. package/dist/utils.js +1 -0
  32. package/dist/utils.js.map +1 -0
  33. package/package.json +4 -2
  34. package/src/index.ts +64 -0
  35. package/src/internal/normalizer.ts +551 -0
  36. package/src/internal/parser.ts +633 -0
  37. package/src/internal/raw-types.ts +268 -0
  38. package/src/intrinsics.ts +129 -0
  39. package/src/repository.ts +406 -0
  40. package/src/types.ts +1192 -0
  41. package/src/utils.ts +12 -0
@@ -0,0 +1,268 @@
1
+ /**
2
+ * Raw GIR type definitions.
3
+ *
4
+ * These types represent the structure of parsed GIR XML data before normalization.
5
+ * They are internal to the @gtkx/gir package and not exported publicly.
6
+ *
7
+ * @internal
8
+ */
9
+
10
+ import type { ContainerType } from "../types.js";
11
+
12
+ export type { ContainerType };
13
+
14
+ /**
15
+ * Represents a parsed GIR namespace (library).
16
+ *
17
+ * Contains all type definitions from a single GIR file, including
18
+ * classes, interfaces, functions, enums, records, and callbacks.
19
+ */
20
+ export type RawNamespace = {
21
+ name: string;
22
+ version: string;
23
+ sharedLibrary: string;
24
+ cPrefix: string;
25
+ classes: RawClass[];
26
+ interfaces: RawInterface[];
27
+ functions: RawFunction[];
28
+ enumerations: RawEnumeration[];
29
+ bitfields: RawEnumeration[];
30
+ records: RawRecord[];
31
+ callbacks: RawCallback[];
32
+ constants: RawConstant[];
33
+ aliases: RawAlias[];
34
+ doc?: string;
35
+ };
36
+
37
+ /**
38
+ * A constant value defined in a GIR namespace.
39
+ */
40
+ export type RawConstant = {
41
+ name: string;
42
+ cType: string;
43
+ value: string;
44
+ type: RawType;
45
+ doc?: string;
46
+ };
47
+
48
+ /**
49
+ * A callback type definition (function pointer type).
50
+ */
51
+ export type RawCallback = {
52
+ name: string;
53
+ cType: string;
54
+ returnType: RawType;
55
+ parameters: RawParameter[];
56
+ doc?: string;
57
+ };
58
+
59
+ /**
60
+ * A GObject interface definition.
61
+ */
62
+ export type RawInterface = {
63
+ name: string;
64
+ cType: string;
65
+ glibTypeName?: string;
66
+ prerequisites: string[];
67
+ methods: RawMethod[];
68
+ properties: RawProperty[];
69
+ signals: RawSignal[];
70
+ doc?: string;
71
+ };
72
+
73
+ /**
74
+ * A GObject class definition.
75
+ */
76
+ export type RawClass = {
77
+ name: string;
78
+ cType: string;
79
+ parent?: string;
80
+ abstract?: boolean;
81
+ glibTypeName?: string;
82
+ glibGetType?: string;
83
+ cSymbolPrefix?: string;
84
+ fundamental?: boolean;
85
+ refFunc?: string;
86
+ unrefFunc?: string;
87
+ implements: string[];
88
+ methods: RawMethod[];
89
+ constructors: RawConstructor[];
90
+ functions: RawFunction[];
91
+ properties: RawProperty[];
92
+ signals: RawSignal[];
93
+ doc?: string;
94
+ };
95
+
96
+ /**
97
+ * A GLib record (boxed type or struct).
98
+ */
99
+ export type RawRecord = {
100
+ name: string;
101
+ cType: string;
102
+ opaque?: boolean;
103
+ disguised?: boolean;
104
+ glibTypeName?: string;
105
+ glibGetType?: string;
106
+ isGtypeStructFor?: string;
107
+ copyFunction?: string;
108
+ freeFunction?: string;
109
+ fields: RawField[];
110
+ methods: RawMethod[];
111
+ constructors: RawConstructor[];
112
+ functions: RawFunction[];
113
+ doc?: string;
114
+ };
115
+
116
+ /**
117
+ * A field within a record or class.
118
+ */
119
+ export type RawField = {
120
+ name: string;
121
+ type: RawType;
122
+ writable?: boolean;
123
+ readable?: boolean;
124
+ private?: boolean;
125
+ doc?: string;
126
+ };
127
+
128
+ /**
129
+ * A method on a class, interface, or record.
130
+ */
131
+ export type RawMethod = {
132
+ name: string;
133
+ cIdentifier: string;
134
+ returnType: RawType;
135
+ parameters: RawParameter[];
136
+ instanceParameter?: RawParameter;
137
+ throws?: boolean;
138
+ doc?: string;
139
+ returnDoc?: string;
140
+ /** For async methods, the name of the corresponding finish function */
141
+ finishFunc?: string;
142
+ shadows?: string;
143
+ shadowedBy?: string;
144
+ };
145
+
146
+ /**
147
+ * A constructor for a class or record.
148
+ */
149
+ export type RawConstructor = {
150
+ name: string;
151
+ cIdentifier: string;
152
+ returnType: RawType;
153
+ parameters: RawParameter[];
154
+ throws?: boolean;
155
+ doc?: string;
156
+ returnDoc?: string;
157
+ shadows?: string;
158
+ shadowedBy?: string;
159
+ };
160
+
161
+ /**
162
+ * A standalone function or static method.
163
+ */
164
+ export type RawFunction = {
165
+ name: string;
166
+ cIdentifier: string;
167
+ returnType: RawType;
168
+ parameters: RawParameter[];
169
+ throws?: boolean;
170
+ doc?: string;
171
+ returnDoc?: string;
172
+ shadows?: string;
173
+ shadowedBy?: string;
174
+ };
175
+
176
+ /**
177
+ * A parameter to a function, method, or callback.
178
+ */
179
+ export type RawParameter = {
180
+ name: string;
181
+ type: RawType;
182
+ direction?: "in" | "out" | "inout";
183
+ callerAllocates?: boolean;
184
+ nullable?: boolean;
185
+ optional?: boolean;
186
+ scope?: "async" | "call" | "notified";
187
+ closure?: number;
188
+ destroy?: number;
189
+ transferOwnership?: "none" | "full" | "container";
190
+ doc?: string;
191
+ };
192
+
193
+ /**
194
+ * A type reference in GIR.
195
+ *
196
+ * Type names may be unqualified (e.g., "Widget") for local types
197
+ * or qualified (e.g., "GObject.Object") for cross-namespace references.
198
+ */
199
+ export type RawType = {
200
+ name: string;
201
+ cType?: string;
202
+ isArray?: boolean;
203
+ elementType?: RawType;
204
+ typeParameters?: RawType[];
205
+ containerType?: ContainerType;
206
+ transferOwnership?: "none" | "full" | "container";
207
+ nullable?: boolean;
208
+ sizeParamIndex?: number;
209
+ zeroTerminated?: boolean;
210
+ fixedSize?: number;
211
+ };
212
+
213
+ /**
214
+ * A GObject property definition.
215
+ */
216
+ export type RawProperty = {
217
+ name: string;
218
+ type: RawType;
219
+ readable?: boolean;
220
+ writable?: boolean;
221
+ constructOnly?: boolean;
222
+ defaultValueRaw?: string;
223
+ getter?: string;
224
+ setter?: string;
225
+ doc?: string;
226
+ };
227
+
228
+ /**
229
+ * A GObject signal definition.
230
+ */
231
+ export type RawSignal = {
232
+ name: string;
233
+ when?: "first" | "last" | "cleanup";
234
+ returnType?: RawType;
235
+ parameters?: RawParameter[];
236
+ doc?: string;
237
+ };
238
+
239
+ /**
240
+ * An enumeration or bitfield definition.
241
+ */
242
+ export type RawEnumeration = {
243
+ name: string;
244
+ cType: string;
245
+ members: RawEnumerationMember[];
246
+ glibGetType?: string;
247
+ doc?: string;
248
+ };
249
+
250
+ /**
251
+ * A member of an enumeration or bitfield.
252
+ */
253
+ export type RawEnumerationMember = {
254
+ name: string;
255
+ value: string;
256
+ cIdentifier: string;
257
+ doc?: string;
258
+ };
259
+
260
+ /**
261
+ * A type alias definition.
262
+ */
263
+ export type RawAlias = {
264
+ name: string;
265
+ cType: string;
266
+ targetType: RawType;
267
+ doc?: string;
268
+ };
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Intrinsic (primitive) types that are not namespace-qualified.
3
+ *
4
+ * These are fundamental GLib/GObject types that exist outside of any namespace.
5
+ * When normalizing type references, intrinsic types remain as-is rather than
6
+ * being qualified with a namespace prefix.
7
+ */
8
+ export const INTRINSIC_TYPES = new Set([
9
+ "void",
10
+ "none",
11
+ "gboolean",
12
+ "gint",
13
+ "gint8",
14
+ "gint16",
15
+ "gint32",
16
+ "gint64",
17
+ "gchar",
18
+ "gshort",
19
+ "glong",
20
+ "gssize",
21
+ "goffset",
22
+ "gintptr",
23
+ "guint",
24
+ "guint8",
25
+ "guint16",
26
+ "guint32",
27
+ "guint64",
28
+ "guchar",
29
+ "gushort",
30
+ "gulong",
31
+ "gsize",
32
+ "guintptr",
33
+ "gfloat",
34
+ "gdouble",
35
+ "gpointer",
36
+ "gconstpointer",
37
+ "utf8",
38
+ "filename",
39
+ "GType",
40
+ "GParamSpec",
41
+ "GVariant",
42
+ "int",
43
+ "uint",
44
+ "long",
45
+ "ulong",
46
+ "float",
47
+ "double",
48
+ "size_t",
49
+ "ssize_t",
50
+ ]);
51
+
52
+ /**
53
+ * Checks if a type name is an intrinsic (primitive) type.
54
+ *
55
+ * @param typeName - The type name to check
56
+ * @returns True if the type is intrinsic and should not be namespace-qualified
57
+ */
58
+ export const isIntrinsicType = (typeName: string): boolean => {
59
+ return INTRINSIC_TYPES.has(typeName);
60
+ };
61
+
62
+ /**
63
+ * String type names (utf8 and filename).
64
+ */
65
+ export const STRING_TYPES = new Set(["utf8", "filename"]);
66
+
67
+ /**
68
+ * Checks if a type name is a string type.
69
+ */
70
+ export const isStringType = (typeName: string): boolean => {
71
+ return STRING_TYPES.has(typeName);
72
+ };
73
+
74
+ /**
75
+ * Numeric type names (integers and floats).
76
+ */
77
+ export const NUMERIC_TYPES = new Set([
78
+ "gint",
79
+ "guint",
80
+ "gint8",
81
+ "guint8",
82
+ "gint16",
83
+ "guint16",
84
+ "gint32",
85
+ "guint32",
86
+ "gint64",
87
+ "guint64",
88
+ "gchar",
89
+ "guchar",
90
+ "gshort",
91
+ "gushort",
92
+ "glong",
93
+ "gulong",
94
+ "gsize",
95
+ "gssize",
96
+ "goffset",
97
+ "gintptr",
98
+ "guintptr",
99
+ "gfloat",
100
+ "gdouble",
101
+ "int",
102
+ "uint",
103
+ "long",
104
+ "ulong",
105
+ "float",
106
+ "double",
107
+ "size_t",
108
+ "ssize_t",
109
+ "GType",
110
+ ]);
111
+
112
+ /**
113
+ * Checks if a type name is a numeric type.
114
+ */
115
+ export const isNumericType = (typeName: string): boolean => {
116
+ return NUMERIC_TYPES.has(typeName);
117
+ };
118
+
119
+ /**
120
+ * Void type names.
121
+ */
122
+ export const VOID_TYPES = new Set(["void", "none"]);
123
+
124
+ /**
125
+ * Checks if a type name is void.
126
+ */
127
+ export const isVoidType = (typeName: string): boolean => {
128
+ return VOID_TYPES.has(typeName);
129
+ };