@gtkx/gir 0.6.0 → 0.7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gtkx/gir",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "GObject Introspection file parser for GTKX",
5
5
  "keywords": [
6
6
  "gtk",
package/src/parser.ts CHANGED
@@ -2,6 +2,7 @@ import { XMLParser } from "fast-xml-parser";
2
2
  import type {
3
3
  GirCallback,
4
4
  GirClass,
5
+ GirConstant,
5
6
  GirConstructor,
6
7
  GirEnumeration,
7
8
  GirEnumerationMember,
@@ -25,6 +26,7 @@ const ARRAY_ELEMENT_PATHS = new Set<string>([
25
26
  "namespace.bitfield",
26
27
  "namespace.record",
27
28
  "namespace.callback",
29
+ "namespace.constant",
28
30
  "namespace.class.method",
29
31
  "namespace.class.constructor",
30
32
  "namespace.class.function",
@@ -113,6 +115,7 @@ export class GirParser {
113
115
  bitfields: this.parseEnumerations(namespace.bitfield ?? []),
114
116
  records: this.parseRecords(namespace.record ?? []),
115
117
  callbacks: this.parseCallbacks(namespace.callback ?? []),
118
+ constants: this.parseConstants(namespace.constant ?? []),
116
119
  };
117
120
  }
118
121
 
@@ -425,4 +428,17 @@ export class GirParser {
425
428
  doc: extractDoc(member),
426
429
  }));
427
430
  }
431
+
432
+ private parseConstants(constants: Record<string, unknown>[]): GirConstant[] {
433
+ if (!constants || !Array.isArray(constants)) {
434
+ return [];
435
+ }
436
+ return constants.map((constant) => ({
437
+ name: String(constant["@_name"] ?? ""),
438
+ cType: String(constant["@_c:type"] ?? ""),
439
+ value: String(constant["@_value"] ?? ""),
440
+ type: this.parseType((constant.type ?? constant.array) as Record<string, unknown> | undefined),
441
+ doc: extractDoc(constant),
442
+ }));
443
+ }
428
444
  }
package/src/types.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Represents a parsed GIR namespace containing all type definitions.
3
3
  */
