ochre-sdk 0.19.9 → 0.19.11

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,4 +1,4 @@
1
- //#region src/types/main.d.ts
1
+ //#region src/types/index.d.ts
2
2
  /**
3
3
  * Represents the OCHRE API version
4
4
  */
@@ -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,20 +968,37 @@ 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>;
975
975
  startIcon: string | null;
976
976
  endIcon: string | null;
977
977
  }>;
978
+ options: {
979
+ attributeFilters: {
980
+ bibliographies: boolean;
981
+ periods: boolean;
982
+ };
983
+ scopes: Array<Scope> | null;
984
+ contexts: PropertyContexts | null;
985
+ labels: {
986
+ title: string | null;
987
+ };
988
+ };
978
989
  displayedProperties: Array<{
979
990
  uuid: string;
980
991
  label: string;
981
992
  }> | null;
982
- itemVariant: "detailed" | "card" | "tile";
983
- paginationVariant: "default" | "numeric";
984
- layout: "image-top" | "image-bottom" | "image-start" | "image-end";
993
+ itemVariant: Extract<WebElementComponent, {
994
+ component: "collection";
995
+ }>["itemVariant"];
996
+ paginationVariant: Extract<WebElementComponent, {
997
+ component: "collection";
998
+ }>["paginationVariant"];
999
+ layout: Extract<WebElementComponent, {
1000
+ component: "collection";
1001
+ }>["layout"];
985
1002
  } | {
986
1003
  component: "search-bar";
987
1004
  queryVariant: "submit" | "change";
@@ -1123,18 +1140,17 @@ declare function fetchItem<T extends DataCategory = DataCategory, U extends Data
1123
1140
  item: never;
1124
1141
  }>;
1125
1142
  //#endregion
1126
- //#region src/utils/fetchers/items-by-property-values.d.ts
1143
+ //#region src/utils/fetchers/set/items-by-property-values.d.ts
1127
1144
  /**
1128
1145
  * Fetches and parses items by property values from the OCHRE API
1129
1146
  *
1130
1147
  * @param params - The parameters for the fetch
1131
- * @param params.projectScopeUuid - The UUID of the project scope
1148
+ * @param params.setScopeUuids - The Set scope UUIDs to filter by
1132
1149
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
1133
1150
  * @param params.propertyVariableUuids - The property variable UUIDs to query by
1134
1151
  * @param params.propertyValues - The property values to query by
1135
1152
  * @param params.page - The page number (1-indexed)
1136
1153
  * @param params.pageSize - The number of items per page
1137
- * @param params.itemCategory - The category of the items to fetch
1138
1154
  * @param params.includeChildItems - Whether to include child items of the same category
1139
1155
  * @param categoryParams - The category parameters for the fetch
1140
1156
  * @param categoryParams.category - The category of the items to fetch
@@ -1144,8 +1160,8 @@ declare function fetchItem<T extends DataCategory = DataCategory, U extends Data
1144
1160
  * @param options.version - The version of the OCHRE API to use
1145
1161
  * @returns The parsed items by property values or null if the fetch/parse fails
1146
1162
  */
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;
1163
+ 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: {
1164
+ setScopeUuids: Array<string>;
1149
1165
  belongsToCollectionScopeUuids: Array<string>;
1150
1166
  propertyVariableUuids: Array<string>;
1151
1167
  propertyValues: Array<{
@@ -1154,7 +1170,6 @@ declare function fetchItemsByPropertyValues<T extends DataCategory = DataCategor
1154
1170
  }>;
1155
1171
  page: number;
1156
1172
  pageSize?: number;
1157
- itemCategory?: "resource" | "spatialUnit" | "concept" | "text";
1158
1173
  includeChildItems?: boolean;
1159
1174
  }, categoryParams?: {
1160
1175
  category?: T;
@@ -1176,31 +1191,31 @@ declare function fetchItemsByPropertyValues<T extends DataCategory = DataCategor
1176
1191
  error: string;
1177
1192
  }>;
1178
1193
  //#endregion
