chore(prettier): fix all files

This commit is contained in:
Elian Doran
2025-01-09 18:07:02 +02:00
parent 19ee861699
commit 4cbb529fd4
571 changed files with 23226 additions and 23940 deletions

View File

@@ -1,4 +1,4 @@
export type SNoteRow = [ string, string, string, string, string, string, boolean ];
export type SBranchRow = [ string, string, string, string, string, boolean ];
export type SAttributeRow = [ string, string, string, string, string, boolean, number ];
export type SAttachmentRow = [ string, string, string, string, string, string, string ];
export type SNoteRow = [string, string, string, string, string, string, boolean];
export type SBranchRow = [string, string, string, string, string, boolean];
export type SAttributeRow = [string, string, string, string, string, boolean, number];
export type SAttachmentRow = [string, string, string, string, string, string, string];

View File

@@ -4,8 +4,8 @@ import sql from "../../sql.js";
import utils from "../../../services/utils.js";
import AbstractShacaEntity from "./abstract_shaca_entity.js";
import SNote from "./snote.js";
import { Blob } from '../../../services/blob-interface.js';
import { SAttachmentRow } from './rows.js';
import { Blob } from "../../../services/blob-interface.js";
import { SAttachmentRow } from "./rows.js";
class SAttachment extends AbstractShacaEntity {
private attachmentId: string;
@@ -42,8 +42,7 @@ class SAttachment extends AbstractShacaEntity {
if (!row) {
if (silentNotFoundError) {
return undefined;
}
else {
} else {
throw new Error(`Cannot find blob for attachment '${this.attachmentId}', blob '${this.blobId}'`);
}
}
@@ -51,11 +50,8 @@ class SAttachment extends AbstractShacaEntity {
let content = row.content;
if (this.hasStringContent()) {
return content === null
? ""
: content.toString("utf-8");
}
else {
return content === null ? "" : content.toString("utf-8");
} else {
return content;
}
}

View File

@@ -5,7 +5,6 @@ import { SAttributeRow } from "./rows.js";
import SNote from "./snote.js";
class SAttribute extends AbstractShacaEntity {
attributeId: string;
private noteId: string;
type: string;
@@ -34,8 +33,8 @@ class SAttribute extends AbstractShacaEntity {
targetNote.targetRelations.push(this);
}
if (this.type === 'relation' && this.name === 'imageLink') {
const linkedChildNote = this.note.getChildNotes().find(childNote => childNote.noteId === this.value);
if (this.type === "relation" && this.name === "imageLink") {
const linkedChildNote = this.note.getChildNotes().find((childNote) => childNote.noteId === this.value);
if (linkedChildNote) {
const branch = this.shaca.getBranchFromChildAndParent(linkedChildNote.noteId, this.noteId);
@@ -44,30 +43,30 @@ class SAttribute extends AbstractShacaEntity {
}
}
if (this.type === 'label' && this.name === 'shareAlias' && this.value.trim()) {
if (this.type === "label" && this.name === "shareAlias" && this.value.trim()) {
this.shaca.aliasToNote[this.value.trim()] = this.note;
}
if (this.type === 'label' && this.name === 'shareRoot') {
if (this.type === "label" && this.name === "shareRoot") {
this.shaca.shareRootNote = this.note;
}
if (this.type === 'label' && this.name === 'shareIndex') {
if (this.type === "label" && this.name === "shareIndex") {
this.shaca.shareIndexEnabled = true;
}
}
get isAffectingSubtree() {
return this.isInheritable
|| (this.type === 'relation' && ['template', 'inherit'].includes(this.name));
return this.isInheritable || (this.type === "relation" && ["template", "inherit"].includes(this.name));
}
get targetNoteId() { // alias
return this.type === 'relation' ? this.value : undefined;
get targetNoteId() {
// alias
return this.type === "relation" ? this.value : undefined;
}
isAutoLink() {
return this.type === 'relation' && ['internalLink', 'imageLink', 'relationMapLink', 'includeNoteLink'].includes(this.name);
return this.type === "relation" && ["internalLink", "imageLink", "relationMapLink", "includeNoteLink"].includes(this.name);
}
get note(): SNote {
@@ -75,7 +74,7 @@ class SAttribute extends AbstractShacaEntity {
}
get targetNote(): SNote | null | undefined {
if (this.type === 'relation') {
if (this.type === "relation") {
return this.shaca.notes[this.value];
}
}
@@ -85,7 +84,7 @@ class SAttribute extends AbstractShacaEntity {
}
getTargetNote(): SNote | null {
if (this.type !== 'relation') {
if (this.type !== "relation") {
throw new Error(`Attribute '${this.attributeId}' is not relation`);
}

View File

@@ -1,11 +1,10 @@
"use strict";
import AbstractShacaEntity from "./abstract_shaca_entity.js";
import { SBranchRow } from './rows.js';
import { SBranchRow } from "./rows.js";
import SNote from "./snote.js";
class SBranch extends AbstractShacaEntity {
private branchId: string;
private noteId: string;
parentNoteId: string;

View File

@@ -4,17 +4,17 @@ import sql from "../../sql.js";
import utils from "../../../services/utils.js";
import AbstractShacaEntity from "./abstract_shaca_entity.js";
import escape from "escape-html";
import { Blob } from '../../../services/blob-interface.js';
import { Blob } from "../../../services/blob-interface.js";
import SAttachment from "./sattachment.js";
import SAttribute from "./sattribute.js";
import SBranch from "./sbranch.js";
import { SNoteRow } from './rows.js';
import { SNoteRow } from "./rows.js";
const LABEL = 'label';
const RELATION = 'relation';
const CREDENTIALS = 'shareCredentials';
const LABEL = "label";
const RELATION = "relation";
const CREDENTIALS = "shareCredentials";
const isCredentials = (attr: SAttribute) => attr.type === 'label' && attr.name === CREDENTIALS;
const isCredentials = (attr: SAttribute) => attr.type === "label" && attr.name === CREDENTIALS;
class SNote extends AbstractShacaEntity {
noteId: string;
@@ -67,13 +67,11 @@ class SNote extends AbstractShacaEntity {
}
getChildBranches(): SBranch[] {
return this.children.map(childNote => this.shaca.getBranchFromChildAndParent(childNote.noteId, this.noteId));
return this.children.map((childNote) => this.shaca.getBranchFromChildAndParent(childNote.noteId, this.noteId));
}
getVisibleChildBranches() {
return this.getChildBranches()
.filter(branch => !branch.isHidden
&& !branch.getNote().isLabelTruthy('shareHiddenFromTree'));
return this.getChildBranches().filter((branch) => !branch.isHidden && !branch.getNote().isLabelTruthy("shareHiddenFromTree"));
}
getParentNotes() {
@@ -85,8 +83,7 @@ class SNote extends AbstractShacaEntity {
}
getVisibleChildNotes() {
return this.getVisibleChildBranches()
.map(branch => branch.getNote());
return this.getVisibleChildBranches().map((branch) => branch.getNote());
}
hasChildren() {
@@ -103,8 +100,7 @@ class SNote extends AbstractShacaEntity {
if (!row) {
if (silentNotFoundError) {
return undefined;
}
else {
} else {
throw new Error(`Cannot find note content for note '${this.noteId}', blob '${this.blobId}'`);
}
}
@@ -112,11 +108,8 @@ class SNote extends AbstractShacaEntity {
let content = row.content;
if (this.hasStringContent()) {
return content === null
? ""
: content.toString("utf-8");
}
else {
return content === null ? "" : content.toString("utf-8");
} else {
return content;
}
}
@@ -138,16 +131,13 @@ class SNote extends AbstractShacaEntity {
}
if (type && name) {
return attributeCache.filter(attr => attr.type === type && attr.name === name && !isCredentials(attr));
}
else if (type) {
return attributeCache.filter(attr => attr.type === type && !isCredentials(attr));
}
else if (name) {
return attributeCache.filter(attr => attr.name === name && !isCredentials(attr));
}
else {
return attributeCache.filter(attr => !isCredentials(attr));
return attributeCache.filter((attr) => attr.type === type && attr.name === name && !isCredentials(attr));
} else if (type) {
return attributeCache.filter((attr) => attr.type === type && !isCredentials(attr));
} else if (name) {
return attributeCache.filter((attr) => attr.name === name && !isCredentials(attr));
} else {
return attributeCache.filter((attr) => !isCredentials(attr));
}
}
@@ -164,7 +154,7 @@ class SNote extends AbstractShacaEntity {
const parentAttributes = this.ownedAttributes.slice();
const newPath = [...path, this.noteId];
if (this.noteId !== 'root') {
if (this.noteId !== "root") {
for (const parentNote of this.parents) {
parentAttributes.push(...parentNote.__getInheritableAttributes(newPath));
}
@@ -172,8 +162,9 @@ class SNote extends AbstractShacaEntity {
const templateAttributes: SAttribute[] = [];
for (const ownedAttr of parentAttributes) { // parentAttributes so we process also inherited templates
if (ownedAttr.type === 'relation' && ['template', 'inherit'].includes(ownedAttr.name)) {
for (const ownedAttr of parentAttributes) {
// parentAttributes so we process also inherited templates
if (ownedAttr.type === "relation" && ["template", "inherit"].includes(ownedAttr.name)) {
const templateNote = this.shaca.notes[ownedAttr.value];
if (templateNote) {
@@ -235,18 +226,17 @@ class SNote extends AbstractShacaEntity {
getJsonContentSafely() {
try {
return this.getJsonContent();
}
catch (e) {
} catch (e) {
return null;
}
}
hasAttribute(type: string, name: string) {
return !!this.getAttributes().find(attr => attr.type === type && attr.name === name);
return !!this.getAttributes().find((attr) => attr.type === type && attr.name === name);
}
getRelationTarget(name: string) {
const relation = this.getAttributes().find(attr => attr.type === 'relation' && attr.name === name);
const relation = this.getAttributes().find((attr) => attr.type === "relation" && attr.name === name);
return relation ? relation.targetNote : null;
}
@@ -255,7 +245,9 @@ class SNote extends AbstractShacaEntity {
* @param name - label name
* @returns true if label exists (including inherited)
*/
hasLabel(name: string) { return this.hasAttribute(LABEL, name); }
hasLabel(name: string) {
return this.hasAttribute(LABEL, name);
}
/**
* @param name - label name
@@ -268,74 +260,96 @@ class SNote extends AbstractShacaEntity {
return false;
}
return !!label && label.value !== 'false';
return !!label && label.value !== "false";
}
/**
* @param name - label name
* @returns true if label exists (excluding inherited)
*/
hasOwnedLabel(name: string) { return this.hasOwnedAttribute(LABEL, name); }
hasOwnedLabel(name: string) {
return this.hasOwnedAttribute(LABEL, name);
}
/**
* @param name - relation name
* @returns true if relation exists (including inherited)
*/
hasRelation(name: string) { return this.hasAttribute(RELATION, name); }
hasRelation(name: string) {
return this.hasAttribute(RELATION, name);
}
/**
* @param name - relation name
* @returns true if relation exists (excluding inherited)
*/
hasOwnedRelation(name: string) { return this.hasOwnedAttribute(RELATION, name); }
hasOwnedRelation(name: string) {
return this.hasOwnedAttribute(RELATION, name);
}
/**
* @param name - label name
* @returns label if it exists, null otherwise
*/
getLabel(name: string) { return this.getAttribute(LABEL, name); }
getLabel(name: string) {
return this.getAttribute(LABEL, name);
}
/**
* @param name - label name
* @returns label if it exists, null otherwise
*/
getOwnedLabel(name: string) { return this.getOwnedAttribute(LABEL, name); }
getOwnedLabel(name: string) {
return this.getOwnedAttribute(LABEL, name);
}
/**
* @param name - relation name
* @returns relation if it exists, null otherwise
*/
getRelation(name: string) { return this.getAttribute(RELATION, name); }
getRelation(name: string) {
return this.getAttribute(RELATION, name);
}
/**
* @param name - relation name
* @returns relation if it exists, null otherwise
*/
getOwnedRelation(name: string) { return this.getOwnedAttribute(RELATION, name); }
getOwnedRelation(name: string) {
return this.getOwnedAttribute(RELATION, name);
}
/**
* @param name - label name
* @returns label value if label exists, null otherwise
*/
getLabelValue(name: string) { return this.getAttributeValue(LABEL, name); }
getLabelValue(name: string) {
return this.getAttributeValue(LABEL, name);
}
/**
* @param name - label name
* @returns label value if label exists, null otherwise
*/
getOwnedLabelValue(name: string) { return this.getOwnedAttributeValue(LABEL, name); }
getOwnedLabelValue(name: string) {
return this.getOwnedAttributeValue(LABEL, name);
}
/**
* @param name - relation name
* @returns relation value if relation exists, null otherwise
*/
getRelationValue(name: string) { return this.getAttributeValue(RELATION, name); }
getRelationValue(name: string) {
return this.getAttributeValue(RELATION, name);
}
/**
* @param name - relation name
* @returns relation value if relation exists, null otherwise
*/
getOwnedRelationValue(name: string) { return this.getOwnedAttributeValue(RELATION, name); }
getOwnedRelationValue(name: string) {
return this.getOwnedAttributeValue(RELATION, name);
}
/**
* @param type - attribute type (label, relation, etc.)
@@ -355,7 +369,7 @@ class SNote extends AbstractShacaEntity {
getAttribute(type: string, name: string) {
const attributes = this.getAttributes();
return attributes.find(attr => attr.type === type && attr.name === name);
return attributes.find((attr) => attr.type === type && attr.name === name);
}
/**
@@ -377,7 +391,7 @@ class SNote extends AbstractShacaEntity {
getOwnedAttributeValue(type: string, name: string) {
const attr = this.getOwnedAttribute(type, name);
return attr ? attr.value as string : null; // FIXME
return attr ? (attr.value as string) : null; // FIXME
}
/**
@@ -393,7 +407,7 @@ class SNote extends AbstractShacaEntity {
* @returns all note's label values, including inherited ones
*/
getLabelValues(name: string) {
return this.getLabels(name).map(l => l.value) as string[]; // FIXME
return this.getLabels(name).map((l) => l.value) as string[]; // FIXME
}
/**
@@ -409,7 +423,7 @@ class SNote extends AbstractShacaEntity {
* @returns all note's label values, excluding inherited ones
*/
getOwnedLabelValues(name: string) {
return this.getOwnedAttributes(LABEL, name).map(l => l.value);
return this.getOwnedAttributes(LABEL, name).map((l) => l.value);
}
/**
@@ -440,15 +454,12 @@ class SNote extends AbstractShacaEntity {
}
if (type && name) {
return this.ownedAttributes.filter(attr => attr.type === type && attr.name === name);
}
else if (type) {
return this.ownedAttributes.filter(attr => attr.type === type);
}
else if (name) {
return this.ownedAttributes.filter(attr => attr.name === name);
}
else {
return this.ownedAttributes.filter((attr) => attr.type === type && attr.name === name);
} else if (type) {
return this.ownedAttributes.filter((attr) => attr.type === type);
} else if (name) {
return this.ownedAttributes.filter((attr) => attr.name === name);
} else {
return this.ownedAttributes.slice();
}
}
@@ -465,11 +476,11 @@ class SNote extends AbstractShacaEntity {
}
get isArchived() {
return this.hasAttribute('label', 'archived');
return this.hasAttribute("label", "archived");
}
isInherited() {
return !!this.targetRelations.find(rel => rel.name === 'template' || rel.name === 'inherit');
return !!this.targetRelations.find((rel) => rel.name === "template" || rel.name === "inherit");
}
getTargetRelations() {
@@ -481,11 +492,11 @@ class SNote extends AbstractShacaEntity {
}
getAttachmentByTitle(title: string) {
return this.attachments.find(attachment => attachment.title === title);
return this.attachments.find((attachment) => attachment.title === title);
}
get shareId() {
if (this.hasOwnedLabel('shareRoot')) {
if (this.hasOwnedLabel("shareRoot")) {
return "";
}
@@ -512,12 +523,11 @@ class SNote extends AbstractShacaEntity {
attributes: this.getAttributes()
// relations could link across shared subtrees which might leak them
// individual relations might be whitelisted based on needs #3434
.filter(attr => attr.type === 'label')
.map(attr => attr.getPojo()),
attachments: this.getAttachments()
.map(attachment => attachment.getPojo()),
parentNoteIds: this.parents.map(parentNote => parentNote.noteId),
childNoteIds: this.children.map(child => child.noteId)
.filter((attr) => attr.type === "label")
.map((attr) => attr.getPojo()),
attachments: this.getAttachments().map((attachment) => attachment.getPojo()),
parentNoteIds: this.parents.map((parentNote) => parentNote.noteId),
childNoteIds: this.children.map((child) => child.noteId)
};
}
}

View File

@@ -4,7 +4,6 @@ import SBranch from "./entities/sbranch.js";
import SNote from "./entities/snote.js";
export default class Shaca {
notes!: Record<string, SNote>;
branches!: Record<string, SBranch>;
childParentToBranch!: Record<string, SBranch>;
@@ -84,12 +83,7 @@ export default class Shaca {
return null;
}
const camelCaseEntityName = entityName.toLowerCase().replace(/(_[a-z])/g,
group =>
group
.toUpperCase()
.replace('_', '')
);
const camelCaseEntityName = entityName.toLowerCase().replace(/(_[a-z])/g, (group) => group.toUpperCase().replace("_", ""));
return (this as any)[camelCaseEntityName][entityId];
}

View File

@@ -9,7 +9,7 @@ import SAttribute from "./entities/sattribute.js";
import SAttachment from "./entities/sattachment.js";
import shareRoot from "../share_root.js";
import eventService from "../../services/events.js";
import { SAttachmentRow, SAttributeRow, SBranchRow, SNoteRow } from './entities/rows.js';
import { SAttachmentRow, SAttributeRow, SBranchRow, SNoteRow } from "./entities/rows.js";
function load() {
const start = Date.now();
@@ -17,7 +17,8 @@ function load() {
// using a raw query and passing arrays to avoid allocating new objects
const noteIds = sql.getColumn(`
const noteIds = sql.getColumn(
`
WITH RECURSIVE
tree(noteId) AS (
SELECT ?
@@ -26,7 +27,9 @@ function load() {
JOIN tree ON branches.parentNoteId = tree.noteId
WHERE branches.isDeleted = 0
)
SELECT noteId FROM tree`, [shareRoot.SHARE_ROOT_NOTE_ID]);
SELECT noteId FROM tree`,
[shareRoot.SHARE_ROOT_NOTE_ID]
);
if (noteIds.length === 0) {
shaca.loaded = true;
@@ -34,7 +37,7 @@ function load() {
return;
}
const noteIdStr = noteIds.map(noteId => `'${noteId}'`).join(",");
const noteIdStr = noteIds.map((noteId) => `'${noteId}'`).join(",");
const rawNoteRows = sql.getRawRows<SNoteRow>(`
SELECT noteId, title, type, mime, blobId, utcDateModified, isProtected
@@ -88,9 +91,12 @@ function ensureLoad() {
}
}
eventService.subscribe([eventService.ENTITY_CREATED, eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED, eventService.ENTITY_CHANGE_SYNCED, eventService.ENTITY_DELETE_SYNCED], ({ entityName, entity }) => {
shaca.reset();
});
eventService.subscribe(
[eventService.ENTITY_CREATED, eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED, eventService.ENTITY_CHANGE_SYNCED, eventService.ENTITY_DELETE_SYNCED],
({ entityName, entity }) => {
shaca.reset();
}
);
export default {
load,