mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
server-ts: Port battribute
This commit is contained in:
parent
eef8297ce1
commit
06287da9d8
@ -4,6 +4,7 @@ import NotFoundError = require('../errors/not_found_error');
|
|||||||
import BOption = require('./entities/boption');
|
import BOption = require('./entities/boption');
|
||||||
import BNote = require('./entities/bnote');
|
import BNote = require('./entities/bnote');
|
||||||
import BEtapiToken = require('./entities/betapi_token');
|
import BEtapiToken = require('./entities/betapi_token');
|
||||||
|
import BAttribute = require('./entities/battribute');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Becca is a backend cache of all notes, branches, and attributes.
|
* Becca is a backend cache of all notes, branches, and attributes.
|
||||||
@ -11,6 +12,9 @@ import BEtapiToken = require('./entities/betapi_token');
|
|||||||
*/
|
*/
|
||||||
class Becca {
|
class Becca {
|
||||||
notes!: Record<string, BNote>;
|
notes!: Record<string, BNote>;
|
||||||
|
attributes!: Record<string, BAttribute>;
|
||||||
|
/** Points from attribute type-name to list of attributes */
|
||||||
|
attributeIndex!: Record<string, BAttribute[]>;
|
||||||
options!: Record<string, BOption>;
|
options!: Record<string, BOption>;
|
||||||
etapiTokens!: Record<string, BEtapiToken>;
|
etapiTokens!: Record<string, BEtapiToken>;
|
||||||
|
|
||||||
@ -25,9 +29,7 @@ class Becca {
|
|||||||
this.branches = {};
|
this.branches = {};
|
||||||
/** @type {Object.<String, BBranch>} */
|
/** @type {Object.<String, BBranch>} */
|
||||||
this.childParentToBranch = {};
|
this.childParentToBranch = {};
|
||||||
/** @type {Object.<String, BAttribute>} */
|
this.attributes = {};
|
||||||
this.attributes = {};
|
|
||||||
/** @type {Object.<String, BAttribute[]>} Points from attribute type-name to list of attributes */
|
|
||||||
this.attributeIndex = {};
|
this.attributeIndex = {};
|
||||||
this.options = {};
|
this.options = {};
|
||||||
this.etapiTokens = {};
|
this.etapiTokens = {};
|
||||||
|
@ -1,17 +1,11 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const BNote = require('./bnote.js');
|
import BNote = require('./bnote.js');
|
||||||
const AbstractBeccaEntity = require('./abstract_becca_entity.js');
|
import AbstractBeccaEntity = require('./abstract_becca_entity.js');
|
||||||
const sql = require('../../services/sql');
|
import dateUtils = require('../../services/date_utils');
|
||||||
const dateUtils = require('../../services/date_utils');
|
import promotedAttributeDefinitionParser = require('../../services/promoted_attribute_definition_parser');
|
||||||
const promotedAttributeDefinitionParser = require('../../services/promoted_attribute_definition_parser.js');
|
import sanitizeAttributeName = require('../../services/sanitize_attribute_name');
|
||||||
const {sanitizeAttributeName} = require('../../services/sanitize_attribute_name.js');
|
import { AttributeRow, AttributeType } from './rows.js';
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* There are currently only two types of attributes, labels or relations.
|
|
||||||
* @typedef {"label" | "relation"} AttributeType
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attribute is an abstract concept which has two real uses - label (key - value pair)
|
* Attribute is an abstract concept which has two real uses - label (key - value pair)
|
||||||
@ -24,7 +18,16 @@ class BAttribute extends AbstractBeccaEntity {
|
|||||||
static get primaryKeyName() { return "attributeId"; }
|
static get primaryKeyName() { return "attributeId"; }
|
||||||
static get hashedProperties() { return ["attributeId", "noteId", "type", "name", "value", "isInheritable"]; }
|
static get hashedProperties() { return ["attributeId", "noteId", "type", "name", "value", "isInheritable"]; }
|
||||||
|
|
||||||
constructor(row) {
|
attributeId!: string;
|
||||||
|
noteId!: string;
|
||||||
|
type!: AttributeType;
|
||||||
|
name!: string;
|
||||||
|
position!: number;
|
||||||
|
value!: string;
|
||||||
|
isInheritable!: boolean;
|
||||||
|
utcDateModified!: string;
|
||||||
|
|
||||||
|
constructor(row: AttributeRow) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
if (!row) {
|
if (!row) {
|
||||||
@ -35,7 +38,7 @@ class BAttribute extends AbstractBeccaEntity {
|
|||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateFromRow(row) {
|
updateFromRow(row: AttributeRow) {
|
||||||
this.update([
|
this.update([
|
||||||
row.attributeId,
|
row.attributeId,
|
||||||
row.noteId,
|
row.noteId,
|
||||||
@ -48,22 +51,14 @@ class BAttribute extends AbstractBeccaEntity {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
update([attributeId, noteId, type, name, value, isInheritable, position, utcDateModified]) {
|
update([attributeId, noteId, type, name, value, isInheritable, position, utcDateModified]: any[]) {
|
||||||
/** @type {string} */
|
|
||||||
this.attributeId = attributeId;
|
this.attributeId = attributeId;
|
||||||
/** @type {string} */
|
|
||||||
this.noteId = noteId;
|
this.noteId = noteId;
|
||||||
/** @type {AttributeType} */
|
|
||||||
this.type = type;
|
this.type = type;
|
||||||
/** @type {string} */
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
/** @type {int} */
|
|
||||||
this.position = position;
|
this.position = position;
|
||||||
/** @type {string} */
|
|
||||||
this.value = value || "";
|
this.value = value || "";
|
||||||
/** @type {boolean} */
|
|
||||||
this.isInheritable = !!isInheritable;
|
this.isInheritable = !!isInheritable;
|
||||||
/** @type {string} */
|
|
||||||
this.utcDateModified = utcDateModified;
|
this.utcDateModified = utcDateModified;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -226,7 +221,7 @@ class BAttribute extends AbstractBeccaEntity {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
createClone(type, name, value, isInheritable) {
|
createClone(type: AttributeType, name: string, value: string, isInheritable: boolean) {
|
||||||
return new BAttribute({
|
return new BAttribute({
|
||||||
noteId: this.noteId,
|
noteId: this.noteId,
|
||||||
type: type,
|
type: type,
|
||||||
@ -239,4 +234,4 @@ class BAttribute extends AbstractBeccaEntity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = BAttribute;
|
export = BAttribute;
|
@ -59,4 +59,17 @@ export interface BlobRow {
|
|||||||
contentLength: number;
|
contentLength: number;
|
||||||
dateModified: string;
|
dateModified: string;
|
||||||
utcDateModified: string;
|
utcDateModified: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AttributeType = "label" | "relation";
|
||||||
|
|
||||||
|
export interface AttributeRow {
|
||||||
|
attributeId?: string;
|
||||||
|
noteId: string;
|
||||||
|
type: AttributeType;
|
||||||
|
name: string;
|
||||||
|
position: number;
|
||||||
|
value: string;
|
||||||
|
isInheritable: boolean;
|
||||||
|
utcDateModified: string;
|
||||||
}
|
}
|
@ -1,6 +1,15 @@
|
|||||||
function parse(value) {
|
interface DefinitionObject {
|
||||||
|
isPromoted: boolean;
|
||||||
|
labelType: string;
|
||||||
|
multiplicity: string;
|
||||||
|
numberPrecision: number;
|
||||||
|
promotedAlias: string;
|
||||||
|
inverseRelation: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse(value: string): DefinitionObject {
|
||||||
const tokens = value.split(',').map(t => t.trim());
|
const tokens = value.split(',').map(t => t.trim());
|
||||||
const defObj = {};
|
const defObj: Partial<DefinitionObject> = {};
|
||||||
|
|
||||||
for (const token of tokens) {
|
for (const token of tokens) {
|
||||||
if (token === 'promoted') {
|
if (token === 'promoted') {
|
||||||
@ -32,9 +41,9 @@ function parse(value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return defObj;
|
return defObj as DefinitionObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export = {
|
||||||
parse
|
parse
|
||||||
};
|
};
|
@ -1,5 +1,5 @@
|
|||||||
function sanitizeAttributeName(origName) {
|
function sanitizeAttributeName(origName: string) {
|
||||||
let fixedName;
|
let fixedName: string;
|
||||||
|
|
||||||
if (origName === '') {
|
if (origName === '') {
|
||||||
fixedName = "unnamed";
|
fixedName = "unnamed";
|
||||||
@ -13,6 +13,4 @@ function sanitizeAttributeName(origName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
export = sanitizeAttributeName;
|
||||||
sanitizeAttributeName
|
|
||||||
};
|
|
Loading…
x
Reference in New Issue
Block a user