1179
- //#region src/utils/fetchers/property-values-by-property-variables.d.ts
1194
+ //#region src/utils/fetchers/set/property-values-by-property-variables.d.ts
1180
1195
  /**
1181
- * Fetches and parses property values by property variables from the OCHRE API
1196
+ * Fetches and parses Set property values by property variables from the OCHRE API
1182
1197
  *
1183
1198
  * @param params - The parameters for the fetch
1184
- * @param params.projectScopeUuid - The UUID of the project scope
1199
+ * @param params.setScopeUuids - An array of set scope UUIDs to filter by
1185
1200
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
1186
1201
  * @param params.propertyVariableUuids - The property variable UUIDs to query by
1187
1202
  * @param options - Options for the fetch
1188
1203
  * @param options.fetch - The fetch function to use
1189
1204
  * @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
1205
+ * @returns The parsed Set property values by property variables or null if the fetch/parse fails
1191
1206
  */
1192
- declare function fetchPropertyValuesByPropertyVariables(params: {
1193
- projectScopeUuid: string;
1207
+ declare function fetchSetPropertyValuesByPropertyVariables(params: {
1208
+ setScopeUuids: Array<string>;
1194
1209
  belongsToCollectionScopeUuids: Array<string>;
1195
1210
  propertyVariableUuids: Array<string>;
1196
1211
  }, options?: {
1197
1212
  fetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
1198
1213
  version?: ApiVersion;
1199
1214
  }): Promise<{
1200
- items: Array<PropertyValueQueryItem> | null;
1215
+ propertyValues: Array<PropertyValueQueryItem> | null;
1201
1216
  error: null;
1202
1217
  } | {
1203
- items: null;
1218
+ propertyValues: null;
1204
1219
  error: string;
1205
1220
  }>;
1206
1221
  //#endregion
@@ -1363,4 +1378,4 @@ declare const DEFAULT_PAGE_SIZE = 48;
1363
1378
  */
1364
1379
  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
1380
  //#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 };
1381
+ 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
@@ -552,6 +552,40 @@ function cleanObject(object) {
552
552
  return Object.fromEntries(Object.entries(object).filter(([_, value]) => value != null));
553
553
  }
554
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
+ }
588
+
555
589
  //#endregion
556
590
  //#region src/schemas.ts
557
591
  /**
@@ -718,40 +752,40 @@ const boundsSchema = z.string().transform((str, ctx) => {
718
752
  return z.NEVER;
719
753
  }
720
754
  }).pipe(z.tuple([z.tuple([z.number(), z.number()]), z.tuple([z.number(), z.number()])], { message: "Must contain exactly 2 coordinate pairs" }));
721
-
722
- //#endregion
723
- //#region src/utils/helpers.ts
724
- /**
725
- * The default API version to use
726
- *
727
- * @remarks
728
- * Version 1 of the OCHRE API is deprecated and will be removed in the future.
729
- * It points to the old Tamino server.
730
- *
731
- * Version 2 of the OCHRE API is the current version and is the default.
732
- * It points to the new MarkLogic server.
733
- */
734
- const DEFAULT_API_VERSION = 2;
735
755
  /**
736
- * The default page size to use for fetching paginated items
737
- */
738
- const DEFAULT_PAGE_SIZE = 48;
739
- /**
740
- * Flatten the properties of an item
741
- * @param item - The item whose properties to flatten
742
- * @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
743
758
  */
744
- function flattenItemProperties(item) {
745
- const allProperties = [];
746
- if ("properties" in item) allProperties.push(...item.properties);
747
- if ("observations" in item) for (const observation of item.observations) allProperties.push(...observation.properties);
748
- if ("interpretations" in item) for (const interpretation of item.interpretations) allProperties.push(...interpretation.properties);
749
- if ("bibliographies" in item) for (const bibliography of item.bibliographies) allProperties.push(...bibliography.properties);
750
- return {
751
- ...item,
752
- properties: flattenProperties(allProperties)
753
- };
754
- }
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
+ });
755
789
 
756
790
  //#endregion
757
791
  //#region src/utils/parse/index.ts
@@ -1992,15 +2026,14 @@ async function fetchItem(uuid, category, itemCategories, options) {
1992
2026
  }
1993
2027
 
1994
2028
  //#endregion
