mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
fix: plugin schema reconciliation
This commit is contained in:
@@ -44,6 +44,8 @@ export type EntityJSON = ReturnType<Entity["toJSON"]>;
|
||||
export const entityTypes = ["regular", "system", "generated"] as const;
|
||||
export type TEntityType = (typeof entityTypes)[number];
|
||||
|
||||
const ENTITY_SYMBOL = Symbol.for("bknd:entity");
|
||||
|
||||
/**
|
||||
* @todo: add check for adding fields (primary and relation not allowed)
|
||||
* @todo: add option to disallow api deletes (or api actions in general)
|
||||
@@ -89,6 +91,14 @@ export class Entity<
|
||||
}
|
||||
|
||||
if (type) this.type = type;
|
||||
this[ENTITY_SYMBOL] = true;
|
||||
}
|
||||
|
||||
// this is currently required as there could be multiple variants
|
||||
// we need to migrate to a mono repo
|
||||
static isEntity(e: unknown): e is Entity {
|
||||
if (!e) return false;
|
||||
return e[ENTITY_SYMBOL] === true;
|
||||
}
|
||||
|
||||
static create(args: {
|
||||
|
||||
@@ -118,12 +118,12 @@ export class EntityManager<TBD extends object = DefaultDB> {
|
||||
): Silent extends true ? Entity | undefined : Entity {
|
||||
// make sure to always retrieve by name
|
||||
const entity = this.entities.find((entity) =>
|
||||
e instanceof Entity ? entity.name === e.name : entity.name === e,
|
||||
Entity.isEntity(e) ? entity.name === e.name : entity.name === e,
|
||||
);
|
||||
|
||||
if (!entity) {
|
||||
if (silent === true) return undefined as any;
|
||||
throw new EntityNotDefinedException(e instanceof Entity ? e.name : (e as string));
|
||||
throw new EntityNotDefinedException(Entity.isEntity(e) ? e.name : (e as string));
|
||||
}
|
||||
|
||||
return entity;
|
||||
@@ -236,7 +236,7 @@ export class EntityManager<TBD extends object = DefaultDB> {
|
||||
}
|
||||
|
||||
getIndicesOf(_entity: Entity | string): EntityIndex[] {
|
||||
const entity = _entity instanceof Entity ? _entity : this.entity(_entity);
|
||||
const entity = Entity.isEntity(_entity) ? _entity : this.entity(_entity);
|
||||
return this.indices.filter((index) => index.entity.name === entity.name);
|
||||
}
|
||||
|
||||
|
||||
@@ -66,9 +66,14 @@ export class ModuleHelper {
|
||||
}
|
||||
|
||||
ensureRelation(relation: EntityRelation) {
|
||||
if (!this.em.relations.exists(relation)) {
|
||||
try {
|
||||
// most reliable way at the moment
|
||||
this.em.addRelation(relation);
|
||||
this.flags.sync_required = true;
|
||||
} catch (e) {}
|
||||
|
||||
// @todo: improve this function, seems like it still doesn't catch all cases
|
||||
if (!this.em.relations.exists(relation)) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user