alizarin 0.2.1-alpha.83

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.
Files changed (57) hide show
  1. package/LICENSE.txt +661 -0
  2. package/README.md +160 -0
  3. package/dist/_wasm.d.ts +23 -0
  4. package/dist/alizarin.full.js +799 -0
  5. package/dist/alizarin.full.js.map +1 -0
  6. package/dist/alizarin.inline-full.js +4 -0
  7. package/dist/alizarin.inline.js +4 -0
  8. package/dist/alizarin.js +47 -0
  9. package/dist/alizarin.js.map +1 -0
  10. package/dist/alizarin_bg.wasm +0 -0
  11. package/dist/backend.d.ts +74 -0
  12. package/dist/cards.d.ts +21 -0
  13. package/dist/client.d.ts +86 -0
  14. package/dist/collectionMutator.d.ts +155 -0
  15. package/dist/csvModelLoader.d.ts +59 -0
  16. package/dist/full.d.ts +3 -0
  17. package/dist/graphManager.d.ts +259 -0
  18. package/dist/interfaces.d.ts +145 -0
  19. package/dist/main-r-MmUiQf.js +12355 -0
  20. package/dist/main-r-MmUiQf.js.map +1 -0
  21. package/dist/main.d.ts +28 -0
  22. package/dist/nodeConfig.d.ts +61 -0
  23. package/dist/pseudos.d.ts +118 -0
  24. package/dist/rdm.d.ts +68 -0
  25. package/dist/renderers.d.ts +65 -0
  26. package/dist/semantic.d.ts +35 -0
  27. package/dist/static-types.d.ts +172 -0
  28. package/dist/staticStore.d.ts +60 -0
  29. package/dist/tracing/index.d.ts +172 -0
  30. package/dist/utils.d.ts +43 -0
  31. package/dist/validation/index.d.ts +734 -0
  32. package/dist/validation/index.js +1194 -0
  33. package/dist/validation/index.js.map +1 -0
  34. package/dist/validation/validators/graphLoading.d.ts +69 -0
  35. package/dist/validation/validators/index.d.ts +1 -0
  36. package/dist/viewModels/BooleanViewModel.d.ts +17 -0
  37. package/dist/viewModels/ConceptListViewModel.d.ts +15 -0
  38. package/dist/viewModels/ConceptValueViewModel.d.ts +28 -0
  39. package/dist/viewModels/DateViewModel.d.ts +16 -0
  40. package/dist/viewModels/DomainValueListViewModel.d.ts +15 -0
  41. package/dist/viewModels/DomainValueViewModel.d.ts +17 -0
  42. package/dist/viewModels/EDTFViewModel.d.ts +13 -0
  43. package/dist/viewModels/GeoJSONViewModel.d.ts +26 -0
  44. package/dist/viewModels/NodeViewModel.d.ts +15 -0
  45. package/dist/viewModels/NonLocalizedStringViewModel.d.ts +13 -0
  46. package/dist/viewModels/NumberViewModel.d.ts +14 -0
  47. package/dist/viewModels/ResourceInstanceListViewModel.d.ts +25 -0
  48. package/dist/viewModels/ResourceInstanceViewModel.d.ts +62 -0
  49. package/dist/viewModels/StringViewModel.d.ts +17 -0
  50. package/dist/viewModels/UrlViewModel.d.ts +22 -0
  51. package/dist/viewModels/cacheEntries.d.ts +73 -0
  52. package/dist/viewModels/getViewModel.d.ts +4 -0
  53. package/dist/viewModels/index.d.ts +20 -0
  54. package/dist/viewModels/types.d.ts +15 -0
  55. package/dist/viewModels.d.ts +1 -0
  56. package/dist/wasmTiming.d.ts +11 -0
  57. package/package.json +93 -0
