ochre-sdk 1.0.18 → 1.0.20

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.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MultilingualOptions, MultilingualString, MultilingualStringEntries, MultilingualStringEntry, MultilingualStringInput, MultilingualStringJSON, MultilingualStringObject, MultilingualStringText } from "./parsers/multilingual.mjs";
2
- import { AccordionWebBlock, ContextTree, ContextTreeFilterLevel, ContextTreeLevel, ContextTreeLevelItem, Scope, Style, StylesheetCategory, StylesheetItem, WebBlock, WebBlockByLayout, WebBlockLayout, WebElement, WebElementComponent, WebElementComponentName, WebElementComponentOf, WebElementOf, WebImage, WebTitle, Webpage, Website, WebsiteMetadata, WebsitePropertyQuery, WebsitePropertyQueryNode, WebsiteSegment, WebsiteType } from "./types/website.mjs";
2
+ import { AccordionWebBlock, ContextTree, ContextTreeFilterLevel, ContextTreeLevel, ContextTreeLevelItem, Scope, Style, StylesheetCategory, StylesheetItem, WebAccordionItem, WebBlock, WebBlockByLayout, WebBlockItem, WebBlockLayout, WebElement, WebElementComponent, WebElementComponentName, WebElementComponentOf, WebElementOf, WebImage, WebTitle, Webpage, Website, WebsiteMetadata, WebsitePropertyQuery, WebsitePropertyQueryNode, WebsiteSegment, WebsiteType } from "./types/website.mjs";
3
3
  import { AnyBibliography, AnyConcept, AnyItem, AnyPeriod, AnyPerson, AnyPropertyValue, AnyPropertyVariable, AnyResource, AnySet, AnySpatialUnit, AnyText, AnyTree, BaseItem, BaseItemLink, BelongsTo, Bibliography, BibliographyEntryInfo, BibliographyItemLink, BibliographySourceDocument, Concept, ConceptItemLink, ContainedItemCategory, ContainedItemCategoryFromOption, ContainedItemCategoryOption, Context, ContextItem, ContextItemCategory, ContextNode, Coordinates, CoordinatesSource, DictionaryUnitItemLink, EmbeddedBibliography, EmbeddedConcept, EmbeddedItem, EmbeddedPeriod, EmbeddedPerson, EmbeddedPropertyValue, EmbeddedPropertyVariable, EmbeddedResource, EmbeddedSet, EmbeddedSpatialUnit, EmbeddedText, EmbeddedTree, Event, Gallery, Heading, HeadingItemCategory, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, ItemCategory, ItemContainerCategory, ItemLink, ItemLinkCategory, ItemLinks, ItemPayloadKind, ItemProperty, ItemWithoutEmbeddedItems, LanguageCodes, License, Metadata, Note, Observation, Period, PeriodItemLink, Person, PersonItemLink, Property, PropertyLike, PropertyValue, PropertyValueContent, PropertyValueDataType, PropertyValueItemLink, PropertyValueQueryItem, PropertyVariable, PropertyVariableItemLink, Query, QueryGroup, QueryLeaf, QueryablePropertyValueDataType, RecursiveItemCategory, Resource, ResourceItemLink, Section, Set, SetAttributeValueQueryItem, SetBibliography, SetConcept, SetItem, SetItemCategory, SetItemLink, SetItemProperty, SetItemSimplifiedProperty, SetItemsSort, SetItemsSortDirection, SetPeriod, SetResource, SetSpatialUnit, SetTree, SimplifiedProperty, SpatialUnit, SpatialUnitItemLink, Text, TextItemLink, TopLevelItem, Tree, TreeItemCategory, TreeItemLink } from "./types/index.mjs";
4
4
  import { fetchGallery } from "./fetchers/gallery.mjs";
5
5
  import { fetchItemLinks } from "./fetchers/item-links.mjs";
@@ -10,4 +10,4 @@ import { fetchWebsiteMetadata } from "./fetchers/website-metadata.mjs";
10
10
  import { fetchWebsite } from "./fetchers/website.mjs";
