ochre-sdk 0.19.15 → 0.20.1

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
@@ -643,6 +643,25 @@ type PropertyValueQueryItem = {
643
643
  content: string | number | boolean | null;
644
644
  label: string | null;
645
645
  };
646
+ /**
647
+ * Represents a query for Set items
648
+ */
649
+ type Query = {
650
+ target: "propertyValue";
651
+ dataType: Exclude<PropertyValueContentType, "coordinate">;
652
+ value: string;
653
+ matchMode: "includes" | "exact";
654
+ isCaseSensitive: boolean;
655
+ language: string;
656
+ operator?: "AND" | "OR";
657
+ } | {
658
+ target: "title" | "description" | "image" | "periods" | "bibliography";
659
+ value: string;
660
+ matchMode: "includes" | "exact";
661
+ isCaseSensitive: boolean;
662
+ language: string;
663
+ operator?: "AND" | "OR";
664
+ };
646
665
  //#endregion
647
666
  //#region src/types/website.d.ts
648
667
  /**
@@ -1144,48 +1163,38 @@ declare function fetchItem<T extends DataCategory = DataCategory, U extends Data
1144
1163
  item: never;
1145
1164
  }>;
1146
1165
  //#endregion
1147
- //#region src/utils/fetchers/set/items-by-property-values.d.ts
1166
+ //#region src/utils/fetchers/set/items.d.ts
1148
1167
  /**
1149
- * Fetches and parses items by property values from the OCHRE API
1168
+ * Fetches and parses Set items from the OCHRE API
1150
1169
  *
1151
1170
  * @param params - The parameters for the fetch
1152
1171
  * @param params.setScopeUuids - The Set scope UUIDs to filter by
1153
1172
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
1154
- * @param params.propertyVariableUuids - The property variable UUIDs to query by
1155
- * @param params.propertyValues - The property values to query by
1173
+ * @param params.propertyVariableUuids - The property variable UUIDs to filter by
1174
+ * @param params.queries - Ordered queries to combine with AND/OR
1156
1175
  * @param params.page - The page number (1-indexed)
1157
1176
  * @param params.pageSize - The number of items per page
1158
- * @param params.includeChildItems - Whether to include child items of the same category
1159
- * @param categoryParams - The category parameters for the fetch
1160
- * @param categoryParams.category - The category of the items to fetch
1161
- * @param categoryParams.itemCategories - The categories of the items to fetch
1177
+ * @param itemCategories - The categories of the items to fetch
1162
1178
  * @param options - Options for the fetch
1163
1179
  * @param options.fetch - The fetch function to use
1164
1180
  * @param options.version - The version of the OCHRE API to use
1165
- * @returns The parsed items by property values or null if the fetch/parse fails
1181
+ * @returns The parsed Set items or null if the fetch/parse fails
1166
1182
  */
