@digitalculture/ochre-sdk 0.2.5 → 0.2.7
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/README.md +3 -3
- package/dist/index.cjs +77 -19
- package/dist/index.d.cts +28 -5
- package/dist/index.d.ts +28 -5
- package/dist/index.js +76 -19
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -5,19 +5,19 @@ This is the OCHRE JavaScript/TypeScript SDK for interacting with OCHRE (Online C
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
pnpm add @
|
|
8
|
+
pnpm add @digitalculture/ochre-sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
or
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
npm install @
|
|
14
|
+
npm install @digitalculture/ochre-sdk
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
or
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
bun add @
|
|
20
|
+
bun add @digitalculture/ochre-sdk
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## Start development server
|
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") {
|
|
@@ -1049,6 +1057,7 @@ function parseTree(tree) {
|
|
|
1049
1057
|
let concepts = [];
|
|
1050
1058
|
let periods = [];
|
|
1051
1059
|
let bibliographies = [];
|
|
1060
|
+
let persons = [];
|
|
1052
1061
|
if (typeof tree.items !== "string" && "resource" in tree.items) {
|
|
1053
1062
|
resources = parseResources(
|
|
1054
1063
|
Array.isArray(tree.items.resource) ? tree.items.resource : [tree.items.resource]
|
|
@@ -1074,6 +1083,11 @@ function parseTree(tree) {
|
|
|
1074
1083
|
Array.isArray(tree.items.bibliography) ? tree.items.bibliography : [tree.items.bibliography]
|
|
1075
1084
|
);
|
|
1076
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
|
+
}
|
|
1077
1091
|
const returnTree = {
|
|
1078
1092
|
uuid: tree.uuid,
|
|
1079
1093
|
category: "tree",
|
|
@@ -1089,7 +1103,8 @@ function parseTree(tree) {
|
|
|
1089
1103
|
spatialUnits,
|
|
1090
1104
|
concepts,
|
|
1091
1105
|
periods,
|
|
1092
|
-
bibliographies
|
|
1106
|
+
bibliographies,
|
|
1107
|
+
persons
|
|
1093
1108
|
},
|
|
1094
1109
|
properties: tree.properties ? parseProperties(
|
|
1095
1110
|
Array.isArray(tree.properties.property) ? tree.properties.property : [tree.properties.property]
|
|
@@ -1103,6 +1118,7 @@ function parseSet(set) {
|
|
|
1103
1118
|
let concepts = [];
|
|
1104
1119
|
let periods = [];
|
|
1105
1120
|
let bibliographies = [];
|
|
1121
|
+
let persons = [];
|
|
1106
1122
|
if (typeof set.items !== "string" && "resource" in set.items) {
|
|
1107
1123
|
resources = parseResources(
|
|
1108
1124
|
Array.isArray(set.items.resource) ? set.items.resource : [set.items.resource],
|
|
@@ -1131,6 +1147,11 @@ function parseSet(set) {
|
|
|
1131
1147
|
Array.isArray(set.items.bibliography) ? set.items.bibliography : [set.items.bibliography]
|
|
1132
1148
|
);
|
|
1133
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
|
+
}
|
|
1134
1155
|
return {
|
|
1135
1156
|
uuid: set.uuid,
|
|
1136
1157
|
category: "set",
|
|
@@ -1150,7 +1171,8 @@ function parseSet(set) {
|
|
|
1150
1171
|
spatialUnits,
|
|
1151
1172
|
concepts,
|
|
1152
1173
|
periods,
|
|
1153
|
-
bibliographies
|
|
1174
|
+
bibliographies,
|
|
1175
|
+
persons
|
|
1154
1176
|
}
|
|
1155
1177
|
};
|
|
1156
1178
|
}
|
|
@@ -1482,6 +1504,22 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1482
1504
|
`Image link not found for the following component: \u201C${componentName}\u201D`
|
|
1483
1505
|
);
|
|
1484
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
|
+
}
|
|
1516
|
+
let variant = getPropertyValueByLabel(
|
|
1517
|
+
componentProperty.properties,
|
|
1518
|
+
"variant"
|
|
1519
|
+
);
|
|
1520
|
+
if (variant === null) {
|
|
1521
|
+
variant = "default";
|
|
1522
|
+
}
|
|
1485
1523
|
let captionLayout = getPropertyValueByLabel(
|
|
1486
1524
|
componentProperty.properties,
|
|
1487
1525
|
"caption-layout"
|
|
@@ -1510,20 +1548,39 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1510
1548
|
if (altTextSource === null) {
|
|
1511
1549
|
altTextSource = "name";
|
|
1512
1550
|
}
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1551
|
+
let secondsPerImage = images.length > 1 ? 5 : null;
|
|
1552
|
+
const secondsPerImageProperty = getPropertyValueByLabel(
|
|
1553
|
+
componentProperty.properties,
|
|
1554
|
+
"seconds-per-image"
|
|
1555
|
+
);
|
|
1556
|
+
if (secondsPerImageProperty !== null) {
|
|
1557
|
+
secondsPerImage = Number.parseFloat(secondsPerImageProperty);
|
|
1558
|
+
}
|
|
1559
|
+
let isFullWidth = false;
|
|
1560
|
+
const isFullWidthProperty = getPropertyValueByLabel(
|
|
1561
|
+
componentProperty.properties,
|
|
1562
|
+
"is-full-width"
|
|
1563
|
+
);
|
|
1564
|
+
if (isFullWidthProperty !== null) {
|
|
1565
|
+
isFullWidth = isFullWidthProperty === "Yes";
|
|
1566
|
+
}
|
|
1567
|
+
let isFullHeight = false;
|
|
1568
|
+
const isFullHeightProperty = getPropertyValueByLabel(
|
|
1569
|
+
componentProperty.properties,
|
|
1570
|
+
"is-full-height"
|
|
1571
|
+
);
|
|
1572
|
+
if (isFullHeightProperty !== null) {
|
|
1573
|
+
isFullHeight = isFullHeightProperty === "Yes";
|
|
1521
1574
|
}
|
|
1522
1575
|
properties.images = images;
|
|
1576
|
+
properties.variant = variant;
|
|
1523
1577
|
properties.imageQuality = imageQuality;
|
|
1524
1578
|
properties.captionLayout = captionLayout;
|
|
1525
1579
|
properties.captionSource = captionSource;
|
|
1526
1580
|
properties.altTextSource = altTextSource;
|
|
1581
|
+
properties.secondsPerImage = secondsPerImage;
|
|
1582
|
+
properties.isFullWidth = isFullWidth;
|
|
1583
|
+
properties.isFullHeight = isFullHeight;
|
|
1527
1584
|
break;
|
|
1528
1585
|
}
|
|
1529
1586
|
case "image-gallery": {
|
|
@@ -2307,6 +2364,7 @@ async function fetchWebsite(abbreviation) {
|
|
|
2307
2364
|
parseObservations,
|
|
2308
2365
|
parsePeriod,
|
|
2309
2366
|
parsePeriods,
|
|
2367
|
+
parsePerson,
|
|
2310
2368
|
parsePersons,
|
|
2311
2369
|
parseProperties,
|
|
2312
2370
|
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,9 @@ type WebElementComponent = {
|
|
|
493
499
|
captionSource: "name" | "abbreviation" | "description";
|
|
494
500
|
captionLayout: "top" | "bottom" | "suppress";
|
|
495
501
|
altTextSource: "name" | "abbreviation" | "description";
|
|
502
|
+
secondsPerImage: number | null;
|
|
503
|
+
isFullWidth: boolean | null;
|
|
504
|
+
isFullHeight: boolean | null;
|
|
496
505
|
} | {
|
|
497
506
|
component: "image-gallery";
|
|
498
507
|
galleryId: string;
|
|
@@ -733,6 +742,7 @@ type OchreData = {
|
|
|
733
742
|
| { concept: OchreConcept }
|
|
734
743
|
| { period: OchrePeriod }
|
|
735
744
|
| { bibliography: OchreBibliography }
|
|
745
|
+
| { person: OchrePerson }
|
|
736
746
|
);
|
|
737
747
|
};
|
|
738
748
|
|
|
@@ -776,7 +786,8 @@ type OchreTree = {
|
|
|
776
786
|
| { spatialUnit: OchreSpatialUnit | Array<OchreSpatialUnit> }
|
|
777
787
|
| { concept: OchreConcept | Array<OchreConcept> }
|
|
778
788
|
| { period: OchrePeriod | Array<OchrePeriod> }
|
|
779
|
-
| { bibliography: OchreBibliography | Array<OchreBibliography> }
|
|
789
|
+
| { bibliography: OchreBibliography | Array<OchreBibliography> }
|
|
790
|
+
| { person: OchrePerson | Array<OchrePerson> };
|
|
780
791
|
properties?: { property: OchreProperty | Array<OchreProperty> };
|
|
781
792
|
};
|
|
782
793
|
|
|
@@ -800,7 +811,8 @@ type OchreSet = {
|
|
|
800
811
|
| { spatialUnit: OchreSpatialUnit | Array<OchreSpatialUnit> }
|
|
801
812
|
| { concept: OchreConcept | Array<OchreConcept> }
|
|
802
813
|
| { period: OchrePeriod | Array<OchrePeriod> }
|
|
803
|
-
| { bibliography: OchreBibliography | Array<OchreBibliography> }
|
|
814
|
+
| { bibliography: OchreBibliography | Array<OchreBibliography> }
|
|
815
|
+
| { person: OchrePerson | Array<OchrePerson> };
|
|
804
816
|
};
|
|
805
817
|
|
|
806
818
|
/**
|
|
@@ -980,6 +992,10 @@ type OchreImage = {
|
|
|
980
992
|
href?: string;
|
|
981
993
|
htmlImgSrcPrefix?: string;
|
|
982
994
|
content?: FakeString;
|
|
995
|
+
widthPreview?: number;
|
|
996
|
+
heightPreview?: number;
|
|
997
|
+
width?: number;
|
|
998
|
+
height?: number;
|
|
983
999
|
};
|
|
984
1000
|
|
|
985
1001
|
/**
|
|
@@ -1531,7 +1547,14 @@ declare function parseLicense(license: OchreLicense): License | null;
|
|
|
1531
1547
|
/**
|
|
1532
1548
|
* Parses raw person data into the standardized Person type
|
|
1533
1549
|
*
|
|
1534
|
-
* @param
|
|
1550
|
+
* @param person - Raw person data from OCHRE format
|
|
1551
|
+
* @returns Parsed Person object
|
|
1552
|
+
*/
|
|
1553
|
+
declare function parsePerson(person: OchrePerson): Person;
|
|
1554
|
+
/**
|
|
1555
|
+
* Parses raw person data into the standardized Person type
|
|
1556
|
+
*
|
|
1557
|
+
* @param persons - Array of raw person data from OCHRE format
|
|
1535
1558
|
* @returns Array of parsed Person objects
|
|
1536
1559
|
*/
|
|
1537
1560
|
declare function parsePersons(persons: Array<OchrePerson>): Array<Person>;
|
|
@@ -1777,4 +1800,4 @@ declare function trimEndLineBreaks(string: string): string;
|
|
|
1777
1800
|
*/
|
|
1778
1801
|
declare function parseStringContent(content: OchreStringContent, language?: string): string;
|
|
1779
1802
|
|
|
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 };
|
|
1803
|
+
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,9 @@ type WebElementComponent = {
|
|
|
493
499
|
captionSource: "name" | "abbreviation" | "description";
|
|
494
500
|
captionLayout: "top" | "bottom" | "suppress";
|
|
495
501
|
altTextSource: "name" | "abbreviation" | "description";
|
|
502
|
+
secondsPerImage: number | null;
|
|
503
|
+
isFullWidth: boolean | null;
|
|
504
|
+
isFullHeight: boolean | null;
|
|
496
505
|
} | {
|
|
497
506
|
component: "image-gallery";
|
|
498
507
|
galleryId: string;
|
|
@@ -733,6 +742,7 @@ type OchreData = {
|
|
|
733
742
|
| { concept: OchreConcept }
|
|
734
743
|
| { period: OchrePeriod }
|
|
735
744
|
| { bibliography: OchreBibliography }
|
|
745
|
+
| { person: OchrePerson }
|
|
736
746
|
);
|
|
737
747
|
};
|
|
738
748
|
|
|
@@ -776,7 +786,8 @@ type OchreTree = {
|
|
|
776
786
|
| { spatialUnit: OchreSpatialUnit | Array<OchreSpatialUnit> }
|
|
777
787
|
| { concept: OchreConcept | Array<OchreConcept> }
|
|
778
788
|
| { period: OchrePeriod | Array<OchrePeriod> }
|
|
779
|
-
| { bibliography: OchreBibliography | Array<OchreBibliography> }
|
|
789
|
+
| { bibliography: OchreBibliography | Array<OchreBibliography> }
|
|
790
|
+
| { person: OchrePerson | Array<OchrePerson> };
|
|
780
791
|
properties?: { property: OchreProperty | Array<OchreProperty> };
|
|
781
792
|
};
|
|
782
793
|
|
|
@@ -800,7 +811,8 @@ type OchreSet = {
|
|
|
800
811
|
| { spatialUnit: OchreSpatialUnit | Array<OchreSpatialUnit> }
|
|
801
812
|
| { concept: OchreConcept | Array<OchreConcept> }
|
|
802
813
|
| { period: OchrePeriod | Array<OchrePeriod> }
|
|
803
|
-
| { bibliography: OchreBibliography | Array<OchreBibliography> }
|
|
814
|
+
| { bibliography: OchreBibliography | Array<OchreBibliography> }
|
|
815
|
+
| { person: OchrePerson | Array<OchrePerson> };
|
|
804
816
|
};
|
|
805
817
|
|
|
806
818
|
/**
|
|
@@ -980,6 +992,10 @@ type OchreImage = {
|
|
|
980
992
|
href?: string;
|
|
981
993
|
htmlImgSrcPrefix?: string;
|
|
982
994
|
content?: FakeString;
|
|
995
|
+
widthPreview?: number;
|
|
996
|
+
heightPreview?: number;
|
|
997
|
+
width?: number;
|
|
998
|
+
height?: number;
|
|
983
999
|
};
|
|
984
1000
|
|
|
985
1001
|
/**
|
|
@@ -1531,7 +1547,14 @@ declare function parseLicense(license: OchreLicense): License | null;
|
|
|
1531
1547
|
/**
|
|
1532
1548
|
* Parses raw person data into the standardized Person type
|
|
1533
1549
|
*
|
|
1534
|
-
* @param
|
|
1550
|
+
* @param person - Raw person data from OCHRE format
|
|
1551
|
+
* @returns Parsed Person object
|
|
1552
|
+
*/
|
|
1553
|
+
declare function parsePerson(person: OchrePerson): Person;
|
|
1554
|
+
/**
|
|
1555
|
+
* Parses raw person data into the standardized Person type
|
|
1556
|
+
*
|
|
1557
|
+
* @param persons - Array of raw person data from OCHRE format
|
|
1535
1558
|
* @returns Array of parsed Person objects
|
|
1536
1559
|
*/
|
|
1537
1560
|
declare function parsePersons(persons: Array<OchrePerson>): Array<Person>;
|
|
@@ -1777,4 +1800,4 @@ declare function trimEndLineBreaks(string: string): string;
|
|
|
1777
1800
|
*/
|
|
1778
1801
|
declare function parseStringContent(content: OchreStringContent, language?: string): string;
|
|
1779
1802
|
|
|
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 };
|
|
1803
|
+
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") {
|
|
@@ -972,6 +979,7 @@ function parseTree(tree) {
|
|
|
972
979
|
let concepts = [];
|
|
973
980
|
let periods = [];
|
|
974
981
|
let bibliographies = [];
|
|
982
|
+
let persons = [];
|
|
975
983
|
if (typeof tree.items !== "string" && "resource" in tree.items) {
|
|
976
984
|
resources = parseResources(
|
|
977
985
|
Array.isArray(tree.items.resource) ? tree.items.resource : [tree.items.resource]
|
|
@@ -997,6 +1005,11 @@ function parseTree(tree) {
|
|
|
997
1005
|
Array.isArray(tree.items.bibliography) ? tree.items.bibliography : [tree.items.bibliography]
|
|
998
1006
|
);
|
|
999
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
|
+
}
|
|
1000
1013
|
const returnTree = {
|
|
1001
1014
|
uuid: tree.uuid,
|
|
1002
1015
|
category: "tree",
|
|
@@ -1012,7 +1025,8 @@ function parseTree(tree) {
|
|
|
1012
1025
|
spatialUnits,
|
|
1013
1026
|
concepts,
|
|
1014
1027
|
periods,
|
|
1015
|
-
bibliographies
|
|
1028
|
+
bibliographies,
|
|
1029
|
+
persons
|
|
1016
1030
|
},
|
|
1017
1031
|
properties: tree.properties ? parseProperties(
|
|
1018
1032
|
Array.isArray(tree.properties.property) ? tree.properties.property : [tree.properties.property]
|
|
@@ -1026,6 +1040,7 @@ function parseSet(set) {
|
|
|
1026
1040
|
let concepts = [];
|
|
1027
1041
|
let periods = [];
|
|
1028
1042
|
let bibliographies = [];
|
|
1043
|
+
let persons = [];
|
|
1029
1044
|
if (typeof set.items !== "string" && "resource" in set.items) {
|
|
1030
1045
|
resources = parseResources(
|
|
1031
1046
|
Array.isArray(set.items.resource) ? set.items.resource : [set.items.resource],
|
|
@@ -1054,6 +1069,11 @@ function parseSet(set) {
|
|
|
1054
1069
|
Array.isArray(set.items.bibliography) ? set.items.bibliography : [set.items.bibliography]
|
|
1055
1070
|
);
|
|
1056
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
|
+
}
|
|
1057
1077
|
return {
|
|
1058
1078
|
uuid: set.uuid,
|
|
1059
1079
|
category: "set",
|
|
@@ -1073,7 +1093,8 @@ function parseSet(set) {
|
|
|
1073
1093
|
spatialUnits,
|
|
1074
1094
|
concepts,
|
|
1075
1095
|
periods,
|
|
1076
|
-
bibliographies
|
|
1096
|
+
bibliographies,
|
|
1097
|
+
persons
|
|
1077
1098
|
}
|
|
1078
1099
|
};
|
|
1079
1100
|
}
|
|
@@ -1405,6 +1426,22 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1405
1426
|
`Image link not found for the following component: \u201C${componentName}\u201D`
|
|
1406
1427
|
);
|
|
1407
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
|
+
}
|
|
1438
|
+
let variant = getPropertyValueByLabel(
|
|
1439
|
+
componentProperty.properties,
|
|
1440
|
+
"variant"
|
|
1441
|
+
);
|
|
1442
|
+
if (variant === null) {
|
|
1443
|
+
variant = "default";
|
|
1444
|
+
}
|
|
1408
1445
|
let captionLayout = getPropertyValueByLabel(
|
|
1409
1446
|
componentProperty.properties,
|
|
1410
1447
|
"caption-layout"
|
|
@@ -1433,20 +1470,39 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1433
1470
|
if (altTextSource === null) {
|
|
1434
1471
|
altTextSource = "name";
|
|
1435
1472
|
}
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1473
|
+
let secondsPerImage = images.length > 1 ? 5 : null;
|
|
1474
|
+
const secondsPerImageProperty = getPropertyValueByLabel(
|
|
1475
|
+
componentProperty.properties,
|
|
1476
|
+
"seconds-per-image"
|
|
1477
|
+
);
|
|
1478
|
+
if (secondsPerImageProperty !== null) {
|
|
1479
|
+
secondsPerImage = Number.parseFloat(secondsPerImageProperty);
|
|
1480
|
+
}
|
|
1481
|
+
let isFullWidth = false;
|
|
1482
|
+
const isFullWidthProperty = getPropertyValueByLabel(
|
|
1483
|
+
componentProperty.properties,
|
|
1484
|
+
"is-full-width"
|
|
1485
|
+
);
|
|
1486
|
+
if (isFullWidthProperty !== null) {
|
|
1487
|
+
isFullWidth = isFullWidthProperty === "Yes";
|
|
1488
|
+
}
|
|
1489
|
+
let isFullHeight = false;
|
|
1490
|
+
const isFullHeightProperty = getPropertyValueByLabel(
|
|
1491
|
+
componentProperty.properties,
|
|
1492
|
+
"is-full-height"
|
|
1493
|
+
);
|
|
1494
|
+
if (isFullHeightProperty !== null) {
|
|
1495
|
+
isFullHeight = isFullHeightProperty === "Yes";
|
|
1444
1496
|
}
|
|
1445
1497
|
properties.images = images;
|
|
1498
|
+
properties.variant = variant;
|
|
1446
1499
|
properties.imageQuality = imageQuality;
|
|
1447
1500
|
properties.captionLayout = captionLayout;
|
|
1448
1501
|
properties.captionSource = captionSource;
|
|
1449
1502
|
properties.altTextSource = altTextSource;
|
|
1503
|
+
properties.secondsPerImage = secondsPerImage;
|
|
1504
|
+
properties.isFullWidth = isFullWidth;
|
|
1505
|
+
properties.isFullHeight = isFullHeight;
|
|
1450
1506
|
break;
|
|
1451
1507
|
}
|
|
1452
1508
|
case "image-gallery": {
|
|
@@ -2229,6 +2285,7 @@ export {
|
|
|
2229
2285
|
parseObservations,
|
|
2230
2286
|
parsePeriod,
|
|
2231
2287
|
parsePeriods,
|
|
2288
|
+
parsePerson,
|
|
2232
2289
|
parsePersons,
|
|
2233
2290
|
parseProperties,
|
|
2234
2291
|
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.7",
|
|
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
|
}
|