Skip to content

Build your personal knowledge base with Trilium Notes

client-ts: Port services/promoted_attribute_definition_parser

Elian Doran81327a09d594
diff --git a/src/public/app/services/promoted_attribute_definition_parser.js b/src/public/app/services/promoted_attribute_definition_parser.ts
similarity index 65%
rename from src/public/app/services/promoted_attribute_definition_parser.js
rename to src/public/app/services/promoted_attribute_definition_parser.ts
index 81d097c420..3cd71ef2ff 100644
--- a/src/public/app/services/promoted_attribute_definition_parser.js
+++ b/src/public/app/services/promoted_attribute_definition_parser.ts
@@ -1,16 +1,28 @@
-function parse(value) {
+type LabelType = "text" | "number" | "boolean" | "date" | "datetime" | "url";
+type Multiplicity = "single" | "multi";
+
+interface DefinitionObject {
+ isPromoted?: boolean;
+ labelType?: LabelType;
+ multiplicity?: Multiplicity;
+ numberPrecision?: number;
+ promotedAlias?: string;
+ inverseRelation?: string;
+}
+
+function parse(value: string) {
const tokens = value.split(',').map(t => t.trim());
- const defObj = {};
+ const defObj: DefinitionObject = {};
for (const token of tokens) {
if (token === 'promoted') {
defObj.isPromoted = true;
}
else if (['text', 'number', 'boolean', 'date', 'datetime', 'url'].includes(token)) {
- defObj.labelType = token;
+ defObj.labelType = token as LabelType;
}
else if (['single', 'multi'].includes(token)) {
- defObj.multiplicity = token;
+ defObj.multiplicity = token as Multiplicity;
}
else if (token.startsWith('precision')) {
const chunks = token.split('=');