MCPcopy Create free account
hub / github.com/subquery/subql / getChainTypes

Function getChainTypes

packages/node/src/utils/project.ts:38–62  ·  view source on GitHub ↗
(
  reader: Reader,
  root: string,
  file: string,
)

Source from the content-addressed store, hash-verified

36}
37
38export async function getChainTypes(
39 reader: Reader,
40 root: string,
41 file: string,
42): Promise<ChainTypes> {
43 // If the project is load from local, we will direct load them
44 let raw: unknown;
45 if (reader instanceof LocalReader) {
46 raw = loadChainTypes(file, root);
47 } else {
48 // If it is stored in ipfs or other resources, we will use the corresponding reader to read the file
49 // Because ipfs not provide extension of the file, it is difficult to determine its format
50 // We will use yaml.load to try to load the script and parse them to supported chain types
51 // if it failed, we will give it another attempt, and assume the script written in js
52 // we will download it to a temp folder, and load them within sandbox
53 const res = await reader.getFile(file);
54 try {
55 raw = yaml.load(res);
56 } catch (e) {
57 const chainTypesPath = await saveFile(reader, root, file, res);
58 raw = loadChainTypesFromJs(chainTypesPath); //root not required, as it been packed in single js
59 }
60 }
61 return parseChainTypes(raw);
62}
63
64export function loadChainTypes(file: string, projectRoot: string): unknown {
65 const { ext } = path.parse(file);

Callers 1

createSubQueryProjectFunction · 0.90

Calls 5

saveFileFunction · 0.90
parseChainTypesFunction · 0.90
loadChainTypesFunction · 0.85
loadChainTypesFromJsFunction · 0.85
getFileMethod · 0.65

Tested by

no test coverage detected