server-ts: Port share/shaca/shaca

This commit is contained in:
Elian Doran 2024-04-09 22:39:43 +03:00
parent 0865e90cae
commit b3c2602620
No known key found for this signature in database
7 changed files with 43 additions and 39 deletions

View File

@ -1,5 +1,5 @@
const { JSDOM } = require("jsdom");
const shaca = require('./shaca/shaca.js');
const shaca = require('./shaca/shaca');
const assetPath = require('../services/asset_path');
const shareRoot = require('./share_root');
const escapeHtml = require('escape-html');

View File

@ -3,7 +3,7 @@ const path = require('path');
const safeCompare = require('safe-compare');
const ejs = require("ejs");
const shaca = require('./shaca/shaca.js');
const shaca = require('./shaca/shaca');
const shacaLoader = require('./shaca/shaca_loader.js');
const shareRoot = require('./share_root');
const contentRenderer = require('./content_renderer.js');

View File

@ -1,10 +1,11 @@
let shaca: any;
import Shaca from "../shaca-interface";
let shaca: Shaca;
class AbstractShacaEntity {
// FIXME: Use right data type once we convert Shaca as well.
get shaca(): any {
get shaca(): Shaca {
if (!shaca) {
shaca = require('../shaca.js');
shaca = require('../shaca');
}
return shaca;

View File

@ -32,7 +32,7 @@ class SNote extends AbstractShacaEntity {
private __attributeCache: SAttribute[] | null;
private __inheritableAttributeCache: SAttribute[] | null;
targetRelations: SAttribute[];
private attachments: SAttachment[];
attachments: SAttachment[];
constructor([noteId, title, type, mime, blobId, utcDateModified, isProtected]: NoteRow) {
super();

View File

@ -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() {
this.reset();
}
reset() {
/** @type {Object.<String, SNote>} */
this.notes = {};
/** @type {Object.<String, SBranch>} */
this.branches = {};
/** @type {Object.<String, SBranch>} */
this.childParentToBranch = {};
/** @type {Object.<String, SAttribute>} */
this.attributes = {};
/** @type {Object.<String, SAttachment>} */
this.attachments = {};
/** @type {Object.<String, SNote>} */
this.aliasToNote = {};
/** @type {SNote|null} */
this.shareRootNote = null;
/** @type {boolean} true if the index of all shared subtrees is enabled */
this.shareIndexEnabled = false;
this.loaded = false;
}
/** @returns {SNote|null} */
getNote(noteId) {
getNote(noteId: string) {
return this.notes[noteId];
}
/** @returns {boolean} */
hasNote(noteId) {
hasNote(noteId: string) {
return noteId in this.notes;
}
/** @returns {SNote[]} */
getNotes(noteIds, ignoreMissing = false) {
getNotes(noteIds: string[], ignoreMissing = false) {
const filteredNotes = [];
for (const noteId of noteIds) {
@ -59,27 +63,23 @@ class Shaca {
return filteredNotes;
}
/** @returns {SBranch|null} */
getBranch(branchId) {
getBranch(branchId: string) {
return this.branches[branchId];
}
/** @returns {SBranch|null} */
getBranchFromChildAndParent(childNoteId, parentNoteId) {
getBranchFromChildAndParent(childNoteId: string, parentNoteId: string) {
return this.childParentToBranch[`${childNoteId}-${parentNoteId}`];
}
/** @returns {SAttribute|null} */
getAttribute(attributeId) {
getAttribute(attributeId: string) {
return this.attributes[attributeId];
}
/** @returns {SAttachment|null} */
getAttachment(attachmentId) {
getAttachment(attachmentId: string) {
return this.attachments[attachmentId];
}
getEntity(entityName, entityId) {
getEntity(entityName: string, entityId: string) {
if (!entityName || !entityId) {
return null;
}
@ -91,10 +91,6 @@ class Shaca {
.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
View File

@ -0,0 +1,7 @@
"use strict";
import Shaca from "./shaca-interface";
const shaca = new Shaca();
export = shaca;

View File

@ -1,7 +1,7 @@
"use strict";
const sql = require('../sql');
const shaca = require('./shaca.js');
const shaca = require('./shaca');
const log = require('../../services/log');
const SNote = require('./entities/snote');
const SBranch = require('./entities/sbranch');