@gtkx/gir 0.13.2 → 0.14.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/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/internal/normalizer.js +3 -2
- package/dist/internal/parser.js +11 -7
- package/dist/internal/raw-types.d.ts +2 -1
- package/dist/types.d.ts +30 -2
- package/dist/types.js +35 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
*/
|
|
23
23
|
export { INTRINSIC_TYPES, isIntrinsicType, isNumericType, isStringType, isVoidType, NUMERIC_TYPES, STRING_TYPES, VOID_TYPES, } from "./intrinsics.js";
|
|
24
24
|
export { GirRepository } from "./repository.js";
|
|
25
|
-
export type { ContainerType, QualifiedName, TypeKind, } from "./types.js";
|
|
26
|
-
export { GirCallback, GirClass, GirConstant, GirConstructor, GirEnumeration, GirEnumerationMember, GirField, GirFunction, GirInterface, GirMethod, GirNamespace, GirParameter, GirProperty, GirRecord, GirSignal, GirType, parseQualifiedName, qualifiedName, } from "./types.js";
|
|
25
|
+
export type { ContainerType, DefaultValue, QualifiedName, TypeKind, } from "./types.js";
|
|
26
|
+
export { GirCallback, GirClass, GirConstant, GirConstructor, GirEnumeration, GirEnumerationMember, GirField, GirFunction, GirInterface, GirMethod, GirNamespace, GirParameter, GirProperty, GirRecord, GirSignal, GirType, parseDefaultValue, parseQualifiedName, qualifiedName, } from "./types.js";
|
|
27
27
|
export { toCamelCase, toPascalCase } from "./utils.js";
|
package/dist/index.js
CHANGED
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
*/
|
|
23
23
|
export { INTRINSIC_TYPES, isIntrinsicType, isNumericType, isStringType, isVoidType, NUMERIC_TYPES, STRING_TYPES, VOID_TYPES, } from "./intrinsics.js";
|
|
24
24
|
export { GirRepository } from "./repository.js";
|
|
25
|
-
export { GirCallback, GirClass, GirConstant, GirConstructor, GirEnumeration, GirEnumerationMember, GirField, GirFunction, GirInterface, GirMethod, GirNamespace, GirParameter, GirProperty, GirRecord, GirSignal, GirType, parseQualifiedName, qualifiedName, } from "./types.js";
|
|
25
|
+
export { GirCallback, GirClass, GirConstant, GirConstructor, GirEnumeration, GirEnumerationMember, GirField, GirFunction, GirInterface, GirMethod, GirNamespace, GirParameter, GirProperty, GirRecord, GirSignal, GirType, parseDefaultValue, parseQualifiedName, qualifiedName, } from "./types.js";
|
|
26
26
|
export { toCamelCase, toPascalCase } from "./utils.js";
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
9
|
import { isIntrinsicType } from "../intrinsics.js";
|
|
10
|
-
import { GirCallback, GirClass, GirConstant, GirConstructor, GirEnumeration, GirEnumerationMember, GirField, GirFunction, GirInterface, GirMethod, GirNamespace, GirParameter, GirProperty, GirRecord, GirSignal, GirType, qualifiedName, } from "../types.js";
|
|
10
|
+
import { GirCallback, GirClass, GirConstant, GirConstructor, GirEnumeration, GirEnumerationMember, GirField, GirFunction, GirInterface, GirMethod, GirNamespace, GirParameter, GirProperty, GirRecord, GirSignal, GirType, parseDefaultValue, qualifiedName, } from "../types.js";
|
|
11
11
|
/**
|
|
12
12
|
* Normalizes a raw namespace into a normalized namespace.
|
|
13
13
|
*/
|
|
@@ -274,6 +274,7 @@ const normalizeEnumeration = (raw, currentNamespace) => {
|
|
|
274
274
|
cIdentifier: m.cIdentifier,
|
|
275
275
|
doc: m.doc,
|
|
276
276
|
})),
|
|
277
|
+
glibGetType: raw.glibGetType,
|
|
277
278
|
doc: raw.doc,
|
|
278
279
|
});
|
|
279
280
|
};
|
|
@@ -382,7 +383,7 @@ const normalizeProperty = (raw, currentNamespace, ctx) => {
|
|
|
382
383
|
readable: raw.readable ?? true,
|
|
383
384
|
writable: raw.writable ?? false,
|
|
384
385
|
constructOnly: raw.constructOnly ?? false,
|
|
385
|
-
|
|
386
|
+
defaultValue: parseDefaultValue(raw.defaultValueRaw),
|
|
386
387
|
getter: raw.getter,
|
|
387
388
|
setter: raw.setter,
|
|
388
389
|
doc: raw.doc,
|
package/dist/internal/parser.js
CHANGED
|
@@ -389,7 +389,7 @@ export class RawGirParser {
|
|
|
389
389
|
readable: prop["@_readable"] !== "0",
|
|
390
390
|
writable: prop["@_writable"] === "1",
|
|
391
391
|
constructOnly: prop["@_construct-only"] === "1",
|
|
392
|
-
|
|
392
|
+
defaultValueRaw: prop["@_default-value"] !== undefined ? String(prop["@_default-value"]) : undefined,
|
|
393
393
|
getter,
|
|
394
394
|
setter,
|
|
395
395
|
doc: extractDoc(prop),
|
|
@@ -461,12 +461,16 @@ export class RawGirParser {
|
|
|
461
461
|
if (!enumerations || !Array.isArray(enumerations)) {
|
|
462
462
|
return [];
|
|
463
463
|
}
|
|
464
|
-
return enumerations.map((enumeration) =>
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
464
|
+
return enumerations.map((enumeration) => {
|
|
465
|
+
const glibGetType = enumeration["@_glib:get-type"];
|
|
466
|
+
return {
|
|
467
|
+
name: String(enumeration["@_name"] ?? ""),
|
|
468
|
+
cType: String(enumeration["@_c:type"] ?? ""),
|
|
469
|
+
members: this.parseEnumerationMembers(ensureArray(enumeration.member)),
|
|
470
|
+
glibGetType: typeof glibGetType === "string" ? glibGetType : undefined,
|
|
471
|
+
doc: extractDoc(enumeration),
|
|
472
|
+
};
|
|
473
|
+
});
|
|
470
474
|
}
|
|
471
475
|
parseEnumerationMembers(members) {
|
|
472
476
|
if (!members || !Array.isArray(members)) {
|
|
@@ -202,7 +202,7 @@ export type RawProperty = {
|
|
|
202
202
|
readable?: boolean;
|
|
203
203
|
writable?: boolean;
|
|
204
204
|
constructOnly?: boolean;
|
|
205
|
-
|
|
205
|
+
defaultValueRaw?: string;
|
|
206
206
|
getter?: string;
|
|
207
207
|
setter?: string;
|
|
208
208
|
doc?: string;
|
|
@@ -224,6 +224,7 @@ export type RawEnumeration = {
|
|
|
224
224
|
name: string;
|
|
225
225
|
cType: string;
|
|
226
226
|
members: RawEnumerationMember[];
|
|
227
|
+
glibGetType?: string;
|
|
227
228
|
doc?: string;
|
|
228
229
|
};
|
|
229
230
|
/**
|
package/dist/types.d.ts
CHANGED
|
@@ -31,6 +31,31 @@ export type TypeKind = "class" | "interface" | "record" | "enum" | "flags" | "ca
|
|
|
31
31
|
* Container type discriminator for generic GLib containers.
|
|
32
32
|
*/
|
|
33
33
|
export type ContainerType = "ghashtable" | "gptrarray" | "garray" | "glist" | "gslist";
|
|
34
|
+
/**
|
|
35
|
+
* Parsed default value from GIR property definitions.
|
|
36
|
+
*/
|
|
37
|
+
export type DefaultValue = {
|
|
38
|
+
kind: "null";
|
|
39
|
+
} | {
|
|
40
|
+
kind: "boolean";
|
|
41
|
+
value: boolean;
|
|
42
|
+
} | {
|
|
43
|
+
kind: "number";
|
|
44
|
+
value: number;
|
|
45
|
+
} | {
|
|
46
|
+
kind: "string";
|
|
47
|
+
value: string;
|
|
48
|
+
} | {
|
|
49
|
+
kind: "enum";
|
|
50
|
+
cIdentifier: string;
|
|
51
|
+
} | {
|
|
52
|
+
kind: "unknown";
|
|
53
|
+
raw: string;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Parses a raw default value string from GIR into a typed DefaultValue.
|
|
57
|
+
*/
|
|
58
|
+
export declare function parseDefaultValue(raw: string | undefined): DefaultValue | null;
|
|
34
59
|
type RepositoryLike = {
|
|
35
60
|
resolveClass(name: QualifiedName): GirClass | null;
|
|
36
61
|
resolveInterface(name: QualifiedName): GirInterface | null;
|
|
@@ -261,12 +286,14 @@ export declare class GirEnumeration {
|
|
|
261
286
|
readonly qualifiedName: QualifiedName;
|
|
262
287
|
readonly cType: string;
|
|
263
288
|
readonly members: GirEnumerationMember[];
|
|
289
|
+
readonly glibGetType?: string;
|
|
264
290
|
readonly doc?: string;
|
|
265
291
|
constructor(data: {
|
|
266
292
|
name: string;
|
|
267
293
|
qualifiedName: QualifiedName;
|
|
268
294
|
cType: string;
|
|
269
295
|
members: GirEnumerationMember[];
|
|
296
|
+
glibGetType?: string;
|
|
270
297
|
doc?: string;
|
|
271
298
|
});
|
|
272
299
|
/** Finds a member by name. */
|
|
@@ -477,7 +504,7 @@ export declare class GirProperty {
|
|
|
477
504
|
readonly readable: boolean;
|
|
478
505
|
readonly writable: boolean;
|
|
479
506
|
readonly constructOnly: boolean;
|
|
480
|
-
readonly
|
|
507
|
+
readonly defaultValue: DefaultValue | null;
|
|
481
508
|
readonly getter?: string;
|
|
482
509
|
readonly setter?: string;
|
|
483
510
|
readonly doc?: string;
|
|
@@ -487,11 +514,12 @@ export declare class GirProperty {
|
|
|
487
514
|
readable: boolean;
|
|
488
515
|
writable: boolean;
|
|
489
516
|
constructOnly: boolean;
|
|
490
|
-
|
|
517
|
+
defaultValue: DefaultValue | null;
|
|
491
518
|
getter?: string;
|
|
492
519
|
setter?: string;
|
|
493
520
|
doc?: string;
|
|
494
521
|
});
|
|
522
|
+
get hasDefault(): boolean;
|
|
495
523
|
/** True if readable but not writable. */
|
|
496
524
|
isReadOnly(): boolean;
|
|
497
525
|
/** True if writable but not readable. */
|
package/dist/types.js
CHANGED
|
@@ -21,6 +21,34 @@ export const parseQualifiedName = (qn) => {
|
|
|
21
21
|
name: qn.slice(dot + 1),
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Parses a raw default value string from GIR into a typed DefaultValue.
|
|
26
|
+
*/
|
|
27
|
+
export function parseDefaultValue(raw) {
|
|
28
|
+
if (raw === undefined) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
if (raw === "NULL") {
|
|
32
|
+
return { kind: "null" };
|
|
33
|
+
}
|
|
34
|
+
if (raw === "TRUE") {
|
|
35
|
+
return { kind: "boolean", value: true };
|
|
36
|
+
}
|
|
37
|
+
if (raw === "FALSE") {
|
|
38
|
+
return { kind: "boolean", value: false };
|
|
39
|
+
}
|
|
40
|
+
const num = Number(raw);
|
|
41
|
+
if (!Number.isNaN(num)) {
|
|
42
|
+
return { kind: "number", value: num };
|
|
43
|
+
}
|
|
44
|
+
if (raw.startsWith('"') && raw.endsWith('"')) {
|
|
45
|
+
return { kind: "string", value: raw.slice(1, -1) };
|
|
46
|
+
}
|
|
47
|
+
if (/^[A-Z][A-Z0-9_]*$/.test(raw)) {
|
|
48
|
+
return { kind: "enum", cIdentifier: raw };
|
|
49
|
+
}
|
|
50
|
+
return { kind: "unknown", raw };
|
|
51
|
+
}
|
|
24
52
|
/**
|
|
25
53
|
* Normalized namespace containing all resolved types.
|
|
26
54
|
*/
|
|
@@ -384,12 +412,14 @@ export class GirEnumeration {
|
|
|
384
412
|
qualifiedName;
|
|
385
413
|
cType;
|
|
386
414
|
members;
|
|
415
|
+
glibGetType;
|
|
387
416
|
doc;
|
|
388
417
|
constructor(data) {
|
|
389
418
|
this.name = data.name;
|
|
390
419
|
this.qualifiedName = data.qualifiedName;
|
|
391
420
|
this.cType = data.cType;
|
|
392
421
|
this.members = data.members;
|
|
422
|
+
this.glibGetType = data.glibGetType;
|
|
393
423
|
this.doc = data.doc;
|
|
394
424
|
}
|
|
395
425
|
/** Finds a member by name. */
|
|
@@ -641,7 +671,7 @@ export class GirProperty {
|
|
|
641
671
|
readable;
|
|
642
672
|
writable;
|
|
643
673
|
constructOnly;
|
|
644
|
-
|
|
674
|
+
defaultValue;
|
|
645
675
|
getter;
|
|
646
676
|
setter;
|
|
647
677
|
doc;
|
|
@@ -651,11 +681,14 @@ export class GirProperty {
|
|
|
651
681
|
this.readable = data.readable;
|
|
652
682
|
this.writable = data.writable;
|
|
653
683
|
this.constructOnly = data.constructOnly;
|
|
654
|
-
this.
|
|
684
|
+
this.defaultValue = data.defaultValue;
|
|
655
685
|
this.getter = data.getter;
|
|
656
686
|
this.setter = data.setter;
|
|
657
687
|
this.doc = data.doc;
|
|
658
688
|
}
|
|
689
|
+
get hasDefault() {
|
|
690
|
+
return this.defaultValue !== null;
|
|
691
|
+
}
|
|
659
692
|
/** True if readable but not writable. */
|
|
660
693
|
isReadOnly() {
|
|
661
694
|
return this.readable && !this.writable;
|