mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
server-ts: Port share/shaca/shaca
This commit is contained in:
parent
0865e90cae
commit
b3c2602620
@ -1,5 +1,5 @@
|
|||||||
const { JSDOM } = require("jsdom");
|
const { JSDOM } = require("jsdom");
|
||||||
const shaca = require('./shaca/shaca.js');
|
const shaca = require('./shaca/shaca');
|
||||||
const assetPath = require('../services/asset_path');
|
const assetPath = require('../services/asset_path');
|
||||||
const shareRoot = require('./share_root');
|
const shareRoot = require('./share_root');
|
||||||
const escapeHtml = require('escape-html');
|
const escapeHtml = require('escape-html');
|
||||||
|
@ -3,7 +3,7 @@ const path = require('path');
|
|||||||
const safeCompare = require('safe-compare');
|
const safeCompare = require('safe-compare');
|
||||||
const ejs = require("ejs");
|
const ejs = require("ejs");
|
||||||
|
|
||||||
const shaca = require('./shaca/shaca.js');
|
const shaca = require('./shaca/shaca');
|
||||||
const shacaLoader = require('./shaca/shaca_loader.js');
|
const shacaLoader = require('./shaca/shaca_loader.js');
|
||||||
const shareRoot = require('./share_root');
|
const shareRoot = require('./share_root');
|
||||||
const contentRenderer = require('./content_renderer.js');
|
const contentRenderer = require('./content_renderer.js');
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
let shaca: any;
|
import Shaca from "../shaca-interface";
|
||||||
|
|
||||||
|
let shaca: Shaca;
|
||||||
|
|
||||||
class AbstractShacaEntity {
|
class AbstractShacaEntity {
|
||||||
// FIXME: Use right data type once we convert Shaca as well.
|
get shaca(): Shaca {
|
||||||
get shaca(): any {
|
|
||||||
if (!shaca) {
|
if (!shaca) {
|
||||||
shaca = require('../shaca.js');
|
shaca = require('../shaca');
|
||||||
}
|
}
|
||||||
|
|
||||||
return shaca;
|
return shaca;
|
||||||
|
@ -32,7 +32,7 @@ class SNote extends AbstractShacaEntity {
|
|||||||
private __attributeCache: SAttribute[] | null;
|
private __attributeCache: SAttribute[] | null;
|
||||||
private __inheritableAttributeCache: SAttribute[] | null;
|
private __inheritableAttributeCache: SAttribute[] | null;
|
||||||
targetRelations: SAttribute[];
|
targetRelations: SAttribute[];
|
||||||
private attachments: SAttachment[];
|
attachments: SAttachment[];
|
||||||
|
|
||||||
constructor([noteId, title, type, mime, blobId, utcDateModified, isProtected]: NoteRow) {
|
constructor([noteId, title, type, mime, blobId, utcDateModified, isProtected]: NoteRow) {
|
||||||
super();
|
super();
|
||||||
|
@ -1,45 +1,49 @@
|
|||||||
"use strict";
|
import SAttachment = require("./entities/sattachment");
|
||||||
|
import SAttribute = require("./entities/sattribute");
|
||||||
|
import SBranch = require("./entities/sbranch");
|
||||||
|
import SNote = require("./entities/snote");
|
||||||
|
|
||||||
|
export default class Shaca {
|
||||||
|
|
||||||
|
notes!: Record<string, SNote>;
|
||||||
|
branches!: Record<string, SBranch>;
|
||||||
|
childParentToBranch!: Record<string, SBranch>;
|
||||||
|
private attributes!: Record<string, SAttribute>;
|
||||||
|
attachments!: Record<string, SAttachment>;
|
||||||
|
private aliasToNote!: Record<string, SNote>;
|
||||||
|
private shareRootNote!: SNote | null;
|
||||||
|
/** true if the index of all shared subtrees is enabled */
|
||||||
|
private shareIndexEnabled!: boolean;
|
||||||
|
private loaded!: boolean;
|
||||||
|
|
||||||
class Shaca {
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.reset();
|
this.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
/** @type {Object.<String, SNote>} */
|
|
||||||
this.notes = {};
|
this.notes = {};
|
||||||
/** @type {Object.<String, SBranch>} */
|
|
||||||
this.branches = {};
|
this.branches = {};
|
||||||
/** @type {Object.<String, SBranch>} */
|
|
||||||
this.childParentToBranch = {};
|
this.childParentToBranch = {};
|
||||||
/** @type {Object.<String, SAttribute>} */
|
|
||||||
this.attributes = {};
|
this.attributes = {};
|
||||||
/** @type {Object.<String, SAttachment>} */
|
|
||||||
this.attachments = {};
|
this.attachments = {};
|
||||||
/** @type {Object.<String, SNote>} */
|
|
||||||
this.aliasToNote = {};
|
this.aliasToNote = {};
|
||||||
|
|
||||||
/** @type {SNote|null} */
|
|
||||||
this.shareRootNote = null;
|
this.shareRootNote = null;
|
||||||
|
|
||||||
/** @type {boolean} true if the index of all shared subtrees is enabled */
|
|
||||||
this.shareIndexEnabled = false;
|
this.shareIndexEnabled = false;
|
||||||
|
|
||||||
this.loaded = false;
|
this.loaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @returns {SNote|null} */
|
getNote(noteId: string) {
|
||||||
getNote(noteId) {
|
|
||||||
return this.notes[noteId];
|
return this.notes[noteId];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @returns {boolean} */
|
hasNote(noteId: string) {
|
||||||
hasNote(noteId) {
|
|
||||||
return noteId in this.notes;
|
return noteId in this.notes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @returns {SNote[]} */
|
getNotes(noteIds: string[], ignoreMissing = false) {
|
||||||
getNotes(noteIds, ignoreMissing = false) {
|
|
||||||
const filteredNotes = [];
|
const filteredNotes = [];
|
||||||
|
|
||||||
for (const noteId of noteIds) {
|
for (const noteId of noteIds) {
|
||||||
@ -59,27 +63,23 @@ class Shaca {
|
|||||||
return filteredNotes;
|
return filteredNotes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @returns {SBranch|null} */
|
getBranch(branchId: string) {
|
||||||
getBranch(branchId) {
|
|
||||||
return this.branches[branchId];
|
return this.branches[branchId];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @returns {SBranch|null} */
|
getBranchFromChildAndParent(childNoteId: string, parentNoteId: string) {
|
||||||
getBranchFromChildAndParent(childNoteId, parentNoteId) {
|
|
||||||
return this.childParentToBranch[`${childNoteId}-${parentNoteId}`];
|
return this.childParentToBranch[`${childNoteId}-${parentNoteId}`];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @returns {SAttribute|null} */
|
getAttribute(attributeId: string) {
|
||||||
getAttribute(attributeId) {
|
|
||||||
return this.attributes[attributeId];
|
return this.attributes[attributeId];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @returns {SAttachment|null} */
|
getAttachment(attachmentId: string) {
|
||||||
getAttachment(attachmentId) {
|
|
||||||
return this.attachments[attachmentId];
|
return this.attachments[attachmentId];
|
||||||
}
|
}
|
||||||
|
|
||||||
getEntity(entityName, entityId) {
|
getEntity(entityName: string, entityId: string) {
|
||||||
if (!entityName || !entityId) {
|
if (!entityName || !entityId) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -91,10 +91,6 @@ class Shaca {
|
|||||||
.replace('_', '')
|
.replace('_', '')
|
||||||
);
|
);
|
||||||
|
|
||||||
return this[camelCaseEntityName][entityId];
|
return (this as any)[camelCaseEntityName][entityId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const shaca = new Shaca();
|
|
||||||
|
|
||||||
module.exports = shaca;
|
|
7
src/share/shaca/shaca.ts
Normal file
7
src/share/shaca/shaca.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
import Shaca from "./shaca-interface";
|
||||||
|
|
||||||
|
const shaca = new Shaca();
|
||||||
|
|
||||||
|
export = shaca;
|
@ -1,7 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const sql = require('../sql');
|
const sql = require('../sql');
|
||||||
const shaca = require('./shaca.js');
|
const shaca = require('./shaca');
|
||||||
const log = require('../../services/log');
|
const log = require('../../services/log');
|
||||||
const SNote = require('./entities/snote');
|
const SNote = require('./entities/snote');
|
||||||
const SBranch = require('./entities/sbranch');
|
const SBranch = require('./entities/sbranch');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user