| 16 | * Wrapper to load the graph |
| 17 | */ |
| 18 | export default class GraphManager { |
| 19 | manifestUrl?: string; |
| 20 | gzippedManifestUrl?: string; |
| 21 | classInfoUrl?: string; |
| 22 | |
| 23 | componentSet: ComponentSet = { components: [] }; |
| 24 | classInfo?: { [key: string]: ClassInfo }; |
| 25 | |
| 26 | // Caches to speed up graph-based operations |
| 27 | private nodeMap: { [componentName: string]: { [key: string]: Node } } = {}; |
| 28 | private componentMap: { [componentName: string]: Component } = {}; |
| 29 | private provisionsToExposingComponentsMap: { [key: string]: Array<string> } = {}; |
| 30 | private subcomponentWeights: { [key: string]: Weight } = {}; |
| 31 | private callsitesMap: { |
| 32 | [componentName: string]: { [key: string]: Node[] }; |
| 33 | } = {}; |
| 34 | |
| 35 | async loadUrl(manifestUrl: string, gzippedManifestUrl: string): Promise<boolean> { |
| 36 | let classInfoUrl = manifestUrl.substring(0, manifestUrl.lastIndexOf("\/") + 1) + "ClassInfo.json"; |
| 37 | |
| 38 | try { |
| 39 | let classInfoResponse = await axios.get(classInfoUrl); |
| 40 | this.classInfo = classInfoResponse.data as { [key: string]: ClassInfo }; |
| 41 | } catch { |
| 42 | // classInfo is optional |
| 43 | } |
| 44 | try { |
| 45 | try { |
| 46 | let manifestResponse = await axios.get(manifestUrl) |
| 47 | this.componentSet = manifestResponse.data as ComponentSet; |
| 48 | } catch { |
| 49 | let manifestResponse = await axios.get(gzippedManifestUrl, {responseType: 'arraybuffer', 'decompress': true }) |
| 50 | this.componentSet = JSON.parse(pako.inflate(manifestResponse.data, { to: 'string' })) as ComponentSet; |
| 51 | } |
| 52 | this.populateCaches(); |
| 53 | } catch { |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | this.manifestUrl = manifestUrl; |
| 58 | this.gzippedManifestUrl = gzippedManifestUrl; |
| 59 | this.classInfoUrl = classInfoUrl; |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | async loadFile(manifestFile: File): Promise<boolean> { |
| 64 | let manifestResponse = await this.readFileAsync(manifestFile) |
| 65 | this.componentSet = JSON.parse(manifestResponse) as ComponentSet; |
| 66 | this.populateCaches(); |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | async readFileAsync(file: File): Promise<string> { |
| 71 | return new Promise((resolve, reject) => { |
| 72 | const reader = new FileReader(); |
| 73 | reader.onload = () => { |
| 74 | resolve(reader.result as string); |
| 75 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected