@digitalculture/ochre-sdk 0.2.4 → 0.2.6
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 +86 -26
- package/dist/index.d.cts +31 -6
- package/dist/index.d.ts +31 -6
- package/dist/index.js +85 -26
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -59,6 +59,7 @@ __export(index_exports, {
|
|
|
59
59
|
parseObservations: () => parseObservations,
|
|
60
60
|
parsePeriod: () => parsePeriod,
|
|
61
61
|
parsePeriods: () => parsePeriods,
|
|
62
|
+
parsePerson: () => parsePerson,
|
|
62
63
|
parsePersons: () => parsePersons,
|
|
63
64
|
parseProperties: () => parseProperties,
|
|
64
65
|
parseResource: () => parseResource,
|
|
@@ -716,17 +717,20 @@ function parseLicense(license) {
|
|
|
716
717
|
url: license.license.target
|
|
717
718
|
};
|
|
718
719
|
}
|
|
720
|
+
function parsePerson(person) {
|
|
721
|
+
return {
|
|
722
|
+
uuid: person.uuid,
|
|
723
|
+
publicationDateTime: person.publicationDateTime != null ? new Date(person.publicationDateTime) : null,
|
|
724
|
+
type: person.type ?? null,
|
|
725
|
+
date: person.date != null ? new Date(person.date) : null,
|
|
726
|
+
identification: person.identification ? parseIdentification(person.identification) : null,
|
|
727
|
+
content: person.content != null ? parseFakeString(person.content) : null
|
|
728
|
+
};
|
|
729
|
+
}
|
|
719
730
|
function parsePersons(persons) {
|
|
720
731
|
const returnPersons = [];
|
|
721
732
|
for (const person of persons) {
|
|
722
|
-
returnPersons.push(
|
|
723
|
-
uuid: person.uuid,
|
|
724
|
-
publicationDateTime: person.publicationDateTime != null ? new Date(person.publicationDateTime) : null,
|
|
725
|
-
type: person.type ?? null,
|
|
726
|
-
date: person.date != null ? new Date(person.date) : null,
|
|
727
|
-
identification: person.identification ? parseIdentification(person.identification) : null,
|
|
728
|
-
content: person.content != null ? parseFakeString(person.content) : null
|
|
729
|
-
});
|
|
733
|
+
returnPersons.push(parsePerson(person));
|
|
730
734
|
}
|
|
731
735
|
return returnPersons;
|
|
732
736
|
}
|
|
@@ -795,7 +799,11 @@ function parseImage(image) {
|
|
|
795
799
|
identification: image.identification ? parseIdentification(image.identification) : null,
|
|
796
800
|
url: image.href ?? (image.htmlImgSrcPrefix == null && image.content != null ? parseFakeString(image.content) : null),
|
|
797
801
|
htmlPrefix: image.htmlImgSrcPrefix ?? null,
|
|
798
|
-
content: image.htmlImgSrcPrefix != null && image.content != null ? parseFakeString(image.content) : null
|
|
802
|
+
content: image.htmlImgSrcPrefix != null && image.content != null ? parseFakeString(image.content) : null,
|
|
803
|
+
widthPreview: image.widthPreview ?? null,
|
|
804
|
+
heightPreview: image.heightPreview ?? null,
|
|
805
|
+
width: image.width ?? null,
|
|
806
|
+
height: image.height ?? null
|
|
799
807
|
};
|
|
800
808
|
}
|
|
801
809
|
function parseNotes(notes, language = "eng") {
|
|
@@ -889,13 +897,21 @@ function parseProperties(properties, language = "eng") {
|
|
|
889
897
|
const returnProperties = [];
|
|
890
898
|
for (const property of properties) {
|
|
891
899
|
const valuesToParse = "value" in property && property.value ? Array.isArray(property.value) ? property.value : [property.value] : [];
|
|
892
|
-
const values = valuesToParse.map(
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
900
|
+
const values = valuesToParse.map(
|
|
901
|
+
(value) => !["string", "number", "boolean"].includes(typeof value) && typeof value === "object" && "uuid" in value ? {
|
|
902
|
+
content: parseStringContent(value),
|
|
903
|
+
type: value.type,
|
|
904
|
+
category: value.category !== "value" ? value.category ?? null : null,
|
|
905
|
+
uuid: value.uuid ?? null,
|
|
906
|
+
publicationDateTime: value.publicationDateTime != null ? new Date(value.publicationDateTime) : null
|
|
907
|
+
} : {
|
|
908
|
+
content: parseFakeString(value),
|
|
909
|
+
type: "string",
|
|
910
|
+
category: "value",
|
|
911
|
+
uuid: null,
|
|
912
|
+
publicationDateTime: null
|
|
913
|
+
}
|
|
914
|
+
);
|
|
899
915
|
returnProperties.push({
|
|
900
916
|
label: parseStringContent(property.label, language).replace(/\s*\.{3}$/, "").trim(),
|
|
901
917
|
values,
|
|
@@ -1041,6 +1057,7 @@ function parseTree(tree) {
|
|
|
1041
1057
|
let concepts = [];
|
|
1042
1058
|
let periods = [];
|
|
1043
1059
|
let bibliographies = [];
|
|
1060
|
+
let persons = [];
|
|
1044
1061
|
if (typeof tree.items !== "string" && "resource" in tree.items) {
|
|
1045
1062
|
resources = parseResources(
|
|
1046
1063
|
Array.isArray(tree.items.resource) ? tree.items.resource : [tree.items.resource]
|
|
@@ -1066,6 +1083,11 @@ function parseTree(tree) {
|
|
|
1066
1083
|
Array.isArray(tree.items.bibliography) ? tree.items.bibliography : [tree.items.bibliography]
|
|
1067
1084
|
);
|
|
1068
1085
|
}
|
|
1086
|
+
if (typeof tree.items !== "string" && "person" in tree.items) {
|
|
1087
|
+
persons = parsePersons(
|
|
1088
|
+
Array.isArray(tree.items.person) ? tree.items.person : [tree.items.person]
|
|
1089
|
+
);
|
|
1090
|
+
}
|
|
1069
1091
|
const returnTree = {
|
|
1070
1092
|
uuid: tree.uuid,
|
|
1071
1093
|
category: "tree",
|
|
@@ -1081,7 +1103,8 @@ function parseTree(tree) {
|
|
|
1081
1103
|
spatialUnits,
|
|
1082
1104
|
concepts,
|
|
1083
1105
|
periods,
|
|
1084
|
-
bibliographies
|
|
1106
|
+
bibliographies,
|
|
1107
|
+
persons
|
|
1085
1108
|
},
|
|
1086
1109
|
properties: tree.properties ? parseProperties(
|
|
1087
1110
|
Array.isArray(tree.properties.property) ? tree.properties.property : [tree.properties.property]
|
|
@@ -1095,6 +1118,7 @@ function parseSet(set) {
|
|
|
1095
1118
|
let concepts = [];
|
|
1096
1119
|
let periods = [];
|
|
1097
1120
|
let bibliographies = [];
|
|
1121
|
+
let persons = [];
|
|
1098
1122
|
if (typeof set.items !== "string" && "resource" in set.items) {
|
|
1099
1123
|
resources = parseResources(
|
|
1100
1124
|
Array.isArray(set.items.resource) ? set.items.resource : [set.items.resource],
|
|
@@ -1123,6 +1147,11 @@ function parseSet(set) {
|
|
|
1123
1147
|
Array.isArray(set.items.bibliography) ? set.items.bibliography : [set.items.bibliography]
|
|
1124
1148
|
);
|
|
1125
1149
|
}
|
|
1150
|
+
if (typeof set.items !== "string" && "person" in set.items) {
|
|
1151
|
+
persons = parsePersons(
|
|
1152
|
+
Array.isArray(set.items.person) ? set.items.person : [set.items.person]
|
|
1153
|
+
);
|
|
1154
|
+
}
|
|
1126
1155
|
return {
|
|
1127
1156
|
uuid: set.uuid,
|
|
1128
1157
|
category: "set",
|
|
@@ -1142,7 +1171,8 @@ function parseSet(set) {
|
|
|
1142
1171
|
spatialUnits,
|
|
1143
1172
|
concepts,
|
|
1144
1173
|
periods,
|
|
1145
|
-
bibliographies
|
|
1174
|
+
bibliographies,
|
|
1175
|
+
persons
|
|
1146
1176
|
}
|
|
1147
1177
|
};
|
|
1148
1178
|
}
|
|
@@ -1474,6 +1504,15 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1474
1504
|
`Image link not found for the following component: \u201C${componentName}\u201D`
|
|
1475
1505
|
);
|
|
1476
1506
|
}
|
|
1507
|
+
const images = [];
|
|
1508
|
+
for (const imageLink of imageLinks) {
|
|
1509
|
+
images.push({
|
|
1510
|
+
url: `https://ochre.lib.uchicago.edu/ochre?uuid=${imageLink.uuid}&load`,
|
|
1511
|
+
label: imageLink.identification?.label ?? null,
|
|
1512
|
+
width: imageLink.image?.width ?? 0,
|
|
1513
|
+
height: imageLink.image?.height ?? 0
|
|
1514
|
+
});
|
|
1515
|
+
}
|
|
1477
1516
|
let captionLayout = getPropertyValueByLabel(
|
|
1478
1517
|
componentProperty.properties,
|
|
1479
1518
|
"caption-layout"
|
|
@@ -1502,20 +1541,40 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1502
1541
|
if (altTextSource === null) {
|
|
1503
1542
|
altTextSource = "name";
|
|
1504
1543
|
}
|
|
1505
|
-
const
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1544
|
+
const carousel = images.length > 1 ? {
|
|
1545
|
+
secondsPerImage: 5,
|
|
1546
|
+
isFullWidth: false,
|
|
1547
|
+
isFullHeight: false
|
|
1548
|
+
} : null;
|
|
1549
|
+
if (carousel !== null) {
|
|
1550
|
+
const carouselSecondsPerImage = getPropertyValueByLabel(
|
|
1551
|
+
componentProperty.properties,
|
|
1552
|
+
"carousel-seconds-per-image"
|
|
1553
|
+
);
|
|
1554
|
+
if (carouselSecondsPerImage !== null) {
|
|
1555
|
+
carousel.secondsPerImage = Number.parseFloat(carouselSecondsPerImage);
|
|
1556
|
+
}
|
|
1557
|
+
const carouselIsFullWidth = getPropertyValueByLabel(
|
|
1558
|
+
componentProperty.properties,
|
|
1559
|
+
"carousel-full-width"
|
|
1560
|
+
);
|
|
1561
|
+
if (carouselIsFullWidth !== null) {
|
|
1562
|
+
carousel.isFullWidth = carouselIsFullWidth === "Yes";
|
|
1563
|
+
}
|
|
1564
|
+
const carouselIsFullHeight = getPropertyValueByLabel(
|
|
1565
|
+
componentProperty.properties,
|
|
1566
|
+
"carousel-full-height"
|
|
1567
|
+
);
|
|
1568
|
+
if (carouselIsFullHeight !== null) {
|
|
1569
|
+
carousel.isFullHeight = carouselIsFullHeight === "Yes";
|
|
1570
|
+
}
|
|
1513
1571
|
}
|
|
1514
1572
|
properties.images = images;
|
|
1515
1573
|
properties.imageQuality = imageQuality;
|
|
1516
1574
|
properties.captionLayout = captionLayout;
|
|
1517
1575
|
properties.captionSource = captionSource;
|
|
1518
1576
|
properties.altTextSource = altTextSource;
|
|
1577
|
+
properties.carousel = carousel;
|
|
1519
1578
|
break;
|
|
1520
1579
|
}
|
|
1521
1580
|
case "image-gallery": {
|
|
@@ -2299,6 +2358,7 @@ async function fetchWebsite(abbreviation) {
|
|
|
2299
2358
|
parseObservations,
|
|
2300
2359
|
parsePeriod,
|
|
2301
2360
|
parsePeriods,
|
|
2361
|
+
parsePerson,
|
|
2302
2362
|
parsePersons,
|
|
2303
2363
|
parseProperties,
|
|
2304
2364
|
parseResource,
|
package/dist/index.d.cts
CHANGED
|
@@ -11,7 +11,7 @@ type Data = {
|
|
|
11
11
|
};
|
|
12
12
|
publicationDateTime: Date;
|
|
13
13
|
metadata: Metadata;
|
|
14
|
-
item: Tree | Set | Resource | SpatialUnit | Concept;
|
|
14
|
+
item: Tree | Set | Resource | SpatialUnit | Concept | Period | Bibliography | Person;
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
17
|
* Basic identification information used across multiple types
|
|
@@ -100,6 +100,10 @@ type Image = {
|
|
|
100
100
|
url: string | null;
|
|
101
101
|
htmlPrefix: string | null;
|
|
102
102
|
content: string | null;
|
|
103
|
+
widthPreview: number | null;
|
|
104
|
+
heightPreview: number | null;
|
|
105
|
+
width: number | null;
|
|
106
|
+
height: number | null;
|
|
103
107
|
};
|
|
104
108
|
/**
|
|
105
109
|
* Represents a link to another item with optional image and bibliographic references
|
|
@@ -288,6 +292,7 @@ type Set = {
|
|
|
288
292
|
concepts: Array<NestedConcept>;
|
|
289
293
|
periods: Array<Period>;
|
|
290
294
|
bibliographies: Array<Bibliography>;
|
|
295
|
+
persons: Array<Person>;
|
|
291
296
|
};
|
|
292
297
|
};
|
|
293
298
|
/**
|
|
@@ -377,6 +382,7 @@ type Tree = {
|
|
|
377
382
|
concepts: Array<Concept>;
|
|
378
383
|
periods: Array<Period>;
|
|
379
384
|
bibliographies: Array<Bibliography>;
|
|
385
|
+
persons: Array<Person>;
|
|
380
386
|
};
|
|
381
387
|
properties: Array<Property>;
|
|
382
388
|
};
|
|
@@ -493,6 +499,11 @@ type WebElementComponent = {
|
|
|
493
499
|
captionSource: "name" | "abbreviation" | "description";
|
|
494
500
|
captionLayout: "top" | "bottom" | "suppress";
|
|
495
501
|
altTextSource: "name" | "abbreviation" | "description";
|
|
502
|
+
carousel: {
|
|
503
|
+
secondsPerImage: number;
|
|
504
|
+
isFullWidth: boolean;
|
|
505
|
+
isFullHeight: boolean;
|
|
506
|
+
} | null;
|
|
496
507
|
} | {
|
|
497
508
|
component: "image-gallery";
|
|
498
509
|
galleryId: string;
|
|
@@ -733,6 +744,7 @@ type OchreData = {
|
|
|
733
744
|
| { concept: OchreConcept }
|
|
734
745
|
| { period: OchrePeriod }
|
|
735
746
|
| { bibliography: OchreBibliography }
|
|
747
|
+
| { person: OchrePerson }
|
|
736
748
|
);
|
|
737
749
|
};
|
|
738
750
|
|
|
@@ -776,7 +788,8 @@ type OchreTree = {
|
|
|
776
788
|
| { spatialUnit: OchreSpatialUnit | Array<OchreSpatialUnit> }
|
|
777
789
|
| { concept: OchreConcept | Array<OchreConcept> }
|
|
778
790
|
| { period: OchrePeriod | Array<OchrePeriod> }
|
|
779
|
-
| { bibliography: OchreBibliography | Array<OchreBibliography> }
|
|
791
|
+
| { bibliography: OchreBibliography | Array<OchreBibliography> }
|
|
792
|
+
| { person: OchrePerson | Array<OchrePerson> };
|
|
780
793
|
properties?: { property: OchreProperty | Array<OchreProperty> };
|
|
781
794
|
};
|
|
782
795
|
|
|
@@ -800,7 +813,8 @@ type OchreSet = {
|
|
|
800
813
|
| { spatialUnit: OchreSpatialUnit | Array<OchreSpatialUnit> }
|
|
801
814
|
| { concept: OchreConcept | Array<OchreConcept> }
|
|
802
815
|
| { period: OchrePeriod | Array<OchrePeriod> }
|
|
803
|
-
| { bibliography: OchreBibliography | Array<OchreBibliography> }
|
|
816
|
+
| { bibliography: OchreBibliography | Array<OchreBibliography> }
|
|
817
|
+
| { person: OchrePerson | Array<OchrePerson> };
|
|
804
818
|
};
|
|
805
819
|
|
|
806
820
|
/**
|
|
@@ -909,7 +923,7 @@ type OchrePropertyValue = OchreStringContent & {
|
|
|
909
923
|
*/
|
|
910
924
|
type OchreProperty = {
|
|
911
925
|
label: OchreStringContent & { uuid: string };
|
|
912
|
-
value?: OchrePropertyValue | Array<OchrePropertyValue
|
|
926
|
+
value?: OchrePropertyValue | Array<OchrePropertyValue> | FakeString;
|
|
913
927
|
comment?: FakeString;
|
|
914
928
|
property?: OchreProperty | Array<OchreProperty>;
|
|
915
929
|
};
|
|
@@ -980,6 +994,10 @@ type OchreImage = {
|
|
|
980
994
|
href?: string;
|
|
981
995
|
htmlImgSrcPrefix?: string;
|
|
982
996
|
content?: FakeString;
|
|
997
|
+
widthPreview?: number;
|
|
998
|
+
heightPreview?: number;
|
|
999
|
+
width?: number;
|
|
1000
|
+
height?: number;
|
|
983
1001
|
};
|
|
984
1002
|
|
|
985
1003
|
/**
|
|
@@ -1531,7 +1549,14 @@ declare function parseLicense(license: OchreLicense): License | null;
|
|
|
1531
1549
|
/**
|
|
1532
1550
|
* Parses raw person data into the standardized Person type
|
|
1533
1551
|
*
|
|
1534
|
-
* @param
|
|
1552
|
+
* @param person - Raw person data from OCHRE format
|
|
1553
|
+
* @returns Parsed Person object
|
|
1554
|
+
*/
|
|
1555
|
+
declare function parsePerson(person: OchrePerson): Person;
|
|
1556
|
+
/**
|
|
1557
|
+
* Parses raw person data into the standardized Person type
|
|
1558
|
+
*
|
|
1559
|
+
* @param persons - Array of raw person data from OCHRE format
|
|
1535
1560
|
* @returns Array of parsed Person objects
|
|
1536
1561
|
*/
|
|
1537
1562
|
declare function parsePersons(persons: Array<OchrePerson>): Array<Person>;
|
|
@@ -1777,4 +1802,4 @@ declare function trimEndLineBreaks(string: string): string;
|
|
|
1777
1802
|
*/
|
|
1778
1803
|
declare function parseStringContent(content: OchreStringContent, language?: string): string;
|
|
1779
1804
|
|
|
1780
|
-
export { type Bibliography, type Concept, type Context, type ContextItem, type ContextNode, type Coordinates, type Data, 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 NestedConcept, type NestedResource, type NestedSpatialUnit, type Note, type Observation, type Period, type Person, type Property, type PropertyValue, type PropertyValueType, type Resource, type Set, type SpatialUnit, type Style, type Tree, type WebElement, type WebElementComponent, type WebImage, type Webpage, type WebpageProperties, type Website, type WebsiteProperties, fetchBibliography, fetchByUuid, fetchConcept, fetchGallery, fetchPeriod, fetchResource, fetchSet, fetchSpatialUnit, fetchTree, fetchWebsite, filterProperties, getAllPropertyLabels, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, parseBibliographies, parseBibliography, parseConcept, parseConcepts, parseContext, parseCoordinates, parseDocument, parseEmailAndUrl, parseEvents, parseFakeString, parseIdentification, parseImage, parseImageMap, parseInterpretations, parseLanguages, parseLicense, parseLink, parseLinks, parseMetadata, parseNotes, parseObservation, parseObservations, parsePeriod, parsePeriods, parsePersons, parseProperties, parseResource, parseResources, parseSet, parseSpatialUnit, parseSpatialUnits, parseStringContent, parseStringDocumentItem, parseStringItem, parseTree, parseWebsite, trimEndLineBreaks };
|
|
1805
|
+
export { type Bibliography, type Concept, type Context, type ContextItem, type ContextNode, type Coordinates, type Data, 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 NestedConcept, type NestedResource, type NestedSpatialUnit, type Note, type Observation, type Period, type Person, type Property, type PropertyValue, type PropertyValueType, type Resource, type Set, type SpatialUnit, type Style, type Tree, type WebElement, type WebElementComponent, type WebImage, type Webpage, type WebpageProperties, type Website, type WebsiteProperties, fetchBibliography, fetchByUuid, fetchConcept, fetchGallery, fetchPeriod, fetchResource, fetchSet, fetchSpatialUnit, fetchTree, fetchWebsite, filterProperties, getAllPropertyLabels, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, parseBibliographies, parseBibliography, parseConcept, parseConcepts, parseContext, parseCoordinates, parseDocument, parseEmailAndUrl, parseEvents, parseFakeString, parseIdentification, parseImage, parseImageMap, parseInterpretations, parseLanguages, parseLicense, parseLink, parseLinks, parseMetadata, parseNotes, parseObservation, parseObservations, parsePeriod, parsePeriods, parsePerson, parsePersons, parseProperties, parseResource, parseResources, parseSet, parseSpatialUnit, parseSpatialUnits, parseStringContent, parseStringDocumentItem, parseStringItem, parseTree, parseWebsite, trimEndLineBreaks };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ type Data = {
|
|
|
11
11
|
};
|
|
12
12
|
publicationDateTime: Date;
|
|
13
13
|
metadata: Metadata;
|
|
14
|
-
item: Tree | Set | Resource | SpatialUnit | Concept;
|
|
14
|
+
item: Tree | Set | Resource | SpatialUnit | Concept | Period | Bibliography | Person;
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
17
|
* Basic identification information used across multiple types
|
|
@@ -100,6 +100,10 @@ type Image = {
|
|
|
100
100
|
url: string | null;
|
|
101
101
|
htmlPrefix: string | null;
|
|
102
102
|
content: string | null;
|
|
103
|
+
widthPreview: number | null;
|
|
104
|
+
heightPreview: number | null;
|
|
105
|
+
width: number | null;
|
|
106
|
+
height: number | null;
|
|
103
107
|
};
|
|
104
108
|
/**
|
|
105
109
|
* Represents a link to another item with optional image and bibliographic references
|
|
@@ -288,6 +292,7 @@ type Set = {
|
|
|
288
292
|
concepts: Array<NestedConcept>;
|
|
289
293
|
periods: Array<Period>;
|
|
290
294
|
bibliographies: Array<Bibliography>;
|
|
295
|
+
persons: Array<Person>;
|
|
291
296
|
};
|
|
292
297
|
};
|
|
293
298
|
/**
|
|
@@ -377,6 +382,7 @@ type Tree = {
|
|
|
377
382
|
concepts: Array<Concept>;
|
|
378
383
|
periods: Array<Period>;
|
|
379
384
|
bibliographies: Array<Bibliography>;
|
|
385
|
+
persons: Array<Person>;
|
|
380
386
|
};
|
|
381
387
|
properties: Array<Property>;
|
|
382
388
|
};
|
|
@@ -493,6 +499,11 @@ type WebElementComponent = {
|
|
|
493
499
|
captionSource: "name" | "abbreviation" | "description";
|
|
494
500
|
captionLayout: "top" | "bottom" | "suppress";
|
|
495
501
|
altTextSource: "name" | "abbreviation" | "description";
|
|
502
|
+
carousel: {
|
|
503
|
+
secondsPerImage: number;
|
|
504
|
+
isFullWidth: boolean;
|
|
505
|
+
isFullHeight: boolean;
|
|
506
|
+
} | null;
|
|
496
507
|
} | {
|
|
497
508
|
component: "image-gallery";
|
|
498
509
|
galleryId: string;
|
|
@@ -733,6 +744,7 @@ type OchreData = {
|
|
|
733
744
|
| { concept: OchreConcept }
|
|
734
745
|
| { period: OchrePeriod }
|
|
735
746
|
| { bibliography: OchreBibliography }
|
|
747
|
+
| { person: OchrePerson }
|
|
736
748
|
);
|
|
737
749
|
};
|
|
738
750
|
|
|
@@ -776,7 +788,8 @@ type OchreTree = {
|
|
|
776
788
|
| { spatialUnit: OchreSpatialUnit | Array<OchreSpatialUnit> }
|
|
777
789
|
| { concept: OchreConcept | Array<OchreConcept> }
|
|
778
790
|
| { period: OchrePeriod | Array<OchrePeriod> }
|
|
779
|
-
| { bibliography: OchreBibliography | Array<OchreBibliography> }
|
|
791
|
+
| { bibliography: OchreBibliography | Array<OchreBibliography> }
|
|
792
|
+
| { person: OchrePerson | Array<OchrePerson> };
|
|
780
793
|
properties?: { property: OchreProperty | Array<OchreProperty> };
|
|
781
794
|
};
|
|
782
795
|
|
|
@@ -800,7 +813,8 @@ type OchreSet = {
|
|
|
800
813
|
| { spatialUnit: OchreSpatialUnit | Array<OchreSpatialUnit> }
|
|
801
814
|
| { concept: OchreConcept | Array<OchreConcept> }
|
|
802
815
|
| { period: OchrePeriod | Array<OchrePeriod> }
|
|
803
|
-
| { bibliography: OchreBibliography | Array<OchreBibliography> }
|
|
816
|
+
| { bibliography: OchreBibliography | Array<OchreBibliography> }
|
|
817
|
+
| { person: OchrePerson | Array<OchrePerson> };
|
|
804
818
|
};
|
|
805
819
|
|
|
806
820
|
/**
|
|
@@ -909,7 +923,7 @@ type OchrePropertyValue = OchreStringContent & {
|
|
|
909
923
|
*/
|
|
910
924
|
type OchreProperty = {
|
|
911
925
|
label: OchreStringContent & { uuid: string };
|
|
912
|
-
value?: OchrePropertyValue | Array<OchrePropertyValue
|
|
926
|
+
value?: OchrePropertyValue | Array<OchrePropertyValue> | FakeString;
|
|
913
927
|
comment?: FakeString;
|
|
914
928
|
property?: OchreProperty | Array<OchreProperty>;
|
|
915
929
|
};
|
|
@@ -980,6 +994,10 @@ type OchreImage = {
|
|
|
980
994
|
href?: string;
|
|
981
995
|
htmlImgSrcPrefix?: string;
|
|
982
996
|
content?: FakeString;
|
|
997
|
+
widthPreview?: number;
|
|
998
|
+
heightPreview?: number;
|
|
999
|
+
width?: number;
|
|
1000
|
+
height?: number;
|
|
983
1001
|
};
|
|
984
1002
|
|
|
985
1003
|
/**
|
|
@@ -1531,7 +1549,14 @@ declare function parseLicense(license: OchreLicense): License | null;
|
|
|
1531
1549
|
/**
|
|
1532
1550
|
* Parses raw person data into the standardized Person type
|
|
1533
1551
|
*
|
|
1534
|
-
* @param
|
|
1552
|
+
* @param person - Raw person data from OCHRE format
|
|
1553
|
+
* @returns Parsed Person object
|
|
1554
|
+
*/
|
|
1555
|
+
declare function parsePerson(person: OchrePerson): Person;
|
|
1556
|
+
/**
|
|
1557
|
+
* Parses raw person data into the standardized Person type
|
|
1558
|
+
*
|
|
1559
|
+
* @param persons - Array of raw person data from OCHRE format
|
|
1535
1560
|
* @returns Array of parsed Person objects
|
|
1536
1561
|
*/
|
|
1537
1562
|
declare function parsePersons(persons: Array<OchrePerson>): Array<Person>;
|
|
@@ -1777,4 +1802,4 @@ declare function trimEndLineBreaks(string: string): string;
|
|
|
1777
1802
|
*/
|
|
1778
1803
|
declare function parseStringContent(content: OchreStringContent, language?: string): string;
|
|
1779
1804
|
|
|
1780
|
-
export { type Bibliography, type Concept, type Context, type ContextItem, type ContextNode, type Coordinates, type Data, 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 NestedConcept, type NestedResource, type NestedSpatialUnit, type Note, type Observation, type Period, type Person, type Property, type PropertyValue, type PropertyValueType, type Resource, type Set, type SpatialUnit, type Style, type Tree, type WebElement, type WebElementComponent, type WebImage, type Webpage, type WebpageProperties, type Website, type WebsiteProperties, fetchBibliography, fetchByUuid, fetchConcept, fetchGallery, fetchPeriod, fetchResource, fetchSet, fetchSpatialUnit, fetchTree, fetchWebsite, filterProperties, getAllPropertyLabels, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, parseBibliographies, parseBibliography, parseConcept, parseConcepts, parseContext, parseCoordinates, parseDocument, parseEmailAndUrl, parseEvents, parseFakeString, parseIdentification, parseImage, parseImageMap, parseInterpretations, parseLanguages, parseLicense, parseLink, parseLinks, parseMetadata, parseNotes, parseObservation, parseObservations, parsePeriod, parsePeriods, parsePersons, parseProperties, parseResource, parseResources, parseSet, parseSpatialUnit, parseSpatialUnits, parseStringContent, parseStringDocumentItem, parseStringItem, parseTree, parseWebsite, trimEndLineBreaks };
|
|
1805
|
+
export { type Bibliography, type Concept, type Context, type ContextItem, type ContextNode, type Coordinates, type Data, 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 NestedConcept, type NestedResource, type NestedSpatialUnit, type Note, type Observation, type Period, type Person, type Property, type PropertyValue, type PropertyValueType, type Resource, type Set, type SpatialUnit, type Style, type Tree, type WebElement, type WebElementComponent, type WebImage, type Webpage, type WebpageProperties, type Website, type WebsiteProperties, fetchBibliography, fetchByUuid, fetchConcept, fetchGallery, fetchPeriod, fetchResource, fetchSet, fetchSpatialUnit, fetchTree, fetchWebsite, filterProperties, getAllPropertyLabels, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, parseBibliographies, parseBibliography, parseConcept, parseConcepts, parseContext, parseCoordinates, parseDocument, parseEmailAndUrl, parseEvents, parseFakeString, parseIdentification, parseImage, parseImageMap, parseInterpretations, parseLanguages, parseLicense, parseLink, parseLinks, parseMetadata, parseNotes, parseObservation, parseObservations, parsePeriod, parsePeriods, parsePerson, parsePersons, parseProperties, parseResource, parseResources, parseSet, parseSpatialUnit, parseSpatialUnits, parseStringContent, parseStringDocumentItem, parseStringItem, parseTree, parseWebsite, trimEndLineBreaks };
|
package/dist/index.js
CHANGED
|
@@ -639,17 +639,20 @@ function parseLicense(license) {
|
|
|
639
639
|
url: license.license.target
|
|
640
640
|
};
|
|
641
641
|
}
|
|
642
|
+
function parsePerson(person) {
|
|
643
|
+
return {
|
|
644
|
+
uuid: person.uuid,
|
|
645
|
+
publicationDateTime: person.publicationDateTime != null ? new Date(person.publicationDateTime) : null,
|
|
646
|
+
type: person.type ?? null,
|
|
647
|
+
date: person.date != null ? new Date(person.date) : null,
|
|
648
|
+
identification: person.identification ? parseIdentification(person.identification) : null,
|
|
649
|
+
content: person.content != null ? parseFakeString(person.content) : null
|
|
650
|
+
};
|
|
651
|
+
}
|
|
642
652
|
function parsePersons(persons) {
|
|
643
653
|
const returnPersons = [];
|
|
644
654
|
for (const person of persons) {
|
|
645
|
-
returnPersons.push(
|
|
646
|
-
uuid: person.uuid,
|
|
647
|
-
publicationDateTime: person.publicationDateTime != null ? new Date(person.publicationDateTime) : null,
|
|
648
|
-
type: person.type ?? null,
|
|
649
|
-
date: person.date != null ? new Date(person.date) : null,
|
|
650
|
-
identification: person.identification ? parseIdentification(person.identification) : null,
|
|
651
|
-
content: person.content != null ? parseFakeString(person.content) : null
|
|
652
|
-
});
|
|
655
|
+
returnPersons.push(parsePerson(person));
|
|
653
656
|
}
|
|
654
657
|
return returnPersons;
|
|
655
658
|
}
|
|
@@ -718,7 +721,11 @@ function parseImage(image) {
|
|
|
718
721
|
identification: image.identification ? parseIdentification(image.identification) : null,
|
|
719
722
|
url: image.href ?? (image.htmlImgSrcPrefix == null && image.content != null ? parseFakeString(image.content) : null),
|
|
720
723
|
htmlPrefix: image.htmlImgSrcPrefix ?? null,
|
|
721
|
-
content: image.htmlImgSrcPrefix != null && image.content != null ? parseFakeString(image.content) : null
|
|
724
|
+
content: image.htmlImgSrcPrefix != null && image.content != null ? parseFakeString(image.content) : null,
|
|
725
|
+
widthPreview: image.widthPreview ?? null,
|
|
726
|
+
heightPreview: image.heightPreview ?? null,
|
|
727
|
+
width: image.width ?? null,
|
|
728
|
+
height: image.height ?? null
|
|
722
729
|
};
|
|
723
730
|
}
|
|
724
731
|
function parseNotes(notes, language = "eng") {
|
|
@@ -812,13 +819,21 @@ function parseProperties(properties, language = "eng") {
|
|
|
812
819
|
const returnProperties = [];
|
|
813
820
|
for (const property of properties) {
|
|
814
821
|
const valuesToParse = "value" in property && property.value ? Array.isArray(property.value) ? property.value : [property.value] : [];
|
|
815
|
-
const values = valuesToParse.map(
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
+
const values = valuesToParse.map(
|
|
823
|
+
(value) => !["string", "number", "boolean"].includes(typeof value) && typeof value === "object" && "uuid" in value ? {
|
|
824
|
+
content: parseStringContent(value),
|
|
825
|
+
type: value.type,
|
|
826
|
+
category: value.category !== "value" ? value.category ?? null : null,
|
|
827
|
+
uuid: value.uuid ?? null,
|
|
828
|
+
publicationDateTime: value.publicationDateTime != null ? new Date(value.publicationDateTime) : null
|
|
829
|
+
} : {
|
|
830
|
+
content: parseFakeString(value),
|
|
831
|
+
type: "string",
|
|
832
|
+
category: "value",
|
|
833
|
+
uuid: null,
|
|
834
|
+
publicationDateTime: null
|
|
835
|
+
}
|
|
836
|
+
);
|
|
822
837
|
returnProperties.push({
|
|
823
838
|
label: parseStringContent(property.label, language).replace(/\s*\.{3}$/, "").trim(),
|
|
824
839
|
values,
|
|
@@ -964,6 +979,7 @@ function parseTree(tree) {
|
|
|
964
979
|
let concepts = [];
|
|
965
980
|
let periods = [];
|
|
966
981
|
let bibliographies = [];
|
|
982
|
+
let persons = [];
|
|
967
983
|
if (typeof tree.items !== "string" && "resource" in tree.items) {
|
|
968
984
|
resources = parseResources(
|
|
969
985
|
Array.isArray(tree.items.resource) ? tree.items.resource : [tree.items.resource]
|
|
@@ -989,6 +1005,11 @@ function parseTree(tree) {
|
|
|
989
1005
|
Array.isArray(tree.items.bibliography) ? tree.items.bibliography : [tree.items.bibliography]
|
|
990
1006
|
);
|
|
991
1007
|
}
|
|
1008
|
+
if (typeof tree.items !== "string" && "person" in tree.items) {
|
|
1009
|
+
persons = parsePersons(
|
|
1010
|
+
Array.isArray(tree.items.person) ? tree.items.person : [tree.items.person]
|
|
1011
|
+
);
|
|
1012
|
+
}
|
|
992
1013
|
const returnTree = {
|
|
993
1014
|
uuid: tree.uuid,
|
|
994
1015
|
category: "tree",
|
|
@@ -1004,7 +1025,8 @@ function parseTree(tree) {
|
|
|
1004
1025
|
spatialUnits,
|
|
1005
1026
|
concepts,
|
|
1006
1027
|
periods,
|
|
1007
|
-
bibliographies
|
|
1028
|
+
bibliographies,
|
|
1029
|
+
persons
|
|
1008
1030
|
},
|
|
1009
1031
|
properties: tree.properties ? parseProperties(
|
|
1010
1032
|
Array.isArray(tree.properties.property) ? tree.properties.property : [tree.properties.property]
|
|
@@ -1018,6 +1040,7 @@ function parseSet(set) {
|
|
|
1018
1040
|
let concepts = [];
|
|
1019
1041
|
let periods = [];
|
|
1020
1042
|
let bibliographies = [];
|
|
1043
|
+
let persons = [];
|
|
1021
1044
|
if (typeof set.items !== "string" && "resource" in set.items) {
|
|
1022
1045
|
resources = parseResources(
|
|
1023
1046
|
Array.isArray(set.items.resource) ? set.items.resource : [set.items.resource],
|
|
@@ -1046,6 +1069,11 @@ function parseSet(set) {
|
|
|
1046
1069
|
Array.isArray(set.items.bibliography) ? set.items.bibliography : [set.items.bibliography]
|
|
1047
1070
|
);
|
|
1048
1071
|
}
|
|
1072
|
+
if (typeof set.items !== "string" && "person" in set.items) {
|
|
1073
|
+
persons = parsePersons(
|
|
1074
|
+
Array.isArray(set.items.person) ? set.items.person : [set.items.person]
|
|
1075
|
+
);
|
|
1076
|
+
}
|
|
1049
1077
|
return {
|
|
1050
1078
|
uuid: set.uuid,
|
|
1051
1079
|
category: "set",
|
|
@@ -1065,7 +1093,8 @@ function parseSet(set) {
|
|
|
1065
1093
|
spatialUnits,
|
|
1066
1094
|
concepts,
|
|
1067
1095
|
periods,
|
|
1068
|
-
bibliographies
|
|
1096
|
+
bibliographies,
|
|
1097
|
+
persons
|
|
1069
1098
|
}
|
|
1070
1099
|
};
|
|
1071
1100
|
}
|
|
@@ -1397,6 +1426,15 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1397
1426
|
`Image link not found for the following component: \u201C${componentName}\u201D`
|
|
1398
1427
|
);
|
|
1399
1428
|
}
|
|
1429
|
+
const images = [];
|
|
1430
|
+
for (const imageLink of imageLinks) {
|
|
1431
|
+
images.push({
|
|
1432
|
+
url: `https://ochre.lib.uchicago.edu/ochre?uuid=${imageLink.uuid}&load`,
|
|
1433
|
+
label: imageLink.identification?.label ?? null,
|
|
1434
|
+
width: imageLink.image?.width ?? 0,
|
|
1435
|
+
height: imageLink.image?.height ?? 0
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1400
1438
|
let captionLayout = getPropertyValueByLabel(
|
|
1401
1439
|
componentProperty.properties,
|
|
1402
1440
|
"caption-layout"
|
|
@@ -1425,20 +1463,40 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1425
1463
|
if (altTextSource === null) {
|
|
1426
1464
|
altTextSource = "name";
|
|
1427
1465
|
}
|
|
1428
|
-
const
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1466
|
+
const carousel = images.length > 1 ? {
|
|
1467
|
+
secondsPerImage: 5,
|
|
1468
|
+
isFullWidth: false,
|
|
1469
|
+
isFullHeight: false
|
|
1470
|
+
} : null;
|
|
1471
|
+
if (carousel !== null) {
|
|
1472
|
+
const carouselSecondsPerImage = getPropertyValueByLabel(
|
|
1473
|
+
componentProperty.properties,
|
|
1474
|
+
"carousel-seconds-per-image"
|
|
1475
|
+
);
|
|
1476
|
+
if (carouselSecondsPerImage !== null) {
|
|
1477
|
+
carousel.secondsPerImage = Number.parseFloat(carouselSecondsPerImage);
|
|
1478
|
+
}
|
|
1479
|
+
const carouselIsFullWidth = getPropertyValueByLabel(
|
|
1480
|
+
componentProperty.properties,
|
|
1481
|
+
"carousel-full-width"
|
|
1482
|
+
);
|
|
1483
|
+
if (carouselIsFullWidth !== null) {
|
|
1484
|
+
carousel.isFullWidth = carouselIsFullWidth === "Yes";
|
|
1485
|
+
}
|
|
1486
|
+
const carouselIsFullHeight = getPropertyValueByLabel(
|
|
1487
|
+
componentProperty.properties,
|
|
1488
|
+
"carousel-full-height"
|
|
1489
|
+
);
|
|
1490
|
+
if (carouselIsFullHeight !== null) {
|
|
1491
|
+
carousel.isFullHeight = carouselIsFullHeight === "Yes";
|
|
1492
|
+
}
|
|
1436
1493
|
}
|
|
1437
1494
|
properties.images = images;
|
|
1438
1495
|
properties.imageQuality = imageQuality;
|
|
1439
1496
|
properties.captionLayout = captionLayout;
|
|
1440
1497
|
properties.captionSource = captionSource;
|
|
1441
1498
|
properties.altTextSource = altTextSource;
|
|
1499
|
+
properties.carousel = carousel;
|
|
1442
1500
|
break;
|
|
1443
1501
|
}
|
|
1444
1502
|
case "image-gallery": {
|
|
@@ -2221,6 +2279,7 @@ export {
|
|
|
2221
2279
|
parseObservations,
|
|
2222
2280
|
parsePeriod,
|
|
2223
2281
|
parsePeriods,
|
|
2282
|
+
parsePerson,
|
|
2224
2283
|
parsePersons,
|
|
2225
2284
|
parseProperties,
|
|
2226
2285
|
parseResource,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitalculture/ochre-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Node.js library for working with OCHRE (Online Cultural and Historical Research Environment) data",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"dev": "tsup src/index.ts --watch",
|
|
61
|
-
"build
|
|
61
|
+
"build": "tsup",
|
|
62
62
|
"lint": "eslint .",
|
|
63
63
|
"lint:fix": "eslint . --fix",
|
|
64
64
|
"format": "prettier --check .",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"check-types": "tsc --noEmit",
|
|
67
67
|
"check-exports": "attw --pack .",
|
|
68
68
|
"test": "vitest run",
|
|
69
|
-
"ci": "pnpm run build
|
|
69
|
+
"ci": "pnpm run build && pnpm run lint && pnpm run format && pnpm run check-types && pnpm run check-exports && pnpm run test",
|
|
70
70
|
"changeset": "changeset add",
|
|
71
71
|
"release": "changeset version && changeset publish"
|
|
72
72
|
}
|