@pact-toolbox/unplugin
Version:
214 lines (212 loc) • 6.53 kB
text/typescript
import { SyntaxNode } from "tree-sitter";
//#region src/transformer/parameter.d.ts
/**
* Represents a parameter (used in functions and capabilities).
*/
declare class PactParameter {
node: SyntaxNode;
module: PactModule;
name: string;
type: string;
constructor(node: SyntaxNode, module: PactModule);
}
//#endregion
//#region src/transformer/function.d.ts
declare function getRequiredCapabilities(node: SyntaxNode): string[];
/**
* Represents a Pact function.
*/
declare class PactFunction {
node: SyntaxNode;
module: PactModule;
name: string;
path: string;
parameters: PactParameter[];
returnType: string;
requiredCapabilities: string[];
doc: string;
constructor(node: SyntaxNode, module: PactModule);
}
//#endregion
//#region src/transformer/schema.d.ts
/**
* Represents a field within a schema.
*/
declare class PactSchemaField {
node: SyntaxNode;
module: PactModule;
name: string;
type: string;
constructor(node: SyntaxNode, module: PactModule);
}
/**
* Represents a Pact schema.
*/
declare class PactSchema {
node: SyntaxNode;
module: PactModule;
name: string;
fields: PactSchemaField[];
doc: string;
constructor(node: SyntaxNode, module: PactModule);
}
//#endregion
//#region src/transformer/module.d.ts
/**
* Represents a Pact module.
*/
declare class PactModule {
node: SyntaxNode;
namespace: string | undefined;
name: string;
governance: string;
functions: PactFunction[];
schemas: PactSchema[];
capabilities: PactCapability[];
doc: string;
path: string;
constructor(node: SyntaxNode, namespace: string | undefined);
getSchema(name: string): PactSchema | undefined;
getFunction(name: string): PactFunction | undefined;
getCapability(name: string): PactCapability | undefined;
}
//#endregion
//#region src/transformer/capability.d.ts
/**
* Represents a Pact capability.
*/
declare class PactCapability {
node: SyntaxNode;
module: PactModule;
name: string;
path: string;
parameters: PactParameter[];
returnType: string;
doc: string;
constructor(node: SyntaxNode, module: PactModule);
}
//#endregion
//#region src/transformer/codeGenerator.d.ts
interface CodeGenerator {
code: string;
types: string;
}
/**
* Generates JavaScript/TypeScript code for a Pact module.
* @param module The PactModule to generate code for.
* @returns The generated module code as a string.
*/
declare function generateModuleCode(module: PactModule, debug?: boolean): CodeGenerator;
/**
* Generates JavaScript/TypeScript code for a Pact function.
* @param func The PactFunction to generate code for.
* @returns The generated function code as a string.
*/
declare function generateFunctionCode(func: PactFunction, debug?: boolean): string;
/**
* Generates TypeScript type declarations for a Pact function.
* @param func The PactFunction to generate type declarations for.
* @returns The generated function types as a string.
*/
declare function generateFunctionTypes(func: PactFunction): string;
/**
* Generates TypeScript interface definitions for a Pact schema.
* @param schema The PactSchema to generate interface definitions for.
* @returns The generated schema types as a string.
*/
declare function generateSchemaTypes(schema: PactSchema): string;
//#endregion
//#region src/transformer/errors.d.ts
interface ErrorDetail {
message: string;
line: number;
column: number;
}
/**
* Custom error class for transformation errors.
*/
declare class TransformationError extends Error {
constructor(message: string);
}
/**
* Custom error class for parsing errors.
*/
declare class ParsingError extends TransformationError {
errors: ErrorDetail[];
constructor(message: string, errors: ErrorDetail[]);
}
//#endregion
//#region src/transformer/pactToJS.d.ts
interface PactModule$1 {
name: string;
path: string;
}
interface TransformationResult {
modules: PactModule$1[];
code: string;
types: string;
}
type PactToJSTransformer = (pactCode: string) => TransformationResult;
interface PactToJSTransformerOptions {
debug?: boolean;
}
declare function createPactToJSTransformer({
debug
}?: PactToJSTransformerOptions): PactToJSTransformer;
//#endregion
//#region src/transformer/transformer.d.ts
/**
* Class responsible for transforming Pact code into a custom AST and applying visitors.
*/
declare class PactTransformer {
private parser;
constructor();
/**
* Transforms the given Pact code into a custom AST and applies the provided visitors.
* @param pactCode The Pact code as a string.
* @param visitors Array of Visitor instances to apply during traversal.
* @returns The transformation result containing the AST.
*/
transform(pactCode: string): PactModule[];
/**
* Collects detailed error information from the syntax tree.
* @param root The root node of the syntax tree.
* @returns An array of error details.
*/
private collectErrors;
}
//#endregion
//#region src/transformer/utils.d.ts
/**
* Maps Pact types to TypeScript types.
* @param pactType The Pact type as a string.
* @param module The current module context.
* @returns The corresponding TypeScript type as a string.
*/
declare function pactTypeToTypescriptType(pactType: string, module: PactModule): string;
declare function getReturnTypeOf(node: SyntaxNode): string;
declare function getNamespaceOf(node: SyntaxNode): string | undefined;
/**
* Converts a multi-line string with backslashes into a JSDoc comment.
*
* @param {string} inputStr - The original multi-line string with backslashes.
* @returns {string} - The formatted JSDoc comment.
*
* @example
* const originalString = " Checks ACCOUNT for reserved name and returns type if \\
* \\ found or empty string. Reserved names start with a \\
* \\ single char and colon, e.g. 'c:foo', which would return 'c' as type.";
*
* console.log(convertToJsDoc(originalString));
*
* // Output:
* /**
* * Checks ACCOUNT for reserved name and returns type if
* * found or empty string. Reserved names start with a
* * single char and colon, e.g. 'c:foo', which would return 'c' as type.
* *\/
*/
declare function convertToJsDoc(inputStr?: string): string;
//#endregion
export { ErrorDetail, PactCapability, PactFunction, PactModule, PactParameter, PactSchema, PactSchemaField, PactTransformer, ParsingError, TransformationError, convertToJsDoc, createPactToJSTransformer, generateFunctionCode, generateFunctionTypes, generateModuleCode, generateSchemaTypes, getNamespaceOf, getRequiredCapabilities, getReturnTypeOf, pactTypeToTypescriptType };
//# sourceMappingURL=utils-4_F0qphL.d.cts.map