@ts-for-gir/lib
Version:
Typescript .d.ts generator from GIR for gjs
229 lines (228 loc) • 10.8 kB
TypeScript
import { TypeIdentifier, Generic } from "../gir.js";
import { TypeExpression } from "../gir.js";
import { IntrospectedBase, IntrospectedClassMember, IntrospectedNamespaceMember, Options } from "./base.js";
import { ClassStructTypeIdentifier, type GirInterfaceElement, type GirClassElement, type GirRecordElement, type GirUnionElement } from "../index.js";
import { IntrospectedClassFunction, IntrospectedVirtualClassFunction, IntrospectedStaticClassFunction, IntrospectedConstructor, IntrospectedDirectAllocationConstructor, IntrospectedClassCallback } from "./function.js";
import { IntrospectedProperty, IntrospectedField } from "./property.js";
import { IntrospectedNamespace } from "./namespace.js";
import { IntrospectedSignal } from "./signal.js";
import { FormatGenerator } from "../generators/generator.js";
import { GirVisitor } from "../visitor.js";
import type { OptionsLoad } from "../types/index.js";
export declare enum FilterBehavior {
DELETE = 0,
PRESERVE = 1
}
export declare function filterConflicts<T extends IntrospectedClassMember | IntrospectedClassFunction | IntrospectedProperty>(ns: IntrospectedNamespace, c: IntrospectedBaseClass, elements: T[], behavior?: FilterBehavior): T[];
export declare function filterFunctionConflict<T extends IntrospectedStaticClassFunction | IntrospectedVirtualClassFunction | IntrospectedClassFunction | IntrospectedConstructor>(ns: IntrospectedNamespace, base: IntrospectedBaseClass, elements: T[], conflict_ids: string[]): T[];
export declare const enum ClassInjectionMember {
MEMBER = "member",
CONSTRUCTOR = "_constructor",
PROPERTY = "prop",
FIELD = "field",
MAIN_CONSTRUCTOR = "constructor"
}
export interface ClassDefinition {
superType: TypeIdentifier;
interfaces: TypeIdentifier[];
mainConstructor: IntrospectedConstructor;
constructors: IntrospectedConstructor[];
members: IntrospectedClassFunction[];
props: IntrospectedProperty[];
fields: IntrospectedField[];
callbacks: IntrospectedClassCallback[];
}
export interface ResolutionNode {
identifier: TypeIdentifier;
node: IntrospectedBaseClass;
}
export interface InterfaceResolution extends ResolutionNode, Iterable<InterfaceResolution | ClassResolution> {
extends(): InterfaceResolution | ClassResolution | undefined;
node: IntrospectedInterface;
}
export interface ClassResolution extends ResolutionNode, Iterable<ClassResolution> {
extends(): ClassResolution | undefined;
implements(): InterfaceResolution[];
node: IntrospectedClass;
}
export interface RecordResolution extends ResolutionNode, Iterable<RecordResolution> {
extends(): RecordResolution | undefined;
node: IntrospectedRecord;
}
export declare abstract class IntrospectedBaseClass extends IntrospectedNamespaceMember {
/**
* Used to add a TypeScript index signature to a class
*
* NOTE: This should probably be migrated into the TypeScript generator itself.
*/
__ts__indexSignature?: string;
superType: TypeIdentifier | null;
mainConstructor: null | IntrospectedConstructor | IntrospectedDirectAllocationConstructor;
constructors: IntrospectedConstructor[];
members: IntrospectedClassFunction[];
props: IntrospectedProperty[];
fields: IntrospectedField[];
callbacks: IntrospectedClassCallback[];
generics: Generic[];
constructor(options: Options<{
name: string;
namespace: IntrospectedNamespace;
}> & Partial<ClassDefinition>);
abstract accept(visitor: GirVisitor): IntrospectedBaseClass;
abstract copy(options?: {
parent?: undefined;
constructors?: IntrospectedConstructor[];
members?: IntrospectedClassFunction[];
props?: IntrospectedProperty[];
fields?: IntrospectedField[];
callbacks?: IntrospectedClassCallback[];
}): IntrospectedBaseClass;
getGenericName: () => string;
abstract resolveParents(): RecordResolution | InterfaceResolution | ClassResolution;
abstract someParent(predicate: (b: IntrospectedBaseClass) => boolean): boolean;
abstract findParent(predicate: (b: IntrospectedBaseClass) => boolean): IntrospectedBaseClass | undefined;
abstract findParentMap<K>(predicate: (b: IntrospectedBaseClass) => K | undefined): K | undefined;
addGeneric(definition: {
deriveFrom?: TypeIdentifier;
default?: TypeExpression;
constraint?: TypeExpression;
propagate?: boolean;
}): void;
getType(): TypeIdentifier;
static fromXML(element: GirClassElement | GirInterfaceElement | GirRecordElement, ns: IntrospectedNamespace, options: OptionsLoad): IntrospectedBaseClass;
abstract asString<T = string>(generator: FormatGenerator<T>): T;
}
type ClassMember = IntrospectedClassMember | IntrospectedClassFunction | IntrospectedProperty;
export declare class IntrospectedClass extends IntrospectedBaseClass {
signals: IntrospectedSignal[];
interfaces: TypeIdentifier[];
isAbstract: boolean;
mainConstructor: null | IntrospectedConstructor;
private _staticDefinition;
constructor(name: string, namespace: IntrospectedNamespace);
/**
* Returns all signals for this class including:
* - Explicit signals defined on the class
* - Property notification signals (notify::property-name) for GObject-derived classes
* - Detailed signal variants for properties (signal-name::property-name)
*/
getAllSignals(): Array<{
name: string;
signal?: IntrospectedSignal;
isNotifySignal?: boolean;
isDetailSignal?: boolean;
parameterTypes?: string[];
returnType?: string;
}>;
/**
* Returns all properties for this class including inherited and implemented properties
*/
private getAllProperties;
accept(visitor: GirVisitor): IntrospectedClass;
hasInstanceSymbol<S extends {
name: string;
}>(s: S): boolean;
someParent(predicate: (p: IntrospectedClass | IntrospectedInterface) => boolean): boolean;
findParent(predicate: (p: IntrospectedClass | IntrospectedInterface) => boolean): IntrospectedClass | IntrospectedInterface | undefined;
findParentMap<K>(predicate: (p: IntrospectedClass | IntrospectedInterface) => K | undefined): K | undefined;
implementedProperties(potentialConflicts?: IntrospectedBase<never>[]): IntrospectedProperty[];
implementedMethods(potentialConflicts?: ClassMember[]): IntrospectedClassFunction<IntrospectedBaseClass | import("./enum.js").IntrospectedEnum>[];
resolveParents(): ClassResolution;
copy(options?: {
parent?: undefined;
signals?: IntrospectedSignal[];
constructors?: IntrospectedConstructor[];
members?: IntrospectedClassFunction[];
props?: IntrospectedProperty[];
fields?: IntrospectedField[];
callbacks?: IntrospectedClassCallback[];
}): IntrospectedClass;
get staticDefinition(): string | null;
static fromXML(element: GirClassElement, ns: IntrospectedNamespace, options: OptionsLoad): IntrospectedClass;
registerStaticDefinition(typeStruct: string): void;
asString<T extends FormatGenerator<unknown>>(generator: T): ReturnType<T["generateClass"]>;
}
export declare class IntrospectedRecord extends IntrospectedBaseClass {
private _isForeign;
private _structFor;
private _isSimple;
private _isSimpleWithoutPointers;
/**
* Returns all signals for this record (records typically don't have signals)
*/
getAllSignals(): Array<{
name: string;
signal?: IntrospectedSignal;
isNotifySignal?: boolean;
isDetailSignal?: boolean;
parameterTypes?: string[];
returnType?: string;
}>;
isForeign(): boolean;
get structFor(): ClassStructTypeIdentifier | null;
getType(): TypeIdentifier;
someParent(predicate: (p: IntrospectedRecord) => boolean): boolean;
findParent(predicate: (p: IntrospectedRecord) => boolean): IntrospectedRecord | undefined;
findParentMap<K>(predicate: (p: IntrospectedRecord) => K | undefined): K | undefined;
accept(visitor: GirVisitor): IntrospectedRecord;
resolveParents(): RecordResolution;
copy(options?: {
parent?: undefined;
constructors?: IntrospectedConstructor[];
members?: IntrospectedClassFunction[];
props?: IntrospectedProperty[];
fields?: IntrospectedField[];
callbacks?: IntrospectedClassCallback[];
}): IntrospectedRecord;
static foreign(name: string, namespace: IntrospectedNamespace): IntrospectedRecord;
static fromXML(element: GirRecordElement | GirUnionElement, namespace: IntrospectedNamespace, options: OptionsLoad): IntrospectedRecord;
/**
* Calculate if a type expression is "simple" without pointers
*/
isSimpleTypeWithoutPointers(typeContainer: TypeExpression): boolean;
/**
* Calculate if a type expression is "simple"
*/
isSimpleType(typeContainer: TypeExpression): boolean;
/**
* Check if a record is "simple" and can be constructed by GJS
*/
isSimple(): boolean;
isSimpleWithoutPointers(): string | null;
asString<T extends FormatGenerator<unknown>>(generator: T): ReturnType<T["generateRecord"]>;
}
export declare class GirComplexRecord extends IntrospectedRecord {
isSimple(): boolean;
}
export declare class IntrospectedInterface extends IntrospectedBaseClass {
noParent: boolean;
mainConstructor: null | IntrospectedConstructor;
/**
* Returns all signals for this interface (most interfaces don't have signals, but some might)
*/
getAllSignals(): Array<{
name: string;
signal?: IntrospectedSignal;
isNotifySignal?: boolean;
isDetailSignal?: boolean;
parameterTypes?: string[];
returnType?: string;
}>;
copy(options?: {
parent?: undefined;
noParent?: boolean;
constructors?: IntrospectedConstructor[];
members?: IntrospectedClassFunction[];
props?: IntrospectedProperty[];
fields?: IntrospectedField[];
callbacks?: IntrospectedClassCallback[];
}): IntrospectedInterface;
someParent(predicate: (p: IntrospectedClass | IntrospectedInterface) => boolean): boolean;
findParent(predicate: (p: IntrospectedClass | IntrospectedInterface) => boolean): IntrospectedInterface | IntrospectedClass | undefined;
findParentMap<K>(predicate: (p: IntrospectedClass | IntrospectedInterface) => K | undefined): K | undefined;
resolveParents(): InterfaceResolution;
accept(visitor: GirVisitor): IntrospectedInterface;
static fromXML(element: GirInterfaceElement, namespace: IntrospectedNamespace, options: OptionsLoad): IntrospectedInterface;
asString<T extends FormatGenerator<unknown>>(generator: T): ReturnType<T["generateInterface"]>;
}
export {};