mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +08:00 
			
		
		
		
	server-ts: Port boption
This commit is contained in:
		
							parent
							
								
									6dd2cd39aa
								
							
						
					
					
						commit
						768aaf2d78
					
				@ -1,6 +1,8 @@
 | 
				
			|||||||
import sql = require('../services/sql');
 | 
					import sql = require('../services/sql');
 | 
				
			||||||
import NoteSet = require('../services/search/note_set');
 | 
					import NoteSet = require('../services/search/note_set');
 | 
				
			||||||
import NotFoundError = require('../errors/not_found_error');
 | 
					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.
 | 
					 * Becca is a backend cache of all notes, branches, and attributes.
 | 
				
			||||||
@ -8,6 +10,7 @@ import NotFoundError = require('../errors/not_found_error');
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class Becca {
 | 
					class Becca {
 | 
				
			||||||
    notes!: Record<string, BNote>;
 | 
					    notes!: Record<string, BNote>;
 | 
				
			||||||
 | 
					    options!: Record<string, BOption>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor() {
 | 
					    constructor() {
 | 
				
			||||||
        this.reset();
 | 
					        this.reset();
 | 
				
			||||||
@ -24,7 +27,6 @@ class Becca {
 | 
				
			|||||||
        this.attributes = {};
 | 
					        this.attributes = {};
 | 
				
			||||||
        /** @type {Object.<String, BAttribute[]>} Points from attribute type-name to list of attributes */
 | 
					        /** @type {Object.<String, BAttribute[]>} Points from attribute type-name to list of attributes */
 | 
				
			||||||
        this.attributeIndex = {};
 | 
					        this.attributeIndex = {};
 | 
				
			||||||
        /** @type {Object.<String, BOption>} */
 | 
					 | 
				
			||||||
        this.options = {};
 | 
					        this.options = {};
 | 
				
			||||||
        /** @type {Object.<String, BEtapiToken>} */
 | 
					        /** @type {Object.<String, BEtapiToken>} */
 | 
				
			||||||
        this.etapiTokens = {};
 | 
					        this.etapiTokens = {};
 | 
				
			||||||
 | 
				
			|||||||
@ -1725,4 +1725,4 @@ class BNote extends AbstractBeccaEntity {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = BNote;
 | 
					export = BNote;
 | 
				
			||||||
 | 
				
			|||||||
@ -1,33 +1,33 @@
 | 
				
			|||||||
"use strict";
 | 
					"use strict";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const dateUtils = require('../../services/date_utils');
 | 
					import dateUtils = require('../../services/date_utils');
 | 
				
			||||||
const AbstractBeccaEntity = require('./abstract_becca_entity.js');
 | 
					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.
 | 
					 * Option represents a name-value pair, either directly configurable by the user or some system property.
 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @extends AbstractBeccaEntity
 | 
					 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class BOption extends AbstractBeccaEntity {
 | 
					class BOption extends AbstractBeccaEntity {
 | 
				
			||||||
    static get entityName() { return "options"; }
 | 
					    static get entityName() { return "options"; }
 | 
				
			||||||
    static get primaryKeyName() { return "name"; }
 | 
					    static get primaryKeyName() { return "name"; }
 | 
				
			||||||
    static get hashedProperties() { return ["name", "value"]; }
 | 
					    static get hashedProperties() { return ["name", "value"]; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor(row) {
 | 
					    name!: string;
 | 
				
			||||||
 | 
					    value!: string;
 | 
				
			||||||
 | 
					    isSynced!: boolean;
 | 
				
			||||||
 | 
					    utcDateModified!: string;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    constructor(row: OptionRow) {
 | 
				
			||||||
        super();
 | 
					        super();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.updateFromRow(row);
 | 
					        this.updateFromRow(row);
 | 
				
			||||||
        this.becca.options[this.name] = this;
 | 
					        this.becca.options[this.name] = this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    updateFromRow(row) {
 | 
					    updateFromRow(row: OptionRow) {
 | 
				
			||||||
        /** @type {string} */
 | 
					 | 
				
			||||||
        this.name = row.name;
 | 
					        this.name = row.name;
 | 
				
			||||||
        /** @type {string} */
 | 
					 | 
				
			||||||
        this.value = row.value;
 | 
					        this.value = row.value;
 | 
				
			||||||
        /** @type {boolean} */
 | 
					 | 
				
			||||||
        this.isSynced = !!row.isSynced;
 | 
					        this.isSynced = !!row.isSynced;
 | 
				
			||||||
        /** @type {string} */
 | 
					 | 
				
			||||||
        this.utcDateModified = row.utcDateModified;
 | 
					        this.utcDateModified = row.utcDateModified;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -47,4 +47,4 @@ class BOption extends AbstractBeccaEntity {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = BOption;
 | 
					export = BOption;
 | 
				
			||||||
@ -1,3 +1,5 @@
 | 
				
			|||||||
 | 
					// FIXME: Booleans should probably be numbers instead (as SQLite does not have booleans.);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface AttachmentRow {
 | 
					export interface AttachmentRow {
 | 
				
			||||||
    attachmentId?: string;
 | 
					    attachmentId?: string;
 | 
				
			||||||
    ownerId: string;
 | 
					    ownerId: string;
 | 
				
			||||||
@ -34,3 +36,10 @@ export interface RecentNoteRow {
 | 
				
			|||||||
    notePath: string;
 | 
					    notePath: string;
 | 
				
			||||||
    utcDateCreated?: string;
 | 
					    utcDateCreated?: string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface OptionRow {
 | 
				
			||||||
 | 
					    name: string;
 | 
				
			||||||
 | 
					    value: string;
 | 
				
			||||||
 | 
					    isSynced: boolean;
 | 
				
			||||||
 | 
					    utcDateModified: string;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user