overleaf/services/web/scripts/ukamf/ukamf-db.js
Jakob Ackermann 9745c045ba Merge pull request #21510 from overleaf/jpa-dependency-cleanup
[web] dependency cleanup

GitOrigin-RevId: 5b1e0ace2b0acfd7b1b839520f7c24acda8027e3
2024-11-01 09:05:28 +00:00

28 lines
671 B
JavaScript

import fs from 'fs'
import xml2js from 'xml2js'
import UKAMFEntity from './ukamf-entity.js'
class UKAMFDB {
constructor(file) {
this.file = file
}
async init() {
const data = await fs.promises.readFile(this.file, 'utf8')
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)
: e => e.$.entityID.includes(matcher)
)
return entity ? new UKAMFEntity(entity) : null
}
}
export default UKAMFDB