@rr0/data
Version:
RR0 data model
36 lines (35 loc) • 1.04 kB
JavaScript
export class AbstractDataService {
constructor(dataService, factory, files) {
this.dataService = dataService;
this.factory = factory;
this.files = files;
this.cache = new Map();
}
get type() {
return this.factory.type;
}
async getByDir(path) {
return this.dataService.getFromDir(path, [this.type, undefined], [this.type + ".json"]);
}
async getAll() {
return this.getFromDirs(this.files);
}
async getFromDirs(dirNames) {
let dataList = [];
for (const dirName of dirNames) {
const list = await this.getFromDir(dirName);
dataList.push(...list);
}
return dataList;
}
/**
* Get people information found in a directory.
*
* @param dirName
* @return {People[]} The found people information.
*/
async getFromDir(dirName) {
const fileSpec = [`${this.type}*.json`];
return this.dataService.getFromDir(dirName, [this.type, undefined], fileSpec);
}
}