server-ts: Port boption

This commit is contained in:
Elian Doran 2024-02-17 01:00:38 +02:00
parent 6dd2cd39aa
commit 768aaf2d78
No known key found for this signature in database
4 changed files with 24 additions and 13 deletions

View File

@ -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<string, BNote>;
options!: Record<string, BOption>;
constructor() {
this.reset();
@ -24,7 +27,6 @@ class Becca {
this.attributes = {};
/** @type {Object.<String, BAttribute[]>} Points from attribute type-name to list of attributes */
this.attributeIndex = {};
/** @type {Object.<String, BOption>} */
this.options = {};
/** @type {Object.<String, BEtapiToken>} */
this.etapiTokens = {};

View File

@ -1725,4 +1725,4 @@ class BNote extends AbstractBeccaEntity {
}
}
module.exports = BNote;
export = BNote;

View File

@ -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;

View File

@ -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;
}