@digitalculture/ochre-sdk 0.5.19 → 0.6.1
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 +469 -666
- package/dist/index.d.cts +58 -357
- package/dist/index.d.ts +58 -357
- package/dist/index.js +468 -656
- 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,247 @@ __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 gallerySchema = import_zod.z.object({
|
|
136
|
+
uuid: import_zod.z.string().uuid({ message: "Invalid UUID" }),
|
|
137
|
+
filter: import_zod.z.string().optional(),
|
|
138
|
+
page: import_zod.z.number().positive({ message: "Page must be positive" }),
|
|
139
|
+
perPage: import_zod.z.number().positive({ message: "Per page must be positive" })
|
|
140
|
+
}).strict();
|
|
141
|
+
var renderOptionsSchema = import_zod.z.string().transform((str) => str.split(" ")).pipe(
|
|
142
|
+
import_zod.z.array(
|
|
143
|
+
import_zod.z.enum([
|
|
115
144
|
"bold",
|
|
116
145
|
"italic",
|
|
117
146
|
"underline"
|
|
118
147
|
])
|
|
119
148
|
)
|
|
120
149
|
);
|
|
121
|
-
var whitespaceSchema =
|
|
122
|
-
|
|
123
|
-
|
|
150
|
+
var whitespaceSchema = import_zod.z.string().transform((str) => str.split(" ")).pipe(
|
|
151
|
+
import_zod.z.array(
|
|
152
|
+
import_zod.z.enum([
|
|
124
153
|
"newline",
|
|
125
154
|
"trailing",
|
|
126
155
|
"leading"
|
|
127
156
|
])
|
|
128
157
|
)
|
|
129
158
|
);
|
|
130
|
-
var emailSchema =
|
|
159
|
+
var emailSchema = import_zod.z.string().email({ message: "Invalid email" });
|
|
160
|
+
|
|
161
|
+
// src/utils/helpers.ts
|
|
162
|
+
function getItemCategory(keys) {
|
|
163
|
+
const categoryFound = keys.find(
|
|
164
|
+
(key) => categorySchema.safeParse(key).success
|
|
165
|
+
);
|
|
166
|
+
if (!categoryFound) {
|
|
167
|
+
const unknownKey = keys.find(
|
|
168
|
+
(key) => ![
|
|
169
|
+
"uuid",
|
|
170
|
+
"uuidBelongsTo",
|
|
171
|
+
"belongsTo",
|
|
172
|
+
"publicationDateTime",
|
|
173
|
+
"metadata",
|
|
174
|
+
"languages"
|
|
175
|
+
].includes(key)
|
|
176
|
+
);
|
|
177
|
+
throw new Error(`Invalid OCHRE data; found unexpected "${unknownKey}" key`);
|
|
178
|
+
}
|
|
179
|
+
const categoryKey = categorySchema.parse(categoryFound);
|
|
180
|
+
return categoryKey;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// src/utils/getters.ts
|
|
184
|
+
var DEFAULT_OPTIONS = {
|
|
185
|
+
searchNestedProperties: false
|
|
186
|
+
};
|
|
187
|
+
function getPropertyByLabel(properties, label, options = DEFAULT_OPTIONS) {
|
|
188
|
+
const { searchNestedProperties } = options;
|
|
189
|
+
const property = properties.find((property2) => property2.label === label);
|
|
190
|
+
if (property) {
|
|
191
|
+
return property;
|
|
192
|
+
}
|
|
193
|
+
if (searchNestedProperties) {
|
|
194
|
+
for (const property2 of properties) {
|
|
195
|
+
if (property2.properties.length > 0) {
|
|
196
|
+
const nestedResult = getPropertyByLabel(property2.properties, label, {
|
|
197
|
+
searchNestedProperties
|
|
198
|
+
});
|
|
199
|
+
if (nestedResult) {
|
|
200
|
+
return nestedResult;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
function getPropertyValuesByLabel(properties, label, options = DEFAULT_OPTIONS) {
|
|
208
|
+
const { searchNestedProperties } = options;
|
|
209
|
+
const property = properties.find((property2) => property2.label === label);
|
|
210
|
+
if (property) {
|
|
211
|
+
return property.values.map((value) => value.content);
|
|
212
|
+
}
|
|
213
|
+
if (searchNestedProperties) {
|
|
214
|
+
for (const property2 of properties) {
|
|
215
|
+
if (property2.properties.length > 0) {
|
|
216
|
+
const nestedResult = getPropertyValuesByLabel(
|
|
217
|
+
property2.properties,
|
|
218
|
+
label,
|
|
219
|
+
{ searchNestedProperties }
|
|
220
|
+
);
|
|
221
|
+
if (nestedResult) {
|
|
222
|
+
return nestedResult;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
function getPropertyValueByLabel(properties, label, options = DEFAULT_OPTIONS) {
|
|
230
|
+
const { searchNestedProperties } = options;
|
|
231
|
+
const values = getPropertyValuesByLabel(properties, label, {
|
|
232
|
+
searchNestedProperties
|
|
233
|
+
});
|
|
234
|
+
if (values !== null && values.length > 0) {
|
|
235
|
+
return values[0];
|
|
236
|
+
}
|
|
237
|
+
if (searchNestedProperties) {
|
|
238
|
+
for (const property of properties) {
|
|
239
|
+
if (property.properties.length > 0) {
|
|
240
|
+
const nestedResult = getPropertyValueByLabel(
|
|
241
|
+
property.properties,
|
|
242
|
+
label,
|
|
243
|
+
{ searchNestedProperties }
|
|
244
|
+
);
|
|
245
|
+
if (nestedResult !== null) {
|
|
246
|
+
return nestedResult;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
function getAllPropertyLabels(properties, options = DEFAULT_OPTIONS) {
|
|
254
|
+
const { searchNestedProperties } = options;
|
|
255
|
+
const labels = /* @__PURE__ */ new Set();
|
|
256
|
+
for (const property of properties) {
|
|
257
|
+
labels.add(property.label);
|
|
258
|
+
if (property.properties.length > 0 && searchNestedProperties) {
|
|
259
|
+
const nestedLabels = getAllPropertyLabels(property.properties, {
|
|
260
|
+
searchNestedProperties: true
|
|
261
|
+
});
|
|
262
|
+
for (const label of nestedLabels) {
|
|
263
|
+
labels.add(label);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return [...labels];
|
|
268
|
+
}
|
|
269
|
+
function filterProperties(property, filter, options = DEFAULT_OPTIONS) {
|
|
270
|
+
const { searchNestedProperties } = options;
|
|
271
|
+
const isAllFields = filter.label.toLocaleLowerCase("en-US") === "all fields";
|
|
272
|
+
if (isAllFields || property.label.toLocaleLowerCase("en-US") === filter.label.toLocaleLowerCase("en-US")) {
|
|
273
|
+
let isFound = property.values.some((value) => {
|
|
274
|
+
if (value.content === null) {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
if (typeof value.content === "string") {
|
|
278
|
+
if (typeof filter.value !== "string") {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
return value.content.toLocaleLowerCase("en-US").includes(filter.value.toLocaleLowerCase("en-US"));
|
|
282
|
+
}
|
|
283
|
+
if (typeof value.content === "number") {
|
|
284
|
+
if (typeof filter.value !== "number") {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
return value.content === filter.value;
|
|
288
|
+
}
|
|
289
|
+
if (typeof value.content === "boolean") {
|
|
290
|
+
if (typeof filter.value !== "boolean") {
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
return value.booleanValue === filter.value;
|
|
294
|
+
}
|
|
295
|
+
if (value.content instanceof Date) {
|
|
296
|
+
if (!(filter.value instanceof Date)) {
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
return value.content.getTime() === filter.value.getTime();
|
|
300
|
+
}
|
|
301
|
+
return false;
|
|
302
|
+
});
|
|
303
|
+
if (!isFound && searchNestedProperties) {
|
|
304
|
+
isFound = property.properties.some(
|
|
305
|
+
(property2) => filterProperties(property2, filter, { searchNestedProperties: true })
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
return isFound;
|
|
309
|
+
}
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// src/utils/string.ts
|
|
131
314
|
function getStringItemByLanguage(content, language) {
|
|
132
315
|
const stringItemToFind = content.find((item) => item.lang === language);
|
|
133
316
|
return stringItemToFind ?? null;
|
|
@@ -370,250 +553,42 @@ function parseStringDocumentItem(item, footnotes) {
|
|
|
370
553
|
}
|
|
371
554
|
}
|
|
372
555
|
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 componentSchema = import_zod3.z.enum(
|
|
593
|
-
[
|
|
594
|
-
"annotated-document",
|
|
595
|
-
"annotated-image",
|
|
596
|
-
"bibliography",
|
|
597
|
-
"blog",
|
|
598
|
-
"button",
|
|
599
|
-
"collection",
|
|
600
|
-
"empty-space",
|
|
601
|
-
"filter-categories",
|
|
602
|
-
"iframe",
|
|
603
|
-
"iiif-viewer",
|
|
604
|
-
"image",
|
|
605
|
-
"image-gallery",
|
|
606
|
-
"n-columns",
|
|
607
|
-
"n-rows",
|
|
608
|
-
"network-graph",
|
|
609
|
-
"search-bar",
|
|
610
|
-
"table",
|
|
611
|
-
"text",
|
|
612
|
-
"timeline",
|
|
613
|
-
"video"
|
|
614
|
-
],
|
|
615
|
-
{ message: "Invalid component" }
|
|
616
|
-
);
|
|
556
|
+
}
|
|
557
|
+
function parseStringContent(content, language = "eng") {
|
|
558
|
+
switch (typeof content.content) {
|
|
559
|
+
case "string":
|
|
560
|
+
case "number":
|
|
561
|
+
case "boolean": {
|
|
562
|
+
return parseFakeString(content.content);
|
|
563
|
+
}
|
|
564
|
+
case "object": {
|
|
565
|
+
if (Array.isArray(content.content)) {
|
|
566
|
+
const stringItem = getStringItemByLanguage(content.content, language);
|
|
567
|
+
if (stringItem) {
|
|
568
|
+
return parseStringItem(stringItem);
|
|
569
|
+
} else {
|
|
570
|
+
const returnStringItem = content.content[0];
|
|
571
|
+
if (!returnStringItem) {
|
|
572
|
+
throw new Error(
|
|
573
|
+
`No string item found for language \u201C${language}\u201D in the following content:
|
|
574
|
+
${JSON.stringify(
|
|
575
|
+
content.content
|
|
576
|
+
)}.`
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
return parseStringItem(returnStringItem);
|
|
580
|
+
}
|
|
581
|
+
} else {
|
|
582
|
+
return parseStringItem(content.content);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
default: {
|
|
586
|
+
return String(content.content).replaceAll(/^(\d+)\./gm, String.raw`$1\.`);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
// src/utils/parse.ts
|
|
617
592
|
function parseIdentification(identification) {
|
|
618
593
|
try {
|
|
619
594
|
const returnIdentification = {
|
|
@@ -1198,54 +1173,83 @@ function parseTree(tree) {
|
|
|
1198
1173
|
return returnTree;
|
|
1199
1174
|
}
|
|
1200
1175
|
function parseSet(set) {
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
let
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1176
|
+
if (typeof set.items === "string") {
|
|
1177
|
+
throw new TypeError("Invalid OCHRE data: Set has no items");
|
|
1178
|
+
}
|
|
1179
|
+
const itemCategory = getItemCategory(Object.keys(set.items));
|
|
1180
|
+
let items = [];
|
|
1181
|
+
switch (itemCategory) {
|
|
1182
|
+
case "resource": {
|
|
1183
|
+
if (!("resource" in set.items)) {
|
|
1184
|
+
throw new Error("Invalid OCHRE data: Set has no resources");
|
|
1185
|
+
}
|
|
1186
|
+
items = parseResources(
|
|
1187
|
+
Array.isArray(set.items.resource) ? set.items.resource : [set.items.resource]
|
|
1188
|
+
);
|
|
1189
|
+
break;
|
|
1190
|
+
}
|
|
1191
|
+
case "spatialUnit": {
|
|
1192
|
+
if (!("spatialUnit" in set.items)) {
|
|
1193
|
+
throw new Error("Invalid OCHRE data: Set has no spatial units");
|
|
1194
|
+
}
|
|
1195
|
+
items = parseSpatialUnits(
|
|
1196
|
+
Array.isArray(set.items.spatialUnit) ? set.items.spatialUnit : [set.items.spatialUnit]
|
|
1197
|
+
);
|
|
1198
|
+
break;
|
|
1199
|
+
}
|
|
1200
|
+
case "concept": {
|
|
1201
|
+
if (!("concept" in set.items)) {
|
|
1202
|
+
throw new Error("Invalid OCHRE data: Set has no concepts");
|
|
1203
|
+
}
|
|
1204
|
+
items = parseConcepts(
|
|
1205
|
+
Array.isArray(set.items.concept) ? set.items.concept : [set.items.concept]
|
|
1206
|
+
);
|
|
1207
|
+
break;
|
|
1208
|
+
}
|
|
1209
|
+
case "period": {
|
|
1210
|
+
if (!("period" in set.items)) {
|
|
1211
|
+
throw new Error("Invalid OCHRE data: Set has no periods");
|
|
1212
|
+
}
|
|
1213
|
+
items = parsePeriods(
|
|
1214
|
+
Array.isArray(set.items.period) ? set.items.period : [set.items.period]
|
|
1215
|
+
);
|
|
1216
|
+
break;
|
|
1217
|
+
}
|
|
1218
|
+
case "bibliography": {
|
|
1219
|
+
if (!("bibliography" in set.items)) {
|
|
1220
|
+
throw new Error("Invalid OCHRE data: Set has no bibliographies");
|
|
1221
|
+
}
|
|
1222
|
+
items = parseBibliographies(
|
|
1223
|
+
Array.isArray(set.items.bibliography) ? set.items.bibliography : [set.items.bibliography]
|
|
1224
|
+
);
|
|
1225
|
+
break;
|
|
1226
|
+
}
|
|
1227
|
+
case "person": {
|
|
1228
|
+
if (!("person" in set.items)) {
|
|
1229
|
+
throw new Error("Invalid OCHRE data: Set has no persons");
|
|
1230
|
+
}
|
|
1231
|
+
items = parsePersons(
|
|
1232
|
+
Array.isArray(set.items.person) ? set.items.person : [set.items.person]
|
|
1233
|
+
);
|
|
1234
|
+
break;
|
|
1235
|
+
}
|
|
1236
|
+
case "propertyValue": {
|
|
1237
|
+
if (!("propertyValue" in set.items)) {
|
|
1238
|
+
throw new Error("Invalid OCHRE data: Set has no property values");
|
|
1239
|
+
}
|
|
1240
|
+
items = parsePropertyValues(
|
|
1241
|
+
Array.isArray(set.items.propertyValue) ? set.items.propertyValue : [set.items.propertyValue]
|
|
1242
|
+
);
|
|
1243
|
+
break;
|
|
1244
|
+
}
|
|
1245
|
+
default: {
|
|
1246
|
+
throw new Error("Invalid OCHRE data: Set has no items or is malformed");
|
|
1247
|
+
}
|
|
1245
1248
|
}
|
|
1246
1249
|
return {
|
|
1247
1250
|
uuid: set.uuid,
|
|
1248
1251
|
category: "set",
|
|
1252
|
+
itemCategory,
|
|
1249
1253
|
publicationDateTime: set.publicationDateTime ? new Date(set.publicationDateTime) : null,
|
|
1250
1254
|
date: set.date != null ? new Date(set.date) : null,
|
|
1251
1255
|
license: parseLicense(set.availability),
|
|
@@ -1257,18 +1261,10 @@ function parseSet(set) {
|
|
|
1257
1261
|
) : [],
|
|
1258
1262
|
type: set.type,
|
|
1259
1263
|
number: set.n,
|
|
1260
|
-
items
|
|
1261
|
-
resources,
|
|
1262
|
-
spatialUnits,
|
|
1263
|
-
concepts,
|
|
1264
|
-
periods,
|
|
1265
|
-
bibliographies,
|
|
1266
|
-
persons,
|
|
1267
|
-
propertyValues
|
|
1268
|
-
}
|
|
1264
|
+
items
|
|
1269
1265
|
};
|
|
1270
1266
|
}
|
|
1271
|
-
function parseResource(resource
|
|
1267
|
+
function parseResource(resource) {
|
|
1272
1268
|
const returnResource = {
|
|
1273
1269
|
uuid: resource.uuid,
|
|
1274
1270
|
category: "resource",
|
|
@@ -1311,34 +1307,20 @@ function parseResource(resource, isNested = false) {
|
|
|
1311
1307
|
Array.isArray(resource.citedBibliography.reference) ? resource.citedBibliography.reference : [resource.citedBibliography.reference]
|
|
1312
1308
|
) : [],
|
|
1313
1309
|
resources: resource.resource ? parseResources(
|
|
1314
|
-
Array.isArray(resource.resource) ? resource.resource : [resource.resource]
|
|
1315
|
-
true
|
|
1310
|
+
Array.isArray(resource.resource) ? resource.resource : [resource.resource]
|
|
1316
1311
|
) : []
|
|
1317
1312
|
};
|
|
1318
|
-
if (isNested) {
|
|
1319
|
-
const returnNestedResource = {
|
|
1320
|
-
...returnResource,
|
|
1321
|
-
publicationDateTime: null,
|
|
1322
|
-
context: null,
|
|
1323
|
-
license: null,
|
|
1324
|
-
copyright: null
|
|
1325
|
-
};
|
|
1326
|
-
delete returnNestedResource.publicationDateTime;
|
|
1327
|
-
delete returnNestedResource.license;
|
|
1328
|
-
delete returnNestedResource.copyright;
|
|
1329
|
-
return returnNestedResource;
|
|
1330
|
-
}
|
|
1331
1313
|
return returnResource;
|
|
1332
1314
|
}
|
|
1333
|
-
function parseResources(resources
|
|
1315
|
+
function parseResources(resources) {
|
|
1334
1316
|
const returnResources = [];
|
|
1335
1317
|
const resourcesToParse = Array.isArray(resources) ? resources : [resources];
|
|
1336
1318
|
for (const resource of resourcesToParse) {
|
|
1337
|
-
returnResources.push(parseResource(resource
|
|
1319
|
+
returnResources.push(parseResource(resource));
|
|
1338
1320
|
}
|
|
1339
1321
|
return returnResources;
|
|
1340
1322
|
}
|
|
1341
|
-
function parseSpatialUnit(spatialUnit
|
|
1323
|
+
function parseSpatialUnit(spatialUnit) {
|
|
1342
1324
|
const returnSpatialUnit = {
|
|
1343
1325
|
uuid: spatialUnit.uuid,
|
|
1344
1326
|
category: "spatialUnit",
|
|
@@ -1358,34 +1340,22 @@ function parseSpatialUnit(spatialUnit, isNested = false) {
|
|
|
1358
1340
|
) : spatialUnit.observation ? [parseObservation(spatialUnit.observation)] : [],
|
|
1359
1341
|
events: "events" in spatialUnit && spatialUnit.events ? parseEvents(
|
|
1360
1342
|
Array.isArray(spatialUnit.events.event) ? spatialUnit.events.event : [spatialUnit.events.event]
|
|
1343
|
+
) : [],
|
|
1344
|
+
properties: "properties" in spatialUnit && spatialUnit.properties ? parseProperties(
|
|
1345
|
+
Array.isArray(spatialUnit.properties.property) ? spatialUnit.properties.property : [spatialUnit.properties.property]
|
|
1361
1346
|
) : []
|
|
1362
1347
|
};
|
|
1363
|
-
if (isNested) {
|
|
1364
|
-
const returnNestedSpatialUnit = {
|
|
1365
|
-
...returnSpatialUnit,
|
|
1366
|
-
publicationDateTime: null,
|
|
1367
|
-
license: null,
|
|
1368
|
-
properties: "properties" in spatialUnit && spatialUnit.properties ? parseProperties(
|
|
1369
|
-
Array.isArray(spatialUnit.properties.property) ? spatialUnit.properties.property : [spatialUnit.properties.property]
|
|
1370
|
-
) : []
|
|
1371
|
-
};
|
|
1372
|
-
delete returnNestedSpatialUnit.publicationDateTime;
|
|
1373
|
-
delete returnNestedSpatialUnit.license;
|
|
1374
|
-
return returnNestedSpatialUnit;
|
|
1375
|
-
}
|
|
1376
1348
|
return returnSpatialUnit;
|
|
1377
1349
|
}
|
|
1378
|
-
function parseSpatialUnits(spatialUnits
|
|
1350
|
+
function parseSpatialUnits(spatialUnits) {
|
|
1379
1351
|
const returnSpatialUnits = [];
|
|
1380
1352
|
const spatialUnitsToParse = Array.isArray(spatialUnits) ? spatialUnits : [spatialUnits];
|
|
1381
1353
|
for (const spatialUnit of spatialUnitsToParse) {
|
|
1382
|
-
returnSpatialUnits.push(
|
|
1383
|
-
parseSpatialUnit(spatialUnit, isNested)
|
|
1384
|
-
);
|
|
1354
|
+
returnSpatialUnits.push(parseSpatialUnit(spatialUnit));
|
|
1385
1355
|
}
|
|
1386
1356
|
return returnSpatialUnits;
|
|
1387
1357
|
}
|
|
1388
|
-
function parseConcept(concept
|
|
1358
|
+
function parseConcept(concept) {
|
|
1389
1359
|
const returnConcept = {
|
|
1390
1360
|
uuid: concept.uuid,
|
|
1391
1361
|
category: "concept",
|
|
@@ -1398,17 +1368,6 @@ function parseConcept(concept, isNested = false) {
|
|
|
1398
1368
|
Array.isArray(concept.interpretations.interpretation) ? concept.interpretations.interpretation : [concept.interpretations.interpretation]
|
|
1399
1369
|
)
|
|
1400
1370
|
};
|
|
1401
|
-
if (isNested) {
|
|
1402
|
-
const returnNestedConcept = {
|
|
1403
|
-
...returnConcept,
|
|
1404
|
-
publicationDateTime: null,
|
|
1405
|
-
context: null,
|
|
1406
|
-
license: null
|
|
1407
|
-
};
|
|
1408
|
-
delete returnNestedConcept.publicationDateTime;
|
|
1409
|
-
delete returnNestedConcept.license;
|
|
1410
|
-
return returnNestedConcept;
|
|
1411
|
-
}
|
|
1412
1371
|
return returnConcept;
|
|
1413
1372
|
}
|
|
1414
1373
|
var parseWebpageResources = async (webpageResources, type) => {
|
|
@@ -1451,11 +1410,11 @@ var parseWebpageResources = async (webpageResources, type) => {
|
|
|
1451
1410
|
}
|
|
1452
1411
|
return returnElements;
|
|
1453
1412
|
};
|
|
1454
|
-
function parseConcepts(concepts
|
|
1413
|
+
function parseConcepts(concepts) {
|
|
1455
1414
|
const returnConcepts = [];
|
|
1456
1415
|
const conceptsToParse = Array.isArray(concepts) ? concepts : [concepts];
|
|
1457
1416
|
for (const concept of conceptsToParse) {
|
|
1458
|
-
returnConcepts.push(parseConcept(concept
|
|
1417
|
+
returnConcepts.push(parseConcept(concept));
|
|
1459
1418
|
}
|
|
1460
1419
|
return returnConcepts;
|
|
1461
1420
|
}
|
|
@@ -1476,11 +1435,11 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1476
1435
|
if (document === null) {
|
|
1477
1436
|
const documentLink = links.find((link) => link.type === "internalDocument");
|
|
1478
1437
|
if (documentLink) {
|
|
1479
|
-
const
|
|
1480
|
-
if (
|
|
1438
|
+
const { item, error } = await fetchItem(documentLink.uuid, "resource");
|
|
1439
|
+
if (error !== null) {
|
|
1481
1440
|
throw new Error("Failed to fetch OCHRE data");
|
|
1482
1441
|
}
|
|
1483
|
-
document =
|
|
1442
|
+
document = item.document;
|
|
1484
1443
|
}
|
|
1485
1444
|
}
|
|
1486
1445
|
switch (componentName) {
|
|
@@ -2521,301 +2480,145 @@ async function parseWebsite(websiteTree, projectName, website) {
|
|
|
2521
2480
|
};
|
|
2522
2481
|
}
|
|
2523
2482
|
|
|
2524
|
-
// src/utils/fetchers/
|
|
2525
|
-
async function
|
|
2526
|
-
try {
|
|
2527
|
-
const [error, dataRaw] = await fetchByUuid(uuid);
|
|
2528
|
-
if (error !== null) {
|
|
2529
|
-
throw new Error(error);
|
|
2530
|
-
}
|
|
2531
|
-
if (!("bibliography" in dataRaw.ochre)) {
|
|
2532
|
-
throw new Error(
|
|
2533
|
-
"Invalid OCHRE data: API response missing 'bibliography' key"
|
|
2534
|
-
);
|
|
2535
|
-
}
|
|
2536
|
-
const bibliographyItem = parseBibliography(dataRaw.ochre.bibliography);
|
|
2537
|
-
const data = {
|
|
2538
|
-
uuid: parseFakeString(dataRaw.ochre.uuid),
|
|
2539
|
-
publicationDateTime: new Date(dataRaw.ochre.publicationDateTime),
|
|
2540
|
-
belongsTo: {
|
|
2541
|
-
uuid: dataRaw.ochre.uuidBelongsTo,
|
|
2542
|
-
abbreviation: parseFakeString(dataRaw.ochre.belongsTo)
|
|
2543
|
-
},
|
|
2544
|
-
metadata: parseMetadata(dataRaw.ochre.metadata),
|
|
2545
|
-
item: bibliographyItem
|
|
2546
|
-
};
|
|
2547
|
-
return { metadata: data.metadata, bibliography: data.item };
|
|
2548
|
-
} catch (error) {
|
|
2549
|
-
console.error(error);
|
|
2550
|
-
return null;
|
|
2551
|
-
}
|
|
2552
|
-
}
|
|
2553
|
-
|
|
2554
|
-
// src/utils/fetchers/concept.ts
|
|
2555
|
-
async function fetchConcept(uuid) {
|
|
2556
|
-
try {
|
|
2557
|
-
const [error, dataRaw] = await fetchByUuid(uuid);
|
|
2558
|
-
if (error !== null) {
|
|
2559
|
-
throw new Error(error);
|
|
2560
|
-
}
|
|
2561
|
-
if (!("concept" in dataRaw.ochre)) {
|
|
2562
|
-
throw new Error("Invalid OCHRE data: API response missing 'concept' key");
|
|
2563
|
-
}
|
|
2564
|
-
const conceptItem = parseConcept(dataRaw.ochre.concept);
|
|
2565
|
-
const data = {
|
|
2566
|
-
uuid: parseFakeString(dataRaw.ochre.uuid),
|
|
2567
|
-
publicationDateTime: new Date(dataRaw.ochre.publicationDateTime),
|
|
2568
|
-
belongsTo: {
|
|
2569
|
-
uuid: dataRaw.ochre.uuidBelongsTo,
|
|
2570
|
-
abbreviation: parseFakeString(dataRaw.ochre.belongsTo)
|
|
2571
|
-
},
|
|
2572
|
-
metadata: parseMetadata(dataRaw.ochre.metadata),
|
|
2573
|
-
item: conceptItem
|
|
2574
|
-
};
|
|
2575
|
-
return { metadata: data.metadata, concept: data.item };
|
|
2576
|
-
} catch (error) {
|
|
2577
|
-
console.error(error);
|
|
2578
|
-
return null;
|
|
2579
|
-
}
|
|
2580
|
-
}
|
|
2581
|
-
|
|
2582
|
-
// src/utils/fetchers/gallery.ts
|
|
2583
|
-
var import_zod4 = require("zod");
|
|
2584
|
-
var gallerySchema = import_zod4.z.object({
|
|
2585
|
-
uuid: import_zod4.z.string().uuid({ message: "Invalid UUID" }),
|
|
2586
|
-
filter: import_zod4.z.string().optional(),
|
|
2587
|
-
page: import_zod4.z.number().positive({ message: "Page must be positive" }),
|
|
2588
|
-
perPage: import_zod4.z.number().positive({ message: "Per page must be positive" })
|
|
2589
|
-
}).strict();
|
|
2590
|
-
async function fetchGallery(uuid, filter, page, perPage) {
|
|
2483
|
+
// src/utils/fetchers/uuid.ts
|
|
2484
|
+
async function fetchByUuid(uuid) {
|
|
2591
2485
|
try {
|
|
2592
|
-
const
|
|
2593
|
-
if (!parsed.success) {
|
|
2594
|
-
throw new Error(parsed.error.message);
|
|
2595
|
-
}
|
|
2486
|
+
const parsedUuid = uuidSchema.parse(uuid);
|
|
2596
2487
|
const response = await fetch(
|
|
2597
|
-
`https://ochre.lib.uchicago.edu/ochre?
|
|
2598
|
-
for $q in input()/ochre[@uuid='${uuid}']
|
|
2599
|
-
let $filtered := $q/tree/items/resource[contains(lower-case(identification/label), lower-case('${filter}'))]
|
|
2600
|
-
let $maxLength := count($filtered)
|
|
2601
|
-
return <gallery maxLength='{$maxLength}'>
|
|
2602
|
-
{$q/metadata/project}
|
|
2603
|
-
{$q/metadata/item}
|
|
2604
|
-
{$filtered[position() >= ${((page - 1) * perPage + 1).toString()} and position() < ${(page * perPage + 1).toString()}]}
|
|
2605
|
-
</gallery>
|
|
2606
|
-
`)}&format=json`
|
|
2488
|
+
`https://ochre.lib.uchicago.edu/ochre?uuid=${parsedUuid}&format=json&lang="*"`
|
|
2607
2489
|
);
|
|
2608
2490
|
if (!response.ok) {
|
|
2609
|
-
throw new Error("
|
|
2610
|
-
}
|
|
2611
|
-
const data = await response.json();
|
|
2612
|
-
if (!("gallery" in data.result)) {
|
|
2613
|
-
throw new Error("Failed to fetch gallery");
|
|
2491
|
+
throw new Error("Failed to fetch OCHRE data");
|
|
2614
2492
|
}
|
|
2615
|
-
const
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
const galleryProjectIdentification = parseIdentification(
|
|
2619
|
-
data.result.gallery.project.identification
|
|
2620
|
-
);
|
|
2621
|
-
const gallery = {
|
|
2622
|
-
identification: galleryIdentification,
|
|
2623
|
-
projectIdentification: galleryProjectIdentification,
|
|
2624
|
-
resources: data.result.gallery.resource ? Array.isArray(data.result.gallery.resource) ? parseResources(data.result.gallery.resource) : [parseResource(data.result.gallery.resource)] : [],
|
|
2625
|
-
maxLength: data.result.gallery.maxLength
|
|
2626
|
-
};
|
|
2627
|
-
return gallery;
|
|
2628
|
-
} catch (error) {
|
|
2629
|
-
console.error(error);
|
|
2630
|
-
return null;
|
|
2631
|
-
}
|
|
2632
|
-
}
|
|
2633
|
-
|
|
2634
|
-
// src/utils/fetchers/period.ts
|
|
2635
|
-
async function fetchPeriod(uuid) {
|
|
2636
|
-
try {
|
|
2637
|
-
const [error, dataRaw] = await fetchByUuid(uuid);
|
|
2638
|
-
if (error !== null) {
|
|
2639
|
-
throw new Error(error);
|
|
2493
|
+
const dataRaw = await response.json();
|
|
2494
|
+
if (!("ochre" in dataRaw)) {
|
|
2495
|
+
throw new Error("Invalid OCHRE data: API response missing 'ochre' key");
|
|
2640
2496
|
}
|
|
2641
|
-
|
|
2642
|
-
throw new Error("Invalid OCHRE data: API response missing 'period' key");
|
|
2643
|
-
}
|
|
2644
|
-
const periodItem = parsePeriod(dataRaw.ochre.period);
|
|
2645
|
-
const data = {
|
|
2646
|
-
uuid: parseFakeString(dataRaw.ochre.uuid),
|
|
2647
|
-
publicationDateTime: new Date(dataRaw.ochre.publicationDateTime),
|
|
2648
|
-
belongsTo: {
|
|
2649
|
-
uuid: dataRaw.ochre.uuidBelongsTo,
|
|
2650
|
-
abbreviation: parseFakeString(dataRaw.ochre.belongsTo)
|
|
2651
|
-
},
|
|
2652
|
-
metadata: parseMetadata(dataRaw.ochre.metadata),
|
|
2653
|
-
item: periodItem
|
|
2654
|
-
};
|
|
2655
|
-
return { metadata: data.metadata, period: data.item };
|
|
2497
|
+
return [null, dataRaw];
|
|
2656
2498
|
} catch (error) {
|
|
2657
|
-
|
|
2658
|
-
return null;
|
|
2499
|
+
return [error instanceof Error ? error.message : "Unknown error", null];
|
|
2659
2500
|
}
|
|
2660
2501
|
}
|
|
2661
2502
|
|
|
2662
|
-
// src/utils/fetchers/
|
|
2663
|
-
async function
|
|
2503
|
+
// src/utils/fetchers/item.ts
|
|
2504
|
+
async function fetchItem(uuid, category) {
|
|
2664
2505
|
try {
|
|
2665
|
-
const [error,
|
|
2506
|
+
const [error, data] = await fetchByUuid(uuid);
|
|
2666
2507
|
if (error !== null) {
|
|
2667
2508
|
throw new Error(error);
|
|
2668
2509
|
}
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2510
|
+
const categoryKey = getItemCategory(Object.keys(data.ochre));
|
|
2511
|
+
let item;
|
|
2512
|
+
switch (categoryKey) {
|
|
2513
|
+
case "resource": {
|
|
2514
|
+
if (!("resource" in data.ochre)) {
|
|
2515
|
+
throw new Error(
|
|
2516
|
+
"Invalid OCHRE data: API response missing 'resource' key"
|
|
2517
|
+
);
|
|
2518
|
+
}
|
|
2519
|
+
item = parseResource(data.ochre.resource);
|
|
2520
|
+
break;
|
|
2521
|
+
}
|
|
2522
|
+
case "spatialUnit": {
|
|
2523
|
+
if (!("spatialUnit" in data.ochre)) {
|
|
2524
|
+
throw new Error(
|
|
2525
|
+
"Invalid OCHRE data: API response missing 'spatialUnit' key"
|
|
2526
|
+
);
|
|
2527
|
+
}
|
|
2528
|
+
item = parseSpatialUnit(data.ochre.spatialUnit);
|
|
2529
|
+
break;
|
|
2530
|
+
}
|
|
2531
|
+
case "concept": {
|
|
2532
|
+
if (!("concept" in data.ochre)) {
|
|
2533
|
+
throw new Error(
|
|
2534
|
+
"Invalid OCHRE data: API response missing 'concept' key"
|
|
2535
|
+
);
|
|
2536
|
+
}
|
|
2537
|
+
item = parseConcept(data.ochre.concept);
|
|
2538
|
+
break;
|
|
2539
|
+
}
|
|
2540
|
+
case "period": {
|
|
2541
|
+
if (!("period" in data.ochre)) {
|
|
2542
|
+
throw new Error(
|
|
2543
|
+
"Invalid OCHRE data: API response missing 'period' key"
|
|
2544
|
+
);
|
|
2545
|
+
}
|
|
2546
|
+
item = parsePeriod(data.ochre.period);
|
|
2547
|
+
break;
|
|
2548
|
+
}
|
|
2549
|
+
case "bibliography": {
|
|
2550
|
+
if (!("bibliography" in data.ochre)) {
|
|
2551
|
+
throw new Error(
|
|
2552
|
+
"Invalid OCHRE data: API response missing 'bibliography' key"
|
|
2553
|
+
);
|
|
2554
|
+
}
|
|
2555
|
+
item = parseBibliography(data.ochre.bibliography);
|
|
2556
|
+
break;
|
|
2557
|
+
}
|
|
2558
|
+
case "person": {
|
|
2559
|
+
if (!("person" in data.ochre)) {
|
|
2560
|
+
throw new Error(
|
|
2561
|
+
"Invalid OCHRE data: API response missing 'person' key"
|
|
2562
|
+
);
|
|
2563
|
+
}
|
|
2564
|
+
item = parsePerson(data.ochre.person);
|
|
2565
|
+
break;
|
|
2566
|
+
}
|
|
2567
|
+
case "propertyValue": {
|
|
2568
|
+
if (!("propertyValue" in data.ochre)) {
|
|
2569
|
+
throw new Error(
|
|
2570
|
+
"Invalid OCHRE data: API response missing 'propertyValue' key"
|
|
2571
|
+
);
|
|
2572
|
+
}
|
|
2573
|
+
item = parsePropertyValue(data.ochre.propertyValue);
|
|
2574
|
+
break;
|
|
2575
|
+
}
|
|
2576
|
+
case "set": {
|
|
2577
|
+
if (!("set" in data.ochre)) {
|
|
2578
|
+
throw new Error("Invalid OCHRE data: API response missing 'set' key");
|
|
2579
|
+
}
|
|
2580
|
+
item = parseSet(data.ochre.set);
|
|
2581
|
+
break;
|
|
2582
|
+
}
|
|
2583
|
+
case "tree": {
|
|
2584
|
+
if (!("tree" in data.ochre)) {
|
|
2585
|
+
throw new Error(
|
|
2586
|
+
"Invalid OCHRE data: API response missing 'tree' key"
|
|
2587
|
+
);
|
|
2588
|
+
}
|
|
2589
|
+
item = parseTree(data.ochre.tree);
|
|
2590
|
+
break;
|
|
2591
|
+
}
|
|
2592
|
+
default: {
|
|
2593
|
+
throw new Error("Invalid category");
|
|
2594
|
+
}
|
|
2698
2595
|
}
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
const data = {
|
|
2704
|
-
uuid: parseFakeString(dataRaw.ochre.uuid),
|
|
2705
|
-
publicationDateTime: new Date(dataRaw.ochre.publicationDateTime),
|
|
2706
|
-
belongsTo: {
|
|
2707
|
-
uuid: dataRaw.ochre.uuidBelongsTo,
|
|
2708
|
-
abbreviation: parseFakeString(dataRaw.ochre.belongsTo)
|
|
2709
|
-
},
|
|
2710
|
-
metadata: parseMetadata(dataRaw.ochre.metadata),
|
|
2711
|
-
item: setItem
|
|
2596
|
+
const metadata = parseMetadata(data.ochre.metadata);
|
|
2597
|
+
const belongsTo = {
|
|
2598
|
+
uuid: data.ochre.uuidBelongsTo,
|
|
2599
|
+
abbreviation: parseFakeString(data.ochre.belongsTo)
|
|
2712
2600
|
};
|
|
2713
|
-
return {
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
// src/utils/fetchers/spatial-unit.ts
|
|
2721
|
-
async function fetchSpatialUnit(uuid) {
|
|
2722
|
-
try {
|
|
2723
|
-
const [error, dataRaw] = await fetchByUuid(uuid);
|
|
2724
|
-
if (error !== null) {
|
|
2725
|
-
throw new Error(error);
|
|
2726
|
-
}
|
|
2727
|
-
if (!("spatialUnit" in dataRaw.ochre)) {
|
|
2728
|
-
throw new Error(
|
|
2729
|
-
"Invalid OCHRE data: API response missing 'spatialUnit' key"
|
|
2730
|
-
);
|
|
2731
|
-
}
|
|
2732
|
-
const spatialUnitItem = parseSpatialUnit(dataRaw.ochre.spatialUnit);
|
|
2733
|
-
const data = {
|
|
2734
|
-
uuid: parseFakeString(dataRaw.ochre.uuid),
|
|
2735
|
-
publicationDateTime: new Date(dataRaw.ochre.publicationDateTime),
|
|
2736
|
-
belongsTo: {
|
|
2737
|
-
uuid: dataRaw.ochre.uuidBelongsTo,
|
|
2738
|
-
abbreviation: parseFakeString(dataRaw.ochre.belongsTo)
|
|
2739
|
-
},
|
|
2740
|
-
metadata: parseMetadata(dataRaw.ochre.metadata),
|
|
2741
|
-
item: spatialUnitItem
|
|
2601
|
+
return {
|
|
2602
|
+
error: null,
|
|
2603
|
+
metadata,
|
|
2604
|
+
belongsTo,
|
|
2605
|
+
item,
|
|
2606
|
+
category
|
|
2742
2607
|
};
|
|
2743
|
-
return { metadata: data.metadata, spatialUnit: data.item };
|
|
2744
2608
|
} catch (error) {
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
async function fetchTree(uuid) {
|
|
2752
|
-
try {
|
|
2753
|
-
const [error, dataRaw] = await fetchByUuid(uuid);
|
|
2754
|
-
if (error !== null) {
|
|
2755
|
-
throw new Error(error);
|
|
2756
|
-
}
|
|
2757
|
-
if (!("tree" in dataRaw.ochre)) {
|
|
2758
|
-
throw new Error("Invalid OCHRE data: API response missing 'tree' key");
|
|
2759
|
-
}
|
|
2760
|
-
const tree = parseTree(dataRaw.ochre.tree);
|
|
2761
|
-
if (!tree) {
|
|
2762
|
-
throw new Error("Invalid OCHRE data: Could not parse tree");
|
|
2763
|
-
}
|
|
2764
|
-
const data = {
|
|
2765
|
-
uuid: parseFakeString(dataRaw.ochre.uuid),
|
|
2766
|
-
publicationDateTime: new Date(dataRaw.ochre.publicationDateTime),
|
|
2767
|
-
belongsTo: {
|
|
2768
|
-
uuid: dataRaw.ochre.uuidBelongsTo,
|
|
2769
|
-
abbreviation: parseFakeString(dataRaw.ochre.belongsTo)
|
|
2770
|
-
},
|
|
2771
|
-
metadata: parseMetadata(dataRaw.ochre.metadata),
|
|
2772
|
-
item: tree
|
|
2609
|
+
return {
|
|
2610
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
2611
|
+
metadata: void 0,
|
|
2612
|
+
belongsTo: void 0,
|
|
2613
|
+
item: void 0,
|
|
2614
|
+
category: void 0
|
|
2773
2615
|
};
|
|
2774
|
-
return { metadata: data.metadata, tree: data.item };
|
|
2775
|
-
} catch (error) {
|
|
2776
|
-
console.error(error);
|
|
2777
|
-
return null;
|
|
2778
|
-
}
|
|
2779
|
-
}
|
|
2780
|
-
|
|
2781
|
-
// src/utils/fetchers/website.ts
|
|
2782
|
-
async function fetchWebsite(abbreviation) {
|
|
2783
|
-
try {
|
|
2784
|
-
const response = await fetch(
|
|
2785
|
-
`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`
|
|
2786
|
-
);
|
|
2787
|
-
if (!response.ok) {
|
|
2788
|
-
throw new Error("Failed to fetch website");
|
|
2789
|
-
}
|
|
2790
|
-
const data = await response.json();
|
|
2791
|
-
if (!("ochre" in data.result) || !("tree" in data.result.ochre)) {
|
|
2792
|
-
throw new Error("Failed to fetch website");
|
|
2793
|
-
}
|
|
2794
|
-
const projectIdentification = data.result.ochre.metadata.project?.identification ? parseIdentification(data.result.ochre.metadata.project.identification) : null;
|
|
2795
|
-
const website = await parseWebsite(
|
|
2796
|
-
data.result.ochre.tree,
|
|
2797
|
-
projectIdentification?.label ?? "",
|
|
2798
|
-
data.result.ochre.metadata.project?.identification.website ?? null
|
|
2799
|
-
);
|
|
2800
|
-
return website;
|
|
2801
|
-
} catch (error) {
|
|
2802
|
-
console.error(error);
|
|
2803
|
-
return null;
|
|
2804
2616
|
}
|
|
2805
2617
|
}
|
|
2806
2618
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2807
2619
|
0 && (module.exports = {
|
|
2808
|
-
fetchBibliography,
|
|
2809
2620
|
fetchByUuid,
|
|
2810
|
-
|
|
2811
|
-
fetchGallery,
|
|
2812
|
-
fetchPeriod,
|
|
2813
|
-
fetchPropertyValue,
|
|
2814
|
-
fetchResource,
|
|
2815
|
-
fetchSet,
|
|
2816
|
-
fetchSpatialUnit,
|
|
2817
|
-
fetchTree,
|
|
2818
|
-
fetchWebsite,
|
|
2621
|
+
fetchItem,
|
|
2819
2622
|
filterProperties,
|
|
2820
2623
|
getAllPropertyLabels,
|
|
2821
2624
|
getPropertyByLabel,
|