From 2b28915710b9202088b7eecfce340ea1622aa6fe Mon Sep 17 00:00:00 2001 From: Pascal Garber Date: Fri, 8 Nov 2024 09:17:04 +0100 Subject: [PATCH] Add Requires property to MetaInfo, fixes #166 --- .../templates/gobject-2.0.d.ts | 140 +++++++++--------- 1 file changed, 74 insertions(+), 66 deletions(-) diff --git a/packages/generator-typescript/templates/gobject-2.0.d.ts b/packages/generator-typescript/templates/gobject-2.0.d.ts index 2a82aca7..df22ff21 100644 --- a/packages/generator-typescript/templates/gobject-2.0.d.ts +++ b/packages/generator-typescript/templates/gobject-2.0.d.ts @@ -1,4 +1,4 @@ -// A few things here are inspired by gi.ts +// A few things here are inspired by gi.ts // See https://gitlab.gnome.org/ewlsh/gi.ts/-/blob/master/packages/lib/src/generators/dts/gobject.ts // Copyright Evan Welsh @@ -6,7 +6,7 @@ export type GType = { __type__(arg: never): T name: string -}; +} // Extra interfaces used to help define GObject classes in js; these // aren't part of gi. @@ -27,17 +27,18 @@ export interface MetaInfo { Template?: Uint8Array | GLib.Bytes | string Children?: string[] InternalChildren?: string[] + Requires?: Object[] } // Correctly types interface checks. -export function type_is_a(obj: Object, is_a_type: { $gtype: GType }): obj is T; +export function type_is_a(obj: Object, is_a_type: { $gtype: GType }): obj is T export class Interface { - static _classInit: (cls: any) => any; - __name__: string; - _construct: (params: any, ...otherArgs: any[]) => any; - _init: (params: any) => void; - $gtype?: GType; + static _classInit: (cls: any) => any + __name__: string + _construct: (params: any, ...otherArgs: any[]) => any + _init: (params: any) => void + $gtype?: GType } /** @@ -48,60 +49,60 @@ export class NotImplementedError extends Error { get name(): 'NotImplementedError' } -export const __gtkCssName__: unique symbol; -export const __gtkTemplate__: unique symbol; -export const __gtkChildren__: unique symbol; -export const __gtkInternalChildren__: unique symbol; +export const __gtkCssName__: unique symbol +export const __gtkTemplate__: unique symbol +export const __gtkChildren__: unique symbol +export const __gtkInternalChildren__: unique symbol // Expose GObject static properties for ES6 classes -export const GTypeName: unique symbol; -export const requires: unique symbol; -export const interfaces: unique symbol; -export const properties: unique symbol; -export const signals: unique symbol; +export const GTypeName: unique symbol +export const requires: unique symbol +export const interfaces: unique symbol +export const properties: unique symbol +export const signals: unique symbol -export let gtypeNameBasedOnJSPath: boolean; +export let gtypeNameBasedOnJSPath: boolean -export let TYPE_BOOLEAN: GType; -export let Boolean: BooleanConstructor; +export let TYPE_BOOLEAN: GType +export let Boolean: BooleanConstructor -export let TYPE_ENUM: GType; -export let TYPE_FLAGS: GType; +export let TYPE_ENUM: GType +export let TYPE_FLAGS: GType -export let TYPE_DOUBLE: GType; -export let Double: NumberConstructor; +export let TYPE_DOUBLE: GType +export let Double: NumberConstructor -export let TYPE_STRING: GType; -export let String: StringConstructor; +export let TYPE_STRING: GType +export let String: StringConstructor -export let TYPE_NONE: GType; -export let TYPE_POINTER: GType; -export let TYPE_BOXED: GType; -export let TYPE_PARAM: GType; -export let TYPE_INTERFACE: GType; -export let TYPE_OBJECT: GType; -export let TYPE_JSOBJECT: GType; -export let TYPE_VARIANT: GType; -export let TYPE_INT: GType; -export let TYPE_UINT: GType; -export let TYPE_INT64: GType; -export let TYPE_UINT64: GType; +export let TYPE_NONE: GType +export let TYPE_POINTER: GType +export let TYPE_BOXED: GType +export let TYPE_PARAM: GType +export let TYPE_INTERFACE: GType +export let TYPE_OBJECT: GType +export let TYPE_JSOBJECT: GType +export let TYPE_VARIANT: GType +export let TYPE_INT: GType +export let TYPE_UINT: GType +export let TYPE_INT64: GType +export let TYPE_UINT64: GType // fake enum for signal accumulators, keep in sync with gi/object.c export enum AccumulatorType { - NONE=0, - FIRST_WINS=1, - TRUE_HANDLED=2, + NONE = 0, + FIRST_WINS = 1, + TRUE_HANDLED = 2, } // A simple workaround if you have a class with .connect, .disconnect or .emit // methods (such as Gio.Socket.connect or NMClient.Device.disconnect) // The original g_signal_* functions are not introspectable anyway, because // we need our own handling of signal argument marshalling -export function signal_connect(object: Object, name: string, handler: (...args: any[]) => any): number; -export function signal_connect_after(object: Object, name: string, handler: (...args: any[]) => any): number; -export function signal_emit_by_name(object: Object, name: string, ...args: any[]): void; +export function signal_connect(object: Object, name: string, handler: (...args: any[]) => any): number +export function signal_connect_after(object: Object, name: string, handler: (...args: any[]) => any): number +export function signal_emit_by_name(object: Object, name: string, ...args: any[]): void /** * Finds the first signal handler that matches certain selection criteria. @@ -116,7 +117,10 @@ export function signal_emit_by_name(object: Object, name: string, ...args: any[] * @param match.func the callback function the handler will invoke. * @returns A valid non-0 signal handler ID for a successful match. */ -export function signal_handler_find(instance: Object, match: {signalId: string, detail: string, func: (...args: any[]) => any}): number | bigint | object | null +export function signal_handler_find( + instance: Object, + match: { signalId: string; detail: string; func: (...args: any[]) => any }, +): number | bigint | object | null /** * Blocks all handlers on an instance that match certain selection criteria. @@ -132,7 +136,10 @@ export function signal_handler_find(instance: Object, match: {signalId: string, * @param match.func the callback function the handler will invoke. * @returns The number of handlers that matched. */ -export function signal_handlers_block_matched(instance: Object, match: {signalId: string, detail: string, func: (...args: any[]) => any}): number +export function signal_handlers_block_matched( + instance: Object, + match: { signalId: string; detail: string; func: (...args: any[]) => any }, +): number /** * Disconnects all handlers on an instance that match certain selection @@ -150,7 +157,10 @@ export function signal_handlers_block_matched(instance: Object, match: {signalId * @param match.func the callback function the handler will invoke. * @returns The number of handlers that matched. */ -export function signal_handlers_unblock_matched(instance: Object, match: {signalId: string, detail: string, func: (...args: any[]) => any}): number +export function signal_handlers_unblock_matched( + instance: Object, + match: { signalId: string; detail: string; func: (...args: any[]) => any }, +): number /** * Disconnects all handlers on an instance that match certain selection @@ -168,7 +178,10 @@ export function signal_handlers_unblock_matched(instance: Object, match: {signal * @param match.func the callback function the handler will invoke. * @returns The number of handlers that matched. */ -export function signal_handlers_disconnect_matched(instance: Object, match: {signalId: string, detail: string, func: (...args: any[]) => any}): number +export function signal_handlers_disconnect_matched( + instance: Object, + match: { signalId: string; detail: string; func: (...args: any[]) => any }, +): number // Also match the macros used in C APIs, even though they're not introspected @@ -179,7 +192,7 @@ export function signal_handlers_disconnect_matched(instance: Object, match: {sig * @param func the callback function the handler will invoke. * @returns The number of handlers that matched. */ -export function signal_handlers_block_by_func(instance: Object, func: (...args: any[]) => any): number; +export function signal_handlers_block_by_func(instance: Object, func: (...args: any[]) => any): number /** * Unblocks all handlers on an instance that match `func`. @@ -189,7 +202,7 @@ export function signal_handlers_block_by_func(instance: Object, func: (...args: * @param func the callback function the handler will invoke. * @returns The number of handlers that matched. */ -export function signal_handlers_unblock_by_func(instance: Object, func: (...args: any[]) => any): number; +export function signal_handlers_unblock_by_func(instance: Object, func: (...args: any[]) => any): number /** * Disconnects all handlers on an instance that match `func`. @@ -198,17 +211,15 @@ export function signal_handlers_unblock_by_func(instance: Object, func: (...args * @param func the callback function the handler will invoke. * @returns The number of handlers that matched. */ -export function signal_handlers_disconnect_by_func(instance: Object, func: (...args: any[]) => any): number; -export function signal_handlers_disconnect_by_data(): void; +export function signal_handlers_disconnect_by_func(instance: Object, func: (...args: any[]) => any): number +export function signal_handlers_disconnect_by_data(): void -export type Property = K extends ParamSpec - ? T - : any; +export type Property = K extends ParamSpec ? T : any -// TODO: What about the generated class Closure -export type TClosure = (...args: P[]) => R; +// TODO: What about the generated class Closure +export type TClosure = (...args: P[]) => R -type ObjectConstructor = { new(...args: any[]): Object }; +type ObjectConstructor = { new (...args: any[]): Object } export function registerClass< T extends ObjectConstructor, @@ -216,13 +227,10 @@ export function registerClass< Interfaces extends { $gtype: GType }[], Sigs extends { [key: string]: { - param_types?: readonly GType[]; - [key: string]: any; - }; - } ->( - options: MetaInfo, - cls: T -): T; + param_types?: readonly GType[] + [key: string]: any + } + }, +>(options: MetaInfo, cls: T): T export function registerClass(cls: T): T