1167
- 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: {
1183
+ declare function fetchSetItems<U extends Array<DataCategory> = Array<DataCategory>>(params: {
1168
1184
  setScopeUuids: Array<string>;
1169
1185
  belongsToCollectionScopeUuids: Array<string>;
1170
1186
  propertyVariableUuids: Array<string>;
1171
- propertyValues: Array<{
1172
- dataType: Exclude<PropertyValueContentType, "coordinate">;
1173
- value: string;
1174
- }>;
1187
+ queries: Array<Query>;
1175
1188
  page: number;
1176
1189
  pageSize?: number;
1177
- includeChildItems?: boolean;
1178
- }, categoryParams?: {
1179
- category?: T;
1180
- itemCategories?: U;
1181
- }, options?: {
1190
+ }, itemCategories?: U, options?: {
1182
1191
  fetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
1183
1192
  version?: ApiVersion;
1184
1193
  }): Promise<{
1185
1194
  totalCount: number;
1186
1195
  page: number;
1187
1196
  pageSize: number;
1188
- items: Array<Item<T, U>>;
1197
+ items: Array<Item<"set", U>>;
1189
1198
  error: null;
1190
1199
  } | {
1191
1200
  totalCount: null;
@@ -1382,4 +1391,4 @@ declare const DEFAULT_PAGE_SIZE = 48;
1382
1391
  */
1383
1392
  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>;
1384
1393
  //#endregion
1385
- 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 };
1394
+ 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, Query, Resource, Scope, Section, Set, SpatialUnit, Style, Text, Tree, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebSegment, WebSegmentItem, WebTitle, Webpage, Website, WebsiteType, fetchGallery, fetchItem, fetchSetItems, fetchSetPropertyValuesByPropertyVariables, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByLabel, getPropertyByLabelAndValue, getPropertyByLabelAndValues, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
package/dist/index.mjs CHANGED
@@ -551,6 +551,14 @@ function parseOptionalDate(dateTime) {
551
551
  function cleanObject(object) {
552
552
  return Object.fromEntries(Object.entries(object).filter(([_, value]) => value != null));
553
553
  }
554
+ /**
555
+ * Build a string literal for an XQuery string
556
+ * @param value - The string value to escape
557
+ * @returns The escaped string literal
558
+ */
559
+ function stringLiteral(value) {
560
+ return `"${value.replaceAll("\"", "\"\"")}"`;
561
+ }
554
562
 
555
563
  //#endregion
556
564
  //#region src/utils/helpers.ts
@@ -760,9 +768,12 @@ const setPropertyValuesByPropertyVariablesParamsSchema = z.object({
760
768
  belongsToCollectionScopeUuids: z.array(uuidSchema).default([]),
761
769
  propertyVariableUuids: z.array(uuidSchema).min(1, "At least one property variable UUID is required")
762
770
  });
763
- const setItemsByPropertyValuesParamsSchema = z.object({
764
- ...setPropertyValuesByPropertyVariablesParamsSchema.shape,
765
- propertyValues: z.array(z.object({
771
+ const setItemsParamsSchema = z.object({
772
+ setScopeUuids: z.array(uuidSchema).min(1, "At least one set scope UUID is required"),
773
+ belongsToCollectionScopeUuids: z.array(uuidSchema).default([]),
774
+ propertyVariableUuids: z.array(uuidSchema).default([]),
775
+ queries: z.array(z.discriminatedUnion("target", [z.object({
776
+ target: z.literal("propertyValue"),
766
777
  dataType: z.enum([
767
778
  "string",
768
779
  "integer",
@@ -773,17 +784,48 @@ const setItemsByPropertyValuesParamsSchema = z.object({
773
784
  "time",
774
785
  "IDREF"
775
786
  ]),
776
- value: z.string()
777
- })).min(1, "At least one property value is required"),
778
- page: z.number().min(1, "Page must be at least 1").default(1),
779
- pageSize: z.number().min(1, "Page size must be at least 1").default(DEFAULT_PAGE_SIZE),
780
- itemCategory: z.enum([
781
- "resource",
782
- "spatialUnit",
783
- "concept",
784
- "text"
785
- ]).optional(),
786
- includeChildItems: z.boolean().optional().default(false)
787
+ value: z.string(),
788
+ matchMode: z.enum(["includes", "exact"]),
789
+ isCaseSensitive: z.boolean(),
790
+ language: z.string().default("eng"),
791
+ operator: z.enum(["AND", "OR"]).optional()
792
+ }), z.object({
793
+ target: z.enum([
794
+ "title",
795
+ "description",
796
+ "image",
797
+ "periods",
798
+ "bibliography"
799
+ ]),
800
+ value: z.string(),
801
+ matchMode: z.enum(["includes", "exact"]),
802
+ isCaseSensitive: z.boolean(),
803
+ language: z.string().default("eng"),
804
+ operator: z.enum(["AND", "OR"]).optional()
805
+ })])).default([]),
806
+ page: z.number().min(1, "Page must be positive").default(1),
807
+ pageSize: z.number().min(1, "Page size must be positive").default(DEFAULT_PAGE_SIZE)
808
+ }).superRefine((value, ctx) => {
809
+ for (const [index, query] of value.queries.entries()) {
810
+ if (index === 0 && query.operator != null) ctx.addIssue({
811
+ code: "custom",
812
+ path: [
813
+ "queries",
814
+ index,
815
+ "operator"
816
+ ],
817
+ message: "The first query rule must not include an operator"
818
+ });
819
+ if (index > 0 && query.operator == null) ctx.addIssue({
820
+ code: "custom",
821
+ path: [
822
+ "queries",
823
+ index,
824
+ "operator"
825
+ ],
826
+ message: "Query rules after the first must include an operator"
827
+ });
828
+ }
787
829
  });
788
830
 
789
831
  //#endregion
@@ -2029,132 +2071,201 @@ async function fetchItem(uuid, category, itemCategories, options) {
2029
2071
  }
2030
2072
 
2031
2073
  //#endregion
2032
- //#region src/utils/fetchers/set/items-by-property-values.ts
2074
+ //#region src/utils/fetchers/set/items.ts
2075
+ /**
2076
+ * Build a string match predicate for an XQuery string
2077
+ * @param params - The parameters for the predicate
2078
+ * @param params.path - The path to the string
2079
+ * @param params.value - The value to match
2080
+ * @param params.matchMode - The match mode (includes or exact)
2081
+ * @param params.isCaseSensitive - Whether to match case-sensitively
2082
+ * @returns The string match predicate
2083
+ */
2084
+ function buildStringMatchPredicate(params) {
2085
+ const { path, value, matchMode, isCaseSensitive } = params;
2086
+ const comparedPath = isCaseSensitive ? path : `lower-case(${path})`;
2087
+ const comparedValueLiteral = stringLiteral(isCaseSensitive ? value : value.toLowerCase());
2088
+ if (matchMode === "includes") return `contains(${comparedPath}, ${comparedValueLiteral})`;
2089
+ return `${comparedPath} = ${comparedValueLiteral}`;
2090
+ }
2091
+ /**
2092
+ * Build a property value predicate for an XQuery string
2093
+ * @param query - The propertyValue query
2094
+ * @returns The property value predicate
2095
+ */
2096
+ function buildPropertyValuePredicate(query) {
2097
+ if (query.dataType === "IDREF") return `.//properties//property[value[@uuid=${stringLiteral(query.value)}]]`;
2098
+ if (query.dataType === "date" || query.dataType === "dateTime" || query.dataType === "time" || query.dataType === "integer" || query.dataType === "decimal" || query.dataType === "boolean") return `.//properties//property[value[@rawValue=${stringLiteral(query.value)}]]`;
2099
+ return `.//properties//property[${buildStringMatchPredicate({
2100
+ path: `string-join(value/content[@xml:lang="${query.language}"]/string, "")`,
2101
+ value: query.value,
2102
+ matchMode: query.matchMode,
2103
+ isCaseSensitive: query.isCaseSensitive
2104
+ })}]`;
2105
+ }
2106
+ /**
2107
+ * Build a query predicate for an XQuery string
2108
+ * @param query - The query to build the predicate for
2109
+ * @returns The query predicate
2110
+ */
2111
+ function buildQueryPredicate(query) {
2112
+ const stringMatchParams = {
2113
+ value: query.value,
2114
+ matchMode: query.matchMode,
2115
+ isCaseSensitive: query.isCaseSensitive,
2116
+ language: query.language
2117
+ };
2118
+ switch (query.target) {
2119
+ case "title": return buildStringMatchPredicate({
2120
+ path: `string-join(identification/label/content[@xml:lang="${query.language}"]/string, "")`,
2121
+ ...stringMatchParams
2122
+ });
2123
+ case "description": return buildStringMatchPredicate({
2124
+ path: `string-join(description/content[@xml:lang="${query.language}"]/string, "")`,
2125
+ ...stringMatchParams
2126
+ });
2127
+ case "periods": return buildStringMatchPredicate({
2128
+ path: `string-join(periods/period/identification/label/content[@xml:lang="${query.language}"]/string, "")`,
2129
+ ...stringMatchParams
2130
+ });
2131
+ case "bibliography": return buildStringMatchPredicate({
2132
+ path: `string-join(bibliographies/bibliography/identification/label/content[@xml:lang="${query.language}"]/string, "")`,
2133
+ ...stringMatchParams
2134
+ });
2135
+ case "image": return buildStringMatchPredicate({
2136
+ path: `string-join(image/identification/label/content[@xml:lang="${query.language}"]/string, "")`,
2137
+ ...stringMatchParams
2138
+ });
2139
+ case "propertyValue": return buildPropertyValuePredicate(query);
2140
+ }
2141
+ }
2033
2142
  /**
2034
- * Build an XQuery string to fetch items by property values from the OCHRE API
2143
+ * Build an XQuery string to fetch Set items from the OCHRE API
2035
2144
  * @param params - The parameters for the fetch
2036
2145
  * @param params.setScopeUuids - An array of Set scope UUIDs to filter by
2037
2146
  * @param params.belongsToCollectionScopeUuids - An array of collection scope UUIDs to filter by
2038
- * @param params.propertyVariableUuids - An array of property variable UUIDs to fetch
2039
- * @param params.propertyValues - An array of property values to fetch
2147
+ * @param params.propertyVariableUuids - An array of property variable UUIDs to filter by
2148
+ * @param params.queries - Ordered queries to combine with AND/OR
2040
2149
  * @param params.page - The page number (1-indexed)
2041
2150
  * @param params.pageSize - The number of items per page
2042
- * @param params.includeChildItems - Whether to include child items of the same category
2043
2151
  * @param options - Options for the fetch
2044
2152
  * @param options.version - The version of the OCHRE API to use
2045
2153
  * @returns An XQuery string
2046
2154
  */
2047
2155
  function buildXQuery$1(params, options) {
2048
2156
  const version = options?.version ?? DEFAULT_API_VERSION;
2049
- const { propertyVariableUuids, propertyValues, setScopeUuids, belongsToCollectionScopeUuids, page, pageSize, includeChildItems = false } = params;
2157
+ const { propertyVariableUuids, queries, setScopeUuids, belongsToCollectionScopeUuids, page, pageSize } = params;
2050
2158
  const startPosition = (page - 1) * pageSize + 1;
2051
2159
  const endPosition = page * pageSize;
2052
- let setScopeFilter = "";
2053
- if (setScopeUuids.length > 0) setScopeFilter = `/set[(${setScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]/items/*`;
2054
- let belongsToCollectionScopeFilter = "";
2055
- if (belongsToCollectionScopeUuids.length > 0) belongsToCollectionScopeFilter = `[.//properties[property[label/@uuid="${BELONGS_TO_COLLECTION_UUID}" and value/(${belongsToCollectionScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]]`;
2056
- const propertyVariables = propertyVariableUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
2057
- const propertyValuesFilters = propertyValues.map(({ dataType, value }) => {
2058
- if (dataType === "IDREF") return `value[@uuid="${value}"]`;
2059
- if (dataType === "date" || dataType === "dateTime" || dataType === "time" || dataType === "integer" || dataType === "decimal" || dataType === "boolean") return `value[@rawValue="${value}"]`;
2060
- return `value[.="${value}"]`;
2061
- }).join(" or ");
2160
+ const setScopeFilter = `/set[(${setScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]/items/*`;
2161
+ const queryFilters = queries.map((query, index) => {
2162
+ const predicate = `(${buildQueryPredicate(query)})`;
2163
+ if (index === 0) return predicate;
2164
+ return `${query.operator === "OR" ? "or" : "and"} ${predicate}`;
2165
+ }).join(" ");
2166
+ const filterPredicates = [];
2167
+ if (belongsToCollectionScopeUuids.length > 0) {
2168
+ const belongsToCollectionScopeValues = belongsToCollectionScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
2169
+ filterPredicates.push(`.//properties[property[label/@uuid="${BELONGS_TO_COLLECTION_UUID}" and value/(${belongsToCollectionScopeValues})]]`);
2170
+ }
2171
+ if (propertyVariableUuids.length > 0) {
2172
+ const propertyVariables = propertyVariableUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
2173
+ filterPredicates.push(`.//properties//property[label[${propertyVariables}]]`);
2174
+ }
2175
+ if (queryFilters.length > 0) filterPredicates.push(`(${queryFilters})`);
2176
+ const itemFilters = filterPredicates.length > 0 ? `[${filterPredicates.join(" and ")}]` : "";
2062
2177
  return `<ochre>{${`let $items := ${version === 2 ? "doc()" : "input()"}/ochre
2063
2178
  ${setScopeFilter}
2064
- ${belongsToCollectionScopeFilter}
2065
- //property[label[${propertyVariables}]][${propertyValuesFilters}]]
2179
+ ${itemFilters}
2066
2180
 
2067
2181
  let $totalCount := count($items)
2068
2182
 
2069
2183
  return <items totalCount="{$totalCount}" page="${page}" pageSize="${pageSize}">{
2070
2184
  for $item in $items[position() ge ${startPosition} and position() le ${endPosition}]
2071
- let $category := local-name($item)
2072
2185
  return element { node-name($item) } {
2073
- $item/@*, ${includeChildItems ? "$item/node()" : "$item/node()[not(local-name(.) = $category)]"}
2186
+ $item/@*, $item/node()
2074
2187
  }
2075
2188
  }</items>`}}</ochre>`;
2076
2189
  }
2077
2190
  /**
2078
- * Fetches and parses items by property values from the OCHRE API
2191
+ * Fetches and parses Set items from the OCHRE API
2079
2192
  *
2080
2193
  * @param params - The parameters for the fetch
2081
2194
  * @param params.setScopeUuids - The Set scope UUIDs to filter by
2082
2195
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
2083
- * @param params.propertyVariableUuids - The property variable UUIDs to query by
2084
- * @param params.propertyValues - The property values to query by
2196
+ * @param params.propertyVariableUuids - The property variable UUIDs to filter by
2197
+ * @param params.queries - Ordered queries to combine with AND/OR
2085
2198
  * @param params.page - The page number (1-indexed)
2086
2199
  * @param params.pageSize - The number of items per page
2087
- * @param params.includeChildItems - Whether to include child items of the same category
2088
- * @param categoryParams - The category parameters for the fetch
2089
- * @param categoryParams.category - The category of the items to fetch
2090
- * @param categoryParams.itemCategories - The categories of the items to fetch
2200
+ * @param itemCategories - The categories of the items to fetch
2091
2201
  * @param options - Options for the fetch
2092
2202
  * @param options.fetch - The fetch function to use
2093
2203
  * @param options.version - The version of the OCHRE API to use
2094
- * @returns The parsed items by property values or null if the fetch/parse fails
2204
+ * @returns The parsed Set items or null if the fetch/parse fails
2095
2205
  */
2096
- async function fetchSetItemsByPropertyValues(params, categoryParams, options) {
2206
+ async function fetchSetItems(params, itemCategories, options) {
2097
2207
  try {
2098
2208
  const version = options?.version ?? DEFAULT_API_VERSION;
2099
- const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids, propertyValues, page, pageSize, includeChildItems } = setItemsByPropertyValuesParamsSchema.parse(params);
2100
- const { category, itemCategories } = categoryParams ?? {};
2209
+ const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids, queries, page, pageSize } = setItemsParamsSchema.parse(params);
2101
2210
  const xquery = buildXQuery$1({
2102
2211
  setScopeUuids,
2103
2212
  belongsToCollectionScopeUuids,
2104
2213
  propertyVariableUuids,
2105
- propertyValues,
2106
- includeChildItems,
2214
+ queries,
2107
2215
  page,
2108
2216
  pageSize
2109
2217
  }, { version });
2110
2218
  const response = await (options?.fetch ?? fetch)(version === 2 ? `https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?xquery=${encodeURIComponent(xquery)}&format=json&lang="*"` : `https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(xquery)}&format=json&lang="*"`);
2111
2219
  if (!response.ok) throw new Error(`OCHRE API responded with status: ${response.status}`);
2112
2220
  const data = await response.json();
2113
- if (Array.isArray(data.result) || Object.keys(data.result.ochre).length === 0) throw new Error("No items found");
2114
- if (category != null && data.result.ochre.items[category] == null) throw new Error(`No items found for category: ${category}`);
2115
- if ((category === "set" || category === "tree") && itemCategories != null && "items" in data.result.ochre.items[category] && Array.isArray(data.result.ochre.items[category].items) && data.result.ochre.items[category].items.every((item) => item.category !== itemCategories)) throw new Error(`No items found for category: ${category} and item categories: ${itemCategories}`);
2221
+ if (Array.isArray(data.result) || Object.keys(data.result).length === 0) throw new Error("No items found");
2222
+ if (itemCategories != null) {
2223
+ const itemCategoriesSet = new Set(Object.keys(data.result.ochre.items));
2224
+ const missingCategories = itemCategories.filter((category) => !itemCategoriesSet.has(category));
2225
+ if (missingCategories.length > 0) throw new Error(`No Set items found for item categories: ${missingCategories.join(", ")}`);
2226
+ }
2116
2227
  const items = [];
2117
- if ("resource" in data.result.ochre.items && data.result.ochre.items.resource != null) {
2228
+ if ((itemCategories == null || itemCategories.includes("resource")) && "resource" in data.result.ochre.items && data.result.ochre.items.resource != null) {
2118
2229
  const resources = parseResources(Array.isArray(data.result.ochre.items.resource) ? data.result.ochre.items.resource : [data.result.ochre.items.resource]);
2119
2230
  items.push(...resources);
2120
2231
  }
2121
- if ("spatialUnit" in data.result.ochre.items && data.result.ochre.items.spatialUnit != null) {
2232
+ if ((itemCategories == null || itemCategories.includes("spatialUnit")) && "spatialUnit" in data.result.ochre.items && data.result.ochre.items.spatialUnit != null) {
2122
2233
  const spatialUnits = parseSpatialUnits(Array.isArray(data.result.ochre.items.spatialUnit) ? data.result.ochre.items.spatialUnit : [data.result.ochre.items.spatialUnit]);
2123
2234
  items.push(...spatialUnits);
2124
2235
  }
2125
- if ("concept" in data.result.ochre.items && data.result.ochre.items.concept != null) {
2236
+ if ((itemCategories == null || itemCategories.includes("concept")) && "concept" in data.result.ochre.items && data.result.ochre.items.concept != null) {
2126
2237
  const concepts = parseConcepts(Array.isArray(data.result.ochre.items.concept) ? data.result.ochre.items.concept : [data.result.ochre.items.concept]);
2127
2238
  items.push(...concepts);
2128
2239
  }
2129
- if ("period" in data.result.ochre.items && data.result.ochre.items.period != null) {
2240
+ if ((itemCategories == null || itemCategories.includes("period")) && "period" in data.result.ochre.items && data.result.ochre.items.period != null) {
2130
2241
  const periods = parsePeriods(Array.isArray(data.result.ochre.items.period) ? data.result.ochre.items.period : [data.result.ochre.items.period]);
2131
2242
  items.push(...periods);
2132
2243
  }
2133
- if ("bibliography" in data.result.ochre.items && data.result.ochre.items.bibliography != null) {
2244
+ if ((itemCategories == null || itemCategories.includes("bibliography")) && "bibliography" in data.result.ochre.items && data.result.ochre.items.bibliography != null) {
2134
2245
  const bibliographies = parseBibliographies(Array.isArray(data.result.ochre.items.bibliography) ? data.result.ochre.items.bibliography : [data.result.ochre.items.bibliography]);
2135
2246
  items.push(...bibliographies);
2136
2247
  }
2137
- if ("person" in data.result.ochre.items && data.result.ochre.items.person != null) {
2248
+ if ((itemCategories == null || itemCategories.includes("person")) && "person" in data.result.ochre.items && data.result.ochre.items.person != null) {
2138
2249
  const persons = parsePersons(Array.isArray(data.result.ochre.items.person) ? data.result.ochre.items.person : [data.result.ochre.items.person]);
2139
2250
  items.push(...persons);
2140
2251
  }
2141
- if ("propertyVariable" in data.result.ochre.items && data.result.ochre.items.propertyVariable != null) {
2252
+ if ((itemCategories == null || itemCategories.includes("propertyVariable")) && "propertyVariable" in data.result.ochre.items && data.result.ochre.items.propertyVariable != null) {
2142
2253
  const propertyVariables = parsePropertyVariables(Array.isArray(data.result.ochre.items.propertyVariable) ? data.result.ochre.items.propertyVariable : [data.result.ochre.items.propertyVariable]);
2143
2254
  items.push(...propertyVariables);
2144
2255
  }
2145
- if ("propertyValue" in data.result.ochre.items && data.result.ochre.items.propertyValue != null) {
2256
+ if ((itemCategories == null || itemCategories.includes("propertyValue")) && "propertyValue" in data.result.ochre.items && data.result.ochre.items.propertyValue != null) {
2146
2257
  const propertyValues = parsePropertyValues(Array.isArray(data.result.ochre.items.propertyValue) ? data.result.ochre.items.propertyValue : [data.result.ochre.items.propertyValue]);
2147
2258
  items.push(...propertyValues);
2148
2259
  }
2149
- if ("text" in data.result.ochre.items && data.result.ochre.items.text != null) {
2260
+ if ((itemCategories == null || itemCategories.includes("text")) && "text" in data.result.ochre.items && data.result.ochre.items.text != null) {
2150
2261
  const texts = parseTexts(Array.isArray(data.result.ochre.items.text) ? data.result.ochre.items.text : [data.result.ochre.items.text]);
2151
2262
  items.push(...texts);
2152
2263
  }
2153
- if ("set" in data.result.ochre.items && data.result.ochre.items.set != null) {
2264
+ if ((itemCategories == null || itemCategories.includes("set")) && "set" in data.result.ochre.items && data.result.ochre.items.set != null) {
2154
2265
  const sets = parseSets(Array.isArray(data.result.ochre.items.set) ? data.result.ochre.items.set : [data.result.ochre.items.set]);
2155
2266
  items.push(...sets);
2156
2267
  }
2157
- if ("tree" in data.result.ochre.items && data.result.ochre.items.tree != null) {
2268
+ if ((itemCategories == null || itemCategories.includes("tree")) && "tree" in data.result.ochre.items && data.result.ochre.items.tree != null) {
2158
2269
  const trees = parseTrees(Array.isArray(data.result.ochre.items.tree) ? data.result.ochre.items.tree : [data.result.ochre.items.tree]);
2159
2270
  items.push(...trees);
2160
2271
  }
@@ -2172,7 +2283,7 @@ async function fetchSetItemsByPropertyValues(params, categoryParams, options) {
2172
2283
  page: null,
2173
2284
  pageSize: null,
2174
2285
  items: null,
2175
- error: error instanceof Error ? error.message : "Failed to fetch items by property values"
2286
+ error: error instanceof Error ? error.message : "Failed to fetch Set items"
2176
2287
  };
2177
2288
  }
2178
2289
  }
@@ -3908,4 +4019,4 @@ async function fetchWebsite(abbreviation, options) {
3908
4019
  }
3909
4020
 
3910
4021
  //#endregion
3911
- 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 };
4022
+ export { DEFAULT_API_VERSION, DEFAULT_PAGE_SIZE, fetchGallery, fetchItem, fetchSetItems, 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.15",
3
+ "version": "0.20.1",
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",
@@ -46,7 +46,7 @@
46
46
  "zod": "^4.3.6"
47
47
  },
48
48
  "devDependencies": {
49
- "@antfu/eslint-config": "^7.5.0",
49
+ "@antfu/eslint-config": "^7.6.1",
50
50
  "@types/node": "^24.10.13",
51
51
  "bumpp": "^10.4.1",
52
52
  "eslint": "^10.0.2",