impress
Version:
Enterprise application server for Node.js
43 lines (35 loc) • 1.14 kB
JavaScript
'use strict';
const { node, metarhia } = require('./deps.js');
const { Place } = require('./place.js');
class Schemas extends Place {
constructor(name, application) {
super(name, application);
this.model = null;
}
async load(targetPath = this.path) {
await super.load(targetPath);
this.model = await metarhia.metaschema.loadModel(targetPath);
}
get(key) {
return this.model.entities.get(key);
}
delete(filePath) {
if (!this.model) return;
const relPath = filePath.substring(this.path.length + 1);
const name = node.path.basename(relPath, '.js');
if (name.startsWith('.')) return;
this.model.entities.delete(name);
this.model.order.delete(name);
}
async change(filePath) {
if (!this.model) return;
if (!filePath.endsWith('.js')) return;
const relPath = filePath.substring(this.path.length + 1);
const name = node.path.basename(relPath, '.js');
if (name.startsWith('.')) return;
const schema = await metarhia.metaschema.loadSchema(filePath);
this.model.entities.set(name, schema);
this.model.preprocess();
}
}
module.exports = { Schemas };