@digitalculture/ochre-sdk 0.6.0 → 0.6.2
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 +203 -145
- package/dist/index.d.cts +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.js +202 -145
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -21,6 +21,7 @@ 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,
|
|
25
26
|
filterProperties: () => filterProperties,
|
|
26
27
|
getAllPropertyLabels: () => getAllPropertyLabels,
|
|
@@ -132,6 +133,12 @@ var categorySchema = import_zod.z.enum([
|
|
|
132
133
|
"set",
|
|
133
134
|
"tree"
|
|
134
135
|
]);
|
|
136
|
+
var gallerySchema = import_zod.z.object({
|
|
137
|
+
uuid: import_zod.z.string().uuid({ message: "Invalid UUID" }),
|
|
138
|
+
filter: import_zod.z.string().optional(),
|
|
139
|
+
page: import_zod.z.number().positive({ message: "Page must be positive" }),
|
|
140
|
+
perPage: import_zod.z.number().positive({ message: "Per page must be positive" })
|
|
141
|
+
}).strict();
|
|
135
142
|
var renderOptionsSchema = import_zod.z.string().transform((str) => str.split(" ")).pipe(
|
|
136
143
|
import_zod.z.array(
|
|
137
144
|
import_zod.z.enum([
|
|
@@ -152,28 +159,6 @@ var whitespaceSchema = import_zod.z.string().transform((str) => str.split(" ")).
|
|
|
152
159
|
);
|
|
153
160
|
var emailSchema = import_zod.z.string().email({ message: "Invalid email" });
|
|
154
161
|
|
|
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
162
|
// src/utils/getters.ts
|
|
178
163
|
var DEFAULT_OPTIONS = {
|
|
179
164
|
searchNestedProperties: false
|
|
@@ -582,6 +567,164 @@ ${JSON.stringify(
|
|
|
582
567
|
}
|
|
583
568
|
}
|
|
584
569
|
|
|
570
|
+
// src/utils/helpers.ts
|
|
571
|
+
function getItemCategory(keys) {
|
|
572
|
+
const categoryFound = keys.find(
|
|
573
|
+
(key) => categorySchema.safeParse(key).success
|
|
574
|
+
);
|
|
575
|
+
if (!categoryFound) {
|
|
576
|
+
const unknownKey = keys.find(
|
|
577
|
+
(key) => ![
|
|
578
|
+
"uuid",
|
|
579
|
+
"uuidBelongsTo",
|
|
580
|
+
"belongsTo",
|
|
581
|
+
"publicationDateTime",
|
|
582
|
+
"metadata",
|
|
583
|
+
"languages"
|
|
584
|
+
].includes(key)
|
|
585
|
+
);
|
|
586
|
+
throw new Error(`Invalid OCHRE data; found unexpected "${unknownKey}" key`);
|
|
587
|
+
}
|
|
588
|
+
const categoryKey = categorySchema.parse(categoryFound);
|
|
589
|
+
return categoryKey;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// src/utils/fetchers/uuid.ts
|
|
593
|
+
async function fetchByUuid(uuid) {
|
|
594
|
+
try {
|
|
595
|
+
const parsedUuid = uuidSchema.parse(uuid);
|
|
596
|
+
const response = await fetch(
|
|
597
|
+
`https://ochre.lib.uchicago.edu/ochre?uuid=${parsedUuid}&format=json&lang="*"`
|
|
598
|
+
);
|
|
599
|
+
if (!response.ok) {
|
|
600
|
+
throw new Error("Failed to fetch OCHRE data");
|
|
601
|
+
}
|
|
602
|
+
const dataRaw = await response.json();
|
|
603
|
+
if (!("ochre" in dataRaw)) {
|
|
604
|
+
throw new Error("Invalid OCHRE data: API response missing 'ochre' key");
|
|
605
|
+
}
|
|
606
|
+
return [null, dataRaw];
|
|
607
|
+
} catch (error) {
|
|
608
|
+
return [error instanceof Error ? error.message : "Unknown error", null];
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// src/utils/fetchers/item.ts
|
|
613
|
+
async function fetchItem(uuid, category) {
|
|
614
|
+
try {
|
|
615
|
+
const [error, data] = await fetchByUuid(uuid);
|
|
616
|
+
if (error !== null) {
|
|
617
|
+
throw new Error(error);
|
|
618
|
+
}
|
|
619
|
+
const categoryKey = getItemCategory(Object.keys(data.ochre));
|
|
620
|
+
let item;
|
|
621
|
+
switch (categoryKey) {
|
|
622
|
+
case "resource": {
|
|
623
|
+
if (!("resource" in data.ochre)) {
|
|
624
|
+
throw new Error(
|
|
625
|
+
"Invalid OCHRE data: API response missing 'resource' key"
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
item = parseResource(data.ochre.resource);
|
|
629
|
+
break;
|
|
630
|
+
}
|
|
631
|
+
case "spatialUnit": {
|
|
632
|
+
if (!("spatialUnit" in data.ochre)) {
|
|
633
|
+
throw new Error(
|
|
634
|
+
"Invalid OCHRE data: API response missing 'spatialUnit' key"
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
item = parseSpatialUnit(data.ochre.spatialUnit);
|
|
638
|
+
break;
|
|
639
|
+
}
|
|
640
|
+
case "concept": {
|
|
641
|
+
if (!("concept" in data.ochre)) {
|
|
642
|
+
throw new Error(
|
|
643
|
+
"Invalid OCHRE data: API response missing 'concept' key"
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
item = parseConcept(data.ochre.concept);
|
|
647
|
+
break;
|
|
648
|
+
}
|
|
649
|
+
case "period": {
|
|
650
|
+
if (!("period" in data.ochre)) {
|
|
651
|
+
throw new Error(
|
|
652
|
+
"Invalid OCHRE data: API response missing 'period' key"
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
item = parsePeriod(data.ochre.period);
|
|
656
|
+
break;
|
|
657
|
+
}
|
|
658
|
+
case "bibliography": {
|
|
659
|
+
if (!("bibliography" in data.ochre)) {
|
|
660
|
+
throw new Error(
|
|
661
|
+
"Invalid OCHRE data: API response missing 'bibliography' key"
|
|
662
|
+
);
|
|
663
|
+
}
|
|
664
|
+
item = parseBibliography(data.ochre.bibliography);
|
|
665
|
+
break;
|
|
666
|
+
}
|
|
667
|
+
case "person": {
|
|
668
|
+
if (!("person" in data.ochre)) {
|
|
669
|
+
throw new Error(
|
|
670
|
+
"Invalid OCHRE data: API response missing 'person' key"
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
item = parsePerson(data.ochre.person);
|
|
674
|
+
break;
|
|
675
|
+
}
|
|
676
|
+
case "propertyValue": {
|
|
677
|
+
if (!("propertyValue" in data.ochre)) {
|
|
678
|
+
throw new Error(
|
|
679
|
+
"Invalid OCHRE data: API response missing 'propertyValue' key"
|
|
680
|
+
);
|
|
681
|
+
}
|
|
682
|
+
item = parsePropertyValue(data.ochre.propertyValue);
|
|
683
|
+
break;
|
|
684
|
+
}
|
|
685
|
+
case "set": {
|
|
686
|
+
if (!("set" in data.ochre)) {
|
|
687
|
+
throw new Error("Invalid OCHRE data: API response missing 'set' key");
|
|
688
|
+
}
|
|
689
|
+
item = parseSet(data.ochre.set);
|
|
690
|
+
break;
|
|
691
|
+
}
|
|
692
|
+
case "tree": {
|
|
693
|
+
if (!("tree" in data.ochre)) {
|
|
694
|
+
throw new Error(
|
|
695
|
+
"Invalid OCHRE data: API response missing 'tree' key"
|
|
696
|
+
);
|
|
697
|
+
}
|
|
698
|
+
item = parseTree(data.ochre.tree);
|
|
699
|
+
break;
|
|
700
|
+
}
|
|
701
|
+
default: {
|
|
702
|
+
throw new Error("Invalid category");
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
const metadata = parseMetadata(data.ochre.metadata);
|
|
706
|
+
const belongsTo = {
|
|
707
|
+
uuid: data.ochre.uuidBelongsTo,
|
|
708
|
+
abbreviation: parseFakeString(data.ochre.belongsTo)
|
|
709
|
+
};
|
|
710
|
+
return {
|
|
711
|
+
error: null,
|
|
712
|
+
metadata,
|
|
713
|
+
belongsTo,
|
|
714
|
+
item,
|
|
715
|
+
category
|
|
716
|
+
};
|
|
717
|
+
} catch (error) {
|
|
718
|
+
return {
|
|
719
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
720
|
+
metadata: void 0,
|
|
721
|
+
belongsTo: void 0,
|
|
722
|
+
item: void 0,
|
|
723
|
+
category: void 0
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
|
|
585
728
|
// src/utils/parse.ts
|
|
586
729
|
function parseIdentification(identification) {
|
|
587
730
|
try {
|
|
@@ -2474,144 +2617,59 @@ async function parseWebsite(websiteTree, projectName, website) {
|
|
|
2474
2617
|
};
|
|
2475
2618
|
}
|
|
2476
2619
|
|
|
2477
|
-
// src/utils/fetchers/
|
|
2478
|
-
async function
|
|
2620
|
+
// src/utils/fetchers/gallery.ts
|
|
2621
|
+
async function fetchGallery(uuid, filter, page, perPage) {
|
|
2479
2622
|
try {
|
|
2480
|
-
const
|
|
2623
|
+
const {
|
|
2624
|
+
uuid: parsedUuid,
|
|
2625
|
+
filter: parsedFilter,
|
|
2626
|
+
page: parsedPage,
|
|
2627
|
+
perPage: parsedPerPage
|
|
2628
|
+
} = gallerySchema.parse({ uuid, filter, page, perPage });
|
|
2481
2629
|
const response = await fetch(
|
|
2482
|
-
`https://ochre.lib.uchicago.edu/ochre?
|
|
2630
|
+
`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
|
|
2631
|
+
for $q in input()/ochre[@uuid='${parsedUuid}']
|
|
2632
|
+
let $filtered := $q/tree/items/resource[contains(lower-case(identification/label), lower-case('${parsedFilter}'))]
|
|
2633
|
+
let $maxLength := count($filtered)
|
|
2634
|
+
return <gallery maxLength='{$maxLength}'>
|
|
2635
|
+
{$q/metadata/project}
|
|
2636
|
+
{$q/metadata/item}
|
|
2637
|
+
{$filtered[position() >= ${((parsedPage - 1) * parsedPerPage + 1).toString()} and position() < ${(parsedPage * parsedPerPage + 1).toString()}]}
|
|
2638
|
+
</gallery>
|
|
2639
|
+
`)}&format=json`
|
|
2483
2640
|
);
|
|
2484
2641
|
if (!response.ok) {
|
|
2485
|
-
throw new Error("
|
|
2642
|
+
throw new Error("Error fetching gallery items, please try again later.");
|
|
2486
2643
|
}
|
|
2487
|
-
const
|
|
2488
|
-
if (!("
|
|
2489
|
-
throw new Error("
|
|
2644
|
+
const data = await response.json();
|
|
2645
|
+
if (!("gallery" in data.result)) {
|
|
2646
|
+
throw new Error("Failed to fetch gallery");
|
|
2490
2647
|
}
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
throw new Error(error);
|
|
2503
|
-
}
|
|
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
|
-
}
|
|
2589
|
-
}
|
|
2590
|
-
const metadata = parseMetadata(data.ochre.metadata);
|
|
2591
|
-
const belongsTo = {
|
|
2592
|
-
uuid: data.ochre.uuidBelongsTo,
|
|
2593
|
-
abbreviation: parseFakeString(data.ochre.belongsTo)
|
|
2594
|
-
};
|
|
2595
|
-
return {
|
|
2596
|
-
error: null,
|
|
2597
|
-
metadata,
|
|
2598
|
-
belongsTo,
|
|
2599
|
-
item,
|
|
2600
|
-
category
|
|
2648
|
+
const galleryIdentification = parseIdentification(
|
|
2649
|
+
data.result.gallery.item.identification
|
|
2650
|
+
);
|
|
2651
|
+
const galleryProjectIdentification = parseIdentification(
|
|
2652
|
+
data.result.gallery.project.identification
|
|
2653
|
+
);
|
|
2654
|
+
const gallery = {
|
|
2655
|
+
identification: galleryIdentification,
|
|
2656
|
+
projectIdentification: galleryProjectIdentification,
|
|
2657
|
+
resources: data.result.gallery.resource ? Array.isArray(data.result.gallery.resource) ? parseResources(data.result.gallery.resource) : [parseResource(data.result.gallery.resource)] : [],
|
|
2658
|
+
maxLength: data.result.gallery.maxLength
|
|
2601
2659
|
};
|
|
2660
|
+
return { item: gallery, error: null };
|
|
2602
2661
|
} catch (error) {
|
|
2662
|
+
console.error(error);
|
|
2603
2663
|
return {
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
belongsTo: void 0,
|
|
2607
|
-
item: void 0,
|
|
2608
|
-
category: void 0
|
|
2664
|
+
item: null,
|
|
2665
|
+
error: error instanceof Error ? error.message : "Failed to fetch gallery"
|
|
2609
2666
|
};
|
|
2610
2667
|
}
|
|
2611
2668
|
}
|
|
2612
2669
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2613
2670
|
0 && (module.exports = {
|
|
2614
2671
|
fetchByUuid,
|
|
2672
|
+
fetchGallery,
|
|
2615
2673
|
fetchItem,
|
|
2616
2674
|
filterProperties,
|
|
2617
2675
|
getAllPropertyLabels,
|
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
|
*
|
|
@@ -1644,4 +1678,4 @@ declare function parseStringDocumentItem(item: OchreStringRichTextItem, footnote
|
|
|
1644
1678
|
*/
|
|
1645
1679
|
declare function parseStringContent(content: OchreStringContent, language?: string): string;
|
|
1646
1680
|
|
|
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 };
|
|
1681
|
+
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, 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
|
*
|
|
@@ -1644,4 +1678,4 @@ declare function parseStringDocumentItem(item: OchreStringRichTextItem, footnote
|
|
|
1644
1678
|
*/
|
|
1645
1679
|
declare function parseStringContent(content: OchreStringContent, language?: string): string;
|
|
1646
1680
|
|
|
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 };
|
|
1681
|
+
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, 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
|
@@ -60,6 +60,12 @@ var categorySchema = z.enum([
|
|
|
60
60
|
"set",
|
|
61
61
|
"tree"
|
|
62
62
|
]);
|
|
63
|
+
var gallerySchema = z.object({
|
|
64
|
+
uuid: z.string().uuid({ message: "Invalid UUID" }),
|
|
65
|
+
filter: z.string().optional(),
|
|
66
|
+
page: z.number().positive({ message: "Page must be positive" }),
|
|
67
|
+
perPage: z.number().positive({ message: "Per page must be positive" })
|
|
68
|
+
}).strict();
|
|
63
69
|
var renderOptionsSchema = z.string().transform((str) => str.split(" ")).pipe(
|
|
64
70
|
z.array(
|
|
65
71
|
z.enum([
|
|
@@ -80,28 +86,6 @@ var whitespaceSchema = z.string().transform((str) => str.split(" ")).pipe(
|
|
|
80
86
|
);
|
|
81
87
|
var emailSchema = z.string().email({ message: "Invalid email" });
|
|
82
88
|
|
|
83
|
-
// src/utils/helpers.ts
|
|
84
|
-
function getItemCategory(keys) {
|
|
85
|
-
const categoryFound = keys.find(
|
|
86
|
-
(key) => categorySchema.safeParse(key).success
|
|
87
|
-
);
|
|
88
|
-
if (!categoryFound) {
|
|
89
|
-
const unknownKey = keys.find(
|
|
90
|
-
(key) => ![
|
|
91
|
-
"uuid",
|
|
92
|
-
"uuidBelongsTo",
|
|
93
|
-
"belongsTo",
|
|
94
|
-
"publicationDateTime",
|
|
95
|
-
"metadata",
|
|
96
|
-
"languages"
|
|
97
|
-
].includes(key)
|
|
98
|
-
);
|
|
99
|
-
throw new Error(`Invalid OCHRE data; found unexpected "${unknownKey}" key`);
|
|
100
|
-
}
|
|
101
|
-
const categoryKey = categorySchema.parse(categoryFound);
|
|
102
|
-
return categoryKey;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
89
|
// src/utils/getters.ts
|
|
106
90
|
var DEFAULT_OPTIONS = {
|
|
107
91
|
searchNestedProperties: false
|
|
@@ -510,6 +494,164 @@ ${JSON.stringify(
|
|
|
510
494
|
}
|
|
511
495
|
}
|
|
512
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
|
+
|
|
513
655
|
// src/utils/parse.ts
|
|
514
656
|
function parseIdentification(identification) {
|
|
515
657
|
try {
|
|
@@ -2402,143 +2544,58 @@ async function parseWebsite(websiteTree, projectName, website) {
|
|
|
2402
2544
|
};
|
|
2403
2545
|
}
|
|
2404
2546
|
|
|
2405
|
-
// src/utils/fetchers/
|
|
2406
|
-
async function
|
|
2547
|
+
// src/utils/fetchers/gallery.ts
|
|
2548
|
+
async function fetchGallery(uuid, filter, page, perPage) {
|
|
2407
2549
|
try {
|
|
2408
|
-
const
|
|
2550
|
+
const {
|
|
2551
|
+
uuid: parsedUuid,
|
|
2552
|
+
filter: parsedFilter,
|
|
2553
|
+
page: parsedPage,
|
|
2554
|
+
perPage: parsedPerPage
|
|
2555
|
+
} = gallerySchema.parse({ uuid, filter, page, perPage });
|
|
2409
2556
|
const response = await fetch(
|
|
2410
|
-
`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`
|
|
2411
2567
|
);
|
|
2412
2568
|
if (!response.ok) {
|
|
2413
|
-
throw new Error("
|
|
2569
|
+
throw new Error("Error fetching gallery items, please try again later.");
|
|
2414
2570
|
}
|
|
2415
|
-
const
|
|
2416
|
-
if (!("
|
|
2417
|
-
throw new Error("
|
|
2571
|
+
const data = await response.json();
|
|
2572
|
+
if (!("gallery" in data.result)) {
|
|
2573
|
+
throw new Error("Failed to fetch gallery");
|
|
2418
2574
|
}
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
throw new Error(error);
|
|
2431
|
-
}
|
|
2432
|
-
const categoryKey = getItemCategory(Object.keys(data.ochre));
|
|
2433
|
-
let item;
|
|
2434
|
-
switch (categoryKey) {
|
|
2435
|
-
case "resource": {
|
|
2436
|
-
if (!("resource" in data.ochre)) {
|
|
2437
|
-
throw new Error(
|
|
2438
|
-
"Invalid OCHRE data: API response missing 'resource' key"
|
|
2439
|
-
);
|
|
2440
|
-
}
|
|
2441
|
-
item = parseResource(data.ochre.resource);
|
|
2442
|
-
break;
|
|
2443
|
-
}
|
|
2444
|
-
case "spatialUnit": {
|
|
2445
|
-
if (!("spatialUnit" in data.ochre)) {
|
|
2446
|
-
throw new Error(
|
|
2447
|
-
"Invalid OCHRE data: API response missing 'spatialUnit' key"
|
|
2448
|
-
);
|
|
2449
|
-
}
|
|
2450
|
-
item = parseSpatialUnit(data.ochre.spatialUnit);
|
|
2451
|
-
break;
|
|
2452
|
-
}
|
|
2453
|
-
case "concept": {
|
|
2454
|
-
if (!("concept" in data.ochre)) {
|
|
2455
|
-
throw new Error(
|
|
2456
|
-
"Invalid OCHRE data: API response missing 'concept' key"
|
|
2457
|
-
);
|
|
2458
|
-
}
|
|
2459
|
-
item = parseConcept(data.ochre.concept);
|
|
2460
|
-
break;
|
|
2461
|
-
}
|
|
2462
|
-
case "period": {
|
|
2463
|
-
if (!("period" in data.ochre)) {
|
|
2464
|
-
throw new Error(
|
|
2465
|
-
"Invalid OCHRE data: API response missing 'period' key"
|
|
2466
|
-
);
|
|
2467
|
-
}
|
|
2468
|
-
item = parsePeriod(data.ochre.period);
|
|
2469
|
-
break;
|
|
2470
|
-
}
|
|
2471
|
-
case "bibliography": {
|
|
2472
|
-
if (!("bibliography" in data.ochre)) {
|
|
2473
|
-
throw new Error(
|
|
2474
|
-
"Invalid OCHRE data: API response missing 'bibliography' key"
|
|
2475
|
-
);
|
|
2476
|
-
}
|
|
2477
|
-
item = parseBibliography(data.ochre.bibliography);
|
|
2478
|
-
break;
|
|
2479
|
-
}
|
|
2480
|
-
case "person": {
|
|
2481
|
-
if (!("person" in data.ochre)) {
|
|
2482
|
-
throw new Error(
|
|
2483
|
-
"Invalid OCHRE data: API response missing 'person' key"
|
|
2484
|
-
);
|
|
2485
|
-
}
|
|
2486
|
-
item = parsePerson(data.ochre.person);
|
|
2487
|
-
break;
|
|
2488
|
-
}
|
|
2489
|
-
case "propertyValue": {
|
|
2490
|
-
if (!("propertyValue" in data.ochre)) {
|
|
2491
|
-
throw new Error(
|
|
2492
|
-
"Invalid OCHRE data: API response missing 'propertyValue' key"
|
|
2493
|
-
);
|
|
2494
|
-
}
|
|
2495
|
-
item = parsePropertyValue(data.ochre.propertyValue);
|
|
2496
|
-
break;
|
|
2497
|
-
}
|
|
2498
|
-
case "set": {
|
|
2499
|
-
if (!("set" in data.ochre)) {
|
|
2500
|
-
throw new Error("Invalid OCHRE data: API response missing 'set' key");
|
|
2501
|
-
}
|
|
2502
|
-
item = parseSet(data.ochre.set);
|
|
2503
|
-
break;
|
|
2504
|
-
}
|
|
2505
|
-
case "tree": {
|
|
2506
|
-
if (!("tree" in data.ochre)) {
|
|
2507
|
-
throw new Error(
|
|
2508
|
-
"Invalid OCHRE data: API response missing 'tree' key"
|
|
2509
|
-
);
|
|
2510
|
-
}
|
|
2511
|
-
item = parseTree(data.ochre.tree);
|
|
2512
|
-
break;
|
|
2513
|
-
}
|
|
2514
|
-
default: {
|
|
2515
|
-
throw new Error("Invalid category");
|
|
2516
|
-
}
|
|
2517
|
-
}
|
|
2518
|
-
const metadata = parseMetadata(data.ochre.metadata);
|
|
2519
|
-
const belongsTo = {
|
|
2520
|
-
uuid: data.ochre.uuidBelongsTo,
|
|
2521
|
-
abbreviation: parseFakeString(data.ochre.belongsTo)
|
|
2522
|
-
};
|
|
2523
|
-
return {
|
|
2524
|
-
error: null,
|
|
2525
|
-
metadata,
|
|
2526
|
-
belongsTo,
|
|
2527
|
-
item,
|
|
2528
|
-
category
|
|
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
|
|
2529
2586
|
};
|
|
2587
|
+
return { item: gallery, error: null };
|
|
2530
2588
|
} catch (error) {
|
|
2589
|
+
console.error(error);
|
|
2531
2590
|
return {
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
belongsTo: void 0,
|
|
2535
|
-
item: void 0,
|
|
2536
|
-
category: void 0
|
|
2591
|
+
item: null,
|
|
2592
|
+
error: error instanceof Error ? error.message : "Failed to fetch gallery"
|
|
2537
2593
|
};
|
|
2538
2594
|
}
|
|
2539
2595
|
}
|
|
2540
2596
|
export {
|
|
2541
2597
|
fetchByUuid,
|
|
2598
|
+
fetchGallery,
|
|
2542
2599
|
fetchItem,
|
|
2543
2600
|
filterProperties,
|
|
2544
2601
|
getAllPropertyLabels,
|
package/package.json
CHANGED