From 2f15d79476febf3eb8ba4f38c235e1a446458d52 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 01:03:38 +0200 Subject: [PATCH] server-ts: Port betapi_token --- src/becca/becca-interface.ts | 3 ++- .../{betapi_token.js => betapi_token.ts} | 21 +++++++++++-------- src/becca/entities/rows.ts | 9 ++++++++ 3 files changed, 23 insertions(+), 10 deletions(-) rename src/becca/entities/{betapi_token.js => betapi_token.ts} (86%) diff --git a/src/becca/becca-interface.ts b/src/becca/becca-interface.ts index 312f6be18..954c34966 100644 --- a/src/becca/becca-interface.ts +++ b/src/becca/becca-interface.ts @@ -3,6 +3,7 @@ import NoteSet = require('../services/search/note_set'); import NotFoundError = require('../errors/not_found_error'); import BOption = require('./entities/boption'); import BNote = require('./entities/bnote'); +import BEtapiToken = require('./entities/betapi_token'); /** * Becca is a backend cache of all notes, branches, and attributes. @@ -11,6 +12,7 @@ import BNote = require('./entities/bnote'); class Becca { notes!: Record; options!: Record; + etapiTokens!: Record; constructor() { this.reset(); @@ -28,7 +30,6 @@ class Becca { /** @type {Object.} Points from attribute type-name to list of attributes */ this.attributeIndex = {}; this.options = {}; - /** @type {Object.} */ this.etapiTokens = {}; this.dirtyNoteSetCache(); diff --git a/src/becca/entities/betapi_token.js b/src/becca/entities/betapi_token.ts similarity index 86% rename from src/becca/entities/betapi_token.js rename to src/becca/entities/betapi_token.ts index aedc1615f..4809dc265 100644 --- a/src/becca/entities/betapi_token.js +++ b/src/becca/entities/betapi_token.ts @@ -1,5 +1,7 @@ "use strict"; +import { EtapiTokenRow } from "./rows"; + const dateUtils = require('../../services/date_utils'); const AbstractBeccaEntity = require('./abstract_becca_entity.js'); @@ -19,7 +21,14 @@ class BEtapiToken extends AbstractBeccaEntity { static get primaryKeyName() { return "etapiTokenId"; } static get hashedProperties() { return ["etapiTokenId", "name", "tokenHash", "utcDateCreated", "utcDateModified", "isDeleted"]; } - constructor(row) { + etapiTokenId!: string; + name!: string; + tokenHash!: string; + utcDateCreated!: string; + utcDateModified!: string; + isDeleted!: boolean; + + constructor(row: EtapiTokenRow) { super(); if (!row) { @@ -30,18 +39,12 @@ class BEtapiToken extends AbstractBeccaEntity { this.init(); } - updateFromRow(row) { - /** @type {string} */ + updateFromRow(row: EtapiTokenRow) { this.etapiTokenId = row.etapiTokenId; - /** @type {string} */ this.name = row.name; - /** @type {string} */ this.tokenHash = row.tokenHash; - /** @type {string} */ this.utcDateCreated = row.utcDateCreated || dateUtils.utcNowDateTime(); - /** @type {string} */ this.utcDateModified = row.utcDateModified || this.utcDateCreated; - /** @type {boolean} */ this.isDeleted = !!row.isDeleted; if (this.etapiTokenId) { @@ -75,4 +78,4 @@ class BEtapiToken extends AbstractBeccaEntity { } } -module.exports = BEtapiToken; +export = BEtapiToken; diff --git a/src/becca/entities/rows.ts b/src/becca/entities/rows.ts index 2f583d092..e2f0a240c 100644 --- a/src/becca/entities/rows.ts +++ b/src/becca/entities/rows.ts @@ -42,4 +42,13 @@ export interface OptionRow { value: string; isSynced: boolean; utcDateModified: string; +} + +export interface EtapiTokenRow { + etapiTokenId: string; + name: string; + tokenHash: string; + utcDateCreated?: string; + utcDateModified?: string; + isDeleted: boolean; } \ No newline at end of file