Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const pdrFile = await fs.readFile(pdrFilePath, 'utf8');
// Investigating CUMULUS-423
if (pdrFile.trim().length === 0) throw new Error(`PDR file had no contents: ${pdrFilePath}`);
// because MODAPS PDRs do not follow the standard ODL spec
// we have to make sure there are spaces before and after every
// question mark
let pdrString = pdrFile.replace(/((\w*)=(\w*))/g, '$2 = $3');
// temporary fix for PVL not recognizing quoted strings as symbols
pdrString = pdrString.replace(/"/g, '');
let parsed;
try {
parsed = pvl.pvlToJS(pdrString);
}
catch (e) {
throw new PDRParsingError(e.message);
}
return parsed;
}
static generatePDRD(err) {
return pvl.jsToPVL(
new pvl.models.PVLRoot()
.add('MESSAGE_TYPE', new pvl.models.PVLTextString('SHORTPDRD'))
.add('DISPOSITION', new pvl.models.PVLTextString(err.message))
);
}
static generatePAN() {
return pvl.jsToPVL(
new pvl.models.PVLRoot()
.add('MESSAGE_TYPE', new pvl.models.PVLTextString('SHORTPAN'))
.add('DISPOSITION', new pvl.models.PVLTextString('SUCCESSFUL'))
.add('TIME_STAMP', new pvl.models.PVLDateTime(new Date()))
);
}
static generatePDRD(err) {
return pvl.jsToPVL(
new pvl.models.PVLRoot()
.add('MESSAGE_TYPE', new pvl.models.PVLTextString('SHORTPDRD'))
.add('DISPOSITION', new pvl.models.PVLTextString(err.message))
);
}
static generatePAN() {
return pvl.jsToPVL(
new pvl.models.PVLRoot()
.add('MESSAGE_TYPE', new pvl.models.PVLTextString('SHORTPAN'))
.add('DISPOSITION', new pvl.models.PVLTextString('SUCCESSFUL'))
.add('TIME_STAMP', new pvl.models.PVLDateTime(new Date()))
);
}
static generatePAN() {
return pvl.jsToPVL(
new pvl.models.PVLRoot()
.add('MESSAGE_TYPE', new pvl.models.PVLTextString('SHORTPAN'))
.add('DISPOSITION', new pvl.models.PVLTextString('SUCCESSFUL'))
.add('TIME_STAMP', new pvl.models.PVLDateTime(new Date()))
);
}
static generatePAN() {
return pvl.jsToPVL(
new pvl.models.PVLRoot()
.add('MESSAGE_TYPE', new pvl.models.PVLTextString('SHORTPAN'))
.add('DISPOSITION', new pvl.models.PVLTextString('SUCCESSFUL'))
.add('TIME_STAMP', new pvl.models.PVLDateTime(new Date()))
);
}
static generatePAN() {
return pvl.jsToPVL(
new pvl.models.PVLRoot()
.add('MESSAGE_TYPE', new pvl.models.PVLTextString('SHORTPAN'))
.add('DISPOSITION', new pvl.models.PVLTextString('SUCCESSFUL'))
.add('TIME_STAMP', new pvl.models.PVLDateTime(new Date()))
);
}
static generatePDRD(err) {
return pvl.jsToPVL(
new pvl.models.PVLRoot()
.add('MESSAGE_TYPE', new pvl.models.PVLTextString('SHORTPDRD'))
.add('DISPOSITION', new pvl.models.PVLTextString(err.message))
);
}
exports.parsePdr = (pdr) => pvl.pvlToJS(pdr);