2024-10-31 11:48:24 -04:00
|
|
|
import fs from 'fs'
|
2024-10-24 07:13:04 -04:00
|
|
|
import xml2js from 'xml2js'
|
|
|
|
import UKAMFEntity from './ukamf-entity.js'
|
2019-11-21 07:42:45 -05:00
|
|
|
|
|
|
|
class UKAMFDB {
|
|
|
|
constructor(file) {
|
|
|
|
this.file = file
|
|
|
|
}
|
|
|
|
|
|
|
|
async init() {
|
2024-10-31 11:48:24 -04:00
|
|
|
const data = await fs.promises.readFile(this.file, 'utf8')
|
2019-11-21 07:42:45 -05:00
|
|
|
const parser = new xml2js.Parser()
|
|
|
|
const xml = await parser.parseStringPromise(data)
|
|
|
|
|
|
|
|
this.entities = xml.EntitiesDescriptor.EntityDescriptor
|
|
|
|
}
|
|
|
|
|
|
|
|
findByEntityID(matcher) {
|
|
|
|
const entity = this.entities.find(
|
|
|
|
matcher instanceof RegExp
|
|
|
|
? e => e.$.entityID.match(matcher)
|
2019-11-27 10:05:26 -05:00
|
|
|
: e => e.$.entityID.includes(matcher)
|
2019-11-21 07:42:45 -05:00
|
|
|
)
|
|
|
|
return entity ? new UKAMFEntity(entity) : null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-24 07:13:04 -04:00
|
|
|
export default UKAMFDB
|