mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
server-ts: Port becca/entity_constructor
This commit is contained in:
parent
1c7532df46
commit
3b7812f829
@ -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 {
|
||||
|
@ -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
|
||||
};
|
33
src/becca/entity_constructor.ts
Normal file
33
src/becca/entity_constructor.ts
Normal file
@ -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
|
||||
};
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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');
|
||||
|
Loading…
x
Reference in New Issue
Block a user