@protobuf-ts/plugin-framework
Version:
framework to create protoc plugins
61 lines (60 loc) • 2.54 kB
TypeScript
import { AnyTypeDescriptorProto } from "./descriptor-info";
import { GeneratedFile } from "./generated-file";
/**
* A table for unique symbols (for any DescriptorProto, EnumDescriptorProto
* or ServiceDescriptorProto) in files (GeneratedFile).
*/
export declare class SymbolTable {
private readonly entries;
private readonly clashResolveMaxTries;
private readonly clashResolver;
constructor(clashResolver?: ClashResolver);
/**
* Register a symbol in the given file for the given descriptor.
*
* If the name is already taken in the file, an alternative name
* is automatically generated by appending '$' and a running
* number to the requested name. You can change the behaviour by
* providing your own `clashResolver`.
*
* Only one symbol per kind can be registered for a descriptor.
*
* If you want to generate an interface *and* a class for a
* message, use a different `kind` for each.
*
* Returns the actual name registered.
*/
register(requestedName: string, descriptor: AnyTypeDescriptorProto, file: GeneratedFile, kind?: string): string;
/**
* Find a symbol (of the given kind) for the given descriptor.
* Return `undefined` if not found.
*/
find(descriptor: AnyTypeDescriptorProto, kind?: string): SymbolTableEntry | undefined;
/**
* Find a symbol (of the given kind) for the given descriptor.
* Raises error if not found.
*/
get(descriptor: AnyTypeDescriptorProto, kind?: string): SymbolTableEntry;
/**
* Is a name (of the given kind) registered for the the given descriptor?
*/
has(descriptor: AnyTypeDescriptorProto, kind?: string): boolean;
/**
* List all names of any kind registered in the given file.
*/
list(file: GeneratedFile): SymbolTableEntry[];
/**
* List all names of the given kind registered in the given file.
*/
list(file: GeneratedFile, kind: string): SymbolTableEntry[];
protected hasNameInFile: (name: string, file: GeneratedFile) => boolean;
static defaultClashResolver(descriptor: AnyTypeDescriptorProto, file: GeneratedFile, requestedName: string, kind: string, tryCount: number): string;
}
interface SymbolTableEntry {
file: GeneratedFile;
descriptor: AnyTypeDescriptorProto;
name: string;
kind: string;
}
declare type ClashResolver = (descriptor: AnyTypeDescriptorProto, file: GeneratedFile, requestedName: string, kind: string, tryCount: number, failedName: string) => string;
export {};