aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/apps/configurationApp/src/services/yangService.ts
blob: 17a4e43a7e053c6614d0209bdd8ed968e143246a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
type YangInfo = [string, (string | null | undefined)];

const cache: { [path: string]: string } = {

};

class YangService {

  public async getCapability(capability: string, version?: string) {
    const url = `/yang-schema/${capability}${version ? `/${version}` : ""}`;

    const cacheHit = cache[url];
    if (cacheHit) return cacheHit;

    const res = await fetch(url);
    const yangFile = res.ok && await res.text();
    if (yangFile !== false && yangFile !== null) {
      cache[url] = yangFile;
    }
    return yangFile;
  }
}

export const yangService = new YangService();
export default yangService;