alizarin 1.0.0
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/LICENSE.txt +661 -0
- package/README.md +42 -0
- package/dist/__vite-browser-external-2Ng8QIWW.js +5 -0
- package/dist/__vite-browser-external-2Ng8QIWW.js.map +1 -0
- package/dist/alizarin.d.ts +1298 -0
- package/dist/alizarin.js +4972 -0
- package/dist/alizarin.js.map +1 -0
- package/dist/alizarin.umd.cjs +4981 -0
- package/dist/alizarin.umd.cjs.map +1 -0
- package/package.json +41 -0
package/dist/alizarin.js
ADDED
|
@@ -0,0 +1,4972 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
var _a, _b, _c, _d, _e;
|
|
5
|
+
const REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
|
|
6
|
+
function validate(uuid) {
|
|
7
|
+
return typeof uuid === "string" && REGEX.test(uuid);
|
|
8
|
+
}
|
|
9
|
+
function parse(uuid) {
|
|
10
|
+
if (!validate(uuid)) {
|
|
11
|
+
throw TypeError("Invalid UUID");
|
|
12
|
+
}
|
|
13
|
+
let v;
|
|
14
|
+
return Uint8Array.of((v = parseInt(uuid.slice(0, 8), 16)) >>> 24, v >>> 16 & 255, v >>> 8 & 255, v & 255, (v = parseInt(uuid.slice(9, 13), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(14, 18), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(19, 23), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(24, 36), 16)) / 1099511627776 & 255, v / 4294967296 & 255, v >>> 24 & 255, v >>> 16 & 255, v >>> 8 & 255, v & 255);
|
|
15
|
+
}
|
|
16
|
+
const byteToHex = [];
|
|
17
|
+
for (let i = 0; i < 256; ++i) {
|
|
18
|
+
byteToHex.push((i + 256).toString(16).slice(1));
|
|
19
|
+
}
|
|
20
|
+
function unsafeStringify(arr, offset = 0) {
|
|
21
|
+
return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
|
22
|
+
}
|
|
23
|
+
let getRandomValues;
|
|
24
|
+
const rnds8 = new Uint8Array(16);
|
|
25
|
+
function rng() {
|
|
26
|
+
if (!getRandomValues) {
|
|
27
|
+
if (typeof crypto === "undefined" || !crypto.getRandomValues) {
|
|
28
|
+
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
29
|
+
}
|
|
30
|
+
getRandomValues = crypto.getRandomValues.bind(crypto);
|
|
31
|
+
}
|
|
32
|
+
return getRandomValues(rnds8);
|
|
33
|
+
}
|
|
34
|
+
function stringToBytes(str) {
|
|
35
|
+
str = unescape(encodeURIComponent(str));
|
|
36
|
+
const bytes = new Uint8Array(str.length);
|
|
37
|
+
for (let i = 0; i < str.length; ++i) {
|
|
38
|
+
bytes[i] = str.charCodeAt(i);
|
|
39
|
+
}
|
|
40
|
+
return bytes;
|
|
41
|
+
}
|
|
42
|
+
const DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
|
|
43
|
+
const URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
|
|
44
|
+
function v35(version, hash, value, namespace, buf, offset) {
|
|
45
|
+
const valueBytes = typeof value === "string" ? stringToBytes(value) : value;
|
|
46
|
+
const namespaceBytes = typeof namespace === "string" ? parse(namespace) : namespace;
|
|
47
|
+
if (typeof namespace === "string") {
|
|
48
|
+
namespace = parse(namespace);
|
|
49
|
+
}
|
|
50
|
+
if ((namespace == null ? void 0 : namespace.length) !== 16) {
|
|
51
|
+
throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");
|
|
52
|
+
}
|
|
53
|
+
let bytes = new Uint8Array(16 + valueBytes.length);
|
|
54
|
+
bytes.set(namespaceBytes);
|
|
55
|
+
bytes.set(valueBytes, namespaceBytes.length);
|
|
56
|
+
bytes = hash(bytes);
|
|
57
|
+
bytes[6] = bytes[6] & 15 | version;
|
|
58
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
59
|
+
return unsafeStringify(bytes);
|
|
60
|
+
}
|
|
61
|
+
const randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
62
|
+
const native = { randomUUID };
|
|
63
|
+
function v4(options, buf, offset) {
|
|
64
|
+
var _a2;
|
|
65
|
+
if (native.randomUUID && true && !options) {
|
|
66
|
+
return native.randomUUID();
|
|
67
|
+
}
|
|
68
|
+
options = options || {};
|
|
69
|
+
const rnds = options.random ?? ((_a2 = options.rng) == null ? void 0 : _a2.call(options)) ?? rng();
|
|
70
|
+
if (rnds.length < 16) {
|
|
71
|
+
throw new Error("Random bytes length must be >= 16");
|
|
72
|
+
}
|
|
73
|
+
rnds[6] = rnds[6] & 15 | 64;
|
|
74
|
+
rnds[8] = rnds[8] & 63 | 128;
|
|
75
|
+
return unsafeStringify(rnds);
|
|
76
|
+
}
|
|
77
|
+
function f(s, x, y, z) {
|
|
78
|
+
switch (s) {
|
|
79
|
+
case 0:
|
|
80
|
+
return x & y ^ ~x & z;
|
|
81
|
+
case 1:
|
|
82
|
+
return x ^ y ^ z;
|
|
83
|
+
case 2:
|
|
84
|
+
return x & y ^ x & z ^ y & z;
|
|
85
|
+
case 3:
|
|
86
|
+
return x ^ y ^ z;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function ROTL(x, n) {
|
|
90
|
+
return x << n | x >>> 32 - n;
|
|
91
|
+
}
|
|
92
|
+
function sha1(bytes) {
|
|
93
|
+
const K = [1518500249, 1859775393, 2400959708, 3395469782];
|
|
94
|
+
const H = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
|
|
95
|
+
const newBytes = new Uint8Array(bytes.length + 1);
|
|
96
|
+
newBytes.set(bytes);
|
|
97
|
+
newBytes[bytes.length] = 128;
|
|
98
|
+
bytes = newBytes;
|
|
99
|
+
const l = bytes.length / 4 + 2;
|
|
100
|
+
const N = Math.ceil(l / 16);
|
|
101
|
+
const M = new Array(N);
|
|
102
|
+
for (let i = 0; i < N; ++i) {
|
|
103
|
+
const arr = new Uint32Array(16);
|
|
104
|
+
for (let j = 0; j < 16; ++j) {
|
|
105
|
+
arr[j] = bytes[i * 64 + j * 4] << 24 | bytes[i * 64 + j * 4 + 1] << 16 | bytes[i * 64 + j * 4 + 2] << 8 | bytes[i * 64 + j * 4 + 3];
|
|
106
|
+
}
|
|
107
|
+
M[i] = arr;
|
|
108
|
+
}
|
|
109
|
+
M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32);
|
|
110
|
+
M[N - 1][14] = Math.floor(M[N - 1][14]);
|
|
111
|
+
M[N - 1][15] = (bytes.length - 1) * 8 & 4294967295;
|
|
112
|
+
for (let i = 0; i < N; ++i) {
|
|
113
|
+
const W = new Uint32Array(80);
|
|
114
|
+
for (let t = 0; t < 16; ++t) {
|
|
115
|
+
W[t] = M[i][t];
|
|
116
|
+
}
|
|
117
|
+
for (let t = 16; t < 80; ++t) {
|
|
118
|
+
W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
|
|
119
|
+
}
|
|
120
|
+
let a = H[0];
|
|
121
|
+
let b = H[1];
|
|
122
|
+
let c = H[2];
|
|
123
|
+
let d = H[3];
|
|
124
|
+
let e = H[4];
|
|
125
|
+
for (let t = 0; t < 80; ++t) {
|
|
126
|
+
const s = Math.floor(t / 20);
|
|
127
|
+
const T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0;
|
|
128
|
+
e = d;
|
|
129
|
+
d = c;
|
|
130
|
+
c = ROTL(b, 30) >>> 0;
|
|
131
|
+
b = a;
|
|
132
|
+
a = T;
|
|
133
|
+
}
|
|
134
|
+
H[0] = H[0] + a >>> 0;
|
|
135
|
+
H[1] = H[1] + b >>> 0;
|
|
136
|
+
H[2] = H[2] + c >>> 0;
|
|
137
|
+
H[3] = H[3] + d >>> 0;
|
|
138
|
+
H[4] = H[4] + e >>> 0;
|
|
139
|
+
}
|
|
140
|
+
return Uint8Array.of(H[0] >> 24, H[0] >> 16, H[0] >> 8, H[0], H[1] >> 24, H[1] >> 16, H[1] >> 8, H[1], H[2] >> 24, H[2] >> 16, H[2] >> 8, H[2], H[3] >> 24, H[3] >> 16, H[3] >> 8, H[3], H[4] >> 24, H[4] >> 16, H[4] >> 8, H[4]);
|
|
141
|
+
}
|
|
142
|
+
function v5(value, namespace, buf, offset) {
|
|
143
|
+
return v35(80, sha1, value, namespace);
|
|
144
|
+
}
|
|
145
|
+
v5.DNS = DNS;
|
|
146
|
+
v5.URL = URL;
|
|
147
|
+
const DEFAULT_LANGUAGE$1 = "en";
|
|
148
|
+
const SLUG_LENGTH = 20;
|
|
149
|
+
const UUID_NAMESPACE = "1a79f1c8-9505-4bea-a18e-28a053f725ca";
|
|
150
|
+
const UUID_NAMESPACE_COMPRESSION = v5("compression", "1a79f1c8-9505-4bea-a18e-28a053f725ca");
|
|
151
|
+
let currentLanguage;
|
|
152
|
+
function slugify(original) {
|
|
153
|
+
return `${original}`.replaceAll(/[^A-Za-z0-9_]/g, "").slice(0, SLUG_LENGTH);
|
|
154
|
+
}
|
|
155
|
+
function getCurrentLanguage$1() {
|
|
156
|
+
return currentLanguage || (typeof navigator != "undefined" && navigator.language || DEFAULT_LANGUAGE$1).slice(0, 2);
|
|
157
|
+
}
|
|
158
|
+
function setCurrentLanguage$1(lang) {
|
|
159
|
+
currentLanguage = lang;
|
|
160
|
+
}
|
|
161
|
+
class AttrPromise extends (_b = Promise, _a = Symbol.toPrimitive, _b) {
|
|
162
|
+
constructor(executor) {
|
|
163
|
+
super(executor);
|
|
164
|
+
__publicField(this, _a);
|
|
165
|
+
const proxy = new Proxy(this, {
|
|
166
|
+
set: (object, keyObj, value) => {
|
|
167
|
+
object.then((val) => {
|
|
168
|
+
val[keyObj] = value;
|
|
169
|
+
return val;
|
|
170
|
+
});
|
|
171
|
+
return true;
|
|
172
|
+
},
|
|
173
|
+
get: (object, keyObj) => {
|
|
174
|
+
if (keyObj in object) {
|
|
175
|
+
const value = object[keyObj];
|
|
176
|
+
if (typeof value === "function") {
|
|
177
|
+
return value.bind(object);
|
|
178
|
+
}
|
|
179
|
+
return value;
|
|
180
|
+
}
|
|
181
|
+
const key = keyObj.toString();
|
|
182
|
+
if (key in object) {
|
|
183
|
+
const value = object[key];
|
|
184
|
+
if (typeof value === "function") {
|
|
185
|
+
return value.bind(object);
|
|
186
|
+
}
|
|
187
|
+
return value;
|
|
188
|
+
}
|
|
189
|
+
if (object instanceof Promise) {
|
|
190
|
+
return object.then((val) => {
|
|
191
|
+
return val ? val[keyObj] : val;
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return object[keyObj];
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
return proxy;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const KEY_COMPRESSION_LENGTH = 1e3;
|
|
201
|
+
function generateUuidv5(group, key) {
|
|
202
|
+
if (Array.isArray(key)) {
|
|
203
|
+
let shortKey = "";
|
|
204
|
+
let keyTracker = "";
|
|
205
|
+
key.forEach((k) => {
|
|
206
|
+
if (keyTracker.length + k.length + 1 > KEY_COMPRESSION_LENGTH) {
|
|
207
|
+
shortKey = v5(shortKey + ">" + keyTracker, UUID_NAMESPACE_COMPRESSION);
|
|
208
|
+
keyTracker = k;
|
|
209
|
+
} else {
|
|
210
|
+
keyTracker += ";" + k;
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
return v5(`${group[0]}:${group[1]}:${key}`, UUID_NAMESPACE);
|
|
215
|
+
}
|
|
216
|
+
const utils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
217
|
+
__proto__: null,
|
|
218
|
+
AttrPromise,
|
|
219
|
+
generateUuidv5,
|
|
220
|
+
getCurrentLanguage: getCurrentLanguage$1,
|
|
221
|
+
setCurrentLanguage: setCurrentLanguage$1,
|
|
222
|
+
slugify
|
|
223
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
224
|
+
class StaticGraphMeta {
|
|
225
|
+
constructor(jsondata) {
|
|
226
|
+
__publicField(this, "author");
|
|
227
|
+
__publicField(this, "cards");
|
|
228
|
+
__publicField(this, "cards_x_nodes_x_widgets");
|
|
229
|
+
__publicField(this, "color");
|
|
230
|
+
__publicField(this, "description");
|
|
231
|
+
__publicField(this, "edges");
|
|
232
|
+
__publicField(this, "graphid");
|
|
233
|
+
__publicField(this, "iconclass");
|
|
234
|
+
__publicField(this, "is_editable");
|
|
235
|
+
__publicField(this, "isresource");
|
|
236
|
+
__publicField(this, "jsonldcontext");
|
|
237
|
+
__publicField(this, "name");
|
|
238
|
+
__publicField(this, "nodegroups");
|
|
239
|
+
__publicField(this, "nodes");
|
|
240
|
+
__publicField(this, "ontology_id");
|
|
241
|
+
__publicField(this, "publication");
|
|
242
|
+
__publicField(this, "relatable_resource_model_ids", []);
|
|
243
|
+
__publicField(this, "resource_2_resource_constraints", []);
|
|
244
|
+
__publicField(this, "root");
|
|
245
|
+
__publicField(this, "slug");
|
|
246
|
+
__publicField(this, "subtitle");
|
|
247
|
+
__publicField(this, "version");
|
|
248
|
+
this.graphid = jsondata.graphid;
|
|
249
|
+
Object.assign(this, jsondata);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
class StaticTranslatableString extends String {
|
|
253
|
+
constructor(s, lang = void 0) {
|
|
254
|
+
let translations;
|
|
255
|
+
let finalLang;
|
|
256
|
+
if (s instanceof StaticTranslatableString) {
|
|
257
|
+
translations = new Map(s.translations);
|
|
258
|
+
if (lang === void 0) {
|
|
259
|
+
finalLang = s.lang;
|
|
260
|
+
} else {
|
|
261
|
+
finalLang = lang;
|
|
262
|
+
}
|
|
263
|
+
} else if (typeof s === "object") {
|
|
264
|
+
translations = new Map(Object.entries(s));
|
|
265
|
+
if (lang === void 0 || !translations.has(lang)) {
|
|
266
|
+
const defaultLanguage = getCurrentLanguage$1();
|
|
267
|
+
if (!translations || translations.has(defaultLanguage)) {
|
|
268
|
+
finalLang = defaultLanguage;
|
|
269
|
+
} else {
|
|
270
|
+
finalLang = Object.keys(s)[0];
|
|
271
|
+
}
|
|
272
|
+
} else {
|
|
273
|
+
finalLang = lang;
|
|
274
|
+
}
|
|
275
|
+
} else {
|
|
276
|
+
translations = /* @__PURE__ */ new Map();
|
|
277
|
+
finalLang = lang || getCurrentLanguage$1();
|
|
278
|
+
translations.set(finalLang, s);
|
|
279
|
+
}
|
|
280
|
+
s = translations.get(finalLang) || "";
|
|
281
|
+
super(s);
|
|
282
|
+
__publicField(this, "translations");
|
|
283
|
+
__publicField(this, "lang");
|
|
284
|
+
this.translations = translations;
|
|
285
|
+
this.lang = finalLang;
|
|
286
|
+
}
|
|
287
|
+
copy() {
|
|
288
|
+
return new StaticTranslatableString(this, this.lang);
|
|
289
|
+
}
|
|
290
|
+
toString() {
|
|
291
|
+
const current = this.lang || getCurrentLanguage$1();
|
|
292
|
+
let asString;
|
|
293
|
+
if (this.translations.size) {
|
|
294
|
+
asString = this.translations.get(current) || this.translations.values().next().value;
|
|
295
|
+
}
|
|
296
|
+
return `${asString}`;
|
|
297
|
+
}
|
|
298
|
+
toJSON() {
|
|
299
|
+
return Object.fromEntries(this.translations);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
class StaticNodegroup {
|
|
303
|
+
constructor(jsonData) {
|
|
304
|
+
__publicField(this, "cardinality");
|
|
305
|
+
__publicField(this, "legacygroupid");
|
|
306
|
+
__publicField(this, "nodegroupid");
|
|
307
|
+
__publicField(this, "parentnodegroup_id");
|
|
308
|
+
this.legacygroupid = jsonData.legacygroupid;
|
|
309
|
+
this.nodegroupid = jsonData.nodegroupid;
|
|
310
|
+
this.parentnodegroup_id = jsonData.parentnodegroup_id;
|
|
311
|
+
this.cardinality = jsonData.cardinality;
|
|
312
|
+
}
|
|
313
|
+
copy() {
|
|
314
|
+
return new StaticNodegroup(this);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
class StaticNode {
|
|
318
|
+
constructor(jsonData) {
|
|
319
|
+
__publicField(this, "alias");
|
|
320
|
+
__publicField(this, "config");
|
|
321
|
+
__publicField(this, "datatype");
|
|
322
|
+
__publicField(this, "description");
|
|
323
|
+
__publicField(this, "exportable");
|
|
324
|
+
__publicField(this, "fieldname");
|
|
325
|
+
__publicField(this, "graph_id");
|
|
326
|
+
__publicField(this, "hascustomalias");
|
|
327
|
+
__publicField(this, "is_collector");
|
|
328
|
+
__publicField(this, "isrequired");
|
|
329
|
+
__publicField(this, "issearchable");
|
|
330
|
+
__publicField(this, "istopnode");
|
|
331
|
+
__publicField(this, "name");
|
|
332
|
+
__publicField(this, "nodegroup_id");
|
|
333
|
+
__publicField(this, "nodeid");
|
|
334
|
+
__publicField(this, "ontologyclass", null);
|
|
335
|
+
__publicField(this, "parentproperty", null);
|
|
336
|
+
__publicField(this, "sortorder");
|
|
337
|
+
__publicField(this, "sourcebranchpublication_id", null);
|
|
338
|
+
this.alias = jsonData.alias;
|
|
339
|
+
this.config = jsonData.config;
|
|
340
|
+
this.datatype = jsonData.datatype;
|
|
341
|
+
this.description = jsonData.description;
|
|
342
|
+
this.exportable = jsonData.exportable;
|
|
343
|
+
this.fieldname = jsonData.fieldname;
|
|
344
|
+
this.graph_id = jsonData.graph_id;
|
|
345
|
+
this.hascustomalias = jsonData.hascustomalias;
|
|
346
|
+
this.is_collector = jsonData.is_collector;
|
|
347
|
+
this.isrequired = jsonData.isrequired;
|
|
348
|
+
this.issearchable = jsonData.issearchable;
|
|
349
|
+
this.istopnode = jsonData.istopnode;
|
|
350
|
+
this.name = jsonData.name;
|
|
351
|
+
this.nodegroup_id = jsonData.nodegroup_id;
|
|
352
|
+
this.nodeid = jsonData.nodeid;
|
|
353
|
+
this.parentproperty = jsonData.parentproperty;
|
|
354
|
+
this.sortorder = jsonData.sortorder;
|
|
355
|
+
this.ontologyclass = jsonData.ontologyclass;
|
|
356
|
+
this.sourcebranchpublication_id = jsonData.sourcebranchpublication_id;
|
|
357
|
+
}
|
|
358
|
+
copy() {
|
|
359
|
+
return new StaticNode(this);
|
|
360
|
+
}
|
|
361
|
+
// true -- same object
|
|
362
|
+
// 2 -- identical
|
|
363
|
+
// 1 -- identical not counting falsey nodeid, nodegroupid and/or graphid
|
|
364
|
+
// -1 -- identical up to nodeid
|
|
365
|
+
// -2 -- identical up to nodeid, nodegroupid
|
|
366
|
+
// -3 -- identical up to nodeid, nodegroupid and graphid
|
|
367
|
+
// false -- different
|
|
368
|
+
// for <2, falsey nodeid, nodegroupid and graphid count as matches
|
|
369
|
+
// and copy/compare are ignored.
|
|
370
|
+
static compare(nodeA, nodeB) {
|
|
371
|
+
if (nodeA === nodeB) {
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
const keys = [...Object.keys(nodeA), ...Object.keys(nodeB)].filter((key) => ![
|
|
375
|
+
"compare",
|
|
376
|
+
"copy",
|
|
377
|
+
"nodeid",
|
|
378
|
+
"graph_id",
|
|
379
|
+
"nodegroup_id"
|
|
380
|
+
].includes(key));
|
|
381
|
+
function compareEntries(entriesA, entriesB) {
|
|
382
|
+
const entryPairs = {};
|
|
383
|
+
for (const [key, value] of [...entriesA, ...entriesB]) {
|
|
384
|
+
entryPairs[key] = entryPairs[key] || [];
|
|
385
|
+
entryPairs[key].push(value);
|
|
386
|
+
}
|
|
387
|
+
for (const [_, [valA, valB]] of Object.entries(entryPairs)) {
|
|
388
|
+
if (valA && valB && typeof valA === "object" && typeof valB === "object") {
|
|
389
|
+
if (!compareEntries(Object.entries(valA), Object.entries(valB))) {
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (Array.isArray(valA) && Array.isArray(valB)) {
|
|
394
|
+
if (!compareEntries(Object.entries(valA), Object.entries(valB))) {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (valA !== valB) {
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return true;
|
|
403
|
+
}
|
|
404
|
+
if (!compareEntries(
|
|
405
|
+
// @ts-expect-error Expecting values to be symbols
|
|
406
|
+
keys.map((k) => [k, nodeA[k]]),
|
|
407
|
+
// @ts-expect-error Expecting values to be symbols
|
|
408
|
+
keys.map((k) => [k, nodeB[k]])
|
|
409
|
+
)) {
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
if (nodeA.graph_id && nodeB.graph_id && nodeA.graph_id !== nodeB.graph_id) {
|
|
413
|
+
return -3;
|
|
414
|
+
}
|
|
415
|
+
if (nodeA.nodegroup_id && nodeB.nodegroup_id && nodeA.nodegroup_id !== nodeB.nodegroup_id) {
|
|
416
|
+
return -2;
|
|
417
|
+
}
|
|
418
|
+
if (nodeA.nodeid && nodeB.nodeid && nodeA.nodeid !== nodeB.nodeid) {
|
|
419
|
+
return -1;
|
|
420
|
+
}
|
|
421
|
+
if ((nodeA.graph_id && nodeB.graph_id || nodeA.graph_id === nodeB.graph_id) && (nodeA.nodegroup_id && nodeB.nodegroup_id || nodeA.nodegroup_id === nodeB.nodegroup_id) && (nodeA.nodeid && nodeB.nodeid || nodeA.nodeid === nodeB.nodeid)) {
|
|
422
|
+
return 2;
|
|
423
|
+
}
|
|
424
|
+
return 1;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
class StaticConstraint {
|
|
428
|
+
constructor(jsonData) {
|
|
429
|
+
__publicField(this, "card_id");
|
|
430
|
+
__publicField(this, "constraintid");
|
|
431
|
+
__publicField(this, "nodes");
|
|
432
|
+
__publicField(this, "uniquetoallinstances");
|
|
433
|
+
this.card_id = jsonData.card_id;
|
|
434
|
+
this.constraintid = jsonData.constraintid;
|
|
435
|
+
this.nodes = jsonData.nodes;
|
|
436
|
+
this.uniquetoallinstances = jsonData.uniquetoallinstances;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
class StaticCard {
|
|
440
|
+
constructor(jsonData) {
|
|
441
|
+
__publicField(this, "active");
|
|
442
|
+
__publicField(this, "cardid");
|
|
443
|
+
__publicField(this, "component_id");
|
|
444
|
+
__publicField(this, "config");
|
|
445
|
+
__publicField(this, "constraints");
|
|
446
|
+
__publicField(this, "cssclass");
|
|
447
|
+
__publicField(this, "description");
|
|
448
|
+
__publicField(this, "graph_id");
|
|
449
|
+
__publicField(this, "helpenabled");
|
|
450
|
+
__publicField(this, "helptext");
|
|
451
|
+
__publicField(this, "helptitle");
|
|
452
|
+
__publicField(this, "instructions");
|
|
453
|
+
__publicField(this, "is_editable");
|
|
454
|
+
__publicField(this, "name");
|
|
455
|
+
__publicField(this, "nodegroup_id");
|
|
456
|
+
__publicField(this, "sortorder");
|
|
457
|
+
__publicField(this, "visible");
|
|
458
|
+
this.active = jsonData.active;
|
|
459
|
+
this.cardid = jsonData.cardid;
|
|
460
|
+
this.component_id = jsonData.component_id;
|
|
461
|
+
this.config = jsonData.config;
|
|
462
|
+
this.constraints = jsonData.constraints.map(
|
|
463
|
+
(constraint) => new StaticConstraint(constraint)
|
|
464
|
+
);
|
|
465
|
+
this.cssclass = jsonData.cssclass;
|
|
466
|
+
this.description = jsonData.description;
|
|
467
|
+
this.graph_id = jsonData.graph_id;
|
|
468
|
+
this.helpenabled = jsonData.helpenabled;
|
|
469
|
+
this.helptext = new StaticTranslatableString(jsonData.helptext);
|
|
470
|
+
this.helptitle = new StaticTranslatableString(jsonData.helptitle);
|
|
471
|
+
this.instructions = new StaticTranslatableString(jsonData.instructions);
|
|
472
|
+
this.is_editable = jsonData.is_editable;
|
|
473
|
+
this.name = new StaticTranslatableString(jsonData.name);
|
|
474
|
+
this.nodegroup_id = jsonData.nodegroup_id;
|
|
475
|
+
this.sortorder = jsonData.sortorder;
|
|
476
|
+
this.visible = jsonData.visible;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
class StaticCardsXNodesXWidgets {
|
|
480
|
+
constructor(jsonData) {
|
|
481
|
+
__publicField(this, "card_id");
|
|
482
|
+
__publicField(this, "config");
|
|
483
|
+
__publicField(this, "id");
|
|
484
|
+
__publicField(this, "label");
|
|
485
|
+
__publicField(this, "node_id");
|
|
486
|
+
__publicField(this, "sortorder");
|
|
487
|
+
__publicField(this, "visible");
|
|
488
|
+
__publicField(this, "widget_id");
|
|
489
|
+
this.card_id = jsonData.card_id;
|
|
490
|
+
this.config = jsonData.config;
|
|
491
|
+
this.id = jsonData.id;
|
|
492
|
+
this.label = new StaticTranslatableString(jsonData.label);
|
|
493
|
+
this.node_id = jsonData.node_id;
|
|
494
|
+
this.sortorder = jsonData.sortorder;
|
|
495
|
+
this.visible = jsonData.visible;
|
|
496
|
+
this.widget_id = jsonData.widget_id;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
class StaticEdge {
|
|
500
|
+
constructor(jsonData) {
|
|
501
|
+
__publicField(this, "description");
|
|
502
|
+
__publicField(this, "domainnode_id");
|
|
503
|
+
__publicField(this, "edgeid");
|
|
504
|
+
__publicField(this, "graph_id");
|
|
505
|
+
__publicField(this, "name");
|
|
506
|
+
__publicField(this, "ontologyproperty", null);
|
|
507
|
+
__publicField(this, "rangenode_id");
|
|
508
|
+
this.description = jsonData.description;
|
|
509
|
+
this.domainnode_id = jsonData.domainnode_id;
|
|
510
|
+
this.edgeid = jsonData.edgeid;
|
|
511
|
+
this.graph_id = jsonData.graph_id;
|
|
512
|
+
this.name = jsonData.name;
|
|
513
|
+
this.rangenode_id = jsonData.rangenode_id;
|
|
514
|
+
this.ontologyproperty = jsonData.ontologyproperty;
|
|
515
|
+
}
|
|
516
|
+
copy() {
|
|
517
|
+
return new StaticEdge(this);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
class StaticFunctionsXGraphs {
|
|
521
|
+
constructor(jsonData) {
|
|
522
|
+
__publicField(this, "config");
|
|
523
|
+
__publicField(this, "function_id");
|
|
524
|
+
__publicField(this, "graph_id");
|
|
525
|
+
__publicField(this, "id");
|
|
526
|
+
this.config = jsonData.config;
|
|
527
|
+
this.function_id = jsonData.function_id;
|
|
528
|
+
this.graph_id = jsonData.graph_id;
|
|
529
|
+
this.id = jsonData.id;
|
|
530
|
+
}
|
|
531
|
+
copy() {
|
|
532
|
+
return new StaticFunctionsXGraphs(this);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
class StaticPublication {
|
|
536
|
+
constructor(jsonData) {
|
|
537
|
+
__publicField(this, "graph_id");
|
|
538
|
+
__publicField(this, "notes");
|
|
539
|
+
__publicField(this, "publicationid");
|
|
540
|
+
__publicField(this, "published_time");
|
|
541
|
+
this.graph_id = jsonData.graph_id;
|
|
542
|
+
this.notes = jsonData.notes;
|
|
543
|
+
this.publicationid = jsonData.publicationid;
|
|
544
|
+
this.published_time = jsonData.published_time;
|
|
545
|
+
}
|
|
546
|
+
copy() {
|
|
547
|
+
return new StaticPublication(this);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
class StaticGraph {
|
|
551
|
+
constructor(jsonData) {
|
|
552
|
+
__publicField(this, "author");
|
|
553
|
+
__publicField(this, "cards", null);
|
|
554
|
+
__publicField(this, "cards_x_nodes_x_widgets", null);
|
|
555
|
+
__publicField(this, "color");
|
|
556
|
+
__publicField(this, "config");
|
|
557
|
+
__publicField(this, "deploymentdate", null);
|
|
558
|
+
__publicField(this, "deploymentfile", null);
|
|
559
|
+
__publicField(this, "description");
|
|
560
|
+
__publicField(this, "edges");
|
|
561
|
+
__publicField(this, "functions_x_graphs", null);
|
|
562
|
+
__publicField(this, "graphid");
|
|
563
|
+
__publicField(this, "iconclass");
|
|
564
|
+
__publicField(this, "is_editable", null);
|
|
565
|
+
__publicField(this, "isresource");
|
|
566
|
+
__publicField(this, "jsonldcontext", null);
|
|
567
|
+
__publicField(this, "name");
|
|
568
|
+
__publicField(this, "nodegroups");
|
|
569
|
+
__publicField(this, "nodes");
|
|
570
|
+
__publicField(this, "ontology_id", null);
|
|
571
|
+
__publicField(this, "publication", null);
|
|
572
|
+
__publicField(this, "relatable_resource_model_ids");
|
|
573
|
+
__publicField(this, "resource_2_resource_constraints", null);
|
|
574
|
+
__publicField(this, "root");
|
|
575
|
+
__publicField(this, "slug", null);
|
|
576
|
+
__publicField(this, "subtitle");
|
|
577
|
+
__publicField(this, "template_id");
|
|
578
|
+
__publicField(this, "version");
|
|
579
|
+
this.author = jsonData.author;
|
|
580
|
+
this.cards = jsonData.cards && jsonData.cards.map((card) => new StaticCard(card));
|
|
581
|
+
this.cards_x_nodes_x_widgets = jsonData.cards_x_nodes_x_widgets && jsonData.cards_x_nodes_x_widgets.map(
|
|
582
|
+
(card_x_node_x_widget) => new StaticCardsXNodesXWidgets(card_x_node_x_widget)
|
|
583
|
+
);
|
|
584
|
+
this.color = jsonData.color;
|
|
585
|
+
this.config = jsonData.config;
|
|
586
|
+
this.deploymentdate = jsonData.deploymentdate;
|
|
587
|
+
this.deploymentfile = jsonData.deploymentfile;
|
|
588
|
+
this.description = new StaticTranslatableString(jsonData.description);
|
|
589
|
+
this.edges = jsonData.edges.map((edge) => new StaticEdge(edge));
|
|
590
|
+
this.functions_x_graphs = jsonData.functions_x_graphs && jsonData.functions_x_graphs.map(
|
|
591
|
+
(functions_x_graphs) => new StaticFunctionsXGraphs(functions_x_graphs)
|
|
592
|
+
);
|
|
593
|
+
this.graphid = jsonData.graphid;
|
|
594
|
+
this.iconclass = jsonData.iconclass;
|
|
595
|
+
this.is_editable = jsonData.is_editable;
|
|
596
|
+
this.isresource = jsonData.isresource;
|
|
597
|
+
this.jsonldcontext = jsonData.jsonldcontext;
|
|
598
|
+
this.name = new StaticTranslatableString(jsonData.name);
|
|
599
|
+
this.nodegroups = jsonData.nodegroups.map(
|
|
600
|
+
(nodegroup) => new StaticNodegroup(nodegroup)
|
|
601
|
+
);
|
|
602
|
+
this.nodes = jsonData.nodes.map((node) => new StaticNode(node));
|
|
603
|
+
this.ontology_id = jsonData.ontology_id;
|
|
604
|
+
this.publication = jsonData.publication && new StaticPublication(jsonData.publication);
|
|
605
|
+
this.relatable_resource_model_ids = jsonData.relatable_resource_model_ids;
|
|
606
|
+
this.resource_2_resource_constraints = jsonData.resource_2_resource_constraints;
|
|
607
|
+
this.root = jsonData.root;
|
|
608
|
+
this.slug = jsonData.slug;
|
|
609
|
+
this.subtitle = new StaticTranslatableString(jsonData.subtitle);
|
|
610
|
+
this.template_id = jsonData.template_id;
|
|
611
|
+
this.version = jsonData.version;
|
|
612
|
+
}
|
|
613
|
+
// TODO: complete deepcopy
|
|
614
|
+
copy() {
|
|
615
|
+
var _a2, _b2, _c2, _d2, _e2, _f;
|
|
616
|
+
const newGraph = new StaticGraph(this);
|
|
617
|
+
Object.assign(newGraph, {
|
|
618
|
+
author: this.author,
|
|
619
|
+
cards: ((_a2 = this.cards) == null ? void 0 : _a2.map((card) => new StaticCard(card))) || [],
|
|
620
|
+
cards_x_nodes_x_widgets: ((_b2 = this.cards_x_nodes_x_widgets) == null ? void 0 : _b2.map((cnw) => new StaticCardsXNodesXWidgets(cnw))) || [],
|
|
621
|
+
color: this.color,
|
|
622
|
+
config: Object.assign({}, this.config),
|
|
623
|
+
// TODO: deepcopy;
|
|
624
|
+
deploymentdate: this.deploymentdate,
|
|
625
|
+
deploymentfile: this.deploymentfile,
|
|
626
|
+
description: this.description.copy && this.description.copy() || this.description,
|
|
627
|
+
edges: this.edges.map((edge) => edge.copy && edge.copy() || edge),
|
|
628
|
+
functions_x_graphs: ((_c2 = this.functions_x_graphs) == null ? void 0 : _c2.map((fxg) => fxg.copy())) || [],
|
|
629
|
+
graphid: this.graphid,
|
|
630
|
+
iconclass: this.iconclass,
|
|
631
|
+
is_editable: this.is_editable,
|
|
632
|
+
isresource: this.isresource,
|
|
633
|
+
jsonldcontext: this.jsonldcontext,
|
|
634
|
+
name: this.name.copy && this.name.copy() || this.name,
|
|
635
|
+
nodegroups: (_d2 = this.nodegroups) == null ? void 0 : _d2.map((ng) => ng.copy && ng.copy() || ng),
|
|
636
|
+
nodes: (_e2 = this.nodes) == null ? void 0 : _e2.map((n) => n.copy && n.copy() || n),
|
|
637
|
+
ontology_id: this.ontology_id,
|
|
638
|
+
publication: ((_f = this.publication) == null ? void 0 : _f.copy) && this.publication.copy() || null,
|
|
639
|
+
relatable_resource_model_ids: [...this.relatable_resource_model_ids || []],
|
|
640
|
+
resource_2_resource_constraints: [...this.resource_2_resource_constraints || []],
|
|
641
|
+
root: this.root.copy && this.root.copy() || this.root,
|
|
642
|
+
slug: this.slug,
|
|
643
|
+
subtitle: this.subtitle.copy && this.subtitle.copy(),
|
|
644
|
+
template_id: this.template_id,
|
|
645
|
+
version: this.version
|
|
646
|
+
});
|
|
647
|
+
return newGraph;
|
|
648
|
+
}
|
|
649
|
+
static create(props, published = true) {
|
|
650
|
+
const graphid = props.graphid || v4();
|
|
651
|
+
const publication = published ? new StaticPublication({
|
|
652
|
+
graph_id: graphid,
|
|
653
|
+
notes: null,
|
|
654
|
+
publicationid: v4(),
|
|
655
|
+
published_time: (/* @__PURE__ */ new Date()).toISOString()
|
|
656
|
+
}) : null;
|
|
657
|
+
const name = props.name ? props.name instanceof StaticTranslatableString ? props.name : new StaticTranslatableString(props.name) : new StaticTranslatableString("");
|
|
658
|
+
const alias = slugify(name);
|
|
659
|
+
const root = new StaticNode({
|
|
660
|
+
"alias": alias,
|
|
661
|
+
"config": {},
|
|
662
|
+
"datatype": "semantic",
|
|
663
|
+
"description": "",
|
|
664
|
+
"exportable": false,
|
|
665
|
+
"fieldname": "",
|
|
666
|
+
"graph_id": graphid,
|
|
667
|
+
"hascustomalias": false,
|
|
668
|
+
"is_collector": false,
|
|
669
|
+
"isrequired": false,
|
|
670
|
+
"issearchable": true,
|
|
671
|
+
"istopnode": true,
|
|
672
|
+
"name": name.toString(),
|
|
673
|
+
"nodegroup_id": null,
|
|
674
|
+
"nodeid": graphid,
|
|
675
|
+
"ontologyclass": props.ontology_id || null,
|
|
676
|
+
"parentproperty": null,
|
|
677
|
+
"sortorder": 0,
|
|
678
|
+
"sourcebranchpublication_id": null
|
|
679
|
+
});
|
|
680
|
+
return new StaticGraph({
|
|
681
|
+
author: props.author,
|
|
682
|
+
cards: null,
|
|
683
|
+
cards_x_nodes_x_widgets: null,
|
|
684
|
+
color: props.color || null,
|
|
685
|
+
config: props.config || {},
|
|
686
|
+
deploymentdate: props.deploymentdate || null,
|
|
687
|
+
deploymentfile: props.deploymentfile || null,
|
|
688
|
+
description: props.description ? props.description instanceof StaticTranslatableString ? props.description : new StaticTranslatableString(props.description) : null,
|
|
689
|
+
edges: [],
|
|
690
|
+
functions_x_graphs: [],
|
|
691
|
+
graphid,
|
|
692
|
+
iconclass: props.iconclass || "",
|
|
693
|
+
is_editable: props.is_editable || null,
|
|
694
|
+
isresource: props.isresource || null,
|
|
695
|
+
jsonldcontext: props.jsonldcontext || null,
|
|
696
|
+
name,
|
|
697
|
+
nodegroups: [],
|
|
698
|
+
nodes: [root.copy()],
|
|
699
|
+
ontology_id: props.ontology_id || null,
|
|
700
|
+
publication,
|
|
701
|
+
relatable_resource_model_ids: props.relatable_resource_model_ids || [],
|
|
702
|
+
resource_2_resource_constraints: props.resource_2_resource_constraints || null,
|
|
703
|
+
root,
|
|
704
|
+
slug: props.slug || null,
|
|
705
|
+
subtitle: props.subtitle ? props.subtitle instanceof StaticTranslatableString ? props.subtitle : new StaticTranslatableString(props.subtitle) : new StaticTranslatableString(""),
|
|
706
|
+
template_id: props.template_id || "",
|
|
707
|
+
version: props.version || ""
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
class StaticValue {
|
|
712
|
+
constructor(jsonData, concept = null) {
|
|
713
|
+
__publicField(this, "id");
|
|
714
|
+
__publicField(this, "value");
|
|
715
|
+
__publicField(this, "__concept");
|
|
716
|
+
__publicField(this, "__conceptId");
|
|
717
|
+
this.id = jsonData.id;
|
|
718
|
+
this.value = jsonData.value;
|
|
719
|
+
if (concept instanceof StaticConcept) {
|
|
720
|
+
this.__concept = concept;
|
|
721
|
+
this.__conceptId = concept ? concept.id : null;
|
|
722
|
+
} else {
|
|
723
|
+
this.__concept = null;
|
|
724
|
+
this.__conceptId = concept;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
toString() {
|
|
728
|
+
return this.value;
|
|
729
|
+
}
|
|
730
|
+
static create(referent, valueType, value, language) {
|
|
731
|
+
const lang = language || getCurrentLanguage$1();
|
|
732
|
+
const referentId = referent instanceof StaticConcept ? referent.id : referent;
|
|
733
|
+
const concept = referent instanceof StaticConcept ? referent : null;
|
|
734
|
+
const id = generateUuidv5(
|
|
735
|
+
["value"],
|
|
736
|
+
`${referentId}/${valueType}/${value}/${lang}`
|
|
737
|
+
);
|
|
738
|
+
return new StaticValue(
|
|
739
|
+
{
|
|
740
|
+
id,
|
|
741
|
+
value
|
|
742
|
+
},
|
|
743
|
+
concept
|
|
744
|
+
);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
class StaticConcept {
|
|
748
|
+
constructor(jsonData) {
|
|
749
|
+
__publicField(this, "id");
|
|
750
|
+
__publicField(this, "prefLabels");
|
|
751
|
+
__publicField(this, "source");
|
|
752
|
+
__publicField(this, "sortOrder");
|
|
753
|
+
__publicField(this, "children");
|
|
754
|
+
this.id = jsonData.id;
|
|
755
|
+
this.prefLabels = jsonData.prefLabels;
|
|
756
|
+
for (const [lang, value] of Object.entries(this.prefLabels)) {
|
|
757
|
+
if (!(value instanceof StaticValue)) {
|
|
758
|
+
this.prefLabels[lang] = new StaticValue(value, this);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
this.source = jsonData.source;
|
|
762
|
+
this.sortOrder = jsonData.sortOrder;
|
|
763
|
+
this.children = jsonData.children;
|
|
764
|
+
if (this.children) {
|
|
765
|
+
this.children = this.children.map((child) => {
|
|
766
|
+
return child instanceof StaticConcept ? child : new StaticConcept(child);
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
getPrefLabel() {
|
|
771
|
+
return this.prefLabels[getCurrentLanguage$1()] || Object.values(this.prefLabels)[0];
|
|
772
|
+
}
|
|
773
|
+
toString() {
|
|
774
|
+
if (!this.getPrefLabel) {
|
|
775
|
+
return this.constructor(this).getPrefLabel().value;
|
|
776
|
+
}
|
|
777
|
+
return this.getPrefLabel().value;
|
|
778
|
+
}
|
|
779
|
+
// NB: copies value, does not make it a child
|
|
780
|
+
static fromValue(conceptScheme, value, children, config = {}) {
|
|
781
|
+
let lang = (config == null ? void 0 : config.baseLanguage) || getCurrentLanguage$1();
|
|
782
|
+
let tmpValue;
|
|
783
|
+
let prefLabels;
|
|
784
|
+
if (typeof value === "string") {
|
|
785
|
+
tmpValue = value;
|
|
786
|
+
prefLabels = { [lang]: new StaticValue({ id: "", value: tmpValue }) };
|
|
787
|
+
} else if (value instanceof StaticValue) {
|
|
788
|
+
tmpValue = value.value;
|
|
789
|
+
prefLabels = { [lang]: value };
|
|
790
|
+
} else if (lang in value) {
|
|
791
|
+
tmpValue = value[lang].value;
|
|
792
|
+
prefLabels = value;
|
|
793
|
+
} else {
|
|
794
|
+
const firstValue = Object.entries(value).sort()[0];
|
|
795
|
+
if (firstValue === void 0) {
|
|
796
|
+
throw Error("Cannot create a concept from values without a non-empty value");
|
|
797
|
+
}
|
|
798
|
+
lang = firstValue[0];
|
|
799
|
+
tmpValue = firstValue[1].value;
|
|
800
|
+
prefLabels = value;
|
|
801
|
+
}
|
|
802
|
+
const conceptId = generateUuidv5(
|
|
803
|
+
["concept"],
|
|
804
|
+
`${(conceptScheme == null ? void 0 : conceptScheme.id) || "(none)"}/${tmpValue}`
|
|
805
|
+
);
|
|
806
|
+
const childConcepts = (children || []).map((child) => {
|
|
807
|
+
if (!(child instanceof StaticConcept)) {
|
|
808
|
+
return StaticConcept.fromValue(conceptScheme, value, [], { baseLanguage: config.baseLanguage });
|
|
809
|
+
}
|
|
810
|
+
return child;
|
|
811
|
+
});
|
|
812
|
+
return new StaticConcept({
|
|
813
|
+
id: conceptId,
|
|
814
|
+
prefLabels,
|
|
815
|
+
source: config.source || null,
|
|
816
|
+
sortOrder: config.sortOrder || null,
|
|
817
|
+
children: childConcepts
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
class StaticCollection {
|
|
822
|
+
constructor(jsonData) {
|
|
823
|
+
__publicField(this, "id");
|
|
824
|
+
__publicField(this, "prefLabels");
|
|
825
|
+
__publicField(this, "concepts");
|
|
826
|
+
__publicField(this, "__allConcepts");
|
|
827
|
+
__publicField(this, "__values");
|
|
828
|
+
this.id = jsonData.id;
|
|
829
|
+
this.prefLabels = jsonData.prefLabels;
|
|
830
|
+
this.concepts = jsonData.concepts;
|
|
831
|
+
this.__allConcepts = {};
|
|
832
|
+
this.__values = {};
|
|
833
|
+
const addValues = (concept) => {
|
|
834
|
+
this.__allConcepts[concept.id] = concept;
|
|
835
|
+
for (const [, value] of Object.entries(concept.prefLabels)) {
|
|
836
|
+
this.__values[value.id] = value;
|
|
837
|
+
}
|
|
838
|
+
if (concept.children) {
|
|
839
|
+
for (let child of concept.children) {
|
|
840
|
+
if (!(child instanceof StaticConcept)) {
|
|
841
|
+
child = new StaticConcept(child);
|
|
842
|
+
}
|
|
843
|
+
addValues(child);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
for (const [id, concept] of Object.entries(this.concepts)) {
|
|
848
|
+
if (!(concept instanceof StaticConcept)) {
|
|
849
|
+
this.concepts[id] = new StaticConcept(concept);
|
|
850
|
+
}
|
|
851
|
+
addValues(this.concepts[id]);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
static fromConceptScheme(props) {
|
|
855
|
+
const collectionName = props.name ?? props.conceptScheme.toString();
|
|
856
|
+
return StaticCollection.create({
|
|
857
|
+
name: collectionName,
|
|
858
|
+
concepts: props.conceptScheme.children || []
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
static create(props) {
|
|
862
|
+
let concepts = props.concepts;
|
|
863
|
+
if (Array.isArray(concepts)) {
|
|
864
|
+
concepts = concepts.reduce(
|
|
865
|
+
(acc, c) => {
|
|
866
|
+
acc[c.id] = c;
|
|
867
|
+
return acc;
|
|
868
|
+
},
|
|
869
|
+
{}
|
|
870
|
+
);
|
|
871
|
+
}
|
|
872
|
+
const name = typeof props.name === "string" ? StaticValue.create("", "prefLabel", props.name) : props.name;
|
|
873
|
+
let collectionid = props.collectionid;
|
|
874
|
+
if (!collectionid) {
|
|
875
|
+
if (typeof name === "string") {
|
|
876
|
+
collectionid = generateUuidv5(
|
|
877
|
+
["collection"],
|
|
878
|
+
name
|
|
879
|
+
);
|
|
880
|
+
} else if (name instanceof StaticValue) {
|
|
881
|
+
collectionid = generateUuidv5(
|
|
882
|
+
["collection"],
|
|
883
|
+
name.value
|
|
884
|
+
);
|
|
885
|
+
} else {
|
|
886
|
+
throw Error("Must have a unique name to create a collection ID");
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
const prefLabels = name instanceof StaticValue ? {
|
|
890
|
+
[getCurrentLanguage$1()]: name
|
|
891
|
+
} : name;
|
|
892
|
+
return new StaticCollection({
|
|
893
|
+
id: collectionid,
|
|
894
|
+
prefLabels,
|
|
895
|
+
concepts,
|
|
896
|
+
__allConcepts: {},
|
|
897
|
+
__values: {}
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
getConceptValue(valueId) {
|
|
901
|
+
return this.__values[valueId];
|
|
902
|
+
}
|
|
903
|
+
getConceptByValue(label) {
|
|
904
|
+
var _a2;
|
|
905
|
+
return (_a2 = Object.values(this.__values).find((value) => value.value == label)) == null ? void 0 : _a2.__concept;
|
|
906
|
+
}
|
|
907
|
+
toString() {
|
|
908
|
+
return (this.prefLabels[getCurrentLanguage$1()] || Object.values(this.prefLabels)[0] || "").toString();
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
class StaticTile {
|
|
912
|
+
constructor(jsonData) {
|
|
913
|
+
__publicField(this, "data");
|
|
914
|
+
__publicField(this, "nodegroup_id");
|
|
915
|
+
__publicField(this, "resourceinstance_id");
|
|
916
|
+
__publicField(this, "tileid");
|
|
917
|
+
__publicField(this, "parenttile_id", null);
|
|
918
|
+
__publicField(this, "provisionaledits", null);
|
|
919
|
+
__publicField(this, "sortorder", null);
|
|
920
|
+
this.data = jsonData.data;
|
|
921
|
+
if (typeof this.data === "object" && !(this.data instanceof Map)) {
|
|
922
|
+
this.data = new Map(Object.entries(this.data));
|
|
923
|
+
}
|
|
924
|
+
this.nodegroup_id = jsonData.nodegroup_id;
|
|
925
|
+
this.resourceinstance_id = jsonData.resourceinstance_id;
|
|
926
|
+
this.tileid = jsonData.tileid;
|
|
927
|
+
this.parenttile_id = jsonData.parenttile_id;
|
|
928
|
+
this.provisionaledits = jsonData.provisionaledits;
|
|
929
|
+
this.sortorder = jsonData.sortorder;
|
|
930
|
+
}
|
|
931
|
+
ensureId() {
|
|
932
|
+
if (!this.tileid) {
|
|
933
|
+
this.tileid = crypto.randomUUID();
|
|
934
|
+
}
|
|
935
|
+
return this.tileid;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
class StaticResourceDescriptors {
|
|
939
|
+
constructor(jsonData) {
|
|
940
|
+
__publicField(this, "name");
|
|
941
|
+
__publicField(this, "map_popup");
|
|
942
|
+
__publicField(this, "description");
|
|
943
|
+
if (jsonData) {
|
|
944
|
+
this.name = jsonData.name;
|
|
945
|
+
this.map_popup = jsonData.map_popup;
|
|
946
|
+
this.description = jsonData.description;
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
isEmpty() {
|
|
950
|
+
return !(this.name || this.map_popup || this.description);
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
class StaticResourceMetadata {
|
|
954
|
+
constructor(jsonData) {
|
|
955
|
+
__publicField(this, "descriptors");
|
|
956
|
+
__publicField(this, "graph_id");
|
|
957
|
+
__publicField(this, "name");
|
|
958
|
+
__publicField(this, "resourceinstanceid");
|
|
959
|
+
__publicField(this, "publication_id", null);
|
|
960
|
+
__publicField(this, "principaluser_id", null);
|
|
961
|
+
__publicField(this, "legacyid", null);
|
|
962
|
+
__publicField(this, "graph_publication_id", null);
|
|
963
|
+
this.descriptors = jsonData.descriptors;
|
|
964
|
+
if (!(this.descriptors instanceof StaticResourceDescriptors)) {
|
|
965
|
+
if (jsonData.descriptors instanceof Map) {
|
|
966
|
+
this.descriptors = new StaticResourceDescriptors(Object.fromEntries(jsonData.descriptors.entries()));
|
|
967
|
+
} else {
|
|
968
|
+
this.descriptors = new StaticResourceDescriptors(this.descriptors);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
this.graph_id = jsonData.graph_id;
|
|
972
|
+
this.name = jsonData.name;
|
|
973
|
+
this.resourceinstanceid = jsonData.resourceinstanceid;
|
|
974
|
+
this.publication_id = jsonData.publication_id;
|
|
975
|
+
this.principaluser_id = jsonData.principaluser_id;
|
|
976
|
+
this.legacyid = jsonData.legacyid;
|
|
977
|
+
this.graph_publication_id = jsonData.graph_publication_id;
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
class StaticDomainValue {
|
|
981
|
+
constructor(jsonData) {
|
|
982
|
+
__publicField(this, "id");
|
|
983
|
+
__publicField(this, "selected");
|
|
984
|
+
__publicField(this, "text");
|
|
985
|
+
this.id = jsonData.id;
|
|
986
|
+
this.selected = jsonData.selected;
|
|
987
|
+
this.text = jsonData.text;
|
|
988
|
+
}
|
|
989
|
+
toString() {
|
|
990
|
+
const lang = getCurrentLanguage$1();
|
|
991
|
+
let localized = this.text[lang];
|
|
992
|
+
if (typeof localized !== "string") {
|
|
993
|
+
localized = Object.values(this.text)[0];
|
|
994
|
+
}
|
|
995
|
+
if (!localized) {
|
|
996
|
+
throw Error(`Could not render domain value ${this.id} in language ${lang}`);
|
|
997
|
+
}
|
|
998
|
+
return localized;
|
|
999
|
+
}
|
|
1000
|
+
lang(lang) {
|
|
1001
|
+
return this.text[lang];
|
|
1002
|
+
}
|
|
1003
|
+
async forJson() {
|
|
1004
|
+
return {
|
|
1005
|
+
id: this.id,
|
|
1006
|
+
selected: this.selected,
|
|
1007
|
+
text: this.text
|
|
1008
|
+
};
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
class StaticResourceReference {
|
|
1012
|
+
constructor(jsonData) {
|
|
1013
|
+
__publicField(this, "id");
|
|
1014
|
+
__publicField(this, "type");
|
|
1015
|
+
__publicField(this, "graphId");
|
|
1016
|
+
__publicField(this, "title");
|
|
1017
|
+
__publicField(this, "root");
|
|
1018
|
+
__publicField(this, "meta");
|
|
1019
|
+
this.id = jsonData.id;
|
|
1020
|
+
this.type = jsonData.type;
|
|
1021
|
+
this.graphId = jsonData.graphId;
|
|
1022
|
+
this.root = jsonData.root;
|
|
1023
|
+
this.title = jsonData.title;
|
|
1024
|
+
if (jsonData.meta) {
|
|
1025
|
+
this.meta = jsonData.meta;
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
class StaticResource {
|
|
1030
|
+
constructor(jsonData) {
|
|
1031
|
+
__publicField(this, "resourceinstance");
|
|
1032
|
+
__publicField(this, "tiles", null);
|
|
1033
|
+
__publicField(this, "metadata");
|
|
1034
|
+
__publicField(this, "__cache");
|
|
1035
|
+
__publicField(this, "__source");
|
|
1036
|
+
__publicField(this, "__scopes");
|
|
1037
|
+
this.resourceinstance = new StaticResourceMetadata(
|
|
1038
|
+
jsonData.resourceinstance
|
|
1039
|
+
);
|
|
1040
|
+
this.tiles = jsonData.tiles && jsonData.tiles.map((tile) => new StaticTile(tile));
|
|
1041
|
+
this.metadata = jsonData.metadata || {};
|
|
1042
|
+
this.__cache = jsonData.__cache;
|
|
1043
|
+
this.__scopes = jsonData.__scopes;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
const staticTypes = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1047
|
+
__proto__: null,
|
|
1048
|
+
StaticCard,
|
|
1049
|
+
StaticCardsXNodesXWidgets,
|
|
1050
|
+
StaticCollection,
|
|
1051
|
+
StaticConcept,
|
|
1052
|
+
StaticConstraint,
|
|
1053
|
+
StaticDomainValue,
|
|
1054
|
+
StaticEdge,
|
|
1055
|
+
StaticFunctionsXGraphs,
|
|
1056
|
+
StaticGraph,
|
|
1057
|
+
StaticGraphMeta,
|
|
1058
|
+
StaticNode,
|
|
1059
|
+
StaticNodegroup,
|
|
1060
|
+
StaticResource,
|
|
1061
|
+
StaticResourceDescriptors,
|
|
1062
|
+
StaticResourceMetadata,
|
|
1063
|
+
StaticResourceReference,
|
|
1064
|
+
StaticTile,
|
|
1065
|
+
StaticTranslatableString,
|
|
1066
|
+
StaticValue
|
|
1067
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
1068
|
+
class GraphResult {
|
|
1069
|
+
constructor(jsonData) {
|
|
1070
|
+
__publicField(this, "models");
|
|
1071
|
+
this.models = Object.fromEntries(
|
|
1072
|
+
Object.entries(jsonData.models).map(([k, v]) => [k, new StaticGraphMeta(v)])
|
|
1073
|
+
);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
class ArchesClient {
|
|
1077
|
+
}
|
|
1078
|
+
class ArchesClientRemote extends ArchesClient {
|
|
1079
|
+
constructor(archesUrl) {
|
|
1080
|
+
super();
|
|
1081
|
+
__publicField(this, "archesUrl");
|
|
1082
|
+
this.archesUrl = archesUrl;
|
|
1083
|
+
}
|
|
1084
|
+
async getGraphs() {
|
|
1085
|
+
const response = await fetch(
|
|
1086
|
+
`${this.archesUrl}/api/arches/graphs?format=arches-json&hide_empty_nodes=false&compact=false`
|
|
1087
|
+
);
|
|
1088
|
+
return await response.json();
|
|
1089
|
+
}
|
|
1090
|
+
async getGraph(graph) {
|
|
1091
|
+
return this.getGraphByIdOnly(graph.graphid);
|
|
1092
|
+
}
|
|
1093
|
+
async getGraphByIdOnly(graphId) {
|
|
1094
|
+
const response = await fetch(
|
|
1095
|
+
`${this.archesUrl}/graphs/${graphId}?format=arches-json&gen=`
|
|
1096
|
+
);
|
|
1097
|
+
return await response.json();
|
|
1098
|
+
}
|
|
1099
|
+
async getResource(resourceId) {
|
|
1100
|
+
throw Error(`Not implemented yet: getResource(${resourceId}`);
|
|
1101
|
+
}
|
|
1102
|
+
async getCollection(collectionId) {
|
|
1103
|
+
throw Error(`Not implemented yet: getCollection(${collectionId}`);
|
|
1104
|
+
}
|
|
1105
|
+
async getResources(graphId, limit) {
|
|
1106
|
+
const response = await fetch(
|
|
1107
|
+
`${this.archesUrl}/resources?graph_uuid=${graphId}&format=arches-json&hide_empty_nodes=false&compact=false&limit=${limit}`
|
|
1108
|
+
);
|
|
1109
|
+
return await response.json();
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
class ArchesClientRemoteStatic extends ArchesClient {
|
|
1113
|
+
constructor(archesUrl, {
|
|
1114
|
+
allGraphFile,
|
|
1115
|
+
graphToGraphFile,
|
|
1116
|
+
graphIdToResourcesFiles,
|
|
1117
|
+
resourceIdToFile,
|
|
1118
|
+
collectionIdToFile,
|
|
1119
|
+
graphIdToGraphFile
|
|
1120
|
+
} = {}) {
|
|
1121
|
+
super();
|
|
1122
|
+
__publicField(this, "archesUrl");
|
|
1123
|
+
__publicField(this, "allGraphFile");
|
|
1124
|
+
__publicField(this, "graphToGraphFile");
|
|
1125
|
+
__publicField(this, "graphIdToGraphFile");
|
|
1126
|
+
__publicField(this, "graphIdToResourcesFiles");
|
|
1127
|
+
__publicField(this, "resourceIdToFile");
|
|
1128
|
+
__publicField(this, "collectionIdToFile");
|
|
1129
|
+
this.archesUrl = archesUrl;
|
|
1130
|
+
this.allGraphFile = allGraphFile || (() => "resource_models/_all.json");
|
|
1131
|
+
this.graphToGraphFile = graphToGraphFile;
|
|
1132
|
+
this.graphIdToGraphFile = graphIdToGraphFile || ((graphId) => `resource_models/${graphId}.json`);
|
|
1133
|
+
this.graphIdToResourcesFiles = graphIdToResourcesFiles || ((graphId) => [`business_data/_${graphId}.json`]);
|
|
1134
|
+
this.resourceIdToFile = resourceIdToFile || ((resourceId) => `business_data/${resourceId}.json`);
|
|
1135
|
+
this.collectionIdToFile = collectionIdToFile || ((collectionId) => `collections/${collectionId}.json`);
|
|
1136
|
+
}
|
|
1137
|
+
async getGraphs() {
|
|
1138
|
+
const response = await fetch(`${this.archesUrl}/${this.allGraphFile()}`);
|
|
1139
|
+
return await response.json();
|
|
1140
|
+
}
|
|
1141
|
+
async getGraph(graph) {
|
|
1142
|
+
if (!this.graphToGraphFile) {
|
|
1143
|
+
return this.getGraphByIdOnly(graph.graphid);
|
|
1144
|
+
}
|
|
1145
|
+
const response = await fetch(
|
|
1146
|
+
`${this.archesUrl}/${this.graphToGraphFile(graph)}`
|
|
1147
|
+
);
|
|
1148
|
+
return (await response.json()).graph[0];
|
|
1149
|
+
}
|
|
1150
|
+
async getGraphByIdOnly(graphId) {
|
|
1151
|
+
const response = await fetch(
|
|
1152
|
+
`${this.archesUrl}/${this.graphIdToGraphFile(graphId)}`
|
|
1153
|
+
);
|
|
1154
|
+
return (await response.json()).graph[0];
|
|
1155
|
+
}
|
|
1156
|
+
async getResource(resourceId) {
|
|
1157
|
+
const source = `${this.archesUrl}/${this.resourceIdToFile(resourceId)}`;
|
|
1158
|
+
const response = await fetch(source);
|
|
1159
|
+
return response.json().then((response2) => {
|
|
1160
|
+
response2.__source = source;
|
|
1161
|
+
return response2;
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
async getCollection(collectionId) {
|
|
1165
|
+
const response = await fetch(
|
|
1166
|
+
`${this.archesUrl}/${this.collectionIdToFile(collectionId)}`
|
|
1167
|
+
);
|
|
1168
|
+
return await response.json();
|
|
1169
|
+
}
|
|
1170
|
+
async getResources(graphId, limit) {
|
|
1171
|
+
const resources = [];
|
|
1172
|
+
for (const file of this.graphIdToResourcesFiles(graphId)) {
|
|
1173
|
+
const source = `${this.archesUrl}/${file}`;
|
|
1174
|
+
const response = await fetch(source);
|
|
1175
|
+
const resourceSet = (await response.json()).business_data.resources;
|
|
1176
|
+
for (const resource of resourceSet) {
|
|
1177
|
+
resource.__source = source;
|
|
1178
|
+
}
|
|
1179
|
+
resources.push(...limit ? resourceSet.slice(0, limit) : resourceSet);
|
|
1180
|
+
if (limit && resources.length > limit) {
|
|
1181
|
+
break;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
return resources;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
class ArchesClientLocal extends ArchesClient {
|
|
1188
|
+
constructor({
|
|
1189
|
+
allGraphFile,
|
|
1190
|
+
graphToGraphFile,
|
|
1191
|
+
graphIdToResourcesFiles,
|
|
1192
|
+
resourceIdToFile,
|
|
1193
|
+
collectionIdToFile,
|
|
1194
|
+
graphIdToGraphFile
|
|
1195
|
+
} = {}) {
|
|
1196
|
+
super();
|
|
1197
|
+
__publicField(this, "fs");
|
|
1198
|
+
__publicField(this, "allGraphFile");
|
|
1199
|
+
__publicField(this, "graphToGraphFile");
|
|
1200
|
+
__publicField(this, "graphIdToGraphFile");
|
|
1201
|
+
__publicField(this, "graphIdToResourcesFiles");
|
|
1202
|
+
__publicField(this, "resourceIdToFile");
|
|
1203
|
+
__publicField(this, "collectionIdToFile");
|
|
1204
|
+
this.fs = import("./__vite-browser-external-2Ng8QIWW.js");
|
|
1205
|
+
this.allGraphFile = allGraphFile || (() => "tests/definitions/models/_all.json");
|
|
1206
|
+
this.graphToGraphFile = graphToGraphFile || ((graph) => `tests/definitions/models/${graph.graphid}.json`);
|
|
1207
|
+
this.graphIdToGraphFile = graphIdToGraphFile || ((graphId) => `tests/definitions/models/${graphId}.json`);
|
|
1208
|
+
this.graphIdToResourcesFiles = graphIdToResourcesFiles || ((graphId) => [`tests/definitions/resources/_${graphId}.json`]);
|
|
1209
|
+
this.resourceIdToFile = resourceIdToFile || ((resourceId) => `tests/definitions/resources/${resourceId}.json`);
|
|
1210
|
+
this.collectionIdToFile = collectionIdToFile || ((collectionId) => `tests/definitions/collections/${collectionId}.json`);
|
|
1211
|
+
}
|
|
1212
|
+
async getGraphs() {
|
|
1213
|
+
const fs = await this.fs;
|
|
1214
|
+
const response = await fs.promises.readFile(this.allGraphFile(), "utf8");
|
|
1215
|
+
return new GraphResult(await JSON.parse(response));
|
|
1216
|
+
}
|
|
1217
|
+
async getGraph(graph) {
|
|
1218
|
+
const fs = await this.fs;
|
|
1219
|
+
const graphFile = this.graphToGraphFile ? this.graphToGraphFile(graph) : this.graphIdToGraphFile(graph.graphid);
|
|
1220
|
+
if (!graphFile) {
|
|
1221
|
+
return null;
|
|
1222
|
+
}
|
|
1223
|
+
const response = await fs.promises.readFile(
|
|
1224
|
+
graphFile,
|
|
1225
|
+
"utf8"
|
|
1226
|
+
);
|
|
1227
|
+
return await JSON.parse(response).graph[0];
|
|
1228
|
+
}
|
|
1229
|
+
async getGraphByIdOnly(graphId) {
|
|
1230
|
+
const fs = await this.fs;
|
|
1231
|
+
const graphFile = this.graphIdToGraphFile(graphId);
|
|
1232
|
+
if (!graphFile) {
|
|
1233
|
+
return null;
|
|
1234
|
+
}
|
|
1235
|
+
const response = await fs.promises.readFile(
|
|
1236
|
+
graphFile,
|
|
1237
|
+
"utf8"
|
|
1238
|
+
);
|
|
1239
|
+
return await JSON.parse(response).graph[0];
|
|
1240
|
+
}
|
|
1241
|
+
async getResource(resourceId) {
|
|
1242
|
+
const fs = await this.fs;
|
|
1243
|
+
const source = this.resourceIdToFile(resourceId);
|
|
1244
|
+
const response = await fs.promises.readFile(
|
|
1245
|
+
source,
|
|
1246
|
+
"utf8"
|
|
1247
|
+
);
|
|
1248
|
+
return JSON.parse(response).then((resource) => {
|
|
1249
|
+
resource.__source = source;
|
|
1250
|
+
return resource;
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
async getCollection(collectionId) {
|
|
1254
|
+
const fs = await this.fs;
|
|
1255
|
+
const response = await fs.promises.readFile(
|
|
1256
|
+
this.collectionIdToFile(collectionId),
|
|
1257
|
+
"utf8"
|
|
1258
|
+
);
|
|
1259
|
+
return await JSON.parse(response);
|
|
1260
|
+
}
|
|
1261
|
+
async getResources(graphId, limit) {
|
|
1262
|
+
const fs = await this.fs;
|
|
1263
|
+
const resources = [];
|
|
1264
|
+
for (const file of this.graphIdToResourcesFiles(graphId)) {
|
|
1265
|
+
const response = JSON.parse(await fs.promises.readFile(file, "utf8"));
|
|
1266
|
+
const source = file;
|
|
1267
|
+
const resourceSet = response.business_data.resources.filter(
|
|
1268
|
+
(resource) => graphId === resource.resourceinstance.graph_id
|
|
1269
|
+
);
|
|
1270
|
+
for (const resource of resourceSet) {
|
|
1271
|
+
resource.__source = source;
|
|
1272
|
+
}
|
|
1273
|
+
resources.push(...limit ? resourceSet.slice(0, limit) : resourceSet);
|
|
1274
|
+
if (limit && resources.length > limit) {
|
|
1275
|
+
break;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
return resources;
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
const archesClient = new ArchesClientRemote("http://localhost:8000");
|
|
1282
|
+
const client = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1283
|
+
__proto__: null,
|
|
1284
|
+
ArchesClient,
|
|
1285
|
+
ArchesClientLocal,
|
|
1286
|
+
ArchesClientRemote,
|
|
1287
|
+
ArchesClientRemoteStatic,
|
|
1288
|
+
GraphResult,
|
|
1289
|
+
archesClient
|
|
1290
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
1291
|
+
const interfaces = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1292
|
+
__proto__: null
|
|
1293
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
1294
|
+
class ReferenceDataManager {
|
|
1295
|
+
constructor(archesClient2) {
|
|
1296
|
+
__publicField(this, "archesClient");
|
|
1297
|
+
__publicField(this, "collections");
|
|
1298
|
+
this.archesClient = archesClient2;
|
|
1299
|
+
this.collections = /* @__PURE__ */ new Map();
|
|
1300
|
+
}
|
|
1301
|
+
retrieveCollection(id) {
|
|
1302
|
+
let collection = this.collections.get(id);
|
|
1303
|
+
if (collection !== void 0) {
|
|
1304
|
+
return collection;
|
|
1305
|
+
}
|
|
1306
|
+
collection = this.archesClient.getCollection(id).then((jsonData) => new StaticCollection(jsonData));
|
|
1307
|
+
this.collections.set(id, collection);
|
|
1308
|
+
return collection;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
const RDM = new ReferenceDataManager(archesClient);
|
|
1312
|
+
class StaticStore {
|
|
1313
|
+
constructor(archesClient2, cacheMetadataOnly = true) {
|
|
1314
|
+
__publicField(this, "archesClient");
|
|
1315
|
+
__publicField(this, "cache");
|
|
1316
|
+
__publicField(this, "cacheMetadataOnly");
|
|
1317
|
+
this.archesClient = archesClient2;
|
|
1318
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
1319
|
+
this.cacheMetadataOnly = cacheMetadataOnly;
|
|
1320
|
+
}
|
|
1321
|
+
async getMeta(id, onlyIfCached = true) {
|
|
1322
|
+
if (this.cache.has(id)) {
|
|
1323
|
+
const resource = this.cache.get(id);
|
|
1324
|
+
if (resource instanceof StaticResource) {
|
|
1325
|
+
return resource.resourceinstance;
|
|
1326
|
+
}
|
|
1327
|
+
return resource || null;
|
|
1328
|
+
}
|
|
1329
|
+
if (!onlyIfCached) {
|
|
1330
|
+
const resource = await this.loadOne(id);
|
|
1331
|
+
return resource.resourceinstance;
|
|
1332
|
+
}
|
|
1333
|
+
return null;
|
|
1334
|
+
}
|
|
1335
|
+
async *loadAll(graphId, limit = void 0) {
|
|
1336
|
+
const resourcesJSON = await this.archesClient.getResources(graphId, limit || 0);
|
|
1337
|
+
for (const resourceJSON of resourcesJSON.values()) {
|
|
1338
|
+
const resource = new StaticResource(resourceJSON);
|
|
1339
|
+
if (resource.resourceinstance.graph_id !== graphId) {
|
|
1340
|
+
continue;
|
|
1341
|
+
}
|
|
1342
|
+
this.cache.set(
|
|
1343
|
+
resource.resourceinstance.resourceinstanceid,
|
|
1344
|
+
this.cacheMetadataOnly ? resource.resourceinstance : resource
|
|
1345
|
+
);
|
|
1346
|
+
yield resource;
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
async loadOne(id) {
|
|
1350
|
+
if (this.cache.has(id)) {
|
|
1351
|
+
const resource2 = this.cache.get(id);
|
|
1352
|
+
if (resource2 instanceof StaticResource) {
|
|
1353
|
+
return resource2;
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
const resourceJSON = await this.archesClient.getResource(id);
|
|
1357
|
+
const resource = new StaticResource(resourceJSON);
|
|
1358
|
+
if (this.cacheMetadataOnly) {
|
|
1359
|
+
this.cache.set(id, this.cacheMetadataOnly ? resource.resourceinstance : resource);
|
|
1360
|
+
}
|
|
1361
|
+
return resource;
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
const staticStore = new StaticStore(archesClient);
|
|
1365
|
+
class CardComponent {
|
|
1366
|
+
constructor(id, name) {
|
|
1367
|
+
__publicField(this, "id");
|
|
1368
|
+
__publicField(this, "name");
|
|
1369
|
+
this.id = id;
|
|
1370
|
+
this.name = name;
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
class Widget {
|
|
1374
|
+
// as JSON - always need a fresh copy
|
|
1375
|
+
constructor(id, name, datatype, defaultConfig) {
|
|
1376
|
+
__publicField(this, "id");
|
|
1377
|
+
__publicField(this, "name");
|
|
1378
|
+
__publicField(this, "datatype");
|
|
1379
|
+
__publicField(this, "defaultConfig");
|
|
1380
|
+
this.id = id;
|
|
1381
|
+
this.name = name;
|
|
1382
|
+
this.datatype = datatype;
|
|
1383
|
+
this.defaultConfig = defaultConfig;
|
|
1384
|
+
}
|
|
1385
|
+
getDefaultConfig() {
|
|
1386
|
+
return JSON.parse(this.defaultConfig);
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
const DEFAULT_CARD_COMPONENT = new CardComponent(
|
|
1390
|
+
"f05e4d3a-53c1-11e8-b0ea-784f435179ea",
|
|
1391
|
+
"Default Card"
|
|
1392
|
+
);
|
|
1393
|
+
const _WIDGET_VALUES = [
|
|
1394
|
+
["10000000-0000-0000-0000-000000000001", "text-widget", "string", '{ "placeholder": "Enter text", "width": "100%", "maxLength": null}'],
|
|
1395
|
+
["10000000-0000-0000-0000-000000000002", "concept-select-widget", "concept", '{ "placeholder": "Select an option", "options": [] }'],
|
|
1396
|
+
["10000000-0000-0000-0000-000000000012", "concept-multiselect-widget", "concept-list", '{ "placeholder": "Select an option", "options": [] }'],
|
|
1397
|
+
["10000000-0000-0000-0000-000000000015", "domain-select-widget", "domain-value", '{ "placeholder": "Select an option" }'],
|
|
1398
|
+
["10000000-0000-0000-0000-000000000016", "domain-multiselect-widget", "domain-value-list", '{ "placeholder": "Select an option" }'],
|
|
1399
|
+
["10000000-0000-0000-0000-000000000003", "switch-widget", "boolean", '{ "subtitle": "Click to switch"}'],
|
|
1400
|
+
["10000000-0000-0000-0000-000000000004", "datepicker-widget", "date", `{
|
|
1401
|
+
"placeholder": "Enter date",
|
|
1402
|
+
"viewMode": "days",
|
|
1403
|
+
"dateFormat": "YYYY-MM-DD",
|
|
1404
|
+
"minDate": false,
|
|
1405
|
+
"maxDate": false
|
|
1406
|
+
}`],
|
|
1407
|
+
["10000000-0000-0000-0000-000000000005", "rich-text-widget", "string", "{}"],
|
|
1408
|
+
["10000000-0000-0000-0000-000000000006", "radio-boolean-widget", "boolean", '{"trueLabel": "Yes", "falseLabel": "No"}'],
|
|
1409
|
+
["10000000-0000-0000-0000-000000000007", "map-widget", "geojson-feature-collection", `{
|
|
1410
|
+
"basemap": "streets",
|
|
1411
|
+
"geometryTypes": [{"text":"Point", "id":"Point"}, {"text":"Line", "id":"Line"}, {"text":"Polygon", "id":"Polygon"}],
|
|
1412
|
+
"overlayConfigs": [],
|
|
1413
|
+
"overlayOpacity": 0.0,
|
|
1414
|
+
"geocodeProvider": "MapzenGeocoder",
|
|
1415
|
+
"zoom": 0,
|
|
1416
|
+
"maxZoom": 20,
|
|
1417
|
+
"minZoom": 0,
|
|
1418
|
+
"centerX": 0,
|
|
1419
|
+
"centerY": 0,
|
|
1420
|
+
"pitch": 0.0,
|
|
1421
|
+
"bearing": 0.0,
|
|
1422
|
+
"geocodePlaceholder": "Search",
|
|
1423
|
+
"geocoderVisible": true,
|
|
1424
|
+
"featureColor": null,
|
|
1425
|
+
"featureLineWidth": null,
|
|
1426
|
+
"featurePointSize": null
|
|
1427
|
+
}`],
|
|
1428
|
+
["10000000-0000-0000-0000-000000000008", "number-widget", "number", '{ "placeholder": "Enter number", "width": "100%", "min":"", "max":""}'],
|
|
1429
|
+
["10000000-0000-0000-0000-000000000009", "concept-radio-widget", "concept", '{ "options": [] }'],
|
|
1430
|
+
["10000000-0000-0000-0000-000000000013", "concept-checkbox-widget", "concept-list", '{ "options": [] }'],
|
|
1431
|
+
["10000000-0000-0000-0000-000000000017", "domain-radio-widget", "domain-value", "{}"],
|
|
1432
|
+
["10000000-0000-0000-0000-000000000018", "domain-checkbox-widget", "domain-value-list", "{}"],
|
|
1433
|
+
["10000000-0000-0000-0000-000000000019", "file-widget", "file-list", '{"acceptedFiles": "", "maxFilesize": "200"}']
|
|
1434
|
+
];
|
|
1435
|
+
const WIDGETS = Object.fromEntries(_WIDGET_VALUES.map((constructor) => [constructor[1], new Widget(...constructor)]));
|
|
1436
|
+
function getDefaultWidgetForNode(node, preferences = {}) {
|
|
1437
|
+
const datatype = node.datatype;
|
|
1438
|
+
if (datatype in preferences) {
|
|
1439
|
+
return WIDGETS[preferences[datatype]];
|
|
1440
|
+
}
|
|
1441
|
+
if (datatype === "semantic") {
|
|
1442
|
+
throw Error("Not default widget for a semantic node");
|
|
1443
|
+
} else if (datatype === "number") {
|
|
1444
|
+
return WIDGETS["number-widget"];
|
|
1445
|
+
} else if (datatype === "string") {
|
|
1446
|
+
return WIDGETS["text-widget"];
|
|
1447
|
+
} else if (datatype === "concept") {
|
|
1448
|
+
return WIDGETS["concept-select-widget"];
|
|
1449
|
+
} else if (datatype === "concept-list") {
|
|
1450
|
+
return WIDGETS["concept-multiselect-widget"];
|
|
1451
|
+
} else if (datatype === "domain-value") {
|
|
1452
|
+
return WIDGETS["domain-select-widget"];
|
|
1453
|
+
} else if (datatype === "domain-value-list") {
|
|
1454
|
+
return WIDGETS["domain-multiselect-widget"];
|
|
1455
|
+
} else if (datatype === "geojson-feature-collection") {
|
|
1456
|
+
return WIDGETS["geojson-feature-collection"];
|
|
1457
|
+
} else if (datatype === "boolean") {
|
|
1458
|
+
return WIDGETS["switch-widget"];
|
|
1459
|
+
} else if (datatype === "date") {
|
|
1460
|
+
return WIDGETS["datepicker-widget"];
|
|
1461
|
+
} else {
|
|
1462
|
+
throw Error(`No default widget for ${datatype} datatype - perhaps you could supply a manual preference`);
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
class StaticNodeConfigBoolean {
|
|
1466
|
+
constructor(jsonData) {
|
|
1467
|
+
__publicField(this, "i18n_properties");
|
|
1468
|
+
__publicField(this, "falseLabel");
|
|
1469
|
+
__publicField(this, "trueLabel");
|
|
1470
|
+
this.i18n_properties = jsonData.i18n_properties;
|
|
1471
|
+
this.falseLabel = jsonData.falseLabel;
|
|
1472
|
+
this.trueLabel = jsonData.trueLabel;
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
class StaticNodeConfigConcept {
|
|
1476
|
+
constructor(jsonData) {
|
|
1477
|
+
__publicField(this, "rdmCollection");
|
|
1478
|
+
this.rdmCollection = jsonData.rdmCollection;
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
class StaticNodeConfigDomain {
|
|
1482
|
+
constructor(jsonData) {
|
|
1483
|
+
__publicField(this, "i18n_config");
|
|
1484
|
+
__publicField(this, "options");
|
|
1485
|
+
this.i18n_config = jsonData.i18n_config;
|
|
1486
|
+
this.options = jsonData.options;
|
|
1487
|
+
if (this.options) {
|
|
1488
|
+
this.options = this.options.map((sdv) => {
|
|
1489
|
+
if (!(sdv instanceof StaticDomainValue)) {
|
|
1490
|
+
return new StaticDomainValue(sdv);
|
|
1491
|
+
}
|
|
1492
|
+
return sdv;
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
getSelected() {
|
|
1497
|
+
return this.options.find((option) => option.selected);
|
|
1498
|
+
}
|
|
1499
|
+
valueFromId(id) {
|
|
1500
|
+
return this.options.find((option) => option.id == id);
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
const _NodeConfigManager = class _NodeConfigManager {
|
|
1504
|
+
constructor(cache = void 0) {
|
|
1505
|
+
__publicField(this, "cache");
|
|
1506
|
+
if (!cache) {
|
|
1507
|
+
cache = _NodeConfigManager._cache || /* @__PURE__ */ new Map();
|
|
1508
|
+
}
|
|
1509
|
+
this.cache = cache;
|
|
1510
|
+
}
|
|
1511
|
+
retrieve(node) {
|
|
1512
|
+
if (this.cache.has(node.nodeid)) {
|
|
1513
|
+
return this.cache.get(node.nodeid);
|
|
1514
|
+
}
|
|
1515
|
+
let nodeConfig2 = null;
|
|
1516
|
+
switch (node.datatype) {
|
|
1517
|
+
case "boolean":
|
|
1518
|
+
nodeConfig2 = new StaticNodeConfigBoolean(node.config);
|
|
1519
|
+
break;
|
|
1520
|
+
case "domain-value-list":
|
|
1521
|
+
case "domain-value":
|
|
1522
|
+
nodeConfig2 = new StaticNodeConfigDomain(node.config);
|
|
1523
|
+
break;
|
|
1524
|
+
}
|
|
1525
|
+
this.cache.set(node.nodeid, nodeConfig2);
|
|
1526
|
+
return nodeConfig2;
|
|
1527
|
+
}
|
|
1528
|
+
};
|
|
1529
|
+
__publicField(_NodeConfigManager, "_cache");
|
|
1530
|
+
let NodeConfigManager = _NodeConfigManager;
|
|
1531
|
+
const nodeConfigManager = new NodeConfigManager();
|
|
1532
|
+
const nodeConfig = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1533
|
+
__proto__: null,
|
|
1534
|
+
StaticNodeConfigBoolean,
|
|
1535
|
+
StaticNodeConfigConcept,
|
|
1536
|
+
StaticNodeConfigDomain,
|
|
1537
|
+
nodeConfigManager
|
|
1538
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
1539
|
+
const DEFAULT_LANGUAGE = "en";
|
|
1540
|
+
class ViewContext {
|
|
1541
|
+
constructor() {
|
|
1542
|
+
__publicField(this, "graphManager");
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
const viewContext = new ViewContext();
|
|
1546
|
+
function tileLoadingError(reason, exc) {
|
|
1547
|
+
{
|
|
1548
|
+
console.error(reason, exc);
|
|
1549
|
+
{
|
|
1550
|
+
throw exc;
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
class ValueList {
|
|
1555
|
+
constructor(values, allNodegroups, wrapper, tiles) {
|
|
1556
|
+
__publicField(this, "values");
|
|
1557
|
+
__publicField(this, "wrapper");
|
|
1558
|
+
__publicField(this, "tiles");
|
|
1559
|
+
__publicField(this, "promises");
|
|
1560
|
+
__publicField(this, "writeLock");
|
|
1561
|
+
this.values = values;
|
|
1562
|
+
this.wrapper = wrapper;
|
|
1563
|
+
this.tiles = tiles;
|
|
1564
|
+
this.promises = allNodegroups;
|
|
1565
|
+
this.writeLock = null;
|
|
1566
|
+
}
|
|
1567
|
+
async get(key) {
|
|
1568
|
+
return this.retrieve(key, this.values.get(key), true);
|
|
1569
|
+
}
|
|
1570
|
+
set(key, value) {
|
|
1571
|
+
this.values.set(key, value);
|
|
1572
|
+
}
|
|
1573
|
+
async has(key) {
|
|
1574
|
+
await this.retrieve(key, null);
|
|
1575
|
+
return this.values.has(key);
|
|
1576
|
+
}
|
|
1577
|
+
async retrieve(key, dflt = null, raiseError = false) {
|
|
1578
|
+
let result = this.values.get(key);
|
|
1579
|
+
if (Array.isArray(result)) {
|
|
1580
|
+
return result;
|
|
1581
|
+
}
|
|
1582
|
+
const node = this.wrapper.model.getNodeObjectsByAlias().get(key);
|
|
1583
|
+
result = await result;
|
|
1584
|
+
if (!node) {
|
|
1585
|
+
throw Error(`This key ${key} has no corresponding node`);
|
|
1586
|
+
}
|
|
1587
|
+
const nodegroupId = node.nodegroup_id || "";
|
|
1588
|
+
const promise = node ? await this.promises.get(nodegroupId) : false;
|
|
1589
|
+
if (promise === false) {
|
|
1590
|
+
await this.writeLock;
|
|
1591
|
+
if (this.wrapper.resource) {
|
|
1592
|
+
const node2 = this.wrapper.model.getNodeObjectsByAlias().get(key);
|
|
1593
|
+
if (node2 === void 0) {
|
|
1594
|
+
throw Error(
|
|
1595
|
+
"Tried to retrieve a node key that does not exist on this resource"
|
|
1596
|
+
);
|
|
1597
|
+
}
|
|
1598
|
+
const values = new Map([...this.values.entries()]);
|
|
1599
|
+
const promise2 = new Promise((resolve) => {
|
|
1600
|
+
return this.wrapper.ensureNodegroup(
|
|
1601
|
+
values,
|
|
1602
|
+
this.promises,
|
|
1603
|
+
nodegroupId,
|
|
1604
|
+
this.wrapper.model.getNodeObjects(),
|
|
1605
|
+
this.wrapper.model.getNodegroupObjects(),
|
|
1606
|
+
this.wrapper.model.getEdges(),
|
|
1607
|
+
false,
|
|
1608
|
+
this.tiles,
|
|
1609
|
+
true
|
|
1610
|
+
).then(async ([ngValues]) => {
|
|
1611
|
+
let original = false;
|
|
1612
|
+
const processValue = (k, concreteValue) => {
|
|
1613
|
+
if (key === k) {
|
|
1614
|
+
original = concreteValue;
|
|
1615
|
+
}
|
|
1616
|
+
if (concreteValue !== false) {
|
|
1617
|
+
this.values.set(k, concreteValue);
|
|
1618
|
+
}
|
|
1619
|
+
};
|
|
1620
|
+
return Promise.all([...ngValues.entries()].map(([k, value]) => {
|
|
1621
|
+
if (value instanceof Promise) {
|
|
1622
|
+
return value.then((concreteValue) => processValue(k, concreteValue));
|
|
1623
|
+
}
|
|
1624
|
+
processValue(k, value);
|
|
1625
|
+
})).then(() => {
|
|
1626
|
+
resolve(original);
|
|
1627
|
+
});
|
|
1628
|
+
});
|
|
1629
|
+
});
|
|
1630
|
+
this.writeLock = promise2;
|
|
1631
|
+
this.promises.set(nodegroupId, promise2);
|
|
1632
|
+
this.values.set(key, promise2);
|
|
1633
|
+
await promise2;
|
|
1634
|
+
this.promises.set(nodegroupId, true);
|
|
1635
|
+
} else {
|
|
1636
|
+
this.values.delete(key);
|
|
1637
|
+
}
|
|
1638
|
+
result = await this.values.get(key);
|
|
1639
|
+
}
|
|
1640
|
+
result = await result;
|
|
1641
|
+
if (result === void 0 || result === false) {
|
|
1642
|
+
if (raiseError) {
|
|
1643
|
+
throw Error(`Unset key ${key}`);
|
|
1644
|
+
} else {
|
|
1645
|
+
return dflt;
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
return result;
|
|
1649
|
+
}
|
|
1650
|
+
async setDefault(key, value) {
|
|
1651
|
+
const newValue = await this.retrieve(key, value, false);
|
|
1652
|
+
this.values.set(key, newValue);
|
|
1653
|
+
return newValue;
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
class ConceptListCacheEntry {
|
|
1657
|
+
constructor({ meta, _ }) {
|
|
1658
|
+
__publicField(this, "datatype", "concept-list");
|
|
1659
|
+
__publicField(this, "_");
|
|
1660
|
+
__publicField(this, "meta");
|
|
1661
|
+
this._ = _.map((instance) => {
|
|
1662
|
+
if (instance instanceof ConceptValueCacheEntry) {
|
|
1663
|
+
return instance;
|
|
1664
|
+
} else if (instance) {
|
|
1665
|
+
return new ConceptValueCacheEntry(instance);
|
|
1666
|
+
}
|
|
1667
|
+
return null;
|
|
1668
|
+
}).filter((cvce) => cvce !== null);
|
|
1669
|
+
this.meta = meta || {};
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
class ConceptValueCacheEntry {
|
|
1673
|
+
constructor({ meta, id, value, conceptId }) {
|
|
1674
|
+
__publicField(this, "datatype", "concept");
|
|
1675
|
+
__publicField(this, "id");
|
|
1676
|
+
__publicField(this, "value");
|
|
1677
|
+
__publicField(this, "conceptId");
|
|
1678
|
+
__publicField(this, "meta");
|
|
1679
|
+
this.id = id;
|
|
1680
|
+
this.value = value;
|
|
1681
|
+
this.conceptId = conceptId;
|
|
1682
|
+
this.meta = meta || {};
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
class ResourceInstanceListCacheEntry {
|
|
1686
|
+
constructor({ meta, _ }) {
|
|
1687
|
+
__publicField(this, "datatype", "resource-instance-list");
|
|
1688
|
+
__publicField(this, "_");
|
|
1689
|
+
__publicField(this, "meta");
|
|
1690
|
+
this._ = _.map((instance) => {
|
|
1691
|
+
if (instance instanceof ResourceInstanceCacheEntry) {
|
|
1692
|
+
return instance;
|
|
1693
|
+
}
|
|
1694
|
+
return new ResourceInstanceCacheEntry(instance);
|
|
1695
|
+
});
|
|
1696
|
+
this.meta = meta || {};
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
class ResourceInstanceCacheEntry {
|
|
1700
|
+
constructor({ meta, id, type, graphId, title }) {
|
|
1701
|
+
__publicField(this, "datatype", "resource-instance");
|
|
1702
|
+
__publicField(this, "id");
|
|
1703
|
+
__publicField(this, "type");
|
|
1704
|
+
__publicField(this, "graphId");
|
|
1705
|
+
__publicField(this, "title");
|
|
1706
|
+
__publicField(this, "meta");
|
|
1707
|
+
this.id = id;
|
|
1708
|
+
this.type = type;
|
|
1709
|
+
this.graphId = graphId;
|
|
1710
|
+
this.meta = meta || {};
|
|
1711
|
+
this.title = this.meta.title || title;
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
class ResourceInstanceListViewModel extends Array {
|
|
1715
|
+
constructor() {
|
|
1716
|
+
super(...arguments);
|
|
1717
|
+
__publicField(this, "_");
|
|
1718
|
+
__publicField(this, "__parentPseudo");
|
|
1719
|
+
__publicField(this, "describeField", () => this.__parentPseudo ? this.__parentPseudo.describeField() : null);
|
|
1720
|
+
__publicField(this, "describeFieldGroup", () => this.__parentPseudo ? this.__parentPseudo.describeFieldGroup() : null);
|
|
1721
|
+
__publicField(this, "_value", null);
|
|
1722
|
+
}
|
|
1723
|
+
async forJson() {
|
|
1724
|
+
const value = await this._value;
|
|
1725
|
+
return value ? value.map((v) => v ? v.forJson() : null) : null;
|
|
1726
|
+
}
|
|
1727
|
+
async __forJsonCache(getMeta) {
|
|
1728
|
+
return new ResourceInstanceListCacheEntry({
|
|
1729
|
+
meta: getMeta ? await getMeta(this) : getMeta,
|
|
1730
|
+
_: await Promise.all([...this.values()].map(async (rivmPromise) => {
|
|
1731
|
+
const rivm = await rivmPromise;
|
|
1732
|
+
return await rivm.__forJsonCache(getMeta);
|
|
1733
|
+
}))
|
|
1734
|
+
});
|
|
1735
|
+
}
|
|
1736
|
+
static async __create(tile, node, value, cacheEntry = null) {
|
|
1737
|
+
const nodeid = node.nodeid;
|
|
1738
|
+
let val;
|
|
1739
|
+
if (tile) {
|
|
1740
|
+
if (!tile.data.has(nodeid)) {
|
|
1741
|
+
tile.data.set(nodeid, null);
|
|
1742
|
+
}
|
|
1743
|
+
if (value !== null) {
|
|
1744
|
+
tile.data.set(nodeid, []);
|
|
1745
|
+
if (!Array.isArray(value)) {
|
|
1746
|
+
throw Error(
|
|
1747
|
+
`Cannot set an (entire) resource list value on node ${nodeid} except via an array: ${JSON.stringify(value)}`
|
|
1748
|
+
);
|
|
1749
|
+
}
|
|
1750
|
+
val = value.map((v, i) => {
|
|
1751
|
+
if (v instanceof ResourceInstanceViewModel) {
|
|
1752
|
+
return v;
|
|
1753
|
+
}
|
|
1754
|
+
return ResourceInstanceViewModel.__create(tile, node, v, cacheEntry && cacheEntry._[i] ? cacheEntry._[i] : null);
|
|
1755
|
+
});
|
|
1756
|
+
Promise.all(
|
|
1757
|
+
val.map(async (c) => {
|
|
1758
|
+
const v = await c;
|
|
1759
|
+
return v ? (await v).id : null;
|
|
1760
|
+
})
|
|
1761
|
+
).then((ids) => {
|
|
1762
|
+
tile.data.set(nodeid, ids.map((id) => {
|
|
1763
|
+
return {
|
|
1764
|
+
resourceId: id
|
|
1765
|
+
};
|
|
1766
|
+
}));
|
|
1767
|
+
return ids;
|
|
1768
|
+
});
|
|
1769
|
+
value = val;
|
|
1770
|
+
}
|
|
1771
|
+
} else {
|
|
1772
|
+
value = [];
|
|
1773
|
+
}
|
|
1774
|
+
if (!tile || !value) {
|
|
1775
|
+
return null;
|
|
1776
|
+
}
|
|
1777
|
+
const str = new ResourceInstanceListViewModel(...value);
|
|
1778
|
+
return str;
|
|
1779
|
+
}
|
|
1780
|
+
async __asTileData() {
|
|
1781
|
+
return this._value ? await this._value : null;
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
_c = Symbol.toPrimitive;
|
|
1785
|
+
const _ResourceInstanceViewModel = class _ResourceInstanceViewModel {
|
|
1786
|
+
constructor(id, modelWrapper, instanceWrapperFactory, cacheEntry) {
|
|
1787
|
+
__publicField(this, "_");
|
|
1788
|
+
__publicField(this, "$");
|
|
1789
|
+
__publicField(this, "__");
|
|
1790
|
+
__publicField(this, "__parentPseudo");
|
|
1791
|
+
__publicField(this, "__cacheEntry", null);
|
|
1792
|
+
__publicField(this, "id");
|
|
1793
|
+
__publicField(this, "then");
|
|
1794
|
+
__publicField(this, _c);
|
|
1795
|
+
__publicField(this, "gm");
|
|
1796
|
+
this.id = id;
|
|
1797
|
+
this.$ = instanceWrapperFactory ? instanceWrapperFactory(this) : null;
|
|
1798
|
+
this.__ = modelWrapper;
|
|
1799
|
+
if (cacheEntry instanceof ResourceInstanceCacheEntry) {
|
|
1800
|
+
this.__cacheEntry = cacheEntry;
|
|
1801
|
+
}
|
|
1802
|
+
return new Proxy(this, {
|
|
1803
|
+
// NOTE: set should not return a promise, so could cause a race
|
|
1804
|
+
// condition with a subsequent read.
|
|
1805
|
+
// @ts-expect-error Returning a promise for set
|
|
1806
|
+
set: async (object, key, value) => {
|
|
1807
|
+
const k = typeof key === "symbol" ? key.description || "" : key;
|
|
1808
|
+
if (key in object) {
|
|
1809
|
+
object[key] = value;
|
|
1810
|
+
} else if (k in object || k.startsWith("__")) {
|
|
1811
|
+
object[k] = value;
|
|
1812
|
+
} else {
|
|
1813
|
+
if (!object.$) {
|
|
1814
|
+
await this.retrieve();
|
|
1815
|
+
if (!object.$) {
|
|
1816
|
+
throw Error("Could not retrieve resource");
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
object.$.setOrmAttribute(k, value);
|
|
1820
|
+
}
|
|
1821
|
+
return true;
|
|
1822
|
+
},
|
|
1823
|
+
get: (object, key) => {
|
|
1824
|
+
const k = typeof key === "symbol" ? key.description || "" : key;
|
|
1825
|
+
if (key in object) {
|
|
1826
|
+
return object[key];
|
|
1827
|
+
} else if (k in object || k.startsWith("__")) {
|
|
1828
|
+
return object[k];
|
|
1829
|
+
}
|
|
1830
|
+
return new AttrPromise(async (resolve) => {
|
|
1831
|
+
if (!object.$) {
|
|
1832
|
+
await this.retrieve();
|
|
1833
|
+
if (!object.$) {
|
|
1834
|
+
throw Error("Could not retrieve resource");
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
return object.$.getOrmAttribute(k).then((v) => {
|
|
1838
|
+
return resolve(v);
|
|
1839
|
+
});
|
|
1840
|
+
});
|
|
1841
|
+
}
|
|
1842
|
+
});
|
|
1843
|
+
}
|
|
1844
|
+
toString() {
|
|
1845
|
+
if (!this.__) {
|
|
1846
|
+
return `[Resource:${this.id}]`;
|
|
1847
|
+
}
|
|
1848
|
+
return `[${this.__.wkrm.modelClassName}:${this.id ?? "-"}]`;
|
|
1849
|
+
}
|
|
1850
|
+
async __has(key) {
|
|
1851
|
+
if (!this.$) {
|
|
1852
|
+
return void 0;
|
|
1853
|
+
}
|
|
1854
|
+
return (await this.$.getRootViewModel() || /* @__PURE__ */ new Map()).__has(key);
|
|
1855
|
+
}
|
|
1856
|
+
async __asTileData() {
|
|
1857
|
+
return {
|
|
1858
|
+
resourceId: this.id
|
|
1859
|
+
};
|
|
1860
|
+
}
|
|
1861
|
+
async __forJsonCache(getMeta) {
|
|
1862
|
+
let wrapper;
|
|
1863
|
+
if (!this.__) {
|
|
1864
|
+
if (this.__cacheEntry) {
|
|
1865
|
+
return this.__cacheEntry;
|
|
1866
|
+
} else {
|
|
1867
|
+
[, wrapper] = await this.retrieve();
|
|
1868
|
+
}
|
|
1869
|
+
} else {
|
|
1870
|
+
wrapper = this.__;
|
|
1871
|
+
}
|
|
1872
|
+
this.__cacheEntry = new ResourceInstanceCacheEntry({
|
|
1873
|
+
meta: getMeta ? await getMeta(this) : void 0,
|
|
1874
|
+
id: this.id,
|
|
1875
|
+
type: wrapper.wkrm.modelClassName,
|
|
1876
|
+
graphId: wrapper.wkrm.graphId,
|
|
1877
|
+
title: null
|
|
1878
|
+
});
|
|
1879
|
+
return this.__cacheEntry;
|
|
1880
|
+
}
|
|
1881
|
+
async forJson(cascade = false) {
|
|
1882
|
+
let jsonData;
|
|
1883
|
+
if (!cascade && this.__cacheEntry) {
|
|
1884
|
+
jsonData = {
|
|
1885
|
+
type: this.__cacheEntry.type,
|
|
1886
|
+
graphId: this.__cacheEntry.graphId,
|
|
1887
|
+
id: this.__cacheEntry.id,
|
|
1888
|
+
title: this.__cacheEntry.title || void 0,
|
|
1889
|
+
meta: this.__cacheEntry.meta || void 0,
|
|
1890
|
+
root: null
|
|
1891
|
+
};
|
|
1892
|
+
} else if (this.__) {
|
|
1893
|
+
jsonData = {
|
|
1894
|
+
type: this.__.wkrm.modelClassName,
|
|
1895
|
+
graphId: this.__.wkrm.graphId,
|
|
1896
|
+
id: this.id,
|
|
1897
|
+
title: void 0,
|
|
1898
|
+
meta: void 0,
|
|
1899
|
+
root: null
|
|
1900
|
+
};
|
|
1901
|
+
} else {
|
|
1902
|
+
jsonData = {
|
|
1903
|
+
type: "(unknown)",
|
|
1904
|
+
graphId: "",
|
|
1905
|
+
id: this.id,
|
|
1906
|
+
title: void 0,
|
|
1907
|
+
meta: void 0,
|
|
1908
|
+
root: null
|
|
1909
|
+
};
|
|
1910
|
+
}
|
|
1911
|
+
const basic = new StaticResourceReference(jsonData);
|
|
1912
|
+
if (cascade) {
|
|
1913
|
+
if (!this.$) {
|
|
1914
|
+
await this.retrieve();
|
|
1915
|
+
if (!this.$) {
|
|
1916
|
+
throw Error("Could not retrieve resource");
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
const root = await this.$.getRootViewModel();
|
|
1920
|
+
basic.root = await root.forJson();
|
|
1921
|
+
}
|
|
1922
|
+
return basic;
|
|
1923
|
+
}
|
|
1924
|
+
async retrieve() {
|
|
1925
|
+
let iw;
|
|
1926
|
+
let mw;
|
|
1927
|
+
if (viewContext.graphManager) {
|
|
1928
|
+
const replacement = await viewContext.graphManager.getResource(this.id, true);
|
|
1929
|
+
iw = replacement.$;
|
|
1930
|
+
mw = replacement.__;
|
|
1931
|
+
} else {
|
|
1932
|
+
throw Error("Cannot traverse resource relationships without a GraphManager");
|
|
1933
|
+
}
|
|
1934
|
+
this.$ = iw;
|
|
1935
|
+
this.__ = mw;
|
|
1936
|
+
return [iw, mw];
|
|
1937
|
+
}
|
|
1938
|
+
static async __create(tile, node, value, cacheEntry) {
|
|
1939
|
+
const nodeid = node.nodeid;
|
|
1940
|
+
let val = value;
|
|
1941
|
+
if (tile) {
|
|
1942
|
+
if (!tile.data.has(nodeid)) {
|
|
1943
|
+
tile.data.set(nodeid, null);
|
|
1944
|
+
}
|
|
1945
|
+
if (value !== null) {
|
|
1946
|
+
if (!value && !(value instanceof StaticResource) && !(value instanceof StaticResourceReference)) {
|
|
1947
|
+
val = null;
|
|
1948
|
+
} else if (value instanceof Promise) {
|
|
1949
|
+
return value.then((value2) => {
|
|
1950
|
+
return _ResourceInstanceViewModel.__create(tile, node, value2, cacheEntry);
|
|
1951
|
+
});
|
|
1952
|
+
} else if (typeof value == "string") {
|
|
1953
|
+
if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.exec(
|
|
1954
|
+
value
|
|
1955
|
+
)) {
|
|
1956
|
+
val = value;
|
|
1957
|
+
} else {
|
|
1958
|
+
throw Error(
|
|
1959
|
+
`Set resource instances using id, not strings in node ${node.alias}: ${value}`
|
|
1960
|
+
);
|
|
1961
|
+
}
|
|
1962
|
+
} else if (value instanceof Object && value.resourceId) {
|
|
1963
|
+
val = value.resourceId;
|
|
1964
|
+
} else if (value instanceof Array && value.length < 2) {
|
|
1965
|
+
if (value.length == 1) {
|
|
1966
|
+
return _ResourceInstanceViewModel.__create(tile, node, value[0], cacheEntry);
|
|
1967
|
+
}
|
|
1968
|
+
} else {
|
|
1969
|
+
throw Error("Could not set resource instance from this data");
|
|
1970
|
+
}
|
|
1971
|
+
tile.data.set(nodeid, val ? [{ resourceId: val }] : null);
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
if (!tile || !val) {
|
|
1975
|
+
return null;
|
|
1976
|
+
}
|
|
1977
|
+
const str = new _ResourceInstanceViewModel(val, null, null, cacheEntry);
|
|
1978
|
+
return str;
|
|
1979
|
+
}
|
|
1980
|
+
};
|
|
1981
|
+
let ResourceInstanceViewModel = _ResourceInstanceViewModel;
|
|
1982
|
+
class FileListViewModel extends Array {
|
|
1983
|
+
constructor() {
|
|
1984
|
+
super(...arguments);
|
|
1985
|
+
__publicField(this, "_");
|
|
1986
|
+
__publicField(this, "__parentPseudo");
|
|
1987
|
+
__publicField(this, "describeField", () => this.__parentPseudo ? this.__parentPseudo.describeField() : null);
|
|
1988
|
+
__publicField(this, "describeFieldGroup", () => this.__parentPseudo ? this.__parentPseudo.describeFieldGroup() : null);
|
|
1989
|
+
__publicField(this, "_value", null);
|
|
1990
|
+
}
|
|
1991
|
+
async forJson() {
|
|
1992
|
+
const value = await this._value;
|
|
1993
|
+
return value ? value.map((v) => v ? v.forJson() : null) : null;
|
|
1994
|
+
}
|
|
1995
|
+
async __forJsonCache() {
|
|
1996
|
+
return null;
|
|
1997
|
+
}
|
|
1998
|
+
static async __create(tile, node, value) {
|
|
1999
|
+
const nodeid = node.nodeid;
|
|
2000
|
+
let val = [];
|
|
2001
|
+
if (!tile.data.has(nodeid)) {
|
|
2002
|
+
tile.data.set(nodeid, null);
|
|
2003
|
+
}
|
|
2004
|
+
if (value !== null) {
|
|
2005
|
+
tile.data.set(nodeid, []);
|
|
2006
|
+
if (!Array.isArray(value)) {
|
|
2007
|
+
throw Error(
|
|
2008
|
+
`Cannot set an (entire) file list value on node ${nodeid} except via an array: ${JSON.stringify(value)}`
|
|
2009
|
+
);
|
|
2010
|
+
}
|
|
2011
|
+
val = value.map((c) => {
|
|
2012
|
+
return c;
|
|
2013
|
+
});
|
|
2014
|
+
Promise.all(val).then((vals) => {
|
|
2015
|
+
Promise.all(
|
|
2016
|
+
vals.map(async (c) => {
|
|
2017
|
+
const v = await c;
|
|
2018
|
+
return v ? (await v.getValue()).id : null;
|
|
2019
|
+
})
|
|
2020
|
+
).then((ids) => {
|
|
2021
|
+
tile.data.set(nodeid, ids);
|
|
2022
|
+
});
|
|
2023
|
+
});
|
|
2024
|
+
value = val;
|
|
2025
|
+
} else {
|
|
2026
|
+
value = [];
|
|
2027
|
+
}
|
|
2028
|
+
const str = new FileListViewModel(...value);
|
|
2029
|
+
return str;
|
|
2030
|
+
}
|
|
2031
|
+
async __asTileData() {
|
|
2032
|
+
return this._value ? await this._value : null;
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
class ConceptListViewModel extends Array {
|
|
2036
|
+
constructor() {
|
|
2037
|
+
super(...arguments);
|
|
2038
|
+
__publicField(this, "_");
|
|
2039
|
+
__publicField(this, "__parentPseudo");
|
|
2040
|
+
__publicField(this, "describeField", () => this.__parentPseudo ? this.__parentPseudo.describeField() : null);
|
|
2041
|
+
__publicField(this, "describeFieldGroup", () => this.__parentPseudo ? this.__parentPseudo.describeFieldGroup() : null);
|
|
2042
|
+
__publicField(this, "_value", null);
|
|
2043
|
+
}
|
|
2044
|
+
async forJson() {
|
|
2045
|
+
const value = await this._value;
|
|
2046
|
+
return value ? value.map((v) => v ? v.forJson() : null) : null;
|
|
2047
|
+
}
|
|
2048
|
+
async __forJsonCache(getMeta) {
|
|
2049
|
+
return new ConceptListCacheEntry({
|
|
2050
|
+
meta: getMeta ? await getMeta(this) : getMeta,
|
|
2051
|
+
_: (await Promise.all([...this.values()].map(async (rivmPromise) => {
|
|
2052
|
+
const rivm = await rivmPromise;
|
|
2053
|
+
if (rivm) {
|
|
2054
|
+
return await rivm.__forJsonCache(getMeta);
|
|
2055
|
+
}
|
|
2056
|
+
}))).filter((val) => val !== void 0)
|
|
2057
|
+
});
|
|
2058
|
+
}
|
|
2059
|
+
static async __create(tile, node, value, cacheEntry = null) {
|
|
2060
|
+
const nodeid = node.nodeid;
|
|
2061
|
+
let val = [];
|
|
2062
|
+
if (!tile.data.has(nodeid)) {
|
|
2063
|
+
tile.data.set(nodeid, null);
|
|
2064
|
+
}
|
|
2065
|
+
if (value !== null) {
|
|
2066
|
+
tile.data.set(nodeid, []);
|
|
2067
|
+
if (!Array.isArray(value)) {
|
|
2068
|
+
throw Error(
|
|
2069
|
+
`Cannot set an (entire) concept list value on node ${nodeid} except via an array: ${JSON.stringify(value)}`
|
|
2070
|
+
);
|
|
2071
|
+
}
|
|
2072
|
+
val = value.map((c, i) => {
|
|
2073
|
+
if (c instanceof ConceptValueViewModel) {
|
|
2074
|
+
return c;
|
|
2075
|
+
}
|
|
2076
|
+
return ConceptValueViewModel.__create(tile, node, c, cacheEntry && cacheEntry._[i] ? cacheEntry._[i] : null);
|
|
2077
|
+
});
|
|
2078
|
+
Promise.all(val).then((vals) => {
|
|
2079
|
+
Promise.all(
|
|
2080
|
+
vals.map(async (c) => {
|
|
2081
|
+
const v = await c;
|
|
2082
|
+
return v ? (await v.getValue()).id : null;
|
|
2083
|
+
})
|
|
2084
|
+
).then((ids) => {
|
|
2085
|
+
tile.data.set(nodeid, ids);
|
|
2086
|
+
});
|
|
2087
|
+
});
|
|
2088
|
+
value = val;
|
|
2089
|
+
} else {
|
|
2090
|
+
value = [];
|
|
2091
|
+
}
|
|
2092
|
+
const str = new ConceptListViewModel(...value);
|
|
2093
|
+
return str;
|
|
2094
|
+
}
|
|
2095
|
+
async __asTileData() {
|
|
2096
|
+
return this._value ? await this._value : null;
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
class DomainValueListViewModel extends Array {
|
|
2100
|
+
constructor() {
|
|
2101
|
+
super(...arguments);
|
|
2102
|
+
__publicField(this, "_");
|
|
2103
|
+
__publicField(this, "__parentPseudo");
|
|
2104
|
+
__publicField(this, "describeField", () => this.__parentPseudo ? this.__parentPseudo.describeField() : null);
|
|
2105
|
+
__publicField(this, "describeFieldGroup", () => this.__parentPseudo ? this.__parentPseudo.describeFieldGroup() : null);
|
|
2106
|
+
__publicField(this, "_value", null);
|
|
2107
|
+
}
|
|
2108
|
+
async forJson() {
|
|
2109
|
+
const value = await this._value;
|
|
2110
|
+
return value ? value.map((v) => v ? v.forJson() : null) : null;
|
|
2111
|
+
}
|
|
2112
|
+
// No point in caching something that is on the graph.
|
|
2113
|
+
__forJsonCache() {
|
|
2114
|
+
return null;
|
|
2115
|
+
}
|
|
2116
|
+
static async __create(tile, node, value) {
|
|
2117
|
+
const nodeid = node.nodeid;
|
|
2118
|
+
let val;
|
|
2119
|
+
if (tile) {
|
|
2120
|
+
if (!tile.data.has(nodeid)) {
|
|
2121
|
+
tile.data.set(nodeid, null);
|
|
2122
|
+
}
|
|
2123
|
+
if (value !== null) {
|
|
2124
|
+
tile.data.set(nodeid, []);
|
|
2125
|
+
if (!Array.isArray(value)) {
|
|
2126
|
+
throw Error(
|
|
2127
|
+
`Cannot set an (entire) domain list value on node ${nodeid} except via an array: ${JSON.stringify(value)}`
|
|
2128
|
+
);
|
|
2129
|
+
}
|
|
2130
|
+
val = value.map((c) => {
|
|
2131
|
+
if (c instanceof DomainValueViewModel) {
|
|
2132
|
+
return c;
|
|
2133
|
+
}
|
|
2134
|
+
return DomainValueViewModel.__create(tile, node, c);
|
|
2135
|
+
});
|
|
2136
|
+
Promise.all(val).then(async (vals) => {
|
|
2137
|
+
const ids = Promise.all(vals.map(async (val2) => val2 === null ? val2 : (await val2._value).id));
|
|
2138
|
+
ids.then((ids2) => {
|
|
2139
|
+
tile.data.set(nodeid, ids2);
|
|
2140
|
+
});
|
|
2141
|
+
});
|
|
2142
|
+
}
|
|
2143
|
+
} else {
|
|
2144
|
+
value = [];
|
|
2145
|
+
}
|
|
2146
|
+
const str = new DomainValueListViewModel(...value);
|
|
2147
|
+
return str;
|
|
2148
|
+
}
|
|
2149
|
+
async __asTileData() {
|
|
2150
|
+
const value = await this._value;
|
|
2151
|
+
return value ?? null;
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
class DomainValueViewModel extends String {
|
|
2155
|
+
constructor(value) {
|
|
2156
|
+
super(value.toString());
|
|
2157
|
+
__publicField(this, "_");
|
|
2158
|
+
__publicField(this, "__parentPseudo");
|
|
2159
|
+
__publicField(this, "describeField", () => this.__parentPseudo ? this.__parentPseudo.describeField() : null);
|
|
2160
|
+
__publicField(this, "describeFieldGroup", () => this.__parentPseudo ? this.__parentPseudo.describeFieldGroup() : null);
|
|
2161
|
+
__publicField(this, "_value");
|
|
2162
|
+
this._value = value;
|
|
2163
|
+
}
|
|
2164
|
+
async forJson() {
|
|
2165
|
+
return this._value;
|
|
2166
|
+
}
|
|
2167
|
+
// No point in caching something that is on the graph.
|
|
2168
|
+
__forJsonCache() {
|
|
2169
|
+
return null;
|
|
2170
|
+
}
|
|
2171
|
+
getValue() {
|
|
2172
|
+
return this._value;
|
|
2173
|
+
}
|
|
2174
|
+
async lang(lang) {
|
|
2175
|
+
return (await this._value).lang(lang);
|
|
2176
|
+
}
|
|
2177
|
+
static async __create(tile, node, value) {
|
|
2178
|
+
const nodeid = node.nodeid;
|
|
2179
|
+
let val = value;
|
|
2180
|
+
if (tile) {
|
|
2181
|
+
if (!tile.data.has(nodeid)) {
|
|
2182
|
+
tile.data.set(nodeid, null);
|
|
2183
|
+
}
|
|
2184
|
+
if (value !== null) {
|
|
2185
|
+
if (!value && !(value instanceof StaticDomainValue)) {
|
|
2186
|
+
val = null;
|
|
2187
|
+
} else if (value instanceof Promise) {
|
|
2188
|
+
return value.then((value2) => {
|
|
2189
|
+
return DomainValueViewModel.__create(tile, node, value2);
|
|
2190
|
+
});
|
|
2191
|
+
} else if (typeof value == "string") {
|
|
2192
|
+
if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i.exec(
|
|
2193
|
+
value
|
|
2194
|
+
)) {
|
|
2195
|
+
const config = nodeConfigManager.retrieve(node);
|
|
2196
|
+
if (!config || !(config instanceof StaticNodeConfigDomain)) {
|
|
2197
|
+
throw Error(`Cannot form domain value for ${node.nodeid} without config`);
|
|
2198
|
+
}
|
|
2199
|
+
val = config.valueFromId(value) || null;
|
|
2200
|
+
} else {
|
|
2201
|
+
throw Error(
|
|
2202
|
+
"Set domain values using values from domain lists, not strings"
|
|
2203
|
+
);
|
|
2204
|
+
}
|
|
2205
|
+
} else {
|
|
2206
|
+
throw Error("Could not set domain value from this data");
|
|
2207
|
+
}
|
|
2208
|
+
if (!(val instanceof Promise)) {
|
|
2209
|
+
tile.data.set(nodeid, val ? val.id : null);
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
if (!tile || !val) {
|
|
2214
|
+
return null;
|
|
2215
|
+
}
|
|
2216
|
+
const str = new DomainValueViewModel(val);
|
|
2217
|
+
return str;
|
|
2218
|
+
}
|
|
2219
|
+
async __asTileData() {
|
|
2220
|
+
const value = await this._value;
|
|
2221
|
+
return value ? value.id : null;
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
class ConceptValueViewModel extends String {
|
|
2225
|
+
constructor(value) {
|
|
2226
|
+
super(value.value);
|
|
2227
|
+
__publicField(this, "_");
|
|
2228
|
+
__publicField(this, "__parentPseudo");
|
|
2229
|
+
__publicField(this, "describeField", () => this.__parentPseudo ? this.__parentPseudo.describeField() : null);
|
|
2230
|
+
__publicField(this, "describeFieldGroup", () => this.__parentPseudo ? this.__parentPseudo.describeFieldGroup() : null);
|
|
2231
|
+
__publicField(this, "_value");
|
|
2232
|
+
this._value = value;
|
|
2233
|
+
}
|
|
2234
|
+
async forJson() {
|
|
2235
|
+
return this._value;
|
|
2236
|
+
}
|
|
2237
|
+
async __forJsonCache(getMeta) {
|
|
2238
|
+
const value = await this._value;
|
|
2239
|
+
return new ConceptValueCacheEntry({
|
|
2240
|
+
meta: getMeta ? await getMeta(this) : void 0,
|
|
2241
|
+
id: value.id,
|
|
2242
|
+
value: value.value,
|
|
2243
|
+
conceptId: value.__conceptId
|
|
2244
|
+
});
|
|
2245
|
+
}
|
|
2246
|
+
getValue() {
|
|
2247
|
+
return this._value;
|
|
2248
|
+
}
|
|
2249
|
+
static async __create(tile, node, value, cacheEntry) {
|
|
2250
|
+
var _a2;
|
|
2251
|
+
const nodeid = node.nodeid;
|
|
2252
|
+
const collectionId = (_a2 = node.config) == null ? void 0 : _a2.rdmCollection;
|
|
2253
|
+
if (!collectionId) {
|
|
2254
|
+
throw Error(`Node ${node.alias} (${node.nodeid}) missing rdmCollection in config`);
|
|
2255
|
+
}
|
|
2256
|
+
let val = value;
|
|
2257
|
+
if (tile) {
|
|
2258
|
+
if (!tile.data.has(nodeid)) {
|
|
2259
|
+
tile.data.set(nodeid, null);
|
|
2260
|
+
}
|
|
2261
|
+
if (value !== null) {
|
|
2262
|
+
if (value instanceof StaticConcept) {
|
|
2263
|
+
if (value.getPrefLabel) {
|
|
2264
|
+
val = value.getPrefLabel();
|
|
2265
|
+
} else {
|
|
2266
|
+
throw Error("Recognizing value as StaticConcept, but no getPrefLabel member");
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
if (!value) {
|
|
2270
|
+
val = null;
|
|
2271
|
+
} else if (value instanceof StaticValue) ;
|
|
2272
|
+
else if (value instanceof Promise) {
|
|
2273
|
+
return value.then((value2) => {
|
|
2274
|
+
return ConceptValueViewModel.__create(tile, node, value2, cacheEntry);
|
|
2275
|
+
});
|
|
2276
|
+
} else if (typeof value == "string") {
|
|
2277
|
+
if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.exec(
|
|
2278
|
+
value
|
|
2279
|
+
)) {
|
|
2280
|
+
if (cacheEntry) {
|
|
2281
|
+
val = new StaticValue({
|
|
2282
|
+
id: cacheEntry.id,
|
|
2283
|
+
value: cacheEntry.value,
|
|
2284
|
+
__concept: null,
|
|
2285
|
+
__conceptId: cacheEntry.conceptId
|
|
2286
|
+
}, cacheEntry.conceptId);
|
|
2287
|
+
return new ConceptValueViewModel(val);
|
|
2288
|
+
} else {
|
|
2289
|
+
const collection = RDM.retrieveCollection(collectionId);
|
|
2290
|
+
return collection.then((collection2) => {
|
|
2291
|
+
if (!collection2.getConceptValue) {
|
|
2292
|
+
throw Error(`Collection ${collection2.id} must be a StaticCollection here, not a key/value object`);
|
|
2293
|
+
}
|
|
2294
|
+
const val2 = collection2.getConceptValue(value);
|
|
2295
|
+
if (!val2) {
|
|
2296
|
+
console.error("Could not find concept for value", value, "for", node.alias, "in collection", collectionId);
|
|
2297
|
+
}
|
|
2298
|
+
tile.data.set(nodeid, val2 ? val2.id : null);
|
|
2299
|
+
if (!tile || !val2) {
|
|
2300
|
+
return null;
|
|
2301
|
+
}
|
|
2302
|
+
const str2 = new ConceptValueViewModel(val2);
|
|
2303
|
+
return str2;
|
|
2304
|
+
});
|
|
2305
|
+
}
|
|
2306
|
+
} else {
|
|
2307
|
+
throw Error(
|
|
2308
|
+
`Set concepts using values from collections, not strings: ${value}`
|
|
2309
|
+
);
|
|
2310
|
+
}
|
|
2311
|
+
} else {
|
|
2312
|
+
throw Error("Could not set concept from this data");
|
|
2313
|
+
}
|
|
2314
|
+
if (!(val instanceof Promise)) {
|
|
2315
|
+
if (!val) {
|
|
2316
|
+
console.error("Could not find concept for value", value, "for", node.alias, "in collection", collectionId);
|
|
2317
|
+
}
|
|
2318
|
+
tile.data.set(nodeid, val ? val.id : null);
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
if (!tile || !val) {
|
|
2323
|
+
return null;
|
|
2324
|
+
}
|
|
2325
|
+
const str = new ConceptValueViewModel(val);
|
|
2326
|
+
return str;
|
|
2327
|
+
}
|
|
2328
|
+
async __asTileData() {
|
|
2329
|
+
const value = await this._value;
|
|
2330
|
+
return value ? value.id : null;
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
class DateViewModel extends Date {
|
|
2334
|
+
constructor(val) {
|
|
2335
|
+
super(val);
|
|
2336
|
+
__publicField(this, "_");
|
|
2337
|
+
__publicField(this, "__parentPseudo");
|
|
2338
|
+
__publicField(this, "__original");
|
|
2339
|
+
__publicField(this, "then");
|
|
2340
|
+
__publicField(this, "describeField", () => this.__parentPseudo ? this.__parentPseudo.describeField() : null);
|
|
2341
|
+
__publicField(this, "describeFieldGroup", () => this.__parentPseudo ? this.__parentPseudo.describeFieldGroup() : null);
|
|
2342
|
+
this.__original = val;
|
|
2343
|
+
}
|
|
2344
|
+
__forJsonCache() {
|
|
2345
|
+
return null;
|
|
2346
|
+
}
|
|
2347
|
+
static __create(tile, node, value) {
|
|
2348
|
+
const nodeid = node.nodeid;
|
|
2349
|
+
if (value instanceof Promise) {
|
|
2350
|
+
return value.then(
|
|
2351
|
+
(value2) => DateViewModel.__create(tile, node, value2)
|
|
2352
|
+
);
|
|
2353
|
+
}
|
|
2354
|
+
if (tile) {
|
|
2355
|
+
if (!tile.data.has(nodeid)) {
|
|
2356
|
+
tile.data.set(nodeid, null);
|
|
2357
|
+
}
|
|
2358
|
+
if (value !== null) {
|
|
2359
|
+
tile.data.set(nodeid, value);
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
let val = tile.data.get(nodeid);
|
|
2363
|
+
if (typeof val == "object" && val["en"] !== void 0) {
|
|
2364
|
+
val = val.en;
|
|
2365
|
+
}
|
|
2366
|
+
if (!tile || val === null || val === void 0 || val === "") {
|
|
2367
|
+
return null;
|
|
2368
|
+
}
|
|
2369
|
+
if (typeof val != "string") {
|
|
2370
|
+
throw Error("Date should be a string");
|
|
2371
|
+
}
|
|
2372
|
+
const str = new DateViewModel(val);
|
|
2373
|
+
return str;
|
|
2374
|
+
}
|
|
2375
|
+
async forJson() {
|
|
2376
|
+
try {
|
|
2377
|
+
return this.toISOString();
|
|
2378
|
+
} catch (e) {
|
|
2379
|
+
console.warn(e);
|
|
2380
|
+
return this.__original;
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
__asTileData() {
|
|
2384
|
+
return this.toISOString();
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
_d = Symbol.toPrimitive;
|
|
2388
|
+
const _GeoJSONViewModel = class _GeoJSONViewModel {
|
|
2389
|
+
constructor(jsonData) {
|
|
2390
|
+
__publicField(this, "_");
|
|
2391
|
+
__publicField(this, "__parentPseudo");
|
|
2392
|
+
__publicField(this, "then");
|
|
2393
|
+
__publicField(this, _d);
|
|
2394
|
+
__publicField(this, "describeField", () => this.__parentPseudo ? this.__parentPseudo.describeField() : null);
|
|
2395
|
+
__publicField(this, "describeFieldGroup", () => this.__parentPseudo ? this.__parentPseudo.describeFieldGroup() : null);
|
|
2396
|
+
__publicField(this, "_value");
|
|
2397
|
+
this._value = jsonData;
|
|
2398
|
+
return new Proxy(this, {
|
|
2399
|
+
get: (object, key) => {
|
|
2400
|
+
const k = typeof key === "symbol" ? key.description || "" : key;
|
|
2401
|
+
if (key in object) {
|
|
2402
|
+
return object[key];
|
|
2403
|
+
} else if (k in object) {
|
|
2404
|
+
return object[k];
|
|
2405
|
+
}
|
|
2406
|
+
return this._value[k];
|
|
2407
|
+
},
|
|
2408
|
+
set: (object, key, value) => {
|
|
2409
|
+
const k = typeof key === "symbol" ? key.description || "" : key;
|
|
2410
|
+
if (key in object) {
|
|
2411
|
+
object[key] = value;
|
|
2412
|
+
} else if (k in object) {
|
|
2413
|
+
object[k] = value;
|
|
2414
|
+
} else {
|
|
2415
|
+
this._value[k] = value;
|
|
2416
|
+
}
|
|
2417
|
+
return true;
|
|
2418
|
+
}
|
|
2419
|
+
});
|
|
2420
|
+
}
|
|
2421
|
+
__forJsonCache() {
|
|
2422
|
+
return null;
|
|
2423
|
+
}
|
|
2424
|
+
static __create(tile, node, value) {
|
|
2425
|
+
const nodeid = node.nodeid;
|
|
2426
|
+
if (value instanceof Promise) {
|
|
2427
|
+
return value.then(
|
|
2428
|
+
(value2) => _GeoJSONViewModel.__create(tile, node, value2)
|
|
2429
|
+
);
|
|
2430
|
+
}
|
|
2431
|
+
if (tile) {
|
|
2432
|
+
if (!tile.data.has(nodeid)) {
|
|
2433
|
+
tile.data.set(nodeid, null);
|
|
2434
|
+
}
|
|
2435
|
+
if (value !== null) {
|
|
2436
|
+
tile.data.set(nodeid, value);
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
const val = tile.data.get(nodeid);
|
|
2440
|
+
if (!tile || val === null || val === void 0) {
|
|
2441
|
+
return null;
|
|
2442
|
+
}
|
|
2443
|
+
if (!(val instanceof Object)) {
|
|
2444
|
+
throw Error("GeoJSON should be a JSON object");
|
|
2445
|
+
}
|
|
2446
|
+
const str = new _GeoJSONViewModel(val);
|
|
2447
|
+
return str;
|
|
2448
|
+
}
|
|
2449
|
+
async forJson() {
|
|
2450
|
+
return await this._value;
|
|
2451
|
+
}
|
|
2452
|
+
__asTileData() {
|
|
2453
|
+
return this._value;
|
|
2454
|
+
}
|
|
2455
|
+
};
|
|
2456
|
+
let GeoJSONViewModel = _GeoJSONViewModel;
|
|
2457
|
+
class EDTFViewModel extends String {
|
|
2458
|
+
constructor() {
|
|
2459
|
+
super(...arguments);
|
|
2460
|
+
__publicField(this, "_");
|
|
2461
|
+
__publicField(this, "__parentPseudo");
|
|
2462
|
+
__publicField(this, "describeField", () => this.__parentPseudo ? this.__parentPseudo.describeField() : null);
|
|
2463
|
+
__publicField(this, "describeFieldGroup", () => this.__parentPseudo ? this.__parentPseudo.describeFieldGroup() : null);
|
|
2464
|
+
}
|
|
2465
|
+
__forJsonCache() {
|
|
2466
|
+
return null;
|
|
2467
|
+
}
|
|
2468
|
+
forJson() {
|
|
2469
|
+
return this.toString();
|
|
2470
|
+
}
|
|
2471
|
+
static __create(tile, node, value) {
|
|
2472
|
+
const nodeid = node.nodeid;
|
|
2473
|
+
if (value instanceof Promise) {
|
|
2474
|
+
return value.then((value2) => EDTFViewModel.__create(tile, node, value2));
|
|
2475
|
+
}
|
|
2476
|
+
if (tile) {
|
|
2477
|
+
if (value !== null) {
|
|
2478
|
+
tile.data.set(nodeid, value);
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
const val = tile.data.get(nodeid);
|
|
2482
|
+
if (!tile || val === null || val === void 0) {
|
|
2483
|
+
return null;
|
|
2484
|
+
}
|
|
2485
|
+
const string = new EDTFViewModel(val);
|
|
2486
|
+
return string;
|
|
2487
|
+
}
|
|
2488
|
+
__asTileData() {
|
|
2489
|
+
return `${this}`;
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
class NonLocalizedStringViewModel extends String {
|
|
2493
|
+
constructor() {
|
|
2494
|
+
super(...arguments);
|
|
2495
|
+
__publicField(this, "_");
|
|
2496
|
+
__publicField(this, "__parentPseudo");
|
|
2497
|
+
__publicField(this, "describeField", () => this.__parentPseudo ? this.__parentPseudo.describeField() : null);
|
|
2498
|
+
__publicField(this, "describeFieldGroup", () => this.__parentPseudo ? this.__parentPseudo.describeFieldGroup() : null);
|
|
2499
|
+
}
|
|
2500
|
+
__forJsonCache() {
|
|
2501
|
+
return null;
|
|
2502
|
+
}
|
|
2503
|
+
forJson() {
|
|
2504
|
+
return this.toString();
|
|
2505
|
+
}
|
|
2506
|
+
static __create(tile, node, value) {
|
|
2507
|
+
const nodeid = node.nodeid;
|
|
2508
|
+
if (value instanceof Promise) {
|
|
2509
|
+
return value.then((value2) => NonLocalizedStringViewModel.__create(tile, node, value2));
|
|
2510
|
+
}
|
|
2511
|
+
if (tile) {
|
|
2512
|
+
if (value !== null) {
|
|
2513
|
+
tile.data.set(nodeid, value);
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2516
|
+
const val = tile.data.get(nodeid);
|
|
2517
|
+
if (!tile || val === null || val === void 0) {
|
|
2518
|
+
return null;
|
|
2519
|
+
}
|
|
2520
|
+
const string = new NonLocalizedStringViewModel(val);
|
|
2521
|
+
return string;
|
|
2522
|
+
}
|
|
2523
|
+
__asTileData() {
|
|
2524
|
+
return `${this}`;
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2527
|
+
class NumberViewModel extends Number {
|
|
2528
|
+
constructor() {
|
|
2529
|
+
super(...arguments);
|
|
2530
|
+
__publicField(this, "_");
|
|
2531
|
+
__publicField(this, "__parentPseudo");
|
|
2532
|
+
__publicField(this, "describeField", () => this.__parentPseudo ? this.__parentPseudo.describeField() : null);
|
|
2533
|
+
__publicField(this, "describeFieldGroup", () => this.__parentPseudo ? this.__parentPseudo.describeFieldGroup() : null);
|
|
2534
|
+
}
|
|
2535
|
+
toString() {
|
|
2536
|
+
return `${this.valueOf()}`;
|
|
2537
|
+
}
|
|
2538
|
+
__forJsonCache() {
|
|
2539
|
+
return null;
|
|
2540
|
+
}
|
|
2541
|
+
forJson() {
|
|
2542
|
+
return this.valueOf();
|
|
2543
|
+
}
|
|
2544
|
+
static __create(tile, node, value) {
|
|
2545
|
+
const nodeid = node.nodeid;
|
|
2546
|
+
if (value instanceof Promise) {
|
|
2547
|
+
return value.then((value2) => NumberViewModel.__create(tile, node, value2));
|
|
2548
|
+
}
|
|
2549
|
+
if (tile) {
|
|
2550
|
+
if (value !== null) {
|
|
2551
|
+
tile.data.set(nodeid, value);
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
const val = tile.data.get(nodeid);
|
|
2555
|
+
if (!tile || val === null || val === void 0) {
|
|
2556
|
+
return null;
|
|
2557
|
+
}
|
|
2558
|
+
const num = new NumberViewModel(val);
|
|
2559
|
+
return num;
|
|
2560
|
+
}
|
|
2561
|
+
__asTileData() {
|
|
2562
|
+
return this.valueOf();
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
class BooleanViewModel extends Boolean {
|
|
2566
|
+
constructor(value, config) {
|
|
2567
|
+
super(value);
|
|
2568
|
+
__publicField(this, "_");
|
|
2569
|
+
__publicField(this, "__parentPseudo");
|
|
2570
|
+
__publicField(this, "__config");
|
|
2571
|
+
__publicField(this, "describeField", () => this.__parentPseudo ? this.__parentPseudo.describeField() : null);
|
|
2572
|
+
__publicField(this, "describeFieldGroup", () => this.__parentPseudo ? this.__parentPseudo.describeFieldGroup() : null);
|
|
2573
|
+
this.__config = config;
|
|
2574
|
+
}
|
|
2575
|
+
toString(lang) {
|
|
2576
|
+
const labelLang = lang || DEFAULT_LANGUAGE;
|
|
2577
|
+
return this.valueOf() ? this.__config && this.__config.trueLabel ? this.__config.trueLabel[labelLang] || "true" : "true" : this.__config && this.__config.trueLabel ? this.__config.falseLabel[labelLang] || "false" : "false";
|
|
2578
|
+
}
|
|
2579
|
+
__forJsonCache() {
|
|
2580
|
+
return null;
|
|
2581
|
+
}
|
|
2582
|
+
forJson() {
|
|
2583
|
+
return this.valueOf();
|
|
2584
|
+
}
|
|
2585
|
+
static __create(tile, node, value) {
|
|
2586
|
+
const nodeid = node.nodeid;
|
|
2587
|
+
if (value instanceof Promise) {
|
|
2588
|
+
return value.then((value2) => BooleanViewModel.__create(tile, node, value2));
|
|
2589
|
+
}
|
|
2590
|
+
if (tile) {
|
|
2591
|
+
if (value !== null) {
|
|
2592
|
+
tile.data.set(nodeid, value);
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
const val = tile.data.get(nodeid);
|
|
2596
|
+
if (!tile || val === null || val === void 0) {
|
|
2597
|
+
return null;
|
|
2598
|
+
}
|
|
2599
|
+
const config = nodeConfigManager.retrieve(node);
|
|
2600
|
+
if (!config || !(config instanceof StaticNodeConfigBoolean)) {
|
|
2601
|
+
throw Error(`Cannot form boolean value for ${node.nodeid} without config`);
|
|
2602
|
+
}
|
|
2603
|
+
if (typeof val !== "boolean" && val !== 0 && val !== 1) {
|
|
2604
|
+
throw Error(`Refusing to use truthiness for value ${val} in boolean`);
|
|
2605
|
+
}
|
|
2606
|
+
const bool = new BooleanViewModel(val ? true : false, config);
|
|
2607
|
+
return bool;
|
|
2608
|
+
}
|
|
2609
|
+
__asTileData() {
|
|
2610
|
+
return this.valueOf();
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
class Url {
|
|
2614
|
+
constructor(url, url_label) {
|
|
2615
|
+
__publicField(this, "url");
|
|
2616
|
+
__publicField(this, "url_label");
|
|
2617
|
+
this.url = url;
|
|
2618
|
+
this.url_label = url_label;
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
class UrlViewModel extends String {
|
|
2622
|
+
constructor(value) {
|
|
2623
|
+
const displayValue = value.url_label || value.url;
|
|
2624
|
+
super(displayValue);
|
|
2625
|
+
__publicField(this, "_");
|
|
2626
|
+
__publicField(this, "__parentPseudo");
|
|
2627
|
+
__publicField(this, "describeField", () => this.__parentPseudo ? this.__parentPseudo.describeField() : null);
|
|
2628
|
+
__publicField(this, "describeFieldGroup", () => this.__parentPseudo ? this.__parentPseudo.describeFieldGroup() : null);
|
|
2629
|
+
__publicField(this, "_value");
|
|
2630
|
+
this._value = value;
|
|
2631
|
+
}
|
|
2632
|
+
__forJsonCache() {
|
|
2633
|
+
return null;
|
|
2634
|
+
}
|
|
2635
|
+
forJson() {
|
|
2636
|
+
return {
|
|
2637
|
+
url: this._value.url,
|
|
2638
|
+
url_label: this._value.url_label || ""
|
|
2639
|
+
};
|
|
2640
|
+
}
|
|
2641
|
+
label() {
|
|
2642
|
+
return this._value.url_label || this._value.url;
|
|
2643
|
+
}
|
|
2644
|
+
href() {
|
|
2645
|
+
return this._value.url;
|
|
2646
|
+
}
|
|
2647
|
+
static __create(tile, node, value) {
|
|
2648
|
+
const nodeid = node.nodeid;
|
|
2649
|
+
if (value instanceof Promise) {
|
|
2650
|
+
return value.then((value2) => UrlViewModel.__create(tile, node, value2));
|
|
2651
|
+
}
|
|
2652
|
+
if (tile) {
|
|
2653
|
+
if (!tile.data.has(nodeid)) {
|
|
2654
|
+
tile.data.set(nodeid, {});
|
|
2655
|
+
}
|
|
2656
|
+
if (value !== null) {
|
|
2657
|
+
if (value instanceof UrlViewModel) {
|
|
2658
|
+
value = value._value;
|
|
2659
|
+
} else if (value instanceof Object) {
|
|
2660
|
+
if (!value.url) {
|
|
2661
|
+
throw Error(`A URL must be null or have a 'url' field: ${value}`);
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
tile.data.set(nodeid, {
|
|
2665
|
+
url: value.url,
|
|
2666
|
+
url_label: value.url_label
|
|
2667
|
+
});
|
|
2668
|
+
}
|
|
2669
|
+
}
|
|
2670
|
+
const val = tile.data.get(nodeid);
|
|
2671
|
+
if (!tile || val === null || val === void 0) {
|
|
2672
|
+
return null;
|
|
2673
|
+
}
|
|
2674
|
+
let url;
|
|
2675
|
+
if (typeof val !== "object") {
|
|
2676
|
+
url = new Url(`${val}`);
|
|
2677
|
+
} else if (val instanceof Map) {
|
|
2678
|
+
url = new Url(val.get("url"), val.get("url_label"));
|
|
2679
|
+
} else if ("url" in val && typeof val === "object" && typeof val.url === "string" && "url_label" in val && (val.url_label === void 0 || typeof val.url_label === "string")) {
|
|
2680
|
+
url = new Url(val.url, val.url_label);
|
|
2681
|
+
} else {
|
|
2682
|
+
throw Error(`Unrecognised URL type: ${val}`);
|
|
2683
|
+
}
|
|
2684
|
+
const str = new UrlViewModel(url);
|
|
2685
|
+
return str;
|
|
2686
|
+
}
|
|
2687
|
+
__asTileData() {
|
|
2688
|
+
return this.forJson();
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
class StringViewModel extends String {
|
|
2692
|
+
constructor(value, language = null) {
|
|
2693
|
+
const lang = value.get(language || DEFAULT_LANGUAGE);
|
|
2694
|
+
let displayValue;
|
|
2695
|
+
if (lang) {
|
|
2696
|
+
if (typeof lang == "string") {
|
|
2697
|
+
displayValue = lang;
|
|
2698
|
+
} else {
|
|
2699
|
+
displayValue = lang.value;
|
|
2700
|
+
}
|
|
2701
|
+
} else {
|
|
2702
|
+
displayValue = "";
|
|
2703
|
+
}
|
|
2704
|
+
super(displayValue);
|
|
2705
|
+
__publicField(this, "_");
|
|
2706
|
+
__publicField(this, "__parentPseudo");
|
|
2707
|
+
__publicField(this, "describeField", () => this.__parentPseudo ? this.__parentPseudo.describeField() : null);
|
|
2708
|
+
__publicField(this, "describeFieldGroup", () => this.__parentPseudo ? this.__parentPseudo.describeFieldGroup() : null);
|
|
2709
|
+
__publicField(this, "_value");
|
|
2710
|
+
this._value = value;
|
|
2711
|
+
}
|
|
2712
|
+
__forJsonCache() {
|
|
2713
|
+
return null;
|
|
2714
|
+
}
|
|
2715
|
+
forJson() {
|
|
2716
|
+
return `${this}`;
|
|
2717
|
+
}
|
|
2718
|
+
lang(language) {
|
|
2719
|
+
const elt = this._value.get(language);
|
|
2720
|
+
if (elt) {
|
|
2721
|
+
if (elt instanceof Object) {
|
|
2722
|
+
return elt.value;
|
|
2723
|
+
}
|
|
2724
|
+
return elt;
|
|
2725
|
+
} else {
|
|
2726
|
+
return void 0;
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
static __create(tile, node, value) {
|
|
2730
|
+
const nodeid = node.nodeid;
|
|
2731
|
+
if (value instanceof Promise) {
|
|
2732
|
+
return value.then((value2) => StringViewModel.__create(tile, node, value2));
|
|
2733
|
+
}
|
|
2734
|
+
if (tile) {
|
|
2735
|
+
if (!tile.data.has(nodeid)) {
|
|
2736
|
+
tile.data.set(nodeid, {});
|
|
2737
|
+
}
|
|
2738
|
+
if (value !== null) {
|
|
2739
|
+
if (value instanceof Object) {
|
|
2740
|
+
const entries = value instanceof Map ? value.entries() : Object.entries(value);
|
|
2741
|
+
for (const [k, v] of [...entries]) {
|
|
2742
|
+
const val2 = tile.data.get(nodeid);
|
|
2743
|
+
if (val2 instanceof Map) {
|
|
2744
|
+
val2.set(k, v);
|
|
2745
|
+
} else if (val2 instanceof Object) {
|
|
2746
|
+
val2[k] = v;
|
|
2747
|
+
} else if (val2 !== null) {
|
|
2748
|
+
throw Error("Malformed string in tile data");
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
} else {
|
|
2752
|
+
tile.data.set(nodeid, {
|
|
2753
|
+
[DEFAULT_LANGUAGE]: value
|
|
2754
|
+
});
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2758
|
+
const val = tile.data.get(nodeid);
|
|
2759
|
+
if (!tile || val === null || val === void 0) {
|
|
2760
|
+
return null;
|
|
2761
|
+
}
|
|
2762
|
+
let mapVal;
|
|
2763
|
+
if (val instanceof Map) {
|
|
2764
|
+
mapVal = val;
|
|
2765
|
+
} else {
|
|
2766
|
+
mapVal = new Map(Object.entries(val));
|
|
2767
|
+
}
|
|
2768
|
+
const str = new StringViewModel(mapVal);
|
|
2769
|
+
return str;
|
|
2770
|
+
}
|
|
2771
|
+
__asTileData() {
|
|
2772
|
+
return this._value;
|
|
2773
|
+
}
|
|
2774
|
+
}
|
|
2775
|
+
_e = Symbol.toPrimitive;
|
|
2776
|
+
const _SemanticViewModel = class _SemanticViewModel {
|
|
2777
|
+
constructor(parentWkri, childNodes, tile, node) {
|
|
2778
|
+
__publicField(this, "_");
|
|
2779
|
+
__publicField(this, "then");
|
|
2780
|
+
__publicField(this, _e);
|
|
2781
|
+
__publicField(this, "__parentPseudo");
|
|
2782
|
+
__publicField(this, "__childValues");
|
|
2783
|
+
__publicField(this, "__parentWkri");
|
|
2784
|
+
__publicField(this, "__childNodes");
|
|
2785
|
+
__publicField(this, "__tile");
|
|
2786
|
+
__publicField(this, "__node");
|
|
2787
|
+
this.__childValues = /* @__PURE__ */ new Map();
|
|
2788
|
+
this.__parentWkri = parentWkri;
|
|
2789
|
+
this.__tile = tile;
|
|
2790
|
+
this.__node = node;
|
|
2791
|
+
this.__childNodes = childNodes;
|
|
2792
|
+
return new Proxy(this, {
|
|
2793
|
+
set: (object, key, value) => {
|
|
2794
|
+
const k = typeof key === "symbol" ? key.description || "" : key;
|
|
2795
|
+
if (key in object) {
|
|
2796
|
+
object[key] = value;
|
|
2797
|
+
} else if (k.startsWith("__") || k in object) {
|
|
2798
|
+
object[k] = value;
|
|
2799
|
+
} else {
|
|
2800
|
+
object.__set(k, value);
|
|
2801
|
+
}
|
|
2802
|
+
return true;
|
|
2803
|
+
},
|
|
2804
|
+
get: (object, key) => {
|
|
2805
|
+
const k = typeof key === "symbol" ? key.description || "" : key;
|
|
2806
|
+
if (key in object) {
|
|
2807
|
+
return object[key];
|
|
2808
|
+
} else if (k.startsWith("__") || k in object) {
|
|
2809
|
+
return object[k];
|
|
2810
|
+
}
|
|
2811
|
+
if (k == "length") {
|
|
2812
|
+
return object.__childNodes.size;
|
|
2813
|
+
}
|
|
2814
|
+
return new AttrPromise((resolve) => {
|
|
2815
|
+
object.__get(k).then(resolve);
|
|
2816
|
+
});
|
|
2817
|
+
}
|
|
2818
|
+
});
|
|
2819
|
+
}
|
|
2820
|
+
__forJsonCache() {
|
|
2821
|
+
return null;
|
|
2822
|
+
}
|
|
2823
|
+
async toString() {
|
|
2824
|
+
const entries = [...this.__childValues.entries()].map(([k, v]) => `${k}: ${v}`);
|
|
2825
|
+
return `[[${entries.join(",")}]]`;
|
|
2826
|
+
}
|
|
2827
|
+
async toObject() {
|
|
2828
|
+
const entries = [...(await this.__getChildValues()).entries()];
|
|
2829
|
+
return Object.fromEntries(await Promise.all(entries.map(async ([k, vl]) => {
|
|
2830
|
+
return [k, (await vl).getValue()];
|
|
2831
|
+
})));
|
|
2832
|
+
}
|
|
2833
|
+
async forJson() {
|
|
2834
|
+
async function _forJson(v) {
|
|
2835
|
+
v = await v;
|
|
2836
|
+
if (!v) {
|
|
2837
|
+
return null;
|
|
2838
|
+
}
|
|
2839
|
+
return await v.forJson();
|
|
2840
|
+
}
|
|
2841
|
+
const entries = [...(await this.__getChildValues()).entries()];
|
|
2842
|
+
return Object.fromEntries(await Promise.all(entries.map(async ([k, vl]) => {
|
|
2843
|
+
return [k, vl ? await _forJson(vl) : vl];
|
|
2844
|
+
})));
|
|
2845
|
+
}
|
|
2846
|
+
async __update(map) {
|
|
2847
|
+
return Promise.all(
|
|
2848
|
+
[...map.entries()].map(([k, v]) => {
|
|
2849
|
+
this.__set(k, v);
|
|
2850
|
+
})
|
|
2851
|
+
);
|
|
2852
|
+
}
|
|
2853
|
+
async __get(key) {
|
|
2854
|
+
const childValue = await this.__getChildValue(key);
|
|
2855
|
+
return childValue.getValue();
|
|
2856
|
+
}
|
|
2857
|
+
async __set(key, value) {
|
|
2858
|
+
if (!this.__childNodes.has(key)) {
|
|
2859
|
+
throw Error(
|
|
2860
|
+
`Semantic node does not have this key: ${key} (${[...this.__childNodes.keys()]})`
|
|
2861
|
+
);
|
|
2862
|
+
}
|
|
2863
|
+
throw Error(`Setting semantic keys (${key} = ${value}) is not implemented yet in Javascript`);
|
|
2864
|
+
}
|
|
2865
|
+
__has(key) {
|
|
2866
|
+
return this.__childNodes.has(key);
|
|
2867
|
+
}
|
|
2868
|
+
async __getChildTypes() {
|
|
2869
|
+
const promises = [...this.__childNodes.keys()].map(async (key) => [
|
|
2870
|
+
key,
|
|
2871
|
+
await this.__getChildValue(key)
|
|
2872
|
+
]);
|
|
2873
|
+
const entries = await Promise.all(promises);
|
|
2874
|
+
return new Map([...entries]);
|
|
2875
|
+
}
|
|
2876
|
+
async __getChildren(direct = null) {
|
|
2877
|
+
const items = /* @__PURE__ */ new Map();
|
|
2878
|
+
for (const [key, value] of [...(await this.__getChildValues()).entries()]) {
|
|
2879
|
+
items.set(key, value);
|
|
2880
|
+
}
|
|
2881
|
+
const children = [...items.entries()].filter((entry) => {
|
|
2882
|
+
const child = this.__childNodes.get(entry[0]);
|
|
2883
|
+
if (!child) {
|
|
2884
|
+
throw Error("Child key is not in child nodes");
|
|
2885
|
+
}
|
|
2886
|
+
return (direct === null || direct === !child.is_collector) && entry[1] !== null;
|
|
2887
|
+
}).map((entry) => entry[1]);
|
|
2888
|
+
return children;
|
|
2889
|
+
}
|
|
2890
|
+
async __getChildValue(key, setDefault = false) {
|
|
2891
|
+
if (!this.__childNodes.has(key)) {
|
|
2892
|
+
throw Error(
|
|
2893
|
+
`Semantic node does not have this key: ${key} (${[...this.__childNodes.keys()]})`
|
|
2894
|
+
);
|
|
2895
|
+
}
|
|
2896
|
+
let child;
|
|
2897
|
+
if (!this.__childValues.has(key)) {
|
|
2898
|
+
const children = await this.__getChildValues();
|
|
2899
|
+
child = children.get(key) || null;
|
|
2900
|
+
let set = true;
|
|
2901
|
+
if (child === null) {
|
|
2902
|
+
child = this.__makePseudo(key);
|
|
2903
|
+
set = setDefault;
|
|
2904
|
+
}
|
|
2905
|
+
if (set) {
|
|
2906
|
+
this.__childValues.set(key, child);
|
|
2907
|
+
}
|
|
2908
|
+
child.parentNode = this.__parentPseudo || null;
|
|
2909
|
+
} else {
|
|
2910
|
+
child = this.__childValues.get(key);
|
|
2911
|
+
}
|
|
2912
|
+
return child;
|
|
2913
|
+
}
|
|
2914
|
+
__makePseudo(key) {
|
|
2915
|
+
const childNode = this.__childNodes.get(key);
|
|
2916
|
+
if (!childNode) {
|
|
2917
|
+
throw Error(`Child node key ${key} missing`);
|
|
2918
|
+
}
|
|
2919
|
+
if (!this.__parentWkri) {
|
|
2920
|
+
throw Error("This semantic node is currently parentless (no WKRI)");
|
|
2921
|
+
}
|
|
2922
|
+
if (!this.__parentWkri.$) {
|
|
2923
|
+
throw Error("This semantic node is currently on an unloaded WKRI");
|
|
2924
|
+
}
|
|
2925
|
+
const child = this.__parentWkri.$.addPseudo(childNode, this.__tile, this.__node);
|
|
2926
|
+
child.parentNode = this.__parentPseudo || null;
|
|
2927
|
+
return child;
|
|
2928
|
+
}
|
|
2929
|
+
static async __create(tile, node, value, parent, childNodes) {
|
|
2930
|
+
const svm = new _SemanticViewModel(parent, childNodes, tile, node);
|
|
2931
|
+
if (value) {
|
|
2932
|
+
try {
|
|
2933
|
+
await svm.__update(value);
|
|
2934
|
+
} catch (e) {
|
|
2935
|
+
tileLoadingError(
|
|
2936
|
+
`
|
|
2937
|
+
Suppressed a tile loading error: ${e}: ${typeof e} (tile: ${tile}; node: ${node}) - ${value}
|
|
2938
|
+
`,
|
|
2939
|
+
e
|
|
2940
|
+
);
|
|
2941
|
+
}
|
|
2942
|
+
}
|
|
2943
|
+
return svm;
|
|
2944
|
+
}
|
|
2945
|
+
async __asTileData() {
|
|
2946
|
+
const relationships = [];
|
|
2947
|
+
for (const value of [...await this.__getChildren(true)]) {
|
|
2948
|
+
const [, subrelationships] = await value.getTile();
|
|
2949
|
+
relationships.push(...subrelationships);
|
|
2950
|
+
}
|
|
2951
|
+
return [null, relationships];
|
|
2952
|
+
}
|
|
2953
|
+
async __getChildValues() {
|
|
2954
|
+
const parent = this.__parentWkri;
|
|
2955
|
+
const childNodes = this.__childNodes;
|
|
2956
|
+
const tile = this.__tile;
|
|
2957
|
+
const node = this.__node;
|
|
2958
|
+
if (!parent || !parent.$) {
|
|
2959
|
+
return /* @__PURE__ */ new Map();
|
|
2960
|
+
}
|
|
2961
|
+
await parent.$.loadNodes([...childNodes.keys()]);
|
|
2962
|
+
const children = /* @__PURE__ */ new Map();
|
|
2963
|
+
for (const entry of [...parent.$.allEntries()]) {
|
|
2964
|
+
const key = entry[0];
|
|
2965
|
+
let values = entry[1];
|
|
2966
|
+
if (values instanceof Promise) {
|
|
2967
|
+
values = await values;
|
|
2968
|
+
}
|
|
2969
|
+
if (values === false || values === null || values === void 0) {
|
|
2970
|
+
continue;
|
|
2971
|
+
}
|
|
2972
|
+
const childNode = childNodes.get(key);
|
|
2973
|
+
if (childNode) {
|
|
2974
|
+
for (let value of values) {
|
|
2975
|
+
if (value !== null && value.node && (!value.parentNode || value.parentNode === this.__parentPseudo)) {
|
|
2976
|
+
value = await value;
|
|
2977
|
+
if (!value.node) {
|
|
2978
|
+
throw Error(`Node ${childNode.alias} (${childNode.nodeid}) is unavailable`);
|
|
2979
|
+
}
|
|
2980
|
+
if (
|
|
2981
|
+
// value.node.nodegroup_id == node.nodeid in all cases for first possibility?
|
|
2982
|
+
value.node.nodegroup_id != node.nodegroup_id && tile && value.tile && (!value.tile.parenttile_id || value.tile.parenttile_id == tile.tileid) || value.node.nodegroup_id == node.nodegroup_id && tile && value.tile == tile && !childNode.is_collector
|
|
2983
|
+
) {
|
|
2984
|
+
children.set(key, value);
|
|
2985
|
+
} else if (node.nodegroup_id != value.node.nodegroup_id && childNode.is_collector) {
|
|
2986
|
+
const childValue = value instanceof PseudoList ? value : value.isIterable() ? await value.getValue() : null;
|
|
2987
|
+
let listValue;
|
|
2988
|
+
if (childValue && Array.isArray(childValue)) {
|
|
2989
|
+
listValue = childValue;
|
|
2990
|
+
} else {
|
|
2991
|
+
listValue = null;
|
|
2992
|
+
}
|
|
2993
|
+
if (listValue !== null) {
|
|
2994
|
+
if (children.has(key)) {
|
|
2995
|
+
children.get(key).push(...listValue);
|
|
2996
|
+
} else {
|
|
2997
|
+
children.set(key, listValue);
|
|
2998
|
+
}
|
|
2999
|
+
} else {
|
|
3000
|
+
children.set(key, value);
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
}
|
|
3004
|
+
}
|
|
3005
|
+
}
|
|
3006
|
+
}
|
|
3007
|
+
for (const [key, value] of [...children.entries()]) {
|
|
3008
|
+
value.parentNode = this.__parentPseudo;
|
|
3009
|
+
this.__childValues.set(key, value);
|
|
3010
|
+
}
|
|
3011
|
+
return children;
|
|
3012
|
+
}
|
|
3013
|
+
};
|
|
3014
|
+
let SemanticViewModel = _SemanticViewModel;
|
|
3015
|
+
const CUSTOM_DATATYPES = /* @__PURE__ */ new Map();
|
|
3016
|
+
async function getViewModel(parentPseudo, tile, node, data, parent, childNodes, isInner = false) {
|
|
3017
|
+
let vm;
|
|
3018
|
+
const cacheEntries = parentPseudo.parent && parentPseudo.parent.$ ? await parentPseudo.parent.$.getValueCache(false, void 0) : void 0;
|
|
3019
|
+
let cacheEntry = null;
|
|
3020
|
+
if (cacheEntries) {
|
|
3021
|
+
cacheEntry = (tile.tileid ? cacheEntries[tile.tileid] ?? {} : {})[node.nodeid];
|
|
3022
|
+
}
|
|
3023
|
+
const datatype = isInner ? "semantic" : CUSTOM_DATATYPES.get(node.datatype) ?? node.datatype;
|
|
3024
|
+
let conceptCacheEntry;
|
|
3025
|
+
let conceptValueCacheEntry;
|
|
3026
|
+
let resourceInstanceCacheEntry;
|
|
3027
|
+
let resourceInstanceListCacheEntry;
|
|
3028
|
+
if (!(typeof datatype == "string")) {
|
|
3029
|
+
vm = await datatype.__create(tile, node, data, cacheEntry);
|
|
3030
|
+
} else {
|
|
3031
|
+
switch (datatype) {
|
|
3032
|
+
case "semantic":
|
|
3033
|
+
vm = await SemanticViewModel.__create(
|
|
3034
|
+
tile,
|
|
3035
|
+
node,
|
|
3036
|
+
data,
|
|
3037
|
+
parent,
|
|
3038
|
+
childNodes
|
|
3039
|
+
);
|
|
3040
|
+
break;
|
|
3041
|
+
case "domain-value":
|
|
3042
|
+
vm = await DomainValueViewModel.__create(tile, node, data);
|
|
3043
|
+
break;
|
|
3044
|
+
case "domain-value-list":
|
|
3045
|
+
vm = await DomainValueListViewModel.__create(tile, node, data);
|
|
3046
|
+
break;
|
|
3047
|
+
case "concept":
|
|
3048
|
+
if (cacheEntry && typeof cacheEntry === "object" && !(cacheEntry instanceof ConceptValueCacheEntry)) {
|
|
3049
|
+
conceptValueCacheEntry = new ConceptValueCacheEntry(cacheEntry);
|
|
3050
|
+
} else {
|
|
3051
|
+
conceptValueCacheEntry = cacheEntry;
|
|
3052
|
+
}
|
|
3053
|
+
vm = await ConceptValueViewModel.__create(tile, node, data, conceptValueCacheEntry);
|
|
3054
|
+
break;
|
|
3055
|
+
case "resource-instance":
|
|
3056
|
+
if (cacheEntry && typeof cacheEntry === "object" && !(cacheEntry instanceof ResourceInstanceCacheEntry)) {
|
|
3057
|
+
resourceInstanceCacheEntry = new ResourceInstanceCacheEntry(cacheEntry);
|
|
3058
|
+
} else {
|
|
3059
|
+
resourceInstanceCacheEntry = cacheEntry;
|
|
3060
|
+
}
|
|
3061
|
+
vm = await ResourceInstanceViewModel.__create(tile, node, data, resourceInstanceCacheEntry);
|
|
3062
|
+
break;
|
|
3063
|
+
case "resource-instance-list":
|
|
3064
|
+
if (cacheEntry && typeof cacheEntry === "object" && !(cacheEntry instanceof ResourceInstanceListCacheEntry)) {
|
|
3065
|
+
resourceInstanceListCacheEntry = new ResourceInstanceListCacheEntry(cacheEntry);
|
|
3066
|
+
} else {
|
|
3067
|
+
resourceInstanceListCacheEntry = cacheEntry;
|
|
3068
|
+
}
|
|
3069
|
+
vm = await ResourceInstanceListViewModel.__create(tile, node, data, resourceInstanceListCacheEntry);
|
|
3070
|
+
break;
|
|
3071
|
+
case "concept-list":
|
|
3072
|
+
if (cacheEntry && typeof cacheEntry === "object" && !(cacheEntry instanceof ConceptListCacheEntry)) {
|
|
3073
|
+
conceptCacheEntry = new ConceptListCacheEntry(cacheEntry);
|
|
3074
|
+
} else {
|
|
3075
|
+
conceptCacheEntry = cacheEntry;
|
|
3076
|
+
}
|
|
3077
|
+
vm = await ConceptListViewModel.__create(tile, node, data, conceptCacheEntry);
|
|
3078
|
+
break;
|
|
3079
|
+
case "date":
|
|
3080
|
+
vm = await DateViewModel.__create(tile, node, data);
|
|
3081
|
+
break;
|
|
3082
|
+
case "geojson-feature-collection":
|
|
3083
|
+
vm = await GeoJSONViewModel.__create(tile, node, data);
|
|
3084
|
+
break;
|
|
3085
|
+
case "boolean":
|
|
3086
|
+
vm = await BooleanViewModel.__create(tile, node, data);
|
|
3087
|
+
break;
|
|
3088
|
+
case "string":
|
|
3089
|
+
vm = await StringViewModel.__create(tile, node, data);
|
|
3090
|
+
break;
|
|
3091
|
+
case "number":
|
|
3092
|
+
vm = await NumberViewModel.__create(tile, node, data);
|
|
3093
|
+
break;
|
|
3094
|
+
case "file-list":
|
|
3095
|
+
vm = await FileListViewModel.__create(tile, node, data);
|
|
3096
|
+
break;
|
|
3097
|
+
case "edtf":
|
|
3098
|
+
vm = await EDTFViewModel.__create(tile, node, data);
|
|
3099
|
+
break;
|
|
3100
|
+
case "url":
|
|
3101
|
+
vm = await UrlViewModel.__create(tile, node, data);
|
|
3102
|
+
break;
|
|
3103
|
+
case "non-localized-string":
|
|
3104
|
+
vm = await NonLocalizedStringViewModel.__create(tile, node, data);
|
|
3105
|
+
break;
|
|
3106
|
+
default:
|
|
3107
|
+
console.warn("Missing type for tile", tile.tileid, "on node", node.alias, "with type", node.datatype);
|
|
3108
|
+
vm = await NonLocalizedStringViewModel.__create(tile, node, data);
|
|
3109
|
+
}
|
|
3110
|
+
}
|
|
3111
|
+
if (vm === null) {
|
|
3112
|
+
return null;
|
|
3113
|
+
}
|
|
3114
|
+
vm.__parentPseudo = parentPseudo;
|
|
3115
|
+
if (vm instanceof Array) {
|
|
3116
|
+
for (const vme of vm) {
|
|
3117
|
+
if (vme instanceof Promise) {
|
|
3118
|
+
vme.then((vmep) => {
|
|
3119
|
+
if (vmep !== null) vmep.__parentPseudo = parentPseudo;
|
|
3120
|
+
});
|
|
3121
|
+
} else {
|
|
3122
|
+
vme.__parentPseudo = parentPseudo;
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
}
|
|
3126
|
+
return vm;
|
|
3127
|
+
}
|
|
3128
|
+
const viewModels = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3129
|
+
__proto__: null,
|
|
3130
|
+
BooleanViewModel,
|
|
3131
|
+
CUSTOM_DATATYPES,
|
|
3132
|
+
ConceptValueViewModel,
|
|
3133
|
+
DEFAULT_LANGUAGE,
|
|
3134
|
+
DateViewModel,
|
|
3135
|
+
DomainValueViewModel,
|
|
3136
|
+
GeoJSONViewModel,
|
|
3137
|
+
NonLocalizedStringViewModel,
|
|
3138
|
+
NumberViewModel,
|
|
3139
|
+
ResourceInstanceCacheEntry,
|
|
3140
|
+
ResourceInstanceViewModel,
|
|
3141
|
+
SemanticViewModel,
|
|
3142
|
+
StringViewModel,
|
|
3143
|
+
UrlViewModel,
|
|
3144
|
+
ValueList,
|
|
3145
|
+
getViewModel,
|
|
3146
|
+
viewContext
|
|
3147
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
3148
|
+
class PseudoUnavailable {
|
|
3149
|
+
constructor(node) {
|
|
3150
|
+
__publicField(this, "parentNode", null);
|
|
3151
|
+
__publicField(this, "tile", null);
|
|
3152
|
+
__publicField(this, "node");
|
|
3153
|
+
__publicField(this, "isOuter", false);
|
|
3154
|
+
this.node = node;
|
|
3155
|
+
}
|
|
3156
|
+
async forJson() {
|
|
3157
|
+
return null;
|
|
3158
|
+
}
|
|
3159
|
+
describeField() {
|
|
3160
|
+
return "Unavailable field";
|
|
3161
|
+
}
|
|
3162
|
+
describeFieldGroup() {
|
|
3163
|
+
return "Unavailable field";
|
|
3164
|
+
}
|
|
3165
|
+
getValue() {
|
|
3166
|
+
return new AttrPromise((resolve) => resolve(null));
|
|
3167
|
+
}
|
|
3168
|
+
getLength() {
|
|
3169
|
+
return 0;
|
|
3170
|
+
}
|
|
3171
|
+
getChildren(_ = false) {
|
|
3172
|
+
return [];
|
|
3173
|
+
}
|
|
3174
|
+
isIterable() {
|
|
3175
|
+
return false;
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3178
|
+
const ITERABLE_DATATYPES = [
|
|
3179
|
+
"concept-list",
|
|
3180
|
+
"resource-instance-list",
|
|
3181
|
+
"domain-value-list"
|
|
3182
|
+
];
|
|
3183
|
+
class PseudoValue {
|
|
3184
|
+
constructor(node, tile, value, parent, childNodes, inner) {
|
|
3185
|
+
__publicField(this, "node");
|
|
3186
|
+
__publicField(this, "tile");
|
|
3187
|
+
__publicField(this, "value");
|
|
3188
|
+
__publicField(this, "parent");
|
|
3189
|
+
__publicField(this, "parentNode");
|
|
3190
|
+
__publicField(this, "valueLoaded", false);
|
|
3191
|
+
__publicField(this, "datatype", null);
|
|
3192
|
+
__publicField(this, "originalTile");
|
|
3193
|
+
__publicField(this, "accessed");
|
|
3194
|
+
__publicField(this, "childNodes");
|
|
3195
|
+
__publicField(this, "isOuter", false);
|
|
3196
|
+
__publicField(this, "isInner", false);
|
|
3197
|
+
__publicField(this, "inner", null);
|
|
3198
|
+
__publicField(this, "independent");
|
|
3199
|
+
this.node = node;
|
|
3200
|
+
this.tile = tile;
|
|
3201
|
+
this.independent = tile === null;
|
|
3202
|
+
if (!parent) {
|
|
3203
|
+
throw Error("Must have a parent or parent class for a pseudo-node");
|
|
3204
|
+
}
|
|
3205
|
+
this.parent = parent;
|
|
3206
|
+
this.parentNode = null;
|
|
3207
|
+
this.childNodes = childNodes;
|
|
3208
|
+
this.value = value;
|
|
3209
|
+
this.accessed = false;
|
|
3210
|
+
this.originalTile = tile;
|
|
3211
|
+
this.datatype = node.datatype;
|
|
3212
|
+
if (inner instanceof PseudoValue) {
|
|
3213
|
+
this.isOuter = true;
|
|
3214
|
+
this.inner = inner;
|
|
3215
|
+
}
|
|
3216
|
+
if (inner === true) {
|
|
3217
|
+
this.isInner = true;
|
|
3218
|
+
this.datatype = "semantic";
|
|
3219
|
+
}
|
|
3220
|
+
}
|
|
3221
|
+
isIterable() {
|
|
3222
|
+
return this.datatype !== null && ITERABLE_DATATYPES.includes(this.datatype);
|
|
3223
|
+
}
|
|
3224
|
+
describeField() {
|
|
3225
|
+
let fieldName = this.node.name;
|
|
3226
|
+
if (this.parent && this.parent.__) {
|
|
3227
|
+
fieldName = `${this.parent.__.wkrm.modelName} - ${fieldName}`;
|
|
3228
|
+
}
|
|
3229
|
+
return fieldName;
|
|
3230
|
+
}
|
|
3231
|
+
describeFieldGroup() {
|
|
3232
|
+
let fieldName = this.node.name;
|
|
3233
|
+
if (this.parent && this.node.nodegroup_id && this.parent.$) {
|
|
3234
|
+
const nodegroup = this.parent.$.model.getNodeObjects().get(this.node.nodegroup_id);
|
|
3235
|
+
if (nodegroup && this.parent.__) {
|
|
3236
|
+
fieldName = `${this.parent.__.wkrm.modelName} - ${nodegroup.name}`;
|
|
3237
|
+
}
|
|
3238
|
+
}
|
|
3239
|
+
return fieldName;
|
|
3240
|
+
}
|
|
3241
|
+
// TODO deepcopy
|
|
3242
|
+
//
|
|
3243
|
+
getParentTileId() {
|
|
3244
|
+
return this.tile ? this.tile.parenttile_id : null;
|
|
3245
|
+
}
|
|
3246
|
+
async getTile() {
|
|
3247
|
+
await this.updateValue();
|
|
3248
|
+
let relationships = [];
|
|
3249
|
+
if (this.inner) {
|
|
3250
|
+
[this.tile, relationships] = await this.inner.getTile();
|
|
3251
|
+
}
|
|
3252
|
+
let tileValue;
|
|
3253
|
+
if (this.value !== null) {
|
|
3254
|
+
const [newTileValue, ownRelationships] = await (await this.value).__asTileData();
|
|
3255
|
+
tileValue = newTileValue;
|
|
3256
|
+
relationships = [...relationships, ...ownRelationships];
|
|
3257
|
+
} else {
|
|
3258
|
+
tileValue = null;
|
|
3259
|
+
}
|
|
3260
|
+
if (!this.tile) {
|
|
3261
|
+
throw Error();
|
|
3262
|
+
}
|
|
3263
|
+
this.tile.data = this.tile.data || {};
|
|
3264
|
+
if (tileValue === null) {
|
|
3265
|
+
if (this.tile.data.get(this.node.nodeid)) {
|
|
3266
|
+
this.tile.data.delete(this.node.nodeid);
|
|
3267
|
+
}
|
|
3268
|
+
} else {
|
|
3269
|
+
this.tile.data.set(this.node.nodeid, tileValue);
|
|
3270
|
+
}
|
|
3271
|
+
const tile = this.independent ? this.tile : null;
|
|
3272
|
+
return [tile, relationships];
|
|
3273
|
+
}
|
|
3274
|
+
clear() {
|
|
3275
|
+
this.value = null;
|
|
3276
|
+
if (this.tile && this.tile.data && this.tile.data.has(this.node.nodeid)) {
|
|
3277
|
+
this.tile.data.delete(this.node.nodeid);
|
|
3278
|
+
}
|
|
3279
|
+
}
|
|
3280
|
+
updateValue(tile) {
|
|
3281
|
+
if (tile) {
|
|
3282
|
+
this.tile = tile;
|
|
3283
|
+
}
|
|
3284
|
+
this.accessed = true;
|
|
3285
|
+
if (this.inner) {
|
|
3286
|
+
this.inner.accessed = true;
|
|
3287
|
+
}
|
|
3288
|
+
if (!this.tile) {
|
|
3289
|
+
if (!this.node) {
|
|
3290
|
+
throw Error("Empty tile");
|
|
3291
|
+
}
|
|
3292
|
+
if (this.inner) {
|
|
3293
|
+
return new AttrPromise(async (resolve) => {
|
|
3294
|
+
var _a2;
|
|
3295
|
+
const tile2 = await ((_a2 = this.inner) == null ? void 0 : _a2.getTile());
|
|
3296
|
+
resolve(this.updateValue(tile2 ? tile2[0] : void 0));
|
|
3297
|
+
});
|
|
3298
|
+
}
|
|
3299
|
+
if (!this.tile) {
|
|
3300
|
+
this.tile = new StaticTile({
|
|
3301
|
+
nodegroup_id: this.node.nodegroup_id || "",
|
|
3302
|
+
tileid: null,
|
|
3303
|
+
data: /* @__PURE__ */ new Map(),
|
|
3304
|
+
sortorder: this.node.sortorder,
|
|
3305
|
+
resourceinstance_id: "",
|
|
3306
|
+
parenttile_id: null,
|
|
3307
|
+
provisionaledits: null,
|
|
3308
|
+
ensureId: () => ""
|
|
3309
|
+
});
|
|
3310
|
+
}
|
|
3311
|
+
}
|
|
3312
|
+
if (this.valueLoaded === false) {
|
|
3313
|
+
this.valueLoaded = void 0;
|
|
3314
|
+
let data;
|
|
3315
|
+
if (this.value === null && this.tile.data !== null && this.tile.data.has(this.node.nodeid) && this.datatype !== "semantic") {
|
|
3316
|
+
data = this.tile.data.get(this.node.nodeid);
|
|
3317
|
+
} else {
|
|
3318
|
+
data = this.value;
|
|
3319
|
+
}
|
|
3320
|
+
if (this.isOuter && typeof data === "object" && this.inner && data) {
|
|
3321
|
+
let outerData = void 0;
|
|
3322
|
+
if ("_" in data && !data.constructor) {
|
|
3323
|
+
outerData = data["_"];
|
|
3324
|
+
delete data["_"];
|
|
3325
|
+
this.inner.getValue().then((v) => v && v.update(data));
|
|
3326
|
+
data = outerData;
|
|
3327
|
+
} else if (data instanceof Map && data.has("_")) {
|
|
3328
|
+
outerData = data.get("_");
|
|
3329
|
+
data.delete("_");
|
|
3330
|
+
this.inner.getValue().then((v) => v && v.update(data));
|
|
3331
|
+
data = outerData;
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
const vm = getViewModel(
|
|
3335
|
+
this,
|
|
3336
|
+
this.tile,
|
|
3337
|
+
this.node,
|
|
3338
|
+
data,
|
|
3339
|
+
this.parent,
|
|
3340
|
+
this.childNodes,
|
|
3341
|
+
this.isInner
|
|
3342
|
+
);
|
|
3343
|
+
const resolveAttr = (vm2) => {
|
|
3344
|
+
if (vm2 !== null && vm2 instanceof Object) {
|
|
3345
|
+
vm2.__parentPseudo = this;
|
|
3346
|
+
if (this.isOuter && this.inner) {
|
|
3347
|
+
vm2._ = this.inner.getValue();
|
|
3348
|
+
}
|
|
3349
|
+
this.valueLoaded = true;
|
|
3350
|
+
}
|
|
3351
|
+
return vm2;
|
|
3352
|
+
};
|
|
3353
|
+
this.value = new AttrPromise((resolve) => {
|
|
3354
|
+
vm.then((vm2) => resolve(vm2 ? resolveAttr(vm2) : vm2));
|
|
3355
|
+
});
|
|
3356
|
+
}
|
|
3357
|
+
return this.value;
|
|
3358
|
+
}
|
|
3359
|
+
getValue() {
|
|
3360
|
+
return this.updateValue();
|
|
3361
|
+
}
|
|
3362
|
+
// @value.setter
|
|
3363
|
+
// def value(this, value):
|
|
3364
|
+
getLength() {
|
|
3365
|
+
return this.getChildren().length;
|
|
3366
|
+
}
|
|
3367
|
+
async getChildTypes() {
|
|
3368
|
+
await this.updateValue();
|
|
3369
|
+
let childTypes = {};
|
|
3370
|
+
if (this.value && this.value instanceof Object && "getChildTypes" in this.value && typeof this.value.getChildTypes === "function") {
|
|
3371
|
+
childTypes = this.value.getChildTypes();
|
|
3372
|
+
}
|
|
3373
|
+
if (this.inner) {
|
|
3374
|
+
Object.assign(childTypes, this.inner.getChildTypes());
|
|
3375
|
+
}
|
|
3376
|
+
return childTypes;
|
|
3377
|
+
}
|
|
3378
|
+
getChildren(direct = null) {
|
|
3379
|
+
let children = [];
|
|
3380
|
+
if (this.value && this.value instanceof Object && "getChildren" in this.value && typeof this.value.getChildren === "function") {
|
|
3381
|
+
children = this.value.getChildren(direct);
|
|
3382
|
+
}
|
|
3383
|
+
if (this.inner) {
|
|
3384
|
+
children = [...children, ...this.inner.getChildren(direct)];
|
|
3385
|
+
}
|
|
3386
|
+
return children;
|
|
3387
|
+
}
|
|
3388
|
+
async forJson() {
|
|
3389
|
+
const value = await this.getValue();
|
|
3390
|
+
return value instanceof Object ? value.forJson() : value;
|
|
3391
|
+
}
|
|
3392
|
+
}
|
|
3393
|
+
class PseudoList extends Array {
|
|
3394
|
+
constructor() {
|
|
3395
|
+
super(...arguments);
|
|
3396
|
+
__publicField(this, "node");
|
|
3397
|
+
__publicField(this, "parent");
|
|
3398
|
+
__publicField(this, "parentNode", null);
|
|
3399
|
+
__publicField(this, "tile");
|
|
3400
|
+
__publicField(this, "parenttileId");
|
|
3401
|
+
__publicField(this, "ghostChildren", null);
|
|
3402
|
+
__publicField(this, "isOuter", false);
|
|
3403
|
+
}
|
|
3404
|
+
isIterable() {
|
|
3405
|
+
return true;
|
|
3406
|
+
}
|
|
3407
|
+
async sorted() {
|
|
3408
|
+
const resolved = await Promise.all(this.map(async (pn) => await pn));
|
|
3409
|
+
const sorted = resolved.sort((a, b) => {
|
|
3410
|
+
const vals = [a, b].map((val) => {
|
|
3411
|
+
if (val && a.__parentPseudo && a.__parentPseudo.tile) {
|
|
3412
|
+
if (val.__parentPseudo.tile.sortorder > 0) ;
|
|
3413
|
+
return val.__parentPseudo.tile.sortorder;
|
|
3414
|
+
} else {
|
|
3415
|
+
return 0;
|
|
3416
|
+
}
|
|
3417
|
+
});
|
|
3418
|
+
return vals[0] - vals[1];
|
|
3419
|
+
});
|
|
3420
|
+
return sorted;
|
|
3421
|
+
}
|
|
3422
|
+
describeField() {
|
|
3423
|
+
if (!this.node) {
|
|
3424
|
+
return "[(uninitialized node)]";
|
|
3425
|
+
}
|
|
3426
|
+
let fieldName = this.node.name;
|
|
3427
|
+
if (this.parent && this.parent.__) {
|
|
3428
|
+
fieldName = `${this.parent.__.wkrm.modelName} - ${fieldName}`;
|
|
3429
|
+
}
|
|
3430
|
+
return `[${fieldName}]`;
|
|
3431
|
+
}
|
|
3432
|
+
describeFieldGroup() {
|
|
3433
|
+
if (!this.node) {
|
|
3434
|
+
return "[(uninitialized node)]";
|
|
3435
|
+
}
|
|
3436
|
+
let fieldName = this.node.name;
|
|
3437
|
+
if (this.parent && this.node.nodegroup_id && this.parent.$) {
|
|
3438
|
+
const nodegroup = this.parent.$.model.getNodeObjects().get(this.node.nodegroup_id);
|
|
3439
|
+
if (nodegroup && this.parent.__) {
|
|
3440
|
+
fieldName = `${this.parent.__.wkrm.modelName} - ${nodegroup.name}`;
|
|
3441
|
+
}
|
|
3442
|
+
}
|
|
3443
|
+
return `[${fieldName}]`;
|
|
3444
|
+
}
|
|
3445
|
+
// Otherwise interferes with Array methods;
|
|
3446
|
+
initialize(node, parent) {
|
|
3447
|
+
this.node = node;
|
|
3448
|
+
if (Array.isArray(this.node)) {
|
|
3449
|
+
throw Error("Cannot make a list of lists");
|
|
3450
|
+
}
|
|
3451
|
+
if (!parent) {
|
|
3452
|
+
throw Error("Must have a parent or parent class for a pseudo-node");
|
|
3453
|
+
}
|
|
3454
|
+
this.parent = parent;
|
|
3455
|
+
this.tile = void 0;
|
|
3456
|
+
this.parenttileId = void 0;
|
|
3457
|
+
this.ghostChildren = /* @__PURE__ */ new Set();
|
|
3458
|
+
}
|
|
3459
|
+
async forJson() {
|
|
3460
|
+
const array = Array.from(
|
|
3461
|
+
(await this.sorted()).map(
|
|
3462
|
+
async (entry) => {
|
|
3463
|
+
const value = await entry;
|
|
3464
|
+
return value && value instanceof Object && value.forJson ? value.forJson() : value;
|
|
3465
|
+
}
|
|
3466
|
+
)
|
|
3467
|
+
);
|
|
3468
|
+
return Promise.all(array);
|
|
3469
|
+
}
|
|
3470
|
+
getValue() {
|
|
3471
|
+
return new AttrPromise((resolve) => resolve(this));
|
|
3472
|
+
}
|
|
3473
|
+
toString() {
|
|
3474
|
+
return `<PL: ${this.length}>`;
|
|
3475
|
+
}
|
|
3476
|
+
}
|
|
3477
|
+
function makePseudoCls(model, key, single, tile = null, wkri = null) {
|
|
3478
|
+
const nodeObjs = model.getNodeObjectsByAlias();
|
|
3479
|
+
const nodeObj = nodeObjs.get(key);
|
|
3480
|
+
if (!nodeObj) {
|
|
3481
|
+
throw Error("Could not find node by alias");
|
|
3482
|
+
}
|
|
3483
|
+
const nodegroups = model.getNodegroupObjects();
|
|
3484
|
+
const nodegroup = nodegroups.get(nodeObj.nodegroup_id || "");
|
|
3485
|
+
let value = null;
|
|
3486
|
+
if (nodeObj.nodegroup_id && nodeObj.is_collector && nodegroup && nodegroup.cardinality == "n" && true) {
|
|
3487
|
+
value = new PseudoList();
|
|
3488
|
+
value.initialize(nodeObj, wkri);
|
|
3489
|
+
}
|
|
3490
|
+
if (value === null || tile) {
|
|
3491
|
+
let nodeValue;
|
|
3492
|
+
const isPermitted = model.isNodegroupPermitted(nodeObj.nodegroup_id || "", tile, nodeObjs);
|
|
3493
|
+
if (isPermitted) {
|
|
3494
|
+
const childNodes = model.getChildNodes(nodeObj.nodeid);
|
|
3495
|
+
let inner = false;
|
|
3496
|
+
if (childNodes && childNodes.size && nodeObj.datatype !== "semantic") {
|
|
3497
|
+
inner = new PseudoValue(nodeObj, tile, null, wkri, childNodes, true);
|
|
3498
|
+
}
|
|
3499
|
+
nodeValue = new PseudoValue(nodeObj, tile, null, wkri, inner !== false ? /* @__PURE__ */ new Map() : childNodes, inner);
|
|
3500
|
+
} else {
|
|
3501
|
+
nodeValue = new PseudoUnavailable(nodeObj);
|
|
3502
|
+
}
|
|
3503
|
+
if (value) {
|
|
3504
|
+
value.push(nodeValue.getValue());
|
|
3505
|
+
} else {
|
|
3506
|
+
value = nodeValue;
|
|
3507
|
+
}
|
|
3508
|
+
}
|
|
3509
|
+
return value;
|
|
3510
|
+
}
|
|
3511
|
+
const MAX_GRAPH_DEPTH = 100;
|
|
3512
|
+
const DESCRIPTOR_FUNCTION_ID = "60000000-0000-0000-0000-000000000001";
|
|
3513
|
+
class WKRM {
|
|
3514
|
+
constructor(meta) {
|
|
3515
|
+
__publicField(this, "modelName");
|
|
3516
|
+
__publicField(this, "modelClassName");
|
|
3517
|
+
__publicField(this, "graphId");
|
|
3518
|
+
__publicField(this, "meta");
|
|
3519
|
+
let name;
|
|
3520
|
+
if (meta.name instanceof Object) {
|
|
3521
|
+
name = meta.name[DEFAULT_LANGUAGE].toString();
|
|
3522
|
+
} else {
|
|
3523
|
+
name = meta.name;
|
|
3524
|
+
}
|
|
3525
|
+
this.modelName = name || "Unnamed";
|
|
3526
|
+
this.graphId = meta.graphid;
|
|
3527
|
+
this.modelClassName = (meta.slug || this.modelName).replace(/[_-]/g, " ").replace(/\s(.)/g, (c) => c.toUpperCase()).replace(/\s/g, "");
|
|
3528
|
+
this.modelClassName = this.modelClassName[0].toUpperCase() + this.modelClassName.slice(1);
|
|
3529
|
+
this.meta = meta;
|
|
3530
|
+
}
|
|
3531
|
+
}
|
|
3532
|
+
class ConfigurationOptions {
|
|
3533
|
+
constructor() {
|
|
3534
|
+
__publicField(this, "graphs");
|
|
3535
|
+
__publicField(this, "eagerLoadGraphs", false);
|
|
3536
|
+
this.graphs = null;
|
|
3537
|
+
}
|
|
3538
|
+
}
|
|
3539
|
+
class ResourceInstanceWrapper {
|
|
3540
|
+
constructor(wkri, model, resource, pruneTiles = true) {
|
|
3541
|
+
__publicField(this, "wkri");
|
|
3542
|
+
__publicField(this, "model");
|
|
3543
|
+
__publicField(this, "resource");
|
|
3544
|
+
__publicField(this, "valueList");
|
|
3545
|
+
__publicField(this, "cache");
|
|
3546
|
+
__publicField(this, "scopes");
|
|
3547
|
+
__publicField(this, "metadata");
|
|
3548
|
+
this.wkri = wkri;
|
|
3549
|
+
this.model = model;
|
|
3550
|
+
if (resource) {
|
|
3551
|
+
this.model.stripTiles(resource);
|
|
3552
|
+
}
|
|
3553
|
+
this.resource = resource;
|
|
3554
|
+
this.valueList = new ValueList(/* @__PURE__ */ new Map(), /* @__PURE__ */ new Map(), this, []);
|
|
3555
|
+
this.cache = resource ? resource.__cache : void 0;
|
|
3556
|
+
this.scopes = resource ? resource.__scopes : void 0;
|
|
3557
|
+
this.metadata = resource ? resource.metadata : void 0;
|
|
3558
|
+
if (pruneTiles && this.resource) {
|
|
3559
|
+
this.pruneResourceTiles();
|
|
3560
|
+
}
|
|
3561
|
+
}
|
|
3562
|
+
pruneResourceTiles() {
|
|
3563
|
+
if (!this.resource) {
|
|
3564
|
+
console.warn("Trying to prune tiles for an empty resource", this.wkri.modelClassName);
|
|
3565
|
+
return;
|
|
3566
|
+
}
|
|
3567
|
+
this.resource.tiles = (this.resource.tiles || []).filter((tile) => {
|
|
3568
|
+
return this.model.isNodegroupPermitted(tile.nodegroup_id || "", tile);
|
|
3569
|
+
});
|
|
3570
|
+
}
|
|
3571
|
+
async loadNodes(aliases) {
|
|
3572
|
+
for (const key of aliases) {
|
|
3573
|
+
await this.valueList.retrieve(key);
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3576
|
+
async getName(update = false) {
|
|
3577
|
+
let resourceName = this.resource && this.resource.resourceinstance.name;
|
|
3578
|
+
if (update || !resourceName) {
|
|
3579
|
+
const descriptors = await this.getDescriptors(update);
|
|
3580
|
+
resourceName = descriptors && descriptors.name || resourceName || "<Unnamed>";
|
|
3581
|
+
if (this.resource && this.resource.resourceinstance) {
|
|
3582
|
+
this.resource.resourceinstance.name = resourceName;
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
return resourceName;
|
|
3586
|
+
}
|
|
3587
|
+
async getDescriptors(update = false) {
|
|
3588
|
+
let descriptors = this.resource && this.resource.resourceinstance.descriptors;
|
|
3589
|
+
if (update || !descriptors || descriptors.isEmpty()) {
|
|
3590
|
+
descriptors = new StaticResourceDescriptors();
|
|
3591
|
+
let descriptorConfig = void 0;
|
|
3592
|
+
if (this.model.graph.functions_x_graphs) {
|
|
3593
|
+
const descriptorNode = this.model.graph.functions_x_graphs.find((node) => node.function_id === DESCRIPTOR_FUNCTION_ID);
|
|
3594
|
+
if (descriptorNode) {
|
|
3595
|
+
descriptorConfig = descriptorNode.config;
|
|
3596
|
+
}
|
|
3597
|
+
}
|
|
3598
|
+
const nodes = this.model.getNodeObjects();
|
|
3599
|
+
if (descriptorConfig) {
|
|
3600
|
+
for (const [descriptor, config] of Object.entries(descriptorConfig.descriptor_types)) {
|
|
3601
|
+
const semanticNode = nodes.get(config.nodegroup_id);
|
|
3602
|
+
let description = config.string_template;
|
|
3603
|
+
if (!description) {
|
|
3604
|
+
continue;
|
|
3605
|
+
}
|
|
3606
|
+
let requestedNodes = description.match(/<[A-Za-z _-]*>/g) || [];
|
|
3607
|
+
const relevantNodes = [...nodes.values()].filter((node) => node.nodegroup_id === config.nodegroup_id && [...requestedNodes].includes(`<${node.name}>`)).map((node) => [node.name, node.alias || ""]);
|
|
3608
|
+
let relevantValues = [];
|
|
3609
|
+
if (semanticNode) {
|
|
3610
|
+
let semanticValue = await (await this.valueList.retrieve(semanticNode.alias || ""))[0];
|
|
3611
|
+
if (semanticValue instanceof PseudoList) {
|
|
3612
|
+
semanticValue = await semanticValue[0];
|
|
3613
|
+
} else if (semanticValue.inner) {
|
|
3614
|
+
relevantValues.push([semanticNode.name || "", await semanticValue.getValue()]);
|
|
3615
|
+
semanticValue = await semanticValue.inner.getValue();
|
|
3616
|
+
} else {
|
|
3617
|
+
semanticValue = await semanticValue.getValue();
|
|
3618
|
+
}
|
|
3619
|
+
if (semanticValue) {
|
|
3620
|
+
relevantValues = [...relevantValues, ...await Promise.all(relevantNodes.filter(([_, alias]) => semanticValue.__has(alias)).map(([name, alias]) => semanticValue[alias].then((value) => [name, value])))];
|
|
3621
|
+
}
|
|
3622
|
+
}
|
|
3623
|
+
if (relevantValues) {
|
|
3624
|
+
description = relevantValues.reduce((desc, [name, value]) => value ? desc.replace(`<${name}>`, value) : desc, description);
|
|
3625
|
+
}
|
|
3626
|
+
requestedNodes = description.match(/<[A-Za-z _-]*>/g) || [];
|
|
3627
|
+
if (requestedNodes.length) {
|
|
3628
|
+
relevantValues = await Promise.all(relevantNodes.map(([name, alias]) => this.valueList.retrieve(alias).then((values) => [name, values ? values[0] : void 0])));
|
|
3629
|
+
if (relevantValues) {
|
|
3630
|
+
description = relevantValues.reduce((desc, [name, value]) => value ? desc.replace(`<${name}>`, value) : desc, description);
|
|
3631
|
+
}
|
|
3632
|
+
}
|
|
3633
|
+
descriptors[descriptor] = description;
|
|
3634
|
+
}
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3637
|
+
if (this.resource && this.resource.resourceinstance) {
|
|
3638
|
+
this.resource.resourceinstance.descriptors = descriptors;
|
|
3639
|
+
if (descriptors.name) {
|
|
3640
|
+
this.resource.resourceinstance.descriptors.name = descriptors.name;
|
|
3641
|
+
}
|
|
3642
|
+
}
|
|
3643
|
+
return descriptors;
|
|
3644
|
+
}
|
|
3645
|
+
addPseudo(childNode, tile, node) {
|
|
3646
|
+
const key = childNode.alias;
|
|
3647
|
+
if (!key) {
|
|
3648
|
+
throw Error(`Cannot add a pseudo node with no alias ${childNode.nodeid}`);
|
|
3649
|
+
}
|
|
3650
|
+
const child = makePseudoCls(
|
|
3651
|
+
this.model,
|
|
3652
|
+
key,
|
|
3653
|
+
false,
|
|
3654
|
+
!childNode.is_collector && childNode.nodegroup_id === node.nodegroup_id ? tile : null,
|
|
3655
|
+
// Does it share a tile
|
|
3656
|
+
this.wkri
|
|
3657
|
+
);
|
|
3658
|
+
const valueList = this.valueList;
|
|
3659
|
+
valueList.setDefault(key, []).then((val) => val.push(child));
|
|
3660
|
+
return child;
|
|
3661
|
+
}
|
|
3662
|
+
allEntries() {
|
|
3663
|
+
return this.valueList.values.entries();
|
|
3664
|
+
}
|
|
3665
|
+
async keys() {
|
|
3666
|
+
return (await this.getRootViewModel()).keys();
|
|
3667
|
+
}
|
|
3668
|
+
async values() {
|
|
3669
|
+
return (await this.getRootViewModel()).values();
|
|
3670
|
+
}
|
|
3671
|
+
async entries() {
|
|
3672
|
+
return (await this.getRootViewModel()).entries();
|
|
3673
|
+
}
|
|
3674
|
+
async getRootViewModel() {
|
|
3675
|
+
const root = await this.getRoot();
|
|
3676
|
+
let value = null;
|
|
3677
|
+
if (root) {
|
|
3678
|
+
const rootValue = await root.getValue();
|
|
3679
|
+
if (!Array.isArray(rootValue)) {
|
|
3680
|
+
value = rootValue;
|
|
3681
|
+
}
|
|
3682
|
+
}
|
|
3683
|
+
if (!value || !(value instanceof SemanticViewModel)) {
|
|
3684
|
+
throw Error(`Tried to get root on ${this.model.wkrm.modelClassName}, which has no root`);
|
|
3685
|
+
}
|
|
3686
|
+
return value;
|
|
3687
|
+
}
|
|
3688
|
+
getOrmAttribute(key) {
|
|
3689
|
+
let promise;
|
|
3690
|
+
if (this.resource === null) {
|
|
3691
|
+
promise = this.model.findStatic(this.wkri.id).then((resource) => {
|
|
3692
|
+
this.resource = resource;
|
|
3693
|
+
}).then(() => this.populate(true));
|
|
3694
|
+
} else {
|
|
3695
|
+
promise = new Promise((resolve) => {
|
|
3696
|
+
resolve();
|
|
3697
|
+
});
|
|
3698
|
+
}
|
|
3699
|
+
return new AttrPromise((resolve) => {
|
|
3700
|
+
promise.then(() => this.getRootViewModel()).then((root) => resolve(root[key]));
|
|
3701
|
+
});
|
|
3702
|
+
}
|
|
3703
|
+
async getRoot() {
|
|
3704
|
+
const values = this.valueList;
|
|
3705
|
+
const node = this.model.getRootNode();
|
|
3706
|
+
if (node) {
|
|
3707
|
+
let value;
|
|
3708
|
+
const alias = node.alias;
|
|
3709
|
+
if (!(typeof alias == "string")) {
|
|
3710
|
+
throw Error(`Alias missing for node ${node.nodeid}`);
|
|
3711
|
+
}
|
|
3712
|
+
await values.setDefault(alias, []);
|
|
3713
|
+
const nodeValues = await values.get(alias);
|
|
3714
|
+
if (nodeValues.length > 1) {
|
|
3715
|
+
throw Error("Cannot have multiple root tiles");
|
|
3716
|
+
} else if (nodeValues.length == 1) {
|
|
3717
|
+
value = nodeValues[0];
|
|
3718
|
+
} else {
|
|
3719
|
+
value = makePseudoCls(this.model, alias, false, null, this.wkri);
|
|
3720
|
+
values.set(alias, [value]);
|
|
3721
|
+
}
|
|
3722
|
+
return value;
|
|
3723
|
+
}
|
|
3724
|
+
}
|
|
3725
|
+
setOrmAttribute(key, value) {
|
|
3726
|
+
return this.getRootViewModel().then((root) => {
|
|
3727
|
+
if (root) {
|
|
3728
|
+
root[key] = value;
|
|
3729
|
+
} else {
|
|
3730
|
+
throw Error(`Tried to set ${key} on ${self}, which has no root`);
|
|
3731
|
+
}
|
|
3732
|
+
});
|
|
3733
|
+
}
|
|
3734
|
+
async ensureNodegroup(allValues, allNodegroups, nodegroupId, nodeObjs, nodegroupObjs, edges, addIfMissing, tiles, doImpliedNodegroups = true) {
|
|
3735
|
+
const impliedNodegroups = /* @__PURE__ */ new Set();
|
|
3736
|
+
const sentinel = allNodegroups.get(nodegroupId);
|
|
3737
|
+
let newValues = /* @__PURE__ */ new Map();
|
|
3738
|
+
if (sentinel === false || addIfMissing && sentinel === void 0) {
|
|
3739
|
+
[...nodeObjs.values()].filter((node) => {
|
|
3740
|
+
return node.nodegroup_id === nodegroupId;
|
|
3741
|
+
}).forEach((node) => allValues.delete(node.alias || ""));
|
|
3742
|
+
let nodegroupTiles;
|
|
3743
|
+
if (tiles === null) {
|
|
3744
|
+
nodegroupTiles = [];
|
|
3745
|
+
console.error("Tiles must be provided and cannot be lazy-loaded yet");
|
|
3746
|
+
} else {
|
|
3747
|
+
nodegroupTiles = tiles.filter(
|
|
3748
|
+
(tile) => tile.nodegroup_id == nodegroupId && this.model.isNodegroupPermitted(nodegroupId, tile)
|
|
3749
|
+
);
|
|
3750
|
+
if (nodegroupTiles.length == 0 && addIfMissing) {
|
|
3751
|
+
nodegroupTiles = [null];
|
|
3752
|
+
}
|
|
3753
|
+
const rgValues = await this.valuesFromResourceNodegroup(
|
|
3754
|
+
allValues,
|
|
3755
|
+
nodegroupTiles,
|
|
3756
|
+
nodegroupId,
|
|
3757
|
+
nodeObjs,
|
|
3758
|
+
edges
|
|
3759
|
+
);
|
|
3760
|
+
newValues = rgValues[0];
|
|
3761
|
+
const newImpliedNodegroups = rgValues[1];
|
|
3762
|
+
[...newValues.entries()].forEach((entry) => {
|
|
3763
|
+
if (entry[1] !== void 0) {
|
|
3764
|
+
allValues.set(entry[0], entry[1]);
|
|
3765
|
+
}
|
|
3766
|
+
});
|
|
3767
|
+
[...newImpliedNodegroups].forEach((v) => {
|
|
3768
|
+
impliedNodegroups.add(v);
|
|
3769
|
+
});
|
|
3770
|
+
allNodegroups.set(nodegroupId, true);
|
|
3771
|
+
}
|
|
3772
|
+
}
|
|
3773
|
+
if (doImpliedNodegroups) {
|
|
3774
|
+
for (const nodegroupId2 of [...impliedNodegroups]) {
|
|
3775
|
+
const [impliedValues] = await this.ensureNodegroup(
|
|
3776
|
+
allValues,
|
|
3777
|
+
allNodegroups,
|
|
3778
|
+
nodegroupId2,
|
|
3779
|
+
nodeObjs,
|
|
3780
|
+
nodegroupObjs,
|
|
3781
|
+
edges,
|
|
3782
|
+
true,
|
|
3783
|
+
tiles,
|
|
3784
|
+
// RMV different from Python
|
|
3785
|
+
true
|
|
3786
|
+
);
|
|
3787
|
+
for (const [key, value] of impliedValues) {
|
|
3788
|
+
newValues.set(key, value);
|
|
3789
|
+
}
|
|
3790
|
+
}
|
|
3791
|
+
impliedNodegroups.clear();
|
|
3792
|
+
}
|
|
3793
|
+
return [newValues, impliedNodegroups];
|
|
3794
|
+
}
|
|
3795
|
+
async populate(lazy) {
|
|
3796
|
+
const nodeObjs = this.model.getNodeObjects();
|
|
3797
|
+
const nodegroupObjs = this.model.getNodegroupObjects();
|
|
3798
|
+
const edges = this.model.getEdges();
|
|
3799
|
+
const allValues = /* @__PURE__ */ new Map();
|
|
3800
|
+
const allNodegroups = new Map([...nodegroupObjs.keys()].map((id) => {
|
|
3801
|
+
return [id || "", false];
|
|
3802
|
+
}));
|
|
3803
|
+
const rootNode = this.model.getRootNode();
|
|
3804
|
+
if (rootNode.alias === null) {
|
|
3805
|
+
throw Error("Cannot populate a model with no proper root node");
|
|
3806
|
+
}
|
|
3807
|
+
allValues.set(rootNode.alias, false);
|
|
3808
|
+
let tiles = null;
|
|
3809
|
+
if (!lazy && this.resource) {
|
|
3810
|
+
tiles = this.resource.tiles;
|
|
3811
|
+
let impliedNodegroups = /* @__PURE__ */ new Set();
|
|
3812
|
+
for (const [ng] of nodegroupObjs) {
|
|
3813
|
+
const [_, newImpliedNodegroups] = await this.ensureNodegroup(
|
|
3814
|
+
allValues,
|
|
3815
|
+
allNodegroups,
|
|
3816
|
+
ng,
|
|
3817
|
+
nodeObjs,
|
|
3818
|
+
nodegroupObjs,
|
|
3819
|
+
edges,
|
|
3820
|
+
true,
|
|
3821
|
+
// RMV: check vs python
|
|
3822
|
+
tiles,
|
|
3823
|
+
false
|
|
3824
|
+
);
|
|
3825
|
+
for (const impliedNodegroup of [...newImpliedNodegroups]) {
|
|
3826
|
+
impliedNodegroups.add(impliedNodegroup);
|
|
3827
|
+
}
|
|
3828
|
+
impliedNodegroups.delete(ng);
|
|
3829
|
+
}
|
|
3830
|
+
while (impliedNodegroups.size) {
|
|
3831
|
+
const newImpliedNodegroups = /* @__PURE__ */ new Set();
|
|
3832
|
+
for (const nodegroupId of [...impliedNodegroups]) {
|
|
3833
|
+
const currentValue = allNodegroups.get(nodegroupId);
|
|
3834
|
+
if (currentValue === false || currentValue === void 0) {
|
|
3835
|
+
const [_, newImpliedNodegroups2] = await this.ensureNodegroup(
|
|
3836
|
+
allValues,
|
|
3837
|
+
allNodegroups,
|
|
3838
|
+
nodegroupId,
|
|
3839
|
+
nodeObjs,
|
|
3840
|
+
nodegroupObjs,
|
|
3841
|
+
edges,
|
|
3842
|
+
true,
|
|
3843
|
+
tiles,
|
|
3844
|
+
// RMV different from Python
|
|
3845
|
+
true
|
|
3846
|
+
);
|
|
3847
|
+
for (const impliedNodegroup of [...newImpliedNodegroups2]) {
|
|
3848
|
+
newImpliedNodegroups2.add(impliedNodegroup);
|
|
3849
|
+
}
|
|
3850
|
+
}
|
|
3851
|
+
}
|
|
3852
|
+
impliedNodegroups = newImpliedNodegroups;
|
|
3853
|
+
}
|
|
3854
|
+
} else if (this.resource) {
|
|
3855
|
+
this.model.stripTiles(this.resource);
|
|
3856
|
+
}
|
|
3857
|
+
this.valueList = new ValueList(
|
|
3858
|
+
allValues,
|
|
3859
|
+
allNodegroups,
|
|
3860
|
+
this,
|
|
3861
|
+
this.resource ? this.resource.tiles : null
|
|
3862
|
+
);
|
|
3863
|
+
}
|
|
3864
|
+
async getValueCache(build = true, getMeta = void 0) {
|
|
3865
|
+
if (build) {
|
|
3866
|
+
this.cache = await this.buildValueCache(getMeta);
|
|
3867
|
+
}
|
|
3868
|
+
return this.cache;
|
|
3869
|
+
}
|
|
3870
|
+
async buildValueCache(getMeta) {
|
|
3871
|
+
const cacheByTile = {};
|
|
3872
|
+
for (let pseudos of this.valueList.values.values()) {
|
|
3873
|
+
pseudos = await pseudos;
|
|
3874
|
+
if (pseudos) {
|
|
3875
|
+
await Promise.all(pseudos.map(async (pseudo) => {
|
|
3876
|
+
const value = await pseudo.getValue();
|
|
3877
|
+
if (pseudo.tile && value && !Array.isArray(pseudo)) {
|
|
3878
|
+
const cacheJson = await value.__forJsonCache(getMeta);
|
|
3879
|
+
if (cacheJson) {
|
|
3880
|
+
const tileId = pseudo.tile.ensureId();
|
|
3881
|
+
const nodeId = pseudo.node.nodeid;
|
|
3882
|
+
if (!(tileId in cacheByTile)) {
|
|
3883
|
+
cacheByTile[tileId] = {};
|
|
3884
|
+
}
|
|
3885
|
+
if (!(nodeId in cacheByTile[tileId])) {
|
|
3886
|
+
cacheByTile[tileId][nodeId] = {};
|
|
3887
|
+
}
|
|
3888
|
+
cacheByTile[tileId][nodeId] = cacheJson;
|
|
3889
|
+
}
|
|
3890
|
+
}
|
|
3891
|
+
}));
|
|
3892
|
+
}
|
|
3893
|
+
}
|
|
3894
|
+
return cacheByTile;
|
|
3895
|
+
}
|
|
3896
|
+
async valuesFromResourceNodegroup(existingValues, nodegroupTiles, nodegroupId, nodeObjs, edges) {
|
|
3897
|
+
const allValues = /* @__PURE__ */ new Map();
|
|
3898
|
+
const impliedNodegroups = /* @__PURE__ */ new Set();
|
|
3899
|
+
const impliedNodes = /* @__PURE__ */ new Map();
|
|
3900
|
+
const nodesUnseen = new Set(
|
|
3901
|
+
[...nodeObjs.values()].filter((node) => node.nodegroup_id == nodegroupId).map((node) => node.alias)
|
|
3902
|
+
);
|
|
3903
|
+
const tileNodesSeen = /* @__PURE__ */ new Set();
|
|
3904
|
+
const _addPseudo = async (node, tile) => {
|
|
3905
|
+
const key = node.alias || "";
|
|
3906
|
+
nodesUnseen.delete(node.alias);
|
|
3907
|
+
const tileid = tile && tile.tileid;
|
|
3908
|
+
if (tileid) {
|
|
3909
|
+
tileNodesSeen.add([node.nodeid, tileid]);
|
|
3910
|
+
}
|
|
3911
|
+
let existing = existingValues.get(key);
|
|
3912
|
+
if (existing instanceof Promise) {
|
|
3913
|
+
existing = await existing;
|
|
3914
|
+
}
|
|
3915
|
+
if (existing !== false && existing !== void 0) {
|
|
3916
|
+
allValues.set(key, existing);
|
|
3917
|
+
}
|
|
3918
|
+
if (!allValues.has(key)) {
|
|
3919
|
+
allValues.set(key, []);
|
|
3920
|
+
}
|
|
3921
|
+
const pseudoNode = makePseudoCls(this.model, key, false, tile, this.wkri);
|
|
3922
|
+
for (const [domain, ranges] of edges) {
|
|
3923
|
+
if (ranges.includes(node.nodeid)) {
|
|
3924
|
+
const domainNode = nodeObjs.get(domain);
|
|
3925
|
+
if (!domainNode) {
|
|
3926
|
+
throw Error("Edge error in graph");
|
|
3927
|
+
}
|
|
3928
|
+
const toAdd = domainNode.nodegroup_id ? domainNode.nodegroup_id : "";
|
|
3929
|
+
if (toAdd && toAdd !== nodegroupId) {
|
|
3930
|
+
impliedNodegroups.add(toAdd);
|
|
3931
|
+
}
|
|
3932
|
+
if (domainNode.nodegroup_id && tile && domainNode.nodegroup_id === tile.nodegroup_id && domainNode.nodegroup_id !== domainNode.nodeid && tileid && !impliedNodes.has(domainNode.nodeid + tileid)) {
|
|
3933
|
+
impliedNodes.set(domainNode.nodeid + tileid, [domainNode, tile]);
|
|
3934
|
+
}
|
|
3935
|
+
break;
|
|
3936
|
+
}
|
|
3937
|
+
}
|
|
3938
|
+
if (Array.isArray(pseudoNode)) {
|
|
3939
|
+
const value = allValues.get(key);
|
|
3940
|
+
if (value !== void 0 && value !== false) {
|
|
3941
|
+
for (const pseudoList of allValues.get(key)) {
|
|
3942
|
+
if (!(pseudoList instanceof PseudoList) || !(pseudoNode instanceof PseudoList)) {
|
|
3943
|
+
throw Error(`Should be all lists not ${typeof pseudoList} and ${typeof pseudoNode}`);
|
|
3944
|
+
}
|
|
3945
|
+
if (pseudoList.parentNode == pseudoNode.parentNode) {
|
|
3946
|
+
for (const ps of pseudoNode) {
|
|
3947
|
+
pseudoList.push(ps);
|
|
3948
|
+
}
|
|
3949
|
+
return;
|
|
3950
|
+
}
|
|
3951
|
+
}
|
|
3952
|
+
}
|
|
3953
|
+
}
|
|
3954
|
+
allValues.get(key).push(pseudoNode);
|
|
3955
|
+
};
|
|
3956
|
+
for (const tile of nodegroupTiles) {
|
|
3957
|
+
const parentNode = nodeObjs.get(nodegroupId);
|
|
3958
|
+
if (parentNode === void 0) {
|
|
3959
|
+
continue;
|
|
3960
|
+
}
|
|
3961
|
+
if (!parentNode.nodegroup_id || parentNode.nodegroup_id == nodegroupId) {
|
|
3962
|
+
await _addPseudo(parentNode, tile);
|
|
3963
|
+
}
|
|
3964
|
+
if (tile) {
|
|
3965
|
+
const tileNodes = /* @__PURE__ */ new Map();
|
|
3966
|
+
for (const [key, value] of [...tile.data.entries()]) {
|
|
3967
|
+
tileNodes.set(key, value);
|
|
3968
|
+
}
|
|
3969
|
+
[...nodeObjs.values()].filter((node) => {
|
|
3970
|
+
return node.nodegroup_id === nodegroupId && !tileNodes.get(node.nodeid) && node.datatype === "semantic";
|
|
3971
|
+
}).forEach((node) => tileNodes.set(node.nodeid, {}));
|
|
3972
|
+
if (!tileNodes.has(tile.nodegroup_id)) {
|
|
3973
|
+
tileNodes.set(tile.nodegroup_id, {});
|
|
3974
|
+
}
|
|
3975
|
+
for (const [nodeid, nodeValue] of [...tileNodes.entries()]) {
|
|
3976
|
+
if (nodeid == nodegroupId) {
|
|
3977
|
+
continue;
|
|
3978
|
+
}
|
|
3979
|
+
const node = nodeObjs.get(nodeid);
|
|
3980
|
+
if (!node) {
|
|
3981
|
+
throw Error(`Unknown node in nodegroup: ${nodeid} in ${nodegroupId}`);
|
|
3982
|
+
}
|
|
3983
|
+
if (nodeValue !== null) {
|
|
3984
|
+
await _addPseudo(node, tile);
|
|
3985
|
+
}
|
|
3986
|
+
}
|
|
3987
|
+
}
|
|
3988
|
+
}
|
|
3989
|
+
while (impliedNodes.size > 0) {
|
|
3990
|
+
const value = impliedNodes.entries().next().value;
|
|
3991
|
+
if (value) {
|
|
3992
|
+
const [node, tile] = value[1];
|
|
3993
|
+
if (tile.tileid && !tileNodesSeen.has([node.nodeid, tile.tileid])) {
|
|
3994
|
+
await _addPseudo(node, tile);
|
|
3995
|
+
}
|
|
3996
|
+
impliedNodes.delete(value[0]);
|
|
3997
|
+
}
|
|
3998
|
+
}
|
|
3999
|
+
[...nodesUnseen.keys()].forEach((nodeUnseen) => {
|
|
4000
|
+
if (nodeUnseen) {
|
|
4001
|
+
allValues.set(nodeUnseen, void 0);
|
|
4002
|
+
}
|
|
4003
|
+
});
|
|
4004
|
+
return [allValues, impliedNodegroups];
|
|
4005
|
+
}
|
|
4006
|
+
}
|
|
4007
|
+
class GraphMutator {
|
|
4008
|
+
constructor(baseGraph, options = {}) {
|
|
4009
|
+
__publicField(this, "baseGraph");
|
|
4010
|
+
__publicField(this, "mutations");
|
|
4011
|
+
__publicField(this, "autocreateCard");
|
|
4012
|
+
this.baseGraph = baseGraph;
|
|
4013
|
+
this.mutations = [];
|
|
4014
|
+
this.autocreateCard = options.autocreateCard === void 0 || options.autocreateCard;
|
|
4015
|
+
}
|
|
4016
|
+
_generateUuidv5(key) {
|
|
4017
|
+
return generateUuidv5(["graph", this.baseGraph.graphid], key);
|
|
4018
|
+
}
|
|
4019
|
+
_generateEdge(fromNode, toNode, ontologyProperty, name, description) {
|
|
4020
|
+
const edgeId = this._generateUuidv5(`node-${fromNode}-${toNode}`);
|
|
4021
|
+
return new StaticEdge({
|
|
4022
|
+
description: description || null,
|
|
4023
|
+
domainnode_id: fromNode,
|
|
4024
|
+
edgeid: edgeId,
|
|
4025
|
+
graph_id: this.baseGraph.graphid,
|
|
4026
|
+
name: name || null,
|
|
4027
|
+
rangenode_id: toNode,
|
|
4028
|
+
ontologyproperty: ontologyProperty
|
|
4029
|
+
});
|
|
4030
|
+
}
|
|
4031
|
+
addSemanticNode(parentAlias, alias, name, cardinality, ontologyClass, parentProperty, description, options = {}, config) {
|
|
4032
|
+
return this._addGenericNode(
|
|
4033
|
+
parentAlias,
|
|
4034
|
+
alias,
|
|
4035
|
+
name,
|
|
4036
|
+
cardinality,
|
|
4037
|
+
"semantic",
|
|
4038
|
+
ontologyClass,
|
|
4039
|
+
parentProperty,
|
|
4040
|
+
description,
|
|
4041
|
+
options,
|
|
4042
|
+
config
|
|
4043
|
+
);
|
|
4044
|
+
}
|
|
4045
|
+
addConceptNode(parentAlias, alias, name, collection, cardinality, ontologyClass, parentProperty, description, options = {}, config) {
|
|
4046
|
+
config = config || {};
|
|
4047
|
+
if (collection == null ? void 0 : collection.id) {
|
|
4048
|
+
config["rdmCollection"] = collection.id;
|
|
4049
|
+
}
|
|
4050
|
+
return this._addGenericNode(
|
|
4051
|
+
parentAlias,
|
|
4052
|
+
alias,
|
|
4053
|
+
name,
|
|
4054
|
+
cardinality,
|
|
4055
|
+
options.is_list ? "concept-list" : "concept",
|
|
4056
|
+
ontologyClass,
|
|
4057
|
+
parentProperty,
|
|
4058
|
+
description,
|
|
4059
|
+
options,
|
|
4060
|
+
config
|
|
4061
|
+
);
|
|
4062
|
+
}
|
|
4063
|
+
addCard(nodegroup, name, component, options = {}, config) {
|
|
4064
|
+
const nodegroupId = typeof nodegroup === "string" ? nodegroup : nodegroup.nodegroupid;
|
|
4065
|
+
const cardName = name instanceof StaticTranslatableString ? name : new StaticTranslatableString(name);
|
|
4066
|
+
const cardComponent = component || DEFAULT_CARD_COMPONENT;
|
|
4067
|
+
const helptext = (options == null ? void 0 : options.helptext) && (options.helptext instanceof StaticTranslatableString ? options.helptext : new StaticTranslatableString(options.helptext));
|
|
4068
|
+
const helptitle = (options == null ? void 0 : options.helptitle) && (options.helptitle instanceof StaticTranslatableString ? options.helptitle : new StaticTranslatableString(options.helptitle));
|
|
4069
|
+
const instructions = (options == null ? void 0 : options.instructions) && (options.instructions instanceof StaticTranslatableString ? options.instructions : new StaticTranslatableString(options.instructions));
|
|
4070
|
+
this.mutations.push((graph) => {
|
|
4071
|
+
graph.cards = graph.cards || [];
|
|
4072
|
+
if (graph.cards.filter((card2) => card2.nodegroup_id === nodegroup).length > 0) {
|
|
4073
|
+
throw Error(`This nodegroup, ${nodegroupId}, already has a card`);
|
|
4074
|
+
}
|
|
4075
|
+
const cardId = this._generateUuidv5(`card-ng-${nodegroupId}`);
|
|
4076
|
+
const card = new StaticCard({
|
|
4077
|
+
active: options.active === void 0 ? true : options.active,
|
|
4078
|
+
cardid: cardId,
|
|
4079
|
+
component_id: cardComponent.id,
|
|
4080
|
+
config: config || null,
|
|
4081
|
+
constraints: options.constraints || [],
|
|
4082
|
+
cssclass: options.cssclass || null,
|
|
4083
|
+
description: options.description || null,
|
|
4084
|
+
graph_id: graph.graphid,
|
|
4085
|
+
helpenabled: !!(options.helpenabled || options.helpenabled === void 0 && (helptext || helptitle)),
|
|
4086
|
+
helptext: helptext || new StaticTranslatableString(""),
|
|
4087
|
+
helptitle: helptitle || new StaticTranslatableString(""),
|
|
4088
|
+
instructions: instructions || new StaticTranslatableString(""),
|
|
4089
|
+
is_editable: options.is_editable === void 0 ? true : options.is_editable,
|
|
4090
|
+
name: cardName,
|
|
4091
|
+
nodegroup_id: nodegroupId,
|
|
4092
|
+
sortorder: options.sortorder || null,
|
|
4093
|
+
visible: options.visible === void 0 ? true : options.visible
|
|
4094
|
+
});
|
|
4095
|
+
graph.cards.push(card);
|
|
4096
|
+
return graph;
|
|
4097
|
+
});
|
|
4098
|
+
}
|
|
4099
|
+
addStringNode(parentAlias, alias, name, cardinality, ontologyClass, parentProperty, description, options = {}, config) {
|
|
4100
|
+
return this._addGenericNode(
|
|
4101
|
+
parentAlias,
|
|
4102
|
+
alias,
|
|
4103
|
+
name,
|
|
4104
|
+
cardinality,
|
|
4105
|
+
"string",
|
|
4106
|
+
ontologyClass,
|
|
4107
|
+
parentProperty,
|
|
4108
|
+
description,
|
|
4109
|
+
options,
|
|
4110
|
+
config
|
|
4111
|
+
);
|
|
4112
|
+
}
|
|
4113
|
+
_addNodegroup(parentAlias, nodegroupId, cardinality, name) {
|
|
4114
|
+
this.mutations.push((graph) => {
|
|
4115
|
+
const prnt = parentAlias === null ? graph.root : graph.nodes.find((node) => node.alias === parentAlias);
|
|
4116
|
+
if (!prnt) {
|
|
4117
|
+
throw Error(`Missing parent for nodegroup: ${parentAlias}`);
|
|
4118
|
+
}
|
|
4119
|
+
const nodegroup = new StaticNodegroup({
|
|
4120
|
+
cardinality,
|
|
4121
|
+
legacygroupid: null,
|
|
4122
|
+
nodegroupid: nodegroupId,
|
|
4123
|
+
parentnodegroup_id: prnt.nodegroup_id
|
|
4124
|
+
});
|
|
4125
|
+
graph.nodegroups.push(nodegroup);
|
|
4126
|
+
return graph;
|
|
4127
|
+
});
|
|
4128
|
+
if (this.autocreateCard) {
|
|
4129
|
+
this.addCard(nodegroupId, name || "(unnamed)");
|
|
4130
|
+
}
|
|
4131
|
+
return this;
|
|
4132
|
+
}
|
|
4133
|
+
_addGenericNode(parentAlias, alias, name, cardinality, datatype, ontologyClass, parentProperty, description, options = {}, config) {
|
|
4134
|
+
const nodeId = this._generateUuidv5(`node-${alias}`);
|
|
4135
|
+
const node = {
|
|
4136
|
+
alias,
|
|
4137
|
+
config: config || {},
|
|
4138
|
+
datatype,
|
|
4139
|
+
description: description || null,
|
|
4140
|
+
exportable: options.exportable || false,
|
|
4141
|
+
fieldname: options.fieldname || null,
|
|
4142
|
+
graph_id: this.baseGraph.graphid,
|
|
4143
|
+
hascustomalias: options.hascustomalias || false,
|
|
4144
|
+
is_collector: options.is_collector || false,
|
|
4145
|
+
isrequired: options.isrequired || false,
|
|
4146
|
+
issearchable: options.issearchable || true,
|
|
4147
|
+
// This is the default in Arches I believe
|
|
4148
|
+
istopnode: options.istopnode || false,
|
|
4149
|
+
name,
|
|
4150
|
+
nodegroup_id: "",
|
|
4151
|
+
nodeid: nodeId,
|
|
4152
|
+
parentproperty: parentProperty,
|
|
4153
|
+
sortorder: options.sortorder || 0,
|
|
4154
|
+
ontologyclass: ontologyClass,
|
|
4155
|
+
sourcebranchpublication_id: null
|
|
4156
|
+
};
|
|
4157
|
+
if (cardinality === "n" || parentAlias === null) {
|
|
4158
|
+
node.nodegroup_id = nodeId;
|
|
4159
|
+
this._addNodegroup(parentAlias, node.nodegroup_id, cardinality, new StaticTranslatableString(name));
|
|
4160
|
+
}
|
|
4161
|
+
this.mutations.push((graph) => {
|
|
4162
|
+
const prnt = parentAlias === null ? graph.root : graph.nodes.find((node2) => node2.alias === parentAlias);
|
|
4163
|
+
if (!prnt) {
|
|
4164
|
+
throw Error(`Parent node does not exist: ${parentAlias}`);
|
|
4165
|
+
}
|
|
4166
|
+
node.nodegroup_id = node.nodegroup_id !== "" ? node.nodegroup_id : prnt.nodegroup_id || "";
|
|
4167
|
+
const newNode = new StaticNode(node);
|
|
4168
|
+
graph.nodes.push(newNode);
|
|
4169
|
+
const edge = this._generateEdge(prnt.nodeid, nodeId, parentProperty);
|
|
4170
|
+
graph.edges.push(edge);
|
|
4171
|
+
return graph;
|
|
4172
|
+
});
|
|
4173
|
+
if (this.autocreateCard && datatype !== "semantic") {
|
|
4174
|
+
const widget = getDefaultWidgetForNode(node);
|
|
4175
|
+
const config2 = widget.getDefaultConfig();
|
|
4176
|
+
config2.label = name;
|
|
4177
|
+
this.addWidgetToCard(
|
|
4178
|
+
nodeId,
|
|
4179
|
+
widget,
|
|
4180
|
+
name,
|
|
4181
|
+
config2,
|
|
4182
|
+
{
|
|
4183
|
+
sortorder: node.sortorder,
|
|
4184
|
+
silentSkip: true
|
|
4185
|
+
// if, for some reason, the card is not present (i.e. was removed), we should not worry
|
|
4186
|
+
}
|
|
4187
|
+
);
|
|
4188
|
+
}
|
|
4189
|
+
return this;
|
|
4190
|
+
}
|
|
4191
|
+
addWidgetToCard(nodeId, widget, name, config, options = {}) {
|
|
4192
|
+
this.mutations.push((graph) => {
|
|
4193
|
+
var _a2;
|
|
4194
|
+
const node = graph.nodes.find((node2) => node2.nodeid === nodeId);
|
|
4195
|
+
if (!node) {
|
|
4196
|
+
throw Error(`Tried to add card to graph ${graph.graphid} for node ${nodeId} but it was not found.`);
|
|
4197
|
+
}
|
|
4198
|
+
const card = (_a2 = graph.cards) == null ? void 0 : _a2.find((card2) => card2.nodegroup_id === node.nodegroup_id);
|
|
4199
|
+
if (card) {
|
|
4200
|
+
const cardXNodeXWidgetId = this._generateUuidv5(`cxnxw-${nodeId}-${widget.id}`);
|
|
4201
|
+
const cardXNodeXWidget = new StaticCardsXNodesXWidgets({
|
|
4202
|
+
card_id: card.cardid,
|
|
4203
|
+
config,
|
|
4204
|
+
id: cardXNodeXWidgetId,
|
|
4205
|
+
label: new StaticTranslatableString(name),
|
|
4206
|
+
node_id: nodeId,
|
|
4207
|
+
sortorder: options.sortorder || 0,
|
|
4208
|
+
visible: options.visible === void 0 || options.visible,
|
|
4209
|
+
widget_id: widget.id
|
|
4210
|
+
});
|
|
4211
|
+
graph.cards_x_nodes_x_widgets = graph.cards_x_nodes_x_widgets || [];
|
|
4212
|
+
graph.cards_x_nodes_x_widgets.push(cardXNodeXWidget);
|
|
4213
|
+
} else if (!options.silentSkip) {
|
|
4214
|
+
throw Error(`Failed adding widget for ${nodeId} to card for ${node.nodegroup_id} on graph ${graph.graphid}, as no card for this nodegroup (yet?)`);
|
|
4215
|
+
}
|
|
4216
|
+
return graph;
|
|
4217
|
+
});
|
|
4218
|
+
return this;
|
|
4219
|
+
}
|
|
4220
|
+
apply() {
|
|
4221
|
+
if (!this.baseGraph.copy) {
|
|
4222
|
+
throw Error("Attempt to build a mutator without a proper StaticGraph base graph");
|
|
4223
|
+
}
|
|
4224
|
+
const graph = this.baseGraph.copy();
|
|
4225
|
+
return this.mutations.reduce((graph2, mutation) => mutation(graph2), graph);
|
|
4226
|
+
}
|
|
4227
|
+
}
|
|
4228
|
+
class ResourceModelWrapper {
|
|
4229
|
+
constructor(wkrm, graph, viewModelClass) {
|
|
4230
|
+
__publicField(this, "wkrm");
|
|
4231
|
+
__publicField(this, "graph");
|
|
4232
|
+
__publicField(this, "viewModelClass");
|
|
4233
|
+
__publicField(this, "permittedNodegroups");
|
|
4234
|
+
__publicField(this, "edges");
|
|
4235
|
+
__publicField(this, "nodes");
|
|
4236
|
+
__publicField(this, "nodegroups");
|
|
4237
|
+
__publicField(this, "nodesByAlias");
|
|
4238
|
+
this.wkrm = wkrm;
|
|
4239
|
+
this.graph = graph;
|
|
4240
|
+
this.viewModelClass = viewModelClass;
|
|
4241
|
+
}
|
|
4242
|
+
// TODO: Switch to getBranches
|
|
4243
|
+
getBranchPublicationIds(accessible) {
|
|
4244
|
+
const accessibleOnly = accessible || false;
|
|
4245
|
+
const nodes = [...this.graph.nodes.values()];
|
|
4246
|
+
return [...nodes.reduce(
|
|
4247
|
+
(acc, node) => {
|
|
4248
|
+
if (node.sourcebranchpublication_id) {
|
|
4249
|
+
if (accessibleOnly) {
|
|
4250
|
+
if (this.isNodegroupPermitted(node.nodegroup_id || "", null)) {
|
|
4251
|
+
acc.add(node.sourcebranchpublication_id);
|
|
4252
|
+
}
|
|
4253
|
+
} else {
|
|
4254
|
+
acc.add(node.sourcebranchpublication_id);
|
|
4255
|
+
}
|
|
4256
|
+
}
|
|
4257
|
+
return acc;
|
|
4258
|
+
},
|
|
4259
|
+
/* @__PURE__ */ new Set()
|
|
4260
|
+
)];
|
|
4261
|
+
}
|
|
4262
|
+
getCollections(accessible) {
|
|
4263
|
+
const accessibleOnly = accessible || false;
|
|
4264
|
+
const nodes = [...this.graph.nodes.values()];
|
|
4265
|
+
return [...nodes.reduce(
|
|
4266
|
+
(acc, node) => {
|
|
4267
|
+
var _a2;
|
|
4268
|
+
if (["concept", "concept-list"].includes(node.datatype) && ((_a2 = node.config) == null ? void 0 : _a2.rdmCollection)) {
|
|
4269
|
+
if (accessibleOnly) {
|
|
4270
|
+
if (this.isNodegroupPermitted(node.nodegroup_id || "", null)) {
|
|
4271
|
+
acc.add(node.config.rdmCollection);
|
|
4272
|
+
}
|
|
4273
|
+
} else {
|
|
4274
|
+
acc.add(node.config.rdmCollection);
|
|
4275
|
+
}
|
|
4276
|
+
}
|
|
4277
|
+
return acc;
|
|
4278
|
+
},
|
|
4279
|
+
/* @__PURE__ */ new Set()
|
|
4280
|
+
)];
|
|
4281
|
+
}
|
|
4282
|
+
pruneGraph(keepFunctions) {
|
|
4283
|
+
const allNodegroups = this.getNodegroupObjects();
|
|
4284
|
+
const root = this.graph.root.nodeid;
|
|
4285
|
+
const allowedNodegroups = new Map([...allNodegroups.values()].filter((nodegroup) => {
|
|
4286
|
+
return this.isNodegroupPermitted(nodegroup.nodegroupid || "", null);
|
|
4287
|
+
}).map((nodegroup) => [nodegroup.nodegroupid, nodegroup.nodegroupid === null || nodegroup.nodegroupid === "" || nodegroup.nodegroupid === root]));
|
|
4288
|
+
const backedges = /* @__PURE__ */ new Map();
|
|
4289
|
+
for (const [d, rs] of this.getEdges()) {
|
|
4290
|
+
for (const r of rs) {
|
|
4291
|
+
if (backedges.has(r)) {
|
|
4292
|
+
throw Error(`Graph is malformed, node ${r} has multiple parents, ${backedges.get(r)} and ${d} at least`);
|
|
4293
|
+
}
|
|
4294
|
+
backedges.set(r, d);
|
|
4295
|
+
}
|
|
4296
|
+
}
|
|
4297
|
+
let loops = 0;
|
|
4298
|
+
allowedNodegroups.set(root, true);
|
|
4299
|
+
while (loops < MAX_GRAPH_DEPTH) {
|
|
4300
|
+
const unrooted = [...allowedNodegroups.entries()].filter(([_, rooted]) => !rooted);
|
|
4301
|
+
if (unrooted.length === 0) {
|
|
4302
|
+
break;
|
|
4303
|
+
}
|
|
4304
|
+
for (const [ng] of unrooted) {
|
|
4305
|
+
if (ng === root) {
|
|
4306
|
+
continue;
|
|
4307
|
+
}
|
|
4308
|
+
const next = backedges.get(ng);
|
|
4309
|
+
if (!next) {
|
|
4310
|
+
throw Error(`Graph does not have a parent for ${ng}`);
|
|
4311
|
+
}
|
|
4312
|
+
allowedNodegroups.set(ng, true);
|
|
4313
|
+
if (!allowedNodegroups.has(next)) {
|
|
4314
|
+
allowedNodegroups.set(next, false);
|
|
4315
|
+
}
|
|
4316
|
+
}
|
|
4317
|
+
loops += 1;
|
|
4318
|
+
}
|
|
4319
|
+
if (loops >= MAX_GRAPH_DEPTH) {
|
|
4320
|
+
throw Error("Hit edge traversal limit when pruning, is the graph well-formed without cycles?");
|
|
4321
|
+
}
|
|
4322
|
+
const allowedNodes = new Set([...this.getNodeObjects().values()].filter((node) => {
|
|
4323
|
+
return node.nodegroup_id && allowedNodegroups.get(node.nodegroup_id) || node.nodeid === root;
|
|
4324
|
+
}).map((node) => node.nodeid));
|
|
4325
|
+
this.graph.cards = (this.graph.cards || []).filter((card) => allowedNodegroups.get(card.nodegroup_id));
|
|
4326
|
+
this.graph.cards_x_nodes_x_widgets = (this.graph.cards_x_nodes_x_widgets || []).filter((card) => allowedNodes.has(card.node_id));
|
|
4327
|
+
this.graph.edges = (this.graph.edges || []).filter((edge) => (edge.domainnode_id === root || allowedNodes.has(edge.domainnode_id)) && allowedNodes.has(edge.rangenode_id));
|
|
4328
|
+
this.graph.nodegroups = (this.graph.nodegroups || []).filter((ng) => allowedNodegroups.has(ng.nodegroupid));
|
|
4329
|
+
this.graph.nodes = (this.graph.nodes || []).filter((node) => allowedNodes.has(node.nodeid));
|
|
4330
|
+
if (Array.isArray(keepFunctions) && this.graph.functions_x_graphs) {
|
|
4331
|
+
this.graph.functions_x_graphs = this.graph.functions_x_graphs.filter((fxg) => keepFunctions.includes(fxg.function_id));
|
|
4332
|
+
} else {
|
|
4333
|
+
this.graph.functions_x_graphs = [];
|
|
4334
|
+
}
|
|
4335
|
+
}
|
|
4336
|
+
exportGraph() {
|
|
4337
|
+
const graph = this.graph;
|
|
4338
|
+
return new StaticGraph({
|
|
4339
|
+
author: graph.author,
|
|
4340
|
+
cards: graph.cards,
|
|
4341
|
+
cards_x_nodes_x_widgets: graph.cards_x_nodes_x_widgets,
|
|
4342
|
+
color: graph.color,
|
|
4343
|
+
config: graph.config,
|
|
4344
|
+
deploymentdate: graph.deploymentdate,
|
|
4345
|
+
deploymentfile: graph.deploymentfile,
|
|
4346
|
+
description: graph.description,
|
|
4347
|
+
edges: graph.edges,
|
|
4348
|
+
functions_x_graphs: graph.functions_x_graphs,
|
|
4349
|
+
graphid: graph.graphid,
|
|
4350
|
+
iconclass: graph.iconclass,
|
|
4351
|
+
is_editable: graph.is_editable,
|
|
4352
|
+
isresource: graph.isresource,
|
|
4353
|
+
jsonldcontext: graph.jsonldcontext,
|
|
4354
|
+
name: graph.name,
|
|
4355
|
+
nodegroups: graph.nodegroups,
|
|
4356
|
+
nodes: graph.nodes,
|
|
4357
|
+
ontology_id: graph.ontology_id,
|
|
4358
|
+
publication: graph.publication,
|
|
4359
|
+
relatable_resource_model_ids: graph.relatable_resource_model_ids,
|
|
4360
|
+
resource_2_resource_constraints: graph.resource_2_resource_constraints,
|
|
4361
|
+
root: graph.root,
|
|
4362
|
+
slug: graph.slug,
|
|
4363
|
+
subtitle: graph.subtitle,
|
|
4364
|
+
template_id: graph.template_id,
|
|
4365
|
+
version: graph.version
|
|
4366
|
+
});
|
|
4367
|
+
}
|
|
4368
|
+
async all(params = void 0) {
|
|
4369
|
+
const paramObj = params || { limit: void 0, lazy: void 0 };
|
|
4370
|
+
const promises = [];
|
|
4371
|
+
for await (const resource of this.iterAll(paramObj)) {
|
|
4372
|
+
promises.push(resource);
|
|
4373
|
+
}
|
|
4374
|
+
return Promise.all(promises);
|
|
4375
|
+
}
|
|
4376
|
+
stripTiles(resource) {
|
|
4377
|
+
if (resource.tiles) {
|
|
4378
|
+
const nodes = this.getNodeObjects();
|
|
4379
|
+
resource.tiles = resource.tiles.filter((tile) => {
|
|
4380
|
+
const node = nodes.get(tile.nodegroup_id);
|
|
4381
|
+
if (!node) {
|
|
4382
|
+
throw Error(`Tile ${tile.tileid} has nodegroup ${tile.nodegroup_id} that is not on the model ${this.graph.graphid}`);
|
|
4383
|
+
}
|
|
4384
|
+
return this.isNodegroupPermitted(tile.nodegroup_id || "", tile);
|
|
4385
|
+
});
|
|
4386
|
+
}
|
|
4387
|
+
}
|
|
4388
|
+
async *resourceGenerator(staticResources, lazy = false, pruneTiles = true) {
|
|
4389
|
+
for await (const staticResource of staticResources) {
|
|
4390
|
+
yield this.fromStaticResource(staticResource, lazy, pruneTiles);
|
|
4391
|
+
}
|
|
4392
|
+
}
|
|
4393
|
+
async *iterAll(params) {
|
|
4394
|
+
yield* this.resourceGenerator(staticStore.loadAll(this.wkrm.graphId, params.limit), params.lazy);
|
|
4395
|
+
}
|
|
4396
|
+
async findStatic(id) {
|
|
4397
|
+
return await staticStore.loadOne(id);
|
|
4398
|
+
}
|
|
4399
|
+
async find(id, lazy = true, pruneTiles = true) {
|
|
4400
|
+
const rivm = await this.findStatic(id);
|
|
4401
|
+
return this.fromStaticResource(rivm, lazy, pruneTiles);
|
|
4402
|
+
}
|
|
4403
|
+
setPermittedNodegroups(permissions) {
|
|
4404
|
+
const nodegroups = this.getNodegroupObjects();
|
|
4405
|
+
const nodes = this.getNodeObjectsByAlias();
|
|
4406
|
+
this.permittedNodegroups = new Map([...permissions].map(([key, value]) => {
|
|
4407
|
+
const k = key || "";
|
|
4408
|
+
if (nodegroups.has(k) || k === "") {
|
|
4409
|
+
return [key, value];
|
|
4410
|
+
} else {
|
|
4411
|
+
const node = nodes.get(k);
|
|
4412
|
+
if (node) {
|
|
4413
|
+
return [node.nodeid, value];
|
|
4414
|
+
} else {
|
|
4415
|
+
throw Error(`Could not find ${key} in nodegroups for permissions`);
|
|
4416
|
+
}
|
|
4417
|
+
}
|
|
4418
|
+
}));
|
|
4419
|
+
}
|
|
4420
|
+
// Defaults to visible, which helps reduce the risk of false sense of security
|
|
4421
|
+
// from front-end filtering masking the presence of data transferred to it.
|
|
4422
|
+
getPermittedNodegroups() {
|
|
4423
|
+
if (!this.permittedNodegroups) {
|
|
4424
|
+
const permissions = new Map([...this.getNodegroupObjects()].map(
|
|
4425
|
+
([k, _]) => [k, true]
|
|
4426
|
+
));
|
|
4427
|
+
permissions.set("", true);
|
|
4428
|
+
this.setPermittedNodegroups(permissions);
|
|
4429
|
+
}
|
|
4430
|
+
const permittedNodegroups = this.permittedNodegroups;
|
|
4431
|
+
if (permittedNodegroups === void 0) {
|
|
4432
|
+
throw Error("Could not set permitted nodegroups");
|
|
4433
|
+
}
|
|
4434
|
+
return permittedNodegroups;
|
|
4435
|
+
}
|
|
4436
|
+
isNodegroupPermitted(nodegroupId, tile) {
|
|
4437
|
+
let permitted = this.getPermittedNodegroups().get(nodegroupId);
|
|
4438
|
+
if (permitted && typeof permitted == "function") {
|
|
4439
|
+
const nodes = this.getNodeObjectsByAlias();
|
|
4440
|
+
permitted = permitted(nodegroupId, tile, nodes);
|
|
4441
|
+
}
|
|
4442
|
+
if (!permitted) {
|
|
4443
|
+
return false;
|
|
4444
|
+
}
|
|
4445
|
+
if (permitted === true) {
|
|
4446
|
+
return true;
|
|
4447
|
+
}
|
|
4448
|
+
throw Error(`Ambiguous permission state: ${permitted} for nodegroup ${nodegroupId}`);
|
|
4449
|
+
}
|
|
4450
|
+
makeInstance(id, resource, pruneTiles = true) {
|
|
4451
|
+
if (!this.viewModelClass) {
|
|
4452
|
+
throw Error(`Cannot instantiate without a viewModelClass in ${this.wkrm.modelClassName}`);
|
|
4453
|
+
}
|
|
4454
|
+
const instance = new this.viewModelClass(
|
|
4455
|
+
id,
|
|
4456
|
+
this.viewModelClass.prototype.__,
|
|
4457
|
+
(rivm) => new ResourceInstanceWrapper(rivm, this, resource, pruneTiles),
|
|
4458
|
+
null
|
|
4459
|
+
);
|
|
4460
|
+
return instance;
|
|
4461
|
+
}
|
|
4462
|
+
getChildNodes(nodeId) {
|
|
4463
|
+
const childNodes = /* @__PURE__ */ new Map();
|
|
4464
|
+
const edges = this.getEdges().get(nodeId);
|
|
4465
|
+
if (edges) {
|
|
4466
|
+
for (const [, n] of this.getNodeObjects()) {
|
|
4467
|
+
if (edges.includes(n.nodeid)) {
|
|
4468
|
+
if (n.alias) {
|
|
4469
|
+
childNodes.set(n.alias, n);
|
|
4470
|
+
}
|
|
4471
|
+
}
|
|
4472
|
+
}
|
|
4473
|
+
}
|
|
4474
|
+
return childNodes;
|
|
4475
|
+
}
|
|
4476
|
+
buildNodes() {
|
|
4477
|
+
if (this.nodes || this.nodegroups) {
|
|
4478
|
+
throw Error("Cache should never try and rebuild nodes when non-empty");
|
|
4479
|
+
}
|
|
4480
|
+
this.edges = /* @__PURE__ */ new Map();
|
|
4481
|
+
this.nodes = /* @__PURE__ */ new Map();
|
|
4482
|
+
this.nodegroups = /* @__PURE__ */ new Map();
|
|
4483
|
+
const graph = this.graph ?? graphManager.getGraph(this.wkrm.graphId);
|
|
4484
|
+
if (!graph) {
|
|
4485
|
+
throw Error(`Could not find graph ${this.wkrm.graphId} for resource`);
|
|
4486
|
+
}
|
|
4487
|
+
const nodes = new Map(graph.nodes.map((node) => [node.nodeid, node]));
|
|
4488
|
+
const nodegroups = new Map(
|
|
4489
|
+
graph.nodes.filter((node) => node.nodegroup_id).map((node) => [
|
|
4490
|
+
node.nodegroup_id || "",
|
|
4491
|
+
new StaticNodegroup({
|
|
4492
|
+
cardinality: "n",
|
|
4493
|
+
legacygroupid: null,
|
|
4494
|
+
nodegroupid: node.nodegroup_id || "",
|
|
4495
|
+
parentnodegroup_id: null
|
|
4496
|
+
})
|
|
4497
|
+
])
|
|
4498
|
+
);
|
|
4499
|
+
for (const nodegroup of graph.nodegroups) {
|
|
4500
|
+
nodegroups.set(nodegroup.nodegroupid, nodegroup);
|
|
4501
|
+
}
|
|
4502
|
+
const edgePairs = graph.edges.map((edge) => [
|
|
4503
|
+
edge.domainnode_id,
|
|
4504
|
+
edge.rangenode_id
|
|
4505
|
+
]);
|
|
4506
|
+
const edges = edgePairs.reduce((edges2, dr) => {
|
|
4507
|
+
const range = edges2.get(dr[0]) || [];
|
|
4508
|
+
range.push(dr[1]);
|
|
4509
|
+
edges2.set(dr[0], range);
|
|
4510
|
+
return edges2;
|
|
4511
|
+
}, /* @__PURE__ */ new Map());
|
|
4512
|
+
this.nodes = nodes;
|
|
4513
|
+
this.nodegroups = nodegroups;
|
|
4514
|
+
this.edges = edges;
|
|
4515
|
+
this.nodesByAlias = new Map(
|
|
4516
|
+
[...nodes.values()].map((node) => [node.alias || "", node])
|
|
4517
|
+
);
|
|
4518
|
+
}
|
|
4519
|
+
getNodeObjectsByAlias() {
|
|
4520
|
+
if (!this.nodesByAlias) {
|
|
4521
|
+
this.buildNodes();
|
|
4522
|
+
}
|
|
4523
|
+
if (!this.nodesByAlias) {
|
|
4524
|
+
throw Error("Could not build nodes");
|
|
4525
|
+
}
|
|
4526
|
+
return this.nodesByAlias;
|
|
4527
|
+
}
|
|
4528
|
+
getEdges() {
|
|
4529
|
+
if (!this.edges) {
|
|
4530
|
+
this.buildNodes();
|
|
4531
|
+
}
|
|
4532
|
+
if (!this.edges) {
|
|
4533
|
+
throw Error("Could not build edges");
|
|
4534
|
+
}
|
|
4535
|
+
return this.edges;
|
|
4536
|
+
}
|
|
4537
|
+
getNodeObjects() {
|
|
4538
|
+
if (!this.nodes) {
|
|
4539
|
+
this.buildNodes();
|
|
4540
|
+
}
|
|
4541
|
+
if (!this.nodes) {
|
|
4542
|
+
throw Error("Could not build nodes");
|
|
4543
|
+
}
|
|
4544
|
+
return this.nodes;
|
|
4545
|
+
}
|
|
4546
|
+
getNodegroupObjects() {
|
|
4547
|
+
if (!this.nodegroups) {
|
|
4548
|
+
this.buildNodes();
|
|
4549
|
+
}
|
|
4550
|
+
if (!this.nodegroups) {
|
|
4551
|
+
throw Error("Could not build nodegroups");
|
|
4552
|
+
}
|
|
4553
|
+
return this.nodegroups;
|
|
4554
|
+
}
|
|
4555
|
+
getRootNode() {
|
|
4556
|
+
const nodes = this.getNodeObjects();
|
|
4557
|
+
const rootNode = [...nodes.values()].find((n) => !n.nodegroup_id);
|
|
4558
|
+
if (!rootNode) {
|
|
4559
|
+
throw Error(
|
|
4560
|
+
`COULD NOT FIND ROOT NODE FOR ${this.wkrm.modelClassName}. Does the graph ${this.graph.graphid} still exist?`
|
|
4561
|
+
);
|
|
4562
|
+
}
|
|
4563
|
+
rootNode.alias = rootNode.alias || "";
|
|
4564
|
+
return rootNode;
|
|
4565
|
+
}
|
|
4566
|
+
fromStaticResource(resource, lazy = false, pruneTiles = true) {
|
|
4567
|
+
const wkri = this.makeInstance(
|
|
4568
|
+
resource.resourceinstance.resourceinstanceid,
|
|
4569
|
+
resource,
|
|
4570
|
+
pruneTiles
|
|
4571
|
+
);
|
|
4572
|
+
if (!wkri.$) {
|
|
4573
|
+
throw Error("Could not load resource from static definition");
|
|
4574
|
+
}
|
|
4575
|
+
return wkri.$.populate(lazy).then(() => wkri);
|
|
4576
|
+
}
|
|
4577
|
+
}
|
|
4578
|
+
function makeResourceModelWrapper(viewModelClass, wkrm, graph) {
|
|
4579
|
+
var _a2;
|
|
4580
|
+
let vmc;
|
|
4581
|
+
if (!viewModelClass) {
|
|
4582
|
+
const viewModelClassObj = {
|
|
4583
|
+
[wkrm.modelClassName]: (_a2 = class extends ResourceInstanceViewModel {
|
|
4584
|
+
}, __publicField(_a2, "_"), __publicField(_a2, "__"), _a2)
|
|
4585
|
+
};
|
|
4586
|
+
vmc = viewModelClassObj[wkrm.modelClassName];
|
|
4587
|
+
} else {
|
|
4588
|
+
vmc = viewModelClass;
|
|
4589
|
+
}
|
|
4590
|
+
const wrapper = new ResourceModelWrapper(wkrm, graph, vmc);
|
|
4591
|
+
vmc.prototype.__ = wrapper;
|
|
4592
|
+
return vmc;
|
|
4593
|
+
}
|
|
4594
|
+
class GraphManager {
|
|
4595
|
+
constructor(archesClient2) {
|
|
4596
|
+
__publicField(this, "_initialized", false);
|
|
4597
|
+
__publicField(this, "archesClient");
|
|
4598
|
+
__publicField(this, "graphs");
|
|
4599
|
+
__publicField(this, "wkrms");
|
|
4600
|
+
this.archesClient = archesClient2;
|
|
4601
|
+
this.graphs = /* @__PURE__ */ new Map();
|
|
4602
|
+
this.wkrms = /* @__PURE__ */ new Map();
|
|
4603
|
+
}
|
|
4604
|
+
async initialize(configurationOptions = void 0) {
|
|
4605
|
+
if (this._initialized) {
|
|
4606
|
+
return;
|
|
4607
|
+
}
|
|
4608
|
+
if (configurationOptions === void 0) {
|
|
4609
|
+
configurationOptions = new ConfigurationOptions();
|
|
4610
|
+
}
|
|
4611
|
+
const graphJsons = await this.archesClient.getGraphs();
|
|
4612
|
+
let graphs = Object.entries(graphJsons["models"]);
|
|
4613
|
+
const allowedGraphs = configurationOptions.graphs;
|
|
4614
|
+
if (allowedGraphs !== null) {
|
|
4615
|
+
if (allowedGraphs === false) {
|
|
4616
|
+
throw Error("No current meaning of allowedGraphs === false");
|
|
4617
|
+
} else if (allowedGraphs !== true) {
|
|
4618
|
+
graphs = graphs.filter(
|
|
4619
|
+
([graphId, _]) => allowedGraphs.includes(graphId)
|
|
4620
|
+
);
|
|
4621
|
+
}
|
|
4622
|
+
}
|
|
4623
|
+
graphs.forEach(([graphId, meta]) => {
|
|
4624
|
+
meta.graphid = meta.graphid || graphId;
|
|
4625
|
+
const wkrm = new WKRM(meta);
|
|
4626
|
+
this.wkrms.set(wkrm.modelClassName, wkrm);
|
|
4627
|
+
});
|
|
4628
|
+
if (configurationOptions.eagerLoadGraphs) {
|
|
4629
|
+
await Promise.all(graphs.map(([g]) => this.loadGraph(g)));
|
|
4630
|
+
}
|
|
4631
|
+
this._initialized = true;
|
|
4632
|
+
}
|
|
4633
|
+
async loadGraph(modelClass) {
|
|
4634
|
+
let modelClassName;
|
|
4635
|
+
if (typeof modelClass == "string") {
|
|
4636
|
+
modelClassName = modelClass;
|
|
4637
|
+
} else {
|
|
4638
|
+
modelClassName = modelClass.name;
|
|
4639
|
+
}
|
|
4640
|
+
let wkrm = this.wkrms.get(modelClassName);
|
|
4641
|
+
if (wkrm === void 0) {
|
|
4642
|
+
wkrm = [...this.wkrms.values()].find((wkrm2) => wkrm2.graphId === modelClassName);
|
|
4643
|
+
if (wkrm === void 0) {
|
|
4644
|
+
throw Error(`Only loading graphs for which metadata is present, not ${modelClassName}`);
|
|
4645
|
+
}
|
|
4646
|
+
modelClass = wkrm.modelClassName;
|
|
4647
|
+
}
|
|
4648
|
+
const wrapper = this.graphs.get(wkrm.graphId);
|
|
4649
|
+
if (wrapper !== void 0) {
|
|
4650
|
+
return wrapper;
|
|
4651
|
+
}
|
|
4652
|
+
const bodyJson = await this.archesClient.getGraph(wkrm.meta);
|
|
4653
|
+
if (!bodyJson) {
|
|
4654
|
+
throw Error(`Could not load graph ${wkrm.graphId}`);
|
|
4655
|
+
}
|
|
4656
|
+
const graph = new StaticGraph(bodyJson);
|
|
4657
|
+
let model;
|
|
4658
|
+
if (typeof modelClass == "string") {
|
|
4659
|
+
modelClassName = modelClass;
|
|
4660
|
+
model = makeResourceModelWrapper(void 0, wkrm, graph);
|
|
4661
|
+
} else {
|
|
4662
|
+
modelClassName = modelClass.name;
|
|
4663
|
+
model = makeResourceModelWrapper(modelClass, wkrm, graph);
|
|
4664
|
+
}
|
|
4665
|
+
this.graphs.set(graph.graphid, model.prototype.__);
|
|
4666
|
+
return model.prototype.__;
|
|
4667
|
+
}
|
|
4668
|
+
async get(modelClass) {
|
|
4669
|
+
let modelClassName;
|
|
4670
|
+
if (typeof modelClass == "string") {
|
|
4671
|
+
modelClassName = modelClass;
|
|
4672
|
+
} else {
|
|
4673
|
+
modelClassName = modelClass.name;
|
|
4674
|
+
}
|
|
4675
|
+
this.initialize(void 0);
|
|
4676
|
+
let wkrm = this.wkrms.get(modelClassName);
|
|
4677
|
+
if (wkrm === void 0) {
|
|
4678
|
+
wkrm = [...this.wkrms.values()].find((w) => w.graphId === modelClassName);
|
|
4679
|
+
if (wkrm === void 0) {
|
|
4680
|
+
throw Error(`Cannot find model requested: ${modelClassName}`);
|
|
4681
|
+
}
|
|
4682
|
+
}
|
|
4683
|
+
const wrapper = this.graphs.get(wkrm.graphId);
|
|
4684
|
+
if (wrapper === void 0) {
|
|
4685
|
+
return this.loadGraph(modelClass);
|
|
4686
|
+
}
|
|
4687
|
+
return wrapper;
|
|
4688
|
+
}
|
|
4689
|
+
async getResource(resourceId, lazy = true, pruneTiles = true) {
|
|
4690
|
+
const rivm = await staticStore.loadOne(resourceId);
|
|
4691
|
+
let graph = this.graphs.get(rivm.resourceinstance.graph_id);
|
|
4692
|
+
if (!graph) {
|
|
4693
|
+
graph = await this.loadGraph(rivm.resourceinstance.graph_id);
|
|
4694
|
+
if (!graph) {
|
|
4695
|
+
throw Error(`Graph not found for resource ${resourceId}`);
|
|
4696
|
+
}
|
|
4697
|
+
}
|
|
4698
|
+
return graph.fromStaticResource(rivm, lazy, pruneTiles);
|
|
4699
|
+
}
|
|
4700
|
+
getGraph(graphId) {
|
|
4701
|
+
const wrapper = this.graphs.get(graphId);
|
|
4702
|
+
if (wrapper === void 0) {
|
|
4703
|
+
throw Error(`Cannot find graph requested: ${graphId}`);
|
|
4704
|
+
}
|
|
4705
|
+
return wrapper.graph;
|
|
4706
|
+
}
|
|
4707
|
+
}
|
|
4708
|
+
const graphManager = new GraphManager(archesClient);
|
|
4709
|
+
viewContext.graphManager = graphManager;
|
|
4710
|
+
class Cleanable extends String {
|
|
4711
|
+
constructor() {
|
|
4712
|
+
super(...arguments);
|
|
4713
|
+
__publicField(this, "__clean");
|
|
4714
|
+
}
|
|
4715
|
+
}
|
|
4716
|
+
class BaseRenderer {
|
|
4717
|
+
async render(asset) {
|
|
4718
|
+
if (!asset.$) {
|
|
4719
|
+
throw Error("Cannot render unloaded asset - do you want to await asset.retrieve()?");
|
|
4720
|
+
}
|
|
4721
|
+
const root = await await asset.$.getRootViewModel();
|
|
4722
|
+
return this.renderValue(root, 0);
|
|
4723
|
+
}
|
|
4724
|
+
async renderValue(value, depth) {
|
|
4725
|
+
let newValue;
|
|
4726
|
+
if (value instanceof Promise) {
|
|
4727
|
+
value = await value;
|
|
4728
|
+
}
|
|
4729
|
+
if (value instanceof DomainValueViewModel) {
|
|
4730
|
+
newValue = this.renderDomainValue(value, depth);
|
|
4731
|
+
} else if (value instanceof DateViewModel) {
|
|
4732
|
+
newValue = this.renderDate(value, depth);
|
|
4733
|
+
} else if (value instanceof ConceptValueViewModel) {
|
|
4734
|
+
newValue = this.renderConceptValue(value, depth);
|
|
4735
|
+
} else if (value instanceof ResourceInstanceViewModel) {
|
|
4736
|
+
newValue = this.renderResourceReference(value, depth);
|
|
4737
|
+
} else if (value instanceof SemanticViewModel) {
|
|
4738
|
+
newValue = this.renderSemantic(value, depth);
|
|
4739
|
+
} else if (value instanceof Array) {
|
|
4740
|
+
newValue = this.renderArray(value, depth);
|
|
4741
|
+
} else if (value instanceof StringViewModel || value instanceof NonLocalizedStringViewModel || typeof value === "string") {
|
|
4742
|
+
newValue = this.renderString(value, depth);
|
|
4743
|
+
} else if (value instanceof BooleanViewModel) {
|
|
4744
|
+
newValue = this.renderBoolean(value, depth);
|
|
4745
|
+
} else if (value instanceof NumberViewModel) {
|
|
4746
|
+
newValue = this.renderNumber(value, depth);
|
|
4747
|
+
} else if (value instanceof GeoJSONViewModel) {
|
|
4748
|
+
newValue = this.renderBlock(await value.forJson(), depth);
|
|
4749
|
+
} else if (value instanceof UrlViewModel) {
|
|
4750
|
+
newValue = this.renderUrl(await value, depth);
|
|
4751
|
+
} else if (value instanceof Object) {
|
|
4752
|
+
newValue = this.renderBlock(value, depth);
|
|
4753
|
+
} else {
|
|
4754
|
+
newValue = value;
|
|
4755
|
+
}
|
|
4756
|
+
return newValue;
|
|
4757
|
+
}
|
|
4758
|
+
}
|
|
4759
|
+
class Renderer extends BaseRenderer {
|
|
4760
|
+
async renderDomainValue(value, _depth) {
|
|
4761
|
+
return value;
|
|
4762
|
+
}
|
|
4763
|
+
async renderString(value, _depth) {
|
|
4764
|
+
return `${value}`;
|
|
4765
|
+
}
|
|
4766
|
+
async renderNumber(value, _depth) {
|
|
4767
|
+
return `${value}`;
|
|
4768
|
+
}
|
|
4769
|
+
async renderBoolean(value, _depth) {
|
|
4770
|
+
return value.toString();
|
|
4771
|
+
}
|
|
4772
|
+
async renderDate(value, _depth) {
|
|
4773
|
+
return value;
|
|
4774
|
+
}
|
|
4775
|
+
async renderConceptValue(value, _depth) {
|
|
4776
|
+
return value;
|
|
4777
|
+
}
|
|
4778
|
+
async renderResourceReference(value, _depth) {
|
|
4779
|
+
return value;
|
|
4780
|
+
}
|
|
4781
|
+
async renderSemantic(value, depth) {
|
|
4782
|
+
return this.renderBlock(await value.toObject(), depth);
|
|
4783
|
+
}
|
|
4784
|
+
async renderUrl(value, _depth) {
|
|
4785
|
+
return value;
|
|
4786
|
+
}
|
|
4787
|
+
renderBlock(block, depth) {
|
|
4788
|
+
const renderedBlock = {};
|
|
4789
|
+
const promises = [];
|
|
4790
|
+
for (const [key, value] of Object.entries(block)) {
|
|
4791
|
+
promises.push(
|
|
4792
|
+
this.renderValue(value, depth + 1).then((val) => {
|
|
4793
|
+
renderedBlock[key] = val;
|
|
4794
|
+
})
|
|
4795
|
+
);
|
|
4796
|
+
}
|
|
4797
|
+
return Promise.all(promises).then(() => renderedBlock);
|
|
4798
|
+
}
|
|
4799
|
+
async renderArray(value, depth) {
|
|
4800
|
+
return Promise.all(value.map((val) => this.renderValue(val, depth + 1)));
|
|
4801
|
+
}
|
|
4802
|
+
}
|
|
4803
|
+
class MarkdownRenderer extends Renderer {
|
|
4804
|
+
constructor(callbacks) {
|
|
4805
|
+
super();
|
|
4806
|
+
__publicField(this, "conceptValueToUrl");
|
|
4807
|
+
__publicField(this, "dateToText");
|
|
4808
|
+
__publicField(this, "domainValueToUrl");
|
|
4809
|
+
__publicField(this, "resourceReferenceToUrl");
|
|
4810
|
+
__publicField(this, "nodeToUrl");
|
|
4811
|
+
this.conceptValueToUrl = callbacks.conceptValueToUrl;
|
|
4812
|
+
this.dateToText = callbacks.dateToText;
|
|
4813
|
+
this.domainValueToUrl = callbacks.domainValueToUrl;
|
|
4814
|
+
this.resourceReferenceToUrl = callbacks.resourceReferenceToUrl;
|
|
4815
|
+
this.nodeToUrl = callbacks.nodeToUrl;
|
|
4816
|
+
}
|
|
4817
|
+
async renderUrl(value, _depth) {
|
|
4818
|
+
const text = `[${value}](${value})`;
|
|
4819
|
+
const wrapper = new Cleanable(text);
|
|
4820
|
+
wrapper.__clean = value.href();
|
|
4821
|
+
return wrapper;
|
|
4822
|
+
}
|
|
4823
|
+
async renderDomainValue(domainValue, _) {
|
|
4824
|
+
const value = await domainValue.getValue();
|
|
4825
|
+
const url = this.domainValueToUrl ? await this.domainValueToUrl(domainValue) : null;
|
|
4826
|
+
const text = url ? `[${value.toString()}](${url.trim()})` : value.toString();
|
|
4827
|
+
const wrapper = new Cleanable(`
|
|
4828
|
+
<span
|
|
4829
|
+
class='alizarin-domain-value' data-id='${value.id}'
|
|
4830
|
+
>
|
|
4831
|
+
${text}
|
|
4832
|
+
</span>`.replace(/\n/g, " ").trim());
|
|
4833
|
+
wrapper.__clean = domainValue.toString();
|
|
4834
|
+
return wrapper;
|
|
4835
|
+
}
|
|
4836
|
+
async renderDate(date, _) {
|
|
4837
|
+
const value = await date;
|
|
4838
|
+
const text = this.dateToText ? await this.dateToText(value) : value.toISOString();
|
|
4839
|
+
const wrapper = new Cleanable(`
|
|
4840
|
+
<time datetime='${text}'>
|
|
4841
|
+
${text}
|
|
4842
|
+
</time>`.replace(/\n/g, " ").trim());
|
|
4843
|
+
wrapper.__clean = text;
|
|
4844
|
+
return wrapper;
|
|
4845
|
+
}
|
|
4846
|
+
async renderConceptValue(conceptValue, _) {
|
|
4847
|
+
const value = await conceptValue.getValue();
|
|
4848
|
+
const url = this.conceptValueToUrl ? await this.conceptValueToUrl(conceptValue) : null;
|
|
4849
|
+
const text = url ? `[${value.value}](${url.trim()})` : value.value;
|
|
4850
|
+
const wrapper = new Cleanable(`
|
|
4851
|
+
<span
|
|
4852
|
+
class='alizarin-concept-value' data-id='${value.id}'
|
|
4853
|
+
data-concept-id='${value.__concept ? value.__concept.id : ""}'
|
|
4854
|
+
data-concept-ref='$${value.__concept ? value.__concept.source : ""}'
|
|
4855
|
+
>
|
|
4856
|
+
${text}
|
|
4857
|
+
</span>`.replace(/\n/g, " ").trim());
|
|
4858
|
+
wrapper.__clean = conceptValue.toString();
|
|
4859
|
+
return wrapper;
|
|
4860
|
+
}
|
|
4861
|
+
async renderResourceReference(rivm, _) {
|
|
4862
|
+
const value = await rivm.forJson(false);
|
|
4863
|
+
const url = this.resourceReferenceToUrl ? await this.resourceReferenceToUrl(rivm) : null;
|
|
4864
|
+
let title = value.title || value.type || "Resource";
|
|
4865
|
+
const text = url ? `[${title}](${url.trim()})` : title;
|
|
4866
|
+
const resourceMetadata = await staticStore.getMeta(value.id);
|
|
4867
|
+
if (resourceMetadata) {
|
|
4868
|
+
title = resourceMetadata.name;
|
|
4869
|
+
}
|
|
4870
|
+
const wrapper = new Cleanable(`
|
|
4871
|
+
<span
|
|
4872
|
+
class='alizarin-resource-instance alizarin-related-resource' data-id='${value.id}'
|
|
4873
|
+
data-graph-id='${value.graphId}'
|
|
4874
|
+
>
|
|
4875
|
+
${text}
|
|
4876
|
+
</span>`.replace(/\n/g, " ").trim());
|
|
4877
|
+
wrapper.__clean = rivm.toString();
|
|
4878
|
+
return wrapper;
|
|
4879
|
+
}
|
|
4880
|
+
}
|
|
4881
|
+
class FlatMarkdownRenderer extends MarkdownRenderer {
|
|
4882
|
+
async renderSemantic(vm, depth) {
|
|
4883
|
+
const children = [...(await vm.__getChildValues()).entries()].map(([_, v]) => [v.node.alias, v.node]);
|
|
4884
|
+
const nodes = Object.fromEntries(await Promise.all(children));
|
|
4885
|
+
return super.renderSemantic(vm, depth).then(async (block) => {
|
|
4886
|
+
const text = [
|
|
4887
|
+
`* <span class='node-type'>${vm.__node.name}</span> →`,
|
|
4888
|
+
...Object.entries(await block).map(([key, value]) => {
|
|
4889
|
+
const node = nodes[key];
|
|
4890
|
+
let nodeName = node.name;
|
|
4891
|
+
if (this.nodeToUrl) {
|
|
4892
|
+
nodeName = `[${node.name}](${this.nodeToUrl(node)})`;
|
|
4893
|
+
}
|
|
4894
|
+
if ((typeof value == "string" || value instanceof String) && value.indexOf("\n") != -1) {
|
|
4895
|
+
return ` * <span class='node-name'>${nodeName}</span> <span class='node-alias'>[*${node.alias}*]</span>:<span class='node-value'>
|
|
4896
|
+
${value.split("\n").map((x) => ` ${x}`).join("\n")}
|
|
4897
|
+
</span>`;
|
|
4898
|
+
} else {
|
|
4899
|
+
return ` * <span class='node-name'>${nodeName}</span> <span class='node-alias'>[*${node.alias}*]</span>: <span class='node-value'>${value}</span>`;
|
|
4900
|
+
}
|
|
4901
|
+
}).join("\n").split("\n")
|
|
4902
|
+
];
|
|
4903
|
+
if (text[1] == "") {
|
|
4904
|
+
text[0] += `<span class='node-empty'><empty></span>`;
|
|
4905
|
+
text.pop();
|
|
4906
|
+
}
|
|
4907
|
+
return text.map((line) => ` ${line}`).join("\n");
|
|
4908
|
+
});
|
|
4909
|
+
}
|
|
4910
|
+
async renderArray(value, depth) {
|
|
4911
|
+
const rows = await super.renderArray(value, depth);
|
|
4912
|
+
if (value instanceof PseudoList || value.indexOf("\n") != -1) {
|
|
4913
|
+
return rows.map((x) => `${x}`).join("\n");
|
|
4914
|
+
} else {
|
|
4915
|
+
return rows.join(", ");
|
|
4916
|
+
}
|
|
4917
|
+
}
|
|
4918
|
+
async renderString(value, _depth) {
|
|
4919
|
+
if (value.indexOf("\n") != -1) {
|
|
4920
|
+
value = "\n " + value.split("\n").join("\n ");
|
|
4921
|
+
}
|
|
4922
|
+
return value;
|
|
4923
|
+
}
|
|
4924
|
+
}
|
|
4925
|
+
class JsonRenderer extends Renderer {
|
|
4926
|
+
async renderDate(value, _depth) {
|
|
4927
|
+
return value.forJson();
|
|
4928
|
+
}
|
|
4929
|
+
async renderBoolean(value, _depth) {
|
|
4930
|
+
return typeof value === "boolean" ? value : value.forJson();
|
|
4931
|
+
}
|
|
4932
|
+
async renderConceptValue(value, _depth) {
|
|
4933
|
+
return value.forJson();
|
|
4934
|
+
}
|
|
4935
|
+
async renderDomainValue(value, _depth) {
|
|
4936
|
+
return value.forJson();
|
|
4937
|
+
}
|
|
4938
|
+
async renderResourceReference(value, _depth) {
|
|
4939
|
+
const val = value.forJson();
|
|
4940
|
+
return val;
|
|
4941
|
+
}
|
|
4942
|
+
}
|
|
4943
|
+
const renderers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
4944
|
+
__proto__: null,
|
|
4945
|
+
Cleanable,
|
|
4946
|
+
FlatMarkdownRenderer,
|
|
4947
|
+
JsonRenderer,
|
|
4948
|
+
MarkdownRenderer
|
|
4949
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
4950
|
+
const AlizarinModel = ResourceInstanceViewModel;
|
|
4951
|
+
const setCurrentLanguage = setCurrentLanguage$1;
|
|
4952
|
+
const getCurrentLanguage = getCurrentLanguage$1;
|
|
4953
|
+
export {
|
|
4954
|
+
AlizarinModel,
|
|
4955
|
+
GraphManager,
|
|
4956
|
+
GraphMutator,
|
|
4957
|
+
RDM,
|
|
4958
|
+
ResourceModelWrapper,
|
|
4959
|
+
WKRM,
|
|
4960
|
+
client,
|
|
4961
|
+
getCurrentLanguage,
|
|
4962
|
+
graphManager,
|
|
4963
|
+
interfaces,
|
|
4964
|
+
nodeConfig,
|
|
4965
|
+
renderers,
|
|
4966
|
+
setCurrentLanguage,
|
|
4967
|
+
staticStore,
|
|
4968
|
+
staticTypes,
|
|
4969
|
+
utils,
|
|
4970
|
+
viewModels
|
|
4971
|
+
};
|
|
4972
|
+
//# sourceMappingURL=alizarin.js.map
|