@digitalculture/ochre-sdk 0.17.11 → 0.17.13

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
@@ -494,7 +494,10 @@ type PropertyValueContentType = "string" | "integer" | "decimal" | "boolean" | "
494
494
  * Represents a property value with type information
495
495
  */
496
496
  type PropertyValueContent<T extends PropertyValueContentType> = {
497
- hierarchyLevel: number | null;
497
+ hierarchy: {
498
+ isLeaf: boolean;
499
+ level: number | null;
500
+ };
498
501
  content: (T extends "integer" ? number : T extends "decimal" ? number : T extends "time" ? number : T extends "boolean" ? boolean : string) | null;
499
502
  dataType: T;
500
503
  label: string | null;
@@ -835,7 +838,7 @@ type WebElementComponent = {
835
838
  isMapDisplayed: boolean;
836
839
  isInputDisplayed: boolean;
837
840
  isLimitedToTitleQuery: boolean;
838
- isLimitedToHighestHierarchyLevel: boolean;
841
+ isLimitedToLeafPropertyValues: boolean;
839
842
  sidebarSort: "default" | "alphabetical";
840
843
  };
841
844
  options: {
@@ -1396,5 +1399,11 @@ declare const DEFAULT_API_VERSION = 2;
1396
1399
  * @returns The item with the properties flattened
1397
1400
  */
1398
1401
  declare function flattenItemProperties<T extends DataCategory = DataCategory, U extends DataCategory | Array<DataCategory> = (T extends "tree" ? Exclude<DataCategory, "tree"> : T extends "set" ? Array<DataCategory> : never)>(item: Item<T, U>): Item<T, U>;
1402
+ /**
1403
+ * Get the leaf property values from an array of property values
1404
+ * @param propertyValues - The array of property values to get the leaf property values from
1405
+ * @returns The array of leaf property values
1406
+ */
1407
+ declare function getLeafPropertyValues<T extends PropertyValueContentType = PropertyValueContentType>(propertyValues: Array<PropertyValueContent<T>>): Array<PropertyValueContent<T>>;
1399
1408
  //#endregion
1400
- export { ApiVersion, Bibliography, Concept, Context, ContextItem, ContextNode, Coordinate, DEFAULT_API_VERSION, Data, DataCategory, Event, FileFormat, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, LevelContext, LevelContextItem, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyContexts, PropertyQueryItem, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Scope, Section, Set, SpatialUnit, Style, Text, Tree, UuidMetadata, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebTitle, Webpage, Website, fetchByUuidMetadata, fetchGallery, fetchItem, fetchItemsByPropertyValues, fetchPropertyValuesByPropertyVariables, fetchWebsite, filterProperties, flattenItemProperties, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
1409
+ export { ApiVersion, Bibliography, Concept, Context, ContextItem, ContextNode, Coordinate, DEFAULT_API_VERSION, Data, DataCategory, Event, FileFormat, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, LevelContext, LevelContextItem, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyContexts, PropertyQueryItem, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Scope, Section, Set, SpatialUnit, Style, Text, Tree, UuidMetadata, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebTitle, Webpage, Website, fetchByUuidMetadata, fetchGallery, fetchItem, fetchItemsByPropertyValues, fetchPropertyValuesByPropertyVariables, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
package/dist/index.mjs CHANGED
@@ -1011,6 +1011,14 @@ function flattenItemProperties(item) {
1011
1011
  properties: collectPropertiesFromSubNodes()
1012
1012
  };
1013
1013
  }
1014
+ /**
1015
+ * Get the leaf property values from an array of property values
1016
+ * @param propertyValues - The array of property values to get the leaf property values from
1017
+ * @returns The array of leaf property values
1018
+ */
1019
+ function getLeafPropertyValues(propertyValues) {
1020
+ return propertyValues.filter((value) => value.hierarchy.isLeaf);
1021
+ }
1014
1022
 
1015
1023
  //#endregion
1016
1024
  //#region src/utils/parse.ts
@@ -1446,7 +1454,10 @@ function parseProperty(property, language = "eng") {
1446
1454
  if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1447
1455
  content = parseFakeString(value);
1448
1456
  return {
1449
- hierarchyLevel: null,
1457
+ hierarchy: {
1458
+ isLeaf: true,
1459
+ level: null
1460
+ },
1450
1461
  content,
1451
1462
  label: null,
1452
1463
  dataType: "string",
@@ -1502,7 +1513,10 @@ function parseProperty(property, language = "eng") {
1502
1513
  break;
1503
1514
  }
1504
1515
  return {
1505
- hierarchyLevel: value.i ?? null,
1516
+ hierarchy: {
1517
+ isLeaf: value.inherited == null || !value.inherited,
1518
+ level: value.i ?? null
1519
+ },
1506
1520
  content,
1507
1521
  dataType: parsedType,
1508
1522
  isUncertain: value.isUncertain ?? false,
@@ -1519,9 +1533,6 @@ function parseProperty(property, language = "eng") {
1519
1533
  slug: value.slug ?? null
1520
1534
  };
1521
1535
  }
1522
- }).toSorted((a, b) => {
1523
- if (a.hierarchyLevel != null && b.hierarchyLevel != null) return b.hierarchyLevel - a.hierarchyLevel;
1524
- return 0;
1525
1536
  });
1526
1537
  return {
1527
1538
  uuid: property.label.uuid,
@@ -2302,9 +2313,9 @@ function parseWebElementProperties(componentProperty, elementResource) {
2302
2313
  let isFilterLimitedToTitleQuery = false;
2303
2314
  const isFilterLimitedToTitleQueryProperty = getPropertyValueByLabel(componentProperty.properties, "filter-limit-to-title-query");
2304
2315
  if (isFilterLimitedToTitleQueryProperty !== null) isFilterLimitedToTitleQuery = isFilterLimitedToTitleQueryProperty === true;
2305
- let isFilterLimitedToHighestHierarchyLevel = false;
2306
- const isFilterLimitedToHighestHierarchyLevelProperty = getPropertyValueByLabel(componentProperty.properties, "filter-limit-to-highest-hierarchy-level");
2307
- if (isFilterLimitedToHighestHierarchyLevelProperty !== null) isFilterLimitedToHighestHierarchyLevel = isFilterLimitedToHighestHierarchyLevelProperty === true;
2316
+ let isFilterLimitedToLeafPropertyValues = false;
2317
+ const isFilterLimitedToLeafPropertyValuesProperty = getPropertyValueByLabel(componentProperty.properties, "filter-limit-to-leaf-property-values");
2318
+ if (isFilterLimitedToLeafPropertyValuesProperty !== null) isFilterLimitedToLeafPropertyValues = isFilterLimitedToLeafPropertyValuesProperty === true;
2308
2319
  let isSortDisplayed = false;
2309
2320
  const isSortDisplayedProperty = getPropertyValueByLabel(componentProperty.properties, "sort-displayed");
2310
2321
  if (isSortDisplayedProperty !== null) isSortDisplayed = isSortDisplayedProperty === true;
@@ -2364,7 +2375,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
2364
2375
  isMapDisplayed: isFilterMapDisplayed,
2365
2376
  isInputDisplayed: isFilterInputDisplayed,
2366
2377
  isLimitedToTitleQuery: isFilterLimitedToTitleQuery,
2367
- isLimitedToHighestHierarchyLevel: isFilterLimitedToHighestHierarchyLevel,
2378
+ isLimitedToLeafPropertyValues: isFilterLimitedToLeafPropertyValues,
2368
2379
  sidebarSort: filterSidebarSort
2369
2380
  };
2370
2381
  properties.isSortDisplayed = isSortDisplayed;
@@ -3888,4 +3899,4 @@ async function fetchWebsite(abbreviation, options) {
3888
3899
  }
3889
3900
 
3890
3901
  //#endregion
3891
- export { DEFAULT_API_VERSION, fetchByUuidMetadata, fetchGallery, fetchItem, fetchItemsByPropertyValues, fetchPropertyValuesByPropertyVariables, fetchWebsite, filterProperties, flattenItemProperties, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
3902
+ export { DEFAULT_API_VERSION, fetchByUuidMetadata, fetchGallery, fetchItem, fetchItemsByPropertyValues, fetchPropertyValuesByPropertyVariables, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalculture/ochre-sdk",
3
- "version": "0.17.11",
3
+ "version": "0.17.13",
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",