@@ -0,0 +1,799 @@
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
+ import { w as wasmReady, r as registerExtensionHandler, C as CUSTOM_DATATYPES, g as getCurrentLanguage, a as registerResolvableDatatype, n as nodeConfigManager, R as RDM } from "./main-r-MmUiQf.js";
5
+ import { A, K, G, p, o, S, L, N, c, I, J, T, k, y, Q, t, B, l, b, _, j, D, m, F, H, i, z, O, q, P, x, d, f, s, E, h, u, M, v, e } from "./main-r-MmUiQf.js";
6
+ class FileListItem {
7
+ constructor(data) {
8
+ __publicField(this, "accepted");
9
+ __publicField(this, "alt_text");
10
+ __publicField(this, "attribution");
11
+ __publicField(this, "content");
12
+ __publicField(this, "description");
13
+ __publicField(this, "file_id");
14
+ __publicField(this, "index");
15
+ __publicField(this, "last_modified");
16
+ __publicField(this, "name");
17
+ __publicField(this, "path");
18
+ __publicField(this, "selected");
19
+ __publicField(this, "size");
20
+ __publicField(this, "status");
21
+ __publicField(this, "title");
22
+ __publicField(this, "type");
23
+ __publicField(this, "url");
24
+ __publicField(this, "renderer");
25
+ this.accepted = data.accepted ?? false;
26
+ this.alt_text = data.alt_text;
27
+ this.attribution = data.attribution;
28
+ this.content = data.content;
29
+ this.description = data.description;
30
+ this.file_id = data.file_id;
31
+ this.index = data.index;
32
+ this.last_modified = data.last_modified;
33
+ this.name = data.name || "";
34
+ this.path = data.path;
35
+ this.selected = data.selected ?? false;
36
+ this.size = data.size;
37
+ this.status = data.status;
38
+ this.title = data.title;
39
+ this.type = data.type;
40
+ this.url = data.url;
41
+ this.renderer = data.renderer;
42
+ }
43
+ /**
44
+ * Get the display string for this file.
45
+ * Uses title if available (in specified language), otherwise falls back to filename.
46
+ */
47
+ toDisplayString(lang) {
48
+ var _a;
49
+ const targetLang = lang || getCurrentLanguage() || "en";
50
+ if (this.title) {
51
+ if ((_a = this.title[targetLang]) == null ? void 0 : _a.value) {
52
+ return this.title[targetLang].value;
53
+ }
54
+ for (const localized of Object.values(this.title)) {
55
+ if (localized.value) {
56
+ return localized.value;
57
+ }
58
+ }
59
+ }
60
+ if (this.name) {
61
+ return this.name;
62
+ }
63
+ return this.file_id || "(unnamed file)";
64
+ }
65
+ /**
66
+ * Get the alt text in a specific language.
67
+ */
68
+ getAltText(lang) {
69
+ var _a;
70
+ const targetLang = lang || getCurrentLanguage() || "en";
71
+ if (this.alt_text) {
72
+ if ((_a = this.alt_text[targetLang]) == null ? void 0 : _a.value) {
73
+ return this.alt_text[targetLang].value;
74
+ }
75
+ }
76
+ return null;
77
+ }
78
+ /**
79
+ * Check if this is an image file based on MIME type.
80
+ */
81
+ isImage() {
82
+ var _a;
83
+ return ((_a = this.type) == null ? void 0 : _a.startsWith("image/")) ?? false;
84
+ }
85
+ /**
86
+ * Convert to plain object for JSON serialization.
87
+ */
88
+ toJson() {
89
+ const result = {
90
+ name: this.name,
91
+ accepted: this.accepted,
92
+ selected: this.selected
93
+ };
94
+ if (this.alt_text) result.alt_text = this.alt_text;
95
+ if (this.attribution) result.attribution = this.attribution;
96
+ if (this.content) result.content = this.content;
97
+ if (this.description) result.description = this.description;
98
+ if (this.file_id) result.file_id = this.file_id;
99
+ if (this.index !== void 0) result.index = this.index;
100
+ if (this.last_modified) result.last_modified = this.last_modified;
101
+ if (this.path) result.path = this.path;
102
+ if (this.size !== void 0) result.size = this.size;
103
+ if (this.status) result.status = this.status;
104
+ if (this.title) result.title = this.title;
105
+ if (this.type) result.type = this.type;
106
+ if (this.url) result.url = this.url;
107
+ if (this.renderer) result.renderer = this.renderer;
108
+ return result;
109
+ }
110
+ }
111
+ wasmReady.then(() => {
112
+ registerExtensionHandler("file-list", {
113
+ renderDisplay: (tileData, language) => {
114
+ if (!tileData) return null;
115
+ if (Array.isArray(tileData)) {
116
+ if (tileData.length === 0) return null;
117
+ const displayStrings = tileData.map((item) => {
118
+ if (!item || typeof item !== "object") return null;
119
+ const file = new FileListItem(item);
120
+ return file.toDisplayString(language);
121
+ }).filter((s2) => s2 !== null);
122
+ return displayStrings.join(", ");
123
+ }
124
+ if (typeof tileData === "object" && tileData !== null) {
125
+ const file = new FileListItem(tileData);
126
+ return file.toDisplayString(language);
127
+ }
128
+ return null;
129
+ }
130
+ });
131
+ });
132
+ class FileItemViewModel extends String {
133
+ constructor(file) {
134
+ super(file.toDisplayString());
135
+ __publicField(this, "_");
136
+ __publicField(this, "__parentPseudo");
137
+ __publicField(this, "describeField", () => this.__parentPseudo ? this.__parentPseudo.describeField() : null);
138
+ __publicField(this, "describeFieldGroup", () => this.__parentPseudo ? this.__parentPseudo.describeFieldGroup() : null);
139
+ __publicField(this, "_file");
140
+ this._file = file;
141
+ }
142
+ async forJson() {
143
+ return this._file.toJson();
144
+ }
145
+ getValue() {
146
+ return this._file;
147
+ }
148
+ get name() {
149
+ return this._file.name;
150
+ }
151
+ get url() {
152
+ return this._file.url;
153
+ }
154
+ get file_id() {
155
+ return this._file.file_id;
156
+ }
157
+ get fileType() {
158
+ return this._file.type;
159
+ }
160
+ get size() {
161
+ return this._file.size;
162
+ }
163
+ isImage() {
164
+ return this._file.isImage();
165
+ }
166
+ getAltText(lang) {
167
+ return this._file.getAltText(lang);
168
+ }
169
+ async __asTileData() {
170
+ return this._file ? this._file.toJson() : null;
171
+ }
172
+ }
173
+ class FileListViewModel extends Array {
174
+ constructor() {
175
+ super(...arguments);
176
+ __publicField(this, "_");
177
+ __publicField(this, "__parentPseudo");
178
+ __publicField(this, "describeField", () => this.__parentPseudo ? this.__parentPseudo.describeField() : null);
179
+ __publicField(this, "describeFieldGroup", () => this.__parentPseudo ? this.__parentPseudo.describeFieldGroup() : null);
180
+ __publicField(this, "_value", null);
181
+ }
182
+ async forJson() {
183
+ const value = await this._value;
184
+ if (!value) return null;
185
+ return Promise.all(value.map(async (v2) => v2 ? v2.forJson() : null));
186
+ }
187
+ /**
188
+ * Get only image files from the list.
189
+ */
190
+ async getImages() {
191
+ const items = Array.from(this);
192
+ const resolved = await Promise.all(items);
193
+ return resolved.filter(
194
+ (item) => item !== null && item.isImage()
195
+ );
196
+ }
197
+ /**
198
+ * Find a file by name.
199
+ */
200
+ async getByName(name) {
201
+ const items = Array.from(this);
202
+ const resolved = await Promise.all(items);
203
+ return resolved.find(
204
+ (item) => item !== null && item.name === name
205
+ ) ?? null;
206
+ }
207
+ /**
208
+ * Find a file by ID.
209
+ */
210
+ async getById(fileId) {
211
+ const items = Array.from(this);
212
+ const resolved = await Promise.all(items);
213
+ return resolved.find(
214
+ (item) => item !== null && item.file_id === fileId
215
+ ) ?? null;
216
+ }
217
+ static async __create(tile, node, value, _cacheEntry = null) {
218
+ const nodeid = node.nodeid;
219
+ let val = [];
220
+ if (!tile.data.has(nodeid)) {
221
+ tile.data.set(nodeid, null);
222
+ }
223
+ if (value !== null && value !== void 0) {
224
+ tile.data.set(nodeid, []);
225
+ if (value instanceof Promise) {
226
+ const resolved = await value;
227
+ return FileListViewModel.__create(tile, node, resolved, _cacheEntry);
228
+ }
229
+ let items;
230
+ if (Array.isArray(value)) {
231
+ items = value;
232
+ } else if (typeof value === "object") {
233
+ items = [value];
234
+ } else {
235
+ throw new Error(
236
+ `Cannot set file-list value on node ${nodeid} except via array or object: ${JSON.stringify(value)}`
237
+ );
238
+ }
239
+ val = items.map((item, idx) => {
240
+ if (item instanceof FileItemViewModel) {
241
+ return item;
242
+ }
243
+ if (typeof item === "object" && item !== null) {
244
+ const fileData = item;
245
+ if (fileData.index === void 0) {
246
+ fileData.index = idx;
247
+ }
248
+ const file = new FileListItem(fileData);
249
+ return new FileItemViewModel(file);
250
+ }
251
+ return null;
252
+ });
253
+ Promise.all(val).then((vals) => {
254
+ const tileData = vals.filter((v2) => v2 !== null).map((v2) => v2.getValue().toJson());
255
+ tile.data.set(nodeid, tileData);
256
+ });
257
+ } else {
258
+ val = [];
259
+ }
260
+ const viewModel = new FileListViewModel(...val);
261
+ viewModel._value = Promise.all(val);
262
+ return viewModel;
263
+ }
264
+ async __asTileData() {
265
+ return this.forJson();
266
+ }
267
+ }
268
+ class FileListDataType {
269
+ static async __create(tile, node, value, _cacheEntry) {
270
+ return FileListViewModel.__create(tile, node, value, _cacheEntry);
271
+ }
272
+ }
273
+ CUSTOM_DATATYPES.set("file-list", FileListDataType);
274
+ function getReferenceValueFromCollection(collection, conceptId) {
275
+ var _a;
276
+ const concept = (_a = collection.__allConcepts) == null ? void 0 : _a[conceptId];
277
+ if (!concept) {
278
+ return null;
279
+ }
280
+ const labels = [];
281
+ for (const [langId, prefLabel] of Object.entries(concept.prefLabels || {})) {
282
+ const pLabel = prefLabel;
283
+ labels.push({
284
+ id: pLabel.id,
285
+ language_id: langId,
286
+ list_item_id: concept.id,
287
+ value: pLabel.value,
288
+ valuetype_id: "prefLabel"
289
+ });
290
+ }
291
+ return {
292
+ labels,
293
+ list_id: collection.id,
294
+ uri: concept.source || `http://localhost:8000/plugins/controlled-list-manager/item/${concept.id}`,
295
+ id: concept.id
296
+ };
297
+ }
298
+ function getReferenceValueByLabelFromCollection(collection, label) {
299
+ const trimmedLabel = label.trim().toLowerCase();
300
+ const values = collection.__values || {};
301
+ const matchingValue = Object.values(values).find(
302
+ (value) => {
303
+ var _a;
304
+ return ((_a = value.value) == null ? void 0 : _a.trim().toLowerCase()) === trimmedLabel;
305
+ }
306
+ );
307
+ if (!matchingValue || !matchingValue.__concept) {
308
+ return null;
309
+ }
310
+ return getReferenceValueFromCollection(collection, matchingValue.__concept.id);
311
+ }
312
+ function flattenToReferences(value) {
313
+ const items = [];
314
+ const visit = (val) => {
315
+ if (!val) return;
316
+ if (val._ref) {
317
+ const ref = val._ref;
318
+ const refObj = typeof ref.toJSON === "function" ? ref.toJSON() : ref;
319
+ if (refObj && (refObj.labels || refObj.__needs_rdm_label_lookup)) {
320
+ items.push(refObj);
321
+ }
322
+ return;
323
+ }
324
+ if (Array.isArray(val)) {
325
+ val.forEach(visit);
326
+ return;
327
+ }
328
+ if (val.__needs_rdm_label_lookup && val.label) {
329
+ items.push(val);
330
+ return;
331
+ }
332
+ if (val.labels) {
333
+ items.push(val);
334
+ return;
335
+ }
336
+ if (typeof val === "string") {
337
+ try {
338
+ visit(JSON.parse(val));
339
+ } catch {
340
+ }
341
+ }
342
+ };
343
+ visit(value);
344
+ return items;
345
+ }
346
+ function renderReferenceDisplay(data, language) {
347
+ if (!data) return null;
348
+ if (data.__needs_rdm_label_lookup && data.label) {
349
+ return data.label;
350
+ }
351
+ if (data.labels && data.labels.length > 0) {
352
+ const langPrefLabel = data.labels.find(
353
+ (l2) => l2.language_id === language && l2.valuetype_id === "prefLabel"
354
+ );
355
+ if (langPrefLabel) return langPrefLabel.value;
356
+ const langLabel = data.labels.find((l2) => l2.language_id === language);
357
+ if (langLabel) return langLabel.value;
358
+ const prefLabel = data.labels.find((l2) => l2.valuetype_id === "prefLabel");
359
+ if (prefLabel) return prefLabel.value;
360
+ return data.labels[0].value;
361
+ }
362
+ return null;
363
+ }
364
+ wasmReady.then(() => {
365
+ registerExtensionHandler("reference", {
366
+ renderDisplay: (tileData, language) => {
367
+ if (!tileData) return null;
368
+ const items = flattenToReferences(tileData);
369
+ if (items.length === 0) return null;
370
+ const displayStrings = items.map((ref) => renderReferenceDisplay(ref, language)).filter((s2) => s2 !== null);
371
+ return displayStrings.join(", ");
372
+ }
373
+ });
374
+ });
375
+ class StaticReferenceLabel {
376
+ constructor(label) {
377
+ __publicField(this, "id");
378
+ __publicField(this, "language_id");
379
+ __publicField(this, "list_item_id");
380
+ __publicField(this, "value");
381
+ __publicField(this, "valuetype_id");
382
+ this.id = label.id;
383
+ this.language_id = label.language_id;
384
+ this.list_item_id = label.list_item_id;
385
+ this.value = label.value;
386
+ this.valuetype_id = label.valuetype_id;
387
+ }
388
+ toJSON() {
389
+ return {
390
+ id: this.id,
391
+ language_id: this.language_id,
392
+ list_item_id: this.list_item_id,
393
+ value: this.value,
394
+ valuetype_id: this.valuetype_id
395
+ };
396
+ }
397
+ }
398
+ class StaticReference {
399
+ constructor(reference) {
400
+ __publicField(this, "labels");
401
+ __publicField(this, "list_id");
402
+ __publicField(this, "uri");
403
+ this.list_id = reference.list_id;
404
+ this.uri = reference.uri;
405
+ this.labels = [];
406
+ for (const label of reference.labels) {
407
+ if (label instanceof StaticReferenceLabel) {
408
+ this.labels.push(label);
409
+ } else {
410
+ this.labels.push(new StaticReferenceLabel(label));
411
+ }
412
+ }
413
+ }
414
+ toJSON() {
415
+ return {
416
+ labels: this.labels.map((l2) => l2.toJSON()),
417
+ list_id: this.list_id,
418
+ uri: this.uri
419
+ };
420
+ }
421
+ }
422
+ function referenceToString(reference) {
423
+ if (reference.labels.length == 1) {
424
+ return reference.labels[0].value;
425
+ }
426
+ let prefLabel;
427
+ const lang = getCurrentLanguage();
428
+ for (const label of reference.labels) {
429
+ if (label.valuetype_id === "prefLabel") {
430
+ prefLabel = label.value;
431
+ if (label.language_id === lang) {
432
+ return prefLabel;
433
+ }
434
+ }
435
+ }
436
+ return prefLabel || "(undefined)";
437
+ }
438
+ class ReferenceValueViewModel extends String {
439
+ constructor(reference, pendingLookup, tile, nodeid, collectionId) {
440
+ super(reference ? referenceToString(reference) : (pendingLookup == null ? void 0 : pendingLookup.type) === "label" ? pendingLookup.label : "(pending)");
441
+ __publicField(this, "_");
442
+ __publicField(this, "__parentPseudo");
443
+ __publicField(this, "describeField", () => this.__parentPseudo ? this.__parentPseudo.describeField() : null);
444
+ __publicField(this, "describeFieldGroup", () => this.__parentPseudo ? this.__parentPseudo.describeFieldGroup() : null);
445
+ __publicField(this, "_ref");
446
+ __publicField(this, "_pendingLookup", null);
447
+ __publicField(this, "_resolvedRef", null);
448
+ __publicField(this, "_resolutionPromise", null);
449
+ __publicField(this, "_tile", null);
450
+ __publicField(this, "_nodeid", null);
451
+ __publicField(this, "_collectionId", null);
452
+ this._ref = reference;
453
+ this._pendingLookup = pendingLookup || null;
454
+ this._tile = tile || null;
455
+ this._nodeid = nodeid || null;
456
+ this._collectionId = collectionId ?? ((pendingLookup == null ? void 0 : pendingLookup.collectionId) ?? null);
457
+ }
458
+ get [Symbol.toStringTag]() {
459
+ return "ReferenceValue";
460
+ }
461
+ async getParent() {
462
+ var _a;
463
+ const ref = await this._resolvePending();
464
+ if (!ref || !this._collectionId) {
465
+ return null;
466
+ }
467
+ const conceptId = (_a = ref.labels[0]) == null ? void 0 : _a.list_item_id;
468
+ if (!conceptId) {
469
+ return null;
470
+ }
471
+ const collection = await RDM.retrieveCollection(this._collectionId);
472
+ if (!collection.getParentId) {
473
+ throw new Error(
474
+ `Collection ${this._collectionId} does not support hierarchy lookups. Ensure WASM is initialized and the collection is a StaticCollection.`
475
+ );
476
+ }
477
+ const parentId = collection.getParentId(conceptId);
478
+ if (!parentId) {
479
+ return null;
480
+ }
481
+ const parentRef = getReferenceValueFromCollection(collection, parentId);
482
+ if (!parentRef) {
483
+ return null;
484
+ }
485
+ return new ReferenceValueViewModel(new StaticReference(parentRef), void 0, void 0, void 0, this._collectionId);
486
+ }
487
+ /**
488
+ * Get the parent reference value, if this reference has a parent in the hierarchy.
489
+ * @returns A new ReferenceValueViewModel for the parent, or null if no parent
490
+ * @throws Error if the collection doesn't support hierarchy lookups
491
+ */
492
+ get parent() {
493
+ return this.getParent();
494
+ }
495
+ /**
496
+ * Get all ancestor reference values, from immediate parent to root.
497
+ * @returns Array of ReferenceValueViewModels for ancestors
498
+ */
499
+ async getAncestors() {
500
+ const result = [];
501
+ let current = this;
502
+ while ((current = await current.parent) !== null) {
503
+ result.push(current);
504
+ }
505
+ return result;
506
+ }
507
+ /**
508
+ * Get all ancestor reference values, from immediate parent to root.
509
+ * @returns Array of ReferenceValueViewModels for ancestors
510
+ */
511
+ get ancestors() {
512
+ return this.getAncestors();
513
+ }
514
+ /**
515
+ * Resolve any pending lookup. Called lazily when the resolved value is needed.
516
+ */
517
+ async _resolvePending() {
518
+ if (this._resolvedRef) {
519
+ return this._resolvedRef;
520
+ }
521
+ if (this._ref) {
522
+ this._resolvedRef = this._ref;
523
+ return this._ref;
524
+ }
525
+ if (!this._pendingLookup) {
526
+ return null;
527
+ }
528
+ if (this._resolutionPromise) {
529
+ return this._resolutionPromise;
530
+ }
531
+ this._resolutionPromise = (async () => {
532
+ const lookup = this._pendingLookup;
533
+ const collection = await RDM.retrieveCollection(lookup.collectionId);
534
+ let val = null;
535
+ if (lookup.type === "uuid") {
536
+ val = getReferenceValueFromCollection(collection, lookup.uuid);
537
+ if (!val) {
538
+ console.error("Could not find reference for UUID", lookup.uuid, "in collection", lookup.collectionId);
539
+ }
540
+ } else if (lookup.type === "label") {
541
+ val = getReferenceValueByLabelFromCollection(collection, lookup.label);
542
+ if (!val) {
543
+ console.error("Could not find reference for label", lookup.label, "in collection", lookup.collectionId);
544
+ }
545
+ }
546
+ if (val) {
547
+ this._resolvedRef = new StaticReference(val);
548
+ if (this._tile && this._nodeid) {
549
+ const currentData = this._tile.data.get(this._nodeid);
550
+ if (!Array.isArray(currentData)) {
551
+ this._tile.data.set(this._nodeid, this._resolvedRef.toJSON());
552
+ }
553
+ }
554
+ }
555
+ return this._resolvedRef;
556
+ })();
557
+ return this._resolutionPromise;
558
+ }
559
+ async forJson() {
560
+ const ref = await this._resolvePending();
561
+ return ref && typeof ref.toJSON === "function" ? ref.toJSON() : ref;
562
+ }
563
+ async getValue() {
564
+ return this._resolvePending();
565
+ }
566
+ /**
567
+ * Get the display string, resolving lazily if needed.
568
+ * For sync contexts, returns the placeholder until resolved.
569
+ */
570
+ async getDisplay() {
571
+ const ref = await this._resolvePending();
572
+ return ref ? referenceToString(ref) : "(unresolved)";
573
+ }
574
+ // For JSON serialization, return the plain reference object (sync version)
575
+ // IMPORTANT: This must return the reference object, NOT the string value,
576
+ // even though ReferenceValueViewModel extends String.
577
+ toJSON() {
578
+ if (this._resolvedRef) {
579
+ return this._resolvedRef.toJSON();
580
+ }
581
+ if (this._ref) {
582
+ return this._ref.toJSON();
583
+ }
584
+ if (this._pendingLookup) {
585
+ if (this._pendingLookup.type === "uuid") {
586
+ return { __needs_rdm_lookup: true, uuid: this._pendingLookup.uuid };
587
+ } else {
588
+ return { __needs_rdm_label_lookup: true, label: this._pendingLookup.label, controlledList: this._pendingLookup.collectionId };
589
+ }
590
+ }
591
+ return null;
592
+ }
593
+ // Convert to plain object for WASM tile data serialization
594
+ async __asTileData() {
595
+ const ref = await this._resolvePending();
596
+ return ref && typeof ref.toJSON === "function" ? ref.toJSON() : ref;
597
+ }
598
+ static async __create(tile, node, value, _cacheEntry) {
599
+ var _a, _b;
600
+ const nodeid = node.nodeid;
601
+ const collectionId = ((_a = node.config) == null ? void 0 : _a.controlledList) || ((_b = node.config) == null ? void 0 : _b.rdmCollection);
602
+ if (!collectionId) {
603
+ throw Error(`Node ${node.alias} (${node.nodeid}) missing controlledList or rdmCollection in config`);
604
+ }
605
+ if (tile) {
606
+ if (!tile.data.has(nodeid)) {
607
+ tile.data.set(nodeid, null);
608
+ }
609
+ if (value !== null) {
610
+ if (value instanceof Promise) {
611
+ return value.then((value2) => {
612
+ return ReferenceValueViewModel.__create(tile, node, value2, _cacheEntry);
613
+ });
614
+ } else if (typeof value == "string") {
615
+ if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.exec(
616
+ value
617
+ )) {
618
+ const pendingLookup = { type: "uuid", uuid: value, collectionId };
619
+ tile.data.set(nodeid, { __needs_rdm_lookup: true, uuid: value });
620
+ return new ReferenceValueViewModel(null, pendingLookup, tile, nodeid, collectionId);
621
+ } else {
622
+ throw Error(
623
+ `Set references using values from collections, not strings: ${value}`
624
+ );
625
+ }
626
+ } else if (typeof value === "object" && value !== null && value.__needs_rdm_lookup && value.uuid) {
627
+ const pendingLookup = { type: "uuid", uuid: value.uuid, collectionId };
628
+ tile.data.set(nodeid, value);
629
+ return new ReferenceValueViewModel(null, pendingLookup, tile, nodeid, collectionId);
630
+ } else if (typeof value === "object" && value !== null && value.__needs_rdm_label_lookup && value.label) {
631
+ const lookupCollectionId = value.controlledList || collectionId;
632
+ const pendingLookup = { type: "label", label: value.label, collectionId: lookupCollectionId };
633
+ tile.data.set(nodeid, value);
634
+ return new ReferenceValueViewModel(null, pendingLookup, tile, nodeid, lookupCollectionId);
635
+ } else if (Array.isArray(value) && value.length > 0 && "labels" in value[0]) {
636
+ const ref = new StaticReference(value[0]);
637
+ tile.data.set(nodeid, ref.toJSON());
638
+ return new ReferenceValueViewModel(ref, void 0, void 0, void 0, collectionId);
639
+ } else if (typeof value === "object" && value !== null && "labels" in value) {
640
+ const ref = new StaticReference(value);
641
+ tile.data.set(nodeid, ref.toJSON());
642
+ return new ReferenceValueViewModel(ref, void 0, void 0, void 0, collectionId);
643
+ } else {
644
+ throw Error("Could not set reference from this data: " + JSON.stringify(value));
645
+ }
646
+ }
647
+ }
648
+ if (!tile || !value) {
649
+ return null;
650
+ }
651
+ const str = new ReferenceValueViewModel(value, void 0, void 0, void 0, collectionId);
652
+ return str;
653
+ }
654
+ }
655
+ class ReferenceListViewModel extends Array {
656
+ constructor() {
657
+ super(...arguments);
658
+ __publicField(this, "_");
659
+ __publicField(this, "__parentPseudo");
660
+ __publicField(this, "describeField", () => this.__parentPseudo ? this.__parentPseudo.describeField() : null);
661
+ __publicField(this, "describeFieldGroup", () => this.__parentPseudo ? this.__parentPseudo.describeFieldGroup() : null);
662
+ __publicField(this, "_value", null);
663
+ }
664
+ get [Symbol.toStringTag]() {
665
+ return "ReferenceList";
666
+ }
667
+ // Return comma-separated labels for string coercion (template rendering)
668
+ toString() {
669
+ return this.map((v2) => (v2 == null ? void 0 : v2.toString()) ?? "").filter((s2) => s2).join(", ");
670
+ }
671
+ // Allow string comparison to reference type
672
+ includes(value) {
673
+ return this.some((item) => item == value);
674
+ }
675
+ // For JSON serialization, return the array of plain reference objects
676
+ toJSON() {
677
+ const result = [];
678
+ for (let i2 = 0; i2 < this.length; i2++) {
679
+ const v2 = this[i2];
680
+ if (v2 && v2._ref) {
681
+ const ref = v2._ref;
682
+ if (typeof ref.toJSON === "function") {
683
+ result.push(ref.toJSON());
684
+ } else {
685
+ result.push(ref);
686
+ }
687
+ } else if (v2) {
688
+ result.push(null);
689
+ }
690
+ }
691
+ return result;
692
+ }
693
+ async forJson() {
694
+ const value = await this._value;
695
+ if (!value) return null;
696
+ const results = await Promise.all(value.map((v2) => v2 ? v2.forJson() : null));
697
+ return results.filter((r) => r !== null);
698
+ }
699
+ static async __create(tile, node, value, _cacheEntry = null) {
700
+ const nodeid = node.nodeid;
701
+ if (!tile.data.has(nodeid)) {
702
+ tile.data.set(nodeid, null);
703
+ }
704
+ if (value === null) {
705
+ const str2 = new ReferenceListViewModel();
706
+ str2._value = Promise.resolve([]);
707
+ return str2;
708
+ }
709
+ if (!Array.isArray(value)) {
710
+ throw Error(
711
+ `Cannot set an (entire) reference list value on node ${nodeid} except via an array: ${JSON.stringify(value)}`
712
+ );
713
+ }
714
+ const viewModelPromises = value.map((c2, _i) => {
715
+ if (c2 instanceof ReferenceValueViewModel) {
716
+ return Promise.resolve(c2);
717
+ }
718
+ return ReferenceValueViewModel.__create(tile, node, c2, {});
719
+ });
720
+ const resolvedViewModels = await Promise.all(viewModelPromises);
721
+ const validViewModels = resolvedViewModels.filter((v2) => v2 !== null);
722
+ const tileDataRefs = await Promise.all(
723
+ validViewModels.map(async (vm) => {
724
+ const ref = await vm.getValue();
725
+ return ref && typeof ref.toJSON === "function" ? ref.toJSON() : ref;
726
+ })
727
+ );
728
+ tile.data.set(nodeid, tileDataRefs);
729
+ const str = new ReferenceListViewModel();
730
+ str.push(...validViewModels);
731
+ str._value = Promise.resolve(validViewModels);
732
+ return str;
733
+ }
734
+ async __asTileData() {
735
+ if (!this._value) return null;
736
+ const values = await this._value;
737
+ return Promise.all(values.map(async (v2) => {
738
+ if (!v2) return null;
739
+ return v2.__asTileData ? await v2.__asTileData() : v2;
740
+ }));
741
+ }
742
+ }
743
+ class ReferenceMergedDataType {
744
+ static async __create(tile, node, value, _cacheEntry) {
745
+ const config = nodeConfigManager.retrieve(node);
746
+ if (config && config.multiValue) {
747
+ return ReferenceListViewModel.__create(tile, node, value, _cacheEntry);
748
+ }
749
+ return ReferenceValueViewModel.__create(tile, node, value, _cacheEntry);
750
+ }
751
+ }
752
+ CUSTOM_DATATYPES.set("reference", ReferenceMergedDataType);
753
+ registerResolvableDatatype("reference");
754
+ export {
755
+ A as AlizarinModel,
756
+ K as CollectionMutator,
757
+ G as GraphManager,
758
+ p as GraphMutator,
759
+ RDM,
760
+ o as ResourceModelWrapper,
761
+ S as autoDetectBackend,
762
+ L as buildGraphFromModelCsvs,
763
+ N as buildResourcesFromBusinessCsv,
764
+ c as client,
765
+ I as collectionToSkosXml,
766
+ J as collectionsToSkosXml,
767
+ T as createResourceRegistry,
768
+ k as createWKRM,
769
+ y as ensureWasmRdmCache,
770
+ Q as getBackend,
771
+ t as getCurrentLanguage,
772
+ B as getTimingStats,
773
+ l as getWKRMClass,
774
+ b as graphManager,
775
+ _ as initWasm,
776
+ j as interfaces,
777
+ D as logTimingStats,
778
+ m as nodeConfig,
779
+ F as parseSkosXml,
780
+ H as parseSkosXmlToCollection,
781
+ registerExtensionHandler,
782
+ registerResolvableDatatype,
783
+ i as renderers,
784
+ z as resetTimingStats,
785
+ O as setBackend,
786
+ q as setCurrentLanguage,
787
+ P as setNapiModule,
788
+ x as setWasmURL,
789
+ d as slugify,
790
+ f as staticStore,
791
+ s as staticTypes,
792
+ E as tracing,
793
+ h as unregisterResolvableDatatype,
794
+ u as utils,
795
+ M as validateModelCsvs,
796
+ v as version,
797
+ e as viewModels,
798
+ wasmReady
799
+ };