ochre-sdk 0.19.8 → 0.19.10

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
@@ -891,7 +891,7 @@ type WebElementComponent = {
891
891
  label: string;
892
892
  }> | null;
893
893
  variant: "full" | "highlights";
894
- itemVariant: "detailed" | "card" | "tile";
894
+ itemVariant: "detailed" | "card" | "tile" | "showcase";
895
895
  paginationVariant: "default" | "numeric";
896
896
  layout: "image-top" | "image-bottom" | "image-start" | "image-end";
897
897
  imageQuality: "high" | "low";
@@ -968,7 +968,7 @@ type WebElementComponent = {
968
968
  isFullHeight: boolean;
969
969
  } | {
970
970
  component: "query";
971
- itemCategory: "resource" | "spatialUnit" | "concept" | "text" | null;
971
+ linkUuids: Array<string>;
972
972
  queries: Array<{
973
973
  label: string;
974
974
  propertyVariableUuids: Array<string>;
@@ -979,9 +979,15 @@ type WebElementComponent = {
979
979
  uuid: string;
980
980
  label: string;
981
981
  }> | null;
982
- itemVariant: "detailed" | "card" | "tile";
983
- paginationVariant: "default" | "numeric";
984
- layout: "image-top" | "image-bottom" | "image-start" | "image-end";
982
+ itemVariant: Extract<WebElementComponent, {
983
+ component: "collection";
984
+ }>["itemVariant"];
985
+ paginationVariant: Extract<WebElementComponent, {
986
+ component: "collection";
987
+ }>["paginationVariant"];
988
+ layout: Extract<WebElementComponent, {
989
+ component: "collection";
990
+ }>["layout"];
985
991
  } | {
986
992
  component: "search-bar";
987
993
  queryVariant: "submit" | "change";
@@ -1123,18 +1129,17 @@ declare function fetchItem<T extends DataCategory = DataCategory, U extends Data
1123
1129
  item: never;
1124
1130
  }>;
1125
1131
  //#endregion
1126
- //#region src/utils/fetchers/items-by-property-values.d.ts
1132
+ //#region src/utils/fetchers/set/items-by-property-values.d.ts
1127
1133
  /**
1128
1134
  * Fetches and parses items by property values from the OCHRE API
1129
1135
  *
1130
1136
  * @param params - The parameters for the fetch
1131
- * @param params.projectScopeUuid - The UUID of the project scope
1137
+ * @param params.setScopeUuids - The Set scope UUIDs to filter by
1132
1138
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
1133
1139
  * @param params.propertyVariableUuids - The property variable UUIDs to query by
1134
1140
  * @param params.propertyValues - The property values to query by
1135
1141
  * @param params.page - The page number (1-indexed)
1136
1142
  * @param params.pageSize - The number of items per page
1137
- * @param params.itemCategory - The category of the items to fetch
1138
1143
  * @param params.includeChildItems - Whether to include child items of the same category
1139
1144
  * @param categoryParams - The category parameters for the fetch
1140
1145
  * @param categoryParams.category - The category of the items to fetch
@@ -1144,8 +1149,8 @@ declare function fetchItem<T extends DataCategory = DataCategory, U extends Data
1144
1149
  * @param options.version - The version of the OCHRE API to use
1145
1150
  * @returns The parsed items by property values or null if the fetch/parse fails
1146
1151
  */
1147
- declare function fetchItemsByPropertyValues<T extends DataCategory = DataCategory, U extends DataCategory | Array<DataCategory> = (T extends "tree" ? Exclude<DataCategory, "tree"> : T extends "set" ? Array<DataCategory> : never)>(params: {
1148
- projectScopeUuid: string;
1152
+ declare function fetchSetItemsByPropertyValues<T extends DataCategory = DataCategory, U extends DataCategory | Array<DataCategory> = (T extends "tree" ? Exclude<DataCategory, "tree"> : T extends "set" ? Array<DataCategory> : never)>(params: {
1153
+ setScopeUuids: Array<string>;
1149
1154
  belongsToCollectionScopeUuids: Array<string>;
1150
1155
  propertyVariableUuids: Array<string>;
1151
1156
  propertyValues: Array<{
@@ -1154,7 +1159,6 @@ declare function fetchItemsByPropertyValues<T extends DataCategory = DataCategor
1154
1159
  }>;
1155
1160
  page: number;
1156
1161
  pageSize?: number;
1157
- itemCategory?: "resource" | "spatialUnit" | "concept" | "text";
1158
1162
  includeChildItems?: boolean;
1159
1163
  }, categoryParams?: {
1160
1164
  category?: T;
@@ -1176,31 +1180,31 @@ declare function fetchItemsByPropertyValues<T extends DataCategory = DataCategor
1176
1180
  error: string;
1177
1181
  }>;
1178
1182
  //#endregion
1179
- //#region src/utils/fetchers/property-values-by-property-variables.d.ts
1183
+ //#region src/utils/fetchers/set/property-values-by-property-variables.d.ts
1180
1184
  /**
1181
- * Fetches and parses property values by property variables from the OCHRE API
1185
+ * Fetches and parses Set property values by property variables from the OCHRE API
1182
1186
  *
1183
1187
  * @param params - The parameters for the fetch
1184
- * @param params.projectScopeUuid - The UUID of the project scope
1188
+ * @param params.setScopeUuids - An array of set scope UUIDs to filter by
1185
1189
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
1186
1190
  * @param params.propertyVariableUuids - The property variable UUIDs to query by
1187
1191
  * @param options - Options for the fetch
1188
1192
  * @param options.fetch - The fetch function to use
1189
1193
  * @param options.version - The version of the OCHRE API to use
1190
- * @returns The parsed property values by property variables or null if the fetch/parse fails
1194
+ * @returns The parsed Set property values by property variables or null if the fetch/parse fails
1191
1195
  */
1192
- declare function fetchPropertyValuesByPropertyVariables(params: {
1193
- projectScopeUuid: string;
1196
+ declare function fetchSetPropertyValuesByPropertyVariables(params: {
1197
+ setScopeUuids: Array<string>;
1194
1198
  belongsToCollectionScopeUuids: Array<string>;
1195
1199
  propertyVariableUuids: Array<string>;
1196
1200
  }, options?: {
1197
1201
  fetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
1198
1202
  version?: ApiVersion;
1199
1203
  }): Promise<{
1200
- items: Array<PropertyValueQueryItem> | null;
1204
+ propertyValues: Array<PropertyValueQueryItem> | null;
1201
1205
  error: null;
1202
1206
  } | {
1203
- items: null;
1207
+ propertyValues: null;
1204
1208
  error: string;
1205
1209
  }>;
1206
1210
  //#endregion
@@ -1363,4 +1367,4 @@ declare const DEFAULT_PAGE_SIZE = 48;
1363
1367
  */
1364
1368
  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>;
1365
1369
  //#endregion
1366
- export { ApiVersion, Bibliography, Concept, Context, ContextItem, ContextNode, Coordinate, DEFAULT_API_VERSION, DEFAULT_PAGE_SIZE, Data, DataCategory, Event, FileFormat, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, LevelContext, LevelContextItem, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyContexts, PropertyValue, PropertyValueContent, PropertyValueContentType, PropertyValueQueryItem, PropertyVariable, Resource, Scope, Section, Set, SpatialUnit, Style, Text, Tree, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebSegment, WebSegmentItem, WebTitle, Webpage, Website, WebsiteType, fetchGallery, fetchItem, fetchItemsByPropertyValues, fetchPropertyValuesByPropertyVariables, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByLabel, getPropertyByLabelAndValue, getPropertyByLabelAndValues, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
1370
+ export { ApiVersion, Bibliography, Concept, Context, ContextItem, ContextNode, Coordinate, DEFAULT_API_VERSION, DEFAULT_PAGE_SIZE, Data, DataCategory, Event, FileFormat, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, LevelContext, LevelContextItem, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyContexts, PropertyValue, PropertyValueContent, PropertyValueContentType, PropertyValueQueryItem, PropertyVariable, Resource, Scope, Section, Set, SpatialUnit, Style, Text, Tree, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebSegment, WebSegmentItem, WebTitle, Webpage, Website, WebsiteType, fetchGallery, fetchItem, fetchSetItemsByPropertyValues, fetchSetPropertyValuesByPropertyVariables, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByLabel, getPropertyByLabelAndValue, getPropertyByLabelAndValues, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
package/dist/index.mjs CHANGED
@@ -543,6 +543,48 @@ function parseFakeStringOrContent(value) {
543
543
  function parseOptionalDate(dateTime) {
544
544
  return dateTime != null ? parseISO(dateTime) : null;
545
545
  }
546
+ /**
547
+ * Cleans an object by removing null values
548
+ * @param object - The object to clean
549
+ * @returns The cleaned object
550
+ */
551
+ function cleanObject(object) {
552
+ return Object.fromEntries(Object.entries(object).filter(([_, value]) => value != null));
553
+ }
554
+
555
+ //#endregion
556
+ //#region src/utils/helpers.ts
557
+ /**
558
+ * The default API version to use
559
+ *
560
+ * @remarks
561
+ * Version 1 of the OCHRE API is deprecated and will be removed in the future.
562
+ * It points to the old Tamino server.
563
+ *
564
+ * Version 2 of the OCHRE API is the current version and is the default.
565
+ * It points to the new MarkLogic server.
566
+ */
567
+ const DEFAULT_API_VERSION = 2;
568
+ /**
569
+ * The default page size to use for fetching paginated items
570
+ */
571
+ const DEFAULT_PAGE_SIZE = 48;
572
+ /**
573
+ * Flatten the properties of an item
574
+ * @param item - The item whose properties to flatten
575
+ * @returns The item with the properties flattened
576
+ */
577
+ function flattenItemProperties(item) {
578
+ const allProperties = [];
579
+ if ("properties" in item) allProperties.push(...item.properties);
580
+ if ("observations" in item) for (const observation of item.observations) allProperties.push(...observation.properties);
581
+ if ("interpretations" in item) for (const interpretation of item.interpretations) allProperties.push(...interpretation.properties);
582
+ if ("bibliographies" in item) for (const bibliography of item.bibliographies) allProperties.push(...bibliography.properties);
583
+ return {
584
+ ...item,
585
+ properties: flattenProperties(allProperties)
586
+ };
587
+ }
546
588
 
547
589
  //#endregion
548
590
  //#region src/schemas.ts
@@ -710,40 +752,40 @@ const boundsSchema = z.string().transform((str, ctx) => {
710
752
  return z.NEVER;
711
753
  }
712
754
  }).pipe(z.tuple([z.tuple([z.number(), z.number()]), z.tuple([z.number(), z.number()])], { message: "Must contain exactly 2 coordinate pairs" }));
713
-
714
- //#endregion
715
- //#region src/utils/helpers.ts
716
- /**
717
- * The default API version to use
718
- *
719
- * @remarks
720
- * Version 1 of the OCHRE API is deprecated and will be removed in the future.
721
- * It points to the old Tamino server.
722
- *
723
- * Version 2 of the OCHRE API is the current version and is the default.
724
- * It points to the new MarkLogic server.
725
- */
726
- const DEFAULT_API_VERSION = 2;
727
- /**
728
- * The default page size to use for fetching paginated items
729
- */
730
- const DEFAULT_PAGE_SIZE = 48;
731
755
  /**
732
- * Flatten the properties of an item
733
- * @param item - The item whose properties to flatten
734
- * @returns The item with the properties flattened
756
+ * Schema for validating the parameters for the Set property values by property variables fetching function
757
+ * @internal
735
758
  */
736
- function flattenItemProperties(item) {
737
- const allProperties = [];
738
- if ("properties" in item) allProperties.push(...item.properties);
739
- if ("observations" in item) for (const observation of item.observations) allProperties.push(...observation.properties);
740
- if ("interpretations" in item) for (const interpretation of item.interpretations) allProperties.push(...interpretation.properties);
741
- if ("bibliographies" in item) for (const bibliography of item.bibliographies) allProperties.push(...bibliography.properties);
742
- return {
743
- ...item,
744
- properties: flattenProperties(allProperties)
745
- };
746
- }
759
+ const setPropertyValuesByPropertyVariablesParamsSchema = z.object({
760
+ setScopeUuids: z.array(uuidSchema).min(1, "At least one set scope UUID is required"),
761
+ belongsToCollectionScopeUuids: z.array(uuidSchema).default([]),
762
+ propertyVariableUuids: z.array(uuidSchema).min(1, "At least one property variable UUID is required")
763
+ });
764
+ const setItemsByPropertyValuesParamsSchema = z.object({
765
+ ...setPropertyValuesByPropertyVariablesParamsSchema.shape,
766
+ propertyValues: z.array(z.object({
767
+ dataType: z.enum([
768
+ "string",
769
+ "integer",
770
+ "decimal",
771
+ "boolean",
772
+ "date",
773
+ "dateTime",
774
+ "time",
775
+ "IDREF"
776
+ ]),
777
+ value: z.string()
778
+ })).min(1, "At least one property value is required"),
779
+ page: z.number().min(1, "Page must be at least 1").default(1),
780
+ pageSize: z.number().min(1, "Page size must be at least 1").default(DEFAULT_PAGE_SIZE),
781
+ itemCategory: z.enum([
782
+ "resource",
783
+ "spatialUnit",
784
+ "concept",
785
+ "text"
786
+ ]).optional(),
787
+ includeChildItems: z.boolean().optional().default(false)
788
+ });
747
789
 
748
790
  //#endregion
749
791
  //#region src/utils/parse/index.ts
@@ -1984,15 +2026,14 @@ async function fetchItem(uuid, category, itemCategories, options) {
1984
2026
  }
1985
2027
 
1986
2028
  //#endregion
1987
- //#region src/utils/fetchers/items-by-property-values.ts
2029
+ //#region src/utils/fetchers/set/items-by-property-values.ts
1988
2030
  /**
1989
2031
  * Build an XQuery string to fetch items by property values from the OCHRE API
1990
2032
  * @param params - The parameters for the fetch
1991
- * @param params.projectScopeUuid - The UUID of the project scope
2033
+ * @param params.setScopeUuids - An array of Set scope UUIDs to filter by
1992
2034
  * @param params.belongsToCollectionScopeUuids - An array of collection scope UUIDs to filter by
1993
2035
  * @param params.propertyVariableUuids - An array of property variable UUIDs to fetch
1994
2036
  * @param params.propertyValues - An array of property values to fetch
1995
- * @param params.itemCategory - The category of the items to fetch
1996
2037
  * @param params.page - The page number (1-indexed)
1997
2038
  * @param params.pageSize - The number of items per page
1998
2039
  * @param params.includeChildItems - Whether to include child items of the same category
@@ -2002,9 +2043,11 @@ async function fetchItem(uuid, category, itemCategories, options) {
2002
2043
  */
2003
2044
  function buildXQuery$1(params, options) {
2004
2045
  const version = options?.version ?? DEFAULT_API_VERSION;
2005
- const { propertyVariableUuids, propertyValues, projectScopeUuid, belongsToCollectionScopeUuids, itemCategory, page, pageSize, includeChildItems = false } = params;
2006
- const startPos = (page - 1) * pageSize + 1;
2007
- const endPos = page * pageSize;
2046
+ const { propertyVariableUuids, propertyValues, setScopeUuids, belongsToCollectionScopeUuids, page, pageSize, includeChildItems = false } = params;
2047
+ const startPosition = (page - 1) * pageSize + 1;
2048
+ const endPosition = page * pageSize;
2049
+ let setScopeFilter = "";
2050
+ if (setScopeUuids.length > 0) setScopeFilter = `/set[(${setScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]/items/*`;
2008
2051
  let belongsToCollectionScopeFilter = "";
2009
2052
  if (belongsToCollectionScopeUuids.length > 0) belongsToCollectionScopeFilter = `[.//properties[property[label/@uuid="${BELONGS_TO_COLLECTION_UUID}" and value/(${belongsToCollectionScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]]`;
2010
2053
  const propertyVariables = propertyVariableUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
@@ -2013,23 +2056,15 @@ function buildXQuery$1(params, options) {
2013
2056
  if (dataType === "date" || dataType === "dateTime" || dataType === "time" || dataType === "integer" || dataType === "decimal" || dataType === "boolean") return `value[@rawValue="${value}"]`;
2014
2057
  return `value[.="${value}"]`;
2015
2058
  }).join(" or ");
2016
- return `<ochre>{${`let $match-uuids := distinct-values(
2017
- ${version === 2 ? "doc()" : "input()"}/ochre[@uuidBelongsTo="${projectScopeUuid}"]
2059
+ return `<ochre>{${`let $items := ${version === 2 ? "doc()" : "input()"}/ochre
2060
+ ${setScopeFilter}
2018
2061
  ${belongsToCollectionScopeFilter}
2019
2062
  //property[label[${propertyVariables}]][${propertyValuesFilters}]]
2020
- /@uuid
2021
- )
2022
2063
 
2023
- let $items := ${version === 2 ? "doc()" : "input()"}/ochre[@uuidBelongsTo="${projectScopeUuid}"]
2024
- /${itemCategory ?? "*"}[@uuid = $match-uuids
2025
- or bibliographies/bibliography/@uuid = $match-uuids]
2026
-
2027
- let $unique-uuids := distinct-values($items/@uuid)
2028
- let $totalCount := count($unique-uuids)
2064
+ let $totalCount := count($items)
2029
2065
 
2030
2066
  return <items totalCount="{$totalCount}" page="${page}" pageSize="${pageSize}">{
2031
- for $uuid in $unique-uuids[position() ge ${startPos} and position() le ${endPos}]
2032
- let $item := ($items[@uuid = $uuid])[1]
2067
+ for $item in $items[position() ge ${startPosition} and position() le ${endPosition}]
2033
2068
  let $category := local-name($item)
2034
2069
  return element { node-name($item) } {
2035
2070
  $item/@*, ${includeChildItems ? "$item/node()" : "$item/node()[not(local-name(.) = $category)]"}
@@ -2040,13 +2075,12 @@ function buildXQuery$1(params, options) {
2040
2075
  * Fetches and parses items by property values from the OCHRE API
2041
2076
  *
2042
2077
  * @param params - The parameters for the fetch
2043
- * @param params.projectScopeUuid - The UUID of the project scope
2078
+ * @param params.setScopeUuids - The Set scope UUIDs to filter by
2044
2079
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
2045
2080
  * @param params.propertyVariableUuids - The property variable UUIDs to query by
2046
2081
  * @param params.propertyValues - The property values to query by
2047
2082
  * @param params.page - The page number (1-indexed)
2048
2083
  * @param params.pageSize - The number of items per page
2049
- * @param params.itemCategory - The category of the items to fetch
2050
2084
  * @param params.includeChildItems - Whether to include child items of the same category
2051
2085
  * @param categoryParams - The category parameters for the fetch
2052
2086
  * @param categoryParams.category - The category of the items to fetch
@@ -2056,17 +2090,16 @@ function buildXQuery$1(params, options) {
2056
2090
  * @param options.version - The version of the OCHRE API to use
2057
2091
  * @returns The parsed items by property values or null if the fetch/parse fails
2058
2092
  */
2059
- async function fetchItemsByPropertyValues(params, categoryParams, options) {
2093
+ async function fetchSetItemsByPropertyValues(params, categoryParams, options) {
2060
2094
  try {
2061
2095
  const version = options?.version ?? DEFAULT_API_VERSION;
2062
- const { propertyVariableUuids, propertyValues, projectScopeUuid, belongsToCollectionScopeUuids, page, pageSize = DEFAULT_PAGE_SIZE, itemCategory, includeChildItems } = params;
2096
+ const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids, propertyValues, page, pageSize, includeChildItems } = setItemsByPropertyValuesParamsSchema.parse(params);
2063
2097
  const { category, itemCategories } = categoryParams ?? {};
2064
2098
  const xquery = buildXQuery$1({
2065
- projectScopeUuid,
2099
+ setScopeUuids,
2066
2100
  belongsToCollectionScopeUuids,
2067
2101
  propertyVariableUuids,
2068
2102
  propertyValues,
2069
- itemCategory,
2070
2103
  includeChildItems,
2071
2104
  page,
2072
2105
  pageSize
@@ -2142,7 +2175,7 @@ async function fetchItemsByPropertyValues(params, categoryParams, options) {
2142
2175
  }
2143
2176
 
2144
2177
  //#endregion
2145
- //#region src/utils/fetchers/property-values-by-property-variables.ts
2178
+ //#region src/utils/fetchers/set/property-values-by-property-variables.ts
2146
2179
  /**
2147
2180
  * Schema for a single property value query item in the OCHRE API response
2148
2181
  */
@@ -2198,7 +2231,7 @@ const responseSchema = z.object({ result: z.union([z.object({ ochre: z.object({
2198
2231
  /**
2199
2232
  * Build an XQuery string to fetch property values by property variables from the OCHRE API
2200
2233
  * @param params - The parameters for the fetch
2201
- * @param params.projectScopeUuid - The UUID of the project scope
2234
+ * @param params.setScopeUuids - An array of set scope UUIDs to filter by
2202
2235
  * @param params.belongsToCollectionScopeUuids - An array of collection scope UUIDs to filter by
2203
2236
  * @param params.propertyVariableUuids - An array of property variable UUIDs to fetch
2204
2237
  * @param options - Options for the fetch
@@ -2207,39 +2240,41 @@ const responseSchema = z.object({ result: z.union([z.object({ ochre: z.object({
2207
2240
  */
2208
2241
  function buildXQuery(params, options) {
2209
2242
  const version = options?.version ?? DEFAULT_API_VERSION;
2210
- const { projectScopeUuid, belongsToCollectionScopeUuids, propertyVariableUuids } = params;
2243
+ const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids } = params;
2244
+ let setScopeFilter = "";
2245
+ if (setScopeUuids.length > 0) setScopeFilter = `/set[(${setScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]/items`;
2211
2246
  let collectionScopeFilter = "";
2212
2247
  if (belongsToCollectionScopeUuids.length > 0) collectionScopeFilter = `//properties[property[label/@uuid="${BELONGS_TO_COLLECTION_UUID}" and value/(${belongsToCollectionScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]]`;
2213
2248
  const propertyVariableFilters = propertyVariableUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
2214
- return `<ochre>{${`let $matching-props := ${version === 2 ? "doc()" : "input()"}/ochre[@uuidBelongsTo="${projectScopeUuid}"]
2249
+ return `<ochre>{${`let $matching-props := ${version === 2 ? "doc()" : "input()"}/ochre
2250
+ ${setScopeFilter}
2215
2251
  ${collectionScopeFilter}
2216
- /*[not(self::set)]
2217
2252
  //property[label/(${propertyVariableFilters})]
2218
2253
 
2219
2254
  for $v in $matching-props/value
2220
- let $item-uuid := $v/ancestor::*[parent::ochre]/@uuid
2255
+ let $item-uuid := $v/ancestor::*[parent::items]/@uuid
2221
2256
  return <propertyValue uuid="{$v/@uuid}" rawValue="{$v/@rawValue}" dataType="{$v/@dataType}" itemUuid="{$item-uuid}">{
2222
2257
  if ($v/content) then $v/content else $v/text()
2223
2258
  }</propertyValue>`}}</ochre>`;
2224
2259
  }
2225
2260
  /**
2226
- * Fetches and parses property values by property variables from the OCHRE API
2261
+ * Fetches and parses Set property values by property variables from the OCHRE API
2227
2262
  *
2228
2263
  * @param params - The parameters for the fetch
2229
- * @param params.projectScopeUuid - The UUID of the project scope
2264
+ * @param params.setScopeUuids - An array of set scope UUIDs to filter by
2230
2265
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
2231
2266
  * @param params.propertyVariableUuids - The property variable UUIDs to query by
2232
2267
  * @param options - Options for the fetch
2233
2268
  * @param options.fetch - The fetch function to use
2234
2269
  * @param options.version - The version of the OCHRE API to use
2235
- * @returns The parsed property values by property variables or null if the fetch/parse fails
2270
+ * @returns The parsed Set property values by property variables or null if the fetch/parse fails
2236
2271
  */
2237
- async function fetchPropertyValuesByPropertyVariables(params, options) {
2272
+ async function fetchSetPropertyValuesByPropertyVariables(params, options) {
2238
2273
  try {
2239
2274
  const version = options?.version ?? DEFAULT_API_VERSION;
2240
- const { belongsToCollectionScopeUuids, propertyVariableUuids, projectScopeUuid } = params;
2275
+ const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids } = setPropertyValuesByPropertyVariablesParamsSchema.parse(params);
2241
2276
  const xquery = buildXQuery({
2242
- projectScopeUuid,
2277
+ setScopeUuids,
2243
2278
  belongsToCollectionScopeUuids,
2244
2279
  propertyVariableUuids
2245
2280
  }, { version });
@@ -2247,28 +2282,28 @@ async function fetchPropertyValuesByPropertyVariables(params, options) {
2247
2282
  if (!response.ok) throw new Error(`OCHRE API responded with status: ${response.status}`);
2248
2283
  const data = await response.json();
2249
2284
  const parsedResultRaw = responseSchema.parse(data);
2250
- if (Array.isArray(parsedResultRaw.result)) throw new TypeError("No items found");
2251
- const parsedItems = Array.isArray(parsedResultRaw.result.ochre.propertyValue) ? parsedResultRaw.result.ochre.propertyValue : [parsedResultRaw.result.ochre.propertyValue];
2252
- const groupedItemsMap = /* @__PURE__ */ new Map();
2253
- for (const item of parsedItems) {
2254
- const existing = groupedItemsMap.get(item.content);
2255
- if (existing == null) groupedItemsMap.set(item.content, {
2256
- dataType: item.dataType,
2257
- content: item.content,
2258
- label: item.label,
2259
- itemUuids: new Set([item.itemUuid])
2285
+ if (Array.isArray(parsedResultRaw.result)) throw new TypeError("No property values found");
2286
+ const parsedPropertyValues = Array.isArray(parsedResultRaw.result.ochre.propertyValue) ? parsedResultRaw.result.ochre.propertyValue : [parsedResultRaw.result.ochre.propertyValue];
2287
+ const groupedPropertyValuesMap = /* @__PURE__ */ new Map();
2288
+ for (const propertyValue of parsedPropertyValues) {
2289
+ const existing = groupedPropertyValuesMap.get(propertyValue.content);
2290
+ if (existing == null) groupedPropertyValuesMap.set(propertyValue.content, {
2291
+ dataType: propertyValue.dataType,
2292
+ content: propertyValue.content,
2293
+ label: propertyValue.label,
2294
+ itemUuids: new Set([propertyValue.itemUuid])
2260
2295
  });
2261
- else existing.itemUuids.add(item.itemUuid);
2296
+ else existing.itemUuids.add(propertyValue.itemUuid);
2262
2297
  }
2263
- const groupedItems = [];
2264
- for (const group of groupedItemsMap.values()) groupedItems.push({
2298
+ const groupedPropertyValues = [];
2299
+ for (const group of groupedPropertyValuesMap.values()) groupedPropertyValues.push({
2265
2300
  count: group.itemUuids.size,
2266
2301
  dataType: group.dataType,
2267
2302
  content: group.content,
2268
2303
  label: group.label
2269
2304
  });
2270
2305
  return {
2271
- items: groupedItems.toSorted((a, b) => {
2306
+ propertyValues: groupedPropertyValues.filter((propertyValue) => propertyValue.content !== null).toSorted((a, b) => {
2272
2307
  if (a.count !== b.count) return b.count - a.count;
2273
2308
  if (a.label !== b.label) return a.label?.localeCompare(b.label ?? "") ?? 0;
2274
2309
  return a.content?.toString().localeCompare(b.content?.toString() ?? "") ?? 0;
@@ -2278,7 +2313,7 @@ async function fetchPropertyValuesByPropertyVariables(params, options) {
2278
2313
  } catch (error) {
2279
2314
  console.error(error);
2280
2315
  return {
2281
- items: null,
2316
+ propertyValues: null,
2282
2317
  error: error instanceof Error ? error.message : "Failed to fetch property values by property variables"
2283
2318
  };
2284
2319
  }
@@ -2757,8 +2792,8 @@ function parseWebElementProperties(componentProperty, elementResource) {
2757
2792
  break;
2758
2793
  }
2759
2794
  case "collection": {
2760
- const collectionLinks = links.filter((link) => link.category === "set");
2761
- if (collectionLinks.every((link) => link.uuid === null)) throw new Error(`Collection links not found for the following component: “${componentName}”`);
2795
+ const setLinks = links.filter((link) => link.category === "set");
2796
+ if (setLinks.every((link) => link.uuid === null)) throw new Error(`Set links not found for the following component: “${componentName}”`);
2762
2797
  const displayedProperties = getPropertyByLabel(componentProperty.properties, "use-property");
2763
2798
  let variant = getPropertyValueByLabel(componentProperty.properties, "variant");
2764
2799
  variant ??= "full";
@@ -2810,7 +2845,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
2810
2845
  }
2811
2846
  properties = {
2812
2847
  component: "collection",
2813
- linkUuids: collectionLinks.map((link) => link.uuid).filter((uuid) => uuid !== null),
2848
+ linkUuids: setLinks.map((link) => link.uuid).filter((uuid) => uuid !== null),
2814
2849
  displayedProperties: displayedProperties?.values.filter(({ uuid }) => uuid !== null).map((value) => ({
2815
2850
  uuid: value.uuid,
2816
2851
  label: value.content?.toString() ?? ""
@@ -3020,9 +3055,9 @@ function parseWebElementProperties(componentProperty, elementResource) {
3020
3055
  break;
3021
3056
  }
3022
3057
  case "query": {
3058
+ const setLinks = links.filter((link) => link.category === "set");
3059
+ if (setLinks.every((link) => link.uuid === null)) throw new Error(`Set links not found for the following component: “${componentName}”`);
3023
3060
  const queries = [];
3024
- let itemCategory = getPropertyValueByLabel(componentProperty.properties, "item-category");
3025
- itemCategory ??= null;
3026
3061
  if (componentProperty.properties.length === 0) throw new Error(`Query properties not found for the following component: “${componentName}”`);
3027
3062
  for (const query of componentProperty.properties) {
3028
3063
  const querySubProperties = query.properties;
@@ -3050,7 +3085,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
3050
3085
  layout ??= "image-start";
3051
3086
  properties = {
3052
3087
  component: "query",
3053
- itemCategory,
3088
+ linkUuids: setLinks.map((link) => link.uuid).filter((uuid) => uuid !== null),
3054
3089
  queries,
3055
3090
  displayedProperties: displayedProperties?.values.filter((value) => value.uuid !== null).map((value) => ({
3056
3091
  uuid: value.uuid,
@@ -3565,9 +3600,10 @@ function parseWebBlock(blockResource) {
3565
3600
  propertiesTablet.isAccordionExpandedByDefault = getPropertyValueByLabel(tabletOverwriteProperties, "accordion-expanded") ?? void 0;
3566
3601
  propertiesTablet.isAccordionSidebarDisplayed = getPropertyValueByLabel(tabletOverwriteProperties, "accordion-sidebar-displayed") ?? void 0;
3567
3602
  }
3568
- if (Object.values(propertiesTablet).every((value) => value != null)) returnBlock.properties.tablet = propertiesTablet;
3603
+ const cleanedPropertiesTablet = cleanObject(propertiesTablet);
3604
+ if (Object.keys(cleanedPropertiesTablet).length > 0) returnBlock.properties.tablet = cleanedPropertiesTablet;
3569
3605
  }
3570
- const mobileOverwriteProperty = getPropertyByLabel(blockMainProperties, "overwrite-tablet");
3606
+ const mobileOverwriteProperty = getPropertyByLabel(blockMainProperties, "overwrite-mobile");
3571
3607
  if (mobileOverwriteProperty !== null) {
3572
3608
  const mobileOverwriteProperties = mobileOverwriteProperty.properties;
3573
3609
  const propertiesMobile = {
@@ -3583,7 +3619,8 @@ function parseWebBlock(blockResource) {
3583
3619
  propertiesMobile.isAccordionExpandedByDefault = getPropertyValueByLabel(mobileOverwriteProperties, "accordion-expanded") ?? void 0;
3584
3620
  propertiesMobile.isAccordionSidebarDisplayed = getPropertyValueByLabel(mobileOverwriteProperties, "accordion-sidebar-displayed") ?? void 0;
3585
3621
  }
3586
- if (Object.values(propertiesMobile).every((value) => value != null)) returnBlock.properties.mobile = propertiesMobile;
3622
+ const cleanedPropertiesMobile = cleanObject(propertiesMobile);
3623
+ if (Object.keys(cleanedPropertiesMobile).length > 0) returnBlock.properties.mobile = cleanedPropertiesMobile;
3587
3624
  }
3588
3625
  }
3589
3626
  const blockResources = blockResource.resource ? ensureArray(blockResource.resource) : [];
@@ -3853,4 +3890,4 @@ async function fetchWebsite(abbreviation, options) {
3853
3890
  }
3854
3891
 
3855
3892
  //#endregion
3856
- export { DEFAULT_API_VERSION, DEFAULT_PAGE_SIZE, fetchGallery, fetchItem, fetchItemsByPropertyValues, fetchPropertyValuesByPropertyVariables, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByLabel, getPropertyByLabelAndValue, getPropertyByLabelAndValues, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
3893
+ export { DEFAULT_API_VERSION, DEFAULT_PAGE_SIZE, fetchGallery, fetchItem, fetchSetItemsByPropertyValues, fetchSetPropertyValuesByPropertyVariables, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByLabel, getPropertyByLabelAndValue, getPropertyByLabelAndValues, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "0.19.8",
3
+ "version": "0.19.10",
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",