@digitalculture/ochre-sdk 0.6.1 → 0.6.3
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 +221 -141
- package/dist/index.d.cts +66 -1
- package/dist/index.d.ts +66 -1
- package/dist/index.js +219 -141
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -21,7 +21,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
fetchByUuid: () => fetchByUuid,
|
|
24
|
+
fetchGallery: () => fetchGallery,
|
|
24
25
|
fetchItem: () => fetchItem,
|
|
26
|
+
fetchWebsite: () => fetchWebsite,
|
|
25
27
|
filterProperties: () => filterProperties,
|
|
26
28
|
getAllPropertyLabels: () => getAllPropertyLabels,
|
|
27
29
|
getPropertyByLabel: () => getPropertyByLabel,
|
|
@@ -158,28 +160,6 @@ var whitespaceSchema = import_zod.z.string().transform((str) => str.split(" ")).
|
|
|
158
160
|
);
|
|
159
161
|
var emailSchema = import_zod.z.string().email({ message: "Invalid email" });
|
|
160
162
|
|
|
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
163
|
// src/utils/getters.ts
|
|
184
164
|
var DEFAULT_OPTIONS = {
|
|
185
165
|
searchNestedProperties: false
|
|
@@ -588,6 +568,164 @@ ${JSON.stringify(
|
|
|
588
568
|
}
|
|
589
569
|
}
|
|
590
570
|
|
|
571
|
+
// src/utils/helpers.ts
|
|
572
|
+
function getItemCategory(keys) {
|
|
573
|
+
const categoryFound = keys.find(
|
|
574
|
+
(key) => categorySchema.safeParse(key).success
|
|
575
|
+
);
|
|
576
|
+
if (!categoryFound) {
|
|
577
|
+
const unknownKey = keys.find(
|
|
578
|
+
(key) => ![
|
|
579
|
+
"uuid",
|
|
580
|
+
"uuidBelongsTo",
|
|
581
|
+
"belongsTo",
|
|
582
|
+
"publicationDateTime",
|
|
583
|
+
"metadata",
|
|
584
|
+
"languages"
|
|
585
|
+
].includes(key)
|
|
586
|
+
);
|
|
587
|
+
throw new Error(`Invalid OCHRE data; found unexpected "${unknownKey}" key`);
|
|
588
|
+
}
|
|
589
|
+
const categoryKey = categorySchema.parse(categoryFound);
|
|
590
|
+
return categoryKey;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// src/utils/fetchers/uuid.ts
|
|
594
|
+
async function fetchByUuid(uuid) {
|
|
595
|
+
try {
|
|
596
|
+
const parsedUuid = uuidSchema.parse(uuid);
|
|
597
|
+
const response = await fetch(
|
|
598
|
+
`https://ochre.lib.uchicago.edu/ochre?uuid=${parsedUuid}&format=json&lang="*"`
|
|
599
|
+
);
|
|
600
|
+
if (!response.ok) {
|
|
601
|
+
throw new Error("Failed to fetch OCHRE data");
|
|
602
|
+
}
|
|
603
|
+
const dataRaw = await response.json();
|
|
604
|
+
if (!("ochre" in dataRaw)) {
|
|
605
|
+
throw new Error("Invalid OCHRE data: API response missing 'ochre' key");
|
|
606
|
+
}
|
|
607
|
+
return [null, dataRaw];
|
|
608
|
+
} catch (error) {
|
|
609
|
+
return [error instanceof Error ? error.message : "Unknown error", null];
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
// src/utils/fetchers/item.ts
|
|
614
|
+
async function fetchItem(uuid, category) {
|
|
615
|
+
try {
|
|
616
|
+
const [error, data] = await fetchByUuid(uuid);
|
|
617
|
+
if (error !== null) {
|
|
618
|
+
throw new Error(error);
|
|
619
|
+
}
|
|
620
|
+
const categoryKey = getItemCategory(Object.keys(data.ochre));
|
|
621
|
+
let item;
|
|
622
|
+
switch (categoryKey) {
|
|
623
|
+
case "resource": {
|
|
624
|
+
if (!("resource" in data.ochre)) {
|
|
625
|
+
throw new Error(
|
|
626
|
+
"Invalid OCHRE data: API response missing 'resource' key"
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
item = parseResource(data.ochre.resource);
|
|
630
|
+
break;
|
|
631
|
+
}
|
|
632
|
+
case "spatialUnit": {
|
|
633
|
+
if (!("spatialUnit" in data.ochre)) {
|
|
634
|
+
throw new Error(
|
|
635
|
+
"Invalid OCHRE data: API response missing 'spatialUnit' key"
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
item = parseSpatialUnit(data.ochre.spatialUnit);
|
|
639
|
+
break;
|
|
640
|
+
}
|
|
641
|
+
case "concept": {
|
|
642
|
+
if (!("concept" in data.ochre)) {
|
|
643
|
+
throw new Error(
|
|
644
|
+
"Invalid OCHRE data: API response missing 'concept' key"
|
|
645
|
+
);
|
|
646
|
+
}
|
|
647
|
+
item = parseConcept(data.ochre.concept);
|
|
648
|
+
break;
|
|
649
|
+
}
|
|
650
|
+
case "period": {
|
|
651
|
+
if (!("period" in data.ochre)) {
|
|
652
|
+
throw new Error(
|
|
653
|
+
"Invalid OCHRE data: API response missing 'period' key"
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
item = parsePeriod(data.ochre.period);
|
|
657
|
+
break;
|
|
658
|
+
}
|
|
659
|
+
case "bibliography": {
|
|
660
|
+
if (!("bibliography" in data.ochre)) {
|
|
661
|
+
throw new Error(
|
|
662
|
+
"Invalid OCHRE data: API response missing 'bibliography' key"
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
item = parseBibliography(data.ochre.bibliography);
|
|
666
|
+
break;
|
|
667
|
+
}
|
|
668
|
+
case "person": {
|
|
669
|
+
if (!("person" in data.ochre)) {
|
|
670
|
+
throw new Error(
|
|
671
|
+
"Invalid OCHRE data: API response missing 'person' key"
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
item = parsePerson(data.ochre.person);
|
|
675
|
+
break;
|
|
676
|
+
}
|
|
677
|
+
case "propertyValue": {
|
|
678
|
+
if (!("propertyValue" in data.ochre)) {
|
|
679
|
+
throw new Error(
|
|
680
|
+
"Invalid OCHRE data: API response missing 'propertyValue' key"
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
item = parsePropertyValue(data.ochre.propertyValue);
|
|
684
|
+
break;
|
|
685
|
+
}
|
|
686
|
+
case "set": {
|
|
687
|
+
if (!("set" in data.ochre)) {
|
|
688
|
+
throw new Error("Invalid OCHRE data: API response missing 'set' key");
|
|
689
|
+
}
|
|
690
|
+
item = parseSet(data.ochre.set);
|
|
691
|
+
break;
|
|
692
|
+
}
|
|
693
|
+
case "tree": {
|
|
694
|
+
if (!("tree" in data.ochre)) {
|
|
695
|
+
throw new Error(
|
|
696
|
+
"Invalid OCHRE data: API response missing 'tree' key"
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
item = parseTree(data.ochre.tree);
|
|
700
|
+
break;
|
|
701
|
+
}
|
|
702
|
+
default: {
|
|
703
|
+
throw new Error("Invalid category");
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
const metadata = parseMetadata(data.ochre.metadata);
|
|
707
|
+
const belongsTo = {
|
|
708
|
+
uuid: data.ochre.uuidBelongsTo,
|
|
709
|
+
abbreviation: parseFakeString(data.ochre.belongsTo)
|
|
710
|
+
};
|
|
711
|
+
return {
|
|
712
|
+
error: null,
|
|
713
|
+
metadata,
|
|
714
|
+
belongsTo,
|
|
715
|
+
item,
|
|
716
|
+
category
|
|
717
|
+
};
|
|
718
|
+
} catch (error) {
|
|
719
|
+
return {
|
|
720
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
721
|
+
metadata: void 0,
|
|
722
|
+
belongsTo: void 0,
|
|
723
|
+
item: void 0,
|
|
724
|
+
category: void 0
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
|
|
591
729
|
// src/utils/parse.ts
|
|
592
730
|
function parseIdentification(identification) {
|
|
593
731
|
try {
|
|
@@ -2480,145 +2618,87 @@ async function parseWebsite(websiteTree, projectName, website) {
|
|
|
2480
2618
|
};
|
|
2481
2619
|
}
|
|
2482
2620
|
|
|
2483
|
-
// src/utils/fetchers/
|
|
2484
|
-
async function
|
|
2621
|
+
// src/utils/fetchers/gallery.ts
|
|
2622
|
+
async function fetchGallery(uuid, filter, page, perPage) {
|
|
2485
2623
|
try {
|
|
2486
|
-
const
|
|
2624
|
+
const {
|
|
2625
|
+
uuid: parsedUuid,
|
|
2626
|
+
filter: parsedFilter,
|
|
2627
|
+
page: parsedPage,
|
|
2628
|
+
perPage: parsedPerPage
|
|
2629
|
+
} = gallerySchema.parse({ uuid, filter, page, perPage });
|
|
2487
2630
|
const response = await fetch(
|
|
2488
|
-
`https://ochre.lib.uchicago.edu/ochre?
|
|
2631
|
+
`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
|
|
2632
|
+
for $q in input()/ochre[@uuid='${parsedUuid}']
|
|
2633
|
+
let $filtered := $q/tree/items/resource[contains(lower-case(identification/label), lower-case('${parsedFilter}'))]
|
|
2634
|
+
let $maxLength := count($filtered)
|
|
2635
|
+
return <gallery maxLength='{$maxLength}'>
|
|
2636
|
+
{$q/metadata/project}
|
|
2637
|
+
{$q/metadata/item}
|
|
2638
|
+
{$filtered[position() >= ${((parsedPage - 1) * parsedPerPage + 1).toString()} and position() < ${(parsedPage * parsedPerPage + 1).toString()}]}
|
|
2639
|
+
</gallery>
|
|
2640
|
+
`)}&format=json`
|
|
2489
2641
|
);
|
|
2490
2642
|
if (!response.ok) {
|
|
2491
|
-
throw new Error("
|
|
2643
|
+
throw new Error("Error fetching gallery items, please try again later.");
|
|
2492
2644
|
}
|
|
2493
|
-
const
|
|
2494
|
-
if (!("
|
|
2495
|
-
throw new Error("
|
|
2645
|
+
const data = await response.json();
|
|
2646
|
+
if (!("gallery" in data.result)) {
|
|
2647
|
+
throw new Error("Failed to fetch gallery");
|
|
2496
2648
|
}
|
|
2497
|
-
|
|
2649
|
+
const galleryIdentification = parseIdentification(
|
|
2650
|
+
data.result.gallery.item.identification
|
|
2651
|
+
);
|
|
2652
|
+
const galleryProjectIdentification = parseIdentification(
|
|
2653
|
+
data.result.gallery.project.identification
|
|
2654
|
+
);
|
|
2655
|
+
const gallery = {
|
|
2656
|
+
identification: galleryIdentification,
|
|
2657
|
+
projectIdentification: galleryProjectIdentification,
|
|
2658
|
+
resources: data.result.gallery.resource ? Array.isArray(data.result.gallery.resource) ? parseResources(data.result.gallery.resource) : [parseResource(data.result.gallery.resource)] : [],
|
|
2659
|
+
maxLength: data.result.gallery.maxLength
|
|
2660
|
+
};
|
|
2661
|
+
return { item: gallery, error: null };
|
|
2498
2662
|
} catch (error) {
|
|
2499
|
-
|
|
2663
|
+
console.error(error);
|
|
2664
|
+
return {
|
|
2665
|
+
item: null,
|
|
2666
|
+
error: error instanceof Error ? error.message : "Failed to fetch gallery"
|
|
2667
|
+
};
|
|
2500
2668
|
}
|
|
2501
2669
|
}
|
|
2502
2670
|
|
|
2503
|
-
// src/utils/fetchers/
|
|
2504
|
-
async function
|
|
2671
|
+
// src/utils/fetchers/website.ts
|
|
2672
|
+
async function fetchWebsite(abbreviation) {
|
|
2505
2673
|
try {
|
|
2506
|
-
const
|
|
2507
|
-
|
|
2508
|
-
|
|
2674
|
+
const response = await fetch(
|
|
2675
|
+
`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`
|
|
2676
|
+
);
|
|
2677
|
+
if (!response.ok) {
|
|
2678
|
+
throw new Error("Failed to fetch website");
|
|
2509
2679
|
}
|
|
2510
|
-
const
|
|
2511
|
-
|
|
2512
|
-
|
|
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
|
-
}
|
|
2680
|
+
const data = await response.json();
|
|
2681
|
+
if (!("ochre" in data.result) || !("tree" in data.result.ochre)) {
|
|
2682
|
+
throw new Error("Failed to fetch website");
|
|
2595
2683
|
}
|
|
2596
|
-
const
|
|
2597
|
-
const
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
metadata,
|
|
2604
|
-
belongsTo,
|
|
2605
|
-
item,
|
|
2606
|
-
category
|
|
2607
|
-
};
|
|
2684
|
+
const projectIdentification = data.result.ochre.metadata.project?.identification ? parseIdentification(data.result.ochre.metadata.project.identification) : null;
|
|
2685
|
+
const website = await parseWebsite(
|
|
2686
|
+
data.result.ochre.tree,
|
|
2687
|
+
projectIdentification?.label ?? "",
|
|
2688
|
+
data.result.ochre.metadata.project?.identification.website ?? null
|
|
2689
|
+
);
|
|
2690
|
+
return website;
|
|
2608
2691
|
} catch (error) {
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
metadata: void 0,
|
|
2612
|
-
belongsTo: void 0,
|
|
2613
|
-
item: void 0,
|
|
2614
|
-
category: void 0
|
|
2615
|
-
};
|
|
2692
|
+
console.error(error);
|
|
2693
|
+
return null;
|
|
2616
2694
|
}
|
|
2617
2695
|
}
|
|
2618
2696
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2619
2697
|
0 && (module.exports = {
|
|
2620
2698
|
fetchByUuid,
|
|
2699
|
+
fetchGallery,
|
|
2621
2700
|
fetchItem,
|
|
2701
|
+
fetchWebsite,
|
|
2622
2702
|
filterProperties,
|
|
2623
2703
|
getAllPropertyLabels,
|
|
2624
2704
|
getPropertyByLabel,
|
package/dist/index.d.cts
CHANGED
|
@@ -619,6 +619,40 @@ type WebBlock = {
|
|
|
619
619
|
cssStylesMobile: Array<Style>;
|
|
620
620
|
};
|
|
621
621
|
|
|
622
|
+
/**
|
|
623
|
+
* Fetches and parses a gallery from the OCHRE API
|
|
624
|
+
*
|
|
625
|
+
* @param uuid - The UUID of the gallery
|
|
626
|
+
* @param filter - The filter to apply to the gallery
|
|
627
|
+
* @param page - The page number to fetch
|
|
628
|
+
* @param perPage - The number of items per page
|
|
629
|
+
* @returns The parsed gallery or null if the fetch/parse fails
|
|
630
|
+
*
|
|
631
|
+
* @example
|
|
632
|
+
* ```ts
|
|
633
|
+
* const gallery = await fetchGallery("9c4da06b-f15e-40af-a747-0933eaf3587e", "1978", 1, 12);
|
|
634
|
+
* if (gallery === null) {
|
|
635
|
+
* console.error("Failed to fetch gallery");
|
|
636
|
+
* return;
|
|
637
|
+
* }
|
|
638
|
+
* console.log(`Fetched gallery: ${gallery.identification.label}`);
|
|
639
|
+
* console.log(`Contains ${gallery.resources.length.toLocaleString()} resources`);
|
|
640
|
+
* ```
|
|
641
|
+
*
|
|
642
|
+
* @remarks
|
|
643
|
+
* The returned gallery includes:
|
|
644
|
+
* - Gallery metadata and identification
|
|
645
|
+
* - Project identification
|
|
646
|
+
* - Resources (gallery items)
|
|
647
|
+
*/
|
|
648
|
+
declare function fetchGallery(uuid: string, filter: string, page: number, perPage: number): Promise<{
|
|
649
|
+
item: Gallery | null;
|
|
650
|
+
error: null;
|
|
651
|
+
} | {
|
|
652
|
+
item: null;
|
|
653
|
+
error: string;
|
|
654
|
+
}>;
|
|
655
|
+
|
|
622
656
|
/**
|
|
623
657
|
* Fetches and parses an OCHRE item from the OCHRE API
|
|
624
658
|
*
|
|
@@ -1256,6 +1290,37 @@ type OchrePropertyValue = {
|
|
|
1256
1290
|
*/
|
|
1257
1291
|
declare function fetchByUuid(uuid: string): Promise<[null, OchreData] | [string, null]>;
|
|
1258
1292
|
|
|
1293
|
+
/**
|
|
1294
|
+
* Fetches and parses a website configuration from the OCHRE API
|
|
1295
|
+
*
|
|
1296
|
+
* @param abbreviation - The abbreviation identifier for the website
|
|
1297
|
+
* @returns The parsed website configuration or null if the fetch/parse fails
|
|
1298
|
+
*
|
|
1299
|
+
* @example
|
|
1300
|
+
* ```ts
|
|
1301
|
+
* const website = await fetchWebsite("guerrilla-television");
|
|
1302
|
+
* if (website === null) {
|
|
1303
|
+
* console.error("Failed to fetch website");
|
|
1304
|
+
* return;
|
|
1305
|
+
* }
|
|
1306
|
+
* console.log(`Fetched website: ${website.identification.label}`);
|
|
1307
|
+
* console.log(`Contains ${website.pages.length.toLocaleString()} pages`);
|
|
1308
|
+
* ```
|
|
1309
|
+
*
|
|
1310
|
+
* @remarks
|
|
1311
|
+
* The returned website configuration includes:
|
|
1312
|
+
* - Website metadata and identification
|
|
1313
|
+
* - Page structure and content
|
|
1314
|
+
* - Layout and styling properties
|
|
1315
|
+
* - Navigation configuration
|
|
1316
|
+
* - Sidebar elements
|
|
1317
|
+
* - Project information
|
|
1318
|
+
* - Creator details
|
|
1319
|
+
*
|
|
1320
|
+
* The abbreviation is case-insensitive and should match the website's configured abbreviation in OCHRE.
|
|
1321
|
+
*/
|
|
1322
|
+
declare function fetchWebsite(abbreviation: string): Promise<Website | null>;
|
|
1323
|
+
|
|
1259
1324
|
/**
|
|
1260
1325
|
* Options for property search operations
|
|
1261
1326
|
*/
|
|
@@ -1644,4 +1709,4 @@ declare function parseStringDocumentItem(item: OchreStringRichTextItem, footnote
|
|
|
1644
1709
|
*/
|
|
1645
1710
|
declare function parseStringContent(content: OchreStringContent, language?: string): string;
|
|
1646
1711
|
|
|
1647
|
-
export { type Bibliography, type Concept, type Context, type ContextItem, type ContextNode, type Coordinates, type Data, type DataCategory, type Document, type Event, type Footnote, type Gallery, type Identification, type Image, type ImageMap, type ImageMapArea, type Interpretation, type License, type Link, type Metadata, type Note, type Observation, type Period, type Person, type Property, type PropertyValue, type PropertyValueContent, type PropertyValueContentType, type Resource, type Set, type SpatialUnit, type Style, type Tree, type WebBlock, type WebElement, type WebElementComponent, type WebImage, type Webpage, type WebpageProperties, type Website, type WebsiteProperties, fetchByUuid, fetchItem, filterProperties, getAllPropertyLabels, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, parseBibliographies, parseBibliography, parseConcept, parseConcepts, parseContext, parseCoordinates, parseDocument, parseEmail, parseEvents, parseFakeString, parseIdentification, parseImage, parseImageMap, parseInterpretations, parseLanguages, parseLicense, parseLink, parseLinks, parseMetadata, parseNotes, parseObservation, parseObservations, parsePeriod, parsePeriods, parsePerson, parsePersons, parseProperties, parseProperty, parsePropertyValue, parsePropertyValues, parseResource, parseResources, parseSet, parseSpatialUnit, parseSpatialUnits, parseStringContent, parseStringDocumentItem, parseStringItem, parseTree, parseWebsite };
|
|
1712
|
+
export { type Bibliography, type Concept, type Context, type ContextItem, type ContextNode, type Coordinates, type Data, type DataCategory, type Document, type Event, type Footnote, type Gallery, type Identification, type Image, type ImageMap, type ImageMapArea, type Interpretation, type License, type Link, type Metadata, type Note, type Observation, type Period, type Person, type Property, type PropertyValue, type PropertyValueContent, type PropertyValueContentType, type Resource, type Set, type SpatialUnit, type Style, type Tree, type WebBlock, type WebElement, type WebElementComponent, type WebImage, type Webpage, type WebpageProperties, type Website, type WebsiteProperties, fetchByUuid, fetchGallery, fetchItem, fetchWebsite, filterProperties, getAllPropertyLabels, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, parseBibliographies, parseBibliography, parseConcept, parseConcepts, parseContext, parseCoordinates, parseDocument, parseEmail, parseEvents, parseFakeString, parseIdentification, parseImage, parseImageMap, parseInterpretations, parseLanguages, parseLicense, parseLink, parseLinks, parseMetadata, parseNotes, parseObservation, parseObservations, parsePeriod, parsePeriods, parsePerson, parsePersons, parseProperties, parseProperty, parsePropertyValue, parsePropertyValues, parseResource, parseResources, parseSet, parseSpatialUnit, parseSpatialUnits, parseStringContent, parseStringDocumentItem, parseStringItem, parseTree, parseWebsite };
|
package/dist/index.d.ts
CHANGED
|
@@ -619,6 +619,40 @@ type WebBlock = {
|
|
|
619
619
|
cssStylesMobile: Array<Style>;
|
|
620
620
|
};
|
|
621
621
|
|
|
622
|
+
/**
|
|
623
|
+
* Fetches and parses a gallery from the OCHRE API
|
|
624
|
+
*
|
|
625
|
+
* @param uuid - The UUID of the gallery
|
|
626
|
+
* @param filter - The filter to apply to the gallery
|
|
627
|
+
* @param page - The page number to fetch
|
|
628
|
+
* @param perPage - The number of items per page
|
|
629
|
+
* @returns The parsed gallery or null if the fetch/parse fails
|
|
630
|
+
*
|
|
631
|
+
* @example
|
|
632
|
+
* ```ts
|
|
633
|
+
* const gallery = await fetchGallery("9c4da06b-f15e-40af-a747-0933eaf3587e", "1978", 1, 12);
|
|
634
|
+
* if (gallery === null) {
|
|
635
|
+
* console.error("Failed to fetch gallery");
|
|
636
|
+
* return;
|
|
637
|
+
* }
|
|
638
|
+
* console.log(`Fetched gallery: ${gallery.identification.label}`);
|
|
639
|
+
* console.log(`Contains ${gallery.resources.length.toLocaleString()} resources`);
|
|
640
|
+
* ```
|
|
641
|
+
*
|
|
642
|
+
* @remarks
|
|
643
|
+
* The returned gallery includes:
|
|
644
|
+
* - Gallery metadata and identification
|
|
645
|
+
* - Project identification
|
|
646
|
+
* - Resources (gallery items)
|
|
647
|
+
*/
|
|
648
|
+
declare function fetchGallery(uuid: string, filter: string, page: number, perPage: number): Promise<{
|
|
649
|
+
item: Gallery | null;
|
|
650
|
+
error: null;
|
|
651
|
+
} | {
|
|
652
|
+
item: null;
|
|
653
|
+
error: string;
|
|
654
|
+
}>;
|
|
655
|
+
|
|
622
656
|
/**
|
|
623
657
|
* Fetches and parses an OCHRE item from the OCHRE API
|
|
624
658
|
*
|
|
@@ -1256,6 +1290,37 @@ type OchrePropertyValue = {
|
|
|
1256
1290
|
*/
|
|
1257
1291
|
declare function fetchByUuid(uuid: string): Promise<[null, OchreData] | [string, null]>;
|
|
1258
1292
|
|
|
1293
|
+
/**
|
|
1294
|
+
* Fetches and parses a website configuration from the OCHRE API
|
|
1295
|
+
*
|
|
1296
|
+
* @param abbreviation - The abbreviation identifier for the website
|
|
1297
|
+
* @returns The parsed website configuration or null if the fetch/parse fails
|
|
1298
|
+
*
|
|
1299
|
+
* @example
|
|
1300
|
+
* ```ts
|
|
1301
|
+
* const website = await fetchWebsite("guerrilla-television");
|
|
1302
|
+
* if (website === null) {
|
|
1303
|
+
* console.error("Failed to fetch website");
|
|
1304
|
+
* return;
|
|
1305
|
+
* }
|
|
1306
|
+
* console.log(`Fetched website: ${website.identification.label}`);
|
|
1307
|
+
* console.log(`Contains ${website.pages.length.toLocaleString()} pages`);
|
|
1308
|
+
* ```
|
|
1309
|
+
*
|
|
1310
|
+
* @remarks
|
|
1311
|
+
* The returned website configuration includes:
|
|
1312
|
+
* - Website metadata and identification
|
|
1313
|
+
* - Page structure and content
|
|
1314
|
+
* - Layout and styling properties
|
|
1315
|
+
* - Navigation configuration
|
|
1316
|
+
* - Sidebar elements
|
|
1317
|
+
* - Project information
|
|
1318
|
+
* - Creator details
|
|
1319
|
+
*
|
|
1320
|
+
* The abbreviation is case-insensitive and should match the website's configured abbreviation in OCHRE.
|
|
1321
|
+
*/
|
|
1322
|
+
declare function fetchWebsite(abbreviation: string): Promise<Website | null>;
|
|
1323
|
+
|
|
1259
1324
|
/**
|
|
1260
1325
|
* Options for property search operations
|
|
1261
1326
|
*/
|
|
@@ -1644,4 +1709,4 @@ declare function parseStringDocumentItem(item: OchreStringRichTextItem, footnote
|
|
|
1644
1709
|
*/
|
|
1645
1710
|
declare function parseStringContent(content: OchreStringContent, language?: string): string;
|
|
1646
1711
|
|
|
1647
|
-
export { type Bibliography, type Concept, type Context, type ContextItem, type ContextNode, type Coordinates, type Data, type DataCategory, type Document, type Event, type Footnote, type Gallery, type Identification, type Image, type ImageMap, type ImageMapArea, type Interpretation, type License, type Link, type Metadata, type Note, type Observation, type Period, type Person, type Property, type PropertyValue, type PropertyValueContent, type PropertyValueContentType, type Resource, type Set, type SpatialUnit, type Style, type Tree, type WebBlock, type WebElement, type WebElementComponent, type WebImage, type Webpage, type WebpageProperties, type Website, type WebsiteProperties, fetchByUuid, fetchItem, filterProperties, getAllPropertyLabels, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, parseBibliographies, parseBibliography, parseConcept, parseConcepts, parseContext, parseCoordinates, parseDocument, parseEmail, parseEvents, parseFakeString, parseIdentification, parseImage, parseImageMap, parseInterpretations, parseLanguages, parseLicense, parseLink, parseLinks, parseMetadata, parseNotes, parseObservation, parseObservations, parsePeriod, parsePeriods, parsePerson, parsePersons, parseProperties, parseProperty, parsePropertyValue, parsePropertyValues, parseResource, parseResources, parseSet, parseSpatialUnit, parseSpatialUnits, parseStringContent, parseStringDocumentItem, parseStringItem, parseTree, parseWebsite };
|
|
1712
|
+
export { type Bibliography, type Concept, type Context, type ContextItem, type ContextNode, type Coordinates, type Data, type DataCategory, type Document, type Event, type Footnote, type Gallery, type Identification, type Image, type ImageMap, type ImageMapArea, type Interpretation, type License, type Link, type Metadata, type Note, type Observation, type Period, type Person, type Property, type PropertyValue, type PropertyValueContent, type PropertyValueContentType, type Resource, type Set, type SpatialUnit, type Style, type Tree, type WebBlock, type WebElement, type WebElementComponent, type WebImage, type Webpage, type WebpageProperties, type Website, type WebsiteProperties, fetchByUuid, fetchGallery, fetchItem, fetchWebsite, filterProperties, getAllPropertyLabels, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, parseBibliographies, parseBibliography, parseConcept, parseConcepts, parseContext, parseCoordinates, parseDocument, parseEmail, parseEvents, parseFakeString, parseIdentification, parseImage, parseImageMap, parseInterpretations, parseLanguages, parseLicense, parseLink, parseLinks, parseMetadata, parseNotes, parseObservation, parseObservations, parsePeriod, parsePeriods, parsePerson, parsePersons, parseProperties, parseProperty, parsePropertyValue, parsePropertyValues, parseResource, parseResources, parseSet, parseSpatialUnit, parseSpatialUnits, parseStringContent, parseStringDocumentItem, parseStringItem, parseTree, parseWebsite };
|
package/dist/index.js
CHANGED
|
@@ -86,28 +86,6 @@ var whitespaceSchema = z.string().transform((str) => str.split(" ")).pipe(
|
|
|
86
86
|
);
|
|
87
87
|
var emailSchema = z.string().email({ message: "Invalid email" });
|
|
88
88
|
|
|
89
|
-
// src/utils/helpers.ts
|
|
90
|
-
function getItemCategory(keys) {
|
|
91
|
-
const categoryFound = keys.find(
|
|
92
|
-
(key) => categorySchema.safeParse(key).success
|
|
93
|
-
);
|
|
94
|
-
if (!categoryFound) {
|
|
95
|
-
const unknownKey = keys.find(
|
|
96
|
-
(key) => ![
|
|
97
|
-
"uuid",
|
|
98
|
-
"uuidBelongsTo",
|
|
99
|
-
"belongsTo",
|
|
100
|
-
"publicationDateTime",
|
|
101
|
-
"metadata",
|
|
102
|
-
"languages"
|
|
103
|
-
].includes(key)
|
|
104
|
-
);
|
|
105
|
-
throw new Error(`Invalid OCHRE data; found unexpected "${unknownKey}" key`);
|
|
106
|
-
}
|
|
107
|
-
const categoryKey = categorySchema.parse(categoryFound);
|
|
108
|
-
return categoryKey;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
89
|
// src/utils/getters.ts
|
|
112
90
|
var DEFAULT_OPTIONS = {
|
|
113
91
|
searchNestedProperties: false
|
|
@@ -516,6 +494,164 @@ ${JSON.stringify(
|
|
|
516
494
|
}
|
|
517
495
|
}
|
|
518
496
|
|
|
497
|
+
// src/utils/helpers.ts
|
|
498
|
+
function getItemCategory(keys) {
|
|
499
|
+
const categoryFound = keys.find(
|
|
500
|
+
(key) => categorySchema.safeParse(key).success
|
|
501
|
+
);
|
|
502
|
+
if (!categoryFound) {
|
|
503
|
+
const unknownKey = keys.find(
|
|
504
|
+
(key) => ![
|
|
505
|
+
"uuid",
|
|
506
|
+
"uuidBelongsTo",
|
|
507
|
+
"belongsTo",
|
|
508
|
+
"publicationDateTime",
|
|
509
|
+
"metadata",
|
|
510
|
+
"languages"
|
|
511
|
+
].includes(key)
|
|
512
|
+
);
|
|
513
|
+
throw new Error(`Invalid OCHRE data; found unexpected "${unknownKey}" key`);
|
|
514
|
+
}
|
|
515
|
+
const categoryKey = categorySchema.parse(categoryFound);
|
|
516
|
+
return categoryKey;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// src/utils/fetchers/uuid.ts
|
|
520
|
+
async function fetchByUuid(uuid) {
|
|
521
|
+
try {
|
|
522
|
+
const parsedUuid = uuidSchema.parse(uuid);
|
|
523
|
+
const response = await fetch(
|
|
524
|
+
`https://ochre.lib.uchicago.edu/ochre?uuid=${parsedUuid}&format=json&lang="*"`
|
|
525
|
+
);
|
|
526
|
+
if (!response.ok) {
|
|
527
|
+
throw new Error("Failed to fetch OCHRE data");
|
|
528
|
+
}
|
|
529
|
+
const dataRaw = await response.json();
|
|
530
|
+
if (!("ochre" in dataRaw)) {
|
|
531
|
+
throw new Error("Invalid OCHRE data: API response missing 'ochre' key");
|
|
532
|
+
}
|
|
533
|
+
return [null, dataRaw];
|
|
534
|
+
} catch (error) {
|
|
535
|
+
return [error instanceof Error ? error.message : "Unknown error", null];
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// src/utils/fetchers/item.ts
|
|
540
|
+
async function fetchItem(uuid, category) {
|
|
541
|
+
try {
|
|
542
|
+
const [error, data] = await fetchByUuid(uuid);
|
|
543
|
+
if (error !== null) {
|
|
544
|
+
throw new Error(error);
|
|
545
|
+
}
|
|
546
|
+
const categoryKey = getItemCategory(Object.keys(data.ochre));
|
|
547
|
+
let item;
|
|
548
|
+
switch (categoryKey) {
|
|
549
|
+
case "resource": {
|
|
550
|
+
if (!("resource" in data.ochre)) {
|
|
551
|
+
throw new Error(
|
|
552
|
+
"Invalid OCHRE data: API response missing 'resource' key"
|
|
553
|
+
);
|
|
554
|
+
}
|
|
555
|
+
item = parseResource(data.ochre.resource);
|
|
556
|
+
break;
|
|
557
|
+
}
|
|
558
|
+
case "spatialUnit": {
|
|
559
|
+
if (!("spatialUnit" in data.ochre)) {
|
|
560
|
+
throw new Error(
|
|
561
|
+
"Invalid OCHRE data: API response missing 'spatialUnit' key"
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
item = parseSpatialUnit(data.ochre.spatialUnit);
|
|
565
|
+
break;
|
|
566
|
+
}
|
|
567
|
+
case "concept": {
|
|
568
|
+
if (!("concept" in data.ochre)) {
|
|
569
|
+
throw new Error(
|
|
570
|
+
"Invalid OCHRE data: API response missing 'concept' key"
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
item = parseConcept(data.ochre.concept);
|
|
574
|
+
break;
|
|
575
|
+
}
|
|
576
|
+
case "period": {
|
|
577
|
+
if (!("period" in data.ochre)) {
|
|
578
|
+
throw new Error(
|
|
579
|
+
"Invalid OCHRE data: API response missing 'period' key"
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
item = parsePeriod(data.ochre.period);
|
|
583
|
+
break;
|
|
584
|
+
}
|
|
585
|
+
case "bibliography": {
|
|
586
|
+
if (!("bibliography" in data.ochre)) {
|
|
587
|
+
throw new Error(
|
|
588
|
+
"Invalid OCHRE data: API response missing 'bibliography' key"
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
item = parseBibliography(data.ochre.bibliography);
|
|
592
|
+
break;
|
|
593
|
+
}
|
|
594
|
+
case "person": {
|
|
595
|
+
if (!("person" in data.ochre)) {
|
|
596
|
+
throw new Error(
|
|
597
|
+
"Invalid OCHRE data: API response missing 'person' key"
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
item = parsePerson(data.ochre.person);
|
|
601
|
+
break;
|
|
602
|
+
}
|
|
603
|
+
case "propertyValue": {
|
|
604
|
+
if (!("propertyValue" in data.ochre)) {
|
|
605
|
+
throw new Error(
|
|
606
|
+
"Invalid OCHRE data: API response missing 'propertyValue' key"
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
item = parsePropertyValue(data.ochre.propertyValue);
|
|
610
|
+
break;
|
|
611
|
+
}
|
|
612
|
+
case "set": {
|
|
613
|
+
if (!("set" in data.ochre)) {
|
|
614
|
+
throw new Error("Invalid OCHRE data: API response missing 'set' key");
|
|
615
|
+
}
|
|
616
|
+
item = parseSet(data.ochre.set);
|
|
617
|
+
break;
|
|
618
|
+
}
|
|
619
|
+
case "tree": {
|
|
620
|
+
if (!("tree" in data.ochre)) {
|
|
621
|
+
throw new Error(
|
|
622
|
+
"Invalid OCHRE data: API response missing 'tree' key"
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
item = parseTree(data.ochre.tree);
|
|
626
|
+
break;
|
|
627
|
+
}
|
|
628
|
+
default: {
|
|
629
|
+
throw new Error("Invalid category");
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
const metadata = parseMetadata(data.ochre.metadata);
|
|
633
|
+
const belongsTo = {
|
|
634
|
+
uuid: data.ochre.uuidBelongsTo,
|
|
635
|
+
abbreviation: parseFakeString(data.ochre.belongsTo)
|
|
636
|
+
};
|
|
637
|
+
return {
|
|
638
|
+
error: null,
|
|
639
|
+
metadata,
|
|
640
|
+
belongsTo,
|
|
641
|
+
item,
|
|
642
|
+
category
|
|
643
|
+
};
|
|
644
|
+
} catch (error) {
|
|
645
|
+
return {
|
|
646
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
647
|
+
metadata: void 0,
|
|
648
|
+
belongsTo: void 0,
|
|
649
|
+
item: void 0,
|
|
650
|
+
category: void 0
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
|
|
519
655
|
// src/utils/parse.ts
|
|
520
656
|
function parseIdentification(identification) {
|
|
521
657
|
try {
|
|
@@ -2408,144 +2544,86 @@ async function parseWebsite(websiteTree, projectName, website) {
|
|
|
2408
2544
|
};
|
|
2409
2545
|
}
|
|
2410
2546
|
|
|
2411
|
-
// src/utils/fetchers/
|
|
2412
|
-
async function
|
|
2547
|
+
// src/utils/fetchers/gallery.ts
|
|
2548
|
+
async function fetchGallery(uuid, filter, page, perPage) {
|
|
2413
2549
|
try {
|
|
2414
|
-
const
|
|
2550
|
+
const {
|
|
2551
|
+
uuid: parsedUuid,
|
|
2552
|
+
filter: parsedFilter,
|
|
2553
|
+
page: parsedPage,
|
|
2554
|
+
perPage: parsedPerPage
|
|
2555
|
+
} = gallerySchema.parse({ uuid, filter, page, perPage });
|
|
2415
2556
|
const response = await fetch(
|
|
2416
|
-
`https://ochre.lib.uchicago.edu/ochre?
|
|
2557
|
+
`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
|
|
2558
|
+
for $q in input()/ochre[@uuid='${parsedUuid}']
|
|
2559
|
+
let $filtered := $q/tree/items/resource[contains(lower-case(identification/label), lower-case('${parsedFilter}'))]
|
|
2560
|
+
let $maxLength := count($filtered)
|
|
2561
|
+
return <gallery maxLength='{$maxLength}'>
|
|
2562
|
+
{$q/metadata/project}
|
|
2563
|
+
{$q/metadata/item}
|
|
2564
|
+
{$filtered[position() >= ${((parsedPage - 1) * parsedPerPage + 1).toString()} and position() < ${(parsedPage * parsedPerPage + 1).toString()}]}
|
|
2565
|
+
</gallery>
|
|
2566
|
+
`)}&format=json`
|
|
2417
2567
|
);
|
|
2418
2568
|
if (!response.ok) {
|
|
2419
|
-
throw new Error("
|
|
2569
|
+
throw new Error("Error fetching gallery items, please try again later.");
|
|
2420
2570
|
}
|
|
2421
|
-
const
|
|
2422
|
-
if (!("
|
|
2423
|
-
throw new Error("
|
|
2571
|
+
const data = await response.json();
|
|
2572
|
+
if (!("gallery" in data.result)) {
|
|
2573
|
+
throw new Error("Failed to fetch gallery");
|
|
2424
2574
|
}
|
|
2425
|
-
|
|
2575
|
+
const galleryIdentification = parseIdentification(
|
|
2576
|
+
data.result.gallery.item.identification
|
|
2577
|
+
);
|
|
2578
|
+
const galleryProjectIdentification = parseIdentification(
|
|
2579
|
+
data.result.gallery.project.identification
|
|
2580
|
+
);
|
|
2581
|
+
const gallery = {
|
|
2582
|
+
identification: galleryIdentification,
|
|
2583
|
+
projectIdentification: galleryProjectIdentification,
|
|
2584
|
+
resources: data.result.gallery.resource ? Array.isArray(data.result.gallery.resource) ? parseResources(data.result.gallery.resource) : [parseResource(data.result.gallery.resource)] : [],
|
|
2585
|
+
maxLength: data.result.gallery.maxLength
|
|
2586
|
+
};
|
|
2587
|
+
return { item: gallery, error: null };
|
|
2426
2588
|
} catch (error) {
|
|
2427
|
-
|
|
2589
|
+
console.error(error);
|
|
2590
|
+
return {
|
|
2591
|
+
item: null,
|
|
2592
|
+
error: error instanceof Error ? error.message : "Failed to fetch gallery"
|
|
2593
|
+
};
|
|
2428
2594
|
}
|
|
2429
2595
|
}
|
|
2430
2596
|
|
|
2431
|
-
// src/utils/fetchers/
|
|
2432
|
-
async function
|
|
2597
|
+
// src/utils/fetchers/website.ts
|
|
2598
|
+
async function fetchWebsite(abbreviation) {
|
|
2433
2599
|
try {
|
|
2434
|
-
const
|
|
2435
|
-
|
|
2436
|
-
|
|
2600
|
+
const response = await fetch(
|
|
2601
|
+
`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`
|
|
2602
|
+
);
|
|
2603
|
+
if (!response.ok) {
|
|
2604
|
+
throw new Error("Failed to fetch website");
|
|
2437
2605
|
}
|
|
2438
|
-
const
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
case "resource": {
|
|
2442
|
-
if (!("resource" in data.ochre)) {
|
|
2443
|
-
throw new Error(
|
|
2444
|
-
"Invalid OCHRE data: API response missing 'resource' key"
|
|
2445
|
-
);
|
|
2446
|
-
}
|
|
2447
|
-
item = parseResource(data.ochre.resource);
|
|
2448
|
-
break;
|
|
2449
|
-
}
|
|
2450
|
-
case "spatialUnit": {
|
|
2451
|
-
if (!("spatialUnit" in data.ochre)) {
|
|
2452
|
-
throw new Error(
|
|
2453
|
-
"Invalid OCHRE data: API response missing 'spatialUnit' key"
|
|
2454
|
-
);
|
|
2455
|
-
}
|
|
2456
|
-
item = parseSpatialUnit(data.ochre.spatialUnit);
|
|
2457
|
-
break;
|
|
2458
|
-
}
|
|
2459
|
-
case "concept": {
|
|
2460
|
-
if (!("concept" in data.ochre)) {
|
|
2461
|
-
throw new Error(
|
|
2462
|
-
"Invalid OCHRE data: API response missing 'concept' key"
|
|
2463
|
-
);
|
|
2464
|
-
}
|
|
2465
|
-
item = parseConcept(data.ochre.concept);
|
|
2466
|
-
break;
|
|
2467
|
-
}
|
|
2468
|
-
case "period": {
|
|
2469
|
-
if (!("period" in data.ochre)) {
|
|
2470
|
-
throw new Error(
|
|
2471
|
-
"Invalid OCHRE data: API response missing 'period' key"
|
|
2472
|
-
);
|
|
2473
|
-
}
|
|
2474
|
-
item = parsePeriod(data.ochre.period);
|
|
2475
|
-
break;
|
|
2476
|
-
}
|
|
2477
|
-
case "bibliography": {
|
|
2478
|
-
if (!("bibliography" in data.ochre)) {
|
|
2479
|
-
throw new Error(
|
|
2480
|
-
"Invalid OCHRE data: API response missing 'bibliography' key"
|
|
2481
|
-
);
|
|
2482
|
-
}
|
|
2483
|
-
item = parseBibliography(data.ochre.bibliography);
|
|
2484
|
-
break;
|
|
2485
|
-
}
|
|
2486
|
-
case "person": {
|
|
2487
|
-
if (!("person" in data.ochre)) {
|
|
2488
|
-
throw new Error(
|
|
2489
|
-
"Invalid OCHRE data: API response missing 'person' key"
|
|
2490
|
-
);
|
|
2491
|
-
}
|
|
2492
|
-
item = parsePerson(data.ochre.person);
|
|
2493
|
-
break;
|
|
2494
|
-
}
|
|
2495
|
-
case "propertyValue": {
|
|
2496
|
-
if (!("propertyValue" in data.ochre)) {
|
|
2497
|
-
throw new Error(
|
|
2498
|
-
"Invalid OCHRE data: API response missing 'propertyValue' key"
|
|
2499
|
-
);
|
|
2500
|
-
}
|
|
2501
|
-
item = parsePropertyValue(data.ochre.propertyValue);
|
|
2502
|
-
break;
|
|
2503
|
-
}
|
|
2504
|
-
case "set": {
|
|
2505
|
-
if (!("set" in data.ochre)) {
|
|
2506
|
-
throw new Error("Invalid OCHRE data: API response missing 'set' key");
|
|
2507
|
-
}
|
|
2508
|
-
item = parseSet(data.ochre.set);
|
|
2509
|
-
break;
|
|
2510
|
-
}
|
|
2511
|
-
case "tree": {
|
|
2512
|
-
if (!("tree" in data.ochre)) {
|
|
2513
|
-
throw new Error(
|
|
2514
|
-
"Invalid OCHRE data: API response missing 'tree' key"
|
|
2515
|
-
);
|
|
2516
|
-
}
|
|
2517
|
-
item = parseTree(data.ochre.tree);
|
|
2518
|
-
break;
|
|
2519
|
-
}
|
|
2520
|
-
default: {
|
|
2521
|
-
throw new Error("Invalid category");
|
|
2522
|
-
}
|
|
2606
|
+
const data = await response.json();
|
|
2607
|
+
if (!("ochre" in data.result) || !("tree" in data.result.ochre)) {
|
|
2608
|
+
throw new Error("Failed to fetch website");
|
|
2523
2609
|
}
|
|
2524
|
-
const
|
|
2525
|
-
const
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
metadata,
|
|
2532
|
-
belongsTo,
|
|
2533
|
-
item,
|
|
2534
|
-
category
|
|
2535
|
-
};
|
|
2610
|
+
const projectIdentification = data.result.ochre.metadata.project?.identification ? parseIdentification(data.result.ochre.metadata.project.identification) : null;
|
|
2611
|
+
const website = await parseWebsite(
|
|
2612
|
+
data.result.ochre.tree,
|
|
2613
|
+
projectIdentification?.label ?? "",
|
|
2614
|
+
data.result.ochre.metadata.project?.identification.website ?? null
|
|
2615
|
+
);
|
|
2616
|
+
return website;
|
|
2536
2617
|
} catch (error) {
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
metadata: void 0,
|
|
2540
|
-
belongsTo: void 0,
|
|
2541
|
-
item: void 0,
|
|
2542
|
-
category: void 0
|
|
2543
|
-
};
|
|
2618
|
+
console.error(error);
|
|
2619
|
+
return null;
|
|
2544
2620
|
}
|
|
2545
2621
|
}
|
|
2546
2622
|
export {
|
|
2547
2623
|
fetchByUuid,
|
|
2624
|
+
fetchGallery,
|
|
2548
2625
|
fetchItem,
|
|
2626
|
+
fetchWebsite,
|
|
2549
2627
|
filterProperties,
|
|
2550
2628
|
getAllPropertyLabels,
|
|
2551
2629
|
getPropertyByLabel,
|
package/package.json
CHANGED