@gtkx/gir 0.10.5 → 0.11.1

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/dist/types.d.ts CHANGED
@@ -1,536 +1,570 @@
1
1
  /**
2
- * GIR type definitions and utilities.
2
+ * Normalized GIR types with helper methods.
3
3
  *
4
- * Provides TypeScript representations of GObject Introspection data
5
- * and utilities for type resolution and mapping.
6
- *
7
- * @packageDocumentation
8
- */
9
- import { toCamelCase, toPascalCase } from "./naming.js";
10
- export { toCamelCase, toPascalCase };
11
- /**
12
- * Represents a parsed GIR namespace (library).
13
- *
14
- * Contains all type definitions from a single GIR file, including
15
- * classes, interfaces, functions, enums, records, and callbacks.
16
- */
17
- export type GirNamespace = {
18
- name: string;
19
- version: string;
20
- sharedLibrary: string;
21
- cPrefix: string;
22
- classes: GirClass[];
23
- interfaces: GirInterface[];
24
- functions: GirFunction[];
25
- enumerations: GirEnumeration[];
26
- bitfields: GirEnumeration[];
27
- records: GirRecord[];
28
- callbacks: GirCallback[];
29
- constants: GirConstant[];
30
- doc?: string;
31
- };
32
- /**
33
- * A constant value defined in a GIR namespace.
4
+ * All type references use fully qualified names (Namespace.TypeName)
5
+ * except for intrinsic types which remain unqualified.
34
6
  */
35
- export type GirConstant = {
36
- name: string;
37
- cType: string;
38
- value: string;
39
- type: GirType;
40
- doc?: string;
41
- };
42
7
  /**
43
- * A callback type definition (function pointer type).
8
+ * A fully qualified type name.
9
+ * Always in the format "Namespace.TypeName" (e.g., "Gtk.Widget", "GLib.Variant").
10
+ * Intrinsic types like "gint" are NOT QualifiedNames.
44
11
  */
