genezio
Version:
Command line utility to interact with Genezio infrastructure.
37 lines (36 loc) • 1.33 kB
JavaScript
import { UserError } from "../../errors.js";
import { AstNodeType, MethodKindEnum, SourceType, } from "../../models/genezioModels.js";
export function mapDbAstToSdkGeneratorAst(ast) {
if (ast.version !== "2") {
throw new UserError("Cannot generate SDK due to unsupported version. Please update your genezio CLI tool, redeploy your project, and try again.");
}
const program = {
originalLanguage: "",
sourceType: SourceType.module,
body: [...ast.types],
};
const classDefinition = {
type: AstNodeType.ClassDefinition,
name: ast.name,
path: ast.path,
docString: ast.docString,
methods: ast.methods.map((method) => ({
type: AstNodeType.MethodDefinition,
name: method.name,
docString: method.docString,
params: method.params.map((param) => ({
type: AstNodeType.ParameterDefinition,
name: param.name,
rawType: "",
paramType: param.type,
optional: param.optional,
defaultValue: undefined,
})),
kind: MethodKindEnum.method,
static: false,
returnType: method.returnType,
})),
};
program.body?.push(classDefinition);
return program;
}