esbuild-plugin-kaitai
Version:
An esbuild plugin for importing Kaitai Struct files.
44 lines (43 loc) • 1.6 kB
TypeScript
import type { OnLoadResult } from 'esbuild';
/**
* Options for running a kaitai compiler from it's js api.
*/
export interface KaitaiApiOptions {
compiler: Compiler;
fileLoader?: FileLoader;
debug?: boolean;
}
/**
* The api interface for loading a file.
*/
export interface FileLoader {
/**
* Loads a Kaitai source file.
* The default file loader reads files from the local filesystem and parses
* them as YAML, but you can override this if you want to use a different
* source or data format.
* @param filePath The path to the file.
* @param mode Indicates if the file path is relative ("rel") or absolute ("abs").
*/
importYaml(filePath: string, mode: 'rel' | 'abs'): Promise<unknown>;
}
/**
* The api interface for a Kaitai compiler.
*/
export interface Compiler {
/**
* Compiles the Kaitai source into a parser.
* @param language The language to compile to.
* @param data The Kaitai source data.
* @param fileLoader (optional) The file loader to use to resolve imports.
* @param debugMode (optional) Enables debug mode.
*/
compile(language: string, data: unknown, fileLoader?: FileLoader | null | undefined, debugMode?: boolean | null | undefined): Promise<Record<string, string>>;
}
/**
* Compiles a ksy file with the given API compiler.
* @param filePath The path to the file to compile.
* @param options The compilation options.
* @returns The results of the compilation.
*/
export declare function compileKaitaiApi(filePath: string, options: KaitaiApiOptions): Promise<OnLoadResult>;