@dossierhq/core
Version:
The core Dossier library used by clients and server alike, used to interact with schema and entities directly, as well as remotely through a client.
44 lines • 1.46 kB
JavaScript
/// <reference types="./BaseSchema.d.ts" />
export class BaseSchema {
spec;
cachedPatternRegExps = {};
constructor(spec) {
this.spec = spec;
}
getEntityTypeCount() {
return this.spec.entityTypes.length;
}
getEntityTypeSpecification(type) {
return this.spec.entityTypes.find((it) => it.name === type) ?? null;
}
getEntityFieldSpecification(entitySpec, fieldName) {
return entitySpec.fields.find((it) => it.name === fieldName) ?? null;
}
getComponentTypeCount() {
return this.spec.componentTypes.length;
}
getComponentTypeSpecification(type) {
return this.spec.componentTypes.find((it) => it.name === type) ?? null;
}
getComponentFieldSpecification(componentSpec, fieldName) {
return componentSpec.fields.find((it) => it.name === fieldName) ?? null;
}
getPattern(name) {
return this.spec.patterns.find((it) => it.name === name) ?? null;
}
getPatternRegExp(name) {
let regexp = this.cachedPatternRegExps[name];
if (regexp)
return regexp;
const pattern = this.getPattern(name);
if (!pattern)
return null;
regexp = new RegExp(pattern.pattern);
this.cachedPatternRegExps[name] = regexp;
return regexp;
}
getIndex(name) {
return this.spec.indexes.find((it) => it.name === name) ?? null;
}
}
//# sourceMappingURL=BaseSchema.js.map