45
- export type GirCallback = {
46
- name: string;
47
- cType: string;
48
- returnType: GirType;
49
- parameters: GirParameter[];
50
- doc?: string;
12
+ export type QualifiedName = string & {
13
+ readonly __brand: "QualifiedName";
51
14
  };
52
15
  /**
53
- * A GObject interface definition.
54
- *
55
- * Interfaces in GObject are similar to TypeScript interfaces - they
56
- * define a contract that classes can implement.
16
+ * Creates a QualifiedName from namespace and type name.
57
17
  */
58
- export type GirInterface = {
59
- name: string;
60
- cType: string;
61
- glibTypeName?: string;
62
- prerequisites: string[];
63
- methods: GirMethod[];
64
- properties: GirProperty[];
65
- signals: GirSignal[];
66
- doc?: string;
67
- };
68
- /**
69
- * A GObject class definition.
70
- *
71
- * Classes are the primary building blocks of GObject-based libraries
72
- * like GTK. They support single inheritance, interface implementation,
73
- * properties, signals, and methods.
74
- */
75
- export type GirClass = {
76
- name: string;
77
- cType: string;
78
- parent?: string;
79
- abstract?: boolean;
80
- glibTypeName?: string;
81
- glibGetType?: string;
82
- cSymbolPrefix?: string;
83
- implements: string[];
84
- methods: GirMethod[];
85
- constructors: GirConstructor[];
86
- functions: GirFunction[];
87
- properties: GirProperty[];
88
- signals: GirSignal[];
89
- doc?: string;
90
- };
91
- /**
92
- * A GLib record (boxed type or struct).
93
- *
94
- * Records are value types that can be allocated on the stack or heap.
95
- * They may have fields, methods, and constructors but no inheritance.
96
- */
97
- export type GirRecord = {
98
- name: string;
99
- cType: string;
100
- opaque?: boolean;
101
- disguised?: boolean;
102
- glibTypeName?: string;
103
- glibGetType?: string;
104
- fields: GirField[];
105
- methods: GirMethod[];
106
- constructors: GirConstructor[];
107
- functions: GirFunction[];
108
- doc?: string;
109
- };
18
+ export declare const qualifiedName: (namespace: string, name: string) => QualifiedName;
110
19
  /**
111
- * A field within a record or class.
20
+ * Parses a QualifiedName into its parts.
112
21
  */
113
- export type GirField = {
22
+ export declare const parseQualifiedName: (qn: QualifiedName) => {
23
+ namespace: string;
114
24
  name: string;
115
- type: GirType;
116
- writable?: boolean;
117
- readable?: boolean;
118
- private?: boolean;
119
- doc?: string;
120
25
  };
121
26
  /**
122
- * A method on a class, interface, or record.
27
+ * The kind of a user-defined type (not intrinsic).
123
28
  */
124
- export type GirMethod = {
125
- name: string;
126
- cIdentifier: string;
127
- returnType: GirType;
128
- parameters: GirParameter[];
129
- throws?: boolean;
130
- doc?: string;
131
- returnDoc?: string;
132
- };
29
+ export type TypeKind = "class" | "interface" | "record" | "enum" | "flags" | "callback";
133
30
  /**
134
- * A constructor for a class or record.
31
+ * Container type discriminator for generic GLib containers.
135
32
  */
136
- export type GirConstructor = {
137
- name: string;
138
- cIdentifier: string;
139
- returnType: GirType;
140
- parameters: GirParameter[];
141
- throws?: boolean;
142
- doc?: string;
143
- returnDoc?: string;
33
+ export type ContainerType = "ghashtable" | "gptrarray" | "garray" | "glist" | "gslist";
34
+ type RepositoryLike = {
35
+ resolveClass(name: QualifiedName): GirClass | null;
36
+ resolveInterface(name: QualifiedName): GirInterface | null;
37
+ resolveRecord(name: QualifiedName): GirRecord | null;
38
+ resolveEnum(name: QualifiedName): GirEnumeration | null;
39
+ resolveFlags(name: QualifiedName): GirEnumeration | null;
40
+ resolveCallback(name: QualifiedName): GirCallback | null;
41
+ getTypeKind(name: QualifiedName): TypeKind | null;
42
+ findClasses(predicate: (cls: GirClass) => boolean): GirClass[];
144
43
  };
145
44
  /**
146
- * A standalone function or static method.
45
+ * Normalized namespace containing all resolved types.
147
46
  */
148
- export type GirFunction = {
149
- name: string;
150
- cIdentifier: string;
151
- returnType: GirType;
152
- parameters: GirParameter[];
153
- throws?: boolean;
154
- doc?: string;
155
- returnDoc?: string;
156
- };
47
+ export declare class GirNamespace {
48
+ readonly name: string;
49
+ readonly version: string;
50
+ readonly sharedLibrary: string;
51
+ readonly cPrefix: string;
52
+ readonly classes: Map<string, GirClass>;
53
+ readonly interfaces: Map<string, GirInterface>;
54
+ readonly records: Map<string, GirRecord>;
55
+ readonly enumerations: Map<string, GirEnumeration>;
56
+ readonly bitfields: Map<string, GirEnumeration>;
57
+ readonly callbacks: Map<string, GirCallback>;
58
+ readonly functions: Map<string, GirFunction>;
59
+ readonly constants: Map<string, GirConstant>;
60
+ readonly doc?: string;
61
+ constructor(data: {
62
+ name: string;
63
+ version: string;
64
+ sharedLibrary: string;
65
+ cPrefix: string;
66
+ classes: Map<string, GirClass>;
67
+ interfaces: Map<string, GirInterface>;
68
+ records: Map<string, GirRecord>;
69
+ enumerations: Map<string, GirEnumeration>;
70
+ bitfields: Map<string, GirEnumeration>;
71
+ callbacks: Map<string, GirCallback>;
72
+ functions: Map<string, GirFunction>;
73
+ constants: Map<string, GirConstant>;
74
+ doc?: string;
75
+ });
76
+ }
157
77
  /**
158
- * A parameter to a function, method, or callback.
159
- *
160
- * Includes direction (in/out/inout) and ownership transfer information
161
- * for proper memory management in generated bindings.
78
+ * Normalized class with helper methods.
162
79
  */
163
- export type GirParameter = {
164
- name: string;
165
- type: GirType;
166
- direction?: "in" | "out" | "inout";
167
- callerAllocates?: boolean;
168
- nullable?: boolean;
169
- optional?: boolean;
170
- scope?: "async" | "call" | "notified";
171
- closure?: number;
172
- destroy?: number;
173
- transferOwnership?: "none" | "full" | "container";
174
- doc?: string;
175
- };
80
+ export declare class GirClass {
81
+ readonly name: string;
82
+ readonly qualifiedName: QualifiedName;
83
+ readonly cType: string;
84
+ readonly parent: QualifiedName | null;
85
+ readonly abstract: boolean;
86
+ readonly glibTypeName?: string;
87
+ readonly glibGetType?: string;
88
+ readonly cSymbolPrefix?: string;
89
+ readonly implements: QualifiedName[];
90
+ readonly methods: GirMethod[];
91
+ readonly constructors: GirConstructor[];
92
+ readonly staticFunctions: GirFunction[];
93
+ readonly properties: GirProperty[];
94
+ readonly signals: GirSignal[];
95
+ readonly doc?: string;
96
+ /** @internal */
97
+ private _repo?;
98
+ constructor(data: {
99
+ name: string;
100
+ qualifiedName: QualifiedName;
101
+ cType: string;
102
+ parent: QualifiedName | null;
103
+ abstract: boolean;
104
+ glibTypeName?: string;
105
+ glibGetType?: string;
106
+ cSymbolPrefix?: string;
107
+ implements: QualifiedName[];
108
+ methods: GirMethod[];
109
+ constructors: GirConstructor[];
110
+ staticFunctions: GirFunction[];
111
+ properties: GirProperty[];
112
+ signals: GirSignal[];
113
+ doc?: string;
114
+ });
115
+ /** @internal */
116
+ _setRepository(repo: RepositoryLike): void;
117
+ /** Checks if this class is a subclass of another (direct or transitive). */
118
+ isSubclassOf(qualifiedName: QualifiedName): boolean;
119
+ /** Gets the full inheritance chain from this class to the root. */
120
+ getInheritanceChain(): QualifiedName[];
121
+ /** Gets the parent class object, or null if this is a root class. */
122
+ getParent(): GirClass | null;
123
+ /** Checks if this class directly or transitively implements an interface. */
124
+ implementsInterface(qualifiedName: QualifiedName): boolean;
125
+ /** Gets all implemented interfaces including inherited ones. */
126
+ getAllImplementedInterfaces(): QualifiedName[];
127
+ /** Finds a method defined on this class by name. */
128
+ getMethod(name: string): GirMethod | null;
129
+ /** Finds a property defined on this class by name. */
130
+ getProperty(name: string): GirProperty | null;
131
+ /** Finds a signal defined on this class by name. */
132
+ getSignal(name: string): GirSignal | null;
133
+ /** Finds a constructor by name. */
134
+ getConstructor(name: string): GirConstructor | null;
135
+ /** Gets all methods including inherited ones. */
136
+ getAllMethods(): GirMethod[];
137
+ /** Gets all properties including inherited ones. */
138
+ getAllProperties(): GirProperty[];
139
+ /** Gets all signals including inherited ones. */
140
+ getAllSignals(): GirSignal[];
141
+ /** Finds a method by name, searching up the inheritance chain. */
142
+ findMethod(name: string): GirMethod | null;
143
+ /** Finds a property by name, searching up the inheritance chain. */
144
+ findProperty(name: string): GirProperty | null;
145
+ /** Finds a signal by name, searching up the inheritance chain. */
146
+ findSignal(name: string): GirSignal | null;
147
+ /** True if this is an abstract class. */
148
+ isAbstract(): boolean;
149
+ /** True if this has a GType (most GObject classes do). */
150
+ hasGType(): boolean;
151
+ /** Gets direct subclasses of this class. */
152
+ getDirectSubclasses(): GirClass[];
153
+ }
176
154
  /**
177
- * A type reference in GIR.
178
- *
179
- * Can represent primitive types, objects, arrays, or boxed types.
180
- * Includes C type information and ownership semantics.
155
+ * Normalized interface with helper methods.
181
156
  */
182
- export type GirType = {
183
- name: string;
184
- cType?: string;
185
- isArray?: boolean;
186
- elementType?: GirType;
187
- transferOwnership?: "none" | "full" | "container";
188
- nullable?: boolean;
189
- };
157
+ export declare class GirInterface {
158
+ readonly name: string;
159
+ readonly qualifiedName: QualifiedName;
160
+ readonly cType: string;
161
+ readonly glibTypeName?: string;
162
+ readonly prerequisites: QualifiedName[];
163
+ readonly methods: GirMethod[];
164
+ readonly properties: GirProperty[];
165
+ readonly signals: GirSignal[];
166
+ readonly doc?: string;
167
+ /** @internal */
168
+ private _repo?;
169
+ constructor(data: {
170
+ name: string;
171
+ qualifiedName: QualifiedName;
172
+ cType: string;
173
+ glibTypeName?: string;
174
+ prerequisites: QualifiedName[];
175
+ methods: GirMethod[];
176
+ properties: GirProperty[];
177
+ signals: GirSignal[];
178
+ doc?: string;
179
+ });
180
+ /** @internal */
181
+ _setRepository(repo: RepositoryLike): void;
182
+ /** Checks if this interface has a prerequisite (direct or transitive). */
183
+ hasPrerequisite(qualifiedName: QualifiedName): boolean;
184
+ /** Gets all prerequisites including transitive ones. */
185
+ getAllPrerequisites(): QualifiedName[];
186
+ /** Finds a method by name. */
187
+ getMethod(name: string): GirMethod | null;
188
+ /** Finds a property by name. */
189
+ getProperty(name: string): GirProperty | null;
190
+ /** Finds a signal by name. */
191
+ getSignal(name: string): GirSignal | null;
192
+ }
190
193
  /**
191
- * A GObject property definition.
192
- *
193
- * Properties in GObject are observable values with getter/setter
194
- * methods and change notification support.
194
+ * Normalized record (boxed type or plain struct) with helper methods.
195
195
  */
196
- export type GirProperty = {
197
- name: string;
198
- type: GirType;
199
- readable?: boolean;
200
- writable?: boolean;
201
- constructOnly?: boolean;
202
- hasDefault?: boolean;
203
- getter?: string;
204
- setter?: string;
205
- doc?: string;
206
- };
196
+ export declare class GirRecord {
197
+ readonly name: string;
198
+ readonly qualifiedName: QualifiedName;
199
+ readonly cType: string;
200
+ readonly opaque: boolean;
201
+ readonly disguised: boolean;
202
+ readonly glibTypeName?: string;
203
+ readonly glibGetType?: string;
204
+ readonly isGtypeStructFor?: string;
205
+ readonly fields: GirField[];
206
+ readonly methods: GirMethod[];
207
+ readonly constructors: GirConstructor[];
208
+ readonly staticFunctions: GirFunction[];
209
+ readonly doc?: string;
210
+ constructor(data: {
211
+ name: string;
212
+ qualifiedName: QualifiedName;
213
+ cType: string;
214
+ opaque: boolean;
215
+ disguised: boolean;
216
+ glibTypeName?: string;
217
+ glibGetType?: string;
218
+ isGtypeStructFor?: string;
219
+ fields: GirField[];
220
+ methods: GirMethod[];
221
+ constructors: GirConstructor[];
222
+ staticFunctions: GirFunction[];
223
+ doc?: string;
224
+ });
225
+ /** True if this is a GLib boxed type (has glibTypeName). */
226
+ isBoxed(): boolean;
227
+ /** True if this is a GType struct (vtable for a class/interface). */
228
+ isGtypeStruct(): boolean;
229
+ /** True if this is a plain C struct (no GType, has public fields). */
230
+ isPlainStruct(): boolean;
231
+ /** Gets public (non-private) fields only. */
232
+ getPublicFields(): GirField[];
233
+ /** Finds a method by name. */
234
+ getMethod(name: string): GirMethod | null;
235
+ /** Finds a field by name. */
236
+ getField(name: string): GirField | null;
237
+ /** Finds a constructor by name. */
238
+ getConstructor(name: string): GirConstructor | null;
239
+ }
207
240
  /**
208
- * A GObject signal definition.
209
- *
210
- * Signals are the GObject event system, allowing objects to emit
211
- * notifications that handlers can connect to.
241
+ * Normalized enumeration with helper methods.
212
242
  */
213
- export type GirSignal = {
214
- name: string;
215
- when?: "first" | "last" | "cleanup";
216
- returnType?: GirType;
217
- parameters?: GirParameter[];
218
- doc?: string;
219
- };
243
+ export declare class GirEnumeration {
244
+ readonly name: string;
245
+ readonly qualifiedName: QualifiedName;
246
+ readonly cType: string;
247
+ readonly members: GirEnumerationMember[];
248
+ readonly doc?: string;
249
+ constructor(data: {
250
+ name: string;
251
+ qualifiedName: QualifiedName;
252
+ cType: string;
253
+ members: GirEnumerationMember[];
254
+ doc?: string;
255
+ });
256
+ /** Finds a member by name. */
257
+ getMember(name: string): GirEnumerationMember | null;
258
+ /** Finds a member by value. */
259
+ getMemberByValue(value: string): GirEnumerationMember | null;
260
+ /** Gets all member names. */
261
+ getMemberNames(): string[];
262
+ }
220
263
  /**
221
- * An enumeration or bitfield definition.
264
+ * Normalized enumeration member.
222
265
  */
223
- export type GirEnumeration = {
224
- name: string;
225
- cType: string;
226
- members: GirEnumerationMember[];
227
- doc?: string;
228
- };
266
+ export declare class GirEnumerationMember {
267
+ readonly name: string;
268
+ readonly value: string;
269
+ readonly cIdentifier: string;
270
+ readonly doc?: string;
271
+ constructor(data: {
272
+ name: string;
273
+ value: string;
274
+ cIdentifier: string;
275
+ doc?: string;
276
+ });
277
+ }
229
278
  /**
230
- * A member of an enumeration or bitfield.
279
+ * Normalized callback type.
231
280
  */
232
- export type GirEnumerationMember = {
233
- name: string;
234
- value: string;
235
- cIdentifier: string;
236
- doc?: string;
237
- };
281
+ export declare class GirCallback {
282
+ readonly name: string;
283
+ readonly qualifiedName: QualifiedName;
284
+ readonly cType: string;
285
+ readonly returnType: GirType;
286
+ readonly parameters: GirParameter[];
287
+ readonly doc?: string;
288
+ constructor(data: {
289
+ name: string;
290
+ qualifiedName: QualifiedName;
291
+ cType: string;
292
+ returnType: GirType;
293
+ parameters: GirParameter[];
294
+ doc?: string;
295
+ });
296
+ }
238
297
  /**
239
- * Describes how a type should be marshalled for FFI calls.
240
- *
241
- * Used by the code generator to create proper FFI type descriptors
242
- * for the native module.
298
+ * Normalized constant.
243
299
  */
244
- export type FfiTypeDescriptor = {
245
- /**
246
- * The FFI type: "int", "float", "string", "boolean", "boxed", "struct", "gobject", etc.
247
- */
248
- type: string;
249
- /**
250
- * Size in bits for numeric types, or bytes for struct types.
251
- */
252
- size?: number;
253
- unsigned?: boolean;
254
- borrowed?: boolean;
255
- innerType?: FfiTypeDescriptor | string;
256
- lib?: string;
257
- getTypeFn?: string;
258
- itemType?: FfiTypeDescriptor;
259
- listType?: "glist" | "gslist";
260
- trampoline?: "asyncReady" | "destroy" | "drawFunc" | "scaleFormatValueFunc" | "shortcutFunc" | "treeListModelCreateFunc";
261
- sourceType?: FfiTypeDescriptor;
262
- resultType?: FfiTypeDescriptor;
263
- argTypes?: FfiTypeDescriptor[];
264
- returnType?: FfiTypeDescriptor;
265
- optional?: boolean;
266
- };
300
+ export declare class GirConstant {
301
+ readonly name: string;
302
+ readonly qualifiedName: QualifiedName;
303
+ readonly cType: string;
304
+ readonly value: string;
305
+ readonly type: GirType;
306
+ readonly doc?: string;
307
+ constructor(data: {
308
+ name: string;
309
+ qualifiedName: QualifiedName;
310
+ cType: string;
311
+ value: string;
312
+ type: GirType;
313
+ doc?: string;
314
+ });
315
+ }
267
316
  /**
268
- * Builds a lookup map from class name to class definition.
269
- *
270
- * @param classes - Array of parsed GIR classes
271
- * @returns Map keyed by class name for O(1) lookup
317
+ * Normalized method with helper methods.
272
318
  */
273
- export declare const buildClassMap: (classes: GirClass[]) => Map<string, GirClass>;
319
+ export declare class GirMethod {
320
+ readonly name: string;
321
+ readonly cIdentifier: string;
322
+ readonly returnType: GirType;
323
+ readonly parameters: GirParameter[];
324
+ readonly throws: boolean;
325
+ readonly doc?: string;
326
+ readonly returnDoc?: string;
327
+ /** For async methods, the name of the corresponding finish function */
328
+ readonly finishFunc?: string;
329
+ constructor(data: {
330
+ name: string;
331
+ cIdentifier: string;
332
+ returnType: GirType;
333
+ parameters: GirParameter[];
334
+ throws: boolean;
335
+ doc?: string;
336
+ returnDoc?: string;
337
+ finishFunc?: string;
338
+ });
339
+ /** True if this follows the async/finish pattern. */
340
+ isAsync(): boolean;
341
+ /** True if this is a _finish method for an async operation. */
342
+ isAsyncFinish(): boolean;
343
+ /** Gets the corresponding _finish method name if this is async. */
344
+ getFinishMethodName(): string | null;
345
+ /** Gets required (non-optional, non-nullable) parameters. */
346
+ getRequiredParameters(): GirParameter[];
347
+ /** Gets optional parameters. */
348
+ getOptionalParameters(): GirParameter[];
349
+ /** True if any parameter is an out parameter. */
350
+ hasOutParameters(): boolean;
351
+ /** Gets out parameters only. */
352
+ getOutParameters(): GirParameter[];
353
+ }
274
354
  /**
275
- * Registers all enumerations and bitfields from a namespace into a type mapper.
276
- *
277
- * @param typeMapper - The type mapper to register enums with
278
- * @param namespace - The parsed GIR namespace containing enums
355
+ * Normalized constructor.
279
356
  */
280
- export declare const registerEnumsFromNamespace: (typeMapper: TypeMapper, namespace: GirNamespace) => void;
357
+ export declare class GirConstructor {
358
+ readonly name: string;
359
+ readonly cIdentifier: string;
360
+ readonly returnType: GirType;
361
+ readonly parameters: GirParameter[];
362
+ readonly throws: boolean;
363
+ readonly doc?: string;
364
+ readonly returnDoc?: string;
365
+ constructor(data: {
366
+ name: string;
367
+ cIdentifier: string;
368
+ returnType: GirType;
369
+ parameters: GirParameter[];
370
+ throws: boolean;
371
+ doc?: string;
372
+ returnDoc?: string;
373
+ });
374
+ /** Gets required (non-optional, non-nullable) parameters. */
375
+ getRequiredParameters(): GirParameter[];
376
+ }
281
377
  /**
282
- * The kind of a registered type.
378
+ * Normalized standalone function.
283
379
  */
284
- export type TypeKind = "class" | "interface" | "enum" | "flags" | "record" | "callback";
380
+ export declare class GirFunction {
381
+ readonly name: string;
382
+ readonly cIdentifier: string;
383
+ readonly returnType: GirType;
384
+ readonly parameters: GirParameter[];
385
+ readonly throws: boolean;
386
+ readonly doc?: string;
387
+ readonly returnDoc?: string;
388
+ constructor(data: {
389
+ name: string;
390
+ cIdentifier: string;
391
+ returnType: GirType;
392
+ parameters: GirParameter[];
393
+ throws: boolean;
394
+ doc?: string;
395
+ returnDoc?: string;
396
+ });
397
+ /** True if this follows the async/finish pattern. */
398
+ isAsync(): boolean;
399
+ /** Gets required parameters. */
400
+ getRequiredParameters(): GirParameter[];
401
+ }
285
402
  /**
286
- * A type registered in the type registry.
287
- *
288
- * Contains metadata about the type including its namespace,
289
- * original name, and transformed TypeScript name.
403
+ * Normalized parameter with helper methods.
290
404
  */
291
- export type RegisteredType = {
292
- kind: TypeKind;
293
- name: string;
294
- namespace: string;
295
- transformedName: string;
296
- glibTypeName?: string;
297
- sharedLibrary?: string;
298
- glibGetType?: string;
299
- /**
300
- * If true, this is a plain C struct without GType registration.
301
- * These require different FFI handling than boxed types.
302
- */
303
- isPlainStruct?: boolean;
304
- /**
305
- * Size in bytes for plain structs (for allocation).
306
- */
307
- structSize?: number;
308
- /**
309
- * Field definitions for plain structs.
310
- */
311
- structFields?: Array<{
405
+ export declare class GirParameter {
406
+ readonly name: string;
407
+ readonly type: GirType;
408
+ readonly direction: "in" | "out" | "inout";
409
+ readonly callerAllocates: boolean;
410
+ readonly nullable: boolean;
411
+ readonly optional: boolean;
412
+ readonly scope?: "async" | "call" | "notified";
413
+ readonly closure?: number;
414
+ readonly destroy?: number;
415
+ readonly transferOwnership?: "none" | "full" | "container";
416
+ readonly doc?: string;
417
+ constructor(data: {
312
418
  name: string;
313
- offset: number;
314
- type: string;
315
- }>;
316
- };
419
+ type: GirType;
420
+ direction: "in" | "out" | "inout";
421
+ callerAllocates: boolean;
422
+ nullable: boolean;
423
+ optional: boolean;
424
+ scope?: "async" | "call" | "notified";
425
+ closure?: number;
426
+ destroy?: number;
427
+ transferOwnership?: "none" | "full" | "container";
428
+ doc?: string;
429
+ });
430
+ /** True if this is an input parameter. */
431
+ isIn(): boolean;
432
+ /** True if this is an output parameter. */
433
+ isOut(): boolean;
434
+ /** True if this is a callback parameter (has scope). */
435
+ isCallback(): boolean;
436
+ /** True if this is the user_data for a callback. */
437
+ isClosureData(): boolean;
438
+ /** True if this is a destroy notify for a callback. */
439
+ isDestroyNotify(): boolean;
440
+ /** True if caller must allocate memory for this out param. */
441
+ requiresCallerAllocation(): boolean;
442
+ }
317
443
  /**
318
- * Registry for resolving types across multiple GIR namespaces.
319
- *
320
- * Enables cross-namespace type resolution by maintaining a map of
321
- * all known types from all loaded namespaces.
322
- *
323
- * @example
324
- * ```tsx
325
- * const registry = TypeRegistry.fromNamespaces([gtkNamespace, gioNamespace]);
326
- * const buttonType = registry.resolve("Gtk.Button");
327
- * ```
444
+ * Normalized property with helper methods.
328
445
  */
329
- export declare class TypeRegistry {
330
- private types;
331
- /**
332
- * Registers a native class type.
333
- *
334
- * @param namespace - The GIR namespace (e.g., "Gtk")
335
- * @param name - The class name (e.g., "Button")
336
- */
337
- registerNativeClass(namespace: string, name: string): void;
338
- /**
339
- * Registers an interface type.
340
- *
341
- * @param namespace - The GIR namespace
342
- * @param name - The interface name
343
- */
344
- registerInterface(namespace: string, name: string): void;
345
- /**
346
- * Registers an enumeration type.
347
- *
348
- * @param namespace - The GIR namespace
349
- * @param name - The enum name
350
- */
351
- registerEnum(namespace: string, name: string): void;
352
- /**
353
- * Registers a flags (bitfield) type.
354
- *
355
- * @param namespace - The GIR namespace
356
- * @param name - The flags name
357
- */
358
- registerFlags(namespace: string, name: string): void;
359
- /**
360
- * Registers a record (boxed) type.
361
- *
362
- * @param namespace - The GIR namespace
363
- * @param name - The record name
364
- * @param glibTypeName - Optional GLib type name for runtime type info
365
- * @param sharedLibrary - Optional shared library containing the type
366
- * @param glibGetType - Optional get_type function name
367
- * @param isPlainStruct - If true, this is a plain C struct without GType
368
- * @param structSize - Size in bytes for plain structs
369
- * @param structFields - Field definitions for plain structs
370
- */
371
- registerRecord(namespace: string, name: string, glibTypeName?: string, sharedLibrary?: string, glibGetType?: string, isPlainStruct?: boolean, structSize?: number, structFields?: Array<{
446
+ export declare class GirProperty {
447
+ readonly name: string;
448
+ readonly type: GirType;
449
+ readonly readable: boolean;
450
+ readonly writable: boolean;
451
+ readonly constructOnly: boolean;
452
+ readonly hasDefault: boolean;
453
+ readonly getter?: string;
454
+ readonly setter?: string;
455
+ readonly doc?: string;
456
+ constructor(data: {
372
457
  name: string;
373
- offset: number;
374
- type: string;
375
- }>): void;
376
- /**
377
- * Registers a callback type.
378
- *
379
- * @param namespace - The GIR namespace
380
- * @param name - The callback name
381
- */
382
- registerCallback(namespace: string, name: string): void;
383
- /**
384
- * Resolves a fully qualified type name.
385
- *
386
- * @param qualifiedName - Type name in "Namespace.TypeName" format
387
- * @returns The registered type, or undefined if not found
388
- */
389
- resolve(qualifiedName: string): RegisteredType | undefined;
390
- /**
391
- * Resolves a type name within a namespace context.
392
- *
393
- * First checks the current namespace, then falls back to
394
- * searching all registered types.
395
- *
396
- * @param name - Type name (may be unqualified)
397
- * @param currentNamespace - The namespace to search first
398
- * @returns The registered type, or undefined if not found
399
- */
400
- resolveInNamespace(name: string, currentNamespace: string): RegisteredType | undefined;
401
- /**
402
- * Creates a type registry from multiple parsed namespaces.
403
- *
404
- * @param namespaces - Array of parsed GIR namespaces
405
- * @returns A populated type registry
406
- *
407
- * @example
408
- * ```tsx
409
- * const parser = new GirParser();
410
- * const gtk = parser.parse(gtkGir);
411
- * const gio = parser.parse(gioGir);
412
- * const registry = TypeRegistry.fromNamespaces([gtk, gio]);
413
- * ```
414
- */
415
- static fromNamespaces(namespaces: GirNamespace[]): TypeRegistry;
458
+ type: GirType;
459
+ readable: boolean;
460
+ writable: boolean;
461
+ constructOnly: boolean;
462
+ hasDefault: boolean;
463
+ getter?: string;
464
+ setter?: string;
465
+ doc?: string;
466
+ });
467
+ /** True if readable but not writable. */
468
+ isReadOnly(): boolean;
469
+ /** True if writable but not readable. */
470
+ isWriteOnly(): boolean;
471
+ /** True if can only be set during construction. */
472
+ isConstructOnly(): boolean;
473
+ /** True if has both getter and setter methods. */
474
+ hasAccessors(): boolean;
416
475
  }
417
476
  /**
418
- * Describes usage of a type from another namespace.
419
- *
420
- * Used to track import dependencies during code generation.
477
+ * Normalized signal with helper methods.
421
478
  */
422
- export type ExternalTypeUsage = {
423
- namespace: string;
424
- name: string;
425
- transformedName: string;
426
- kind: TypeKind;
427
- };
479
+ export declare class GirSignal {
480
+ readonly name: string;
481
+ readonly when: "first" | "last" | "cleanup";
482
+ readonly returnType: GirType | null;
483
+ readonly parameters: GirParameter[];
484
+ readonly doc?: string;
485
+ constructor(data: {
486
+ name: string;
487
+ when: "first" | "last" | "cleanup";
488
+ returnType: GirType | null;
489
+ parameters: GirParameter[];
490
+ doc?: string;
491
+ });
492
+ /** True if the signal returns a value. */
493
+ hasReturnValue(): boolean;
494
+ }
428
495
  /**
429
- * Result of mapping a GIR type to TypeScript and FFI representations.
496
+ * Normalized field.
430
497
  */
431
- export type MappedType = {
432
- ts: string;
433
- ffi: FfiTypeDescriptor;
434
- externalType?: ExternalTypeUsage;
435
- kind?: TypeKind;
436
- nullable?: boolean;
437
- };
498
+ export declare class GirField {
499
+ readonly name: string;
500
+ readonly type: GirType;
501
+ readonly writable: boolean;
502
+ readonly readable: boolean;
503
+ readonly private: boolean;
504
+ readonly doc?: string;
505
+ constructor(data: {
506
+ name: string;
507
+ type: GirType;
508
+ writable: boolean;
509
+ readable: boolean;
510
+ private: boolean;
511
+ doc?: string;
512
+ });
513
+ }
438
514
  /**
439
- * Maps GIR types to TypeScript and FFI type representations.
440
- *
441
- * Handles conversion of GIR type information into:
442
- * - TypeScript type strings for generated declarations
443
- * - FFI type descriptors for runtime marshalling
444
- *
445
- * Supports callbacks for tracking type usage dependencies.
446
- *
447
- * @example
448
- * ```tsx
449
- * const mapper = new TypeMapper();
450
- * mapper.registerEnum("Orientation", "Orientation");
451
- * mapper.setTypeRegistry(registry, "Gtk");
452
- *
453
- * const result = mapper.mapType({ name: "utf8" });
454
- * // { ts: "string", ffi: { type: "string", borrowed: false } }
455
- * ```
515
+ * Normalized type reference with helper methods.
456
516
  */
457
- export declare class TypeMapper {
458
- private enumNames;
459
- private enumTransforms;
460
- private flagsNames;
461
- private flagsTransforms;
462
- private recordNames;
463
- private recordTransforms;
464
- private recordGlibTypes;
465
- private skippedClasses;
466
- private onEnumUsed?;
467
- private onRecordUsed?;
468
- private onExternalTypeUsed?;
469
- private onSameNamespaceClassUsed?;
470
- private typeRegistry?;
471
- private currentNamespace?;
472
- private forceExternalNamespace?;
473
- /**
474
- * Registers an enumeration for type mapping.
475
- *
476
- * @param originalName - The GIR enum name
477
- * @param transformedName - Optional transformed TypeScript name
478
- */
479
- registerEnum(originalName: string, transformedName?: string): void;
480
- /**
481
- * Registers a flags (bitfield) type for type mapping.
482
- *
483
- * @param originalName - The GIR flags name
484
- * @param transformedName - Optional transformed TypeScript name
485
- */
486
- registerFlags(originalName: string, transformedName?: string): void;
487
- /**
488
- * Registers a record for type mapping.
489
- *
490
- * @param originalName - The GIR record name
491
- * @param transformedName - Optional transformed TypeScript name
492
- * @param glibTypeName - Optional GLib type name for boxed type marshalling
493
- */
494
- registerRecord(originalName: string, transformedName?: string, glibTypeName?: string): void;
495
- setEnumUsageCallback(callback: ((enumName: string) => void) | null): void;
496
- getEnumUsageCallback(): ((enumName: string) => void) | null;
497
- setRecordUsageCallback(callback: ((recordName: string) => void) | null): void;
498
- getRecordUsageCallback(): ((recordName: string) => void) | null;
499
- setExternalTypeUsageCallback(callback: ((usage: ExternalTypeUsage) => void) | null): void;
500
- getExternalTypeUsageCallback(): ((usage: ExternalTypeUsage) => void) | null;
501
- setSameNamespaceClassUsageCallback(callback: ((className: string, originalName: string) => void) | null): void;
502
- getSameNamespaceClassUsageCallback(): ((className: string, originalName: string) => void) | null;
503
- /**
504
- * Sets the type registry for cross-namespace type resolution.
505
- *
506
- * @param registry - The type registry to use
507
- * @param currentNamespace - The current namespace being processed
508
- */
509
- setTypeRegistry(registry: TypeRegistry, currentNamespace: string): void;
510
- setForceExternalNamespace(namespace: string | null): void;
511
- registerSkippedClass(name: string): void;
512
- clearSkippedClasses(): void;
513
- /**
514
- * Maps a GIR type to TypeScript and FFI representations.
515
- *
516
- * @param girType - The GIR type to map
517
- * @param isReturn - Whether this is a return type (affects ownership)
518
- * @param parentTransferOwnership - Transfer ownership from parent (used for array elements)
519
- * @returns The mapped type with TypeScript and FFI descriptors
520
- */
521
- mapType(girType: GirType, isReturn?: boolean, parentTransferOwnership?: string): MappedType;
522
- isCallback(typeName: string): boolean;
523
- /**
524
- * Maps a function parameter to TypeScript and FFI representations.
525
- *
526
- * Handles special cases like out parameters, callbacks, and
527
- * ownership transfer.
528
- *
529
- * @param param - The GIR parameter to map
530
- * @returns The mapped type with TypeScript and FFI descriptors
531
- */
532
- mapParameter(param: GirParameter): MappedType;
533
- isClosureTarget(paramIndex: number, allParams: GirParameter[]): boolean;
534
- isNullable(param: GirParameter): boolean;
535
- hasUnsupportedCallback(param: GirParameter): boolean;
517
+ export declare class GirType {
518
+ /** Type name - either a QualifiedName or an intrinsic type string */
519
+ readonly name: QualifiedName | string;
520
+ readonly cType?: string;
521
+ readonly isArray: boolean;
522
+ readonly elementType: GirType | null;
523
+ readonly typeParameters: readonly GirType[];
524
+ readonly containerType?: ContainerType;
525
+ readonly transferOwnership?: "none" | "full" | "container";
526
+ readonly nullable: boolean;
527
+ constructor(data: {
528
+ name: QualifiedName | string;
529
+ cType?: string;
530
+ isArray: boolean;
531
+ elementType: GirType | null;
532
+ typeParameters?: readonly GirType[];
533
+ containerType?: ContainerType;
534
+ transferOwnership?: "none" | "full" | "container";
535
+ nullable: boolean;
536
+ });
537
+ /** True if this is an intrinsic/primitive type. */
538
+ isIntrinsic(): boolean;
539
+ /** True if this is a string type (utf8 or filename). */
540
+ isString(): boolean;
541
+ /** True if this is a numeric type. */
542
+ isNumeric(): boolean;
543
+ /** True if this is a boolean type. */
544
+ isBoolean(): boolean;
545
+ /** True if this is void. */
546
+ isVoid(): boolean;
547
+ /** True if this is GVariant. */
548
+ isVariant(): boolean;
549
+ /** True if this is GParamSpec. */
550
+ isParamSpec(): boolean;
551
+ /** True if this is a GHashTable container. */
552
+ isHashTable(): boolean;
553
+ /** True if this is a GPtrArray container. */
554
+ isPtrArray(): boolean;
555
+ /** True if this is a GArray container. */
556
+ isGArray(): boolean;
557
+ /** True if this is a GList or GSList container. */
558
+ isList(): boolean;
559
+ /** True if this is any generic container type. */
560
+ isGenericContainer(): boolean;
561
+ /** Gets the key type for GHashTable, or null for other types. */
562
+ getKeyType(): GirType | null;
563
+ /** Gets the value type for GHashTable, or null for other types. */
564
+ getValueType(): GirType | null;
565
+ /** Gets the namespace part of a qualified name, or null for intrinsics. */
566
+ getNamespace(): string | null;
567
+ /** Gets the simple name part (without namespace). */
568
+ getSimpleName(): string;
536
569
  }
570
+ export {};