@gtkx/runtime 0.0.1 → 1.0.0-rc.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 (123) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +171 -3
  3. package/dist/arg.d.ts +13 -0
  4. package/dist/arg.d.ts.map +1 -0
  5. package/dist/arg.js +6 -0
  6. package/dist/arg.js.map +1 -0
  7. package/dist/bind.d.ts +5 -0
  8. package/dist/bind.d.ts.map +1 -0
  9. package/dist/bind.js +19 -0
  10. package/dist/bind.js.map +1 -0
  11. package/dist/callback.d.ts +13 -0
  12. package/dist/callback.d.ts.map +1 -0
  13. package/dist/callback.js +86 -0
  14. package/dist/callback.js.map +1 -0
  15. package/dist/descriptors.d.ts +158 -0
  16. package/dist/descriptors.d.ts.map +1 -0
  17. package/dist/descriptors.js +135 -0
  18. package/dist/descriptors.js.map +1 -0
  19. package/dist/error.d.ts +24 -0
  20. package/dist/error.d.ts.map +1 -0
  21. package/dist/error.js +33 -0
  22. package/dist/error.js.map +1 -0
  23. package/dist/exit-hook.d.ts +2 -0
  24. package/dist/exit-hook.d.ts.map +1 -0
  25. package/dist/exit-hook.js +3 -0
  26. package/dist/exit-hook.js.map +1 -0
  27. package/dist/fn.d.ts +10 -0
  28. package/dist/fn.d.ts.map +1 -0
  29. package/dist/fn.js +90 -0
  30. package/dist/fn.js.map +1 -0
  31. package/dist/index.d.ts +16 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +16 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/internal.d.ts +5 -0
  36. package/dist/internal.d.ts.map +1 -0
  37. package/dist/internal.js +5 -0
  38. package/dist/internal.js.map +1 -0
  39. package/dist/library.d.ts +8 -0
  40. package/dist/library.d.ts.map +1 -0
  41. package/dist/library.js +14 -0
  42. package/dist/library.js.map +1 -0
  43. package/dist/lifecycle.d.ts +42 -0
  44. package/dist/lifecycle.d.ts.map +1 -0
  45. package/dist/lifecycle.js +70 -0
  46. package/dist/lifecycle.js.map +1 -0
  47. package/dist/listeners.d.ts +36 -0
  48. package/dist/listeners.d.ts.map +1 -0
  49. package/dist/listeners.js +85 -0
  50. package/dist/listeners.js.map +1 -0
  51. package/dist/mixin.d.ts +13 -0
  52. package/dist/mixin.d.ts.map +1 -0
  53. package/dist/mixin.js +49 -0
  54. package/dist/mixin.js.map +1 -0
  55. package/dist/native-value.d.ts +13 -0
  56. package/dist/native-value.d.ts.map +1 -0
  57. package/dist/native-value.js +105 -0
  58. package/dist/native-value.js.map +1 -0
  59. package/dist/object.d.ts +32 -0
  60. package/dist/object.d.ts.map +1 -0
  61. package/dist/object.js +66 -0
  62. package/dist/object.js.map +1 -0
  63. package/dist/promisify.d.ts +21 -0
  64. package/dist/promisify.d.ts.map +1 -0
  65. package/dist/promisify.js +39 -0
  66. package/dist/promisify.js.map +1 -0
  67. package/dist/properties.d.ts +14 -0
  68. package/dist/properties.d.ts.map +1 -0
  69. package/dist/properties.js +79 -0
  70. package/dist/properties.js.map +1 -0
  71. package/dist/register-class.d.ts +25 -0
  72. package/dist/register-class.d.ts.map +1 -0
  73. package/dist/register-class.js +178 -0
  74. package/dist/register-class.js.map +1 -0
  75. package/dist/registry.d.ts +69 -0
  76. package/dist/registry.d.ts.map +1 -0
  77. package/dist/registry.js +186 -0
  78. package/dist/registry.js.map +1 -0
  79. package/dist/signal.d.ts +35 -0
  80. package/dist/signal.d.ts.map +1 -0
  81. package/dist/signal.js +95 -0
  82. package/dist/signal.js.map +1 -0
  83. package/dist/t.d.ts +50 -0
  84. package/dist/t.d.ts.map +1 -0
  85. package/dist/t.js +49 -0
  86. package/dist/t.js.map +1 -0
  87. package/dist/tuple.d.ts +7 -0
  88. package/dist/tuple.d.ts.map +1 -0
  89. package/dist/tuple.js +26 -0
  90. package/dist/tuple.js.map +1 -0
  91. package/dist/type.d.ts +88 -0
  92. package/dist/type.d.ts.map +1 -0
  93. package/dist/type.js +194 -0
  94. package/dist/type.js.map +1 -0
  95. package/dist/value.d.ts +29 -0
  96. package/dist/value.d.ts.map +1 -0
  97. package/dist/value.js +292 -0
  98. package/dist/value.js.map +1 -0
  99. package/package.json +54 -13
  100. package/src/arg.ts +15 -0
  101. package/src/bind.ts +31 -0
  102. package/src/callback.ts +149 -0
  103. package/src/descriptors.ts +350 -0
  104. package/src/error.ts +58 -0
  105. package/src/exit-hook.ts +3 -0
  106. package/src/fn.ts +139 -0
  107. package/src/index.ts +59 -0
  108. package/src/internal.ts +12 -0
  109. package/src/library.ts +17 -0
  110. package/src/lifecycle.ts +101 -0
  111. package/src/listeners.ts +112 -0
  112. package/src/mixin.ts +73 -0
  113. package/src/native-value.ts +135 -0
  114. package/src/object.ts +95 -0
  115. package/src/promisify.ts +67 -0
  116. package/src/properties.ts +115 -0
  117. package/src/register-class.ts +305 -0
  118. package/src/registry.ts +311 -0
  119. package/src/signal.ts +192 -0
  120. package/src/t.ts +90 -0
  121. package/src/tuple.ts +37 -0
  122. package/src/type.ts +290 -0
  123. package/src/value.ts +430 -0
