@digitalculture/ochre-sdk 0.5.17 → 0.5.19
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 +120 -30
- package/dist/index.d.cts +21 -11
- package/dist/index.d.ts +21 -11
- package/dist/index.js +119 -30
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -63,6 +63,7 @@ __export(index_exports, {
|
|
|
63
63
|
parsePerson: () => parsePerson,
|
|
64
64
|
parsePersons: () => parsePersons,
|
|
65
65
|
parseProperties: () => parseProperties,
|
|
66
|
+
parseProperty: () => parseProperty,
|
|
66
67
|
parsePropertyValue: () => parsePropertyValue,
|
|
67
68
|
parsePropertyValues: () => parsePropertyValues,
|
|
68
69
|
parseResource: () => parseResource,
|
|
@@ -524,9 +525,36 @@ function filterProperties(property, filter, options = DEFAULT_OPTIONS) {
|
|
|
524
525
|
const { searchNestedProperties } = options;
|
|
525
526
|
const isAllFields = filter.label.toLocaleLowerCase("en-US") === "all fields";
|
|
526
527
|
if (isAllFields || property.label.toLocaleLowerCase("en-US") === filter.label.toLocaleLowerCase("en-US")) {
|
|
527
|
-
let isFound = property.values.some(
|
|
528
|
-
(value
|
|
529
|
-
|
|
528
|
+
let isFound = property.values.some((value) => {
|
|
529
|
+
if (value.content === null) {
|
|
530
|
+
return false;
|
|
531
|
+
}
|
|
532
|
+
if (typeof value.content === "string") {
|
|
533
|
+
if (typeof filter.value !== "string") {
|
|
534
|
+
return false;
|
|
535
|
+
}
|
|
536
|
+
return value.content.toLocaleLowerCase("en-US").includes(filter.value.toLocaleLowerCase("en-US"));
|
|
537
|
+
}
|
|
538
|
+
if (typeof value.content === "number") {
|
|
539
|
+
if (typeof filter.value !== "number") {
|
|
540
|
+
return false;
|
|
541
|
+
}
|
|
542
|
+
return value.content === filter.value;
|
|
543
|
+
}
|
|
544
|
+
if (typeof value.content === "boolean") {
|
|
545
|
+
if (typeof filter.value !== "boolean") {
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
return value.booleanValue === filter.value;
|
|
549
|
+
}
|
|
550
|
+
if (value.content instanceof Date) {
|
|
551
|
+
if (!(filter.value instanceof Date)) {
|
|
552
|
+
return false;
|
|
553
|
+
}
|
|
554
|
+
return value.content.getTime() === filter.value.getTime();
|
|
555
|
+
}
|
|
556
|
+
return false;
|
|
557
|
+
});
|
|
530
558
|
if (!isFound && searchNestedProperties) {
|
|
531
559
|
isFound = property.properties.some(
|
|
532
560
|
(property2) => filterProperties(property2, filter, { searchNestedProperties: true })
|
|
@@ -874,33 +902,71 @@ function parseEvents(events) {
|
|
|
874
902
|
}
|
|
875
903
|
return returnEvents;
|
|
876
904
|
}
|
|
877
|
-
function
|
|
878
|
-
const
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
} : {
|
|
889
|
-
content: parseFakeString(value),
|
|
890
|
-
type: "string",
|
|
905
|
+
function parseProperty(property, type, language = "eng") {
|
|
906
|
+
const valuesToParse = "value" in property && property.value ? Array.isArray(property.value) ? property.value : [property.value] : [];
|
|
907
|
+
const values = valuesToParse.map((value) => {
|
|
908
|
+
let content = null;
|
|
909
|
+
let booleanValue = null;
|
|
910
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
911
|
+
content = parseFakeString(value);
|
|
912
|
+
const returnValue = {
|
|
913
|
+
content,
|
|
914
|
+
booleanValue,
|
|
915
|
+
type,
|
|
891
916
|
category: "value",
|
|
892
917
|
uuid: null,
|
|
893
918
|
publicationDateTime: null
|
|
919
|
+
};
|
|
920
|
+
return returnValue;
|
|
921
|
+
} else {
|
|
922
|
+
switch (type) {
|
|
923
|
+
case "integer":
|
|
924
|
+
case "decimal": {
|
|
925
|
+
content = Number(value.content);
|
|
926
|
+
break;
|
|
927
|
+
}
|
|
928
|
+
case "dateTime": {
|
|
929
|
+
content = value.content ? typeof value.content === "string" ? new Date(value.content) : new Date(parseStringContent({ content: value.content })) : null;
|
|
930
|
+
break;
|
|
931
|
+
}
|
|
932
|
+
default: {
|
|
933
|
+
if ("slug" in value && value.slug != null) {
|
|
934
|
+
content = parseFakeString(value.slug);
|
|
935
|
+
} else if (value.content != null) {
|
|
936
|
+
content = parseStringContent({ content: value.content });
|
|
937
|
+
}
|
|
938
|
+
if (type === "boolean") {
|
|
939
|
+
booleanValue = value.booleanValue ?? null;
|
|
940
|
+
}
|
|
941
|
+
break;
|
|
942
|
+
}
|
|
894
943
|
}
|
|
944
|
+
const returnValue = {
|
|
945
|
+
content,
|
|
946
|
+
booleanValue,
|
|
947
|
+
type,
|
|
948
|
+
category: value.category ?? "value",
|
|
949
|
+
uuid: value.uuid ?? null,
|
|
950
|
+
publicationDateTime: value.publicationDateTime != null ? new Date(value.publicationDateTime) : null
|
|
951
|
+
};
|
|
952
|
+
return returnValue;
|
|
953
|
+
}
|
|
954
|
+
});
|
|
955
|
+
return {
|
|
956
|
+
label: parseStringContent(property.label, language).replace(/\s*\.{3}$/, "").trim(),
|
|
957
|
+
values,
|
|
958
|
+
comment: property.comment != null ? parseFakeString(property.comment) : null,
|
|
959
|
+
properties: property.property ? parseProperties(
|
|
960
|
+
Array.isArray(property.property) ? property.property : [property.property]
|
|
961
|
+
) : []
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
function parseProperties(properties, language = "eng") {
|
|
965
|
+
const returnProperties = [];
|
|
966
|
+
for (const property of properties) {
|
|
967
|
+
returnProperties.push(
|
|
968
|
+
parseProperty(property, "string", language)
|
|
895
969
|
);
|
|
896
|
-
returnProperties.push({
|
|
897
|
-
label: parseStringContent(property.label, language).replace(/\s*\.{3}$/, "").trim(),
|
|
898
|
-
values,
|
|
899
|
-
comment: property.comment != null ? parseFakeString(property.comment) : null,
|
|
900
|
-
properties: property.property ? parseProperties(
|
|
901
|
-
Array.isArray(property.property) ? property.property : [property.property]
|
|
902
|
-
) : []
|
|
903
|
-
});
|
|
904
970
|
}
|
|
905
971
|
return returnProperties;
|
|
906
972
|
}
|
|
@@ -1644,7 +1710,11 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1644
1710
|
"width"
|
|
1645
1711
|
);
|
|
1646
1712
|
if (widthProperty !== null) {
|
|
1647
|
-
|
|
1713
|
+
if (typeof widthProperty === "number") {
|
|
1714
|
+
width = widthProperty;
|
|
1715
|
+
} else if (typeof widthProperty === "string") {
|
|
1716
|
+
width = Number.parseFloat(widthProperty);
|
|
1717
|
+
}
|
|
1648
1718
|
}
|
|
1649
1719
|
let height = null;
|
|
1650
1720
|
const heightProperty = getPropertyValueByLabel(
|
|
@@ -1652,7 +1722,11 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1652
1722
|
"height"
|
|
1653
1723
|
);
|
|
1654
1724
|
if (heightProperty !== null) {
|
|
1655
|
-
|
|
1725
|
+
if (typeof heightProperty === "number") {
|
|
1726
|
+
height = heightProperty;
|
|
1727
|
+
} else if (typeof heightProperty === "string") {
|
|
1728
|
+
height = Number.parseFloat(heightProperty);
|
|
1729
|
+
}
|
|
1656
1730
|
}
|
|
1657
1731
|
let isFullWidth = true;
|
|
1658
1732
|
const isFullWidthProperty = getPropertyValueByLabel(
|
|
@@ -1714,7 +1788,11 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1714
1788
|
"seconds-per-image"
|
|
1715
1789
|
);
|
|
1716
1790
|
if (secondsPerImageProperty !== null) {
|
|
1717
|
-
|
|
1791
|
+
if (typeof secondsPerImageProperty === "number") {
|
|
1792
|
+
secondsPerImage = secondsPerImageProperty;
|
|
1793
|
+
} else if (typeof secondsPerImageProperty === "string") {
|
|
1794
|
+
secondsPerImage = Number.parseFloat(secondsPerImageProperty);
|
|
1795
|
+
}
|
|
1718
1796
|
}
|
|
1719
1797
|
}
|
|
1720
1798
|
carouselOptions = {
|
|
@@ -1969,7 +2047,7 @@ async function parseWebpage(webpageResource) {
|
|
|
1969
2047
|
resourceProperties,
|
|
1970
2048
|
"presentation"
|
|
1971
2049
|
);
|
|
1972
|
-
if (
|
|
2050
|
+
if (resourceType == null) {
|
|
1973
2051
|
continue;
|
|
1974
2052
|
}
|
|
1975
2053
|
switch (resourceType) {
|
|
@@ -2150,7 +2228,7 @@ async function parseBlock(blockResource) {
|
|
|
2150
2228
|
resourceProperties,
|
|
2151
2229
|
"presentation"
|
|
2152
2230
|
);
|
|
2153
|
-
if (
|
|
2231
|
+
if (resourceType == null) {
|
|
2154
2232
|
continue;
|
|
2155
2233
|
}
|
|
2156
2234
|
switch (resourceType) {
|
|
@@ -2223,6 +2301,16 @@ function parseWebsiteProperties(properties) {
|
|
|
2223
2301
|
if (!result.success) {
|
|
2224
2302
|
throw new Error(`Invalid website properties: ${result.error.message}`);
|
|
2225
2303
|
}
|
|
2304
|
+
let contact = null;
|
|
2305
|
+
const contactProperty = websiteProperties.find(
|
|
2306
|
+
(property) => property.label === "contact"
|
|
2307
|
+
);
|
|
2308
|
+
if (contactProperty) {
|
|
2309
|
+
const [name, email] = (contactProperty.values[0]?.content).split(
|
|
2310
|
+
";"
|
|
2311
|
+
);
|
|
2312
|
+
contact = { name, email: email ?? null };
|
|
2313
|
+
}
|
|
2226
2314
|
const logoUuid = websiteProperties.find((property) => property.label === "logo")?.values[0]?.uuid ?? null;
|
|
2227
2315
|
let isHeaderDisplayed = true;
|
|
2228
2316
|
let headerVariant = "default";
|
|
@@ -2289,6 +2377,7 @@ function parseWebsiteProperties(properties) {
|
|
|
2289
2377
|
type: validatedType,
|
|
2290
2378
|
privacy: validatedPrivacy,
|
|
2291
2379
|
status: validatedStatus,
|
|
2380
|
+
contact,
|
|
2292
2381
|
isHeaderDisplayed,
|
|
2293
2382
|
headerVariant,
|
|
2294
2383
|
headerAlignment,
|
|
@@ -2759,6 +2848,7 @@ async function fetchWebsite(abbreviation) {
|
|
|
2759
2848
|
parsePerson,
|
|
2760
2849
|
parsePersons,
|
|
2761
2850
|
parseProperties,
|
|
2851
|
+
parseProperty,
|
|
2762
2852
|
parsePropertyValue,
|
|
2763
2853
|
parsePropertyValues,
|
|
2764
2854
|
parseResource,
|
package/dist/index.d.cts
CHANGED
|
@@ -112,7 +112,7 @@ type Link = {
|
|
|
112
112
|
uuid: string;
|
|
113
113
|
publicationDateTime: Date | null;
|
|
114
114
|
type: string | null;
|
|
115
|
-
category:
|
|
115
|
+
category: string | null;
|
|
116
116
|
identification: Identification | null;
|
|
117
117
|
content: string | null;
|
|
118
118
|
href: string | null;
|
|
@@ -360,13 +360,15 @@ type PropertyValue = {
|
|
|
360
360
|
notes: Array<Note>;
|
|
361
361
|
links: Array<Link>;
|
|
362
362
|
};
|
|
363
|
+
type PropertyValueContentType = "string" | "integer" | "decimal" | "boolean" | "date" | "dateTime" | "time" | "coordinate" | "IDREF";
|
|
363
364
|
/**
|
|
364
365
|
* Represents a property value with type information
|
|
365
366
|
*/
|
|
366
|
-
type PropertyValueContent = {
|
|
367
|
-
content: string;
|
|
368
|
-
|
|
369
|
-
|
|
367
|
+
type PropertyValueContent<T extends PropertyValueContentType> = {
|
|
368
|
+
content: T extends "number" ? number : T extends "integer" ? number : T extends "decimal" ? number : T extends "dateTime" ? Date | null : string;
|
|
369
|
+
booleanValue: T extends "boolean" ? boolean : null;
|
|
370
|
+
type: T;
|
|
371
|
+
category: string;
|
|
370
372
|
uuid: string | null;
|
|
371
373
|
publicationDateTime: Date | null;
|
|
372
374
|
};
|
|
@@ -375,7 +377,7 @@ type PropertyValueContent = {
|
|
|
375
377
|
*/
|
|
376
378
|
type Property = {
|
|
377
379
|
label: string;
|
|
378
|
-
values: Array<PropertyValueContent
|
|
380
|
+
values: Array<PropertyValueContent<PropertyValueContentType>>;
|
|
379
381
|
comment: string | null;
|
|
380
382
|
properties: Array<Property>;
|
|
381
383
|
};
|
|
@@ -443,6 +445,10 @@ type WebsiteProperties = {
|
|
|
443
445
|
type: "traditional" | "digital-collection" | "plum" | "cedar" | "elm" | "maple" | "oak" | "palm";
|
|
444
446
|
privacy: "public" | "password" | "private";
|
|
445
447
|
status: "development" | "preview" | "production";
|
|
448
|
+
contact: {
|
|
449
|
+
name: string;
|
|
450
|
+
email: string | null;
|
|
451
|
+
} | null;
|
|
446
452
|
isHeaderDisplayed: boolean;
|
|
447
453
|
headerVariant: "default" | "floating" | "inline";
|
|
448
454
|
headerAlignment: "start" | "center" | "end";
|
|
@@ -988,12 +994,14 @@ type OchreNestedConcept = Omit<OchreConcept, "context" | "availability">;
|
|
|
988
994
|
/**
|
|
989
995
|
* Raw property value structure corresponding to the parsed PropertyValue type
|
|
990
996
|
*/
|
|
991
|
-
type OchrePropertyValueContent =
|
|
997
|
+
type OchrePropertyValueContent = {
|
|
992
998
|
uuid?: string;
|
|
993
999
|
publicationDateTime?: string; // YYYY-MM-DDThh:mm:ssZ
|
|
994
1000
|
type: string;
|
|
995
1001
|
category?: string;
|
|
996
1002
|
slug?: FakeString;
|
|
1003
|
+
booleanValue?: boolean;
|
|
1004
|
+
content?: FakeString | OchreStringItem | Array<OchreStringItem>;
|
|
997
1005
|
};
|
|
998
1006
|
|
|
999
1007
|
/**
|
|
@@ -1020,6 +1028,7 @@ type OchreIdentification = {
|
|
|
1020
1028
|
heightPreview?: number;
|
|
1021
1029
|
height?: number;
|
|
1022
1030
|
width?: number;
|
|
1031
|
+
email?: FakeString;
|
|
1023
1032
|
website?: string;
|
|
1024
1033
|
};
|
|
1025
1034
|
|
|
@@ -1584,7 +1593,7 @@ declare function getPropertyByLabel(properties: Array<Property>, label: string,
|
|
|
1584
1593
|
* }
|
|
1585
1594
|
* ```
|
|
1586
1595
|
*/
|
|
1587
|
-
declare function getPropertyValuesByLabel(properties: Array<Property>, label: string, options?: PropertyOptions): Array<string> | null;
|
|
1596
|
+
declare function getPropertyValuesByLabel(properties: Array<Property>, label: string, options?: PropertyOptions): Array<string | number | boolean | Date | null> | null;
|
|
1588
1597
|
/**
|
|
1589
1598
|
* Gets the first value of a property with the given label
|
|
1590
1599
|
*
|
|
@@ -1601,7 +1610,7 @@ declare function getPropertyValuesByLabel(properties: Array<Property>, label: st
|
|
|
1601
1610
|
* }
|
|
1602
1611
|
* ```
|
|
1603
1612
|
*/
|
|
1604
|
-
declare function getPropertyValueByLabel(properties: Array<Property>, label: string, options?: PropertyOptions): string | null;
|
|
1613
|
+
declare function getPropertyValueByLabel(properties: Array<Property>, label: string, options?: PropertyOptions): string | number | boolean | Date | null;
|
|
1605
1614
|
/**
|
|
1606
1615
|
* Gets all unique property labels from an array of properties
|
|
1607
1616
|
*
|
|
@@ -1639,7 +1648,7 @@ declare function getAllPropertyLabels(properties: Array<Property>, options?: Pro
|
|
|
1639
1648
|
*/
|
|
1640
1649
|
declare function filterProperties(property: Property, filter: {
|
|
1641
1650
|
label: string;
|
|
1642
|
-
value: string;
|
|
1651
|
+
value: string | number | boolean | Date;
|
|
1643
1652
|
}, options?: PropertyOptions): boolean;
|
|
1644
1653
|
|
|
1645
1654
|
/**
|
|
@@ -1756,6 +1765,7 @@ declare function parseObservations(observations: Array<OchreObservation>): Array
|
|
|
1756
1765
|
* @returns Array of parsed Event objects
|
|
1757
1766
|
*/
|
|
1758
1767
|
declare function parseEvents(events: Array<OchreEvent>): Array<Event>;
|
|
1768
|
+
declare function parseProperty<T extends PropertyValueContentType>(property: OchreProperty, type: T, language?: string): Property;
|
|
1759
1769
|
/**
|
|
1760
1770
|
* Parses raw properties into standardized Property objects
|
|
1761
1771
|
*
|
|
@@ -1933,4 +1943,4 @@ declare function parseStringDocumentItem(item: OchreStringRichTextItem, footnote
|
|
|
1933
1943
|
*/
|
|
1934
1944
|
declare function parseStringContent(content: OchreStringContent, language?: string): string;
|
|
1935
1945
|
|
|
1936
|
-
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 PropertyValueContent, 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, fetchBibliography, fetchByUuid, fetchConcept, fetchGallery, fetchPeriod, fetchPropertyValue, fetchResource, fetchSet, fetchSpatialUnit, fetchTree, fetchWebsite, filterProperties, getAllPropertyLabels, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, parseBibliographies, parseBibliography, parseConcept, parseConcepts, parseContext, parseCoordinates, parseDocument, parseEmail, parseEvents, parseFakeString, parseIdentification, parseImage, parseImageMap, parseInterpretations, parseLanguages, parseLicense, parseLink, parseLinks, parseMetadata, parseNotes, parseObservation, parseObservations, parsePeriod, parsePeriods, parsePerson, parsePersons, parseProperties, parsePropertyValue, parsePropertyValues, parseResource, parseResources, parseSet, parseSpatialUnit, parseSpatialUnits, parseStringContent, parseStringDocumentItem, parseStringItem, parseTree, parseWebsite };
|
|
1946
|
+
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 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, fetchBibliography, fetchByUuid, fetchConcept, fetchGallery, fetchPeriod, fetchPropertyValue, fetchResource, fetchSet, fetchSpatialUnit, fetchTree, fetchWebsite, filterProperties, getAllPropertyLabels, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, parseBibliographies, parseBibliography, parseConcept, parseConcepts, parseContext, parseCoordinates, parseDocument, parseEmail, parseEvents, parseFakeString, parseIdentification, parseImage, parseImageMap, parseInterpretations, parseLanguages, parseLicense, parseLink, parseLinks, parseMetadata, parseNotes, parseObservation, parseObservations, parsePeriod, parsePeriods, parsePerson, parsePersons, parseProperties, parseProperty, parsePropertyValue, parsePropertyValues, parseResource, parseResources, parseSet, parseSpatialUnit, parseSpatialUnits, parseStringContent, parseStringDocumentItem, parseStringItem, parseTree, parseWebsite };
|
package/dist/index.d.ts
CHANGED
|
@@ -112,7 +112,7 @@ type Link = {
|
|
|
112
112
|
uuid: string;
|
|
113
113
|
publicationDateTime: Date | null;
|
|
114
114
|
type: string | null;
|
|
115
|
-
category:
|
|
115
|
+
category: string | null;
|
|
116
116
|
identification: Identification | null;
|
|
117
117
|
content: string | null;
|
|
118
118
|
href: string | null;
|
|
@@ -360,13 +360,15 @@ type PropertyValue = {
|
|
|
360
360
|
notes: Array<Note>;
|
|
361
361
|
links: Array<Link>;
|
|
362
362
|
};
|
|
363
|
+
type PropertyValueContentType = "string" | "integer" | "decimal" | "boolean" | "date" | "dateTime" | "time" | "coordinate" | "IDREF";
|
|
363
364
|
/**
|
|
364
365
|
* Represents a property value with type information
|
|
365
366
|
*/
|
|
366
|
-
type PropertyValueContent = {
|
|
367
|
-
content: string;
|
|
368
|
-
|
|
369
|
-
|
|
367
|
+
type PropertyValueContent<T extends PropertyValueContentType> = {
|
|
368
|
+
content: T extends "number" ? number : T extends "integer" ? number : T extends "decimal" ? number : T extends "dateTime" ? Date | null : string;
|
|
369
|
+
booleanValue: T extends "boolean" ? boolean : null;
|
|
370
|
+
type: T;
|
|
371
|
+
category: string;
|
|
370
372
|
uuid: string | null;
|
|
371
373
|
publicationDateTime: Date | null;
|
|
372
374
|
};
|
|
@@ -375,7 +377,7 @@ type PropertyValueContent = {
|
|
|
375
377
|
*/
|
|
376
378
|
type Property = {
|
|
377
379
|
label: string;
|
|
378
|
-
values: Array<PropertyValueContent
|
|
380
|
+
values: Array<PropertyValueContent<PropertyValueContentType>>;
|
|
379
381
|
comment: string | null;
|
|
380
382
|
properties: Array<Property>;
|
|
381
383
|
};
|
|
@@ -443,6 +445,10 @@ type WebsiteProperties = {
|
|
|
443
445
|
type: "traditional" | "digital-collection" | "plum" | "cedar" | "elm" | "maple" | "oak" | "palm";
|
|
444
446
|
privacy: "public" | "password" | "private";
|
|
445
447
|
status: "development" | "preview" | "production";
|
|
448
|
+
contact: {
|
|
449
|
+
name: string;
|
|
450
|
+
email: string | null;
|
|
451
|
+
} | null;
|
|
446
452
|
isHeaderDisplayed: boolean;
|
|
447
453
|
headerVariant: "default" | "floating" | "inline";
|
|
448
454
|
headerAlignment: "start" | "center" | "end";
|
|
@@ -988,12 +994,14 @@ type OchreNestedConcept = Omit<OchreConcept, "context" | "availability">;
|
|
|
988
994
|
/**
|
|
989
995
|
* Raw property value structure corresponding to the parsed PropertyValue type
|
|
990
996
|
*/
|
|
991
|
-
type OchrePropertyValueContent =
|
|
997
|
+
type OchrePropertyValueContent = {
|
|
992
998
|
uuid?: string;
|
|
993
999
|
publicationDateTime?: string; // YYYY-MM-DDThh:mm:ssZ
|
|
994
1000
|
type: string;
|
|
995
1001
|
category?: string;
|
|
996
1002
|
slug?: FakeString;
|
|
1003
|
+
booleanValue?: boolean;
|
|
1004
|
+
content?: FakeString | OchreStringItem | Array<OchreStringItem>;
|
|
997
1005
|
};
|
|
998
1006
|
|
|
999
1007
|
/**
|
|
@@ -1020,6 +1028,7 @@ type OchreIdentification = {
|
|
|
1020
1028
|
heightPreview?: number;
|
|
1021
1029
|
height?: number;
|
|
1022
1030
|
width?: number;
|
|
1031
|
+
email?: FakeString;
|
|
1023
1032
|
website?: string;
|
|
1024
1033
|
};
|
|
1025
1034
|
|
|
@@ -1584,7 +1593,7 @@ declare function getPropertyByLabel(properties: Array<Property>, label: string,
|
|
|
1584
1593
|
* }
|
|
1585
1594
|
* ```
|
|
1586
1595
|
*/
|
|
1587
|
-
declare function getPropertyValuesByLabel(properties: Array<Property>, label: string, options?: PropertyOptions): Array<string> | null;
|
|
1596
|
+
declare function getPropertyValuesByLabel(properties: Array<Property>, label: string, options?: PropertyOptions): Array<string | number | boolean | Date | null> | null;
|
|
1588
1597
|
/**
|
|
1589
1598
|
* Gets the first value of a property with the given label
|
|
1590
1599
|
*
|
|
@@ -1601,7 +1610,7 @@ declare function getPropertyValuesByLabel(properties: Array<Property>, label: st
|
|
|
1601
1610
|
* }
|
|
1602
1611
|
* ```
|
|
1603
1612
|
*/
|
|
1604
|
-
declare function getPropertyValueByLabel(properties: Array<Property>, label: string, options?: PropertyOptions): string | null;
|
|
1613
|
+
declare function getPropertyValueByLabel(properties: Array<Property>, label: string, options?: PropertyOptions): string | number | boolean | Date | null;
|
|
1605
1614
|
/**
|
|
1606
1615
|
* Gets all unique property labels from an array of properties
|
|
1607
1616
|
*
|
|
@@ -1639,7 +1648,7 @@ declare function getAllPropertyLabels(properties: Array<Property>, options?: Pro
|
|
|
1639
1648
|
*/
|
|
1640
1649
|
declare function filterProperties(property: Property, filter: {
|
|
1641
1650
|
label: string;
|
|
1642
|
-
value: string;
|
|
1651
|
+
value: string | number | boolean | Date;
|
|
1643
1652
|
}, options?: PropertyOptions): boolean;
|
|
1644
1653
|
|
|
1645
1654
|
/**
|
|
@@ -1756,6 +1765,7 @@ declare function parseObservations(observations: Array<OchreObservation>): Array
|
|
|
1756
1765
|
* @returns Array of parsed Event objects
|
|
1757
1766
|
*/
|
|
1758
1767
|
declare function parseEvents(events: Array<OchreEvent>): Array<Event>;
|
|
1768
|
+
declare function parseProperty<T extends PropertyValueContentType>(property: OchreProperty, type: T, language?: string): Property;
|
|
1759
1769
|
/**
|
|
1760
1770
|
* Parses raw properties into standardized Property objects
|
|
1761
1771
|
*
|
|
@@ -1933,4 +1943,4 @@ declare function parseStringDocumentItem(item: OchreStringRichTextItem, footnote
|
|
|
1933
1943
|
*/
|
|
1934
1944
|
declare function parseStringContent(content: OchreStringContent, language?: string): string;
|
|
1935
1945
|
|
|
1936
|
-
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 PropertyValueContent, 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, fetchBibliography, fetchByUuid, fetchConcept, fetchGallery, fetchPeriod, fetchPropertyValue, fetchResource, fetchSet, fetchSpatialUnit, fetchTree, fetchWebsite, filterProperties, getAllPropertyLabels, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, parseBibliographies, parseBibliography, parseConcept, parseConcepts, parseContext, parseCoordinates, parseDocument, parseEmail, parseEvents, parseFakeString, parseIdentification, parseImage, parseImageMap, parseInterpretations, parseLanguages, parseLicense, parseLink, parseLinks, parseMetadata, parseNotes, parseObservation, parseObservations, parsePeriod, parsePeriods, parsePerson, parsePersons, parseProperties, parsePropertyValue, parsePropertyValues, parseResource, parseResources, parseSet, parseSpatialUnit, parseSpatialUnits, parseStringContent, parseStringDocumentItem, parseStringItem, parseTree, parseWebsite };
|
|
1946
|
+
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 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, fetchBibliography, fetchByUuid, fetchConcept, fetchGallery, fetchPeriod, fetchPropertyValue, fetchResource, fetchSet, fetchSpatialUnit, fetchTree, fetchWebsite, filterProperties, getAllPropertyLabels, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, parseBibliographies, parseBibliography, parseConcept, parseConcepts, parseContext, parseCoordinates, parseDocument, parseEmail, parseEvents, parseFakeString, parseIdentification, parseImage, parseImageMap, parseInterpretations, parseLanguages, parseLicense, parseLink, parseLinks, parseMetadata, parseNotes, parseObservation, parseObservations, parsePeriod, parsePeriods, parsePerson, parsePersons, parseProperties, parseProperty, parsePropertyValue, parsePropertyValues, parseResource, parseResources, parseSet, parseSpatialUnit, parseSpatialUnits, parseStringContent, parseStringDocumentItem, parseStringItem, parseTree, parseWebsite };
|
package/dist/index.js
CHANGED
|
@@ -444,9 +444,36 @@ function filterProperties(property, filter, options = DEFAULT_OPTIONS) {
|
|
|
444
444
|
const { searchNestedProperties } = options;
|
|
445
445
|
const isAllFields = filter.label.toLocaleLowerCase("en-US") === "all fields";
|
|
446
446
|
if (isAllFields || property.label.toLocaleLowerCase("en-US") === filter.label.toLocaleLowerCase("en-US")) {
|
|
447
|
-
let isFound = property.values.some(
|
|
448
|
-
(value
|
|
449
|
-
|
|
447
|
+
let isFound = property.values.some((value) => {
|
|
448
|
+
if (value.content === null) {
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
if (typeof value.content === "string") {
|
|
452
|
+
if (typeof filter.value !== "string") {
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
return value.content.toLocaleLowerCase("en-US").includes(filter.value.toLocaleLowerCase("en-US"));
|
|
456
|
+
}
|
|
457
|
+
if (typeof value.content === "number") {
|
|
458
|
+
if (typeof filter.value !== "number") {
|
|
459
|
+
return false;
|
|
460
|
+
}
|
|
461
|
+
return value.content === filter.value;
|
|
462
|
+
}
|
|
463
|
+
if (typeof value.content === "boolean") {
|
|
464
|
+
if (typeof filter.value !== "boolean") {
|
|
465
|
+
return false;
|
|
466
|
+
}
|
|
467
|
+
return value.booleanValue === filter.value;
|
|
468
|
+
}
|
|
469
|
+
if (value.content instanceof Date) {
|
|
470
|
+
if (!(filter.value instanceof Date)) {
|
|
471
|
+
return false;
|
|
472
|
+
}
|
|
473
|
+
return value.content.getTime() === filter.value.getTime();
|
|
474
|
+
}
|
|
475
|
+
return false;
|
|
476
|
+
});
|
|
450
477
|
if (!isFound && searchNestedProperties) {
|
|
451
478
|
isFound = property.properties.some(
|
|
452
479
|
(property2) => filterProperties(property2, filter, { searchNestedProperties: true })
|
|
@@ -794,33 +821,71 @@ function parseEvents(events) {
|
|
|
794
821
|
}
|
|
795
822
|
return returnEvents;
|
|
796
823
|
}
|
|
797
|
-
function
|
|
798
|
-
const
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
} : {
|
|
809
|
-
content: parseFakeString(value),
|
|
810
|
-
type: "string",
|
|
824
|
+
function parseProperty(property, type, language = "eng") {
|
|
825
|
+
const valuesToParse = "value" in property && property.value ? Array.isArray(property.value) ? property.value : [property.value] : [];
|
|
826
|
+
const values = valuesToParse.map((value) => {
|
|
827
|
+
let content = null;
|
|
828
|
+
let booleanValue = null;
|
|
829
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
830
|
+
content = parseFakeString(value);
|
|
831
|
+
const returnValue = {
|
|
832
|
+
content,
|
|
833
|
+
booleanValue,
|
|
834
|
+
type,
|
|
811
835
|
category: "value",
|
|
812
836
|
uuid: null,
|
|
813
837
|
publicationDateTime: null
|
|
838
|
+
};
|
|
839
|
+
return returnValue;
|
|
840
|
+
} else {
|
|
841
|
+
switch (type) {
|
|
842
|
+
case "integer":
|
|
843
|
+
case "decimal": {
|
|
844
|
+
content = Number(value.content);
|
|
845
|
+
break;
|
|
846
|
+
}
|
|
847
|
+
case "dateTime": {
|
|
848
|
+
content = value.content ? typeof value.content === "string" ? new Date(value.content) : new Date(parseStringContent({ content: value.content })) : null;
|
|
849
|
+
break;
|
|
850
|
+
}
|
|
851
|
+
default: {
|
|
852
|
+
if ("slug" in value && value.slug != null) {
|
|
853
|
+
content = parseFakeString(value.slug);
|
|
854
|
+
} else if (value.content != null) {
|
|
855
|
+
content = parseStringContent({ content: value.content });
|
|
856
|
+
}
|
|
857
|
+
if (type === "boolean") {
|
|
858
|
+
booleanValue = value.booleanValue ?? null;
|
|
859
|
+
}
|
|
860
|
+
break;
|
|
861
|
+
}
|
|
814
862
|
}
|
|
863
|
+
const returnValue = {
|
|
864
|
+
content,
|
|
865
|
+
booleanValue,
|
|
866
|
+
type,
|
|
867
|
+
category: value.category ?? "value",
|
|
868
|
+
uuid: value.uuid ?? null,
|
|
869
|
+
publicationDateTime: value.publicationDateTime != null ? new Date(value.publicationDateTime) : null
|
|
870
|
+
};
|
|
871
|
+
return returnValue;
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
return {
|
|
875
|
+
label: parseStringContent(property.label, language).replace(/\s*\.{3}$/, "").trim(),
|
|
876
|
+
values,
|
|
877
|
+
comment: property.comment != null ? parseFakeString(property.comment) : null,
|
|
878
|
+
properties: property.property ? parseProperties(
|
|
879
|
+
Array.isArray(property.property) ? property.property : [property.property]
|
|
880
|
+
) : []
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
function parseProperties(properties, language = "eng") {
|
|
884
|
+
const returnProperties = [];
|
|
885
|
+
for (const property of properties) {
|
|
886
|
+
returnProperties.push(
|
|
887
|
+
parseProperty(property, "string", language)
|
|
815
888
|
);
|
|
816
|
-
returnProperties.push({
|
|
817
|
-
label: parseStringContent(property.label, language).replace(/\s*\.{3}$/, "").trim(),
|
|
818
|
-
values,
|
|
819
|
-
comment: property.comment != null ? parseFakeString(property.comment) : null,
|
|
820
|
-
properties: property.property ? parseProperties(
|
|
821
|
-
Array.isArray(property.property) ? property.property : [property.property]
|
|
822
|
-
) : []
|
|
823
|
-
});
|
|
824
889
|
}
|
|
825
890
|
return returnProperties;
|
|
826
891
|
}
|
|
@@ -1564,7 +1629,11 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1564
1629
|
"width"
|
|
1565
1630
|
);
|
|
1566
1631
|
if (widthProperty !== null) {
|
|
1567
|
-
|
|
1632
|
+
if (typeof widthProperty === "number") {
|
|
1633
|
+
width = widthProperty;
|
|
1634
|
+
} else if (typeof widthProperty === "string") {
|
|
1635
|
+
width = Number.parseFloat(widthProperty);
|
|
1636
|
+
}
|
|
1568
1637
|
}
|
|
1569
1638
|
let height = null;
|
|
1570
1639
|
const heightProperty = getPropertyValueByLabel(
|
|
@@ -1572,7 +1641,11 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1572
1641
|
"height"
|
|
1573
1642
|
);
|
|
1574
1643
|
if (heightProperty !== null) {
|
|
1575
|
-
|
|
1644
|
+
if (typeof heightProperty === "number") {
|
|
1645
|
+
height = heightProperty;
|
|
1646
|
+
} else if (typeof heightProperty === "string") {
|
|
1647
|
+
height = Number.parseFloat(heightProperty);
|
|
1648
|
+
}
|
|
1576
1649
|
}
|
|
1577
1650
|
let isFullWidth = true;
|
|
1578
1651
|
const isFullWidthProperty = getPropertyValueByLabel(
|
|
@@ -1634,7 +1707,11 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1634
1707
|
"seconds-per-image"
|
|
1635
1708
|
);
|
|
1636
1709
|
if (secondsPerImageProperty !== null) {
|
|
1637
|
-
|
|
1710
|
+
if (typeof secondsPerImageProperty === "number") {
|
|
1711
|
+
secondsPerImage = secondsPerImageProperty;
|
|
1712
|
+
} else if (typeof secondsPerImageProperty === "string") {
|
|
1713
|
+
secondsPerImage = Number.parseFloat(secondsPerImageProperty);
|
|
1714
|
+
}
|
|
1638
1715
|
}
|
|
1639
1716
|
}
|
|
1640
1717
|
carouselOptions = {
|
|
@@ -1889,7 +1966,7 @@ async function parseWebpage(webpageResource) {
|
|
|
1889
1966
|
resourceProperties,
|
|
1890
1967
|
"presentation"
|
|
1891
1968
|
);
|
|
1892
|
-
if (
|
|
1969
|
+
if (resourceType == null) {
|
|
1893
1970
|
continue;
|
|
1894
1971
|
}
|
|
1895
1972
|
switch (resourceType) {
|
|
@@ -2070,7 +2147,7 @@ async function parseBlock(blockResource) {
|
|
|
2070
2147
|
resourceProperties,
|
|
2071
2148
|
"presentation"
|
|
2072
2149
|
);
|
|
2073
|
-
if (
|
|
2150
|
+
if (resourceType == null) {
|
|
2074
2151
|
continue;
|
|
2075
2152
|
}
|
|
2076
2153
|
switch (resourceType) {
|
|
@@ -2143,6 +2220,16 @@ function parseWebsiteProperties(properties) {
|
|
|
2143
2220
|
if (!result.success) {
|
|
2144
2221
|
throw new Error(`Invalid website properties: ${result.error.message}`);
|
|
2145
2222
|
}
|
|
2223
|
+
let contact = null;
|
|
2224
|
+
const contactProperty = websiteProperties.find(
|
|
2225
|
+
(property) => property.label === "contact"
|
|
2226
|
+
);
|
|
2227
|
+
if (contactProperty) {
|
|
2228
|
+
const [name, email] = (contactProperty.values[0]?.content).split(
|
|
2229
|
+
";"
|
|
2230
|
+
);
|
|
2231
|
+
contact = { name, email: email ?? null };
|
|
2232
|
+
}
|
|
2146
2233
|
const logoUuid = websiteProperties.find((property) => property.label === "logo")?.values[0]?.uuid ?? null;
|
|
2147
2234
|
let isHeaderDisplayed = true;
|
|
2148
2235
|
let headerVariant = "default";
|
|
@@ -2209,6 +2296,7 @@ function parseWebsiteProperties(properties) {
|
|
|
2209
2296
|
type: validatedType,
|
|
2210
2297
|
privacy: validatedPrivacy,
|
|
2211
2298
|
status: validatedStatus,
|
|
2299
|
+
contact,
|
|
2212
2300
|
isHeaderDisplayed,
|
|
2213
2301
|
headerVariant,
|
|
2214
2302
|
headerAlignment,
|
|
@@ -2678,6 +2766,7 @@ export {
|
|
|
2678
2766
|
parsePerson,
|
|
2679
2767
|
parsePersons,
|
|
2680
2768
|
parseProperties,
|
|
2769
|
+
parseProperty,
|
|
2681
2770
|
parsePropertyValue,
|
|
2682
2771
|
parsePropertyValues,
|
|
2683
2772
|
parseResource,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitalculture/ochre-sdk",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.19",
|
|
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",
|
|
@@ -41,12 +41,12 @@
|
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"iso-639-3": "^3.0.1",
|
|
44
|
-
"zod": "^3.24.
|
|
44
|
+
"zod": "^3.24.3"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@antfu/eslint-config": "^4.12.0",
|
|
48
48
|
"@arethetypeswrong/cli": "^0.17.4",
|
|
49
|
-
"@changesets/cli": "^2.29.
|
|
49
|
+
"@changesets/cli": "^2.29.2",
|
|
50
50
|
"@total-typescript/ts-reset": "^0.6.1",
|
|
51
51
|
"@types/node": "^22.14.1",
|
|
52
52
|
"eslint": "^9.24.0",
|