@digitalculture/ochre-sdk 0.5.18 → 0.6.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/dist/index.cjs +465 -689
- package/dist/index.d.cts +59 -362
- package/dist/index.d.ts +59 -362
- package/dist/index.js +464 -679
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -20,17 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
fetchBibliography: () => fetchBibliography,
|
|
24
23
|
fetchByUuid: () => fetchByUuid,
|
|
25
|
-
|
|
26
|
-
fetchGallery: () => fetchGallery,
|
|
27
|
-
fetchPeriod: () => fetchPeriod,
|
|
28
|
-
fetchPropertyValue: () => fetchPropertyValue,
|
|
29
|
-
fetchResource: () => fetchResource,
|
|
30
|
-
fetchSet: () => fetchSet,
|
|
31
|
-
fetchSpatialUnit: () => fetchSpatialUnit,
|
|
32
|
-
fetchTree: () => fetchTree,
|
|
33
|
-
fetchWebsite: () => fetchWebsite,
|
|
24
|
+
fetchItem: () => fetchItem,
|
|
34
25
|
filterProperties: () => filterProperties,
|
|
35
26
|
getAllPropertyLabels: () => getAllPropertyLabels,
|
|
36
27
|
getPropertyByLabel: () => getPropertyByLabel,
|
|
@@ -79,55 +70,241 @@ __export(index_exports, {
|
|
|
79
70
|
});
|
|
80
71
|
module.exports = __toCommonJS(index_exports);
|
|
81
72
|
|
|
82
|
-
// src/
|
|
83
|
-
var import_zod3 = require("zod");
|
|
84
|
-
|
|
85
|
-
// src/utils/fetchers/generic.ts
|
|
73
|
+
// src/schemas.ts
|
|
86
74
|
var import_zod = require("zod");
|
|
87
75
|
var uuidSchema = import_zod.z.string().uuid({ message: "Invalid UUID provided" });
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
var
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
76
|
+
var websiteSchema = import_zod.z.object({
|
|
77
|
+
type: import_zod.z.enum(
|
|
78
|
+
[
|
|
79
|
+
"traditional",
|
|
80
|
+
"digital-collection",
|
|
81
|
+
"plum",
|
|
82
|
+
"cedar",
|
|
83
|
+
"elm",
|
|
84
|
+
"maple",
|
|
85
|
+
"oak",
|
|
86
|
+
"palm"
|
|
87
|
+
],
|
|
88
|
+
{ message: "Invalid website type" }
|
|
89
|
+
),
|
|
90
|
+
status: import_zod.z.enum(
|
|
91
|
+
["development", "preview", "production"],
|
|
92
|
+
{ message: "Invalid website status" }
|
|
93
|
+
),
|
|
94
|
+
privacy: import_zod.z.enum(
|
|
95
|
+
["public", "password", "private"],
|
|
96
|
+
{ message: "Invalid website privacy" }
|
|
97
|
+
)
|
|
98
|
+
});
|
|
99
|
+
var componentSchema = import_zod.z.enum(
|
|
100
|
+
[
|
|
101
|
+
"annotated-document",
|
|
102
|
+
"annotated-image",
|
|
103
|
+
"bibliography",
|
|
104
|
+
"blog",
|
|
105
|
+
"button",
|
|
106
|
+
"collection",
|
|
107
|
+
"empty-space",
|
|
108
|
+
"filter-categories",
|
|
109
|
+
"iframe",
|
|
110
|
+
"iiif-viewer",
|
|
111
|
+
"image",
|
|
112
|
+
"image-gallery",
|
|
113
|
+
"n-columns",
|
|
114
|
+
"n-rows",
|
|
115
|
+
"network-graph",
|
|
116
|
+
"search-bar",
|
|
117
|
+
"table",
|
|
118
|
+
"text",
|
|
119
|
+
"timeline",
|
|
120
|
+
"video"
|
|
121
|
+
],
|
|
122
|
+
{ message: "Invalid component" }
|
|
123
|
+
);
|
|
124
|
+
var categorySchema = import_zod.z.enum([
|
|
125
|
+
"resource",
|
|
126
|
+
"spatialUnit",
|
|
127
|
+
"concept",
|
|
128
|
+
"period",
|
|
129
|
+
"bibliography",
|
|
130
|
+
"person",
|
|
131
|
+
"propertyValue",
|
|
132
|
+
"set",
|
|
133
|
+
"tree"
|
|
134
|
+
]);
|
|
135
|
+
var renderOptionsSchema = import_zod.z.string().transform((str) => str.split(" ")).pipe(
|
|
136
|
+
import_zod.z.array(
|
|
137
|
+
import_zod.z.enum([
|
|
115
138
|
"bold",
|
|
116
139
|
"italic",
|
|
117
140
|
"underline"
|
|
118
141
|
])
|
|
119
142
|
)
|
|
120
143
|
);
|
|
121
|
-
var whitespaceSchema =
|
|
122
|
-
|
|
123
|
-
|
|
144
|
+
var whitespaceSchema = import_zod.z.string().transform((str) => str.split(" ")).pipe(
|
|
145
|
+
import_zod.z.array(
|
|
146
|
+
import_zod.z.enum([
|
|
124
147
|
"newline",
|
|
125
148
|
"trailing",
|
|
126
149
|
"leading"
|
|
127
150
|
])
|
|
128
151
|
)
|
|
129
152
|
);
|
|
130
|
-
var emailSchema =
|
|
153
|
+
var emailSchema = import_zod.z.string().email({ message: "Invalid email" });
|
|
154
|
+
|
|
155
|
+
// src/utils/helpers.ts
|
|
156
|
+
function getItemCategory(keys) {
|
|
157
|
+
const categoryFound = keys.find(
|
|
158
|
+
(key) => categorySchema.safeParse(key).success
|
|
159
|
+
);
|
|
160
|
+
if (!categoryFound) {
|
|
161
|
+
const unknownKey = keys.find(
|
|
162
|
+
(key) => ![
|
|
163
|
+
"uuid",
|
|
164
|
+
"uuidBelongsTo",
|
|
165
|
+
"belongsTo",
|
|
166
|
+
"publicationDateTime",
|
|
167
|
+
"metadata",
|
|
168
|
+
"languages"
|
|
169
|
+
].includes(key)
|
|
170
|
+
);
|
|
171
|
+
throw new Error(`Invalid OCHRE data; found unexpected "${unknownKey}" key`);
|
|
172
|
+
}
|
|
173
|
+
const categoryKey = categorySchema.parse(categoryFound);
|
|
174
|
+
return categoryKey;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// src/utils/getters.ts
|
|
178
|
+
var DEFAULT_OPTIONS = {
|
|
179
|
+
searchNestedProperties: false
|
|
180
|
+
};
|
|
181
|
+
function getPropertyByLabel(properties, label, options = DEFAULT_OPTIONS) {
|
|
182
|
+
const { searchNestedProperties } = options;
|
|
183
|
+
const property = properties.find((property2) => property2.label === label);
|
|
184
|
+
if (property) {
|
|
185
|
+
return property;
|
|
186
|
+
}
|
|
187
|
+
if (searchNestedProperties) {
|
|
188
|
+
for (const property2 of properties) {
|
|
189
|
+
if (property2.properties.length > 0) {
|
|
190
|
+
const nestedResult = getPropertyByLabel(property2.properties, label, {
|
|
191
|
+
searchNestedProperties
|
|
192
|
+
});
|
|
193
|
+
if (nestedResult) {
|
|
194
|
+
return nestedResult;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
function getPropertyValuesByLabel(properties, label, options = DEFAULT_OPTIONS) {
|
|
202
|
+
const { searchNestedProperties } = options;
|
|
203
|
+
const property = properties.find((property2) => property2.label === label);
|
|
204
|
+
if (property) {
|
|
205
|
+
return property.values.map((value) => value.content);
|
|
206
|
+
}
|
|
207
|
+
if (searchNestedProperties) {
|
|
208
|
+
for (const property2 of properties) {
|
|
209
|
+
if (property2.properties.length > 0) {
|
|
210
|
+
const nestedResult = getPropertyValuesByLabel(
|
|
211
|
+
property2.properties,
|
|
212
|
+
label,
|
|
213
|
+
{ searchNestedProperties }
|
|
214
|
+
);
|
|
215
|
+
if (nestedResult) {
|
|
216
|
+
return nestedResult;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
function getPropertyValueByLabel(properties, label, options = DEFAULT_OPTIONS) {
|
|
224
|
+
const { searchNestedProperties } = options;
|
|
225
|
+
const values = getPropertyValuesByLabel(properties, label, {
|
|
226
|
+
searchNestedProperties
|
|
227
|
+
});
|
|
228
|
+
if (values !== null && values.length > 0) {
|
|
229
|
+
return values[0];
|
|
230
|
+
}
|
|
231
|
+
if (searchNestedProperties) {
|
|
232
|
+
for (const property of properties) {
|
|
233
|
+
if (property.properties.length > 0) {
|
|
234
|
+
const nestedResult = getPropertyValueByLabel(
|
|
235
|
+
property.properties,
|
|
236
|
+
label,
|
|
237
|
+
{ searchNestedProperties }
|
|
238
|
+
);
|
|
239
|
+
if (nestedResult !== null) {
|
|
240
|
+
return nestedResult;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
function getAllPropertyLabels(properties, options = DEFAULT_OPTIONS) {
|
|
248
|
+
const { searchNestedProperties } = options;
|
|
249
|
+
const labels = /* @__PURE__ */ new Set();
|
|
250
|
+
for (const property of properties) {
|
|
251
|
+
labels.add(property.label);
|
|
252
|
+
if (property.properties.length > 0 && searchNestedProperties) {
|
|
253
|
+
const nestedLabels = getAllPropertyLabels(property.properties, {
|
|
254
|
+
searchNestedProperties: true
|
|
255
|
+
});
|
|
256
|
+
for (const label of nestedLabels) {
|
|
257
|
+
labels.add(label);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return [...labels];
|
|
262
|
+
}
|
|
263
|
+
function filterProperties(property, filter, options = DEFAULT_OPTIONS) {
|
|
264
|
+
const { searchNestedProperties } = options;
|
|
265
|
+
const isAllFields = filter.label.toLocaleLowerCase("en-US") === "all fields";
|
|
266
|
+
if (isAllFields || property.label.toLocaleLowerCase("en-US") === filter.label.toLocaleLowerCase("en-US")) {
|
|
267
|
+
let isFound = property.values.some((value) => {
|
|
268
|
+
if (value.content === null) {
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
if (typeof value.content === "string") {
|
|
272
|
+
if (typeof filter.value !== "string") {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
return value.content.toLocaleLowerCase("en-US").includes(filter.value.toLocaleLowerCase("en-US"));
|
|
276
|
+
}
|
|
277
|
+
if (typeof value.content === "number") {
|
|
278
|
+
if (typeof filter.value !== "number") {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
return value.content === filter.value;
|
|
282
|
+
}
|
|
283
|
+
if (typeof value.content === "boolean") {
|
|
284
|
+
if (typeof filter.value !== "boolean") {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
return value.booleanValue === filter.value;
|
|
288
|
+
}
|
|
289
|
+
if (value.content instanceof Date) {
|
|
290
|
+
if (!(filter.value instanceof Date)) {
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
return value.content.getTime() === filter.value.getTime();
|
|
294
|
+
}
|
|
295
|
+
return false;
|
|
296
|
+
});
|
|
297
|
+
if (!isFound && searchNestedProperties) {
|
|
298
|
+
isFound = property.properties.some(
|
|
299
|
+
(property2) => filterProperties(property2, filter, { searchNestedProperties: true })
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
return isFound;
|
|
303
|
+
}
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// src/utils/string.ts
|
|
131
308
|
function getStringItemByLanguage(content, language) {
|
|
132
309
|
const stringItemToFind = content.find((item) => item.lang === language);
|
|
133
310
|
return stringItemToFind ?? null;
|
|
@@ -370,267 +547,42 @@ function parseStringDocumentItem(item, footnotes) {
|
|
|
370
547
|
}
|
|
371
548
|
}
|
|
372
549
|
return returnString.replaceAll(/^(\d+)\./gm, String.raw`$1\.`);
|
|
373
|
-
}
|
|
374
|
-
function parseStringContent(content, language = "eng") {
|
|
375
|
-
switch (typeof content.content) {
|
|
376
|
-
case "string":
|
|
377
|
-
case "number":
|
|
378
|
-
case "boolean": {
|
|
379
|
-
return parseFakeString(content.content);
|
|
380
|
-
}
|
|
381
|
-
case "object": {
|
|
382
|
-
if (Array.isArray(content.content)) {
|
|
383
|
-
const stringItem = getStringItemByLanguage(content.content, language);
|
|
384
|
-
if (stringItem) {
|
|
385
|
-
return parseStringItem(stringItem);
|
|
386
|
-
} else {
|
|
387
|
-
const returnStringItem = content.content[0];
|
|
388
|
-
if (!returnStringItem) {
|
|
389
|
-
throw new Error(
|
|
390
|
-
`No string item found for language \u201C${language}\u201D in the following content:
|
|
391
|
-
${JSON.stringify(
|
|
392
|
-
content.content
|
|
393
|
-
)}.`
|
|
394
|
-
);
|
|
395
|
-
}
|
|
396
|
-
return parseStringItem(returnStringItem);
|
|
397
|
-
}
|
|
398
|
-
} else {
|
|
399
|
-
return parseStringItem(content.content);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
default: {
|
|
403
|
-
return String(content.content).replaceAll(/^(\d+)\./gm, String.raw`$1\.`);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
// src/utils/
|
|
409
|
-
async function fetchResource(uuid) {
|
|
410
|
-
try {
|
|
411
|
-
const [error, dataRaw] = await fetchByUuid(uuid);
|
|
412
|
-
if (error !== null) {
|
|
413
|
-
throw new Error(error);
|
|
414
|
-
}
|
|
415
|
-
if (!("resource" in dataRaw.ochre)) {
|
|
416
|
-
throw new Error(
|
|
417
|
-
"Invalid OCHRE data: API response missing 'resource' key"
|
|
418
|
-
);
|
|
419
|
-
}
|
|
420
|
-
const resourceItem = parseResource(dataRaw.ochre.resource);
|
|
421
|
-
const data = {
|
|
422
|
-
uuid: parseFakeString(dataRaw.ochre.uuid),
|
|
423
|
-
publicationDateTime: new Date(dataRaw.ochre.publicationDateTime),
|
|
424
|
-
belongsTo: {
|
|
425
|
-
uuid: dataRaw.ochre.uuidBelongsTo,
|
|
426
|
-
abbreviation: parseFakeString(dataRaw.ochre.belongsTo)
|
|
427
|
-
},
|
|
428
|
-
metadata: parseMetadata(dataRaw.ochre.metadata),
|
|
429
|
-
item: resourceItem
|
|
430
|
-
};
|
|
431
|
-
return { metadata: data.metadata, resource: data.item };
|
|
432
|
-
} catch (error) {
|
|
433
|
-
console.error(error);
|
|
434
|
-
return null;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
// src/utils/getters.ts
|
|
439
|
-
var DEFAULT_OPTIONS = {
|
|
440
|
-
searchNestedProperties: false
|
|
441
|
-
};
|
|
442
|
-
function getPropertyByLabel(properties, label, options = DEFAULT_OPTIONS) {
|
|
443
|
-
const { searchNestedProperties } = options;
|
|
444
|
-
const property = properties.find((property2) => property2.label === label);
|
|
445
|
-
if (property) {
|
|
446
|
-
return property;
|
|
447
|
-
}
|
|
448
|
-
if (searchNestedProperties) {
|
|
449
|
-
for (const property2 of properties) {
|
|
450
|
-
if (property2.properties.length > 0) {
|
|
451
|
-
const nestedResult = getPropertyByLabel(property2.properties, label, {
|
|
452
|
-
searchNestedProperties
|
|
453
|
-
});
|
|
454
|
-
if (nestedResult) {
|
|
455
|
-
return nestedResult;
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
return null;
|
|
461
|
-
}
|
|
462
|
-
function getPropertyValuesByLabel(properties, label, options = DEFAULT_OPTIONS) {
|
|
463
|
-
const { searchNestedProperties } = options;
|
|
464
|
-
const property = properties.find((property2) => property2.label === label);
|
|
465
|
-
if (property) {
|
|
466
|
-
return property.values.map((value) => value.content);
|
|
467
|
-
}
|
|
468
|
-
if (searchNestedProperties) {
|
|
469
|
-
for (const property2 of properties) {
|
|
470
|
-
if (property2.properties.length > 0) {
|
|
471
|
-
const nestedResult = getPropertyValuesByLabel(
|
|
472
|
-
property2.properties,
|
|
473
|
-
label,
|
|
474
|
-
{ searchNestedProperties }
|
|
475
|
-
);
|
|
476
|
-
if (nestedResult) {
|
|
477
|
-
return nestedResult;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
return null;
|
|
483
|
-
}
|
|
484
|
-
function getPropertyValueByLabel(properties, label, options = DEFAULT_OPTIONS) {
|
|
485
|
-
const { searchNestedProperties } = options;
|
|
486
|
-
const values = getPropertyValuesByLabel(properties, label, {
|
|
487
|
-
searchNestedProperties
|
|
488
|
-
});
|
|
489
|
-
if (values !== null && values.length > 0) {
|
|
490
|
-
return values[0];
|
|
491
|
-
}
|
|
492
|
-
if (searchNestedProperties) {
|
|
493
|
-
for (const property of properties) {
|
|
494
|
-
if (property.properties.length > 0) {
|
|
495
|
-
const nestedResult = getPropertyValueByLabel(
|
|
496
|
-
property.properties,
|
|
497
|
-
label,
|
|
498
|
-
{ searchNestedProperties }
|
|
499
|
-
);
|
|
500
|
-
if (nestedResult !== null) {
|
|
501
|
-
return nestedResult;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
return null;
|
|
507
|
-
}
|
|
508
|
-
function getAllPropertyLabels(properties, options = DEFAULT_OPTIONS) {
|
|
509
|
-
const { searchNestedProperties } = options;
|
|
510
|
-
const labels = /* @__PURE__ */ new Set();
|
|
511
|
-
for (const property of properties) {
|
|
512
|
-
labels.add(property.label);
|
|
513
|
-
if (property.properties.length > 0 && searchNestedProperties) {
|
|
514
|
-
const nestedLabels = getAllPropertyLabels(property.properties, {
|
|
515
|
-
searchNestedProperties: true
|
|
516
|
-
});
|
|
517
|
-
for (const label of nestedLabels) {
|
|
518
|
-
labels.add(label);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
return [...labels];
|
|
523
|
-
}
|
|
524
|
-
function filterProperties(property, filter, options = DEFAULT_OPTIONS) {
|
|
525
|
-
const { searchNestedProperties } = options;
|
|
526
|
-
const isAllFields = filter.label.toLocaleLowerCase("en-US") === "all fields";
|
|
527
|
-
if (isAllFields || property.label.toLocaleLowerCase("en-US") === filter.label.toLocaleLowerCase("en-US")) {
|
|
528
|
-
let isFound = property.values.some((value) => {
|
|
529
|
-
if (value.content === null) {
|
|
530
|
-
return false;
|
|
531
|
-
}
|
|
532
|
-
if (typeof value.content === "string") {
|
|
533
|
-
if (typeof filter.value !== "string") {
|
|
534
|
-
return false;
|
|
535
|
-
}
|
|
536
|
-
return value.content.toLocaleLowerCase("en-US").includes(filter.value.toLocaleLowerCase("en-US"));
|
|
537
|
-
}
|
|
538
|
-
if (typeof value.content === "number") {
|
|
539
|
-
if (typeof filter.value !== "number") {
|
|
540
|
-
return false;
|
|
541
|
-
}
|
|
542
|
-
return value.content === filter.value;
|
|
543
|
-
}
|
|
544
|
-
if (typeof value.content === "boolean") {
|
|
545
|
-
if (typeof filter.value !== "boolean") {
|
|
546
|
-
return false;
|
|
547
|
-
}
|
|
548
|
-
return value.booleanValue === filter.value;
|
|
549
|
-
}
|
|
550
|
-
if (value.content instanceof Date) {
|
|
551
|
-
if (!(filter.value instanceof Date)) {
|
|
552
|
-
return false;
|
|
553
|
-
}
|
|
554
|
-
return value.content.getTime() === filter.value.getTime();
|
|
555
|
-
}
|
|
556
|
-
return false;
|
|
557
|
-
});
|
|
558
|
-
if (!isFound && searchNestedProperties) {
|
|
559
|
-
isFound = property.properties.some(
|
|
560
|
-
(property2) => filterProperties(property2, filter, { searchNestedProperties: true })
|
|
561
|
-
);
|
|
562
|
-
}
|
|
563
|
-
return isFound;
|
|
564
|
-
}
|
|
565
|
-
return false;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
// src/utils/parse.ts
|
|
569
|
-
var websiteSchema = import_zod3.z.object({
|
|
570
|
-
type: import_zod3.z.enum(
|
|
571
|
-
[
|
|
572
|
-
"traditional",
|
|
573
|
-
"digital-collection",
|
|
574
|
-
"plum",
|
|
575
|
-
"cedar",
|
|
576
|
-
"elm",
|
|
577
|
-
"maple",
|
|
578
|
-
"oak",
|
|
579
|
-
"palm"
|
|
580
|
-
],
|
|
581
|
-
{ message: "Invalid website type" }
|
|
582
|
-
),
|
|
583
|
-
status: import_zod3.z.enum(
|
|
584
|
-
["development", "preview", "production"],
|
|
585
|
-
{ message: "Invalid website status" }
|
|
586
|
-
),
|
|
587
|
-
privacy: import_zod3.z.enum(
|
|
588
|
-
["public", "password", "private"],
|
|
589
|
-
{ message: "Invalid website privacy" }
|
|
590
|
-
)
|
|
591
|
-
});
|
|
592
|
-
var resourceTypeSchema = import_zod3.z.enum(
|
|
593
|
-
[
|
|
594
|
-
"audio",
|
|
595
|
-
"document",
|
|
596
|
-
"drawing",
|
|
597
|
-
"FITS",
|
|
598
|
-
"geospatial",
|
|
599
|
-
"IIIF",
|
|
600
|
-
"image",
|
|
601
|
-
"model",
|
|
602
|
-
"PTM",
|
|
603
|
-
"TEI",
|
|
604
|
-
"video",
|
|
605
|
-
"webpage"
|
|
606
|
-
],
|
|
607
|
-
{ message: "Invalid resource type" }
|
|
608
|
-
);
|
|
609
|
-
var componentSchema = import_zod3.z.enum(
|
|
610
|
-
[
|
|
611
|
-
"annotated-document",
|
|
612
|
-
"annotated-image",
|
|
613
|
-
"bibliography",
|
|
614
|
-
"blog",
|
|
615
|
-
"button",
|
|
616
|
-
"collection",
|
|
617
|
-
"empty-space",
|
|
618
|
-
"filter-categories",
|
|
619
|
-
"iframe",
|
|
620
|
-
"iiif-viewer",
|
|
621
|
-
"image",
|
|
622
|
-
"image-gallery",
|
|
623
|
-
"n-columns",
|
|
624
|
-
"n-rows",
|
|
625
|
-
"network-graph",
|
|
626
|
-
"search-bar",
|
|
627
|
-
"table",
|
|
628
|
-
"text",
|
|
629
|
-
"timeline",
|
|
630
|
-
"video"
|
|
631
|
-
],
|
|
632
|
-
{ message: "Invalid component" }
|
|
633
|
-
);
|
|
550
|
+
}
|
|
551
|
+
function parseStringContent(content, language = "eng") {
|
|
552
|
+
switch (typeof content.content) {
|
|
553
|
+
case "string":
|
|
554
|
+
case "number":
|
|
555
|
+
case "boolean": {
|
|
556
|
+
return parseFakeString(content.content);
|
|
557
|
+
}
|
|
558
|
+
case "object": {
|
|
559
|
+
if (Array.isArray(content.content)) {
|
|
560
|
+
const stringItem = getStringItemByLanguage(content.content, language);
|
|
561
|
+
if (stringItem) {
|
|
562
|
+
return parseStringItem(stringItem);
|
|
563
|
+
} else {
|
|
564
|
+
const returnStringItem = content.content[0];
|
|
565
|
+
if (!returnStringItem) {
|
|
566
|
+
throw new Error(
|
|
567
|
+
`No string item found for language \u201C${language}\u201D in the following content:
|
|
568
|
+
${JSON.stringify(
|
|
569
|
+
content.content
|
|
570
|
+
)}.`
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
return parseStringItem(returnStringItem);
|
|
574
|
+
}
|
|
575
|
+
} else {
|
|
576
|
+
return parseStringItem(content.content);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
default: {
|
|
580
|
+
return String(content.content).replaceAll(/^(\d+)\./gm, String.raw`$1\.`);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// src/utils/parse.ts
|
|
634
586
|
function parseIdentification(identification) {
|
|
635
587
|
try {
|
|
636
588
|
const returnIdentification = {
|
|
@@ -1040,13 +992,10 @@ function parsePeriods(periods) {
|
|
|
1040
992
|
function parseBibliography(bibliography) {
|
|
1041
993
|
let resource = null;
|
|
1042
994
|
if (bibliography.source?.resource) {
|
|
1043
|
-
const resourceType = resourceTypeSchema.parse(
|
|
1044
|
-
bibliography.source.resource.type
|
|
1045
|
-
);
|
|
1046
995
|
resource = {
|
|
1047
996
|
uuid: bibliography.source.resource.uuid,
|
|
1048
997
|
publicationDateTime: bibliography.source.resource.publicationDateTime ? new Date(bibliography.source.resource.publicationDateTime) : null,
|
|
1049
|
-
type:
|
|
998
|
+
type: bibliography.source.resource.type,
|
|
1050
999
|
identification: parseIdentification(
|
|
1051
1000
|
bibliography.source.resource.identification
|
|
1052
1001
|
)
|
|
@@ -1218,54 +1167,83 @@ function parseTree(tree) {
|
|
|
1218
1167
|
return returnTree;
|
|
1219
1168
|
}
|
|
1220
1169
|
function parseSet(set) {
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
let
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1170
|
+
if (typeof set.items === "string") {
|
|
1171
|
+
throw new TypeError("Invalid OCHRE data: Set has no items");
|
|
1172
|
+
}
|
|
1173
|
+
const itemCategory = getItemCategory(Object.keys(set.items));
|
|
1174
|
+
let items = [];
|
|
1175
|
+
switch (itemCategory) {
|
|
1176
|
+
case "resource": {
|
|
1177
|
+
if (!("resource" in set.items)) {
|
|
1178
|
+
throw new Error("Invalid OCHRE data: Set has no resources");
|
|
1179
|
+
}
|
|
1180
|
+
items = parseResources(
|
|
1181
|
+
Array.isArray(set.items.resource) ? set.items.resource : [set.items.resource]
|
|
1182
|
+
);
|
|
1183
|
+
break;
|
|
1184
|
+
}
|
|
1185
|
+
case "spatialUnit": {
|
|
1186
|
+
if (!("spatialUnit" in set.items)) {
|
|
1187
|
+
throw new Error("Invalid OCHRE data: Set has no spatial units");
|
|
1188
|
+
}
|
|
1189
|
+
items = parseSpatialUnits(
|
|
1190
|
+
Array.isArray(set.items.spatialUnit) ? set.items.spatialUnit : [set.items.spatialUnit]
|
|
1191
|
+
);
|
|
1192
|
+
break;
|
|
1193
|
+
}
|
|
1194
|
+
case "concept": {
|
|
1195
|
+
if (!("concept" in set.items)) {
|
|
1196
|
+
throw new Error("Invalid OCHRE data: Set has no concepts");
|
|
1197
|
+
}
|
|
1198
|
+
items = parseConcepts(
|
|
1199
|
+
Array.isArray(set.items.concept) ? set.items.concept : [set.items.concept]
|
|
1200
|
+
);
|
|
1201
|
+
break;
|
|
1202
|
+
}
|
|
1203
|
+
case "period": {
|
|
1204
|
+
if (!("period" in set.items)) {
|
|
1205
|
+
throw new Error("Invalid OCHRE data: Set has no periods");
|
|
1206
|
+
}
|
|
1207
|
+
items = parsePeriods(
|
|
1208
|
+
Array.isArray(set.items.period) ? set.items.period : [set.items.period]
|
|
1209
|
+
);
|
|
1210
|
+
break;
|
|
1211
|
+
}
|
|
1212
|
+
case "bibliography": {
|
|
1213
|
+
if (!("bibliography" in set.items)) {
|
|
1214
|
+
throw new Error("Invalid OCHRE data: Set has no bibliographies");
|
|
1215
|
+
}
|
|
1216
|
+
items = parseBibliographies(
|
|
1217
|
+
Array.isArray(set.items.bibliography) ? set.items.bibliography : [set.items.bibliography]
|
|
1218
|
+
);
|
|
1219
|
+
break;
|
|
1220
|
+
}
|
|
1221
|
+
case "person": {
|
|
1222
|
+
if (!("person" in set.items)) {
|
|
1223
|
+
throw new Error("Invalid OCHRE data: Set has no persons");
|
|
1224
|
+
}
|
|
1225
|
+
items = parsePersons(
|
|
1226
|
+
Array.isArray(set.items.person) ? set.items.person : [set.items.person]
|
|
1227
|
+
);
|
|
1228
|
+
break;
|
|
1229
|
+
}
|
|
1230
|
+
case "propertyValue": {
|
|
1231
|
+
if (!("propertyValue" in set.items)) {
|
|
1232
|
+
throw new Error("Invalid OCHRE data: Set has no property values");
|
|
1233
|
+
}
|
|
1234
|
+
items = parsePropertyValues(
|
|
1235
|
+
Array.isArray(set.items.propertyValue) ? set.items.propertyValue : [set.items.propertyValue]
|
|
1236
|
+
);
|
|
1237
|
+
break;
|
|
1238
|
+
}
|
|
1239
|
+
default: {
|
|
1240
|
+
throw new Error("Invalid OCHRE data: Set has no items or is malformed");
|
|
1241
|
+
}
|
|
1265
1242
|
}
|
|
1266
1243
|
return {
|
|
1267
1244
|
uuid: set.uuid,
|
|
1268
1245
|
category: "set",
|
|
1246
|
+
itemCategory,
|
|
1269
1247
|
publicationDateTime: set.publicationDateTime ? new Date(set.publicationDateTime) : null,
|
|
1270
1248
|
date: set.date != null ? new Date(set.date) : null,
|
|
1271
1249
|
license: parseLicense(set.availability),
|
|
@@ -1277,24 +1255,15 @@ function parseSet(set) {
|
|
|
1277
1255
|
) : [],
|
|
1278
1256
|
type: set.type,
|
|
1279
1257
|
number: set.n,
|
|
1280
|
-
items
|
|
1281
|
-
resources,
|
|
1282
|
-
spatialUnits,
|
|
1283
|
-
concepts,
|
|
1284
|
-
periods,
|
|
1285
|
-
bibliographies,
|
|
1286
|
-
persons,
|
|
1287
|
-
propertyValues
|
|
1288
|
-
}
|
|
1258
|
+
items
|
|
1289
1259
|
};
|
|
1290
1260
|
}
|
|
1291
|
-
function parseResource(resource
|
|
1292
|
-
const resourceType = resourceTypeSchema.parse(resource.type);
|
|
1261
|
+
function parseResource(resource) {
|
|
1293
1262
|
const returnResource = {
|
|
1294
1263
|
uuid: resource.uuid,
|
|
1295
1264
|
category: "resource",
|
|
1296
1265
|
publicationDateTime: resource.publicationDateTime ? new Date(resource.publicationDateTime) : null,
|
|
1297
|
-
type:
|
|
1266
|
+
type: resource.type,
|
|
1298
1267
|
number: resource.n,
|
|
1299
1268
|
format: resource.format ?? null,
|
|
1300
1269
|
context: "context" in resource && resource.context ? parseContext(resource.context) : null,
|
|
@@ -1332,34 +1301,20 @@ function parseResource(resource, isNested = false) {
|
|
|
1332
1301
|
Array.isArray(resource.citedBibliography.reference) ? resource.citedBibliography.reference : [resource.citedBibliography.reference]
|
|
1333
1302
|
) : [],
|
|
1334
1303
|
resources: resource.resource ? parseResources(
|
|
1335
|
-
Array.isArray(resource.resource) ? resource.resource : [resource.resource]
|
|
1336
|
-
true
|
|
1304
|
+
Array.isArray(resource.resource) ? resource.resource : [resource.resource]
|
|
1337
1305
|
) : []
|
|
1338
1306
|
};
|
|
1339
|
-
if (isNested) {
|
|
1340
|
-
const returnNestedResource = {
|
|
1341
|
-
...returnResource,
|
|
1342
|
-
publicationDateTime: null,
|
|
1343
|
-
context: null,
|
|
1344
|
-
license: null,
|
|
1345
|
-
copyright: null
|
|
1346
|
-
};
|
|
1347
|
-
delete returnNestedResource.publicationDateTime;
|
|
1348
|
-
delete returnNestedResource.license;
|
|
1349
|
-
delete returnNestedResource.copyright;
|
|
1350
|
-
return returnNestedResource;
|
|
1351
|
-
}
|
|
1352
1307
|
return returnResource;
|
|
1353
1308
|
}
|
|
1354
|
-
function parseResources(resources
|
|
1309
|
+
function parseResources(resources) {
|
|
1355
1310
|
const returnResources = [];
|
|
1356
1311
|
const resourcesToParse = Array.isArray(resources) ? resources : [resources];
|
|
1357
1312
|
for (const resource of resourcesToParse) {
|
|
1358
|
-
returnResources.push(parseResource(resource
|
|
1313
|
+
returnResources.push(parseResource(resource));
|
|
1359
1314
|
}
|
|
1360
1315
|
return returnResources;
|
|
1361
1316
|
}
|
|
1362
|
-
function parseSpatialUnit(spatialUnit
|
|
1317
|
+
function parseSpatialUnit(spatialUnit) {
|
|
1363
1318
|
const returnSpatialUnit = {
|
|
1364
1319
|
uuid: spatialUnit.uuid,
|
|
1365
1320
|
category: "spatialUnit",
|
|
@@ -1379,34 +1334,22 @@ function parseSpatialUnit(spatialUnit, isNested = false) {
|
|
|
1379
1334
|
) : spatialUnit.observation ? [parseObservation(spatialUnit.observation)] : [],
|
|
1380
1335
|
events: "events" in spatialUnit && spatialUnit.events ? parseEvents(
|
|
1381
1336
|
Array.isArray(spatialUnit.events.event) ? spatialUnit.events.event : [spatialUnit.events.event]
|
|
1337
|
+
) : [],
|
|
1338
|
+
properties: "properties" in spatialUnit && spatialUnit.properties ? parseProperties(
|
|
1339
|
+
Array.isArray(spatialUnit.properties.property) ? spatialUnit.properties.property : [spatialUnit.properties.property]
|
|
1382
1340
|
) : []
|
|
1383
1341
|
};
|
|
1384
|
-
if (isNested) {
|
|
1385
|
-
const returnNestedSpatialUnit = {
|
|
1386
|
-
...returnSpatialUnit,
|
|
1387
|
-
publicationDateTime: null,
|
|
1388
|
-
license: null,
|
|
1389
|
-
properties: "properties" in spatialUnit && spatialUnit.properties ? parseProperties(
|
|
1390
|
-
Array.isArray(spatialUnit.properties.property) ? spatialUnit.properties.property : [spatialUnit.properties.property]
|
|
1391
|
-
) : []
|
|
1392
|
-
};
|
|
1393
|
-
delete returnNestedSpatialUnit.publicationDateTime;
|
|
1394
|
-
delete returnNestedSpatialUnit.license;
|
|
1395
|
-
return returnNestedSpatialUnit;
|
|
1396
|
-
}
|
|
1397
1342
|
return returnSpatialUnit;
|
|
1398
1343
|
}
|
|
1399
|
-
function parseSpatialUnits(spatialUnits
|
|
1344
|
+
function parseSpatialUnits(spatialUnits) {
|
|
1400
1345
|
const returnSpatialUnits = [];
|
|
1401
1346
|
const spatialUnitsToParse = Array.isArray(spatialUnits) ? spatialUnits : [spatialUnits];
|
|
1402
1347
|
for (const spatialUnit of spatialUnitsToParse) {
|
|
1403
|
-
returnSpatialUnits.push(
|
|
1404
|
-
parseSpatialUnit(spatialUnit, isNested)
|
|
1405
|
-
);
|
|
1348
|
+
returnSpatialUnits.push(parseSpatialUnit(spatialUnit));
|
|
1406
1349
|
}
|
|
1407
1350
|
return returnSpatialUnits;
|
|
1408
1351
|
}
|
|
1409
|
-
function parseConcept(concept
|
|
1352
|
+
function parseConcept(concept) {
|
|
1410
1353
|
const returnConcept = {
|
|
1411
1354
|
uuid: concept.uuid,
|
|
1412
1355
|
category: "concept",
|
|
@@ -1419,17 +1362,6 @@ function parseConcept(concept, isNested = false) {
|
|
|
1419
1362
|
Array.isArray(concept.interpretations.interpretation) ? concept.interpretations.interpretation : [concept.interpretations.interpretation]
|
|
1420
1363
|
)
|
|
1421
1364
|
};
|
|
1422
|
-
if (isNested) {
|
|
1423
|
-
const returnNestedConcept = {
|
|
1424
|
-
...returnConcept,
|
|
1425
|
-
publicationDateTime: null,
|
|
1426
|
-
context: null,
|
|
1427
|
-
license: null
|
|
1428
|
-
};
|
|
1429
|
-
delete returnNestedConcept.publicationDateTime;
|
|
1430
|
-
delete returnNestedConcept.license;
|
|
1431
|
-
return returnNestedConcept;
|
|
1432
|
-
}
|
|
1433
1365
|
return returnConcept;
|
|
1434
1366
|
}
|
|
1435
1367
|
var parseWebpageResources = async (webpageResources, type) => {
|
|
@@ -1472,11 +1404,11 @@ var parseWebpageResources = async (webpageResources, type) => {
|
|
|
1472
1404
|
}
|
|
1473
1405
|
return returnElements;
|
|
1474
1406
|
};
|
|
1475
|
-
function parseConcepts(concepts
|
|
1407
|
+
function parseConcepts(concepts) {
|
|
1476
1408
|
const returnConcepts = [];
|
|
1477
1409
|
const conceptsToParse = Array.isArray(concepts) ? concepts : [concepts];
|
|
1478
1410
|
for (const concept of conceptsToParse) {
|
|
1479
|
-
returnConcepts.push(parseConcept(concept
|
|
1411
|
+
returnConcepts.push(parseConcept(concept));
|
|
1480
1412
|
}
|
|
1481
1413
|
return returnConcepts;
|
|
1482
1414
|
}
|
|
@@ -1497,11 +1429,11 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1497
1429
|
if (document === null) {
|
|
1498
1430
|
const documentLink = links.find((link) => link.type === "internalDocument");
|
|
1499
1431
|
if (documentLink) {
|
|
1500
|
-
const
|
|
1501
|
-
if (
|
|
1432
|
+
const { item, error } = await fetchItem(documentLink.uuid, "resource");
|
|
1433
|
+
if (error !== null) {
|
|
1502
1434
|
throw new Error("Failed to fetch OCHRE data");
|
|
1503
1435
|
}
|
|
1504
|
-
document =
|
|
1436
|
+
document = item.document;
|
|
1505
1437
|
}
|
|
1506
1438
|
}
|
|
1507
1439
|
switch (componentName) {
|
|
@@ -2542,301 +2474,145 @@ async function parseWebsite(websiteTree, projectName, website) {
|
|
|
2542
2474
|
};
|
|
2543
2475
|
}
|
|
2544
2476
|
|
|
2545
|
-
// src/utils/fetchers/
|
|
2546
|
-
async function
|
|
2547
|
-
try {
|
|
2548
|
-
const [error, dataRaw] = await fetchByUuid(uuid);
|
|
2549
|
-
if (error !== null) {
|
|
2550
|
-
throw new Error(error);
|
|
2551
|
-
}
|
|
2552
|
-
if (!("bibliography" in dataRaw.ochre)) {
|
|
2553
|
-
throw new Error(
|
|
2554
|
-
"Invalid OCHRE data: API response missing 'bibliography' key"
|
|
2555
|
-
);
|
|
2556
|
-
}
|
|
2557
|
-
const bibliographyItem = parseBibliography(dataRaw.ochre.bibliography);
|
|
2558
|
-
const data = {
|
|
2559
|
-
uuid: parseFakeString(dataRaw.ochre.uuid),
|
|
2560
|
-
publicationDateTime: new Date(dataRaw.ochre.publicationDateTime),
|
|
2561
|
-
belongsTo: {
|
|
2562
|
-
uuid: dataRaw.ochre.uuidBelongsTo,
|
|
2563
|
-
abbreviation: parseFakeString(dataRaw.ochre.belongsTo)
|
|
2564
|
-
},
|
|
2565
|
-
metadata: parseMetadata(dataRaw.ochre.metadata),
|
|
2566
|
-
item: bibliographyItem
|
|
2567
|
-
};
|
|
2568
|
-
return { metadata: data.metadata, bibliography: data.item };
|
|
2569
|
-
} catch (error) {
|
|
2570
|
-
console.error(error);
|
|
2571
|
-
return null;
|
|
2572
|
-
}
|
|
2573
|
-
}
|
|
2574
|
-
|
|
2575
|
-
// src/utils/fetchers/concept.ts
|
|
2576
|
-
async function fetchConcept(uuid) {
|
|
2577
|
-
try {
|
|
2578
|
-
const [error, dataRaw] = await fetchByUuid(uuid);
|
|
2579
|
-
if (error !== null) {
|
|
2580
|
-
throw new Error(error);
|
|
2581
|
-
}
|
|
2582
|
-
if (!("concept" in dataRaw.ochre)) {
|
|
2583
|
-
throw new Error("Invalid OCHRE data: API response missing 'concept' key");
|
|
2584
|
-
}
|
|
2585
|
-
const conceptItem = parseConcept(dataRaw.ochre.concept);
|
|
2586
|
-
const data = {
|
|
2587
|
-
uuid: parseFakeString(dataRaw.ochre.uuid),
|
|
2588
|
-
publicationDateTime: new Date(dataRaw.ochre.publicationDateTime),
|
|
2589
|
-
belongsTo: {
|
|
2590
|
-
uuid: dataRaw.ochre.uuidBelongsTo,
|
|
2591
|
-
abbreviation: parseFakeString(dataRaw.ochre.belongsTo)
|
|
2592
|
-
},
|
|
2593
|
-
metadata: parseMetadata(dataRaw.ochre.metadata),
|
|
2594
|
-
item: conceptItem
|
|
2595
|
-
};
|
|
2596
|
-
return { metadata: data.metadata, concept: data.item };
|
|
2597
|
-
} catch (error) {
|
|
2598
|
-
console.error(error);
|
|
2599
|
-
return null;
|
|
2600
|
-
}
|
|
2601
|
-
}
|
|
2602
|
-
|
|
2603
|
-
// src/utils/fetchers/gallery.ts
|
|
2604
|
-
var import_zod4 = require("zod");
|
|
2605
|
-
var gallerySchema = import_zod4.z.object({
|
|
2606
|
-
uuid: import_zod4.z.string().uuid({ message: "Invalid UUID" }),
|
|
2607
|
-
filter: import_zod4.z.string().optional(),
|
|
2608
|
-
page: import_zod4.z.number().positive({ message: "Page must be positive" }),
|
|
2609
|
-
perPage: import_zod4.z.number().positive({ message: "Per page must be positive" })
|
|
2610
|
-
}).strict();
|
|
2611
|
-
async function fetchGallery(uuid, filter, page, perPage) {
|
|
2477
|
+
// src/utils/fetchers/uuid.ts
|
|
2478
|
+
async function fetchByUuid(uuid) {
|
|
2612
2479
|
try {
|
|
2613
|
-
const
|
|
2614
|
-
if (!parsed.success) {
|
|
2615
|
-
throw new Error(parsed.error.message);
|
|
2616
|
-
}
|
|
2480
|
+
const parsedUuid = uuidSchema.parse(uuid);
|
|
2617
2481
|
const response = await fetch(
|
|
2618
|
-
`https://ochre.lib.uchicago.edu/ochre?
|
|
2619
|
-
for $q in input()/ochre[@uuid='${uuid}']
|
|
2620
|
-
let $filtered := $q/tree/items/resource[contains(lower-case(identification/label), lower-case('${filter}'))]
|
|
2621
|
-
let $maxLength := count($filtered)
|
|
2622
|
-
return <gallery maxLength='{$maxLength}'>
|
|
2623
|
-
{$q/metadata/project}
|
|
2624
|
-
{$q/metadata/item}
|
|
2625
|
-
{$filtered[position() >= ${((page - 1) * perPage + 1).toString()} and position() < ${(page * perPage + 1).toString()}]}
|
|
2626
|
-
</gallery>
|
|
2627
|
-
`)}&format=json`
|
|
2482
|
+
`https://ochre.lib.uchicago.edu/ochre?uuid=${parsedUuid}&format=json&lang="*"`
|
|
2628
2483
|
);
|
|
2629
2484
|
if (!response.ok) {
|
|
2630
|
-
throw new Error("
|
|
2631
|
-
}
|
|
2632
|
-
const data = await response.json();
|
|
2633
|
-
if (!("gallery" in data.result)) {
|
|
2634
|
-
throw new Error("Failed to fetch gallery");
|
|
2485
|
+
throw new Error("Failed to fetch OCHRE data");
|
|
2635
2486
|
}
|
|
2636
|
-
const
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
const galleryProjectIdentification = parseIdentification(
|
|
2640
|
-
data.result.gallery.project.identification
|
|
2641
|
-
);
|
|
2642
|
-
const gallery = {
|
|
2643
|
-
identification: galleryIdentification,
|
|
2644
|
-
projectIdentification: galleryProjectIdentification,
|
|
2645
|
-
resources: data.result.gallery.resource ? Array.isArray(data.result.gallery.resource) ? parseResources(data.result.gallery.resource) : [parseResource(data.result.gallery.resource)] : [],
|
|
2646
|
-
maxLength: data.result.gallery.maxLength
|
|
2647
|
-
};
|
|
2648
|
-
return gallery;
|
|
2649
|
-
} catch (error) {
|
|
2650
|
-
console.error(error);
|
|
2651
|
-
return null;
|
|
2652
|
-
}
|
|
2653
|
-
}
|
|
2654
|
-
|
|
2655
|
-
// src/utils/fetchers/period.ts
|
|
2656
|
-
async function fetchPeriod(uuid) {
|
|
2657
|
-
try {
|
|
2658
|
-
const [error, dataRaw] = await fetchByUuid(uuid);
|
|
2659
|
-
if (error !== null) {
|
|
2660
|
-
throw new Error(error);
|
|
2487
|
+
const dataRaw = await response.json();
|
|
2488
|
+
if (!("ochre" in dataRaw)) {
|
|
2489
|
+
throw new Error("Invalid OCHRE data: API response missing 'ochre' key");
|
|
2661
2490
|
}
|
|
2662
|
-
|
|
2663
|
-
throw new Error("Invalid OCHRE data: API response missing 'period' key");
|
|
2664
|
-
}
|
|
2665
|
-
const periodItem = parsePeriod(dataRaw.ochre.period);
|
|
2666
|
-
const data = {
|
|
2667
|
-
uuid: parseFakeString(dataRaw.ochre.uuid),
|
|
2668
|
-
publicationDateTime: new Date(dataRaw.ochre.publicationDateTime),
|
|
2669
|
-
belongsTo: {
|
|
2670
|
-
uuid: dataRaw.ochre.uuidBelongsTo,
|
|
2671
|
-
abbreviation: parseFakeString(dataRaw.ochre.belongsTo)
|
|
2672
|
-
},
|
|
2673
|
-
metadata: parseMetadata(dataRaw.ochre.metadata),
|
|
2674
|
-
item: periodItem
|
|
2675
|
-
};
|
|
2676
|
-
return { metadata: data.metadata, period: data.item };
|
|
2491
|
+
return [null, dataRaw];
|
|
2677
2492
|
} catch (error) {
|
|
2678
|
-
|
|
2679
|
-
return null;
|
|
2493
|
+
return [error instanceof Error ? error.message : "Unknown error", null];
|
|
2680
2494
|
}
|
|
2681
2495
|
}
|
|
2682
2496
|
|
|
2683
|
-
// src/utils/fetchers/
|
|
2684
|
-
async function
|
|
2497
|
+
// src/utils/fetchers/item.ts
|
|
2498
|
+
async function fetchItem(uuid, category) {
|
|
2685
2499
|
try {
|
|
2686
|
-
const [error,
|
|
2500
|
+
const [error, data] = await fetchByUuid(uuid);
|
|
2687
2501
|
if (error !== null) {
|
|
2688
2502
|
throw new Error(error);
|
|
2689
2503
|
}
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2504
|
+
const categoryKey = getItemCategory(Object.keys(data.ochre));
|
|
2505
|
+
let item;
|
|
2506
|
+
switch (categoryKey) {
|
|
2507
|
+
case "resource": {
|
|
2508
|
+
if (!("resource" in data.ochre)) {
|
|
2509
|
+
throw new Error(
|
|
2510
|
+
"Invalid OCHRE data: API response missing 'resource' key"
|
|
2511
|
+
);
|
|
2512
|
+
}
|
|
2513
|
+
item = parseResource(data.ochre.resource);
|
|
2514
|
+
break;
|
|
2515
|
+
}
|
|
2516
|
+
case "spatialUnit": {
|
|
2517
|
+
if (!("spatialUnit" in data.ochre)) {
|
|
2518
|
+
throw new Error(
|
|
2519
|
+
"Invalid OCHRE data: API response missing 'spatialUnit' key"
|
|
2520
|
+
);
|
|
2521
|
+
}
|
|
2522
|
+
item = parseSpatialUnit(data.ochre.spatialUnit);
|
|
2523
|
+
break;
|
|
2524
|
+
}
|
|
2525
|
+
case "concept": {
|
|
2526
|
+
if (!("concept" in data.ochre)) {
|
|
2527
|
+
throw new Error(
|
|
2528
|
+
"Invalid OCHRE data: API response missing 'concept' key"
|
|
2529
|
+
);
|
|
2530
|
+
}
|
|
2531
|
+
item = parseConcept(data.ochre.concept);
|
|
2532
|
+
break;
|
|
2533
|
+
}
|
|
2534
|
+
case "period": {
|
|
2535
|
+
if (!("period" in data.ochre)) {
|
|
2536
|
+
throw new Error(
|
|
2537
|
+
"Invalid OCHRE data: API response missing 'period' key"
|
|
2538
|
+
);
|
|
2539
|
+
}
|
|
2540
|
+
item = parsePeriod(data.ochre.period);
|
|
2541
|
+
break;
|
|
2542
|
+
}
|
|
2543
|
+
case "bibliography": {
|
|
2544
|
+
if (!("bibliography" in data.ochre)) {
|
|
2545
|
+
throw new Error(
|
|
2546
|
+
"Invalid OCHRE data: API response missing 'bibliography' key"
|
|
2547
|
+
);
|
|
2548
|
+
}
|
|
2549
|
+
item = parseBibliography(data.ochre.bibliography);
|
|
2550
|
+
break;
|
|
2551
|
+
}
|
|
2552
|
+
case "person": {
|
|
2553
|
+
if (!("person" in data.ochre)) {
|
|
2554
|
+
throw new Error(
|
|
2555
|
+
"Invalid OCHRE data: API response missing 'person' key"
|
|
2556
|
+
);
|
|
2557
|
+
}
|
|
2558
|
+
item = parsePerson(data.ochre.person);
|
|
2559
|
+
break;
|
|
2560
|
+
}
|
|
2561
|
+
case "propertyValue": {
|
|
2562
|
+
if (!("propertyValue" in data.ochre)) {
|
|
2563
|
+
throw new Error(
|
|
2564
|
+
"Invalid OCHRE data: API response missing 'propertyValue' key"
|
|
2565
|
+
);
|
|
2566
|
+
}
|
|
2567
|
+
item = parsePropertyValue(data.ochre.propertyValue);
|
|
2568
|
+
break;
|
|
2569
|
+
}
|
|
2570
|
+
case "set": {
|
|
2571
|
+
if (!("set" in data.ochre)) {
|
|
2572
|
+
throw new Error("Invalid OCHRE data: API response missing 'set' key");
|
|
2573
|
+
}
|
|
2574
|
+
item = parseSet(data.ochre.set);
|
|
2575
|
+
break;
|
|
2576
|
+
}
|
|
2577
|
+
case "tree": {
|
|
2578
|
+
if (!("tree" in data.ochre)) {
|
|
2579
|
+
throw new Error(
|
|
2580
|
+
"Invalid OCHRE data: API response missing 'tree' key"
|
|
2581
|
+
);
|
|
2582
|
+
}
|
|
2583
|
+
item = parseTree(data.ochre.tree);
|
|
2584
|
+
break;
|
|
2585
|
+
}
|
|
2586
|
+
default: {
|
|
2587
|
+
throw new Error("Invalid category");
|
|
2588
|
+
}
|
|
2719
2589
|
}
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
const data = {
|
|
2725
|
-
uuid: parseFakeString(dataRaw.ochre.uuid),
|
|
2726
|
-
publicationDateTime: new Date(dataRaw.ochre.publicationDateTime),
|
|
2727
|
-
belongsTo: {
|
|
2728
|
-
uuid: dataRaw.ochre.uuidBelongsTo,
|
|
2729
|
-
abbreviation: parseFakeString(dataRaw.ochre.belongsTo)
|
|
2730
|
-
},
|
|
2731
|
-
metadata: parseMetadata(dataRaw.ochre.metadata),
|
|
2732
|
-
item: setItem
|
|
2590
|
+
const metadata = parseMetadata(data.ochre.metadata);
|
|
2591
|
+
const belongsTo = {
|
|
2592
|
+
uuid: data.ochre.uuidBelongsTo,
|
|
2593
|
+
abbreviation: parseFakeString(data.ochre.belongsTo)
|
|
2733
2594
|
};
|
|
2734
|
-
return {
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
// src/utils/fetchers/spatial-unit.ts
|
|
2742
|
-
async function fetchSpatialUnit(uuid) {
|
|
2743
|
-
try {
|
|
2744
|
-
const [error, dataRaw] = await fetchByUuid(uuid);
|
|
2745
|
-
if (error !== null) {
|
|
2746
|
-
throw new Error(error);
|
|
2747
|
-
}
|
|
2748
|
-
if (!("spatialUnit" in dataRaw.ochre)) {
|
|
2749
|
-
throw new Error(
|
|
2750
|
-
"Invalid OCHRE data: API response missing 'spatialUnit' key"
|
|
2751
|
-
);
|
|
2752
|
-
}
|
|
2753
|
-
const spatialUnitItem = parseSpatialUnit(dataRaw.ochre.spatialUnit);
|
|
2754
|
-
const data = {
|
|
2755
|
-
uuid: parseFakeString(dataRaw.ochre.uuid),
|
|
2756
|
-
publicationDateTime: new Date(dataRaw.ochre.publicationDateTime),
|
|
2757
|
-
belongsTo: {
|
|
2758
|
-
uuid: dataRaw.ochre.uuidBelongsTo,
|
|
2759
|
-
abbreviation: parseFakeString(dataRaw.ochre.belongsTo)
|
|
2760
|
-
},
|
|
2761
|
-
metadata: parseMetadata(dataRaw.ochre.metadata),
|
|
2762
|
-
item: spatialUnitItem
|
|
2595
|
+
return {
|
|
2596
|
+
error: null,
|
|
2597
|
+
metadata,
|
|
2598
|
+
belongsTo,
|
|
2599
|
+
item,
|
|
2600
|
+
category
|
|
2763
2601
|
};
|
|
2764
|
-
return { metadata: data.metadata, spatialUnit: data.item };
|
|
2765
2602
|
} catch (error) {
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
async function fetchTree(uuid) {
|
|
2773
|
-
try {
|
|
2774
|
-
const [error, dataRaw] = await fetchByUuid(uuid);
|
|
2775
|
-
if (error !== null) {
|
|
2776
|
-
throw new Error(error);
|
|
2777
|
-
}
|
|
2778
|
-
if (!("tree" in dataRaw.ochre)) {
|
|
2779
|
-
throw new Error("Invalid OCHRE data: API response missing 'tree' key");
|
|
2780
|
-
}
|
|
2781
|
-
const tree = parseTree(dataRaw.ochre.tree);
|
|
2782
|
-
if (!tree) {
|
|
2783
|
-
throw new Error("Invalid OCHRE data: Could not parse tree");
|
|
2784
|
-
}
|
|
2785
|
-
const data = {
|
|
2786
|
-
uuid: parseFakeString(dataRaw.ochre.uuid),
|
|
2787
|
-
publicationDateTime: new Date(dataRaw.ochre.publicationDateTime),
|
|
2788
|
-
belongsTo: {
|
|
2789
|
-
uuid: dataRaw.ochre.uuidBelongsTo,
|
|
2790
|
-
abbreviation: parseFakeString(dataRaw.ochre.belongsTo)
|
|
2791
|
-
},
|
|
2792
|
-
metadata: parseMetadata(dataRaw.ochre.metadata),
|
|
2793
|
-
item: tree
|
|
2603
|
+
return {
|
|
2604
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
2605
|
+
metadata: void 0,
|
|
2606
|
+
belongsTo: void 0,
|
|
2607
|
+
item: void 0,
|
|
2608
|
+
category: void 0
|
|
2794
2609
|
};
|
|
2795
|
-
return { metadata: data.metadata, tree: data.item };
|
|
2796
|
-
} catch (error) {
|
|
2797
|
-
console.error(error);
|
|
2798
|
-
return null;
|
|
2799
|
-
}
|
|
2800
|
-
}
|
|
2801
|
-
|
|
2802
|
-
// src/utils/fetchers/website.ts
|
|
2803
|
-
async function fetchWebsite(abbreviation) {
|
|
2804
|
-
try {
|
|
2805
|
-
const response = await fetch(
|
|
2806
|
-
`https://ochre.lib.uchicago.edu/ochre?xquery=for $q in input()/ochre[tree[@type='lesson'][identification/abbreviation='${abbreviation.toLocaleLowerCase("en-US")}']] return $q&format=json`
|
|
2807
|
-
);
|
|
2808
|
-
if (!response.ok) {
|
|
2809
|
-
throw new Error("Failed to fetch website");
|
|
2810
|
-
}
|
|
2811
|
-
const data = await response.json();
|
|
2812
|
-
if (!("ochre" in data.result) || !("tree" in data.result.ochre)) {
|
|
2813
|
-
throw new Error("Failed to fetch website");
|
|
2814
|
-
}
|
|
2815
|
-
const projectIdentification = data.result.ochre.metadata.project?.identification ? parseIdentification(data.result.ochre.metadata.project.identification) : null;
|
|
2816
|
-
const website = await parseWebsite(
|
|
2817
|
-
data.result.ochre.tree,
|
|
2818
|
-
projectIdentification?.label ?? "",
|
|
2819
|
-
data.result.ochre.metadata.project?.identification.website ?? null
|
|
2820
|
-
);
|
|
2821
|
-
return website;
|
|
2822
|
-
} catch (error) {
|
|
2823
|
-
console.error(error);
|
|
2824
|
-
return null;
|
|
2825
2610
|
}
|
|
2826
2611
|
}
|
|
2827
2612
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2828
2613
|
0 && (module.exports = {
|
|
2829
|
-
fetchBibliography,
|
|
2830
2614
|
fetchByUuid,
|
|
2831
|
-
|
|
2832
|
-
fetchGallery,
|
|
2833
|
-
fetchPeriod,
|
|
2834
|
-
fetchPropertyValue,
|
|
2835
|
-
fetchResource,
|
|
2836
|
-
fetchSet,
|
|
2837
|
-
fetchSpatialUnit,
|
|
2838
|
-
fetchTree,
|
|
2839
|
-
fetchWebsite,
|
|
2615
|
+
fetchItem,
|
|
2840
2616
|
filterProperties,
|
|
2841
2617
|
getAllPropertyLabels,
|
|
2842
2618
|
getPropertyByLabel,
|