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

Function extractFromTs

packages/cli/src/utils/utils.ts:190–218  ·  view source on GitHub ↗
(
  manifest: string,
  patterns: {[key: string]: RegExp | undefined}
)

Source from the content-addressed store, hash-verified

188}
189
190export function extractFromTs(
191 manifest: string,
192 patterns: {[key: string]: RegExp | undefined}
193): {[key: string]: string | string[] | null} {
194 const result: {[key: string]: string | string[] | null} = {};
195 // TODO should extract then validate value type ?
196 // check what the following char is after key
197 const arrKeys = ['endpoint', 'topics'];
198 const nestArr = ['dataSources', 'handlers'];
199 for (const key in patterns) {
200 if (!nestArr.includes(key)) {
201 const regExp = patterns[key];
202 assert(regExp, `Pattern for ${key} is not defined`);
203 const match = manifest.match(regExp);
204
205 if (arrKeys.includes(key) && match) {
206 const inputStr = match[1].replace(/`/g, '"');
207 const jsonOutput = JSON5.parse(inputStr);
208 result[key] = Array.isArray(jsonOutput) ? jsonOutput : [jsonOutput];
209 } else {
210 result[key] = match ? match[1] : null;
211 }
212 } else {
213 result[key] = extractArrayValueFromTsManifest(manifest, key);
214 }
215 }
216
217 return result;
218}
219
220export function splitArrayString(arrayStr: string): string[] {
221 // Remove the starting and ending square brackets

Callers 6

readDefaultsFunction · 0.90
tsExtractorFunction · 0.90
generateManifestTsFunction · 0.90
generateAdapterFunction · 0.90

Calls 1

Tested by

no test coverage detected