typir
Version:
General purpose type checking library
55 lines • 3 kB
TypeScript
/******************************************************************************
* Copyright 2024 TypeFox GmbH
* This program and the accompanying materials are made available under the
* terms of the MIT License, which is available in the project root.
******************************************************************************/
import { EdgeCachingInformation } from '../services/caching.js';
import { TypeEdge } from './type-edge.js';
import { Type } from './type-node.js';
/**
* Each Typir instance has one single type graph.
* Each type exists only once and is stored inside this type graph.
*
* Edges with different meaning/purpose will exist in parallel inside the same graph,
* otherwise nodes/types need to be duplicated or would be used in multiple graphs.
* Graph algorithms will need to filter the required edges regarding $relation.
*/
export declare class TypeGraph {
protected readonly nodes: Map<string, Type>;
protected readonly edges: TypeEdge[];
protected readonly listeners: TypeGraphListener[];
/**
* Usually this method is called by kinds after creating a corresponding type.
* Therefore it is usually not needed to call this method in an other context.
* @param type the new type
* @param key an optional key to register the type, since it is allowed to register the same type with different keys in the graph
*/
addNode(type: Type, key?: string): void;
/**
* When removing a type/node, all its edges (incoming and outgoing) are removed as well.
* Design decision:
* This is the central API call to remove a type from the type system in case that it is no longer valid/existing/needed.
* It is not required to directly inform the kind of the removed type yourself, since the kind itself will take care of removed types.
* @param typeToRemove the type to remove
* @param key an optional key to register the type, since it is allowed to register the same type with different keys in the graph
*/
removeNode(typeToRemove: Type, key?: string): void;
getNode(key: string): Type | undefined;
getType(key: string): Type | undefined;
getAllRegisteredTypes(): Type[];
addEdge(edge: TypeEdge): void;
removeEdge(edge: TypeEdge): void;
getUnidirectionalEdge<T extends TypeEdge>(from: Type, to: Type, $relation: T['$relation'], cachingMode?: EdgeCachingInformation): T | undefined;
getBidirectionalEdge<T extends TypeEdge>(from: Type, to: Type, $relation: T['$relation'], cachingMode?: EdgeCachingInformation): T | undefined;
addListener(listener: TypeGraphListener, options?: {
callOnAddedForAllExisting: boolean;
}): void;
removeListener(listener: TypeGraphListener): void;
}
export type TypeGraphListener = Partial<{
onAddedType(type: Type, key: string): void;
onRemovedType(type: Type, key: string): void;
onAddedEdge(edge: TypeEdge): void;
onRemovedEdge(edge: TypeEdge): void;
}>;
//# sourceMappingURL=type-graph.d.ts.map