@gtkx/gir 0.1.21 → 0.1.23
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 +1 -1
- package/src/types.ts +51 -0
package/package.json
CHANGED
package/src/types.ts
CHANGED
|
@@ -400,9 +400,18 @@ const normalizeTypeName = (name: string): string => {
|
|
|
400
400
|
return CLASS_RENAMES.get(pascalName) ?? pascalName;
|
|
401
401
|
};
|
|
402
402
|
|
|
403
|
+
/**
|
|
404
|
+
* Registry for tracking all types across GIR namespaces.
|
|
405
|
+
* Used for cross-namespace type resolution during code generation.
|
|
406
|
+
*/
|
|
403
407
|
export class TypeRegistry {
|
|
404
408
|
private types = new Map<string, RegisteredType>();
|
|
405
409
|
|
|
410
|
+
/**
|
|
411
|
+
* Registers a class type.
|
|
412
|
+
* @param namespace - The namespace containing the class
|
|
413
|
+
* @param name - The class name
|
|
414
|
+
*/
|
|
406
415
|
registerClass(namespace: string, name: string): void {
|
|
407
416
|
const transformedName = normalizeTypeName(name);
|
|
408
417
|
this.types.set(`${namespace}.${name}`, {
|
|
@@ -413,6 +422,11 @@ export class TypeRegistry {
|
|
|
413
422
|
});
|
|
414
423
|
}
|
|
415
424
|
|
|
425
|
+
/**
|
|
426
|
+
* Registers an interface type.
|
|
427
|
+
* @param namespace - The namespace containing the interface
|
|
428
|
+
* @param name - The interface name
|
|
429
|
+
*/
|
|
416
430
|
registerInterface(namespace: string, name: string): void {
|
|
417
431
|
const transformedName = normalizeTypeName(name);
|
|
418
432
|
this.types.set(`${namespace}.${name}`, {
|
|
@@ -423,6 +437,11 @@ export class TypeRegistry {
|
|
|
423
437
|
});
|
|
424
438
|
}
|
|
425
439
|
|
|
440
|
+
/**
|
|
441
|
+
* Registers an enumeration type.
|
|
442
|
+
* @param namespace - The namespace containing the enum
|
|
443
|
+
* @param name - The enum name
|
|
444
|
+
*/
|
|
426
445
|
registerEnum(namespace: string, name: string): void {
|
|
427
446
|
const transformedName = toPascalCase(name);
|
|
428
447
|
this.types.set(`${namespace}.${name}`, {
|
|
@@ -433,6 +452,12 @@ export class TypeRegistry {
|
|
|
433
452
|
});
|
|
434
453
|
}
|
|
435
454
|
|
|
455
|
+
/**
|
|
456
|
+
* Registers a record (struct) type.
|
|
457
|
+
* @param namespace - The namespace containing the record
|
|
458
|
+
* @param name - The record name
|
|
459
|
+
* @param glibTypeName - Optional GLib type name for boxed type handling
|
|
460
|
+
*/
|
|
436
461
|
registerRecord(namespace: string, name: string, glibTypeName?: string): void {
|
|
437
462
|
const transformedName = normalizeTypeName(name);
|
|
438
463
|
this.types.set(`${namespace}.${name}`, {
|
|
@@ -444,6 +469,11 @@ export class TypeRegistry {
|
|
|
444
469
|
});
|
|
445
470
|
}
|
|
446
471
|
|
|
472
|
+
/**
|
|
473
|
+
* Registers a callback type.
|
|
474
|
+
* @param namespace - The namespace containing the callback
|
|
475
|
+
* @param name - The callback name
|
|
476
|
+
*/
|
|
447
477
|
registerCallback(namespace: string, name: string): void {
|
|
448
478
|
const transformedName = toPascalCase(name);
|
|
449
479
|
this.types.set(`${namespace}.${name}`, {
|
|
@@ -454,10 +484,21 @@ export class TypeRegistry {
|
|
|
454
484
|
});
|
|
455
485
|
}
|
|
456
486
|
|
|
487
|
+
/**
|
|
488
|
+
* Resolves a type by its fully qualified name (Namespace.TypeName).
|
|
489
|
+
* @param qualifiedName - The fully qualified type name
|
|
490
|
+
* @returns The registered type or undefined if not found
|
|
491
|
+
*/
|
|
457
492
|
resolve(qualifiedName: string): RegisteredType | undefined {
|
|
458
493
|
return this.types.get(qualifiedName);
|
|
459
494
|
}
|
|
460
495
|
|
|
496
|
+
/**
|
|
497
|
+
* Resolves a type name within a namespace context.
|
|
498
|
+
* @param name - The type name (may or may not be qualified)
|
|
499
|
+
* @param currentNamespace - The namespace to use if name is not qualified
|
|
500
|
+
* @returns The registered type or undefined if not found
|
|
501
|
+
*/
|
|
461
502
|
resolveInNamespace(name: string, currentNamespace: string): RegisteredType | undefined {
|
|
462
503
|
if (name.includes(".")) {
|
|
463
504
|
return this.resolve(name);
|
|
@@ -465,6 +506,11 @@ export class TypeRegistry {
|
|
|
465
506
|
return this.resolve(`${currentNamespace}.${name}`);
|
|
466
507
|
}
|
|
467
508
|
|
|
509
|
+
/**
|
|
510
|
+
* Creates a TypeRegistry populated with all types from the given namespaces.
|
|
511
|
+
* @param namespaces - Array of GIR namespaces to register
|
|
512
|
+
* @returns A new TypeRegistry containing all types
|
|
513
|
+
*/
|
|
468
514
|
static fromNamespaces(namespaces: GirNamespace[]): TypeRegistry {
|
|
469
515
|
const registry = new TypeRegistry();
|
|
470
516
|
for (const ns of namespaces) {
|
|
@@ -917,6 +963,11 @@ export class TypeMapper {
|
|
|
917
963
|
return mapCType(girType.cType);
|
|
918
964
|
}
|
|
919
965
|
|
|
966
|
+
/**
|
|
967
|
+
* Checks if a type name refers to a callback type.
|
|
968
|
+
* @param typeName - The type name to check
|
|
969
|
+
* @returns True if the type is a callback
|
|
970
|
+
*/
|
|
920
971
|
isCallback(typeName: string): boolean {
|
|
921
972
|
if (this.typeRegistry) {
|
|
922
973
|
const resolved = this.currentNamespace
|