From 3b7812f8295de360e21f0bb9a998dfdef780544a Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 20:28:05 +0200 Subject: [PATCH] server-ts: Port becca/entity_constructor --- src/anonymize.js | 2 +- src/becca/entity_constructor.js | 33 --------------------------------- src/becca/entity_constructor.ts | 33 +++++++++++++++++++++++++++++++++ src/services/sync.js | 2 +- src/services/sync_update.js | 2 +- src/tools/generate_document.js | 2 +- 6 files changed, 37 insertions(+), 37 deletions(-) delete mode 100644 src/becca/entity_constructor.js create mode 100644 src/becca/entity_constructor.ts diff --git a/src/anonymize.js b/src/anonymize.js index cb9bbe9b2..0fa00cda1 100644 --- a/src/anonymize.js +++ b/src/anonymize.js @@ -1,6 +1,6 @@ const anonymizationService = require('./services/anonymization'); const sqlInit = require('./services/sql_init'); -require('./becca/entity_constructor.js'); +require('./becca/entity_constructor'); sqlInit.dbReady.then(async () => { try { diff --git a/src/becca/entity_constructor.js b/src/becca/entity_constructor.js deleted file mode 100644 index c140b8a75..000000000 --- a/src/becca/entity_constructor.js +++ /dev/null @@ -1,33 +0,0 @@ -const BAttachment = require('./entities/battachment'); -const BAttribute = require('./entities/battribute'); -const BBlob = require('./entities/bblob'); -const BBranch = require('./entities/bbranch'); -const BEtapiToken = require('./entities/betapi_token'); -const BNote = require('./entities/bnote'); -const BOption = require('./entities/boption'); -const BRecentNote = require('./entities/brecent_note'); -const BRevision = require('./entities/brevision'); - -const ENTITY_NAME_TO_ENTITY = { - "attachments": BAttachment, - "attributes": BAttribute, - "blobs": BBlob, - "branches": BBranch, - "etapi_tokens": BEtapiToken, - "notes": BNote, - "options": BOption, - "recent_notes": BRecentNote, - "revisions": BRevision -}; - -function getEntityFromEntityName(entityName) { - if (!(entityName in ENTITY_NAME_TO_ENTITY)) { - throw new Error(`Entity for table '${entityName}' not found!`); - } - - return ENTITY_NAME_TO_ENTITY[entityName]; -} - -module.exports = { - getEntityFromEntityName -}; diff --git a/src/becca/entity_constructor.ts b/src/becca/entity_constructor.ts new file mode 100644 index 000000000..18c012078 --- /dev/null +++ b/src/becca/entity_constructor.ts @@ -0,0 +1,33 @@ +import BAttachment = require('./entities/battachment'); +import BAttribute = require('./entities/battribute'); +import BBlob = require('./entities/bblob'); +import BBranch = require('./entities/bbranch'); +import BEtapiToken = require('./entities/betapi_token'); +import BNote = require('./entities/bnote'); +import BOption = require('./entities/boption'); +import BRecentNote = require('./entities/brecent_note'); +import BRevision = require('./entities/brevision'); + +const ENTITY_NAME_TO_ENTITY: Record = { + "attachments": BAttachment, + "attributes": BAttribute, + "blobs": BBlob, + "branches": BBranch, + "etapi_tokens": BEtapiToken, + "notes": BNote, + "options": BOption, + "recent_notes": BRecentNote, + "revisions": BRevision +}; + +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]; +} + +export = { + getEntityFromEntityName +}; diff --git a/src/services/sync.js b/src/services/sync.js index 1111cdb56..011ac4d39 100644 --- a/src/services/sync.js +++ b/src/services/sync.js @@ -15,7 +15,7 @@ const cls = require('./cls'); const request = require('./request.js'); const ws = require('./ws'); const entityChangesService = require('./entity_changes'); -const entityConstructor = require('../becca/entity_constructor.js'); +const entityConstructor = require('../becca/entity_constructor'); const becca = require('../becca/becca'); let proxyToggle = true; diff --git a/src/services/sync_update.js b/src/services/sync_update.js index 6b6bbf556..af7b87e11 100644 --- a/src/services/sync_update.js +++ b/src/services/sync_update.js @@ -2,7 +2,7 @@ const sql = require('./sql'); const log = require('./log'); const entityChangesService = require('./entity_changes'); const eventService = require('./events'); -const entityConstructor = require('../becca/entity_constructor.js'); +const entityConstructor = require('../becca/entity_constructor'); const ws = require('./ws'); function updateEntities(entityChanges, instanceId) { diff --git a/src/tools/generate_document.js b/src/tools/generate_document.js index c12efbcc5..9f66e76c9 100644 --- a/src/tools/generate_document.js +++ b/src/tools/generate_document.js @@ -3,7 +3,7 @@ * will create 1000 new notes and some clones into the current document.db */ -require('../becca/entity_constructor.js'); +require('../becca/entity_constructor'); const sqlInit = require('../services/sql_init'); const noteService = require('../services/notes.js'); const attributeService = require('../services/attributes.js');