11
11
  import { PropertyOptions, filterProperties, getLeafPropertyValues, getPropertyByVariableLabel, getPropertyByVariableLabelAndValue, getPropertyByVariableLabelAndValueContent, getPropertyByVariableLabelAndValueContents, getPropertyByVariableLabelAndValues, getPropertyByVariableUuid, getPropertyValueByVariableLabel, getPropertyValueByVariableUuid, getPropertyValueContentByVariableLabel, getPropertyValueContentByVariableUuid, getPropertyValueContentsByVariableUuid, getPropertyValuesByVariableLabel, getPropertyValuesByVariableUuid, getUniqueProperties, getUniquePropertyVariableLabels } from "./getters.mjs";
12
12
  import { DEFAULT_PAGE_SIZE, flattenItemProperties } from "./helpers.mjs";
13
- export { type AccordionWebBlock, type AnyBibliography, type AnyConcept, type AnyItem, type AnyPeriod, type AnyPerson, type AnyPropertyValue, type AnyPropertyVariable, type AnyResource, type AnySet, type AnySpatialUnit, type AnyText, type AnyTree, type BaseItem, type BaseItemLink, type BelongsTo, type Bibliography, type BibliographyEntryInfo, type BibliographyItemLink, type BibliographySourceDocument, type Concept, type ConceptItemLink, type ContainedItemCategory, type ContainedItemCategoryFromOption, type ContainedItemCategoryOption, type Context, type ContextItem, type ContextItemCategory, type ContextNode, type ContextTree, type ContextTreeFilterLevel, type ContextTreeLevel, type ContextTreeLevelItem, type Coordinates, type CoordinatesSource, DEFAULT_PAGE_SIZE, type DictionaryUnitItemLink, type EmbeddedBibliography, type EmbeddedConcept, type EmbeddedItem, type EmbeddedPeriod, type EmbeddedPerson, type EmbeddedPropertyValue, type EmbeddedPropertyVariable, type EmbeddedResource, type EmbeddedSet, type EmbeddedSpatialUnit, type EmbeddedText, type EmbeddedTree, type Event, type Gallery, type Heading, type HeadingItemCategory, type Identification, type Image, type ImageMap, type ImageMapArea, type Interpretation, type Item, type ItemCategory, type ItemContainerCategory, type ItemLink, type ItemLinkCategory, type ItemLinks, type ItemPayloadKind, type ItemProperty, type ItemWithoutEmbeddedItems, type LanguageCodes, type License, type Metadata, type MultilingualOptions, MultilingualString, type MultilingualStringEntries, type MultilingualStringEntry, type MultilingualStringInput, type MultilingualStringJSON, type MultilingualStringObject, type MultilingualStringText, type Note, type Observation, type Period, type PeriodItemLink, type Person, type PersonItemLink, type Property, type PropertyLike, PropertyOptions, type PropertyValue, type PropertyValueContent, type PropertyValueDataType, type PropertyValueItemLink, type PropertyValueQueryItem, type PropertyVariable, type PropertyVariableItemLink, type Query, type QueryGroup, type QueryLeaf, type QueryablePropertyValueDataType, type RecursiveItemCategory, type Resource, type ResourceItemLink, type Scope, type Section, type Set, type SetAttributeValueQueryItem, type SetBibliography, type SetConcept, type SetItem, type SetItemCategory, type SetItemLink, type SetItemProperty, type SetItemSimplifiedProperty, type SetItemsSort, type SetItemsSortDirection, type SetPeriod, type SetResource, type SetSpatialUnit, type SetTree, type SimplifiedProperty, type SpatialUnit, type SpatialUnitItemLink, type Style, type StylesheetCategory, type StylesheetItem, type Text, type TextItemLink, type TopLevelItem, type Tree, type TreeItemCategory, type TreeItemLink, type WebBlock, type WebBlockByLayout, type WebBlockLayout, type WebElement, type WebElementComponent, type WebElementComponentName, type WebElementComponentOf, type WebElementOf, type WebImage, type WebTitle, type Webpage, type Website, type WebsiteMetadata, type WebsitePropertyQuery, type WebsitePropertyQueryNode, type WebsiteSegment, type WebsiteType, defineLanguages, fetchGallery, fetchItem, fetchItemLinks, fetchSetItems, fetchSetPropertyValues, fetchWebsite, fetchWebsiteMetadata, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByVariableLabel, getPropertyByVariableLabelAndValue, getPropertyByVariableLabelAndValueContent, getPropertyByVariableLabelAndValueContents, getPropertyByVariableLabelAndValues, getPropertyByVariableUuid, getPropertyValueByVariableLabel, getPropertyValueByVariableUuid, getPropertyValueContentByVariableLabel, getPropertyValueContentByVariableUuid, getPropertyValueContentsByVariableUuid, getPropertyValuesByVariableLabel, getPropertyValuesByVariableUuid, getUniqueProperties, getUniquePropertyVariableLabels, withLanguages };
13
+ export { type AccordionWebBlock, type AnyBibliography, type AnyConcept, type AnyItem, type AnyPeriod, type AnyPerson, type AnyPropertyValue, type AnyPropertyVariable, type AnyResource, type AnySet, type AnySpatialUnit, type AnyText, type AnyTree, type BaseItem, type BaseItemLink, type BelongsTo, type Bibliography, type BibliographyEntryInfo, type BibliographyItemLink, type BibliographySourceDocument, type Concept, type ConceptItemLink, type ContainedItemCategory, type ContainedItemCategoryFromOption, type ContainedItemCategoryOption, type Context, type ContextItem, type ContextItemCategory, type ContextNode, type ContextTree, type ContextTreeFilterLevel, type ContextTreeLevel, type ContextTreeLevelItem, type Coordinates, type CoordinatesSource, DEFAULT_PAGE_SIZE, type DictionaryUnitItemLink, type EmbeddedBibliography, type EmbeddedConcept, type EmbeddedItem, type EmbeddedPeriod, type EmbeddedPerson, type EmbeddedPropertyValue, type EmbeddedPropertyVariable, type EmbeddedResource, type EmbeddedSet, type EmbeddedSpatialUnit, type EmbeddedText, type EmbeddedTree, type Event, type Gallery, type Heading, type HeadingItemCategory, type Identification, type Image, type ImageMap, type ImageMapArea, type Interpretation, type Item, type ItemCategory, type ItemContainerCategory, type ItemLink, type ItemLinkCategory, type ItemLinks, type ItemPayloadKind, type ItemProperty, type ItemWithoutEmbeddedItems, type LanguageCodes, type License, type Metadata, type MultilingualOptions, MultilingualString, type MultilingualStringEntries, type MultilingualStringEntry, type MultilingualStringInput, type MultilingualStringJSON, type MultilingualStringObject, type MultilingualStringText, type Note, type Observation, type Period, type PeriodItemLink, type Person, type PersonItemLink, type Property, type PropertyLike, PropertyOptions, type PropertyValue, type PropertyValueContent, type PropertyValueDataType, type PropertyValueItemLink, type PropertyValueQueryItem, type PropertyVariable, type PropertyVariableItemLink, type Query, type QueryGroup, type QueryLeaf, type QueryablePropertyValueDataType, type RecursiveItemCategory, type Resource, type ResourceItemLink, type Scope, type Section, type Set, type SetAttributeValueQueryItem, type SetBibliography, type SetConcept, type SetItem, type SetItemCategory, type SetItemLink, type SetItemProperty, type SetItemSimplifiedProperty, type SetItemsSort, type SetItemsSortDirection, type SetPeriod, type SetResource, type SetSpatialUnit, type SetTree, type SimplifiedProperty, type SpatialUnit, type SpatialUnitItemLink, type Style, type StylesheetCategory, type StylesheetItem, type Text, type TextItemLink, type TopLevelItem, type Tree, type TreeItemCategory, type TreeItemLink, type WebAccordionItem, type WebBlock, type WebBlockByLayout, type WebBlockItem, type WebBlockLayout, type WebElement, type WebElementComponent, type WebElementComponentName, type WebElementComponentOf, type WebElementOf, type WebImage, type WebTitle, type Webpage, type Website, type WebsiteMetadata, type WebsitePropertyQuery, type WebsitePropertyQueryNode, type WebsiteSegment, type WebsiteType, defineLanguages, fetchGallery, fetchItem, fetchItemLinks, fetchSetItems, fetchSetPropertyValues, fetchWebsite, fetchWebsiteMetadata, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByVariableLabel, getPropertyByVariableLabelAndValue, getPropertyByVariableLabelAndValueContent, getPropertyByVariableLabelAndValueContents, getPropertyByVariableLabelAndValues, getPropertyByVariableUuid, getPropertyValueByVariableLabel, getPropertyValueByVariableUuid, getPropertyValueContentByVariableLabel, getPropertyValueContentByVariableUuid, getPropertyValueContentsByVariableUuid, getPropertyValuesByVariableLabel, getPropertyValuesByVariableUuid, getUniqueProperties, getUniquePropertyVariableLabels, withLanguages };
@@ -395,7 +395,7 @@ function parseImageMapArea(area) {
395
395
  const shape = area.shape === "rect" ? "rectangle" : area.shape === "circle" ? "circle" : "polygon";
396
396
  return {
397
397
  uuid: area.uuid,
398
- publicationDateTime: area.publicationDateTime,
398
+ publicationDateTime: area.publicationDateTime ?? null,
399
399
  type: area.type,
400
400
  title: area.title,
401
401
  slug: area.slug ?? null,
@@ -889,15 +889,8 @@ function parseSidebar(resources, options) {
889
889
  };
890
890
  return returnSidebar;
891
891
  }
892
- /**
893
- * Parses raw text element data for accordion layout with items support
894
- *
895
- * @param elementResource - Raw element resource data in OCHRE format
896
- * @returns Parsed text WebElement with items array
897
- */
898
- function parseWebElementForAccordion(elementResource, options) {
899
- const textElement = parseWebElement(elementResource, options);
900
- const childResources = elementResource.resource ? normalizeWebsiteResources(elementResource.resource) : [];
892
+ function parseWebAccordionItem(elementResource, childResources, options) {
893
+ const trigger = parseWebElement(elementResource, options);
901
894
  const items = [];
902
895
  for (const resource of childResources) {
903
896
  const resourceType = websitePresentationReader(resource.properties ? parseSimplifiedProperties(resource.properties, options) : []).value("presentation");
@@ -916,7 +909,9 @@ function parseWebElementForAccordion(elementResource, options) {
916
909
  }
917
910
  }
918
911
  return {
919
- ...textElement,
912
+ uuid: trigger.uuid,
913
+ type: "accordion-item",
914
+ trigger,
920
915
  items
921
916
  };
922
917
  }
@@ -1000,38 +995,33 @@ function parseWebBlock(blockResource, options) {
1000
995
  }
1001
996
  }
1002
997
  const blockResources = blockResource.resource ? normalizeWebsiteResources(blockResource.resource) : [];
1003
- if (returnBlock.properties.default.layout === "accordion") {
1004
- const accordionItems = [];
1005
- for (const resource of blockResources) {
1006
- const resourceReader = websitePresentationReader(resource.properties ? parseSimplifiedProperties(resource.properties, options) : []);
1007
- const resourceType = resourceReader.value("presentation");
1008
- if (resourceType !== "element") throw new Error(`Accordion only accepts elements, but got “${resourceType}” (${formatXMLWebsiteResourceMetadata(resource)})`, { cause: resource });
1009
- const componentType = resourceReader.nestedByValue("presentation", "element").value("component");
1010
- if (componentType !== "text") throw new Error(`Accordion only accepts text components, but got “${componentType}” (${formatXMLWebsiteResourceMetadata(resource)})`, { cause: resource });
1011
- const element = parseWebElementForAccordion(resource, options);
1012
- accordionItems.push(element);
1013
- }
1014
- returnBlock.items = accordionItems;
1015
- } else {
1016
- const blockItems = [];
1017
- for (const resource of blockResources) {
1018
- const resourceType = websitePresentationReader(resource.properties ? parseSimplifiedProperties(resource.properties, options) : []).value("presentation");
1019
- if (resourceType === null) continue;
1020
- switch (resourceType) {
1021
- case "element": {
1022
- const element = parseWebElement(resource, options);
1023
- blockItems.push(element);
1024
- break;
1025
- }
1026
- case "block": {
1027
- const block = parseWebBlock(resource, options);
1028
- if (block) blockItems.push(block);
998
+ const supportsAccordionItems = returnBlock.properties.default.layout === "accordion" || returnBlock.properties.tablet?.layout === "accordion" || returnBlock.properties.mobile?.layout === "accordion";
999
+ const blockItems = [];
1000
+ for (const resource of blockResources) {
1001
+ const resourceReader = websitePresentationReader(resource.properties ? parseSimplifiedProperties(resource.properties, options) : []);
1002
+ const resourceType = resourceReader.value("presentation");
1003
+ if (resourceType === null) continue;
1004
+ switch (resourceType) {
1005
+ case "element": {
1006
+ const childResources = resource.resource ? normalizeWebsiteResources(resource.resource) : [];
1007
+ const componentType = resourceReader.nestedByValue("presentation", "element").value("component");
1008
+ if (supportsAccordionItems && componentType === "text" && childResources.length > 0) {
1009
+ const item = parseWebAccordionItem(resource, childResources, options);
1010
+ blockItems.push(item);
1029
1011
  break;
1030
1012
  }
1013
+ const element = parseWebElement(resource, options);
1014
+ blockItems.push(element);
1015
+ break;
1016
+ }
1017
+ case "block": {
1018
+ const block = parseWebBlock(resource, options);
1019
+ if (block) blockItems.push(block);
1020
+ break;
1031
1021
  }
1032
1022
  }
1033
- returnBlock.items = blockItems;
1034
1023
  }
1024
+ returnBlock.items = blockItems;
1035
1025
  returnBlock.cssStyles = parseResponsiveCssStyles(blockProperties);
1036
1026
  return returnBlock;
1037
1027
  }
@@ -458,6 +458,13 @@ type Style = {
458
458
  value: string;
459
459
  };
460
460
  type WebBlockLayout = "vertical" | "horizontal" | "grid" | "vertical-flex" | "horizontal-flex" | "accordion";
461
+ type WebBlockItem<T extends LanguageCodes = LanguageCodes> = WebElement<T> | WebBlock<T>;
462
+ type WebAccordionItem<T extends LanguageCodes = LanguageCodes> = {
463
+ uuid: string;
464
+ type: "accordion-item";
465
+ trigger: WebElementOf<"text", T>;
466
+ items: Array<WebBlockItem<T>>;
467
+ };
461
468
  /**
462
469
  * Represents a block of vertical or horizontal content alignment
463
470
  */
@@ -465,11 +472,7 @@ type WebBlock<T extends LanguageCodes = LanguageCodes, U extends WebBlockLayout
465
472
  uuid: string;
466
473
  type: "block";
467
474
  title: WebTitle<T>;
468
- items: U extends "accordion" ? Array<Extract<WebElement<T>, {
469
- component: "text";
470
- }> & {
471
- items: Array<WebElement<T> | WebBlock<T>>;
472
- }> : Array<WebElement<T> | WebBlock<T>>;
475
+ items: U extends "accordion" ? Array<WebAccordionItem<T> | WebBlockItem<T>> : Array<WebBlockItem<T>>;
473
476
  properties: {
474
477
  default: {
475
478
  layout: U;
@@ -514,4 +517,4 @@ type WebsiteMetadata<T extends LanguageCodes = LanguageCodes> = {
514
517
  };
515
518
  };
516
519
  //#endregion
517
- export { AccordionWebBlock, ContextTree, ContextTreeFilterLevel, ContextTreeLevel, ContextTreeLevelItem, Scope, Style, StylesheetCategory, StylesheetItem, WebBlock, WebBlockByLayout, WebBlockLayout, WebElement, WebElementComponent, WebElementComponentName, WebElementComponentOf, WebElementOf, WebImage, WebTitle, Webpage, Website, WebsiteMetadata, WebsitePropertyQuery, WebsitePropertyQueryNode, WebsiteSegment, WebsiteType };
520
+ export { AccordionWebBlock, ContextTree, ContextTreeFilterLevel, ContextTreeLevel, ContextTreeLevelItem, Scope, Style, StylesheetCategory, StylesheetItem, WebAccordionItem, WebBlock, WebBlockByLayout, WebBlockItem, WebBlockLayout, WebElement, WebElementComponent, WebElementComponentName, WebElementComponentOf, WebElementOf, WebImage, WebTitle, Webpage, Website, WebsiteMetadata, WebsitePropertyQuery, WebsitePropertyQueryNode, WebsiteSegment, WebsiteType };
@@ -201,9 +201,9 @@ const XMLImage = v.object({
201
201
  fileSize: XMLOptionalNumber,
202
202
  payload: v.optional(v.string("XMLImage: payload is string and optional"))
203
203
  }, "XMLImage: Shape error");
204
- const XMLImageMapArea = v.object({
204
+ const XMLImageMapArea = v.pipe(v.object({
205
205
  uuid: v.pipe(v.string("XMLImageMapArea: uuid is string and required"), v.check(isPseudoUuid, "XMLImageMapArea: uuid is not a valid pseudo-UUID")),
206
- publicationDateTime: customDateTime("XMLImageMapArea: publicationDateTime is not a valid datetime"),
206
+ publicationDateTime: v.optional(customDateTime("XMLImageMapArea: publicationDateTime is not a valid datetime")),
207
207
  type: v.string("XMLImageMapArea: type is string and required"),
208
208
  title: v.string("XMLImageMapArea: title is string and required"),
209
209
  slug: v.optional(v.string("XMLImageMapArea: slug is string and optional")),
@@ -213,7 +213,7 @@ const XMLImageMapArea = v.object({
213
213
  "poly"
214
214
  ], "XMLImageMapArea: shape is rect, circle, or poly"),
215
215
  coords: v.string("XMLImageMapArea: coords is string and required")
216
- }, "XMLImageMapArea: Shape error");
216
+ }, "XMLImageMapArea: Shape error"), v.check((area) => area.type === "person" || area.publicationDateTime != null, "XMLImageMapArea: publicationDateTime is required unless type is person"));
217
217
  const XMLImageMap = v.object({
218
218
  area: v.array(XMLImageMapArea, "XMLImageMap: area is array of XMLImageMapArea"),
219
219
  width: XMLNumber,
@@ -163,7 +163,7 @@ type XMLImage = {
163
163
  };
164
164
  type XMLImageMapArea = {
165
165
  uuid: string;
166
- publicationDateTime: Date;
166
+ publicationDateTime?: Date;
167
167
  type: string;
168
168
  title: string;
169
169
  slug?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
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",
@@ -44,6 +44,28 @@
44
44
  "files": [
45
45
  "dist"
46
46
  ],
47
+ "changelogithub": {
48
+ "types": {
49
+ "feat": {
50
+ "title": "🚀 Features"
51
+ },
52
+ "fix": {
53
+ "title": "🐞 Bug Fixes"
54
+ },
55
+ "refactor": {
56
+ "title": "🔧 Refactors"
57
+ },
58
+ "test": {
59
+ "title": "🧪 Tests"
60
+ },
61
+ "docs": {
62
+ "title": "📝 Documentation"
63
+ },
64
+ "chore": {
65
+ "title": "🧹 Chores"
66
+ }
67
+ }
68
+ },
47
69
  "dependencies": {
48
70
  "date-fns": "^4.3.0",
49
71
  "fast-equals": "^6.0.0",