Skip to content

Build your personal knowledge base with Trilium Notes

server-ts: Port becca/entity_constructor

Elian Doran3b7812f8295d
diff --git a/src/anonymize.js b/src/anonymize.js
index cb9bbe9b20..0fa00cda18 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 c140b8a750..0000000000
--- 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 0000000000..18c012078b
--- /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<string, any> = {
+ "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 1111cdb565..011ac4d39f 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 6b6bbf5564..af7b87e116 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 c12efbcc51..9f66e76c9f 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');