From 768aaf2d7835497723e0256cf6d03b49c490840c Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 01:00:38 +0200 Subject: [PATCH] server-ts: Port boption --- src/becca/becca-interface.ts | 4 +++- src/becca/entities/bnote.ts | 2 +- src/becca/entities/{boption.js => boption.ts} | 22 +++++++++---------- src/becca/entities/rows.ts | 9 ++++++++ 4 files changed, 24 insertions(+), 13 deletions(-) rename src/becca/entities/{boption.js => boption.ts} (72%) diff --git a/src/becca/becca-interface.ts b/src/becca/becca-interface.ts index 294442cbb..312f6be18 100644 --- a/src/becca/becca-interface.ts +++ b/src/becca/becca-interface.ts @@ -1,6 +1,8 @@ import sql = require('../services/sql'); import NoteSet = require('../services/search/note_set'); import NotFoundError = require('../errors/not_found_error'); +import BOption = require('./entities/boption'); +import BNote = require('./entities/bnote'); /** * Becca is a backend cache of all notes, branches, and attributes. @@ -8,6 +10,7 @@ import NotFoundError = require('../errors/not_found_error'); */ class Becca { notes!: Record; + options!: Record; constructor() { this.reset(); @@ -24,7 +27,6 @@ class Becca { this.attributes = {}; /** @type {Object.} Points from attribute type-name to list of attributes */ this.attributeIndex = {}; - /** @type {Object.} */ this.options = {}; /** @type {Object.} */ this.etapiTokens = {}; diff --git a/src/becca/entities/bnote.ts b/src/becca/entities/bnote.ts index 5cfded718..f72a83916 100644 --- a/src/becca/entities/bnote.ts +++ b/src/becca/entities/bnote.ts @@ -1725,4 +1725,4 @@ class BNote extends AbstractBeccaEntity { } } -module.exports = BNote; +export = BNote; diff --git a/src/becca/entities/boption.js b/src/becca/entities/boption.ts similarity index 72% rename from src/becca/entities/boption.js rename to src/becca/entities/boption.ts index 7fa121ccc..ebfd951d1 100644 --- a/src/becca/entities/boption.js +++ b/src/becca/entities/boption.ts @@ -1,33 +1,33 @@ "use strict"; -const dateUtils = require('../../services/date_utils'); -const AbstractBeccaEntity = require('./abstract_becca_entity.js'); +import dateUtils = require('../../services/date_utils'); +import AbstractBeccaEntity = require('./abstract_becca_entity.js'); +import { OptionRow } from './rows'; /** * Option represents a name-value pair, either directly configurable by the user or some system property. - * - * @extends AbstractBeccaEntity */ class BOption extends AbstractBeccaEntity { static get entityName() { return "options"; } static get primaryKeyName() { return "name"; } static get hashedProperties() { return ["name", "value"]; } - constructor(row) { + name!: string; + value!: string; + isSynced!: boolean; + utcDateModified!: string; + + constructor(row: OptionRow) { super(); this.updateFromRow(row); this.becca.options[this.name] = this; } - updateFromRow(row) { - /** @type {string} */ + updateFromRow(row: OptionRow) { this.name = row.name; - /** @type {string} */ this.value = row.value; - /** @type {boolean} */ this.isSynced = !!row.isSynced; - /** @type {string} */ this.utcDateModified = row.utcDateModified; } @@ -47,4 +47,4 @@ class BOption extends AbstractBeccaEntity { } } -module.exports = BOption; +export = BOption; diff --git a/src/becca/entities/rows.ts b/src/becca/entities/rows.ts index 5793ee7ab..2f583d092 100644 --- a/src/becca/entities/rows.ts +++ b/src/becca/entities/rows.ts @@ -1,3 +1,5 @@ +// FIXME: Booleans should probably be numbers instead (as SQLite does not have booleans.); + export interface AttachmentRow { attachmentId?: string; ownerId: string; @@ -34,3 +36,10 @@ export interface RecentNoteRow { notePath: string; utcDateCreated?: string; } + +export interface OptionRow { + name: string; + value: string; + isSynced: boolean; + utcDateModified: string; +} \ No newline at end of file