4
- export interface GirNamespace {
4
+ export type GirNamespace = {
5
5
  /** The namespace name (e.g., "Gtk", "Gio"). */
6
6
  name: string;
7
7
  /** The namespace version (e.g., "4.0"). */
@@ -24,14 +24,32 @@ export interface GirNamespace {
24
24
  records: GirRecord[];
25
25
  /** All callback types defined in this namespace. */
26
26
  callbacks: GirCallback[];
27
+ /** All constants defined in this namespace. */
28
+ constants: GirConstant[];
27
29
  /** Documentation for the namespace. */
28
30
  doc?: string;
29
- }
31
+ };
32
+
33
+ /**
34
+ * Represents a GIR constant definition.
35
+ */
36
+ export type GirConstant = {
37
+ /** The constant name. */
38
+ name: string;
39
+ /** The C type name. */
40
+ cType: string;
41
+ /** The constant value (as a string, may be numeric or string literal). */
42
+ value: string;
43
+ /** The type of the constant value. */
44
+ type: GirType;
45
+ /** Documentation for the constant. */
46
+ doc?: string;
47
+ };
30
48
 
31
49
  /**
32
50
  * Represents a GIR callback type definition.
33
51
  */
34
- export interface GirCallback {
52
+ export type GirCallback = {
35
53
  /** The callback name. */
36
54
  name: string;
37
55
  /** The C type name. */
@@ -42,12 +60,12 @@ export interface GirCallback {
42
60
  parameters: GirParameter[];
43
61
  /** Documentation for the callback. */
44
62
  doc?: string;
45
- }
63
+ };
46
64
 
47
65
  /**
48
66
  * Represents a GIR interface definition.
49
67
  */
50
- export interface GirInterface {
68
+ export type GirInterface = {
51
69
  /** The interface name. */
52
70
  name: string;
53
71
  /** The C type name. */
@@ -62,12 +80,12 @@ export interface GirInterface {
62
80
  signals: GirSignal[];
63
81
  /** Documentation for the interface. */
64
82
  doc?: string;
65
- }
83
+ };
66
84
 
67
85
  /**
68
86
  * Represents a GIR class definition.
69
87
  */
70
- export interface GirClass {
88
+ export type GirClass = {
71
89
  /** The class name. */
72
90
  name: string;
73
91
  /** The C type name. */
@@ -96,12 +114,12 @@ export interface GirClass {
96
114
  signals: GirSignal[];
97
115
  /** Documentation for the class. */
98
116
  doc?: string;
99
- }
117
+ };
100
118
 
101
119
  /**
102
120
  * Represents a GIR record (struct) definition.
103
121
  */
104
- export interface GirRecord {
122
+ export type GirRecord = {
105
123
  /** The record name. */
106
124
  name: string;
107
125
  /** The C type name. */
@@ -124,12 +142,12 @@ export interface GirRecord {
124
142
  functions: GirFunction[];
125
143
  /** Documentation for the record. */
126
144
  doc?: string;
127
- }
145
+ };
128
146
 
129
147
  /**
130
148
  * Represents a GIR field definition in a record.
131
149
  */
132
- export interface GirField {
150
+ export type GirField = {
133
151
  /** The field name. */
134
152
  name: string;
135
153
  /** The field type. */
@@ -142,12 +160,12 @@ export interface GirField {
142
160
  private?: boolean;
143
161
  /** Documentation for the field. */
144
162
  doc?: string;
145
- }
163
+ };
146
164
 
147
165
  /**
148
166
  * Represents a GIR method definition.
149
167
  */
150
- export interface GirMethod {
168
+ export type GirMethod = {
151
169
  /** The method name. */
152
170
  name: string;
153
171
  /** The C function identifier. */
@@ -160,12 +178,12 @@ export interface GirMethod {
160
178
  throws?: boolean;
161
179
  /** Documentation for the method. */
162
180
  doc?: string;
163
- }
181
+ };
164
182
 
165
183
  /**
166
184
  * Represents a GIR constructor definition.
167
185
  */
168
- export interface GirConstructor {
186
+ export type GirConstructor = {
169
187
  /** The constructor name. */
170
188
  name: string;
171
189
  /** The C function identifier. */
@@ -178,12 +196,12 @@ export interface GirConstructor {
178
196
  throws?: boolean;
179
197
  /** Documentation for the constructor. */
180
198
  doc?: string;
181
- }
199
+ };
182
200
 
183
201
  /**
184
202
  * Represents a GIR standalone function definition.
185
203
  */
186
- export interface GirFunction {
204
+ export type GirFunction = {
187
205
  /** The function name. */
188
206
  name: string;
189
207
  /** The C function identifier. */
@@ -196,12 +214,12 @@ export interface GirFunction {
196
214
  throws?: boolean;
197
215
  /** Documentation for the function. */
198
216
  doc?: string;
199
- }
217
+ };
200
218
 
201
219
  /**
202
220
  * Represents a GIR parameter definition.
203
221
  */
204
- export interface GirParameter {
222
+ export type GirParameter = {
205
223
  /** The parameter name. */
206
224
  name: string;
207
225
  /** The parameter type. */
@@ -224,12 +242,12 @@ export interface GirParameter {
224
242
  transferOwnership?: "none" | "full" | "container";
225
243
  /** Documentation for the parameter. */
226
244
  doc?: string;
227
- }
245
+ };
228
246
 
229
247
  /**
230
248
  * Represents a GIR type reference.
231
249
  */
232
- export interface GirType {
250
+ export type GirType = {
233
251
  /** The type name. */
234
252
  name: string;
235
253
  /** The C type name. */
@@ -242,12 +260,12 @@ export interface GirType {
242
260
  transferOwnership?: "none" | "full" | "container";
243
261
  /** Whether this type can be null (for return types). */
244
262
  nullable?: boolean;
245
- }
263
+ };
246
264
 
247
265
  /**
248
266
  * Represents a GIR property definition.
249
267
  */
250
- export interface GirProperty {
268
+ export type GirProperty = {
251
269
  /** The property name. */
252
270
  name: string;
253
271
  /** The property type. */
@@ -266,12 +284,12 @@ export interface GirProperty {
266
284
  setter?: string;
267
285
  /** Documentation for the property. */
268
286
  doc?: string;
269
- }
287
+ };
270
288
 
271
289
  /**
272
290
  * Represents a GIR signal definition.
273
291
  */
274
- export interface GirSignal {
292
+ export type GirSignal = {
275
293
  /** The signal name. */
276
294
  name: string;
277
295
  /** When the signal handler runs relative to the default handler. */
@@ -282,12 +300,12 @@ export interface GirSignal {
282
300
  parameters?: GirParameter[];
283
301
  /** Documentation for the signal. */
284
302
  doc?: string;
285
- }
303
+ };
286
304
 
287
305
  /**
288
306
  * Represents a GIR enumeration or bitfield definition.
289
307
  */
290
- export interface GirEnumeration {
308
+ export type GirEnumeration = {
291
309
  /** The enumeration name. */
292
310
  name: string;
293
311
  /** The C type name. */
@@ -296,12 +314,12 @@ export interface GirEnumeration {
296
314
  members: GirEnumerationMember[];
297
315
  /** Documentation for the enumeration. */
298
316
  doc?: string;
299
- }
317
+ };
300
318
 
301
319
  /**
302
320
  * Represents a single enumeration member.
303
321
  */
304
- export interface GirEnumerationMember {
322
+ export type GirEnumerationMember = {
305
323
  /** The member name. */
306
324
  name: string;
307
325
  /** The numeric value. */
@@ -310,12 +328,12 @@ export interface GirEnumerationMember {
310
328
  cIdentifier: string;
311
329
  /** Documentation for the member. */
312
330
  doc?: string;
313
- }
331
+ };
314
332
 
315
333
  /**
316
334
  * Describes an FFI type for code generation.
317
335
  */
318
- export interface FfiTypeDescriptor {
336
+ export type FfiTypeDescriptor = {
319
337
  /** The FFI type category. */
320
338
  type: string;
321
339
  /** Size in bits for integer/float types. */
@@ -340,7 +358,7 @@ export interface FfiTypeDescriptor {
340
358
  argTypes?: FfiTypeDescriptor[];
341
359
  /** Whether this argument is optional (can be null/undefined for pointer types). */
342
360
  optional?: boolean;
343
- }
361
+ };
344
362
 
345
363
  /**
346
364
  * Converts a snake_case or kebab-case string to camelCase.
@@ -390,13 +408,13 @@ type TypeMapping = { ts: string; ffi: FfiTypeDescriptor };
390
408
 
391
409
  export type TypeKind = "class" | "interface" | "enum" | "record" | "callback";
392
410
 
393
- export interface RegisteredType {
411
+ export type RegisteredType = {
394
412
  kind: TypeKind;
395
413
  name: string;
396
414
  namespace: string;
397
415
  transformedName: string;
398
416
  glibTypeName?: string;
399
- }
417
+ };
400
418
 
401
419
  const CLASS_RENAMES = new Map<string, string>([["Error", "GError"]]);
402
420
 
@@ -441,7 +459,7 @@ export class TypeRegistry {
441
459
  registerInterface(namespace: string, name: string): void {
442
460
  const transformedName = normalizeTypeName(name, namespace);
443
461
  this.types.set(`${namespace}.${name}`, {
444
- kind: "class",
462
+ kind: "interface",
445
463
  name,
446
464
  namespace,
447
465
  transformedName,
@@ -684,20 +702,20 @@ const BASIC_TYPE_MAP = new Map<string, TypeMapping>([
684
702
  ["FreeFunc", { ts: "number", ffi: { type: "int", size: 64, unsigned: true } }],
685
703
  ]);
686
704
 
687
- export interface ExternalTypeUsage {
705
+ export type ExternalTypeUsage = {
688
706
  namespace: string;
689
707
  name: string;
690
708
  transformedName: string;
691
709
  kind: TypeKind;
692
- }
710
+ };
693
711
 
694
- export interface MappedType {
712
+ export type MappedType = {
695
713
  ts: string;
696
714
  ffi: FfiTypeDescriptor;
697
715
  externalType?: ExternalTypeUsage;
698
716
  kind?: TypeKind;
699
717
  nullable?: boolean;
700
- }
718
+ };
701
719
 
702
720
  /**
703
721
  * Maps GIR types to TypeScript types and FFI type descriptors.