glossarist 0.4.18 → 0.4.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -37,12 +37,21 @@ export class RelatedConcept extends GlossaristModel {
|
|
|
37
37
|
constructor(data = {}) {
|
|
38
38
|
super();
|
|
39
39
|
this.type = data.type ?? 'see';
|
|
40
|
-
this.content = data.content
|
|
40
|
+
this.content = normalizeContent(data.content);
|
|
41
41
|
this.ref = data.ref
|
|
42
42
|
? (data.ref instanceof ConceptRef ? data.ref : new ConceptRef(data.ref))
|
|
43
43
|
: null;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
// Convenience reader: returns the first available string value
|
|
47
|
+
// from the localized hash, or null if absent. Mirrors
|
|
48
|
+
// PartitiveHyperedge#contentString.
|
|
49
|
+
get contentString() {
|
|
50
|
+
if (!this.content) return null;
|
|
51
|
+
const values = Object.values(this.content);
|
|
52
|
+
return values.length > 0 ? values[0] : null;
|
|
53
|
+
}
|
|
54
|
+
|
|
46
55
|
toJSON() {
|
|
47
56
|
const obj = { type: this.type };
|
|
48
57
|
if (this.content != null) obj.content = this.content;
|
|
@@ -50,7 +59,30 @@ export class RelatedConcept extends GlossaristModel {
|
|
|
50
59
|
return obj;
|
|
51
60
|
}
|
|
52
61
|
|
|
62
|
+
static identityOf(value) {
|
|
63
|
+
const v = value ?? {};
|
|
64
|
+
const ref = v?.ref;
|
|
65
|
+
return `${v.type ?? ''}|${ref?.source ?? ''}|${ref?.id ?? ''}`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
identity() {
|
|
69
|
+
return RelatedConcept.identityOf(this);
|
|
70
|
+
}
|
|
71
|
+
|
|
53
72
|
static fromJSON(data) {
|
|
54
73
|
return new RelatedConcept(data);
|
|
55
74
|
}
|
|
56
75
|
}
|
|
76
|
+
|
|
77
|
+
// Content is a localized string (language → text). Plain strings on
|
|
78
|
+
// input are normalized to `{ default: '...' }` so callers always see
|
|
79
|
+
// the same shape. Mirrors PartitiveHyperedge's normalizeContent.
|
|
80
|
+
function normalizeContent(value) {
|
|
81
|
+
if (value == null) return null;
|
|
82
|
+
if (typeof value === 'string') return { default: value };
|
|
83
|
+
if (typeof value === 'object') {
|
|
84
|
+
const entries = Object.entries(value).filter(([, v]) => typeof v === 'string');
|
|
85
|
+
return entries.length > 0 ? Object.fromEntries(entries) : null;
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|