package/dist/tuple.js ADDED
@@ -0,0 +1,26 @@
1
+ const packTupleResult = (outs, primary, hasPrimary) => {
2
+ if (hasPrimary) {
3
+ return outs.length === 0 ? primary : [primary, ...outs];
4
+ }
5
+ if (outs.length === 0) {
6
+ return undefined;
7
+ }
8
+ if (outs.length === 1) {
9
+ return outs[0];
10
+ }
11
+ return outs;
12
+ };
13
+ const splitTupleResult = (result, hasPrimary, outCount) => {
14
+ if (hasPrimary) {
15
+ if (Array.isArray(result)) {
16
+ return { primary: result[0], outValues: result.slice(1) };
17
+ }
18
+ return { primary: result, outValues: [] };
19
+ }
20
+ if (outCount === 1) {
21
+ return { primary: undefined, outValues: [result] };
22
+ }
23
+ return { primary: undefined, outValues: Array.isArray(result) ? result : [] };
24
+ };
25
+ export { packTupleResult, splitTupleResult };
26
+ //# sourceMappingURL=tuple.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tuple.js","sourceRoot":"","sources":["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gB,EAAE,CAAC","sourcesContent":["const packTupleResult = (outs: unknown[], primary: unknown, hasPrimary: boolean): unknown => {\n if (hasPrimary) {\n return outs.length === 0 ? primary : [primary, ...outs];\n }\n\n if (outs.length === 0) {\n return undefined;\n }\n\n if (outs.length === 1) {\n return outs[0];\n }\n\n return outs;\n};\n\nconst splitTupleResult = (\n result: unknown,\n hasPrimary: boolean,\n outCount: number,\n): { primary: unknown; outValues: unknown[] } => {\n if (hasPrimary) {\n if (Array.isArray(result)) {\n return { primary: result[0], outValues: result.slice(1) };\n }\n\n return { primary: result, outValues: [] };\n }\n\n if (outCount === 1) {\n return { primary: undefined, outValues: [result] };\n }\n\n return { primary: undefined, outValues: Array.isArray(result) ? result : [] };\n};\n\nexport { packTupleResult, splitTupleResult };\n"]}
package/dist/type.d.ts ADDED
@@ -0,0 +1,88 @@
1
+ import { type Descriptor } from "@gtkx/native";
2
+ import { type BoxedDescriptor, type FundamentalDescriptor } from "./descriptors.js";
3
+ /** Object tagged with its GLib type through a `__type__` GType field. */
4
+ type TypedClass = {
5
+ __type__: bigint;
6
+ };
7
+ type ResolvableKind = "enum" | "flags" | "boxed" | "fundamental" | "array";
8
+ /** Descriptor kinds whose GType is resolved from library metadata rather than a fixed fundamental type. */
9
+ type ResolvableDescriptor = Extract<Descriptor, {
10
+ kind: ResolvableKind;
11
+ }>;
12
+ /** GType tag for an invalid or uninitialized type. */
13
+ declare const TYPE_INVALID = 0n;
14
+ /** GType tag for the absence of a value (`void`). */
15
+ declare const TYPE_NONE: bigint;
16
+ /** GType tag for the base GInterface type. */
17
+ declare const TYPE_INTERFACE: bigint;
18
+ /** GType tag for `gchar` (signed 8-bit integer). */
19
+ declare const TYPE_CHAR: bigint;
20
+ /** GType tag for `guchar` (unsigned 8-bit integer). */
21
+ declare const TYPE_UCHAR: bigint;
22
+ /** GType tag for `gboolean`. */
23
+ declare const TYPE_BOOLEAN: bigint;
24
+ /** GType tag for `gint`. */
25
+ declare const TYPE_INT: bigint;
26
+ /** GType tag for `guint`. */
27
+ declare const TYPE_UINT: bigint;
28
+ /** GType tag for `glong`. */
29
+ declare const TYPE_LONG: bigint;
30
+ /** GType tag for `gulong`. */
31
+ declare const TYPE_ULONG: bigint;
32
+ /** GType tag for `gint64`. */
33
+ declare const TYPE_INT64: bigint;
34
+ /** GType tag for `guint64`. */
35
+ declare const TYPE_UINT64: bigint;
36
+ /** GType tag for the base GEnum type. */
37
+ declare const TYPE_ENUM: bigint;
38
+ /** GType tag for the base GFlags type. */
39
+ declare const TYPE_FLAGS: bigint;
40
+ /** GType tag for `gfloat`. */
41
+ declare const TYPE_FLOAT: bigint;
42
+ /** GType tag for `gdouble`. */
43
+ declare const TYPE_DOUBLE: bigint;
44
+ /** GType tag for `gchararray` (a nul-terminated C string). */
45
+ declare const TYPE_STRING: bigint;
46
+ /** GType tag for `gpointer` (an opaque pointer). */
47
+ declare const TYPE_POINTER: bigint;
48
+ /** GType tag for the base GBoxed type. */
49
+ declare const TYPE_BOXED: bigint;
50
+ /** GType tag for the base GParam type. */
51
+ declare const TYPE_PARAM: bigint;
52
+ /** GType tag for the base GObject type. */
53
+ declare const TYPE_OBJECT: bigint;
54
+ /** GType tag for a GType value itself. */
55
+ declare const TYPE_GTYPE: bigint;
56
+ /** GType tag for GVariant. */
57
+ declare const TYPE_VARIANT: bigint;
58
+ /** GType tag for a Unicode character stored as `guint`. */
59
+ declare const TYPE_UNICHAR: bigint;
60
+ declare const getErrorType: () => bigint;
61
+ declare const getStrvType: () => bigint;
62
+ declare const isTypedClass: (value: unknown) => value is TypedClass;
63
+ /** Returns whether `type` is `ancestorType` or descends from it. */
64
+ declare function typeIsA(type: bigint, ancestorType: bigint): boolean;
65
+ /** Returns the immediate parent GType of the given type. */
66
+ declare function typeParent(type: bigint): bigint;
67
+ /** Returns the GTypes of the interfaces implemented by the given type. */
68
+ declare function typeInterfaces(type: bigint): bigint[];
69
+ /** Returns the GType registered under the given name, or `TYPE_INVALID` if none exists. */
70
+ declare function typeFromName(name: string): bigint;
71
+ declare function typeFundamental(type: bigint): bigint;
72
+ /** Returns the registered name of a GType, or null if it has none. */
73
+ declare function typeName(type: bigint): string | null;
74
+ /** Returns whether `value` is a typed wrapper whose GType is or descends from `gtype`. */
75
+ declare function valueIsA(value: unknown, gtype: bigint): boolean;
76
+ /**
77
+ * Resolves the GType produced by a `get_type` function in a shared library, caching
78
+ * the result per library and function name.
79
+ * @param sharedLibrary Path or name of the shared library exporting the function.
80
+ * @param typeFnName Name of the `*_get_type` function to call.
81
+ */
82
+ declare const resolveType: (sharedLibrary: string, typeFnName: string) => bigint;
83
+ declare const resolveBoxedType: (descriptor: BoxedDescriptor) => bigint;
84
+ declare const resolveFundamentalType: (descriptor: FundamentalDescriptor) => bigint;
85
+ declare function isResolvableDescriptor(descriptor: Descriptor): descriptor is ResolvableDescriptor;
86
+ declare function resolveDescriptorType(descriptor: Descriptor): bigint;
87
+ export { TYPE_INVALID, TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR, TYPE_BOOLEAN, TYPE_INT, TYPE_UINT, TYPE_LONG, TYPE_ULONG, TYPE_INT64, TYPE_UINT64, TYPE_ENUM, TYPE_FLAGS, TYPE_FLOAT, TYPE_DOUBLE, TYPE_STRING, TYPE_POINTER, TYPE_BOXED, TYPE_PARAM, TYPE_OBJECT, TYPE_GTYPE, TYPE_VARIANT, TYPE_UNICHAR, getErrorType, getStrvType, isResolvableDescriptor, isTypedClass, typeIsA, typeParent, typeInterfaces, typeFromName, typeFundamental, typeName, valueIsA, resolveType, resolveBoxedType, resolveFundamentalType, resolveDescriptorType, type ResolvableDescriptor, type TypedClass, };
88
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAoC,MAAM,cAAc,CAAC;AAEjF,OAAO,EAIH,KAAK,eAAe,EACpB,KAAK,qBA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,GAAG,OAAO,CAExD;AAED;;;;;GAKG;AACH,QAAA,MAAM,WAAW,GAAI,eAAe,MAAM,EAAE,YAAY,MAAM,KAAG,MAYhE,CAAC;AAEF,QAAA,MAAM,gBAAgB,GAAI,YAAY,eAAe,KAAG,MAYvD,CAAC;AAEF,QAAA,MAAM,sBAAsB,GAAI,YAAY,qBAAqB,KAAG,MAUnE,CAAC;AAUF,iBAAS,sBAAsB,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,oBAAoB,CAE1F;AAED,iBAAS,qBAAqB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CA8B7D;AAED,OAAO,EACH,YAAY,EACZ,SAAS,EACT,cAAc,EACd,SAAS,EACT,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,SAAS,EACT,UAAU,EACV,UAAU,EACV,WAAW,EACX,SAAS,EACT,UAAU,EACV,UAAU,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,UAAU,EACV,UAAU,EACV,WAAW,EACX,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,sBAAsB,EACtB,YAAY,EACZ,OAAO,EACP,UAAU,EACV,cAAc,EACd,YAAY,EACZ,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,EACrB,KAAK,oBAAoB,EACzB,KAAK,UAAU,GAClB,CAAC"}
package/dist/type.js ADDED
@@ -0,0 +1,194 @@
1
+ import { resolveType as nativeResolveType } from "@gtkx/native";
2
+ import { bind } from "./bind.js";
3
+ import { biguint64T, booleanT, refT, sizedArrayT, stringT, uint32T, } from "./descriptors.js";
4
+ import { LIB } from "./library.js";
5
+ const resolvedTypeCache = new Map();
6
+ const gTypeFromName = bind(LIB, "g_type_from_name", [stringT("borrowed")], biguint64T);
7
+ const gTypeIsA = bind(LIB, "g_type_is_a", [biguint64T, biguint64T], booleanT);
8
+ const gTypeParent = bind(LIB, "g_type_parent", [biguint64T], biguint64T);
9
+ const gTypeFundamental = bind(LIB, "g_type_fundamental", [biguint64T], biguint64T);
10
+ const gTypeName = bind(LIB, "g_type_name", [biguint64T], stringT("borrowed"));
11
+ const gTypeInterfaces = bind(LIB, "g_type_interfaces", [biguint64T, refT(uint32T)], sizedArrayT(biguint64T, 1, "full"));
12
+ /** GType tag for an invalid or uninitialized type. */
13
+ const TYPE_INVALID = 0n;
14
+ /** GType tag for the absence of a value (`void`). */
15
+ const TYPE_NONE = typeFromName("void");
16
+ /** GType tag for the base GInterface type. */
17
+ const TYPE_INTERFACE = typeFromName("GInterface");
18
+ /** GType tag for `gchar` (signed 8-bit integer). */
19
+ const TYPE_CHAR = typeFromName("gchar");
20
+ /** GType tag for `guchar` (unsigned 8-bit integer). */
21
+ const TYPE_UCHAR = typeFromName("guchar");
22
+ /** GType tag for `gboolean`. */
23
+ const TYPE_BOOLEAN = typeFromName("gboolean");
24
+ /** GType tag for `gint`. */
25
+ const TYPE_INT = typeFromName("gint");
26
+ /** GType tag for `guint`. */
27
+ const TYPE_UINT = typeFromName("guint");
28
+ /** GType tag for `glong`. */
29
+ const TYPE_LONG = typeFromName("glong");
30
+ /** GType tag for `gulong`. */
31
+ const TYPE_ULONG = typeFromName("gulong");
32
+ /** GType tag for `gint64`. */
33
+ const TYPE_INT64 = typeFromName("gint64");
34
+ /** GType tag for `guint64`. */
35
+ const TYPE_UINT64 = typeFromName("guint64");
36
+ /** GType tag for the base GEnum type. */
37
+ const TYPE_ENUM = typeFromName("GEnum");
38
+ /** GType tag for the base GFlags type. */
39
+ const TYPE_FLAGS = typeFromName("GFlags");
40
+ /** GType tag for `gfloat`. */
41
+ const TYPE_FLOAT = typeFromName("gfloat");
42
+ /** GType tag for `gdouble`. */
43
+ const TYPE_DOUBLE = typeFromName("gdouble");
44
+ /** GType tag for `gchararray` (a nul-terminated C string). */
45
+ const TYPE_STRING = typeFromName("gchararray");
46
+ /** GType tag for `gpointer` (an opaque pointer). */
47
+ const TYPE_POINTER = typeFromName("gpointer");
48
+ /** GType tag for the base GBoxed type. */
49
+ const TYPE_BOXED = typeFromName("GBoxed");
50
+ /** GType tag for the base GParam type. */
51
+ const TYPE_PARAM = typeFromName("GParam");
52
+ /** GType tag for the base GObject type. */
53
+ const TYPE_OBJECT = typeFromName("GObject");
54
+ /** GType tag for a GType value itself. */
55
+ const TYPE_GTYPE = typeFromName("GType");
56
+ /** GType tag for GVariant. */
57
+ const TYPE_VARIANT = typeFromName("GVariant");
58
+ /** GType tag for a Unicode character stored as `guint`. */
59
+ const TYPE_UNICHAR = typeFromName("guint");
60
+ const getErrorType = lazyType("GError");
61
+ const getStrvType = lazyType("GStrv");
62
+ const PLAIN_DESCRIPTOR_TYPES = {
63
+ boolean: TYPE_BOOLEAN,
64
+ string: TYPE_STRING,
65
+ int8: TYPE_INT,
66
+ int16: TYPE_INT,
67
+ int32: TYPE_INT,
68
+ uint8: TYPE_UINT,
69
+ uint16: TYPE_UINT,
70
+ uint32: TYPE_UINT,
71
+ int64: TYPE_INT64,
72
+ bigint64: TYPE_INT64,
73
+ uint64: TYPE_UINT64,
74
+ biguint64: TYPE_UINT64,
75
+ float32: TYPE_FLOAT,
76
+ float64: TYPE_DOUBLE,
77
+ object: TYPE_OBJECT,
78
+ };
79
+ const RESOLVABLE_DESCRIPTOR_KINDS = new Set([
80
+ "enum",
81
+ "flags",
82
+ "boxed",
83
+ "fundamental",
84
+ "array",
85
+ ]);
86
+ function lazyType(name) {
87
+ let cached;
88
+ return () => {
89
+ cached ??= typeFromName(name);
90
+ return cached;
91
+ };
92
+ }
93
+ const isTypedClass = (value) => typeof value === "object" && value !== null && "__type__" in value && typeof value.__type__ === "bigint";
94
+ /** Returns whether `type` is `ancestorType` or descends from it. */
95
+ function typeIsA(type, ancestorType) {
96
+ return gTypeIsA(type, ancestorType);
97
+ }
98
+ /** Returns the immediate parent GType of the given type. */
99
+ function typeParent(type) {
100
+ return gTypeParent(type);
101
+ }
102
+ /** Returns the GTypes of the interfaces implemented by the given type. */
103
+ function typeInterfaces(type) {
104
+ const nInterfacesRef = { value: 0 };
105
+ return gTypeInterfaces(type, nInterfacesRef);
106
+ }
107
+ /** Returns the GType registered under the given name, or `TYPE_INVALID` if none exists. */
108
+ function typeFromName(name) {
109
+ return gTypeFromName(name);
110
+ }
111
+ function typeFundamental(type) {
112
+ return gTypeFundamental(type);
113
+ }
114
+ /** Returns the registered name of a GType, or null if it has none. */
115
+ function typeName(type) {
116
+ return (gTypeName(type) ?? null);
117
+ }
118
+ /** Returns whether `value` is a typed wrapper whose GType is or descends from `gtype`. */
119
+ function valueIsA(value, gtype) {
120
+ return isTypedClass(value) && typeIsA(value.__type__, gtype);
121
+ }
122
+ /**
123
+ * Resolves the GType produced by a `get_type` function in a shared library, caching
124
+ * the result per library and function name.
125
+ * @param sharedLibrary Path or name of the shared library exporting the function.
126
+ * @param typeFnName Name of the `*_get_type` function to call.
127
+ */
128
+ const resolveType = (sharedLibrary, typeFnName) => {
129
+ const key = `${sharedLibrary}:${typeFnName}`;
130
+ const cached = resolvedTypeCache.get(key);
131
+ if (cached !== undefined) {
132
+ return cached;
133
+ }
134
+ const gtype = nativeResolveType(sharedLibrary, typeFnName);
135
+ resolvedTypeCache.set(key, gtype);
136
+ return gtype;
137
+ };
138
+ const resolveBoxedType = (descriptor) => {
139
+ if (descriptor.getTypeFnName && descriptor.sharedLibrary) {
140
+ return resolveType(descriptor.sharedLibrary, descriptor.getTypeFnName);
141
+ }
142
+ const gtype = typeFromName(descriptor.typeName);
143
+ if (gtype === TYPE_INVALID) {
144
+ throw new Error(`Cannot resolve gtype for boxed type '${descriptor.typeName}'`);
145
+ }
146
+ return gtype;
147
+ };
148
+ const resolveFundamentalType = (descriptor) => {
149
+ if (descriptor.typeName) {
150
+ const gtype = typeFromName(descriptor.typeName);
151
+ if (gtype !== TYPE_INVALID) {
152
+ return gtype;
153
+ }
154
+ }
155
+ throw new Error("Cannot resolve gtype for fundamental type without a typeName");
156
+ };
157
+ function resolveArrayType(descriptor) {
158
+ if (descriptor.itemDescriptor.kind === "string" && descriptor.arrayKind === "array") {
159
+ return getStrvType();
160
+ }
161
+ throw new Error(`Unsupported array type ${descriptor.arrayKind} of ${descriptor.itemDescriptor.kind}`);
162
+ }
163
+ function isResolvableDescriptor(descriptor) {
164
+ return RESOLVABLE_DESCRIPTOR_KINDS.has(descriptor.kind);
165
+ }
166
+ function resolveDescriptorType(descriptor) {
167
+ if (descriptor.kind === "biguint64" && "type" in descriptor) {
168
+ return TYPE_GTYPE;
169
+ }
170
+ const plain = PLAIN_DESCRIPTOR_TYPES[descriptor.kind];
171
+ if (plain !== undefined) {
172
+ return plain;
173
+ }
174
+ if (!isResolvableDescriptor(descriptor)) {
175
+ throw new Error(`Unsupported type descriptor '${descriptor.kind}'`);
176
+ }
177
+ switch (descriptor.kind) {
178
+ case "enum":
179
+ case "flags": {
180
+ return resolveType(descriptor.sharedLibrary, descriptor.getTypeFnName);
181
+ }
182
+ case "boxed": {
183
+ return resolveBoxedType(descriptor);
184
+ }
185
+ case "fundamental": {
186
+ return resolveFundamentalType(descriptor);
187
+ }
188
+ case "array": {
189
+ return resolveArrayType(descriptor);
190
+ }
191
+ }
192
+ }
193
+ export { TYPE_INVALID, TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR, TYPE_BOOLEAN, TYPE_INT, TYPE_UINT, TYPE_LONG, TYPE_ULONG, TYPE_INT64, TYPE_UINT64, TYPE_ENUM, TYPE_FLAGS, TYPE_FLOAT, TYPE_DOUBLE, TYPE_STRING, TYPE_POINTER, TYPE_BOXED, TYPE_PARAM, TYPE_OBJECT, TYPE_GTYPE, TYPE_VARIANT, TYPE_UNICHAR, getErrorType, getStrvType, isResolvableDescriptor, isTypedClass, typeIsA, typeParent, typeInterfaces, typeFromName, typeFundamental, typeName, valueIsA, resolveType, resolveBoxedType, resolveFundamentalType, resolveDescriptorType, };
194
+ //# sourceMappingURL=type.js.map
@@ -0,0 +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ACX,SAAS,EACT,UAAU,EACV,UAAU,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,UAAU,EACV,UAAU,EACV,WAAW,EACX,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,sBAAsB,EACtB,YAAY,EACZ,OAAO,EACP,UAAU,EACV,cAAc,EACd,YAAY,EACZ,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,GAGxB,CAAC","sourcesContent":["import { type Descriptor, resolveType as nativeResolveType } from \"@gtkx/native\";\nimport { bind } from \"./bind.js\";\nimport {\n type ArrayDescriptor,\n biguint64T,\n booleanT,\n type BoxedDescriptor,\n type FundamentalDescriptor,\n refT,\n sizedArrayT,\n stringT,\n uint32T,\n} from \"./descriptors.js\";\nimport { LIB } from \"./library.js\";\n\n/** Object tagged with its GLib type through a `__type__` GType field. */\ntype TypedClass = {\n __type__: bigint;\n};\n\ntype ResolvableKind = \"enum\" | \"flags\" | \"boxed\" | \"fundamental\" | \"array\";\n/** Descriptor kinds whose GType is resolved from library metadata rather than a fixed fundamental type. */\ntype ResolvableDescriptor = Extract<Descriptor, { kind: ResolvableKind }>;\n\nconst resolvedTypeCache: Map<string, bigint> = new Map();\nconst gTypeFromName = bind(LIB, \"g_type_from_name\", [stringT(\"borrowed\")], biguint64T);\nconst gTypeIsA = bind(LIB, \"g_type_is_a\", [biguint64T, biguint64T], booleanT);\nconst gTypeParent = bind(LIB, \"g_type_parent\", [biguint64T], biguint64T);\nconst gTypeFundamental = bind(LIB, \"g_type_fundamental\", [biguint64T], biguint64T);\nconst gTypeName = bind(LIB, \"g_type_name\", [biguint64T], stringT(\"borrowed\"));\nconst gTypeInterfaces = bind(LIB, \"g_type_interfaces\", [biguint64T, refT(uint32T)], sizedArrayT(biguint64T, 1, \"full\"));\n/** GType tag for an invalid or uninitialized type. */\nconst TYPE_INVALID = 0n;\n/** GType tag for the absence of a value (`void`). */\nconst TYPE_NONE: bigint = typeFromName(\"void\");\n/** GType tag for the base GInterface type. */\nconst TYPE_INTERFACE: bigint = typeFromName(\"GInterface\");\n/** GType tag for `gchar` (signed 8-bit integer). */\nconst TYPE_CHAR: bigint = typeFromName(\"gchar\");\n/** GType tag for `guchar` (unsigned 8-bit integer). */\nconst TYPE_UCHAR: bigint = typeFromName(\"guchar\");\n/** GType tag for `gboolean`. */\nconst TYPE_BOOLEAN: bigint = typeFromName(\"gboolean\");\n/** GType tag for `gint`. */\nconst TYPE_INT: bigint = typeFromName(\"gint\");\n/** GType tag for `guint`. */\nconst TYPE_UINT: bigint = typeFromName(\"guint\");\n/** GType tag for `glong`. */\nconst TYPE_LONG: bigint = typeFromName(\"glong\");\n/** GType tag for `gulong`. */\nconst TYPE_ULONG: bigint = typeFromName(\"gulong\");\n/** GType tag for `gint64`. */\nconst TYPE_INT64: bigint = typeFromName(\"gint64\");\n/** GType tag for `guint64`. */\nconst TYPE_UINT64: bigint = typeFromName(\"guint64\");\n/** GType tag for the base GEnum type. */\nconst TYPE_ENUM: bigint = typeFromName(\"GEnum\");\n/** GType tag for the base GFlags type. */\nconst TYPE_FLAGS: bigint = typeFromName(\"GFlags\");\n/** GType tag for `gfloat`. */\nconst TYPE_FLOAT: bigint = typeFromName(\"gfloat\");\n/** GType tag for `gdouble`. */\nconst TYPE_DOUBLE: bigint = typeFromName(\"gdouble\");\n/** GType tag for `gchararray` (a nul-terminated C string). */\nconst TYPE_STRING: bigint = typeFromName(\"gchararray\");\n/** GType tag for `gpointer` (an opaque pointer). */\nconst TYPE_POINTER: bigint = typeFromName(\"gpointer\");\n/** GType tag for the base GBoxed type. */\nconst TYPE_BOXED: bigint = typeFromName(\"GBoxed\");\n/** GType tag for the base GParam type. */\nconst TYPE_PARAM: bigint = typeFromName(\"GParam\");\n/** GType tag for the base GObject type. */\nconst TYPE_OBJECT: bigint = typeFromName(\"GObject\");\n/** GType tag for a GType value itself. */\nconst TYPE_GTYPE: bigint = typeFromName(\"GType\");\n/** GType tag for GVariant. */\nconst TYPE_VARIANT: bigint = typeFromName(\"GVariant\");\n/** GType tag for a Unicode character stored as `guint`. */\nconst TYPE_UNICHAR: bigint = typeFromName(\"guint\");\nconst getErrorType: () => bigint = lazyType(\"GError\");\nconst getStrvType: () => bigint = lazyType(\"GStrv\");\n\nconst PLAIN_DESCRIPTOR_TYPES: Partial<Record<Descriptor[\"kind\"], bigint>> = {\n boolean: TYPE_BOOLEAN,\n string: TYPE_STRING,\n int8: TYPE_INT,\n int16: TYPE_INT,\n int32: TYPE_INT,\n uint8: TYPE_UINT,\n uint16: TYPE_UINT,\n uint32: TYPE_UINT,\n int64: TYPE_INT64,\n bigint64: TYPE_INT64,\n uint64: TYPE_UINT64,\n biguint64: TYPE_UINT64,\n float32: TYPE_FLOAT,\n float64: TYPE_DOUBLE,\n object: TYPE_OBJECT,\n};\n\nconst RESOLVABLE_DESCRIPTOR_KINDS: Set<Descriptor[\"kind\"]> = new Set<ResolvableKind>([\n \"enum\",\n \"flags\",\n \"boxed\",\n \"fundamental\",\n \"array\",\n]);\n\nfunction lazyType(name: string): () => bigint {\n let cached: bigint | undefined;\n\n return () => {\n cached ??= typeFromName(name);\n\n return cached;\n };\n}\n\nconst isTypedClass = (value: unknown): value is TypedClass =>\n typeof value === \"object\" && value !== null && \"__type__\" in value && typeof value.__type__ === \"bigint\";\n\n/** Returns whether `type` is `ancestorType` or descends from it. */\nfunction typeIsA(type: bigint, ancestorType: bigint): boolean {\n return gTypeIsA(type, ancestorType) as boolean;\n}\n\n/** Returns the immediate parent GType of the given type. */\nfunction typeParent(type: bigint): bigint {\n return gTypeParent(type) as bigint;\n}\n\n/** Returns the GTypes of the interfaces implemented by the given type. */\nfunction typeInterfaces(type: bigint): bigint[] {\n const nInterfacesRef = { value: 0 };\n\n return gTypeInterfaces(type, nInterfacesRef) as bigint[];\n}\n\n/** Returns the GType registered under the given name, or `TYPE_INVALID` if none exists. */\nfunction typeFromName(name: string): bigint {\n return gTypeFromName(name) as bigint;\n}\n\nfunction typeFundamental(type: bigint): bigint {\n return gTypeFundamental(type) as bigint;\n}\n\n/** Returns the registered name of a GType, or null if it has none. */\nfunction typeName(type: bigint): string | null {\n return (gTypeName(type) ?? null) as string | null;\n}\n\n/** Returns whether `value` is a typed wrapper whose GType is or descends from `gtype`. */\nfunction valueIsA(value: unknown, gtype: bigint): boolean {\n return isTypedClass(value) && typeIsA(value.__type__, gtype);\n}\n\n/**\n * Resolves the GType produced by a `get_type` function in a shared library, caching\n * the result per library and function name.\n * @param sharedLibrary Path or name of the shared library exporting the function.\n * @param typeFnName Name of the `*_get_type` function to call.\n */\nconst resolveType = (sharedLibrary: string, typeFnName: string): bigint => {\n const key = `${sharedLibrary}:${typeFnName}`;\n const cached = resolvedTypeCache.get(key);\n\n if (cached !== undefined) {\n return cached;\n }\n\n const gtype = nativeResolveType(sharedLibrary, typeFnName);\n resolvedTypeCache.set(key, gtype);\n\n return gtype;\n};\n\nconst resolveBoxedType = (descriptor: BoxedDescriptor): bigint => {\n if (descriptor.getTypeFnName && descriptor.sharedLibrary) {\n return resolveType(descriptor.sharedLibrary, descriptor.getTypeFnName);\n }\n\n const gtype = typeFromName(descriptor.typeName);\n\n if (gtype === TYPE_INVALID) {\n throw new Error(`Cannot resolve gtype for boxed type '${descriptor.typeName}'`);\n }\n\n return gtype;\n};\n\nconst resolveFundamentalType = (descriptor: FundamentalDescriptor): bigint => {\n if (descriptor.typeName) {\n const gtype = typeFromName(descriptor.typeName);\n\n if (gtype !== TYPE_INVALID) {\n return gtype;\n }\n }\n\n throw new Error(\"Cannot resolve gtype for fundamental type without a typeName\");\n};\n\nfunction resolveArrayType(descriptor: ArrayDescriptor): bigint {\n if (descriptor.itemDescriptor.kind === \"string\" && descriptor.arrayKind === \"array\") {\n return getStrvType();\n }\n\n throw new Error(`Unsupported array type ${descriptor.arrayKind} of ${descriptor.itemDescriptor.kind}`);\n}\n\nfunction isResolvableDescriptor(descriptor: Descriptor): descriptor is ResolvableDescriptor {\n return RESOLVABLE_DESCRIPTOR_KINDS.has(descriptor.kind);\n}\n\nfunction resolveDescriptorType(descriptor: Descriptor): bigint {\n if (descriptor.kind === \"biguint64\" && \"type\" in descriptor) {\n return TYPE_GTYPE;\n }\n\n const plain = PLAIN_DESCRIPTOR_TYPES[descriptor.kind];\n\n if (plain !== undefined) {\n return plain;\n }\n\n if (!isResolvableDescriptor(descriptor)) {\n throw new Error(`Unsupported type descriptor '${descriptor.kind}'`);\n }\n\n switch (descriptor.kind) {\n case \"enum\":\n case \"flags\": {\n return resolveType(descriptor.sharedLibrary, descriptor.getTypeFnName);\n }\n case \"boxed\": {\n return resolveBoxedType(descriptor);\n }\n case \"fundamental\": {\n return resolveFundamentalType(descriptor);\n }\n case \"array\": {\n return resolveArrayType(descriptor);\n }\n }\n}\n\nexport {\n TYPE_INVALID,\n TYPE_NONE,\n TYPE_INTERFACE,\n TYPE_CHAR,\n TYPE_UCHAR,\n TYPE_BOOLEAN,\n TYPE_INT,\n TYPE_UINT,\n TYPE_LONG,\n TYPE_ULONG,\n TYPE_INT64,\n TYPE_UINT64,\n TYPE_ENUM,\n TYPE_FLAGS,\n TYPE_FLOAT,\n TYPE_DOUBLE,\n TYPE_STRING,\n TYPE_POINTER,\n TYPE_BOXED,\n TYPE_PARAM,\n TYPE_OBJECT,\n TYPE_GTYPE,\n TYPE_VARIANT,\n TYPE_UNICHAR,\n getErrorType,\n getStrvType,\n isResolvableDescriptor,\n isTypedClass,\n typeIsA,\n typeParent,\n typeInterfaces,\n typeFromName,\n typeFundamental,\n typeName,\n valueIsA,\n resolveType,\n resolveBoxedType,\n resolveFundamentalType,\n resolveDescriptorType,\n type ResolvableDescriptor,\n type TypedClass,\n};\n"]}
@@ -0,0 +1,29 @@
1
+ import { type Descriptor, type ExternalObject, type Handle } from "@gtkx/native";
2
+ declare function getValueType(value: ExternalObject<Handle>): bigint;
3
+ declare function copyValue(dest: ExternalObject<Handle>, src: ExternalObject<Handle>): void;
4
+ /**
5
+ * Reads the boxed pointer out of a GValue and returns it wrapped in its registered
6
+ * class, or null when the value does not hold a boxed type.
7
+ */
8
+ declare function getBoxedValue(value: ExternalObject<Handle>): object | null;
9
+ /** Stores a boxed object, or null, into a GValue that holds a boxed type. */
10
+ declare function setBoxedValue(value: ExternalObject<Handle>, boxed: object | null): void;
11
+ /**
12
+ * Stores a JavaScript value into an already-initialized GValue, converting it to
13
+ * whatever type the GValue holds.
14
+ *
15
+ * @param value The initialized GValue to write into.
16
+ * @param jsValue The JavaScript value to store.
17
+ */
18
+ declare function intoValue(value: ExternalObject<Handle>, jsValue: unknown): void;
19
+ declare function toValue(descriptor: Descriptor, value: unknown): ExternalObject<Handle>;
20
+ declare function fromValue(value: ExternalObject<Handle>): unknown;
21
+ declare function newValueForDescriptor(descriptor: Descriptor): ExternalObject<Handle>;
22
+ declare function outValueForDescriptor(descriptor: Descriptor, initial?: unknown): {
23
+ value: ExternalObject<Handle>;
24
+ read: () => unknown;
25
+ };
26
+ declare function outValueForBoxedDescriptor(descriptor: Descriptor, boxed: object): ExternalObject<Handle>;
27
+ declare function inoutValueForBoxedDescriptor(descriptor: Descriptor, boxed: object): ExternalObject<Handle>;
28
+ export { getValueType, intoValue, copyValue, getBoxedValue, setBoxedValue, toValue, fromValue, newValueForDescriptor, outValueForDescriptor, outValueForBoxedDescriptor, inoutValueForBoxedDescriptor, };
29
+ //# sourceMappingURL=value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value.d.ts","sourceRoot":"","sources":["../src/value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,UAAU,EAAE,KAAK,cAAc,EAAW,KAAK,MAAM,EAAe,MAAM,cAAc,CAAC;AAmL9G,iBAAS,YAAY,CAAC,KAAK,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG,MAAM,CAE3D;AAED,iBAAS,SAAS,CAAC,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,cAA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