@rcsb/rcsb-saguaro-app
Version:
RCSB 1D Saguaro Web App
82 lines • 3.66 kB
JavaScript
import { asyncScheduler } from "rxjs";
import resource from "../../RcsbServerConfig/web.resources.json";
//TODO are static attributes/methods safe in this case ?
//TODO change `XMLHttpRequest` to `fetch`
export class NcbiSummary {
static requestChromosomeData(chrId) {
if (NcbiSummary.jobTask)
NcbiSummary.jobTask.unsubscribe();
const urlPrefix = resource.ncbi_summary_nuccore.url;
const urlSuffix = resource.ncbi_summary_nuccore.url_suffix;
return new Promise((resolve, reject) => {
const recursiveRequest = () => {
const url = urlPrefix + chrId + urlSuffix;
const Http = new XMLHttpRequest();
Http.timeout = NcbiSummary.httpTimeout;
Http.open("GET", url);
Http.send();
Http.onloadend = (e) => {
var _a;
if (Http.responseText.length == 0) {
NcbiSummary.jobTask = asyncScheduler.schedule(() => {
recursiveRequest();
}, NcbiSummary.timeout);
}
else {
const jsonResult = JSON.parse(Http.responseText);
const uid = (_a = jsonResult === null || jsonResult === void 0 ? void 0 : jsonResult.result) === null || _a === void 0 ? void 0 : _a.uids[0];
const out = jsonResult.result[uid];
out.ncbiId = chrId;
resolve(out);
}
};
Http.onerror = (e) => {
if (NcbiSummary.jobTask)
NcbiSummary.jobTask.unsubscribe();
NcbiSummary.jobTask = asyncScheduler.schedule(() => {
recursiveRequest();
}, NcbiSummary.timeout);
};
};
recursiveRequest();
});
}
static requestTaxonomyData(taxId) {
if (NcbiSummary.jobTask)
NcbiSummary.jobTask.unsubscribe();
const urlPrefix = resource.ncbi_summary_taxonomy.url;
const urlSuffix = resource.ncbi_summary_taxonomy.url_suffix;
return new Promise((resolve, reject) => {
const recursiveRequest = () => {
const url = urlPrefix + taxId + urlSuffix;
const Http = new XMLHttpRequest();
Http.timeout = NcbiSummary.httpTimeout;
Http.open("GET", url);
Http.send();
Http.onloadend = (e) => {
var _a;
if (Http.responseText.length == 0) {
NcbiSummary.jobTask = asyncScheduler.schedule(() => {
recursiveRequest();
}, NcbiSummary.timeout);
}
else {
const jsonResult = JSON.parse(Http.responseText);
const uid = (_a = jsonResult === null || jsonResult === void 0 ? void 0 : jsonResult.result) === null || _a === void 0 ? void 0 : _a.uids[0];
resolve(jsonResult.result[uid]);
}
};
Http.onerror = (e) => {
NcbiSummary.jobTask = asyncScheduler.schedule(() => {
recursiveRequest();
}, NcbiSummary.timeout);
};
};
recursiveRequest();
});
}
}
NcbiSummary.timeout = 3000;
NcbiSummary.httpTimeout = 10000;
NcbiSummary.jobTask = null;
//# sourceMappingURL=NcbiSummary.js.map