MCPcopy
hub / github.com/subquery/subql / generateJsonInterfaces

Function generateJsonInterfaces

packages/cli/src/controller/codegen-controller.ts:70–98  ·  view source on GitHub ↗
(projectPath: string, schema: string)

Source from the content-addressed store, hash-verified

68}
69
70export async function generateJsonInterfaces(projectPath: string, schema: string): Promise<void> {
71 const typesDir = path.join(projectPath, TYPE_ROOT_DIR);
72 const jsonObjects = getAllJsonObjects(schema);
73 const jsonInterfaces = jsonObjects.map((r) => {
74 const object = setJsonObjectType(r, jsonObjects);
75 const fields = processFields('jsonField', object.name, object.fields);
76 return {
77 interfaceName: object.name,
78 fields,
79 };
80 });
81
82 if (jsonInterfaces.length !== 0) {
83 const interfaceTemplate = {
84 props: {
85 jsonInterfaces,
86 },
87 helper: {
88 upperFirst,
89 },
90 };
91 try {
92 await renderTemplate(INTERFACE_TEMPLATE_PATH, path.join(typesDir, `interfaces.ts`), interfaceTemplate);
93 exportTypes.interfaces = true;
94 } catch (e) {
95 throw new Error(`Codegen failed for json interface.`, {cause: e});
96 }
97 }
98}
99
100export async function generateEnums(projectPath: string, schema: string): Promise<void> {
101 const typesDir = path.join(projectPath, TYPE_ROOT_DIR);

Callers 1

generateSchemaModelsFunction · 0.85

Calls 5

getAllJsonObjectsFunction · 0.90
setJsonObjectTypeFunction · 0.90
renderTemplateFunction · 0.90
processFieldsFunction · 0.85
mapMethod · 0.80

Tested by

no test coverage detected