1995
- //#region src/utils/fetchers/items-by-property-values.ts
2029
+ //#region src/utils/fetchers/set/items-by-property-values.ts
1996
2030
  /**
1997
2031
  * Build an XQuery string to fetch items by property values from the OCHRE API
1998
2032
  * @param params - The parameters for the fetch
1999
- * @param params.projectScopeUuid - The UUID of the project scope
2033
+ * @param params.setScopeUuids - An array of Set scope UUIDs to filter by
2000
2034
  * @param params.belongsToCollectionScopeUuids - An array of collection scope UUIDs to filter by
2001
2035
  * @param params.propertyVariableUuids - An array of property variable UUIDs to fetch
2002
2036
  * @param params.propertyValues - An array of property values to fetch
2003
- * @param params.itemCategory - The category of the items to fetch
2004
2037
  * @param params.page - The page number (1-indexed)
2005
2038
  * @param params.pageSize - The number of items per page
2006
2039
  * @param params.includeChildItems - Whether to include child items of the same category
@@ -2010,9 +2043,11 @@ async function fetchItem(uuid, category, itemCategories, options) {
2010
2043
  */
2011
2044
  function buildXQuery$1(params, options) {
2012
2045
  const version = options?.version ?? DEFAULT_API_VERSION;
2013
- const { propertyVariableUuids, propertyValues, projectScopeUuid, belongsToCollectionScopeUuids, itemCategory, page, pageSize, includeChildItems = false } = params;
2014
- const startPos = (page - 1) * pageSize + 1;
2015
- 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/*`;
2016
2051
  let belongsToCollectionScopeFilter = "";
2017
2052
  if (belongsToCollectionScopeUuids.length > 0) belongsToCollectionScopeFilter = `[.//properties[property[label/@uuid="${BELONGS_TO_COLLECTION_UUID}" and value/(${belongsToCollectionScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]]`;
2018
2053
  const propertyVariables = propertyVariableUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
@@ -2021,23 +2056,15 @@ function buildXQuery$1(params, options) {
2021
2056
  if (dataType === "date" || dataType === "dateTime" || dataType === "time" || dataType === "integer" || dataType === "decimal" || dataType === "boolean") return `value[@rawValue="${value}"]`;
2022
2057
  return `value[.="${value}"]`;
2023
2058
  }).join(" or ");
2024
- return `<ochre>{${`let $match-uuids := distinct-values(
2025
- ${version === 2 ? "doc()" : "input()"}/ochre[@uuidBelongsTo="${projectScopeUuid}"]
2059
+ return `<ochre>{${`let $items := ${version === 2 ? "doc()" : "input()"}/ochre
2060
+ ${setScopeFilter}
2026
2061
  ${belongsToCollectionScopeFilter}
2027
2062
  //property[label[${propertyVariables}]][${propertyValuesFilters}]]
2028
- /@uuid
2029
- )
2030
-
2031
- let $items := ${version === 2 ? "doc()" : "input()"}/ochre[@uuidBelongsTo="${projectScopeUuid}"]
2032
- /${itemCategory ?? "*"}[@uuid = $match-uuids
2033
- or bibliographies/bibliography/@uuid = $match-uuids]
2034
2063
 
2035
- let $unique-uuids := distinct-values($items/@uuid)
2036
- let $totalCount := count($unique-uuids)
2064
+ let $totalCount := count($items)
2037
2065
 
2038
2066
  return <items totalCount="{$totalCount}" page="${page}" pageSize="${pageSize}">{
2039
- for $uuid in $unique-uuids[position() ge ${startPos} and position() le ${endPos}]
2040
- let $item := ($items[@uuid = $uuid])[1]
2067
+ for $item in $items[position() ge ${startPosition} and position() le ${endPosition}]
2041
2068
  let $category := local-name($item)
2042
2069
  return element { node-name($item) } {
2043
2070
  $item/@*, ${includeChildItems ? "$item/node()" : "$item/node()[not(local-name(.) = $category)]"}
@@ -2048,13 +2075,12 @@ function buildXQuery$1(params, options) {
2048
2075
  * Fetches and parses items by property values from the OCHRE API
2049
2076
  *
2050
2077
  * @param params - The parameters for the fetch
2051
- * @param params.projectScopeUuid - The UUID of the project scope
2078
+ * @param params.setScopeUuids - The Set scope UUIDs to filter by
2052
2079
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
2053
2080
  * @param params.propertyVariableUuids - The property variable UUIDs to query by
2054
2081
  * @param params.propertyValues - The property values to query by
2055
2082
  * @param params.page - The page number (1-indexed)
2056
2083
  * @param params.pageSize - The number of items per page
2057
- * @param params.itemCategory - The category of the items to fetch
2058
2084
  * @param params.includeChildItems - Whether to include child items of the same category
2059
2085
  * @param categoryParams - The category parameters for the fetch
2060
2086
  * @param categoryParams.category - The category of the items to fetch
@@ -2064,17 +2090,16 @@ function buildXQuery$1(params, options) {
2064
2090
  * @param options.version - The version of the OCHRE API to use
2065
2091
  * @returns The parsed items by property values or null if the fetch/parse fails
2066
2092
  */
2067
- async function fetchItemsByPropertyValues(params, categoryParams, options) {
2093
+ async function fetchSetItemsByPropertyValues(params, categoryParams, options) {
2068
2094
  try {
2069
2095
  const version = options?.version ?? DEFAULT_API_VERSION;
2070
- 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);
2071
2097
  const { category, itemCategories } = categoryParams ?? {};
2072
2098
  const xquery = buildXQuery$1({
2073
- projectScopeUuid,
2099
+ setScopeUuids,
2074
2100
  belongsToCollectionScopeUuids,
2075
2101
  propertyVariableUuids,
2076
2102
  propertyValues,
2077
- itemCategory,
2078
2103
  includeChildItems,
2079
2104
  page,
2080
2105
  pageSize
@@ -2150,7 +2175,7 @@ async function fetchItemsByPropertyValues(params, categoryParams, options) {
2150
2175
  }
2151
2176
 
2152
2177
  //#endregion
2153
- //#region src/utils/fetchers/property-values-by-property-variables.ts
2178
+ //#region src/utils/fetchers/set/property-values-by-property-variables.ts
2154
2179
  /**
2155
2180
  * Schema for a single property value query item in the OCHRE API response
2156
2181
  */
@@ -2206,7 +2231,7 @@ const responseSchema = z.object({ result: z.union([z.object({ ochre: z.object({
2206
2231
  /**
2207
2232
  * Build an XQuery string to fetch property values by property variables from the OCHRE API
2208
2233
  * @param params - The parameters for the fetch
2209
- * @param params.projectScopeUuid - The UUID of the project scope
2234
+ * @param params.setScopeUuids - An array of set scope UUIDs to filter by
2210
2235
  * @param params.belongsToCollectionScopeUuids - An array of collection scope UUIDs to filter by
2211
2236
  * @param params.propertyVariableUuids - An array of property variable UUIDs to fetch
2212
2237
  * @param options - Options for the fetch
@@ -2215,39 +2240,41 @@ const responseSchema = z.object({ result: z.union([z.object({ ochre: z.object({
2215
2240
  */
2216
2241
  function buildXQuery(params, options) {
2217
2242
  const version = options?.version ?? DEFAULT_API_VERSION;
2218
- 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`;
2219
2246
  let collectionScopeFilter = "";
2220
2247
  if (belongsToCollectionScopeUuids.length > 0) collectionScopeFilter = `//properties[property[label/@uuid="${BELONGS_TO_COLLECTION_UUID}" and value/(${belongsToCollectionScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]]`;
2221
2248
  const propertyVariableFilters = propertyVariableUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
2222
- 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}
2223
2251
  ${collectionScopeFilter}
2224
- /*[not(self::set)]
2225
2252
  //property[label/(${propertyVariableFilters})]
2226
2253
 
2227
2254
  for $v in $matching-props/value
2228
- let $item-uuid := $v/ancestor::*[parent::ochre]/@uuid
2255
+ let $item-uuid := $v/ancestor::*[parent::items]/@uuid
2229
2256
  return <propertyValue uuid="{$v/@uuid}" rawValue="{$v/@rawValue}" dataType="{$v/@dataType}" itemUuid="{$item-uuid}">{
2230
2257
  if ($v/content) then $v/content else $v/text()
2231
2258
  }</propertyValue>`}}</ochre>`;
2232
2259
  }
2233
2260
  /**
2234
- * 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
2235
2262
  *
2236
2263
  * @param params - The parameters for the fetch
2237
- * @param params.projectScopeUuid - The UUID of the project scope
2264
+ * @param params.setScopeUuids - An array of set scope UUIDs to filter by
2238
2265
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
2239
2266
  * @param params.propertyVariableUuids - The property variable UUIDs to query by
2240
2267
  * @param options - Options for the fetch
2241
2268
  * @param options.fetch - The fetch function to use
2242
2269
  * @param options.version - The version of the OCHRE API to use
2243
- * @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
2244
2271
  */
2245
- async function fetchPropertyValuesByPropertyVariables(params, options) {
2272
+ async function fetchSetPropertyValuesByPropertyVariables(params, options) {
2246
2273
  try {
2247
2274
  const version = options?.version ?? DEFAULT_API_VERSION;
2248
- const { belongsToCollectionScopeUuids, propertyVariableUuids, projectScopeUuid } = params;
2275
+ const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids } = setPropertyValuesByPropertyVariablesParamsSchema.parse(params);
2249
2276
  const xquery = buildXQuery({
2250
- projectScopeUuid,
2277
+ setScopeUuids,
2251
2278
  belongsToCollectionScopeUuids,
2252
2279
  propertyVariableUuids
2253
2280
  }, { version });
@@ -2255,28 +2282,28 @@ async function fetchPropertyValuesByPropertyVariables(params, options) {
2255
2282
  if (!response.ok) throw new Error(`OCHRE API responded with status: ${response.status}`);
2256
2283
  const data = await response.json();
2257
2284
  const parsedResultRaw = responseSchema.parse(data);
2258
- if (Array.isArray(parsedResultRaw.result)) throw new TypeError("No items found");
2259
- const parsedItems = Array.isArray(parsedResultRaw.result.ochre.propertyValue) ? parsedResultRaw.result.ochre.propertyValue : [parsedResultRaw.result.ochre.propertyValue];
2260
- const groupedItemsMap = /* @__PURE__ */ new Map();
2261
- for (const item of parsedItems) {
2262
- const existing = groupedItemsMap.get(item.content);
2263
- if (existing == null) groupedItemsMap.set(item.content, {
2264
- dataType: item.dataType,
2265
- content: item.content,
2266
- label: item.label,
2267
- 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])
2268
2295
  });
2269
- else existing.itemUuids.add(item.itemUuid);
2296
+ else existing.itemUuids.add(propertyValue.itemUuid);
2270
2297
  }
2271
- const groupedItems = [];
2272
- for (const group of groupedItemsMap.values()) groupedItems.push({
2298
+ const groupedPropertyValues = [];
2299
+ for (const group of groupedPropertyValuesMap.values()) groupedPropertyValues.push({
2273
2300
  count: group.itemUuids.size,
2274
2301
  dataType: group.dataType,
2275
2302
  content: group.content,
2276
2303
  label: group.label
2277
2304
  });
2278
2305
  return {
2279
- items: groupedItems.toSorted((a, b) => {
2306
+ propertyValues: groupedPropertyValues.filter((propertyValue) => propertyValue.content !== null).toSorted((a, b) => {
2280
2307
  if (a.count !== b.count) return b.count - a.count;
2281
2308
  if (a.label !== b.label) return a.label?.localeCompare(b.label ?? "") ?? 0;
2282
2309
  return a.content?.toString().localeCompare(b.content?.toString() ?? "") ?? 0;
@@ -2286,7 +2313,7 @@ async function fetchPropertyValuesByPropertyVariables(params, options) {
2286
2313
  } catch (error) {
2287
2314
  console.error(error);
2288
2315
  return {
2289
- items: null,
2316
+ propertyValues: null,
2290
2317
  error: error instanceof Error ? error.message : "Failed to fetch property values by property variables"
2291
2318
  };
2292
2319
  }
@@ -2765,8 +2792,8 @@ function parseWebElementProperties(componentProperty, elementResource) {
2765
2792
  break;
2766
2793
  }
2767
2794
  case "collection": {
2768
- const collectionLinks = links.filter((link) => link.category === "set");
2769
- 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}”`);
2770
2797
  const displayedProperties = getPropertyByLabel(componentProperty.properties, "use-property");
2771
2798
  let variant = getPropertyValueByLabel(componentProperty.properties, "variant");
2772
2799
  variant ??= "full";
@@ -2818,7 +2845,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
2818
2845
  }
2819
2846
  properties = {
2820
2847
  component: "collection",
2821
- linkUuids: collectionLinks.map((link) => link.uuid).filter((uuid) => uuid !== null),
2848
+ linkUuids: setLinks.map((link) => link.uuid).filter((uuid) => uuid !== null),
2822
2849
  displayedProperties: displayedProperties?.values.filter(({ uuid }) => uuid !== null).map((value) => ({
2823
2850
  uuid: value.uuid,
2824
2851
  label: value.content?.toString() ?? ""
@@ -3028,9 +3055,9 @@ function parseWebElementProperties(componentProperty, elementResource) {
3028
3055
  break;
3029
3056
  }
3030
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}”`);
3031
3060
  const queries = [];
3032
- let itemCategory = getPropertyValueByLabel(componentProperty.properties, "item-category");
3033
- itemCategory ??= null;
3034
3061
  if (componentProperty.properties.length === 0) throw new Error(`Query properties not found for the following component: “${componentName}”`);
3035
3062
  for (const query of componentProperty.properties) {
3036
3063
  const querySubProperties = query.properties;
@@ -3049,6 +3076,26 @@ function parseWebElementProperties(componentProperty, elementResource) {
3049
3076
  });
3050
3077
  }
3051
3078
  if (queries.length === 0) throw new Error(`No queries found for the following component: “${componentName}”`);
3079
+ const options = {
3080
+ attributeFilters: {
3081
+ bibliographies: elementResource.options?.filterBibliography ?? false,
3082
+ periods: elementResource.options?.filterPeriods ?? false
3083
+ },
3084
+ scopes: elementResource.options?.scopes != null ? ensureArray(elementResource.options.scopes.scope).map((scope) => ({
3085
+ uuid: scope.uuid.content,
3086
+ type: scope.uuid.type,
3087
+ identification: parseIdentification(scope.identification)
3088
+ })) : null,
3089
+ contexts: null,
3090
+ labels: { title: null }
3091
+ };
3092
+ if ("options" in elementResource && elementResource.options) {
3093
+ options.contexts = parseAllOptionContexts(elementResource.options);
3094
+ if ("notes" in elementResource.options && elementResource.options.notes) {
3095
+ const labelNotes = parseNotes(ensureArray(elementResource.options.notes.note));
3096
+ options.labels.title = labelNotes.find((note) => note.title === "Title label")?.content ?? null;
3097
+ }
3098
+ }
3052
3099
  const displayedProperties = getPropertyByLabel(componentProperty.properties, "use-property");
3053
3100
  let itemVariant = getPropertyValueByLabel(componentProperty.properties, "item-variant");
3054
3101
  itemVariant ??= "detailed";
@@ -3058,8 +3105,9 @@ function parseWebElementProperties(componentProperty, elementResource) {
3058
3105
  layout ??= "image-start";
3059
3106
  properties = {
3060
3107
  component: "query",
3061
- itemCategory,
3108
+ linkUuids: setLinks.map((link) => link.uuid).filter((uuid) => uuid !== null),
3062
3109
  queries,
3110
+ options,
3063
3111
  displayedProperties: displayedProperties?.values.filter((value) => value.uuid !== null).map((value) => ({
3064
3112
  uuid: value.uuid,
3065
3113
  label: value.content?.toString() ?? ""
@@ -3863,4 +3911,4 @@ async function fetchWebsite(abbreviation, options) {
3863
3911
  }
3864
3912
 
3865
3913
  //#endregion
3866
- 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 };
3914
+ 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.9",
3
+ "version": "0.19.11",
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",