2025-01-09 18:36:24 +02:00
|
|
|
import type { ConstructorData } from "./becca-interface.js";
|
2025-01-13 23:18:10 +02:00
|
|
|
import type AbstractBeccaEntity from "./entities/abstract_becca_entity.js";
|
2024-07-18 21:35:17 +03:00
|
|
|
import BAttachment from "./entities/battachment.js";
|
|
|
|
import BAttribute from "./entities/battribute.js";
|
|
|
|
import BBlob from "./entities/bblob.js";
|
|
|
|
import BBranch from "./entities/bbranch.js";
|
|
|
|
import BEtapiToken from "./entities/betapi_token.js";
|
|
|
|
import BNote from "./entities/bnote.js";
|
2025-03-12 22:37:49 +00:00
|
|
|
import BNoteEmbedding from "./entities/bnote_embedding.js";
|
2024-07-18 21:35:17 +03:00
|
|
|
import BOption from "./entities/boption.js";
|
|
|
|
import BRecentNote from "./entities/brecent_note.js";
|
|
|
|
import BRevision from "./entities/brevision.js";
|
2024-02-17 20:28:05 +02:00
|
|
|
|
2024-04-02 23:00:04 +03:00
|
|
|
type EntityClass = new (row?: any) => AbstractBeccaEntity<any>;
|
|
|
|
|
|
|
|
const ENTITY_NAME_TO_ENTITY: Record<string, ConstructorData<any> & EntityClass> = {
|
2025-01-09 18:07:02 +02:00
|
|
|
attachments: BAttachment,
|
|
|
|
attributes: BAttribute,
|
|
|
|
blobs: BBlob,
|
|
|
|
branches: BBranch,
|
|
|
|
etapi_tokens: BEtapiToken,
|
|
|
|
notes: BNote,
|
2025-03-12 22:37:49 +00:00
|
|
|
note_embeddings: BNoteEmbedding,
|
2025-01-09 18:07:02 +02:00
|
|
|
options: BOption,
|
|
|
|
recent_notes: BRecentNote,
|
2025-03-06 23:52:01 +02:00
|
|
|
revisions: BRevision
|
2024-02-17 20:28:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function getEntityFromEntityName(entityName: keyof typeof ENTITY_NAME_TO_ENTITY) {
|
|
|
|
if (!(entityName in ENTITY_NAME_TO_ENTITY)) {
|
|
|
|
throw new Error(`Entity for table '${entityName}' not found!`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ENTITY_NAME_TO_ENTITY[entityName];
|
|
|
|
}
|
|
|
|
|
2024-07-18 21:42:44 +03:00
|
|
|
export default {
|
2024-02-17 20:28:05 +02:00
|
|
|
getEntityFromEntityName
|
|
|
|
};
|