ochre-sdk 0.19.15 → 0.20.0

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,17 @@ 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: "title" | "description" | "image" | "periods" | "bibliography" | "propertyValue";
651
+ value: string;
652
+ matchMode: "includes" | "exact";
653
+ isCaseSensitive: boolean;
654
+ language: string;
655
+ operator?: "AND" | "OR";
656
+ };
646
657
  //#endregion
647
658
  //#region src/types/website.d.ts
648
659
  /**
@@ -1144,48 +1155,38 @@ declare function fetchItem<T extends DataCategory = DataCategory, U extends Data
1144
1155
  item: never;
1145
1156
  }>;
1146
1157
  //#endregion
1147
- //#region src/utils/fetchers/set/items-by-property-values.d.ts
1158
+ //#region src/utils/fetchers/set/items.d.ts
1148
1159
  /**
1149
- * Fetches and parses items by property values from the OCHRE API
1160
+ * Fetches and parses Set items from the OCHRE API
1150
1161
  *
1151
1162
  * @param params - The parameters for the fetch
1152
1163
  * @param params.setScopeUuids - The Set scope UUIDs to filter by
1153
1164
  * @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
1165
+ * @param params.propertyVariableUuids - The property variable UUIDs to filter by
1166
+ * @param params.queries - Ordered queries to combine with AND/OR
1156
1167
  * @param params.page - The page number (1-indexed)
1157
1168
  * @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
1169
+ * @param itemCategories - The categories of the items to fetch
1162
1170
  * @param options - Options for the fetch
1163
1171
  * @param options.fetch - The fetch function to use
1164
1172
  * @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
1173
+ * @returns The parsed Set items or null if the fetch/parse fails
1166
1174
  */
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: {
1175
+ declare function fetchSetItems<U extends Array<DataCategory> = Array<DataCategory>>(params: {
1168
1176
  setScopeUuids: Array<string>;
1169
1177
  belongsToCollectionScopeUuids: Array<string>;
1170
1178
  propertyVariableUuids: Array<string>;
1171
- propertyValues: Array<{
1172
- dataType: Exclude<PropertyValueContentType, "coordinate">;
1173
- value: string;
1174
- }>;
1179
+ queries: Array<Query>;
1175
1180
  page: number;
1176
1181
  pageSize?: number;
1177
- includeChildItems?: boolean;
1178
- }, categoryParams?: {
1179
- category?: T;
1180
- itemCategories?: U;
1181
- }, options?: {
1182
+ }, itemCategories?: U, options?: {
1182
1183
  fetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
1183
1184
  version?: ApiVersion;
1184
1185
  }): Promise<{
1185
1186
  totalCount: number;
1186
1187
  page: number;
1187
1188
  pageSize: number;
1188
- items: Array<Item<T, U>>;
1189
+ items: Array<Item<"set", U>>;
1189
1190
  error: null;
1190
1191
  } | {
1191
1192
  totalCount: null;
@@ -1382,4 +1383,4 @@ declare const DEFAULT_PAGE_SIZE = 48;
1382
1383
  */
1383
1384
  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
1385
  //#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 };
1386
+ 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,30 +768,48 @@ 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({
766
- dataType: z.enum([
767
- "string",
768
- "integer",
769
- "decimal",
770
- "boolean",
771
- "date",
772
- "dateTime",
773
- "time",
774
- "IDREF"
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.object({
776
+ target: z.enum([
777
+ "title",
778
+ "description",
779
+ "image",
780
+ "periods",
781
+ "bibliography",
782
+ "propertyValue"
775
783
  ]),
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)
784
+ value: z.string(),
785
+ matchMode: z.enum(["includes", "exact"]),
786
+ isCaseSensitive: z.boolean(),
787
+ language: z.string().default("eng"),
788
+ operator: z.enum(["AND", "OR"]).optional()
789
+ })).default([]),
790
+ page: z.number().min(1, "Page must be positive").default(1),
791
+ pageSize: z.number().min(1, "Page size must be positive").default(DEFAULT_PAGE_SIZE)
792
+ }).superRefine((value, ctx) => {
793
+ for (const [index, query] of value.queries.entries()) {
794
+ if (index === 0 && query.operator != null) ctx.addIssue({
795
+ code: "custom",
796
+ path: [
797
+ "queries",
798
+ index,
799
+ "operator"
800
+ ],
801
+ message: "The first query rule must not include an operator"
802
+ });
803
+ if (index > 0 && query.operator == null) ctx.addIssue({
804
+ code: "custom",
805
+ path: [
806
+ "queries",
807
+ index,
808
+ "operator"
809
+ ],
810
+ message: "Query rules after the first must include an operator"
811
+ });
812
+ }
787
813
  });
788
814
 
789
815
  //#endregion
@@ -2029,132 +2055,189 @@ async function fetchItem(uuid, category, itemCategories, options) {
2029
2055
  }
2030
2056
 
2031
2057
  //#endregion
2032
- //#region src/utils/fetchers/set/items-by-property-values.ts
2058
+ //#region src/utils/fetchers/set/items.ts
2059
+ /**
2060
+ * Build a string match predicate for an XQuery string
2061
+ * @param params - The parameters for the predicate
2062
+ * @param params.path - The path to the string
2063
+ * @param params.value - The value to match
2064
+ * @param params.matchMode - The match mode (includes or exact)
2065
+ * @param params.isCaseSensitive - Whether to match case-sensitively
2066
+ * @returns The string match predicate
2067
+ */
2068
+ function buildStringMatchPredicate(params) {
2069
+ const { path, value, matchMode, isCaseSensitive } = params;
2070
+ const comparedPath = isCaseSensitive ? path : `lower-case(${path})`;
2071
+ const comparedValueLiteral = stringLiteral(isCaseSensitive ? value : value.toLowerCase());
2072
+ if (matchMode === "includes") return `contains(${comparedPath}, ${comparedValueLiteral})`;
2073
+ return `${comparedPath} = ${comparedValueLiteral}`;
2074
+ }
2075
+ /**
2076
+ * Build a query predicate for an XQuery string
2077
+ * @param query - The query to build the predicate for
2078
+ * @returns The query predicate
2079
+ */
2080
+ function buildQueryPredicate(query) {
2081
+ const stringMatchParams = {
2082
+ value: query.value,
2083
+ matchMode: query.matchMode,
2084
+ isCaseSensitive: query.isCaseSensitive,
2085
+ language: query.language
2086
+ };
2087
+ switch (query.target) {
2088
+ case "title": return buildStringMatchPredicate({
2089
+ path: `string-join(identification/label/content[@xml:lang="${query.language}"]/string, "")`,
2090
+ ...stringMatchParams
2091
+ });
2092
+ case "description": return buildStringMatchPredicate({
2093
+ path: `string-join(description/content[@xml:lang="${query.language}"]/string, "")`,
2094
+ ...stringMatchParams
2095
+ });
2096
+ case "periods": return buildStringMatchPredicate({
2097
+ path: `string-join(periods/period/identification/label/content[@xml:lang="${query.language}"]/string, "")`,
2098
+ ...stringMatchParams
2099
+ });
2100
+ case "bibliography": return buildStringMatchPredicate({
2101
+ path: `string-join(bibliographies/bibliography/identification/label/content[@xml:lang="${query.language}"]/string, "")`,
2102
+ ...stringMatchParams
2103
+ });
2104
+ case "image": return buildStringMatchPredicate({
2105
+ path: `string-join(image/identification/label/content[@xml:lang="${query.language}"]/string, "")`,
2106
+ ...stringMatchParams
2107
+ });
2108
+ case "propertyValue": return `.//properties//property[${buildStringMatchPredicate({
2109
+ path: `string-join(value/content[@xml:lang="${query.language}"]/string, "")`,
2110
+ ...stringMatchParams
2111
+ })}]`;
2112
+ }
2113
+ }
2033
2114
  /**
2034
- * Build an XQuery string to fetch items by property values from the OCHRE API
2115
+ * Build an XQuery string to fetch Set items from the OCHRE API
2035
2116
  * @param params - The parameters for the fetch
2036
2117
  * @param params.setScopeUuids - An array of Set scope UUIDs to filter by
2037
2118
  * @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
2119
+ * @param params.propertyVariableUuids - An array of property variable UUIDs to filter by
2120
+ * @param params.queries - Ordered queries to combine with AND/OR
2040
2121
  * @param params.page - The page number (1-indexed)
2041
2122
  * @param params.pageSize - The number of items per page
2042
- * @param params.includeChildItems - Whether to include child items of the same category
2043
2123
  * @param options - Options for the fetch
2044
2124
  * @param options.version - The version of the OCHRE API to use
2045
2125
  * @returns An XQuery string
2046
2126
  */
2047
2127
  function buildXQuery$1(params, options) {
2048
2128
  const version = options?.version ?? DEFAULT_API_VERSION;
2049
- const { propertyVariableUuids, propertyValues, setScopeUuids, belongsToCollectionScopeUuids, page, pageSize, includeChildItems = false } = params;
2129
+ const { propertyVariableUuids, queries, setScopeUuids, belongsToCollectionScopeUuids, page, pageSize } = params;
2050
2130
  const startPosition = (page - 1) * pageSize + 1;
2051
2131
  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 ");
2132
+ const setScopeFilter = `/set[(${setScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]/items/*`;
2133
+ const queryFilters = queries.map((query, index) => {
2134
+ const predicate = `(${buildQueryPredicate(query)})`;
2135
+ if (index === 0) return predicate;
2136
+ return `${query.operator === "OR" ? "or" : "and"} ${predicate}`;
2137
+ }).join(" ");
2138
+ const filterPredicates = [];
2139
+ if (belongsToCollectionScopeUuids.length > 0) {
2140
+ const belongsToCollectionScopeValues = belongsToCollectionScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
2141
+ filterPredicates.push(`.//properties[property[label/@uuid="${BELONGS_TO_COLLECTION_UUID}" and value/(${belongsToCollectionScopeValues})]]`);
2142
+ }
2143
+ if (propertyVariableUuids.length > 0) {
2144
+ const propertyVariables = propertyVariableUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
2145
+ filterPredicates.push(`.//properties//property[label[${propertyVariables}]]`);
2146
+ }
2147
+ if (queryFilters.length > 0) filterPredicates.push(`(${queryFilters})`);
2148
+ const itemFilters = filterPredicates.length > 0 ? `[${filterPredicates.join(" and ")}]` : "";
2062
2149
  return `<ochre>{${`let $items := ${version === 2 ? "doc()" : "input()"}/ochre
2063
2150
  ${setScopeFilter}
2064
- ${belongsToCollectionScopeFilter}
2065
- //property[label[${propertyVariables}]][${propertyValuesFilters}]]
2151
+ ${itemFilters}
2066
2152
 
2067
2153
  let $totalCount := count($items)
2068
2154
 
2069
2155
  return <items totalCount="{$totalCount}" page="${page}" pageSize="${pageSize}">{
2070
2156
  for $item in $items[position() ge ${startPosition} and position() le ${endPosition}]
2071
- let $category := local-name($item)
2072
2157
  return element { node-name($item) } {
2073
- $item/@*, ${includeChildItems ? "$item/node()" : "$item/node()[not(local-name(.) = $category)]"}
2158
+ $item/@*, $item/node()
2074
2159
  }
2075
2160
  }</items>`}}</ochre>`;
2076
2161
  }
2077
2162
  /**
2078
- * Fetches and parses items by property values from the OCHRE API
2163
+ * Fetches and parses Set items from the OCHRE API
2079
2164
  *
2080
2165
  * @param params - The parameters for the fetch
2081
2166
  * @param params.setScopeUuids - The Set scope UUIDs to filter by
2082
2167
  * @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
2168
+ * @param params.propertyVariableUuids - The property variable UUIDs to filter by
2169
+ * @param params.queries - Ordered queries to combine with AND/OR
2085
2170
  * @param params.page - The page number (1-indexed)
2086
2171
  * @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
2172
+ * @param itemCategories - The categories of the items to fetch
2091
2173
  * @param options - Options for the fetch
2092
2174
  * @param options.fetch - The fetch function to use
2093
2175
  * @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
2176
+ * @returns The parsed Set items or null if the fetch/parse fails
2095
2177
  */
2096
- async function fetchSetItemsByPropertyValues(params, categoryParams, options) {
2178
+ async function fetchSetItems(params, itemCategories, options) {
2097
2179
  try {
2098
2180
  const version = options?.version ?? DEFAULT_API_VERSION;
2099
- const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids, propertyValues, page, pageSize, includeChildItems } = setItemsByPropertyValuesParamsSchema.parse(params);
2100
- const { category, itemCategories } = categoryParams ?? {};
2181
+ const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids, queries, page, pageSize } = setItemsParamsSchema.parse(params);
2101
2182
  const xquery = buildXQuery$1({
2102
2183
  setScopeUuids,
2103
2184
  belongsToCollectionScopeUuids,
2104
2185
  propertyVariableUuids,
2105
- propertyValues,
2106
- includeChildItems,
2186
+ queries,
2107
2187
  page,
2108
2188
  pageSize
2109
2189
  }, { version });
2110
2190
  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
2191
  if (!response.ok) throw new Error(`OCHRE API responded with status: ${response.status}`);
2112
2192
  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}`);
2193
+ if (Array.isArray(data.result) || Object.keys(data.result).length === 0) throw new Error("No items found");
2194
+ if (itemCategories != null) {
2195
+ const itemCategoriesSet = new Set(Object.keys(data.result.ochre.items));
2196
+ const missingCategories = itemCategories.filter((category) => !itemCategoriesSet.has(category));
2197
+ if (missingCategories.length > 0) throw new Error(`No Set items found for item categories: ${missingCategories.join(", ")}`);
2198
+ }
2116
2199
  const items = [];
2117
- if ("resource" in data.result.ochre.items && data.result.ochre.items.resource != null) {
2200
+ if ((itemCategories == null || itemCategories.includes("resource")) && "resource" in data.result.ochre.items && data.result.ochre.items.resource != null) {
2118
2201
  const resources = parseResources(Array.isArray(data.result.ochre.items.resource) ? data.result.ochre.items.resource : [data.result.ochre.items.resource]);
2119
2202
  items.push(...resources);
2120
2203
  }
2121
- if ("spatialUnit" in data.result.ochre.items && data.result.ochre.items.spatialUnit != null) {
2204
+ if ((itemCategories == null || itemCategories.includes("spatialUnit")) && "spatialUnit" in data.result.ochre.items && data.result.ochre.items.spatialUnit != null) {
2122
2205
  const spatialUnits = parseSpatialUnits(Array.isArray(data.result.ochre.items.spatialUnit) ? data.result.ochre.items.spatialUnit : [data.result.ochre.items.spatialUnit]);
2123
2206
  items.push(...spatialUnits);
2124
2207
  }
2125
- if ("concept" in data.result.ochre.items && data.result.ochre.items.concept != null) {
2208
+ if ((itemCategories == null || itemCategories.includes("concept")) && "concept" in data.result.ochre.items && data.result.ochre.items.concept != null) {
2126
2209
  const concepts = parseConcepts(Array.isArray(data.result.ochre.items.concept) ? data.result.ochre.items.concept : [data.result.ochre.items.concept]);
2127
2210
  items.push(...concepts);
2128
2211
  }
2129
- if ("period" in data.result.ochre.items && data.result.ochre.items.period != null) {
2212
+ if ((itemCategories == null || itemCategories.includes("period")) && "period" in data.result.ochre.items && data.result.ochre.items.period != null) {
2130
2213
  const periods = parsePeriods(Array.isArray(data.result.ochre.items.period) ? data.result.ochre.items.period : [data.result.ochre.items.period]);
2131
2214
  items.push(...periods);
2132
2215
  }
2133
- if ("bibliography" in data.result.ochre.items && data.result.ochre.items.bibliography != null) {
2216
+ if ((itemCategories == null || itemCategories.includes("bibliography")) && "bibliography" in data.result.ochre.items && data.result.ochre.items.bibliography != null) {
2134
2217
  const bibliographies = parseBibliographies(Array.isArray(data.result.ochre.items.bibliography) ? data.result.ochre.items.bibliography : [data.result.ochre.items.bibliography]);
2135
2218
  items.push(...bibliographies);
2136
2219
  }
2137
- if ("person" in data.result.ochre.items && data.result.ochre.items.person != null) {
2220
+ if ((itemCategories == null || itemCategories.includes("person")) && "person" in data.result.ochre.items && data.result.ochre.items.person != null) {
2138
2221
  const persons = parsePersons(Array.isArray(data.result.ochre.items.person) ? data.result.ochre.items.person : [data.result.ochre.items.person]);
2139
2222
  items.push(...persons);
2140
2223
  }
2141
- if ("propertyVariable" in data.result.ochre.items && data.result.ochre.items.propertyVariable != null) {
2224
+ if ((itemCategories == null || itemCategories.includes("propertyVariable")) && "propertyVariable" in data.result.ochre.items && data.result.ochre.items.propertyVariable != null) {
2142
2225
  const propertyVariables = parsePropertyVariables(Array.isArray(data.result.ochre.items.propertyVariable) ? data.result.ochre.items.propertyVariable : [data.result.ochre.items.propertyVariable]);
2143
2226
  items.push(...propertyVariables);
2144
2227
  }
2145
- if ("propertyValue" in data.result.ochre.items && data.result.ochre.items.propertyValue != null) {
2228
+ if ((itemCategories == null || itemCategories.includes("propertyValue")) && "propertyValue" in data.result.ochre.items && data.result.ochre.items.propertyValue != null) {
2146
2229
  const propertyValues = parsePropertyValues(Array.isArray(data.result.ochre.items.propertyValue) ? data.result.ochre.items.propertyValue : [data.result.ochre.items.propertyValue]);
2147
2230
  items.push(...propertyValues);
2148
2231
  }
2149
- if ("text" in data.result.ochre.items && data.result.ochre.items.text != null) {
2232
+ if ((itemCategories == null || itemCategories.includes("text")) && "text" in data.result.ochre.items && data.result.ochre.items.text != null) {
2150
2233
  const texts = parseTexts(Array.isArray(data.result.ochre.items.text) ? data.result.ochre.items.text : [data.result.ochre.items.text]);
2151
2234
  items.push(...texts);
2152
2235
  }
2153
- if ("set" in data.result.ochre.items && data.result.ochre.items.set != null) {
2236
+ if ((itemCategories == null || itemCategories.includes("set")) && "set" in data.result.ochre.items && data.result.ochre.items.set != null) {
2154
2237
  const sets = parseSets(Array.isArray(data.result.ochre.items.set) ? data.result.ochre.items.set : [data.result.ochre.items.set]);
2155
2238
  items.push(...sets);
2156
2239
  }
2157
- if ("tree" in data.result.ochre.items && data.result.ochre.items.tree != null) {
2240
+ if ((itemCategories == null || itemCategories.includes("tree")) && "tree" in data.result.ochre.items && data.result.ochre.items.tree != null) {
2158
2241
  const trees = parseTrees(Array.isArray(data.result.ochre.items.tree) ? data.result.ochre.items.tree : [data.result.ochre.items.tree]);
2159
2242
  items.push(...trees);
2160
2243
  }
@@ -2172,7 +2255,7 @@ async function fetchSetItemsByPropertyValues(params, categoryParams, options) {
2172
2255
  page: null,
2173
2256
  pageSize: null,
2174
2257
  items: null,
2175
- error: error instanceof Error ? error.message : "Failed to fetch items by property values"
2258
+ error: error instanceof Error ? error.message : "Failed to fetch Set items"
2176
2259
  };
2177
2260
  }
2178
2261
  }
@@ -3908,4 +3991,4 @@ async function fetchWebsite(abbreviation, options) {
3908
3991
  }
3909
3992
 
3910
3993
  //#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 };
3994
+ 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.0",
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",